Improve logging

- Only log potentially sensitive information in debug mode
- Apply consistent style
This commit is contained in:
Roy Clarkson
2020-05-29 13:16:09 -04:00
committed by Roy Clarkson
parent b77ee1980f
commit 8f055e89db
15 changed files with 798 additions and 422 deletions

View File

@@ -71,8 +71,6 @@ import reactor.core.publisher.Mono;
import org.springframework.stereotype.Service;
import static java.lang.String.format;
@Service
public class CloudFoundryService {
@@ -88,8 +86,7 @@ public class CloudFoundryService {
private final CloudFoundryProperties cloudFoundryProperties;
public CloudFoundryService(CloudFoundryClient cloudFoundryClient,
CloudFoundryOperations cloudFoundryOperations,
public CloudFoundryService(CloudFoundryClient cloudFoundryClient, CloudFoundryOperations cloudFoundryOperations,
CloudFoundryProperties cloudFoundryProperties) {
this.cloudFoundryClient = cloudFoundryClient;
this.cloudFoundryOperations = cloudFoundryOperations;
@@ -97,47 +94,47 @@ public class CloudFoundryService {
}
public Mono<Void> enableServiceBrokerAccess(String serviceName) {
return cloudFoundryOperations.serviceAdmin()
.enableServiceAccess(EnableServiceAccessRequest.builder()
.serviceName(serviceName)
.build())
.doOnSuccess(item -> LOG.info("Enabled access to service " + serviceName))
.doOnError(error -> LOG.error("Error enabling access to service " + serviceName + ": " + error));
return cloudFoundryOperations.serviceAdmin().enableServiceAccess(EnableServiceAccessRequest.builder()
.serviceName(serviceName)
.build())
.doOnSuccess(v -> LOG.info("Enabled access to service. serviceName={}", serviceName))
.doOnError(e -> LOG.error(String.format("Error enabling access to service. serviceName=%s, error=%s",
serviceName, e.getMessage()), e));
}
public Mono<Void> createServiceBroker(String brokerName, String testBrokerAppName) {
return getApplicationRoute(testBrokerAppName)
.flatMap(url -> cloudFoundryOperations.serviceAdmin()
.create(CreateServiceBrokerRequest.builder()
.name(brokerName)
.username("user")
.password("password")
.url(url)
.build())
.doOnSuccess(item -> LOG.info("Created service broker " + brokerName))
.doOnError(error -> LOG.error("Error creating service broker " + brokerName + ": " + error)));
.flatMap(url -> cloudFoundryOperations.serviceAdmin().create(CreateServiceBrokerRequest.builder()
.name(brokerName)
.username("user")
.password("password")
.url(url)
.build())
.doOnSuccess(v -> LOG.info("Success creating service broker. brokerName={}", brokerName))
.doOnError(e -> LOG.error(String.format("Error creating service broker. brokerName=%s, error=%s",
brokerName, e.getMessage()), e)));
}
public Mono<Void> updateServiceBroker(String brokerName, String testBrokerAppName) {
return getApplicationRoute(testBrokerAppName)
.flatMap(url -> cloudFoundryOperations.serviceAdmin()
.update(UpdateServiceBrokerRequest.builder()
.name(brokerName)
.username("user")
.password("password")
.url(url)
.build())
.doOnSuccess(item -> LOG.info("Updating service broker " + brokerName))
.doOnError(error -> LOG.error("Error updating service broker " + brokerName + ": " + error)));
.flatMap(url -> cloudFoundryOperations.serviceAdmin().update(UpdateServiceBrokerRequest.builder()
.name(brokerName)
.username("user")
.password("password")
.url(url)
.build())
.doOnSuccess(v -> LOG.info("Success updating service broker. brokerName={}", brokerName))
.doOnError(e -> LOG.error(String.format("Error updating service broker. brokerName=%s, error=%s",
brokerName, e.getMessage()), e)));
}
public Mono<String> getApplicationRoute(String appName) {
return cloudFoundryOperations.applications()
.get(GetApplicationRequest.builder()
.name(appName)
.build())
.doOnSuccess(item -> LOG.info("Got route for app " + appName))
.doOnError(error -> LOG.error("Error getting route for app " + appName + ": " + error))
return cloudFoundryOperations.applications().get(GetApplicationRequest.builder()
.name(appName)
.build())
.doOnSuccess(item -> LOG.info("Success getting route for app. appName={}", appName))
.doOnError(e -> LOG.error(String.format("Error getting route for app. appName=%s, error=%s", appName,
e.getMessage()), e))
.map(ApplicationDetail::getUrls)
.flatMapMany(Flux::fromIterable)
.next()
@@ -146,101 +143,99 @@ public class CloudFoundryService {
public Mono<Void> pushBrokerApp(String appName, Path appPath, String brokerClientId,
List<String> appBrokerProperties) {
return cloudFoundryOperations.applications()
.pushManifest(PushApplicationManifestRequest.builder()
.manifest(ApplicationManifest.builder()
.environmentVariables(appBrokerDeployerEnvironmentVariables(brokerClientId))
.putAllEnvironmentVariables(propertiesToEnvironment(appBrokerProperties))
.name(appName)
.path(appPath)
.memory(1024)
.build())
return cloudFoundryOperations.applications().pushManifest(PushApplicationManifestRequest.builder()
.manifest(ApplicationManifest.builder()
.environmentVariables(appBrokerDeployerEnvironmentVariables(brokerClientId))
.putAllEnvironmentVariables(propertiesToEnvironment(appBrokerProperties))
.name(appName)
.path(appPath)
.memory(1024)
.build())
.doOnSuccess(item -> LOG.info("Pushed broker app " + appName))
.doOnError(error -> LOG.error("Error pushing broker app " + appName + ": " + error));
.build())
.doOnSuccess(v -> LOG.info("Success pushing broker app. appName={}", appName))
.doOnError(e -> LOG.error(String.format("Error pushing broker app. appName=%s, error=%s", appName,
e.getMessage()), e));
}
public Mono<Void> updateBrokerApp(String appName, String brokerClientId, List<String> appBrokerProperties) {
return cloudFoundryOperations.applications()
.get(GetApplicationRequest.builder().name(appName).build())
return cloudFoundryOperations.applications().get(GetApplicationRequest.builder().name(appName).build())
.map(ApplicationDetail::getId)
.flatMap(applicationId ->
cloudFoundryClient
.applicationsV2()
.update(UpdateApplicationRequest
.builder()
.applicationId(applicationId)
.putAllEnvironmentJsons(appBrokerDeployerEnvironmentVariables(brokerClientId))
.putAllEnvironmentJsons(propertiesToEnvironment(appBrokerProperties))
.name(appName)
.memory(1024)
.build())
.thenReturn(applicationId))
.then(cloudFoundryOperations.applications()
.restart(RestartApplicationRequest.builder().name(appName).build()))
.flatMap(applicationId -> cloudFoundryClient.applicationsV2().update(UpdateApplicationRequest
.builder()
.applicationId(applicationId)
.putAllEnvironmentJsons(appBrokerDeployerEnvironmentVariables(brokerClientId))
.putAllEnvironmentJsons(propertiesToEnvironment(appBrokerProperties))
.name(appName)
.memory(1024)
.build())
.thenReturn(applicationId))
.then(cloudFoundryOperations.applications().restart(RestartApplicationRequest.builder()
.name(appName)
.build()))
.doOnSuccess(item -> LOG.info("Updated broker app " + appName))
.doOnError(error -> LOG.error("Error updating broker app " + appName + ": " + error))
.then();
}
public Mono<Void> deleteApp(String appName) {
return cloudFoundryOperations.applications()
.delete(DeleteApplicationRequest.builder()
.name(appName)
.deleteRoutes(true)
.build())
.doOnSuccess(item -> LOG.info("Deleted app " + appName))
.doOnError(error -> LOG.warn("Error deleting app " + appName + ": " + error))
return cloudFoundryOperations.applications().delete(DeleteApplicationRequest.builder()
.name(appName)
.deleteRoutes(true)
.build())
.doOnSuccess(item -> LOG.info("Success deleting app. appName={}", appName))
.doOnError(e -> LOG.warn(String.format("Error deleting app. appName=%s, error=%s", appName,
e.getMessage()), e))
.onErrorResume(e -> Mono.empty());
}
public Mono<Void> deleteServiceBroker(String brokerName) {
return cloudFoundryOperations.serviceAdmin()
.delete(DeleteServiceBrokerRequest.builder()
.name(brokerName)
.build())
.doOnSuccess(item -> LOG.info("Deleted service broker " + brokerName))
.doOnError(error -> LOG.warn("Error deleting service broker " + brokerName + ": " + error))
return cloudFoundryOperations.serviceAdmin().delete(DeleteServiceBrokerRequest.builder()
.name(brokerName)
.build())
.doOnSuccess(item -> LOG.info("Success deleting service broker. brokerName={}", brokerName))
.doOnError(e -> LOG.warn(String.format("Error deleting service broker. brokerName=%s, error=%s ",
brokerName, e.getMessage()), e))
.onErrorResume(e -> Mono.empty());
}
public Mono<Void> deleteServiceInstance(String serviceInstanceName) {
return getServiceInstance(serviceInstanceName)
.flatMap(si -> cloudFoundryOperations.services()
.deleteInstance(DeleteServiceInstanceRequest.builder()
.name(si.getName())
.build())
.doOnSuccess(item -> LOG.info("Deleted service instance " + serviceInstanceName))
.doOnError(
error -> LOG.error("Error deleting service instance " + serviceInstanceName + ": " + error))
.flatMap(si -> cloudFoundryOperations.services().deleteInstance(DeleteServiceInstanceRequest.builder()
.name(si.getName())
.build())
.doOnSuccess(v -> LOG.info("Success deleting service instance. serviceInstanceName={}",
serviceInstanceName))
.doOnError(e -> LOG.error(String.format("Error deleting service instance. serviceInstanceName=%s, " +
"error=%s", serviceInstanceName, e.getMessage()), e))
.onErrorResume(e -> Mono.empty()))
.doOnError(error -> LOG.warn("Error getting service instance " + serviceInstanceName + ": " + error))
.doOnError(e -> LOG.warn(String.format("Error getting service instance. serviceInstanceName=%s, " +
"error=%s", serviceInstanceName, e.getMessage()), e))
.onErrorResume(e -> Mono.empty());
}
public Mono<Void> createServiceInstance(String planName,
String serviceName,
String serviceInstanceName,
public Mono<Void> createServiceInstance(String planName, String serviceName, String serviceInstanceName,
Map<String, Object> parameters) {
return cloudFoundryOperations.services()
.createInstance(CreateServiceInstanceRequest.builder()
.planName(planName)
.serviceName(serviceName)
.serviceInstanceName(serviceInstanceName)
.parameters(parameters)
.build())
.doOnSuccess(item -> LOG.info("Created service instance " + serviceInstanceName))
.doOnError(error -> LOG.error("Error creating service instance " + serviceInstanceName + ": " + error));
return cloudFoundryOperations.services().createInstance(CreateServiceInstanceRequest.builder()
.planName(planName)
.serviceName(serviceName)
.serviceInstanceName(serviceInstanceName)
.parameters(parameters)
.build())
.doOnSuccess(item -> LOG.info("Success creating service instance. serviceInstanceName={}",
serviceInstanceName))
.doOnError(e -> LOG.error(String.format("Error creating service instance. serviceInstanceName=%s, " +
"error=%s", serviceInstanceName, e.getMessage()), e));
}
public Mono<Void> updateServiceInstance(String serviceInstanceName, Map<String, Object> parameters) {
return cloudFoundryOperations.services()
.updateInstance(UpdateServiceInstanceRequest.builder()
.serviceInstanceName(serviceInstanceName)
.parameters(parameters)
.build())
.doOnSuccess(item -> LOG.info("Updated service instance " + serviceInstanceName))
.doOnError(error -> LOG.error("Error updating service instance " + serviceInstanceName + ": " + error));
return cloudFoundryOperations.services().updateInstance(UpdateServiceInstanceRequest.builder()
.serviceInstanceName(serviceInstanceName)
.parameters(parameters)
.build())
.doOnSuccess(item -> LOG.info("Success updating service instance. serviceInstanceName={}",
serviceInstanceName))
.doOnError(e -> LOG.error(String.format("Error updating service instance. serviceInstanceName=%s, " +
"error=%s", serviceInstanceName, e.getMessage()), e));
}
public Flux<ServiceInstanceSummary> listServiceInstances() {
@@ -257,12 +252,13 @@ public class CloudFoundryService {
private Mono<ServiceInstance> getServiceInstance(CloudFoundryOperations operations,
String serviceInstanceName) {
return operations.services()
.getInstance(GetServiceInstanceRequest.builder()
.name(serviceInstanceName)
.build())
.doOnSuccess(item -> LOG.info("Got service instance " + serviceInstanceName))
.doOnError(error -> LOG.error("Error getting service instance " + serviceInstanceName + ": " + error));
return operations.services().getInstance(GetServiceInstanceRequest.builder()
.name(serviceInstanceName)
.build())
.doOnSuccess(item -> LOG.info("Success getting service instance. serviceInstanceName={}",
serviceInstanceName))
.doOnError(e -> LOG.error(String.format("Error getting service instance. serviceInstanceName=%s, " +
"error=%s", serviceInstanceName, e.getMessage()), e));
}
public Mono<List<ApplicationSummary>> getApplications() {
@@ -286,7 +282,7 @@ public class CloudFoundryService {
return operations.applications()
.list()
.doOnComplete(() -> LOG.info("Listed applications"))
.doOnError(error -> LOG.error("Error listing applications: " + error));
.doOnError(e -> LOG.error(String.format("Error listing applications. error=%s", e.getMessage()), e));
}
public Mono<ApplicationEnvironments> getApplicationEnvironment(String appName) {
@@ -302,8 +298,9 @@ public class CloudFoundryService {
.getEnvironments(GetApplicationEnvironmentsRequest.builder()
.name(appName)
.build())
.doOnSuccess(item -> LOG.info("Got environment for application " + appName))
.doOnError(error -> LOG.error("Error getting environment for application " + appName + ": " + error));
.doOnSuccess(item -> LOG.info("Success getting environment for application. appName={}", appName))
.doOnError(e -> LOG.error(String.format("Error getting environment for application. appName=%s, " +
"error=%s", appName, e.getMessage()), e));
}
public Mono<Void> stopApplication(String appName) {
@@ -313,10 +310,9 @@ public class CloudFoundryService {
}
public Mono<List<String>> getSpaces() {
return cloudFoundryOperations.spaces()
.list()
.doOnComplete(() -> LOG.info("Listed spaces"))
.doOnError(error -> LOG.error("Error listing spaces: " + error))
return cloudFoundryOperations.spaces().list()
.doOnComplete(() -> LOG.info("Success listing spaces"))
.doOnError(e -> LOG.error(String.format("Error listing spaces. error=%s" + e.getMessage()), e))
.map(SpaceSummary::getName)
.collectList();
}
@@ -331,13 +327,11 @@ public class CloudFoundryService {
.spaces();
final String defaultSpace = cloudFoundryProperties.getDefaultSpace();
return getDefaultSpace(spaceOperations)
.switchIfEmpty(spaceOperations.create(CreateSpaceRequest
.builder()
.name(defaultSpace)
.organization(defaultOrg)
.build())
.then(getDefaultSpace(spaceOperations)));
return getDefaultSpace(spaceOperations).switchIfEmpty(spaceOperations.create(CreateSpaceRequest.builder()
.name(defaultSpace)
.organization(defaultOrg)
.build())
.then(getDefaultSpace(spaceOperations)));
}
public Mono<OrganizationSummary> getOrCreateDefaultOrganization() {
@@ -345,11 +339,9 @@ public class CloudFoundryService {
final String defaultOrg = cloudFoundryProperties.getDefaultOrg();
return getDefaultOrg(organizationOperations)
.switchIfEmpty(organizationOperations
.create(CreateOrganizationRequest
.builder()
.organizationName(defaultOrg)
.build())
.switchIfEmpty(organizationOperations.create(CreateOrganizationRequest.builder()
.organizationName(defaultOrg)
.build())
.then(getDefaultOrg(organizationOperations)));
}
@@ -488,7 +480,7 @@ public class CloudFoundryService {
environment.put(propertyKeyValue[0], propertyKeyValue[1]);
}
else {
throw new IllegalArgumentException(format("App Broker property '%s' is incorrectly formatted",
throw new IllegalArgumentException(String.format("App Broker property '%s' is incorrectly formatted",
Arrays.toString(propertyKeyValue)));
}
}

View File

@@ -25,7 +25,9 @@ import reactor.util.Loggers;
public class DefaultBackingAppDeploymentService implements BackingAppDeploymentService {
private final Logger log = Loggers.getLogger(DefaultBackingAppDeploymentService.class);
private static final Logger LOG = Loggers.getLogger(DefaultBackingAppDeploymentService.class);
private static final String BACKINGAPPS_LOG_TEMPLATE = "backingApps={}";
private final DeployerClient deployerClient;
@@ -40,11 +42,18 @@ public class DefaultBackingAppDeploymentService implements BackingAppDeploymentS
.runOn(Schedulers.parallel())
.flatMap(backingApplication -> deployerClient.deploy(backingApplication, serviceInstanceId))
.sequential()
.doOnRequest(l -> log.debug("Deploying applications {}", backingApps))
.doOnEach(response -> log.debug("Finished deploying application {}", response))
.doOnComplete(() -> log.debug("Finished deploying application {}", backingApps))
.doOnError(exception -> log.error(String.format("Error deploying applications %s with error '%s'",
backingApps, exception.getMessage()), exception));
.doOnRequest(l -> {
LOG.info("Deploying applications");
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
})
.doOnComplete(() -> {
LOG.info("Finish deploying applications");
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
})
.doOnError(e -> {
LOG.error(String.format("Error deploying applications. error=%s", e.getMessage()), e);
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
});
}
@Override
@@ -54,11 +63,18 @@ public class DefaultBackingAppDeploymentService implements BackingAppDeploymentS
.runOn(Schedulers.parallel())
.flatMap(backingApplication -> deployerClient.update(backingApplication, serviceInstanceId))
.sequential()
.doOnRequest(l -> log.debug("Updating applications {}", backingApps))
.doOnEach(response -> log.debug("Finished updating application {}", response))
.doOnComplete(() -> log.debug("Finished updating application {}", backingApps))
.doOnError(exception -> log
.error(String.format("Error updating applications %s with error '%s'", backingApps, exception)));
.doOnRequest(l -> {
LOG.info("Updating applications");
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
})
.doOnComplete(() -> {
LOG.info("Finish updating applications");
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
})
.doOnError(e -> {
LOG.error(String.format("Error updating applications. error=%s", e.getMessage()), e);
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
});
}
@Override
@@ -68,11 +84,18 @@ public class DefaultBackingAppDeploymentService implements BackingAppDeploymentS
.runOn(Schedulers.parallel())
.flatMap(deployerClient::undeploy)
.sequential()
.doOnRequest(l -> log.debug("Undeploying applications {}", backingApps))
.doOnEach(response -> log.debug("Finished undeploying application {}", response))
.doOnComplete(() -> log.debug("Finished undeploying application {}", backingApps))
.doOnError(exception -> log.error(String.format("Error undeploying applications %s with error '%s'",
backingApps, exception.getMessage()), exception));
.doOnRequest(l -> {
LOG.info("Undeploying applications");
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
})
.doOnComplete(() -> {
LOG.info("Finish undeploying applications");
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
})
.doOnError(e -> {
LOG.error(String.format("Error undeploying applications. error=%s", e.getMessage()), e);
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
});
}
}

View File

@@ -25,7 +25,9 @@ import reactor.util.Loggers;
public class DefaultBackingServicesProvisionService implements BackingServicesProvisionService {
private final Logger log = Loggers.getLogger(DefaultBackingServicesProvisionService.class);
private static final Logger LOG = Loggers.getLogger(DefaultBackingServicesProvisionService.class);
private static final String BACKINGSERVICES_LOG_TEMPLATE = "backingServices={}";
private final DeployerClient deployerClient;
@@ -40,11 +42,15 @@ public class DefaultBackingServicesProvisionService implements BackingServicesPr
.runOn(Schedulers.parallel())
.flatMap(deployerClient::createServiceInstance)
.sequential()
.doOnRequest(l -> log.debug("Creating backing services {}", backingServices))
.doOnEach(response -> log.debug("Finished creating backing service {}", response))
.doOnComplete(() -> log.debug("Finished creating backing services {}", backingServices))
.doOnError(exception -> log.error(String.format("Error creating backing services %s with error '%s'",
backingServices, exception.getMessage()), exception));
.doOnRequest(l -> {
LOG.info("Creating backing services");
LOG.debug(BACKINGSERVICES_LOG_TEMPLATE, backingServices);
})
.doOnComplete(() -> {
LOG.info("Finish creating backing services");
LOG.debug(BACKINGSERVICES_LOG_TEMPLATE, backingServices);
})
.doOnError(e -> LOG.error(String.format("Error creating backing services. error=%s", e.getMessage()), e));
}
@Override
@@ -54,11 +60,15 @@ public class DefaultBackingServicesProvisionService implements BackingServicesPr
.runOn(Schedulers.parallel())
.flatMap(deployerClient::updateServiceInstance)
.sequential()
.doOnRequest(l -> log.debug("Updating backing services {}", backingServices))
.doOnEach(response -> log.debug("Finished updating backing service {}", response))
.doOnComplete(() -> log.debug("Finished updating backing services {}", backingServices))
.doOnError(exception -> log.error(String.format("Error updating backing services %s with error '%s'",
backingServices, exception.getMessage()), exception));
.doOnRequest(l -> {
LOG.info("Updating backing services");
LOG.debug(BACKINGSERVICES_LOG_TEMPLATE, backingServices);
})
.doOnComplete(() -> {
LOG.info("Finish updating backing services");
LOG.debug(BACKINGSERVICES_LOG_TEMPLATE, backingServices);
})
.doOnError(e -> LOG.error(String.format("Error updating backing services. error=%s", e.getMessage()), e));
}
@Override
@@ -68,11 +78,15 @@ public class DefaultBackingServicesProvisionService implements BackingServicesPr
.runOn(Schedulers.parallel())
.flatMap(deployerClient::deleteServiceInstance)
.sequential()
.doOnRequest(l -> log.debug("Deleting backing services {}", backingServices))
.doOnEach(response -> log.debug("Finished deleting backing service {}", response))
.doOnComplete(() -> log.debug("Finished deleting backing services {}", backingServices))
.doOnError(exception -> log.error(String.format("Error deleting backing services %s with error '%s'",
backingServices, exception.getMessage()), exception));
.doOnRequest(l -> {
LOG.info("Deleting backing services");
LOG.debug(BACKINGSERVICES_LOG_TEMPLATE, backingServices);
})
.doOnComplete(() -> {
LOG.info("Finish deleting backing services");
LOG.debug(BACKINGSERVICES_LOG_TEMPLATE, backingServices);
})
.doOnError(e -> LOG.error(String.format("Error deleting backing services. error=%s", e.getMessage()), e));
}
}

View File

@@ -24,7 +24,11 @@ import reactor.util.Loggers;
public class DeployerClient {
private final Logger log = Loggers.getLogger(DeployerClient.class);
private static final Logger LOG = Loggers.getLogger(DeployerClient.class);
private static final String BACKINGAPP_LOG_TEMPLATE = "backingApp={}";
private static final String BACKINGSERVICE_LOG_TEMPLATE = "backingService={}";
private final AppDeployer appDeployer;
@@ -45,10 +49,19 @@ public class DeployerClient {
.collect(Collectors.toList()))
.serviceInstanceId(serviceInstanceId)
.build())
.doOnRequest(l -> log.debug("Deploying application {}", backingApplication))
.doOnSuccess(response -> log.debug("Finished deploying application {}", backingApplication))
.doOnError(exception -> log.error(String.format("Error deploying application %s with error '%s'",
backingApplication, exception.getMessage()), exception))
.doOnRequest(l -> {
LOG.info("Deploying application. backingAppName={}", backingApplication.getName());
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApplication);
})
.doOnSuccess(response -> {
LOG.info("Success deploying application. backingAppName={}", backingApplication.getName());
LOG.debug("response={}, backingApp={}", response, backingApplication);
})
.doOnError(e -> {
LOG.error(String.format("Error deploying application. backingAppName=%s, error=%s",
backingApplication.getName(), e.getMessage()), e);
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApplication);
})
.map(DeployApplicationResponse::getName);
}
@@ -65,10 +78,19 @@ public class DeployerClient {
.collect(Collectors.toList()))
.serviceInstanceId(serviceInstanceId)
.build())
.doOnRequest(l -> log.debug("Updating application {}", backingApplication))
.doOnSuccess(response -> log.debug("Finished updating application {}", backingApplication))
.doOnError(exception -> log.error(String.format("Error updating application %s with error '%s'",
backingApplication, exception), exception))
.doOnRequest(l -> {
LOG.info("Updating application. backingAppName={}", backingApplication.getName());
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApplication);
})
.doOnSuccess(response -> {
LOG.info("Success updating application. backingAppName={}", backingApplication.getName());
LOG.debug("response={}, backingApp={}", response, backingApplication);
})
.doOnError(e -> {
LOG.error(String.format("Error updating application. backingAppName=%s, error=%s",
backingApplication.getName(), e.getMessage()), e);
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApplication);
})
.map(UpdateApplicationResponse::getName);
}
@@ -79,10 +101,19 @@ public class DeployerClient {
.properties(backingApplication.getProperties())
.name(backingApplication.getName())
.build())
.doOnRequest(l -> log.debug("Undeploying application {}", backingApplication))
.doOnSuccess(response -> log.debug("Finished undeploying application {}", backingApplication))
.doOnError(exception -> log.error(String.format("Error undeploying application %s with error '%s'",
backingApplication, exception.getMessage()), exception))
.doOnRequest(l -> {
LOG.info("Undeploying application. backingAppName={}", backingApplication.getName());
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApplication);
})
.doOnSuccess(response -> {
LOG.info("Success undeploying application. backingAppName={}", backingApplication.getName());
LOG.debug("response={}, backingApp={}", response, backingApplication);
})
.doOnError(e -> {
LOG.error(String.format("Error undeploying application. backingAppName=%s, error=%s",
backingApplication.getName(), e.getMessage()), e);
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApplication);
})
.onErrorReturn(UndeployApplicationResponse.builder()
.name(backingApplication.getName())
.build())
@@ -100,10 +131,19 @@ public class DeployerClient {
.parameters(backingService.getParameters())
.properties(backingService.getProperties())
.build())
.doOnRequest(l -> log.debug("Creating backing service {}", backingService.getName()))
.doOnSuccess(response -> log.debug("Finished creating backing service {}", backingService.getName()))
.doOnError(exception -> log.error(String.format("Error creating backing service %s with error '%s'",
backingService.getName(), exception.getMessage()), exception))
.doOnRequest(l -> {
LOG.info("Creating backing service {}", backingService.getName());
LOG.debug(BACKINGSERVICE_LOG_TEMPLATE, backingService);
})
.doOnSuccess(response -> {
LOG.info("Success creating backing service {}", backingService.getName());
LOG.debug("response={}, backingService={}", response, backingService);
})
.doOnError(e -> {
LOG.error(String.format("Error creating backing service. backingServiceName=%s, error=%s",
backingService.getName(), e.getMessage()), e);
LOG.debug(BACKINGSERVICE_LOG_TEMPLATE, backingService);
})
.map(CreateServiceInstanceResponse::getName);
}
@@ -117,10 +157,19 @@ public class DeployerClient {
.properties(backingService.getProperties())
.rebindOnUpdate(backingService.isRebindOnUpdate())
.build())
.doOnRequest(l -> log.debug("Updating backing service {}", backingService.getName()))
.doOnSuccess(response -> log.debug("Finished updating backing service {}", backingService.getName()))
.doOnError(exception -> log.error(String.format("Error updating backing service %s with error '%s'",
backingService.getName(), exception.getMessage()), exception))
.doOnRequest(l -> {
LOG.info("Updating backing service {}", backingService.getName());
LOG.debug(BACKINGSERVICE_LOG_TEMPLATE, backingService);
})
.doOnSuccess(response -> {
LOG.info("Success updating backing service {}", backingService.getName());
LOG.debug("response={}, backingService={}", response, backingService);
})
.doOnError(e -> {
LOG.error(String.format("Error updating backing service. backingServiceName=%s, error=%s",
backingService.getName(), e.getMessage()), e);
LOG.debug(BACKINGSERVICE_LOG_TEMPLATE, backingService);
})
.map(UpdateServiceInstanceResponse::getName);
}
@@ -132,10 +181,19 @@ public class DeployerClient {
.serviceInstanceName(backingService.getServiceInstanceName())
.properties(backingService.getProperties())
.build())
.doOnRequest(l -> log.debug("Deleting backing service {}", backingService.getName()))
.doOnSuccess(response -> log.debug("Finished deleting backing service {}", backingService.getName()))
.doOnError(exception -> log.error(String.format("Error deleting backing service %s with error '%s'",
backingService.getName(), exception.getMessage()), exception))
.doOnRequest(l -> {
LOG.info("Deleting backing service {}", backingService.getName());
LOG.debug(BACKINGSERVICE_LOG_TEMPLATE, backingService);
})
.doOnSuccess(response -> {
LOG.info("Success deleting backing service {}", backingService.getName());
LOG.debug("response={}, backingService={}", response, backingService);
})
.doOnError(e -> {
LOG.error(String.format("Error deleting backing service. backingServiceName=%s, error=%s",
backingService.getName(), e.getMessage()), e);
LOG.debug(BACKINGSERVICE_LOG_TEMPLATE, backingService);
})
.onErrorReturn(DeleteServiceInstanceResponse.builder()
.name(backingService.getServiceInstanceName())
.build())

View File

@@ -31,7 +31,7 @@ import org.springframework.cloud.appbroker.deployer.BackingApplication;
public class EnvironmentMappingParametersTransformerFactory extends
ParametersTransformerFactory<BackingApplication, EnvironmentMappingParametersTransformerFactory.Config> {
private final Logger logger = Loggers.getLogger(EnvironmentMappingParametersTransformerFactory.class);
private static final Logger LOG = Loggers.getLogger(EnvironmentMappingParametersTransformerFactory.class);
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
@@ -62,7 +62,7 @@ public class EnvironmentMappingParametersTransformerFactory extends
valueString = OBJECT_MAPPER.writeValueAsString(value);
}
catch (JsonProcessingException e) {
logger.error("Failed to write object as JSON String", e);
LOG.error("Failed to write object as JSON String", e);
valueString = value.toString();
}
}

View File

@@ -61,8 +61,8 @@ public class KebabCasePropertyBeanIntrospector implements BeanIntrospector {
}
catch (final IntrospectionException e) {
if (LOG.isErrorEnabled()) {
LOG.error("Error when creating PropertyDescriptor for method '{}'. " +
"This property will be ignored. {}", m, e);
LOG.error(String.format("Error when creating PropertyDescriptor for method '%s'. This " +
"property will be ignored. %s", m), e);
}
}
}

View File

@@ -36,7 +36,9 @@ import org.springframework.cloud.appbroker.extensions.targets.TargetService;
public class BackingAppManagementService {
private final Logger log = Loggers.getLogger(BackingAppManagementService.class);
private static final Logger LOG = Loggers.getLogger(BackingAppManagementService.class);
private static final String BACKINGAPPS_LOG_TEMPLATE = "backingApp={}";
private final ManagementClient managementClient;
@@ -60,11 +62,18 @@ public class BackingAppManagementService {
.parallel()
.runOn(Schedulers.parallel())
.flatMap(managementClient::stop)
.doOnRequest(l -> log.debug("Stopping applications {}", backingApps))
.doOnEach(response -> log.debug("Finished stopping application {}", response))
.doOnComplete(() -> log.debug("Finished stopping application {}", backingApps))
.doOnError(exception -> log.error(String.format("Error stopping applications %s with error '%s'",
backingApps, exception.getMessage()), exception)))
.doOnRequest(l -> {
LOG.info("Stopping applications");
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
})
.doOnComplete(() -> {
LOG.info("Finish stopping applications");
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
})
.doOnError(e -> {
LOG.error(String.format("Error stopping applications. error=%s", e.getMessage()), e);
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
}))
.then();
}
@@ -74,11 +83,18 @@ public class BackingAppManagementService {
.parallel()
.runOn(Schedulers.parallel())
.flatMap(managementClient::start)
.doOnRequest(l -> log.debug("Starting applications {}", backingApps))
.doOnEach(response -> log.debug("Finished starting application {}", response))
.doOnComplete(() -> log.debug("Finished starting application {}", backingApps))
.doOnError(exception -> log.error(String.format("Error starting applications %s with error '%s'",
backingApps, exception.getMessage()), exception)))
.doOnRequest(l -> {
LOG.info("Starting applications");
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
})
.doOnComplete(() -> {
LOG.info("Finish starting applications");
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
})
.doOnError(e -> {
LOG.error(String.format("Error starting applications. error=%s", e.getMessage()), e);
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
}))
.then();
}
@@ -88,11 +104,18 @@ public class BackingAppManagementService {
.parallel()
.runOn(Schedulers.parallel())
.flatMap(managementClient::restart)
.doOnRequest(l -> log.debug("Restarting applications {}", backingApps))
.doOnEach(response -> log.debug("Finished restarting application {}", response))
.doOnComplete(() -> log.debug("Finished restarting application {}", backingApps))
.doOnError(exception -> log.error(String.format("Error restarting applications %s with error '%s'",
backingApps, exception.getMessage()), exception)))
.doOnRequest(l -> {
LOG.info("Restarting applications");
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
})
.doOnComplete(() -> {
LOG.info("Finish restarting applications");
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
})
.doOnError(e -> {
LOG.error(String.format("Error restarting applications. error=%s", e.getMessage()), e);
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
}))
.then();
}
@@ -102,11 +125,18 @@ public class BackingAppManagementService {
.parallel()
.runOn(Schedulers.parallel())
.flatMap(managementClient::restage)
.doOnRequest(l -> log.debug("Restaging applications {}", backingApps))
.doOnEach(response -> log.debug("Finished restaging application {}", response))
.doOnComplete(() -> log.debug("Finished restaging application {}", backingApps))
.doOnError(exception -> log.error(String.format("Error restaging applications %s with error '%s'",
backingApps, exception.getMessage()), exception)))
.doOnRequest(l -> {
LOG.info("Restaging applications");
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
})
.doOnComplete(() -> {
LOG.info("Finish restaging applications");
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
})
.doOnError(e -> {
LOG.error(String.format("Error restaging applications. error=%s", e.getMessage()), e);
LOG.debug(BACKINGAPPS_LOG_TEMPLATE, backingApps);
}))
.then();
}
@@ -131,12 +161,19 @@ public class BackingAppManagementService {
.services(services)
.environment(response.getEnvironment())
.build()))
.doOnRequest(l -> log.debug("Getting deployed backing applications {}", app))
.doOnError(exception -> log.error(String.format("Error getting deployed backing application %s " +
"with error '%s'", app.getName(), exception.getMessage()), exception))
.doOnRequest(l -> {
LOG.info("Getting deployed backing application. appName={}", app.getName());
LOG.debug("backingApp={}", app);
})
.doOnError(e -> {
LOG.error(String.format("Error getting deployed backing application. appName=%s, error=%s",
app.getName(), e.getMessage()), e);
LOG.debug("backingApp={}", app);
})
.onErrorResume(exception -> Mono.empty()))
.collectList()
.map(BackingApplications::new);
.map(BackingApplications::new)
.doOnSuccess(backingApplications -> LOG.debug("backingApplications={}", backingApplications));
}
private Mono<BackingApplications> getBackingApplicationsForService(String serviceInstanceId) {

View File

@@ -26,6 +26,8 @@ public class ManagementClient {
private static final Logger LOG = Loggers.getLogger(ManagementClient.class);
private static final String BACKINGAPP_LOG_TEMPLATE = "backingApp={}";
private final AppManager appManager;
public ManagementClient(AppManager appManager) {
@@ -38,10 +40,19 @@ public class ManagementClient {
.name(backingApp.getName())
.properties(backingApp.getProperties())
.build())
.doOnRequest(l -> LOG.debug("Starting application {}", backingApp))
.doOnSuccess(response -> LOG.debug("Finished starting application {}", backingApp))
.doOnError(exception -> LOG.error(String.format("Error starting application %s with error '%s'",
backingApp, exception.getMessage()), exception)));
.doOnRequest(l -> {
LOG.info("Starting application. backingAppName={}", backingApp.getName());
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApp);
})
.doOnSuccess(response -> {
LOG.info("Success starting application. backingAppName={}", backingApp.getName());
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApp);
})
.doOnError(e -> {
LOG.error(String.format("Error starting application. backingAppName=%s, error=%s",
backingApp.getName(), e.getMessage()), e);
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApp);
}));
}
public Mono<Void> stop(BackingApplication backingApplication) {
@@ -50,10 +61,19 @@ public class ManagementClient {
.name(backingApp.getName())
.properties(backingApp.getProperties())
.build())
.doOnRequest(l -> LOG.debug("Stopping application {}", backingApp))
.doOnSuccess(response -> LOG.debug("Finished stopping application {}", backingApp))
.doOnError(exception -> LOG.error(String.format("Error stopping application %s with error '%s'",
backingApp, exception.getMessage()), exception)));
.doOnRequest(l -> {
LOG.info("Stopping application. backingAppName={}", backingApp.getName());
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApp);
})
.doOnSuccess(response -> {
LOG.info("Success stopping application. backingAppName={}", backingApp.getName());
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApp);
})
.doOnError(e -> {
LOG.error(String.format("Error stopping application. backingAppName=%s, error=%s",
backingApp.getName(), e.getMessage()), e);
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApp);
}));
}
public Mono<Void> restart(BackingApplication backingApplication) {
@@ -62,10 +82,19 @@ public class ManagementClient {
.name(backingApp.getName())
.properties(backingApp.getProperties())
.build())
.doOnRequest(l -> LOG.debug("Restarting application {}", backingApp))
.doOnSuccess(response -> LOG.debug("Finished restarting application {}", backingApp))
.doOnError(exception -> LOG.error(String.format("Error restarting application %s with error '%s'",
backingApp, exception.getMessage()), exception)));
.doOnRequest(l -> {
LOG.info("Restarting application. backingAppName={}", backingApp.getName());
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApp);
})
.doOnSuccess(response -> {
LOG.info("Success restarting application. backingAppName={}", backingApp.getName());
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApp);
})
.doOnError(e -> {
LOG.error(String.format("Error restarting application. backingAppName=%s, error=%s",
backingApp.getName(), e.getMessage()), e);
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApp);
}));
}
public Mono<Void> restage(BackingApplication backingApplication) {
@@ -74,10 +103,19 @@ public class ManagementClient {
.name(backingApp.getName())
.properties(backingApp.getProperties())
.build())
.doOnRequest(l -> LOG.debug("Restaging application {}", backingApp))
.doOnSuccess(response -> LOG.debug("Finished restaging application {}", backingApp))
.doOnError(exception -> LOG.error(String.format("Error restaging application %s with error '%s'",
backingApp, exception.getMessage()), exception)));
.doOnRequest(l -> {
LOG.info("Restaging application. backingAppName={}", backingApp.getName());
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApp);
})
.doOnSuccess(response -> {
LOG.info("Success restaging application. backingAppName={}", backingApp.getName());
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApp);
})
.doOnError(e -> {
LOG.error(String.format("Error restaging application. backingAppName=%s, error=%s",
backingApp.getName(), e.getMessage()), e);
LOG.debug(BACKINGAPP_LOG_TEMPLATE, backingApp);
}));
}
}

