diff --git a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/Messages.java b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/Messages.java index 73e8e26094..47ceabaf47 100644 --- a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/Messages.java +++ b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/Messages.java @@ -183,7 +183,9 @@ public class Messages { public static final String ERROR_WHILE_POLLING_SERVICE_BINDING_OPERATIONS_BETWEEN_APP_0_AND_SERVICE_INSTANCE_1 = "Error while polling service binding operations between app: \"{0}\" and service instance \"{1}\""; public static final String ERROR_WHILE_CHECKING_SERVICE_BINDING_OPERATIONS_BETWEEN_APP_0_AND_SERVICE_INSTANCE_1 = "Error while checking service binding operations between app: \"{0}\" and service instance \"{1}\""; public static final String ERROR_WHILE_CHECKING_SERVICE_BINDING_OPERATIONS_0 = "Error while checking service binding operations for service binding: \"{0}\""; - public static final String ASYNC_OPERATION_FOR_SERVICE_BINDING_FAILED_WITH = "Async operation for service binding between app \"{0}\" and service instance \"{1}\" failed with \"{2}\""; + public static final String ASYNC_OPERATION_FOR_SERVICE_BINDING_FAILED_WITH = "Async operation for service binding between app \"{0}\" and service instance \"{1}\" with offering \"{2}\" and plan \"{3}\" failed with \"{4}\""; + public static final String ASYNC_OPERATION_FOR_USER_PROVIDED_SERVICE_BINDING_FAILED_WITH = "Async operation for service binding between app \"{0}\" and user-provided service instance \"{1}\" failed with \"{2}\""; + public static final String ASYNC_OPERATION_FOR_SERVICE_BINDING_FAILED_INSTANCE_MISSING = "Async operation for service binding between app \"{0}\" and service instance \"{1}\" failed: Instance not found. Cause: {2}"; public static final String ASYNC_OPERATION_FOR_SERVICE_KEY_FAILED_WITH = "Async operation for service key of service instance \"{0}\" failed with \"{1}\""; public static final String ASYNC_OPERATION_FOR_OPTIONAL_SERVICE_KEY_FAILED_WITH = "Async operation for service key of optional service instance \"{0}\" failed with \"{1}\""; public static final String ASYNC_OPERATION_FOR_SERVICE_BINDING_FOR_OPTIONAL_SERVICE_FAILED_WITH = "Async operation for service binding for optional service between app \"{0}\" and service instance \"{1}\" failed with \"{2}\""; diff --git a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollServiceBindingUnbindingOperationBaseExecution.java b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollServiceBindingUnbindingOperationBaseExecution.java index 1fd21af746..853fd94bbb 100644 --- a/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollServiceBindingUnbindingOperationBaseExecution.java +++ b/multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/PollServiceBindingUnbindingOperationBaseExecution.java @@ -1,16 +1,22 @@ package org.cloudfoundry.multiapps.controller.process.steps; +import java.text.MessageFormat; import java.util.List; +import java.util.Optional; import java.util.function.Consumer; +import org.cloudfoundry.multiapps.controller.client.facade.CloudControllerClient; import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudApplication; import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudAsyncJob; +import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudServiceInstance; import org.cloudfoundry.multiapps.controller.client.lib.domain.CloudServiceInstanceExtended; import org.cloudfoundry.multiapps.controller.process.Messages; import org.cloudfoundry.multiapps.controller.process.variables.Variables; public abstract class PollServiceBindingUnbindingOperationBaseExecution extends PollOperationBaseExecution { + private static final String MISSING_VALUE_PLACEHOLDER = "missing"; + @Override protected boolean isOptional(ProcessContext context) { List servicesToBind = context.getVariable(Variables.SERVICES_TO_BIND); @@ -35,9 +41,39 @@ protected Consumer getOnCompleteHandler(ProcessContext context) { protected Consumer getOnErrorHandler(ProcessContext context) { CloudApplication app = context.getVariable(Variables.APP_TO_PROCESS); String serviceInstanceName = context.getVariable(Variables.SERVICE_TO_UNBIND_BIND); + + CloudControllerClient client = context.getControllerClient(); + CloudServiceInstance serviceInstance = client.getServiceInstance(serviceInstanceName, false); + return serviceBindingJob -> context.getStepLogger() - .error(Messages.ASYNC_OPERATION_FOR_SERVICE_BINDING_FAILED_WITH, app.getName(), - serviceInstanceName, serviceBindingJob.getErrors()); + .error(buildErrorMessage(app, serviceInstance, serviceInstanceName, serviceBindingJob)); + + } + + private String buildErrorMessage(CloudApplication app, CloudServiceInstance serviceInstance, String serviceInstanceName, + CloudAsyncJob serviceBindingJob) { + + if (serviceInstance == null) { + return MessageFormat.format(Messages.ASYNC_OPERATION_FOR_SERVICE_BINDING_FAILED_INSTANCE_MISSING, app.getName(), + serviceInstanceName, serviceBindingJob.getErrors()); + } + + if (serviceInstance.isUserProvided()) { + return MessageFormat.format(Messages.ASYNC_OPERATION_FOR_USER_PROVIDED_SERVICE_BINDING_FAILED_WITH, app.getName(), + serviceInstanceName, serviceBindingJob.getErrors()); + } + + String serviceOffering = getValueOrMissing(serviceInstance.getLabel()); + String servicePlan = getValueOrMissing(serviceInstance.getPlan()); + + return MessageFormat.format(Messages.ASYNC_OPERATION_FOR_SERVICE_BINDING_FAILED_WITH, app.getName(), serviceInstanceName, + serviceOffering, servicePlan, serviceBindingJob.getErrors()); + + } + + private String getValueOrMissing(String value) { + return Optional.ofNullable(value) + .orElse(MISSING_VALUE_PLACEHOLDER); } @Override