Skip to content

Commit 98e3c99

Browse files
author
I562548
committed
change to not fail update when the service is optional
LMCROSSITXSADEPLOY-2784
1 parent 0573010 commit 98e3c99

14 files changed

+547
-75
lines changed

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/Messages.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ public class Messages {
202202
public static final String COULD_NOT_BIND_OPTIONAL_SERVICE_TO_APP = "Could not bind optional service \"{0}\" to application \"{1}\"";
203203
public static final String COULD_NOT_UNBIND_OPTIONAL_SERVICE_TO_APP = "Could not unbind optional service \"{0}\" to application \"{1}\"";
204204
public static final String COULD_NOT_CREATE_OPTIONAL_SERVICE = "Could not create optional service \"{0}\"";
205+
public static final String COULD_NOT_UPDATE_TAGS_OF_OPTIONAL_SERVICE = "Could not update tags of optional service \"{0}\" : {1}";
206+
public static final String COULD_NOT_UPDATE_METADATA_OF_OPTIONAL_SERVICE = "Could not update metadata of optional service \"{0}\" : {1}";
207+
public static final String COULD_NOT_UPDATE_PARAMETERS_OPTIONAL_SERVICE = "Could not update parameters of optional service \"{0}\" : {1}";
208+
public static final String COULD_NOT_UPDATE_PLAN_OPTIONAL_SERVICE = "Could not update plan of optional service \"{0}\" : {1}";
209+
public static final String COULD_NOT_UPDATE_SYSLOG_DRAIN_URL_OPTIONAL_SERVICE = "Could not update syslog drain url of optional service \"{0}\" : {1}";
205210
public static final String COULD_NOT_GET_SERVICE_KEYS_FOR_OPTIONAL_SERVICE = "Could not get service keys for optional service \"{0}\"";
206211
public static final String DEFAULT_FAILED_OPERATION_DESCRIPTION = "The service broker returned an error with no description!";
207212
public static final String ERROR_DURING_CLEAN_UP_0 = "Error during clean-up: {0}";

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/CreateServiceStep.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
import org.springframework.util.Assert;
2020

2121
import com.sap.cloudfoundry.client.facade.CloudControllerClient;
22-
import com.sap.cloudfoundry.client.facade.CloudControllerException;
2322
import com.sap.cloudfoundry.client.facade.CloudOperationException;
24-
import com.sap.cloudfoundry.client.facade.CloudServiceBrokerException;
2523
import com.sap.cloudfoundry.client.facade.domain.CloudServiceInstance;
2624
import com.sap.cloudfoundry.client.facade.domain.ServiceOperation;
2725

@@ -44,7 +42,12 @@ protected OperationExecutionState executeOperation(ProcessContext context, Cloud
4442
if (operationExecutionState.isPresent()) {
4543
return operationExecutionState.get();
4644
}
47-
processServiceCreationFailure(context, serviceInstance, e);
45+
String exceptionDescription = MessageFormat.format(Messages.COULD_NOT_CREATE_OPTIONAL_SERVICE, serviceInstance.getName());
46+
CloudOperationException cloudOperationException = new CloudOperationException(e.getStatusCode(),
47+
e.getStatusText(),
48+
exceptionDescription);
49+
50+
processServiceActionFailure(context, serviceInstance, cloudOperationException);
4851
}
4952
return OperationExecutionState.FINISHED;
5053
}
@@ -74,21 +77,6 @@ private void setServiceGuid(ProcessContext context, CloudServiceInstanceExtended
7477
new DynamicResolvableParametersContextUpdater(context).updateServiceGuid(serviceInstance);
7578
}
7679

77-
private void processServiceCreationFailure(ProcessContext context, CloudServiceInstanceExtended serviceInstance,
78-
CloudOperationException e) {
79-
if (!serviceInstance.isOptional()) {
80-
String detailedDescription = MessageFormat.format(Messages.ERROR_CREATING_SERVICE, serviceInstance.getName(),
81-
serviceInstance.getLabel(), serviceInstance.getPlan(), e.getDescription());
82-
if (e.getStatusCode() == HttpStatus.BAD_GATEWAY) {
83-
context.setVariable(Variables.SERVICE_OFFERING, serviceInstance.getLabel());
84-
throw new CloudServiceBrokerException(e.getStatusCode(), e.getStatusText(), detailedDescription);
85-
}
86-
throw new CloudControllerException(e.getStatusCode(), e.getStatusText(), detailedDescription);
87-
}
88-
getStepLogger().warn(MessageFormat.format(Messages.COULD_NOT_CREATE_OPTIONAL_SERVICE, serviceInstance.getName()), e,
89-
ExceptionMessageTailMapper.map(configuration, CloudComponents.SERVICE_BROKERS, serviceInstance.getLabel()));
90-
}
91-
9280
private Optional<OperationExecutionState> getServiceInstanceStateIfCreated(CloudControllerClient controllerClient,
9381
CloudServiceInstanceExtended serviceInstance,
9482
CloudOperationException e) {

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/ServiceStep.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import javax.inject.Inject;
88

9+
import com.sap.cloudfoundry.client.facade.CloudControllerException;
10+
import com.sap.cloudfoundry.client.facade.CloudServiceBrokerException;
911
import org.cloudfoundry.multiapps.common.util.JsonUtil;
1012
import org.cloudfoundry.multiapps.controller.client.lib.domain.CloudServiceInstanceExtended;
1113
import org.cloudfoundry.multiapps.controller.core.util.OperationExecutionState;
@@ -17,6 +19,7 @@
1719
import com.sap.cloudfoundry.client.facade.CloudControllerClient;
1820
import com.sap.cloudfoundry.client.facade.CloudOperationException;
1921
import com.sap.cloudfoundry.client.facade.domain.ServiceOperation;
22+
import org.springframework.http.HttpStatus;
2023

2124
public abstract class ServiceStep extends AsyncFlowableStep {
2225

@@ -61,6 +64,20 @@ private OperationExecutionState executeOperationAndHandleExceptions(ProcessConte
6164
protected abstract OperationExecutionState executeOperation(ProcessContext context, CloudControllerClient controllerClient,
6265
CloudServiceInstanceExtended service);
6366

67+
protected void processServiceActionFailure(ProcessContext context, CloudServiceInstanceExtended serviceInstance,
68+
CloudOperationException e) {
69+
if (!serviceInstance.isOptional()) {
70+
String detailedDescription = MessageFormat.format(Messages.ERROR_CREATING_SERVICE, serviceInstance.getName(),
71+
serviceInstance.getLabel(), serviceInstance.getPlan(), e.getDescription());
72+
if (e.getStatusCode() == HttpStatus.BAD_GATEWAY) {
73+
context.setVariable(Variables.SERVICE_OFFERING, serviceInstance.getLabel());
74+
throw new CloudServiceBrokerException(e.getStatusCode(), e.getStatusText(), detailedDescription);
75+
}
76+
throw new CloudControllerException(e.getStatusCode(), e.getStatusText(), detailedDescription);
77+
}
78+
getStepLogger().warn(e.getDescription());
79+
}
80+
6481
protected abstract ServiceOperation.Type getOperationType();
6582

6683
protected ServiceOperationGetter getServiceOperationGetter() {

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/UpdateServiceMetadataStep.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.cloudfoundry.multiapps.controller.process.steps;
22

3+
import java.text.MessageFormat;
34
import java.util.Collections;
45
import java.util.List;
56
import java.util.UUID;
@@ -13,6 +14,7 @@
1314
import org.springframework.context.annotation.Scope;
1415

1516
import com.sap.cloudfoundry.client.facade.CloudControllerClient;
17+
import com.sap.cloudfoundry.client.facade.CloudOperationException;
1618
import com.sap.cloudfoundry.client.facade.domain.ServiceOperation;
1719

1820
@Named("updateServiceMetadataStep")
@@ -24,10 +26,21 @@ protected OperationExecutionState executeOperation(ProcessContext context, Cloud
2426
CloudServiceInstanceExtended service) {
2527
getStepLogger().debug(Messages.UPDATING_METADATA_OF_SERVICE_INSTANCE_0, service.getName(), service.getResourceName());
2628

27-
UUID serviceGuid = client.getRequiredServiceInstanceGuid(service.getName());
28-
client.updateServiceInstanceMetadata(serviceGuid, service.getV3Metadata());
29+
try {
30+
UUID serviceGuid = client.getRequiredServiceInstanceGuid(service.getName());
31+
client.updateServiceInstanceMetadata(serviceGuid, service.getV3Metadata());
32+
getStepLogger().debug(Messages.UPDATING_METADATA_OF_SERVICE_INSTANCE_0_DONE, service.getName());
33+
} catch (CloudOperationException e) {
34+
String exceptionDescription = MessageFormat.format(Messages.COULD_NOT_UPDATE_METADATA_OF_OPTIONAL_SERVICE, service.getName(),
35+
e.getDescription());
36+
CloudOperationException cloudOperationException = new CloudOperationException(e.getStatusCode(),
37+
e.getStatusText(),
38+
exceptionDescription);
39+
40+
processServiceActionFailure(context, service, cloudOperationException);
41+
return OperationExecutionState.FINISHED;
42+
}
2943

30-
getStepLogger().debug(Messages.UPDATING_METADATA_OF_SERVICE_INSTANCE_0_DONE, service.getName());
3144
return OperationExecutionState.EXECUTING;
3245
}
3346

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/UpdateServiceParametersStep.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.cloudfoundry.multiapps.controller.process.steps;
22

3+
import java.text.MessageFormat;
34
import java.util.Collections;
45
import java.util.List;
56

@@ -12,6 +13,7 @@
1213
import org.springframework.context.annotation.Scope;
1314

1415
import com.sap.cloudfoundry.client.facade.CloudControllerClient;
16+
import com.sap.cloudfoundry.client.facade.CloudOperationException;
1517
import com.sap.cloudfoundry.client.facade.domain.ServiceOperation;
1618

1719
@Named("updateServiceParametersStep")
@@ -27,9 +29,19 @@ protected OperationExecutionState executeOperation(ProcessContext context, Cloud
2729
}
2830
getStepLogger().info(Messages.UPDATING_SERVICE, service.getName());
2931

30-
client.updateServiceParameters(service.getName(), service.getCredentials());
31-
32-
getStepLogger().debug(Messages.SERVICE_UPDATED, service.getName());
32+
try {
33+
client.updateServiceParameters(service.getName(), service.getCredentials());
34+
getStepLogger().debug(Messages.SERVICE_UPDATED, service.getName());
35+
} catch (CloudOperationException e) {
36+
String exceptionDescription = MessageFormat.format(Messages.COULD_NOT_UPDATE_PARAMETERS_OPTIONAL_SERVICE, service.getName(),
37+
e.getDescription());
38+
CloudOperationException cloudOperationException = new CloudOperationException(e.getStatusCode(),
39+
e.getStatusText(),
40+
exceptionDescription);
41+
42+
processServiceActionFailure(context, service, cloudOperationException);
43+
return OperationExecutionState.FINISHED;
44+
}
3345

3446
return OperationExecutionState.EXECUTING;
3547
}

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/UpdateServicePlanStep.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.cloudfoundry.multiapps.controller.process.steps;
22

3+
import java.text.MessageFormat;
34
import java.util.Collections;
45
import java.util.List;
56

@@ -12,6 +13,7 @@
1213
import org.springframework.context.annotation.Scope;
1314

1415
import com.sap.cloudfoundry.client.facade.CloudControllerClient;
16+
import com.sap.cloudfoundry.client.facade.CloudOperationException;
1517
import com.sap.cloudfoundry.client.facade.domain.ServiceOperation;
1618

1719
@Named("updateServicePlanStep")
@@ -27,9 +29,20 @@ protected OperationExecutionState executeOperation(ProcessContext context, Cloud
2729
}
2830
getStepLogger().debug(Messages.UPDATING_SERVICE_0_WITH_PLAN_1, service.getName(), service.getPlan());
2931

30-
client.updateServicePlan(service.getName(), service.getPlan());
32+
try {
33+
client.updateServicePlan(service.getName(), service.getPlan());
34+
getStepLogger().debug(Messages.SERVICE_PLAN_FOR_SERVICE_0_UPDATED, service.getName());
35+
} catch (CloudOperationException e) {
36+
String exceptionDescription = MessageFormat.format(Messages.COULD_NOT_UPDATE_PLAN_OPTIONAL_SERVICE, service.getName(),
37+
e.getDescription());
38+
CloudOperationException cloudOperationException = new CloudOperationException(e.getStatusCode(),
39+
e.getStatusText(),
40+
exceptionDescription);
41+
42+
processServiceActionFailure(context, service, cloudOperationException);
43+
return OperationExecutionState.FINISHED;
44+
}
3145

32-
getStepLogger().debug(Messages.SERVICE_PLAN_FOR_SERVICE_0_UPDATED, service.getName());
3346
return OperationExecutionState.EXECUTING;
3447
}
3548

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/UpdateServiceSyslogDrainUrlStep.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.cloudfoundry.multiapps.controller.process.steps;
22

3+
import java.text.MessageFormat;
34
import java.util.Collections;
45
import java.util.List;
56

@@ -12,6 +13,7 @@
1213
import org.springframework.context.annotation.Scope;
1314

1415
import com.sap.cloudfoundry.client.facade.CloudControllerClient;
16+
import com.sap.cloudfoundry.client.facade.CloudOperationException;
1517
import com.sap.cloudfoundry.client.facade.domain.ServiceOperation;
1618
import com.sap.cloudfoundry.client.facade.domain.ServiceOperation.Type;
1719

@@ -28,9 +30,20 @@ protected OperationExecutionState executeOperation(ProcessContext context, Cloud
2830
}
2931
getStepLogger().info(Messages.UPDATING_SERVICE_SYSLOG_URL, service.getName());
3032

31-
client.updateServiceSyslogDrainUrl(service.getName(), service.getSyslogDrainUrl());
33+
try {
34+
client.updateServiceSyslogDrainUrl(service.getName(), service.getSyslogDrainUrl());
35+
getStepLogger().debug(Messages.SERVICE_SYSLOG_URL_UPDATED, service.getName());
36+
} catch (CloudOperationException e) {
37+
String exceptionDescription = MessageFormat.format(Messages.COULD_NOT_UPDATE_SYSLOG_DRAIN_URL_OPTIONAL_SERVICE,
38+
service.getName(), e.getDescription());
39+
CloudOperationException cloudOperationException = new CloudOperationException(e.getStatusCode(),
40+
e.getStatusText(),
41+
exceptionDescription);
42+
43+
processServiceActionFailure(context, service, cloudOperationException);
44+
return OperationExecutionState.FINISHED;
45+
}
3246

33-
getStepLogger().debug(Messages.SERVICE_SYSLOG_URL_UPDATED, service.getName());
3447
return OperationExecutionState.EXECUTING;
3548
}
3649

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/UpdateServiceTagsStep.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.cloudfoundry.multiapps.controller.process.steps;
22

3+
import java.text.MessageFormat;
34
import java.util.Collections;
45
import java.util.List;
56

@@ -12,6 +13,7 @@
1213
import org.springframework.context.annotation.Scope;
1314

1415
import com.sap.cloudfoundry.client.facade.CloudControllerClient;
16+
import com.sap.cloudfoundry.client.facade.CloudOperationException;
1517
import com.sap.cloudfoundry.client.facade.domain.ServiceOperation;
1618

1719
@Named("updateServiceTagsStep")
@@ -27,9 +29,20 @@ protected OperationExecutionState executeOperation(ProcessContext context, Cloud
2729
}
2830
getStepLogger().info(Messages.UPDATING_SERVICE_TAGS, service.getName());
2931

30-
client.updateServiceTags(service.getName(), service.getTags());
32+
try {
33+
client.updateServiceTags(service.getName(), service.getTags());
34+
getStepLogger().debug(Messages.SERVICE_TAGS_UPDATED, service.getName());
35+
} catch (CloudOperationException e) {
36+
String exceptionDescription = MessageFormat.format(Messages.COULD_NOT_UPDATE_TAGS_OF_OPTIONAL_SERVICE, service.getName(),
37+
e.getDescription());
38+
CloudOperationException cloudOperationException = new CloudOperationException(e.getStatusCode(),
39+
e.getStatusText(),
40+
exceptionDescription);
41+
42+
processServiceActionFailure(context, service, cloudOperationException);
43+
return OperationExecutionState.FINISHED;
44+
}
3145

32-
getStepLogger().debug(Messages.SERVICE_TAGS_UPDATED, service.getName());
3346
return OperationExecutionState.EXECUTING;
3447
}
3548

multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/SyncFlowableStepTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
package org.cloudfoundry.multiapps.controller.process.steps;
22

3+
import static java.lang.Boolean.TRUE;
34
import static org.junit.jupiter.api.Assertions.assertEquals;
45
import static org.mockito.ArgumentMatchers.any;
6+
import static org.mockito.ArgumentMatchers.anyString;
57
import static org.mockito.Mockito.when;
68

79
import java.util.Collections;
810
import java.util.List;
11+
import java.util.UUID;
912

13+
import com.sap.cloudfoundry.client.facade.CloudOperationException;
14+
import com.sap.cloudfoundry.client.facade.domain.ImmutableCloudMetadata;
15+
import org.cloudfoundry.client.v3.Metadata;
1016
import org.cloudfoundry.multiapps.common.test.Tester;
17+
import org.cloudfoundry.multiapps.controller.client.lib.domain.CloudServiceInstanceExtended;
18+
import org.cloudfoundry.multiapps.controller.client.lib.domain.ImmutableCloudServiceInstanceExtended;
1119
import org.cloudfoundry.multiapps.controller.core.cf.CloudControllerClientProvider;
1220
import org.cloudfoundry.multiapps.controller.core.util.ApplicationConfiguration;
1321
import org.cloudfoundry.multiapps.controller.persistence.services.FileService;
@@ -37,6 +45,7 @@
3745
import org.slf4j.LoggerFactory;
3846

3947
import com.sap.cloudfoundry.client.facade.CloudControllerClient;
48+
import org.springframework.http.HttpStatus;
4049

4150
public abstract class SyncFlowableStepTest<T extends SyncFlowableStep> {
4251

@@ -48,6 +57,12 @@ public abstract class SyncFlowableStepTest<T extends SyncFlowableStep> {
4857
protected static final String SPACE_GUID = "spaceGuid";
4958
protected final String TEST_CORRELATION_ID = "test";
5059
protected final String TEST_TASK_ID = "testTask";
60+
protected final String RETRY_STEP_EXECUTION_STATUS = "RETRY";
61+
protected final String DONE_STEP_EXECUTION_STATUS = "DONE";
62+
protected static final String SERVICE_NAME = "test-service";
63+
private static final String METADATA_LABEL = "test-label";
64+
private static final String METADATA_LABEL_VALUE = "test-label-value";
65+
private static final String SYSLOG_DRAIN_URL = "test-syslog-url";
5166

5267
protected final Tester tester = Tester.forClass(getClass());
5368

@@ -137,6 +152,32 @@ private ExecutionQuery createExecutionQueryMock() {
137152
return mockExecutionQuery;
138153
}
139154

155+
protected void assertExecutionStepStatus(String executionStepStatus) {
156+
assertEquals(executionStepStatus, getExecutionStatus());
157+
}
158+
159+
protected void prepareServiceToProcess(CloudServiceInstanceExtended serviceToProcess) {
160+
context.setVariable(Variables.SERVICE_TO_PROCESS, serviceToProcess);
161+
}
162+
163+
protected void prepareClient(CloudServiceInstanceExtended serviceToProcess) {
164+
when(client.getRequiredServiceInstanceGuid(SERVICE_NAME)).thenReturn(serviceToProcess.getGuid());
165+
}
166+
167+
protected CloudServiceInstanceExtended buildServiceToProcess(boolean isOptional) {
168+
return ImmutableCloudServiceInstanceExtended.builder()
169+
.name(SERVICE_NAME)
170+
.metadata(ImmutableCloudMetadata.builder()
171+
.guid(UUID.randomUUID())
172+
.build())
173+
.syslogDrainUrl(SYSLOG_DRAIN_URL)
174+
.v3Metadata(Metadata.builder()
175+
.label(METADATA_LABEL, METADATA_LABEL_VALUE)
176+
.build())
177+
.isOptional(isOptional)
178+
.build();
179+
}
180+
140181
protected void assertStepFinishedSuccessfully() {
141182
assertEquals(StepPhase.DONE.toString(), getExecutionStatus());
142183
}

0 commit comments

Comments
 (0)