View File

@@ -152,10 +152,16 @@ public class WorkflowServiceInstanceBindingService implements ServiceInstanceBin
return stateRepository.saveState(request.getServiceInstanceId(), request.getBindingId(),
OperationState.IN_PROGRESS, "create service instance binding started")
.thenMany(invokeCreateWorkflows(request, response)
.doOnRequest(l -> LOG.debug("Creating service instance binding"))
.doOnComplete(() -> LOG.debug("Finished creating service instance binding"))
.doOnError(exception -> LOG.error(String.format("Error creating service instance binding with error " +
"'%s'", exception.getMessage()), exception)))
.doOnRequest(l -> {
LOG.info("Creating service instance binding");
LOG.debug("request={}", request);
})
.doOnComplete(() -> {
LOG.debug("Finish creating service instance binding");
LOG.debug("request={}, response={}", request, response);
})
.doOnError(e -> LOG.error(String.format("Error creating service instance binding. error=%s",
e.getMessage()), e)))
.thenEmpty(stateRepository.saveState(request.getServiceInstanceId(), request.getBindingId(),
OperationState.SUCCEEDED, "create service instance binding completed")
.then())
@@ -218,10 +224,16 @@ public class WorkflowServiceInstanceBindingService implements ServiceInstanceBin
return stateRepository.saveState(request.getServiceInstanceId(), request.getBindingId(),
OperationState.IN_PROGRESS, "delete service instance binding started")
.thenMany(invokeDeleteWorkflows(request, response)
.doOnRequest(l -> LOG.debug("Deleting service instance binding"))
.doOnComplete(() -> LOG.debug("Finished deleting service instance binding"))
.doOnError(exception -> LOG.error(String.format("Error deleting service instance binding with error " +
"'%s'", exception.getMessage()), exception)))
.doOnRequest(l -> {
LOG.info("Deleting service instance binding");
LOG.debug("request={}", request);
})
.doOnComplete(() -> {
LOG.info("Finish deleting service instance binding");
LOG.debug("request={}, response={}", request, response);
})
.doOnError(e -> LOG.error(String.format("Error deleting service instance binding. error=%s",
e.getMessage()), e)))
.thenEmpty(stateRepository.saveState(request.getServiceInstanceId(), request.getBindingId(),
OperationState.SUCCEEDED, "delete service instance binding completed")
.then())

View File

@@ -50,7 +50,7 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator;
*/
public class WorkflowServiceInstanceService implements ServiceInstanceService {
private final Logger log = Loggers.getLogger(WorkflowServiceInstanceService.class);
private static final Logger LOG = Loggers.getLogger(WorkflowServiceInstanceService.class);
private final List<CreateServiceInstanceWorkflow> createServiceInstanceWorkflows;
@@ -99,10 +99,16 @@ public class WorkflowServiceInstanceService implements ServiceInstanceService {
OperationState.IN_PROGRESS,
"create service instance started")
.thenMany(invokeCreateWorkflows(request, response)
.doOnRequest(l -> log.debug("Creating service instance"))
.doOnComplete(() -> log.debug("Finished creating service instance"))
.doOnError(exception -> log.error(String.format("Error creating service instance with error '%s'",
exception.getMessage()), exception)))
.doOnRequest(l -> {
LOG.info("Creating service instance");
LOG.debug("request={}", request);
})
.doOnComplete(() -> {
LOG.info("Finish creating service instance");
LOG.debug("request={}, response={}", request, response);
})
.doOnError(e -> LOG.error(String.format("Error creating service instance. error=%s",
e.getMessage()), e)))
.thenEmpty(stateRepository.saveState(request.getServiceInstanceId(),
OperationState.SUCCEEDED, "create service instance completed")
.then())
@@ -142,10 +148,16 @@ public class WorkflowServiceInstanceService implements ServiceInstanceService {
return stateRepository.saveState(request.getServiceInstanceId(),
OperationState.IN_PROGRESS, "delete service instance started")
.thenMany(invokeDeleteWorkflows(request, response)
.doOnRequest(l -> log.debug("Deleting service instance"))
.doOnComplete(() -> log.debug("Finished deleting service instance"))
.doOnError(exception -> log.error(String.format("Error deleting service instance with error '%s'",
exception.getMessage()), exception)))
.doOnRequest(l -> {
LOG.info("Deleting service instance");
LOG.debug("request={}", request);
})
.doOnComplete(() -> {
LOG.info("Finish deleting service instance");
LOG.debug("request={}, response={}", request, response);
})
.doOnError(e -> LOG.error(String.format("Error deleting service instance. error=%s",
e.getMessage()), e)))
.thenEmpty(stateRepository.saveState(request.getServiceInstanceId(),
OperationState.SUCCEEDED, "delete service instance completed")
.then())
@@ -185,10 +197,16 @@ public class WorkflowServiceInstanceService implements ServiceInstanceService {
return stateRepository.saveState(request.getServiceInstanceId(),
OperationState.IN_PROGRESS, "update service instance started")
.thenMany(invokeUpdateWorkflows(request, response)
.doOnRequest(l -> log.debug("Updating service instance"))
.doOnComplete(() -> log.debug("Finished updating service instance"))
.doOnError(exception -> log.error(String.format("Error updating service instance with error '%s'",
exception.getMessage()), exception)))
.doOnRequest(l -> {
LOG.info("Updating service instance");
LOG.debug("request={}", request);
})
.doOnComplete(() -> {
LOG.info("Finish updating service instance");
LOG.debug("request={}, response={}", request, response);
})
.doOnError(e -> LOG.error(String.format("Error updating service instance. error=%s",
e.getMessage()), e)))
.thenEmpty(stateRepository.saveState(request.getServiceInstanceId(),
OperationState.SUCCEEDED, "update service instance completed")
.then())

View File

@@ -39,7 +39,9 @@ public class AppDeploymentCreateServiceInstanceWorkflow
extends AppDeploymentInstanceWorkflow
implements CreateServiceInstanceWorkflow {
private final Logger log = Loggers.getLogger(AppDeploymentCreateServiceInstanceWorkflow.class);
private static final Logger LOG = Loggers.getLogger(AppDeploymentCreateServiceInstanceWorkflow.class);
private static final String REQUEST_LOG_TEMPLATE = "request={}";
private final BackingAppDeploymentService deploymentService;
@@ -86,13 +88,24 @@ public class AppDeploymentCreateServiceInstanceWorkflow
servicesParametersTransformationService.transformParameters(backingServices,
request.getParameters()))
.flatMapMany(backingServicesProvisionService::createServiceInstance)
.doOnRequest(l -> log.debug("Creating backing services for {}/{}",
request.getServiceDefinition().getName(), request.getPlan().getName()))
.doOnComplete(() -> log.debug("Finished creating backing services for {}/{}",
request.getServiceDefinition().getName(), request.getPlan().getName()))
.doOnError(exception -> log.error(String.format("Error creating backing services for %s/%s with error '%s'",
request.getServiceDefinition().getName(), request.getPlan().getName(), exception.getMessage()),
exception));
.doOnRequest(l -> {
LOG.info("Creating backing services. serviceDefinitionName={}, planName={}",
request.getServiceDefinition().getName(), request.getPlan().getName());
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnComplete(() -> {
LOG.info("Finish creating backing services. serviceDefinitionName={}, planName={}",
request.getServiceDefinition().getName(), request.getPlan().getName());
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnError(e -> {
if (LOG.isErrorEnabled()) {
LOG.error(String.format("Error creating backing services. serviceDefinitionName=%s, planName=%s, " +
"error=%s",
request.getServiceDefinition().getName(), request.getPlan().getName(), e.getMessage()), e);
}
LOG.debug(REQUEST_LOG_TEMPLATE, request);
});
}
private Flux<String> deployBackingApplications(CreateServiceInstanceRequest request) {
@@ -108,14 +121,24 @@ public class AppDeploymentCreateServiceInstanceWorkflow
credentialProviderService.addCredentials(backingApps,
request.getServiceInstanceId()))
.flatMapMany(backingApps -> deploymentService.deploy(backingApps, request.getServiceInstanceId()))
.doOnRequest(l -> log.debug("Deploying backing applications for {}/{}",
request.getServiceDefinition().getName(), request.getPlan().getName()))
.doOnComplete(() -> log.debug("Finished deploying backing applications for {}/{}",
request.getServiceDefinition().getName(), request.getPlan().getName()))
.doOnError(
exception -> log.error(String.format("Error deploying backing applications for %s/%s with error '%s'",
request.getServiceDefinition().getName(), request.getPlan().getName(), exception.getMessage()),
exception));
.doOnRequest(l -> {
LOG.info("Deploying backing applications. serviceDefinitionName={}, planName={}",
request.getServiceDefinition().getName(), request.getPlan().getName());
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnComplete(() -> {
LOG.info("Finish deploying backing applications. serviceDefinitionName={}, planName={}",
request.getServiceDefinition().getName(), request.getPlan().getName());
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnError(e -> {
if (LOG.isErrorEnabled()) {
LOG.error(String.format("Error deploying backing applications. serviceDefinitionName=%s, " +
"planName=%s, error=%s", request.getServiceDefinition().getName(), request.getPlan().getName(),
e.getMessage()), e);
}
LOG.debug(REQUEST_LOG_TEMPLATE, request);
});
}
@Override

View File

@@ -44,7 +44,9 @@ public class AppDeploymentDeleteServiceInstanceWorkflow
extends AppDeploymentInstanceWorkflow
implements DeleteServiceInstanceWorkflow {
private final Logger log = Loggers.getLogger(AppDeploymentDeleteServiceInstanceWorkflow.class);
private static final Logger LOG = Loggers.getLogger(AppDeploymentDeleteServiceInstanceWorkflow.class);
private static final String REQUEST_LOG_TEMPLATE = "request={}";
private final BackingAppDeploymentService deploymentService;
@@ -86,11 +88,24 @@ public class AppDeploymentDeleteServiceInstanceWorkflow
}
return Flux.empty();
})
.doOnComplete(() -> log.debug("Finished deleting backing services for {}/{}",
request.getServiceDefinition().getName(), request.getPlan().getName()))
.doOnError(exception -> log.error(String.format("Error deleting backing services for %s/%s with error '%s'",
request.getServiceDefinition().getName(), request.getPlan().getName(), exception.getMessage()),
exception));
.doOnRequest(l -> {
LOG.info("Deleting backing services. serviceDefinitionName={}, planName={}",
request.getServiceDefinition().getName(), request.getPlan().getName());
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnComplete(() -> {
LOG.info("Finish deleting backing services. serviceDefinitionName={}, planName={}",
request.getServiceDefinition().getName(), request.getPlan().getName());
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnError(e -> {
if (LOG.isErrorEnabled()) {
LOG.error(String.format("Error deleting backing services. " +
"serviceDefinitionName=%s, planName=%s, error=%s", request.getServiceDefinition().getName(),
request.getPlan().getName(), e.getMessage()), e);
}
LOG.debug(REQUEST_LOG_TEMPLATE, request);
});
}
private Flux<BackingService> collectBackingServices(DeleteServiceInstanceRequest request) {
@@ -138,14 +153,24 @@ public class AppDeploymentDeleteServiceInstanceWorkflow
request.getServiceInstanceId()))
.defaultIfEmpty(backingApps))
.flatMapMany(deploymentService::undeploy)
.doOnRequest(l -> log.debug("Undeploying backing applications for {}/{}",
request.getServiceDefinition().getName(), request.getPlan().getName()))
.doOnComplete(() -> log.debug("Finished undeploying backing applications for {}/{}",
request.getServiceDefinition().getName(), request.getPlan().getName()))
.doOnError(
exception -> log.error(String.format("Error undeploying backing applications for %s/%s with error '%s'",
request.getServiceDefinition().getName(), request.getPlan().getName(), exception.getMessage()),
exception));
.doOnRequest(l -> {
LOG.info("Undeploying backing applications. serviceDefinitionName={}, planName={}",
request.getServiceDefinition().getName(), request.getPlan().getName());
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnComplete(() -> {
LOG.info("Finish undeploying backing applications. serviceDefinitionName={}, planName={}",
request.getServiceDefinition().getName(), request.getPlan().getName());
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnError(e -> {
if (LOG.isErrorEnabled()) {
LOG.error(String.format("Error undeploying backing applications. serviceDefinitionName=%s, " +
"planName=%s, error=%s", request.getServiceDefinition().getName(), request.getPlan().getName(),
e.getMessage()), e);
}
LOG.debug(REQUEST_LOG_TEMPLATE, request);
});
}
@Override

View File

@@ -48,7 +48,9 @@ import org.springframework.core.annotation.Order;
public class AppDeploymentUpdateServiceInstanceWorkflow extends AppDeploymentInstanceWorkflow
implements UpdateServiceInstanceWorkflow {
private final Logger log = Loggers.getLogger(AppDeploymentUpdateServiceInstanceWorkflow.class);
private static final Logger LOG = Loggers.getLogger(AppDeploymentUpdateServiceInstanceWorkflow.class);
private static final String REQUEST_LOG_TEMPLATE = "request={}";
private final BackingAppDeploymentService deploymentService;
@@ -110,9 +112,9 @@ public class AppDeploymentUpdateServiceInstanceWorkflow extends AppDeploymentIns
List<BackingService> servicesToDelete = servicesInNameList(existingServices,
serviceNamesToDelete);
log.debug("Backing services to update: {}", serviceNamesToUpdate);
log.debug("Backing services to create: {}", serviceNamesToCreate);
log.debug("Backing services to delete: {}", serviceNamesToDelete);
LOG.debug("Backing services to update: {}", serviceNamesToUpdate);
LOG.debug("Backing services to create: {}", serviceNamesToCreate);
LOG.debug("Backing services to delete: {}", serviceNamesToDelete);
return Flux.concat(
backingServicesProvisionService.updateServiceInstance(servicesToUpdate),
@@ -121,14 +123,24 @@ public class AppDeploymentUpdateServiceInstanceWorkflow extends AppDeploymentIns
.parallel()
.runOn(Schedulers.parallel());
})
.doOnRequest(l -> log.debug("Updating backing services for {}/{}",
request.getServiceDefinition().getName(), request.getPlan().getName()))
.doOnComplete(() -> log.debug("Finished updating backing services for {}/{}",
request.getServiceDefinition().getName(), request.getPlan().getName()))
.doOnError(
exception -> log.error(String.format("Error updating backing services for %s/%s with error '%s'",
request.getServiceDefinition().getName(), request.getPlan().getName(), exception.getMessage()),
exception));
.doOnRequest(l -> {
LOG.info("Updating backing services. serviceDefinitionName={}, planName={}",
request.getServiceDefinition().getName(), request.getPlan().getName());
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnComplete(() -> {
LOG.info("Finish updating backing services. serviceDefinitionName={}, planName={}",
request.getServiceDefinition().getName(), request.getPlan().getName());
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnError(e -> {
if (LOG.isErrorEnabled()) {
LOG.error(String.format("Error updating backing services. serviceDefinitionName=%s, planName=%s, " +
"error=%s", request.getServiceDefinition().getName(), request.getPlan().getName(),
e.getMessage()), e);
}
LOG.debug(REQUEST_LOG_TEMPLATE, request);
});
}
private Mono<Map<String, BackingService>> getExistingBackingServiceNameMap(UpdateServiceInstanceRequest request) {
@@ -170,14 +182,24 @@ public class AppDeploymentUpdateServiceInstanceWorkflow extends AppDeploymentIns
.flatMap(backingApps ->
appsParametersTransformationService.transformParameters(backingApps, request.getParameters()))
.flatMapMany(backingApps -> deploymentService.update(backingApps, request.getServiceInstanceId()))
.doOnRequest(l -> log.debug("Updating backing applications for {}/{}",
request.getServiceDefinition().getName(), request.getPlan().getName()))
.doOnComplete(() -> log.debug("Finished updating backing applications for {}/{}",
request.getServiceDefinition().getName(), request.getPlan().getName()))
.doOnError(
exception -> log.error(String.format("Error updating backing applications for %s/%s with error '%s'",
request.getServiceDefinition().getName(), request.getPlan().getName(), exception.getMessage()),
exception));
.doOnRequest(l -> {
LOG.info("Updating backing applications. serviceDefinitionName={}, planName={}",
request.getServiceDefinition().getName(), request.getPlan().getName());
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnComplete(() -> {
LOG.info("Finish updating backing applications. serviceDefinitionName={}, planName={}",
request.getServiceDefinition().getName(), request.getPlan().getName());
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnError(e -> {
if (LOG.isErrorEnabled()) {
LOG.error(String.format("Error updating backing applications. serviceDefinitionName=%s, " +
"planName=%s, error=%s", request.getServiceDefinition().getName(), request.getPlan().getName(),
e.getMessage()), e);
}
LOG.debug(REQUEST_LOG_TEMPLATE, request);
});
}
@Override

View File

@@ -136,6 +136,12 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
private static final Logger LOG = LoggerFactory.getLogger(CloudFoundryAppDeployer.class);
private static final String REQUEST_LOG_TEMPLATE = "request={}";
private static final String RESPONSE_LOG_TEMPLATE = "response={}";
private static final String ERROR_LOG_TEMPLATE = "error=%s";
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private final CloudFoundryDeploymentProperties defaultDeploymentProperties;
@@ -171,18 +177,27 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
@Override
public Mono<GetApplicationResponse> get(GetApplicationRequest request) {
final String name = request.getName();
final String appName = request.getName();
return operationsUtils.getOperations(request.getProperties())
.flatMap(cfOperations -> cfOperations.applications()
.get(org.cloudfoundry.operations.applications.GetApplicationRequest.builder().name(name).build())
.doOnRequest(l -> LOG.debug("Getting application {}", name))
.doOnSuccess(response -> LOG.info("Success getting application {} id: {}", name, response.getId()))
.doOnError(e -> LOG.warn(String.format("Error getting application %s: %s", name, e.getMessage())))
.get(org.cloudfoundry.operations.applications.GetApplicationRequest.builder()
.name(appName)
.build())
.doOnRequest(l -> {
LOG.info("Getting application. appName={}", appName);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnSuccess(response -> {
LOG.info("Success getting application. appName={}", appName);
LOG.debug(RESPONSE_LOG_TEMPLATE, response);
})
.doOnError(e -> LOG.error(String.format("Error getting application. appName=%s, " + ERROR_LOG_TEMPLATE,
appName, e.getMessage()), e))
.map(ApplicationDetail::getId)
.flatMap(id ->
client.applicationsV2()
.summary(SummaryApplicationRequest.builder().applicationId(id).build())))
.flatMap(id -> client.applicationsV2().summary(SummaryApplicationRequest.builder()
.applicationId(id)
.build())))
.flatMap(summary -> Flux.fromIterable(summary.getServices())
.map(org.cloudfoundry.client.v2.serviceinstances.ServiceInstance::getName)
.collectList()
@@ -192,9 +207,16 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.services(services)
.environment(summary.getEnvironmentJsons())
.build()))
.doOnRequest(l -> LOG.debug("Getting application summary for {}", name))
.doOnSuccess(item -> LOG.info("Success getting application summary for {}", name))
.doOnError(error -> LOG.error("Failed to get application summary for {}", name));
.doOnRequest(l -> {
LOG.info("Getting application summary. appName={}", appName);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnSuccess(response -> {
LOG.info("Success getting application summary. appName={}", appName);
LOG.debug(RESPONSE_LOG_TEMPLATE, response);
})
.doOnError(e -> LOG.error(String.format("Error getting application summary. appName=%s, " +
ERROR_LOG_TEMPLATE, appName, e.getMessage()), e));
}
@Override
@@ -211,16 +233,13 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
return pushApplication(request, deploymentProperties, appResource)
.timeout(Duration.ofSeconds(this.defaultDeploymentProperties.getApiTimeout()))
.doOnSuccess(item -> LOG.info("Successfully deployed {}", appName))
.doOnError(error -> {
if (httpStatusNotFoundPredicate().test(error)) {
if (LOG.isWarnEnabled()) {
LOG.warn(
"Unable to deploy application. It may have been destroyed before start completed: " + error
.getMessage());
}
.doOnError(e -> {
if (httpStatusNotFoundPredicate().test(e)) {
LOG.error(String.format("Unable to deploy application. It may have been destroyed before " +
"start completed. " + ERROR_LOG_TEMPLATE, e.getMessage()), e);
}
else {
logError(String.format("Failed to deploy %s", appName)).accept(error);
logError(String.format("Error deploying application. appName=%s", appName)).accept(e);
}
})
.thenReturn(DeployApplicationResponse.builder()
@@ -230,9 +249,12 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
@Override
public Mono<UpdateApplicationResponse> update(UpdateApplicationRequest request) {
final String name = request.getName();
final String appName = request.getName();
return get(GetApplicationRequest.builder().name(name).properties(request.getProperties()).build())
return get(GetApplicationRequest.builder()
.name(appName)
.properties(request.getProperties())
.build())
.flatMap(response -> bindNewServices(response, request.getServices(), request.getProperties()))
.flatMap(applicationId -> {
if (request.getProperties().containsKey("routes")) {
@@ -261,10 +283,16 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
})
.map(CreateDeploymentResponse::getId)
.flatMap(this::waitForDeploymentDeployed)
.doOnRequest(l -> LOG.debug("Updating application {}", name))
.doOnSuccess(item -> LOG.info("Successfully updated application {}", name))
.doOnError(error -> LOG.error("Failed to update application {}", name))
.thenReturn(UpdateApplicationResponse.builder().name(name).build());
.doOnRequest(l -> {
LOG.info("Updating application. appName={}", appName);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnSuccess(response -> {
LOG.info("Success updating application. appName={}", appName);
LOG.debug(RESPONSE_LOG_TEMPLATE, response);
})
.doOnError(e -> LOG.error(String.format("Error updating application. appName=%s", appName), e))
.thenReturn(UpdateApplicationResponse.builder().name(appName).build());
}
private Mono<String> bindNewServices(GetApplicationResponse deployedApp, List<String> services,
@@ -278,17 +306,19 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
return Mono.just(id);
}
String name = deployedApp.getName();
String appName = deployedApp.getName();
return operationsUtils.getOperations(properties)
.flatMapMany(cfOperations -> Flux.fromIterable(servicesToBind)
.flatMap(service -> cfOperations.services()
.bind(BindServiceInstanceRequest.builder()
.applicationName(name)
.serviceInstanceName(service)
.build())
.doOnRequest(l -> LOG.debug("Binding application {} to service {}", name, service))
.doOnNext(item -> LOG.info("Successfully bind application {} to service {}", name, service))
.doOnError(error -> LOG.error("Failed to bind application {} to service {}", name, service))))
.flatMap(service -> cfOperations.services().bind(BindServiceInstanceRequest.builder()
.applicationName(appName)
.serviceInstanceName(service)
.build())
.doOnRequest(
l -> LOG.info("Binding application to service. appName={}, serviceName={}", appName, service))
.doOnNext(v -> LOG.info("Success binding application to service. appName={}, service={}", appName,
service))
.doOnError(e -> LOG.error(String.format("Error binding application to service. appName=%s, " +
"service=%s", appName, service), e))))
.then()
.thenReturn(id);
}
@@ -324,8 +354,8 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
return Mono.just(routes)
.zipWith(operationsUtils.getOperations(properties)
.map(cfOperations -> cfOperations.domains().list())
.flatMap(domains -> domains.collectMap(Domain::getName)))
.map(cfOperations -> cfOperations.domains().list())
.flatMap(domains -> domains.collectMap(Domain::getName)))
.zipWith(getSpaceId(properties))
.flatMapMany(routesDomainsAndSpace -> {
List<String[]> routesComponents = routesDomainsAndSpace.getT1().getT1();
@@ -334,8 +364,10 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
return Flux.fromStream(routesComponents.stream()
.map(route -> new String[] {route[0], domainsByName.get(route[1]).getId()}))
.flatMap(hostAndDomainId -> associateHostForDomain(applicationId, hostAndDomainId[0], hostAndDomainId[1], spaceId));
})
.flatMap(
hostAndDomainId -> associateHostForDomain(applicationId, hostAndDomainId[0], hostAndDomainId[1],
spaceId));
})
.then(Mono.just(applicationId));
}
@@ -347,7 +379,7 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.host(host)
.build())
.map(response -> response.getMetadata().getId())
.doOnError(error -> LOG.info("Host was already associated: " + host))
.doOnError(error -> LOG.info("Host was already associated. host={}", host))
.onErrorResume(e -> Mono.empty())
.flatMap(routeId -> client.applicationsV2().associateRoute(AssociateApplicationRouteRequest.builder()
.applicationId(applicationId)
@@ -402,10 +434,13 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.build())
.filter(p -> p.getState().equals(DeploymentState.DEPLOYED))
.repeatWhenEmpty(getExponentialBackOff())
.doOnRequest(l -> LOG.debug("Waiting for deployment deployed {}", deploymentId))
.doOnSuccess(response -> LOG.info("Deployment deployed {}", deploymentId))
.doOnError(e -> LOG
.warn(String.format("Error waiting for deployment deployed %s: %s", deploymentId, e.getMessage())));
.doOnRequest(l -> LOG.debug("Waiting for deployment to complete. deploymentId={}", deploymentId))
.doOnSuccess(response -> {
LOG.info("Success waiting for deployment to complete. deploymentId={}", deploymentId);
LOG.debug(RESPONSE_LOG_TEMPLATE, response);
})
.doOnError(e -> LOG.error(String.format("Error waiting for deployment to complete. deploymentId=%s, " +
ERROR_LOG_TEMPLATE, deploymentId, e.getMessage()), e));
}
private Mono<CreateDeploymentResponse> createDeployment(String dropletId, String applicationId) {
@@ -423,21 +458,28 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.build()
).build())
.build())
.doOnRequest(l -> LOG.debug("Creating deployment for application {}", applicationId))
.doOnSuccess(response -> LOG.info("Created deployment for application {}", applicationId))
.doOnError(e -> LOG.warn(
String.format("Error creating deployment for application %s: %s", applicationId, e.getMessage())));
.doOnRequest(l -> LOG.debug("Creating deployment for application. applicationId={}", applicationId))
.doOnSuccess(response -> {
LOG.info("Success creating deployment for application. applicationId={}", applicationId);
LOG.debug(RESPONSE_LOG_TEMPLATE, response);
})
.doOnError(e -> LOG.error(String.format("Error creating deployment for application. applicationId=%s, " +
ERROR_LOG_TEMPLATE, applicationId, e.getMessage()), e));
}
private Mono<GetBuildResponse> waitForBuildStaged(String buildId) {
return this.client
.builds().get(GetBuildRequest.builder().buildId(buildId).build())
return this.client.builds().get(GetBuildRequest.builder()
.buildId(buildId)
.build())
.filter(p -> p.getState().equals(BuildState.STAGED))
.repeatWhenEmpty(getExponentialBackOff())
.doOnRequest(l -> LOG.debug("Waiting for build staged {}", buildId))
.doOnSuccess(response -> LOG.info("Build staged {}", buildId))
.doOnError(
e -> LOG.warn(String.format("Error waiting for build staged %s: %s", buildId, e.getMessage())));
.doOnRequest(l -> LOG.debug("Waiting for build to stage. buildId={}", buildId))
.doOnSuccess(response -> {
LOG.info("Success waiting for build to stage. buildId={}", buildId);
LOG.debug(RESPONSE_LOG_TEMPLATE, response);
})
.doOnError(e -> LOG.error(String.format("Error waiting for build to stage. buildId=%s, " +
ERROR_LOG_TEMPLATE, buildId, e.getMessage()), e));
}
private Mono<String> createBuildForPackage(String packageId) {
@@ -448,10 +490,13 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.getPackage(Relationship.builder().id(packageId).build())
.build())
.map(CreateBuildResponse::getId)
.doOnRequest(l -> LOG.debug("Creating build for package {}", packageId))
.doOnSuccess(response -> LOG.info("Created build for package {}", packageId))
.doOnError(
e -> LOG.warn(String.format("Error creating build package %s: %s", packageId, e.getMessage())));
.doOnRequest(l -> LOG.debug("Creating build for package. packageId={}", packageId))
.doOnSuccess(response -> {
LOG.info("Success creating build for package. packageId={}", packageId);
LOG.debug(RESPONSE_LOG_TEMPLATE, response);
})
.doOnError(e -> LOG.error(String.format("Error creating build package. packageId=%s, " +
ERROR_LOG_TEMPLATE, packageId, e.getMessage()), e));
}
private Mono<GetPackageResponse> waitForPackageReady(String packageId) {
@@ -460,10 +505,13 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.get(GetPackageRequest.builder().packageId(packageId).build())
.filter(p -> p.getState().equals(PackageState.READY))
.repeatWhenEmpty(getExponentialBackOff())
.doOnRequest(l -> LOG.debug("Waiting for package ready {}", packageId))
.doOnSuccess(response -> LOG.info("Package ready {}", packageId))
.doOnError(
e -> LOG.warn(String.format("Error waiting for package ready %s: %s", packageId, e.getMessage())));
.doOnRequest(l -> LOG.debug("Waiting for package ready. packageId={}", packageId))
.doOnSuccess(response -> {
LOG.info("Success waiting for package ready. packageId={}", packageId);
LOG.debug(RESPONSE_LOG_TEMPLATE, response);
})
.doOnError(e -> LOG.error(String.format("Error waiting for package ready. packageId=%s, " +
ERROR_LOG_TEMPLATE, packageId, e.getMessage()), e));
}
private Mono<UploadPackageResponse> uploadPackage(UpdateApplicationRequest request, String packageId) {
@@ -475,10 +523,16 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.packageId(packageId)
.bits(Paths.get(getAppResource(request.getPath()).getURI()))
.build())
.doOnRequest(l -> LOG.debug("Uploading package {}", packageId))
.doOnSuccess(response -> LOG.info("Package uploaded {}", packageId))
.doOnError(
e -> LOG.warn(String.format("Error uploading package %s: %s", packageId, e.getMessage())));
.doOnRequest(l -> {
LOG.info("Uploading package. packageId={}", packageId);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnSuccess(response -> {
LOG.info("Success uploading package. packageId={}", packageId);
LOG.debug(RESPONSE_LOG_TEMPLATE, response);
})
.doOnError(e -> LOG.error(String.format("Error uploading package. packageId=%s, " + ERROR_LOG_TEMPLATE,
packageId, e.getMessage()), e));
}
catch (IOException e) {
throw Exceptions.propagate(e);
@@ -514,10 +568,13 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.applicationId(applicationId)
.state(PackageState.READY)
.build())
.doOnRequest(l -> LOG.debug("Getting application package for application {}", applicationId))
.doOnSuccess(response -> LOG.info("Got application package for application {}", applicationId))
.doOnError(e -> LOG.warn(String
.format("Error getting application package for application %s: %s", applicationId, e.getMessage())))
.doOnRequest(l -> LOG.debug("Getting application package. applicationId={}", applicationId))
.doOnSuccess(response -> {
LOG.info("Success getting application package. applicationId={}", applicationId);
LOG.debug(RESPONSE_LOG_TEMPLATE, response);
})
.doOnError(e -> LOG.error(String.format("Error getting application package. applicationId=%s, " +
ERROR_LOG_TEMPLATE, applicationId, e.getMessage()), e))
.map(ListApplicationPackagesResponse::getResources)
.map(this::getLastUpdatedPackageId);
}
@@ -547,10 +604,13 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.build())
.type(PackageType.BITS)
.build())
.doOnRequest(l -> LOG.debug("Creating package for application {}", applicationId))
.doOnSuccess(response -> LOG.info("Created package for application {}", applicationId))
.doOnError(e -> LOG
.warn(String.format("Error creating package for application %s: %s", applicationId, e.getMessage())));
.doOnRequest(l -> LOG.debug("Creating package. applicationId={}", applicationId))
.doOnSuccess(response -> {
LOG.info("Success creating package. applicationId={}", applicationId);
LOG.debug(RESPONSE_LOG_TEMPLATE, response);
})
.doOnError(e -> LOG.error(String.format("Error creating package. applicationId=%s, " + ERROR_LOG_TEMPLATE,
applicationId, e.getMessage()), e));
}
private Mono<org.cloudfoundry.client.v2.applications.UpdateApplicationResponse> updateApplicationEnvironment(
@@ -565,24 +625,24 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.memory(memory(properties))
.putAllEnvironmentJsons(environmentVariables)
.build())
.doOnRequest(l -> LOG.debug("Updating environment for application {}", applicationId))
.doOnSuccess(response -> LOG.info("Updated environment for application {}", applicationId))
.doOnError(e -> LOG.warn(
String.format("Error Updating environment for application %s: %s", applicationId, e.getMessage())));
.doOnRequest(l -> LOG.debug("Updating environment. applicationId={}", applicationId))
.doOnSuccess(response -> {
LOG.info("Success updating environment. applicationId={}", applicationId);
LOG.debug(RESPONSE_LOG_TEMPLATE, response);
})
.doOnError(e -> LOG.error(String.format("Error updating environment. applicationId=%s, " +
ERROR_LOG_TEMPLATE, applicationId, e.getMessage()), e));
}
private Function<Flux<Long>, Publisher<?>> getExponentialBackOff() {
return DelayUtils.exponentialBackOff(Duration.ofSeconds(2), Duration.ofMinutes(5), Duration.ofMinutes(10));
}
private Mono<Void> pushApplication(DeployApplicationRequest request,
Map<String, String> deploymentProperties,
private Mono<Void> pushApplication(DeployApplicationRequest request, Map<String, String> deploymentProperties,
Resource appResource) {
ApplicationManifest manifest = buildAppManifest(request, deploymentProperties, appResource);
if (LOG.isDebugEnabled()) {
LOG.debug("Pushing manifest" + manifest.toString());
}
LOG.debug("Pushing app manifest. manifest={}", manifest.toString());
PushApplicationManifestRequest applicationManifestRequest =
PushApplicationManifestRequest.builder()
@@ -602,9 +662,9 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
}
return requestPushApplication
.doOnSuccess(v -> LOG.info("Done uploading bits for {}", request.getName()))
.doOnError(e -> LOG.error(
String.format("Error creating app %s. Exception Message %s", request.getName(), e.getMessage())));
.doOnSuccess(v -> LOG.info("Success pushing app manifest. appName={}", request.getName()))
.doOnError(e -> LOG.error(String.format("Error pushing app manifest. appName=%s, " + ERROR_LOG_TEMPLATE,
request.getName(), e.getMessage()), e));
}
private ApplicationManifest buildAppManifest(DeployApplicationRequest request,
@@ -669,9 +729,12 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.organizationId(orgId)
.name(spaceName)
.build())
.doOnSuccess(response -> LOG.info("Created space {}", spaceName))
.doOnError(
e -> LOG.warn(String.format("Error creating space %s: %s", spaceName, e.getMessage())))
.doOnSuccess(response -> {
LOG.info("Success creating space. spaceName={}", spaceName);
LOG.debug(RESPONSE_LOG_TEMPLATE, response);
})
.doOnError(e -> LOG.error(String.format("Error creating space. spaceName=%s, " +
ERROR_LOG_TEMPLATE, spaceName, e.getMessage()), e))
.map(response -> response.getMetadata().getId())
.flatMap(spaceId -> addSpaceDeveloperRoleForCurrentUser(orgName, spaceName, spaceId)
.thenReturn(spaceId)))));
@@ -684,9 +747,12 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.spaceId(spaceId)
.developerId(targetProperties.getClientId())
.build())
.doOnSuccess(v -> LOG.info("Set space developer role for space {}", spaceName))
.doOnError(e -> LOG.warn(String
.format("Error setting space developer role for space %s: %s", spaceName, e.getMessage())))
.doOnSuccess(response -> {
LOG.info("Setting space developer role. spaceName={}", spaceName);
LOG.debug(RESPONSE_LOG_TEMPLATE, response);
})
.doOnError(e -> LOG.error(String.format("Error setting space developer role. spaceName=%s, " +
ERROR_LOG_TEMPLATE, spaceName, e.getMessage()), e))
.then();
}
else if (StringUtils.hasText(targetProperties.getUsername())) {
@@ -696,9 +762,9 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.spaceName(spaceName)
.username(targetProperties.getUsername())
.build())
.doOnSuccess(v -> LOG.info("Set space developer role for space {}", spaceName))
.doOnError(e -> LOG.warn(String
.format("Error setting space developer role for space %s: %s", spaceName, e.getMessage())));
.doOnSuccess(v -> LOG.info("Seting space developer role. spaceName={}", spaceName))
.doOnError(e -> LOG.error(String.format("Error setting space developer role. spaceName=%s, " +
ERROR_LOG_TEMPLATE, spaceName, e.getMessage()), e));
}
return Mono.empty();
});
@@ -713,7 +779,7 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
@Override
public Mono<UndeployApplicationResponse> undeploy(UndeployApplicationRequest request) {
LOG.trace("Undeploying application: request={}", request);
LOG.trace("Undeploying application. request={}", request);
String appName = request.getName();
Map<String, String> deploymentProperties = request.getProperties();
@@ -730,8 +796,8 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
return requestDeleteApplication
.timeout(Duration.ofSeconds(this.defaultDeploymentProperties.getApiTimeout()))
.doOnSuccess(v -> LOG.info("Successfully undeployed app {}", appName))
.doOnError(logError(String.format("Failed to undeploy app %s", appName)))
.doOnSuccess(v -> LOG.info("Success undeploying application. appName={}", appName))
.doOnError(logError(String.format("Error undeploying application. appName=%s", appName)))
.then(Mono.just(UndeployApplicationResponse.builder()
.name(appName)
.build()));
@@ -747,27 +813,30 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
private Mono<Void> deleteApplicationInSpace(String name, String spaceName) {
return getSpaceId(spaceName)
.doOnError(error -> LOG.warn("Unable to get space name: {} ", spaceName))
.doOnError(e -> LOG.error(String.format("Unable to get space name. spaceName=%s, " + ERROR_LOG_TEMPLATE,
spaceName, e.getMessage()), e))
.then(operationsUtils.getOperationsForSpace(spaceName))
.flatMap(cfOperations -> cfOperations.applications().delete(DeleteApplicationRequest.builder()
.deleteRoutes(this.defaultDeploymentProperties.isDeleteRoutes())
.name(name)
.build())
.doOnError(error -> LOG.warn("Unable to delete application: {} ", name)))
.doOnError(e -> LOG.error(String.format("Error deleting application. appName=%s, " + ERROR_LOG_TEMPLATE,
name, e.getMessage()), e)))
.onErrorResume(e -> Mono.empty());
}
private Mono<Void> deleteSpace(String spaceName) {
return getSpaceId(spaceName)
.doOnError(error -> LOG.warn("Unable to get space name: {} ", spaceName))
.doOnError(e -> LOG.error(String.format("Unable to get space name. spaceName=%s, " + ERROR_LOG_TEMPLATE,
spaceName, e.getMessage()), e))
.flatMap(spaceId -> this.client.spaces()
.delete(DeleteSpaceRequest.builder()
.spaceId(spaceId)
.recursive(true)
.build())
.then())
.doOnError(exception -> LOG.debug("Error deleting space {} with error '{}'",
spaceName, exception.getMessage()))
.doOnError(e -> LOG.error(String.format("Error deleting space. spaceName=%s, " + ERROR_LOG_TEMPLATE,
spaceName, e.getMessage()), e))
.onErrorResume(e -> Mono.empty());
}
@@ -1113,8 +1182,10 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
}
return requestDeleteServiceInstance
.doOnSuccess(v -> LOG.info("Successfully deleted service instance {}", serviceInstanceName))
.doOnError(logError(String.format("Failed to delete service instance %s", serviceInstanceName)))
.doOnSuccess(v -> LOG.info("Success deleting service instance. serviceInstanceName={}",
serviceInstanceName))
.doOnError(logError(String.format("Error deleting service instance. serviceInstanceName=%s",
serviceInstanceName)))
.thenReturn(DeleteServiceInstanceResponse.builder()
.name(serviceInstanceName)
.build());
@@ -1124,13 +1195,12 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
CloudFoundryOperations cloudFoundryOperations,
Map<String, String> deploymentProperties) {
return cloudFoundryOperations.services().deleteInstance(
org.cloudfoundry.operations.services.DeleteServiceInstanceRequest
.builder()
org.cloudfoundry.operations.services.DeleteServiceInstanceRequest.builder()
.name(serviceInstanceName)
.completionTimeout(apiPollingTimeout(deploymentProperties))
.build())
.doOnError(exception -> LOG.debug(String.format("Error deleting service instance %s with error '%s'",
serviceInstanceName, exception.getMessage()), exception))
.doOnError(e -> LOG.error(String.format("Error deleting service instance. serviceInstanceName=%s, " +
ERROR_LOG_TEMPLATE, serviceInstanceName, e.getMessage()), e))
.onErrorResume(e -> Mono.empty());
}
@@ -1140,8 +1210,8 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.getInstance(org.cloudfoundry.operations.services.GetServiceInstanceRequest.builder()
.name(serviceInstanceName)
.build())
.doOnError(exception -> LOG.debug("Error unbinding service instance {} with error '{}'",
serviceInstanceName, exception.getMessage()))
.doOnError(e -> LOG.error(String.format("Error getting service instance. serviceInstanceName=%s, " +
ERROR_LOG_TEMPLATE, serviceInstanceName, e.getMessage()), e))
.onErrorResume(e -> Mono.empty())
.map(ServiceInstance::getApplications)
.flatMap(applications -> Flux.fromIterable(applications)
@@ -1151,6 +1221,8 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.serviceInstanceName(serviceInstanceName)
.build())
)
.doOnError(e -> LOG.error(String.format("Error unbinding service instance. serviceInstanceName=%s, " +
ERROR_LOG_TEMPLATE, serviceInstanceName, e.getMessage()), e))
.onErrorResume(e -> Mono.empty())
.then(Mono.empty()));
}

View File

@@ -30,6 +30,8 @@ public class CloudFoundryAppManager implements AppManager {
private static final Logger LOG = LoggerFactory.getLogger(CloudFoundryAppManager.class);
private static final String REQUEST_LOG_TEMPLATE = "request={}";
private final CloudFoundryOperationsUtils operationsUtils;
public CloudFoundryAppManager(CloudFoundryOperationsUtils operationsUtils) {
@@ -45,9 +47,19 @@ public class CloudFoundryAppManager implements AppManager {
org.cloudfoundry.operations.applications.StartApplicationRequest.builder()
.name(appName)
.build())
.doOnRequest(l -> LOG.debug("Starting application {}", appName))
.doOnSuccess(item -> LOG.info("Successfully started application {}", appName))
.doOnError(error -> LOG.error("Failed to start application {}", appName)))));
.doOnRequest(l -> {
LOG.info("Starting application. appName={}", appName);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnSuccess(v -> {
LOG.info("Success starting application. appName={}", appName);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnError(e -> {
LOG.error(String.format("Error starting application. appName=%s, error=%s", appName,
e.getMessage()), e);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
}))));
}
@Override
@@ -59,9 +71,19 @@ public class CloudFoundryAppManager implements AppManager {
org.cloudfoundry.operations.applications.StopApplicationRequest.builder()
.name(appName)
.build())
.doOnRequest(l -> LOG.debug("Stopping application {}", appName))
.doOnSuccess(item -> LOG.info("Successfully stopped application {}", appName))
.doOnError(error -> LOG.error("Failed to stop application {}", appName)))));
.doOnRequest(l -> {
LOG.info("Stopping application. appName={}", appName);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnSuccess(v -> {
LOG.info("Success stopping application. appName={}", appName);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnError(e -> {
LOG.error(String.format("Error stopping application. appName=%s, error=%s", appName,
e.getMessage()), e);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
}))));
}
@Override
@@ -73,9 +95,19 @@ public class CloudFoundryAppManager implements AppManager {
org.cloudfoundry.operations.applications.RestartApplicationRequest.builder()
.name(appName)
.build())
.doOnRequest(l -> LOG.debug("Restarting application {}", appName))
.doOnSuccess(item -> LOG.info("Successfully restarted application {}", appName))
.doOnError(error -> LOG.error("Failed to restart application {}", appName)))));
.doOnRequest(l -> {
LOG.info("Restarting application. appName={}", appName);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnSuccess(v -> {
LOG.info("Success restarting application. appName={}", appName);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnError(e -> {
LOG.error(String.format("Error restarting application. appName=%s, error=%s", appName,
e.getMessage()), e);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
}))));
}
@Override
@@ -87,9 +119,19 @@ public class CloudFoundryAppManager implements AppManager {
org.cloudfoundry.operations.applications.RestageApplicationRequest.builder()
.name(appName)
.build())
.doOnRequest(l -> LOG.debug("Restaging application {}", appName))
.doOnSuccess(item -> LOG.info("Successfully restaged application {}", appName))
.doOnError(error -> LOG.error("Failed to restage application {}", appName)))));
.doOnRequest(l -> {
LOG.info("Restaging application. appName={}", appName);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnSuccess(v -> {
LOG.info("Success restaging application. appName={}", appName);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
})
.doOnError(e -> {
LOG.error(String.format("Error restaging application. appName=%s, error=%s", appName,
e.getMessage()), e);
LOG.debug(REQUEST_LOG_TEMPLATE, request);
}))));
}
}