Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}\"";
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CloudServiceInstanceExtended> servicesToBind = context.getVariable(Variables.SERVICES_TO_BIND);
Expand All @@ -35,9 +41,39 @@ protected Consumer<CloudAsyncJob> getOnCompleteHandler(ProcessContext context) {
protected Consumer<CloudAsyncJob> 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
Expand Down
Loading