From 8ef2ec86175055aba4158f7ae571e259c7ddeddf Mon Sep 17 00:00:00 2001 From: eeginux Date: Thu, 23 May 2019 10:51:36 +0100 Subject: [PATCH] exception handling Update the appc client jar version Throw exception for non success cds call Fix CreateVcpeResCustServiceSimplifiedTest IT Issue-ID: SO-1857 SO-1779 Change-Id: Ifee080600051c92fd964a92d16efb67e4ab05d5d Signed-off-by: eeginux --- bpmn/MSOCommonBPMN/pom.xml | 4 +- .../client/cds/AbstractCDSProcessingBBUtils.java | 18 +++++- bpmn/pom.xml | 1 + .../resources/process/ConfigurePnfResource.bpmn | 4 +- .../CreateVcpeResCustServiceSimplifiedTest.java | 70 ++++++++++------------ 5 files changed, 55 insertions(+), 42 deletions(-) diff --git a/bpmn/MSOCommonBPMN/pom.xml b/bpmn/MSOCommonBPMN/pom.xml index 20be69c006..e233e6a7c6 100644 --- a/bpmn/MSOCommonBPMN/pom.xml +++ b/bpmn/MSOCommonBPMN/pom.xml @@ -311,7 +311,7 @@ org.onap.appc.client client-lib - 1.5.0-SNAPSHOT + ${appc.client.version} org.mockito @@ -330,7 +330,7 @@ org.onap.appc.client client-kit - 1.5.0-SNAPSHOT + ${appc.client.version} org.mockito diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java index 6bfa67502d..5498b5be31 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java @@ -34,6 +34,7 @@ import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOu import org.onap.so.client.PreconditionFailedException; import org.onap.so.client.RestPropertiesLoader; import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean; +import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.ExceptionBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,6 +59,12 @@ public class AbstractCDSProcessingBBUtils implements CDSProcessingListener { private static final String FAILED = "Failed"; private static final String PROCESSING = "Processing"; + /** + * indicate exception thrown. + */ + private static final String EXCEPTION = "Exception"; + + private final AtomicReference cdsResponse = new AtomicReference<>(); @Autowired @@ -132,7 +139,15 @@ public class AbstractCDSProcessingBBUtils implements CDSProcessingListener { } if (cdsResponse != null) { - execution.setVariable("CDSStatus", cdsResponse.get()); + String cdsResponseStatus = cdsResponse.get(); + execution.setVariable("CDSStatus", cdsResponseStatus); + + /** + * throw CDS failed exception. + */ + if (cdsResponseStatus != SUCCESS) { + throw new BadResponseException("CDS call failed with status: " + cdsResponseStatus); + } } } catch (Exception ex) { @@ -177,6 +192,7 @@ public class AbstractCDSProcessingBBUtils implements CDSProcessingListener { public void onError(Throwable t) { Status status = Status.fromThrowable(t); logger.error("Failed processing blueprint {}", status, t); + cdsResponse.set(EXCEPTION); } } diff --git a/bpmn/pom.xml b/bpmn/pom.xml index c4aad4ba69..fd070bb81b 100644 --- a/bpmn/pom.xml +++ b/bpmn/pom.xml @@ -25,6 +25,7 @@ UTF-8 UTF-8 1.5.1 + 1.6.0-SNAPSHOT diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ConfigurePnfResource.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ConfigurePnfResource.bpmn index f489a27052..9a1a7ed628 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ConfigurePnfResource.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ConfigurePnfResource.bpmn @@ -30,7 +30,7 @@ SequenceFlow_17llfxw SequenceFlow_0p0aqtx - + SequenceFlow_0p0aqtx SequenceFlow_1owbpsy SequenceFlow_1w4p9f7 @@ -49,7 +49,7 @@ SequenceFlow_0jfgn7n SequenceFlow_08voj55 - + SequenceFlow_08voj55 SequenceFlow_1n080up SequenceFlow_0d24h26 diff --git a/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/CreateVcpeResCustServiceSimplifiedTest.java b/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/CreateVcpeResCustServiceSimplifiedTest.java index f51ea006d2..35f8f45999 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/CreateVcpeResCustServiceSimplifiedTest.java +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/CreateVcpeResCustServiceSimplifiedTest.java @@ -33,10 +33,8 @@ import com.google.protobuf.Struct; import java.io.IOException; import java.util.List; import java.util.UUID; -import org.camunda.bpm.engine.runtime.Execution; import org.camunda.bpm.engine.runtime.ProcessInstance; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers; import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader; @@ -52,12 +50,13 @@ import org.springframework.beans.factory.annotation.Autowired; /** * Basic Integration test for createVcpeResCustService_Simplified.bpmn workflow. */ -@Ignore public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest { - private static final long WORKFLOW_WAIT_TIME = 1000L; private Logger logger = LoggerFactory.getLogger(getClass()); + private static final long WORKFLOW_WAIT_TIME = 1000L; + private static final int DMAAP_DELAY_TIME_MS = 2000; + private static final String TEST_PROCESSINSTANCE_KEY = "CreateVcpeResCustService_simplified"; private String testBusinessKey; @@ -113,17 +112,9 @@ public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest { ProcessInstance pi = runtimeService.startProcessInstanceByKey(TEST_PROCESSINSTANCE_KEY, testBusinessKey, variables); - assertThat(pi).isNotNull(); - - Thread.sleep(WORKFLOW_WAIT_TIME); - - Execution execution = runtimeService.createExecutionQuery().processInstanceBusinessKey(testBusinessKey) - .messageEventSubscriptionName("WorkflowMessage").singleResult(); - - assertThat(execution).isNotNull(); int waitCount = 10; - while (!pi.isEnded() && waitCount >= 0) { + while (!isProcessInstanceEnded() && waitCount >= 0) { Thread.sleep(WORKFLOW_WAIT_TIME); waitCount--; } @@ -145,6 +136,11 @@ public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest { } } + private boolean isProcessInstanceEnded() { + return runtimeService.createProcessInstanceQuery().processDefinitionKey(TEST_PROCESSINSTANCE_KEY) + .singleResult() == null; + } + private void checkConfigAssign(ExecutionServiceInput executionServiceInput) { logger.info("Checking the configAssign request"); @@ -154,26 +150,26 @@ public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest { * the fields of actionIdentifiers should match the one in the * response/createVcpeResCustServiceSimplifiedTest_catalogdb.json. */ - assertThat(actionIdentifiers.getBlueprintName()).matches("test_configuration_restconf"); - assertThat(actionIdentifiers.getBlueprintVersion()).matches("1.0.0"); - assertThat(actionIdentifiers.getActionName()).matches("config-assign"); - assertThat(actionIdentifiers.getMode()).matches("sync"); + assertThat(actionIdentifiers.getBlueprintName()).isEqualTo("test_configuration_restconf"); + assertThat(actionIdentifiers.getBlueprintVersion()).isEqualTo("1.0.0"); + assertThat(actionIdentifiers.getActionName()).isEqualTo("config-assign"); + assertThat(actionIdentifiers.getMode()).isEqualTo("sync"); CommonHeader commonHeader = executionServiceInput.getCommonHeader(); - assertThat(commonHeader.getOriginatorId()).matches("SO"); - assertThat(commonHeader.getRequestId()).matches(msoRequestId); + assertThat(commonHeader.getOriginatorId()).isEqualTo("SO"); + assertThat(commonHeader.getRequestId()).isEqualTo(msoRequestId); Struct payload = executionServiceInput.getPayload(); Struct requeststruct = payload.getFieldsOrThrow("config-assign-request").getStructValue(); - assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).matches("PNFDemo"); + assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).isEqualTo("PNFDemo"); Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-assign-properties").getStructValue(); - assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).matches("PNFDemo"); + assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo("PNFDemo"); assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue()) - .matches("f2daaac6-5017-4e1e-96c8-6a27dfbe1421"); + .isEqualTo("f2daaac6-5017-4e1e-96c8-6a27dfbe1421"); assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue()) - .matches("68dc9a92-214c-11e7-93ae-92361f002680"); + .isEqualTo("68dc9a92-214c-11e7-93ae-92361f002680"); } private void checkConfigDeploy(ExecutionServiceInput executionServiceInput) { @@ -185,32 +181,32 @@ public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest { * the fields of actionIdentifiers should match the one in the * response/createVcpeResCustServiceSimplifiedTest_catalogdb.json. */ - assertThat(actionIdentifiers.getBlueprintName()).matches("test_configuration_restconf"); - assertThat(actionIdentifiers.getBlueprintVersion()).matches("1.0.0"); - assertThat(actionIdentifiers.getActionName()).matches("config-deploy"); - assertThat(actionIdentifiers.getMode()).matches("async"); + assertThat(actionIdentifiers.getBlueprintName()).isEqualTo("test_configuration_restconf"); + assertThat(actionIdentifiers.getBlueprintVersion()).isEqualTo("1.0.0"); + assertThat(actionIdentifiers.getActionName()).isEqualTo("config-deploy"); + assertThat(actionIdentifiers.getMode()).isEqualTo("async"); CommonHeader commonHeader = executionServiceInput.getCommonHeader(); - assertThat(commonHeader.getOriginatorId()).matches("SO"); - assertThat(commonHeader.getRequestId()).matches(msoRequestId); + assertThat(commonHeader.getOriginatorId()).isEqualTo("SO"); + assertThat(commonHeader.getRequestId()).isEqualTo(msoRequestId); Struct payload = executionServiceInput.getPayload(); Struct requeststruct = payload.getFieldsOrThrow("config-deploy-request").getStructValue(); - assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).matches("PNFDemo"); + assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).isEqualTo("PNFDemo"); Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-deploy-properties").getStructValue(); - assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).matches("PNFDemo"); + assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo("PNFDemo"); assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue()) - .matches("f2daaac6-5017-4e1e-96c8-6a27dfbe1421"); + .isEqualTo("f2daaac6-5017-4e1e-96c8-6a27dfbe1421"); assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue()) - .matches("68dc9a92-214c-11e7-93ae-92361f002680"); + .isEqualTo("68dc9a92-214c-11e7-93ae-92361f002680"); /** * IP addresses match the OAM ip addresses from AAI. */ - assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv4-address").getStringValue()).matches("1.1.1.1"); - assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv6-address").getStringValue()).matches("::/128"); + assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv4-address").getStringValue()).isEqualTo("1.1.1.1"); + assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv6-address").getStringValue()).isEqualTo("::/128"); } /** @@ -223,8 +219,8 @@ public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest { /** * Get the events from PNF topic */ - wireMockServer - .stubFor(get(urlPathMatching("/events/pnfReady/consumerGroup.*")).willReturn(okJson(pnfResponse))); + wireMockServer.stubFor(get(urlPathMatching("/events/pnfReady/consumerGroup.*")) + .willReturn(okJson(pnfResponse).withFixedDelay(DMAAP_DELAY_TIME_MS))); } private void mockAai() { -- 2.16.6