org.cloudfoundry.multiapps.controller.client.ResilientCloudControllerClient Maven / Gradle / Ivy
The newest version!
package org.cloudfoundry.multiapps.controller.client;
import java.nio.file.Path;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.Supplier;
import org.cloudfoundry.client.v3.Metadata;
import org.cloudfoundry.multiapps.controller.client.util.ResilientCloudOperationExecutor;
import org.springframework.http.HttpStatus;
import com.sap.cloudfoundry.client.facade.ApplicationServicesUpdateCallback;
import com.sap.cloudfoundry.client.facade.CloudControllerClient;
import com.sap.cloudfoundry.client.facade.CloudControllerClientImpl;
import com.sap.cloudfoundry.client.facade.ServiceBindingOperationCallback;
import com.sap.cloudfoundry.client.facade.UploadStatusCallback;
import com.sap.cloudfoundry.client.facade.domain.CloudApplication;
import com.sap.cloudfoundry.client.facade.domain.CloudAsyncJob;
import com.sap.cloudfoundry.client.facade.domain.CloudBuild;
import com.sap.cloudfoundry.client.facade.domain.CloudDomain;
import com.sap.cloudfoundry.client.facade.domain.CloudEvent;
import com.sap.cloudfoundry.client.facade.domain.CloudPackage;
import com.sap.cloudfoundry.client.facade.domain.CloudProcess;
import com.sap.cloudfoundry.client.facade.domain.CloudRoute;
import com.sap.cloudfoundry.client.facade.domain.CloudServiceBinding;
import com.sap.cloudfoundry.client.facade.domain.CloudServiceBroker;
import com.sap.cloudfoundry.client.facade.domain.CloudServiceInstance;
import com.sap.cloudfoundry.client.facade.domain.CloudServiceKey;
import com.sap.cloudfoundry.client.facade.domain.CloudServiceOffering;
import com.sap.cloudfoundry.client.facade.domain.CloudSpace;
import com.sap.cloudfoundry.client.facade.domain.CloudStack;
import com.sap.cloudfoundry.client.facade.domain.CloudTask;
import com.sap.cloudfoundry.client.facade.domain.DockerInfo;
import com.sap.cloudfoundry.client.facade.domain.DropletInfo;
import com.sap.cloudfoundry.client.facade.domain.InstancesInfo;
import com.sap.cloudfoundry.client.facade.domain.ServicePlanVisibility;
import com.sap.cloudfoundry.client.facade.domain.Staging;
import com.sap.cloudfoundry.client.facade.domain.Upload;
import com.sap.cloudfoundry.client.facade.domain.UserRole;
import com.sap.cloudfoundry.client.facade.dto.ApplicationToCreateDto;
import com.sap.cloudfoundry.client.facade.rest.CloudControllerRestClient;
public class ResilientCloudControllerClient implements CloudControllerClient {
private final CloudControllerClientImpl delegate;
public ResilientCloudControllerClient(CloudControllerRestClient delegate) {
this.delegate = new CloudControllerClientImpl(delegate);
}
@Override
public CloudSpace getTarget() {
return delegate.getTarget();
}
@Override
public void createServiceInstance(CloudServiceInstance serviceInstance) {
executeWithRetry(() -> delegate.createServiceInstance(serviceInstance));
}
@Override
public void addDomain(String domainName) {
executeWithRetry(() -> delegate.addDomain(domainName));
}
@Override
public void addRoute(String host, String domainName, String path) {
executeWithRetry(() -> delegate.addRoute(host, domainName, path));
}
@Override
public Optional bindServiceInstance(String bindingName, String applicationName, String serviceInstanceName) {
return executeWithRetry(() -> delegate.bindServiceInstance(bindingName, applicationName, serviceInstanceName));
}
@Override
public Optional bindServiceInstance(String bindingName, String applicationName, String serviceInstanceName,
Map parameters,
ApplicationServicesUpdateCallback applicationServicesUpdateCallback) {
return executeWithRetry(() -> delegate.bindServiceInstance(bindingName, applicationName, serviceInstanceName, parameters,
applicationServicesUpdateCallback));
}
@Override
public void createApplication(ApplicationToCreateDto applicationToCreateDto) {
executeWithRetry(() -> delegate.createApplication(applicationToCreateDto));
}
@Override
public String createServiceBroker(CloudServiceBroker serviceBroker) {
return executeWithRetry(() -> delegate.createServiceBroker(serviceBroker));
}
@Override
public void createUserProvidedServiceInstance(CloudServiceInstance serviceInstance) {
executeWithRetry(() -> delegate.createUserProvidedServiceInstance(serviceInstance));
}
@Override
public void deleteApplication(String applicationName) {
executeWithRetry(() -> delegate.deleteApplication(applicationName));
}
@Override
public void deleteDomain(String domainName) {
executeWithRetry(() -> delegate.deleteDomain(domainName));
}
@Override
public void deleteOrphanedRoutes() {
executeWithRetry(delegate::deleteOrphanedRoutes, HttpStatus.NOT_FOUND);
}
@Override
public void deleteRoute(String host, String domainName, String path) {
executeWithRetry(() -> delegate.deleteRoute(host, domainName, path));
}
@Override
public void deleteServiceInstance(String serviceInstanceName) {
executeWithRetry(() -> delegate.deleteServiceInstance(serviceInstanceName));
}
@Override
public void deleteServiceInstance(CloudServiceInstance serviceInstance) {
executeWithRetry(() -> delegate.deleteServiceInstance(serviceInstance));
}
@Override
public String deleteServiceBroker(String name) {
return executeWithRetry(() -> delegate.deleteServiceBroker(name));
}
@Override
public CloudServiceBinding getServiceBinding(UUID serviceBindingId) {
return executeWithRetry(() -> delegate.getServiceBinding(serviceBindingId));
}
@Override
public Optional deleteServiceBinding(String serviceInstanceName, String serviceKeyName) {
return executeWithRetry(() -> delegate.deleteServiceBinding(serviceInstanceName, serviceKeyName));
}
@Override
public CloudApplication getApplication(String applicationName) {
return executeWithRetry(() -> delegate.getApplication(applicationName));
}
@Override
public CloudApplication getApplication(String applicationName, boolean required) {
return executeWithRetry(() -> delegate.getApplication(applicationName, required));
}
@Override
public UUID getApplicationGuid(String applicationName) {
return executeWithRetry(() -> delegate.getApplicationGuid(applicationName));
}
@Override
public String getApplicationName(UUID uuid) {
return executeWithRetry(() -> delegate.getApplicationName(uuid));
}
@Override
public InstancesInfo getApplicationInstances(CloudApplication application) {
return executeWithRetry(() -> delegate.getApplicationInstances(application));
}
@Override
public InstancesInfo getApplicationInstances(UUID applicationGuid) {
return executeWithRetry(() -> delegate.getApplicationInstances(applicationGuid));
}
@Override
public CloudProcess getApplicationProcess(UUID applicationGuid) {
return executeWithRetry(() -> delegate.getApplicationProcess(applicationGuid));
}
@Override
public List getApplicationRoutes(UUID applicationGuid) {
return executeWithRetry(() -> delegate.getApplicationRoutes(applicationGuid));
}
@Override
public boolean getApplicationSshEnabled(UUID applicationGuid) {
return executeWithRetry(() -> delegate.getApplicationSshEnabled(applicationGuid));
}
@Override
public List getApplications() {
return executeWithRetry(delegate::getApplications, HttpStatus.NOT_FOUND);
}
@Override
public CloudDomain getDefaultDomain() {
return executeWithRetry(delegate::getDefaultDomain);
}
@Override
public List getDomains() {
return executeWithRetry(delegate::getDomains, HttpStatus.NOT_FOUND);
}
@Override
public List getDomainsForOrganization() {
return executeWithRetry(delegate::getDomainsForOrganization, HttpStatus.NOT_FOUND);
}
@Override
public List getPrivateDomains() {
return executeWithRetry(delegate::getPrivateDomains, HttpStatus.NOT_FOUND);
}
@Override
public List getRoutes(String domainName) {
return executeWithRetry(() -> delegate.getRoutes(domainName), HttpStatus.NOT_FOUND);
}
@Override
public CloudServiceBroker getServiceBroker(String name) {
return executeWithRetry(() -> delegate.getServiceBroker(name));
}
@Override
public CloudServiceBroker getServiceBroker(String name, boolean required) {
return executeWithRetry(() -> delegate.getServiceBroker(name, required));
}
@Override
public List getServiceBrokers() {
return executeWithRetry(delegate::getServiceBrokers, HttpStatus.NOT_FOUND);
}
@Override
public UUID getRequiredServiceInstanceGuid(String name) {
return executeWithRetry(() -> delegate.getRequiredServiceInstanceGuid(name));
}
@Override
public CloudServiceInstance getServiceInstance(String serviceInstanceName) {
return executeWithRetry(() -> delegate.getServiceInstance(serviceInstanceName));
}
@Override
public CloudServiceInstance getServiceInstance(String serviceInstanceName, boolean required) {
return executeWithRetry(() -> delegate.getServiceInstance(serviceInstanceName, required));
}
@Override
public String getServiceInstanceName(UUID serviceInstanceGuid) {
return executeWithRetry(() -> delegate.getServiceInstanceName(serviceInstanceGuid));
}
@Override
public CloudServiceInstance getServiceInstanceWithoutAuxiliaryContent(String serviceInstanceName) {
return executeWithRetry(() -> delegate.getServiceInstanceWithoutAuxiliaryContent(serviceInstanceName));
}
@Override
public CloudServiceInstance getServiceInstanceWithoutAuxiliaryContent(String serviceInstanceName, boolean required) {
return executeWithRetry(() -> delegate.getServiceInstanceWithoutAuxiliaryContent(serviceInstanceName, required));
}
@Override
public List getServiceAppBindings(UUID serviceInstanceGuid) {
return executeWithRetry(() -> delegate.getServiceAppBindings(serviceInstanceGuid));
}
@Override
public List getAppBindings(UUID applicationGuid) {
return executeWithRetry(() -> delegate.getAppBindings(applicationGuid));
}
@Override
public CloudServiceBinding getServiceBindingForApplication(UUID applicationGuid, UUID serviceInstanceGuid) {
return executeWithRetry(() -> delegate.getServiceBindingForApplication(applicationGuid, serviceInstanceGuid));
}
@Override
public Map getServiceInstanceParameters(UUID guid) {
return executeWithRetry(() -> delegate.getServiceInstanceParameters(guid));
}
@Override
public Map getUserProvidedServiceInstanceParameters(UUID guid) {
return executeWithRetry(() -> delegate.getUserProvidedServiceInstanceParameters(guid));
}
@Override
public Map getServiceBindingParameters(UUID guid) {
return executeWithRetry(() -> delegate.getServiceBindingParameters(guid));
}
@Override
public CloudServiceKey getServiceKey(String serviceInstanceName, String serviceKeyName) {
return executeWithRetry(() -> delegate.getServiceKey(serviceInstanceName, serviceKeyName));
}
@Override
public List getSharedDomains() {
return executeWithRetry(delegate::getSharedDomains, HttpStatus.NOT_FOUND);
}
@Override
public void rename(String oldApplicationName, String newApplicationName) {
executeWithRetry(() -> delegate.rename(oldApplicationName, newApplicationName));
}
@Override
public void restartApplication(String applicationName) {
executeWithRetry(() -> delegate.restartApplication(applicationName));
}
@Override
public void startApplication(String applicationName) {
executeWithRetry(() -> delegate.startApplication(applicationName));
}
@Override
public void stopApplication(String applicationName) {
executeWithRetry(() -> delegate.stopApplication(applicationName));
}
@Override
public Optional unbindServiceInstance(String applicationName, String serviceInstanceName) {
return executeWithRetry(() -> delegate.unbindServiceInstance(applicationName, serviceInstanceName));
}
@Override
public Optional unbindServiceInstance(UUID appGuid, UUID serviceGuid) {
return executeWithRetry(() -> delegate.unbindServiceInstance(appGuid, serviceGuid));
}
@Override
public void updateApplicationDiskQuota(String applicationName, int disk) {
executeWithRetry(() -> delegate.updateApplicationDiskQuota(applicationName, disk));
}
@Override
public void updateApplicationEnv(String applicationName, Map env) {
executeWithRetry(() -> delegate.updateApplicationEnv(applicationName, env));
}
@Override
public void updateApplicationInstances(String applicationName, int instances) {
executeWithRetry(() -> delegate.updateApplicationInstances(applicationName, instances));
}
@Override
public void updateApplicationMemory(String applicationName, int memory) {
executeWithRetry(() -> delegate.updateApplicationMemory(applicationName, memory));
}
@Override
public void updateApplicationStaging(String applicationName, Staging staging) {
executeWithRetry(() -> delegate.updateApplicationStaging(applicationName, staging));
}
@Override
public void updateApplicationRoutes(String applicationName, Set routes) {
executeWithRetry(() -> delegate.updateApplicationRoutes(applicationName, routes), HttpStatus.NOT_FOUND);
}
@Override
public String updateServiceBroker(CloudServiceBroker serviceBroker) {
return executeWithRetry(() -> delegate.updateServiceBroker(serviceBroker));
}
@Override
public void updateServicePlanVisibilityForBroker(String name, ServicePlanVisibility visibility) {
executeWithRetry(() -> delegate.updateServicePlanVisibilityForBroker(name, visibility));
}
@Override
public void updateServicePlan(String serviceName, String servicePlan) {
executeWithRetry(() -> delegate.updateServicePlan(serviceName, servicePlan));
}
@Override
public void updateServiceParameters(String serviceName, Map parameters) {
executeWithRetry(() -> delegate.updateServiceParameters(serviceName, parameters));
}
@Override
public void updateServiceTags(String serviceName, List tags) {
executeWithRetry(() -> delegate.updateServiceTags(serviceName, tags));
}
@Override
public void updateServiceSyslogDrainUrl(String serviceName, String syslogDrainUrl) {
executeWithRetry(() -> delegate.updateServiceSyslogDrainUrl(serviceName, syslogDrainUrl));
}
@Override
public CloudPackage asyncUploadApplicationWithExponentialBackoff(String applicationName, Path file, UploadStatusCallback callback,
Duration overrideTimeout) {
if (overrideTimeout != null) {
return executeWithRetry(() -> delegate.asyncUploadApplicationWithExponentialBackoff(applicationName, file, callback,
overrideTimeout));
}
return executeWithExponentialBackoff(timeout -> delegate.asyncUploadApplicationWithExponentialBackoff(applicationName, file,
callback, timeout));
}
@Override
public Upload getUploadStatus(UUID packageGuid) {
return executeWithRetry(() -> delegate.getUploadStatus(packageGuid));
}
@Override
public CloudServiceKey createAndFetchServiceKey(CloudServiceKey keyModel, String serviceInstanceName) {
return executeWithRetry(() -> delegate.createAndFetchServiceKey(keyModel, serviceInstanceName));
}
@Override
public Optional createServiceKey(CloudServiceKey keyModel, String serviceInstanceName) {
return executeWithRetry(() -> delegate.createServiceKey(keyModel, serviceInstanceName));
}
@Override
public Optional createServiceKey(String serviceInstanceName, String serviceKeyName, Map parameters) {
return executeWithRetry(() -> delegate.createServiceKey(serviceInstanceName, serviceKeyName, parameters));
}
@Override
public Optional deleteServiceBinding(UUID serviceBindingGuid, ServiceBindingOperationCallback serviceBindingOperationCallback) {
return executeWithRetry(() -> delegate.deleteServiceBinding(serviceBindingGuid, serviceBindingOperationCallback));
}
@Override
public Optional deleteServiceBinding(UUID bindingGuid) {
return executeWithRetry(() -> delegate.deleteServiceBinding(bindingGuid));
}
@Override
public Map getApplicationEnvironment(String applicationName) {
return executeWithRetry(() -> delegate.getApplicationEnvironment(applicationName));
}
@Override
public Map getApplicationEnvironment(UUID appGuid) {
return executeWithRetry(() -> delegate.getApplicationEnvironment(appGuid));
}
@Override
public List getApplicationEvents(String applicationName) {
return executeWithRetry(() -> delegate.getApplicationEvents(applicationName), HttpStatus.NOT_FOUND);
}
@Override
public List getEventsByActee(UUID uuid) {
return executeWithRetry(() -> delegate.getEventsByActee(uuid));
}
@Override
public List getEvents() {
return executeWithRetry(delegate::getEvents, HttpStatus.NOT_FOUND);
}
@Override
public List getServiceKeys(String serviceInstanceName) {
return executeWithRetry(() -> delegate.getServiceKeys(serviceInstanceName), HttpStatus.NOT_FOUND);
}
@Override
public List getServiceKeysWithCredentials(String serviceInstanceName) {
return executeWithRetry(() -> delegate.getServiceKeysWithCredentials(serviceInstanceName), HttpStatus.NOT_FOUND);
}
@Override
public List getServiceKeys(CloudServiceInstance serviceInstance) {
return executeWithRetry(() -> delegate.getServiceKeys(serviceInstance), HttpStatus.NOT_FOUND);
}
@Override
public List getServiceKeysWithCredentials(CloudServiceInstance serviceInstance) {
return executeWithRetry(() -> delegate.getServiceKeysWithCredentials(serviceInstance), HttpStatus.NOT_FOUND);
}
@Override
public List getServiceOfferings() {
return executeWithRetry(delegate::getServiceOfferings, HttpStatus.NOT_FOUND);
}
@Override
public CloudStack getStack(String name) {
return executeWithRetry(() -> delegate.getStack(name));
}
@Override
public CloudStack getStack(String name, boolean required) {
return executeWithRetry(() -> delegate.getStack(name, required));
}
@Override
public List getStacks() {
return executeWithRetry(delegate::getStacks, HttpStatus.NOT_FOUND);
}
@Override
public CloudTask getTask(UUID taskGuid) {
return executeWithRetry(() -> delegate.getTask(taskGuid));
}
@Override
public List getTasks(String applicationName) {
return executeWithRetry(() -> delegate.getTasks(applicationName), HttpStatus.NOT_FOUND);
}
@Override
public CloudTask runTask(String applicationName, CloudTask task) {
return executeWithRetry(() -> delegate.runTask(applicationName, task));
}
@Override
public CloudTask cancelTask(UUID taskGuid) {
return executeWithRetry(() -> delegate.cancelTask(taskGuid));
}
@Override
public CloudBuild createBuild(UUID packageGuid) {
return executeWithRetry(() -> delegate.createBuild(packageGuid));
}
@Override
public List getBuildsForPackage(UUID packageGuid) {
return executeWithRetry(() -> delegate.getBuildsForPackage(packageGuid));
}
@Override
public CloudBuild getBuild(UUID buildGuid) {
return executeWithRetry(() -> delegate.getBuild(buildGuid));
}
@Override
public void bindDropletToApp(UUID dropletGuid, UUID appGuid) {
executeWithRetry(() -> delegate.bindDropletToApp(dropletGuid, appGuid));
}
@Override
public List getBuildsForApplication(UUID applicationGuid) {
return executeWithRetry(() -> delegate.getBuildsForApplication(applicationGuid));
}
@Override
public Optional unbindServiceInstance(String applicationName, String serviceInstanceName,
ApplicationServicesUpdateCallback applicationServicesUpdateCallback) {
return executeWithRetry(() -> delegate.unbindServiceInstance(applicationName, serviceInstanceName,
applicationServicesUpdateCallback));
}
@Override
public List getApplicationsByMetadataLabelSelector(String labelSelector) {
return executeWithRetry(() -> delegate.getApplicationsByMetadataLabelSelector(labelSelector));
}
@Override
public List getServiceInstancesByMetadataLabelSelector(String labelSelector) {
return executeWithRetry(() -> delegate.getServiceInstancesByMetadataLabelSelector(labelSelector));
}
@Override
public List getServiceInstancesWithoutAuxiliaryContentByMetadataLabelSelector(String labelSelector) {
return executeWithRetry(() -> delegate.getServiceInstancesWithoutAuxiliaryContentByMetadataLabelSelector(labelSelector));
}
@Override
public void updateApplicationMetadata(UUID guid, Metadata metadata) {
executeWithRetry(() -> delegate.updateApplicationMetadata(guid, metadata));
}
@Override
public void updateServiceInstanceMetadata(UUID guid, Metadata metadata) {
executeWithRetry(() -> delegate.updateServiceInstanceMetadata(guid, metadata));
}
@Override
public void updateServiceBindingMetadata(UUID guid, Metadata metadata) {
executeWithRetry(() -> delegate.updateServiceBindingMetadata(guid, metadata));
}
@Override
public List getServiceInstancesWithoutAuxiliaryContentByNames(List names) {
return executeWithRetry(() -> delegate.getServiceInstancesWithoutAuxiliaryContentByNames(names));
}
@Override
public DropletInfo getCurrentDropletForApplication(UUID applicationGuid) {
return executeWithRetry(() -> delegate.getCurrentDropletForApplication(applicationGuid));
}
@Override
public CloudPackage getPackage(UUID packageGuid) {
return executeWithRetry(() -> delegate.getPackage(packageGuid));
}
@Override
public List getPackagesForApplication(UUID applicationGuid) {
return executeWithRetry(() -> delegate.getPackagesForApplication(applicationGuid));
}
@Override
public Set getUserRolesBySpaceAndUser(UUID spaceGuid, UUID userGuid) {
return executeWithRetry(() -> delegate.getUserRolesBySpaceAndUser(spaceGuid, userGuid));
}
@Override
public CloudPackage createDockerPackage(UUID applicationGuid, DockerInfo dockerInfo) {
return executeWithRetry(() -> delegate.createDockerPackage(applicationGuid, dockerInfo));
}
@Override
public CloudAsyncJob getAsyncJob(String jobId) {
return executeWithRetry(() -> delegate.getAsyncJob(jobId));
}
private void executeWithRetry(Runnable operation, HttpStatus... statusesToIgnore) {
executeWithRetry(() -> {
operation.run();
return null;
}, statusesToIgnore);
}
private T executeWithRetry(Supplier operation, HttpStatus... statusesToIgnore) {
ResilientCloudOperationExecutor executor = new ResilientCloudOperationExecutor().withStatusesToIgnore(statusesToIgnore);
return executor.execute(operation);
}
private T executeWithExponentialBackoff(Function operation, HttpStatus... statusesToIgnore) {
ResilientCloudOperationExecutor executor = new ResilientCloudOperationExecutor().withStatusesToIgnore(statusesToIgnore);
return executor.executeWithExponentialBackoff(operation);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy