All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.pivotal.services.plugin.tasks.helper.CfServicesDetailHelper Maven / Gradle / Ivy

There is a newer version: 2.3.0-rc.6
Show newest version
package io.pivotal.services.plugin.tasks.helper;

import org.cloudfoundry.operations.CloudFoundryOperations;
import org.cloudfoundry.operations.services.GetServiceInstanceRequest;
import org.cloudfoundry.operations.services.ServiceInstance;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import reactor.core.publisher.Mono;

import java.util.Optional;

/**
 * Responsible for getting the service instance given a service name
 */
public class CfServicesDetailHelper {
    private static final Logger LOGGER = Logging.getLogger(CfServicesDetailHelper.class);

    public Mono> getServiceInstanceDetail(CloudFoundryOperations cfOperations,
                                                                    String serviceName) {

        LOGGER.lifecycle("Checking details of service '{}'", serviceName);
        Mono serviceInstanceMono = cfOperations.services()
            .getInstance(
                GetServiceInstanceRequest.builder()
                    .name(serviceName)
                    .build());

        return serviceInstanceMono
            .map(serviceInstance -> Optional.ofNullable(serviceInstance))
            .onErrorResume(Exception.class, e -> Mono.just(Optional.empty()));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy