diff options
11 files changed, 168 insertions, 96 deletions
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/valet/ValetClient.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/valet/ValetClient.java index 3c073af6ba..d75824357f 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/valet/ValetClient.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/valet/ValetClient.java @@ -50,7 +50,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; -import org.onap.so.client.RestTemplateConfig; import javax.inject.Provider; @Component diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java index 08aee1ab4e..da989b0155 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java @@ -977,29 +977,28 @@ public class ToscaResourceInstaller { logger.debug("VF Category is : " + vfCustomizationCategory); - if (vfResourceStructure.getVfModuleStructure() != null - && !vfResourceStructure.getVfModuleStructure().isEmpty()) { + String vfCustomizationUUID = + vfEntityDetails.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - String vfCustomizationUUID = - vfEntityDetails.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + logger.debug("VFCustomizationUUID=" + vfCustomizationUUID); - logger.debug("VFCustomizationUUID=" + vfCustomizationUUID); + IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance(); - IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance(); + // Make sure the VF ResourceCustomizationUUID from the notification and tosca customizations match before + // comparing their VF Modules UUID's + logger.debug("Checking if Notification VF ResourceCustomizationUUID: " + + vfNotificationResource.getResourceCustomizationUUID() + " matches Tosca VF Customization UUID: " + + vfCustomizationUUID); - // Make sure the VF ResourceCustomizationUUID from the notification and tosca customizations match before - // comparing their VF Modules UUID's - logger.debug("Checking if Notification VF ResourceCustomizationUUID: " - + vfNotificationResource.getResourceCustomizationUUID() + " matches Tosca VF Customization UUID: " - + vfCustomizationUUID); + if (vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())) { - if (vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())) { + logger.debug("vfCustomizationUUID: " + vfCustomizationUUID + + " matches vfNotificationResource CustomizationUUID"); - logger.debug("vfCustomizationUUID: " + vfCustomizationUUID - + " matches vfNotificationResource CustomizationUUID"); - - VnfResourceCustomization vnfResource = createVnfResource(vfEntityDetails, toscaResourceStruct, service); + VnfResourceCustomization vnfResource = createVnfResource(vfEntityDetails, toscaResourceStruct, service); + if (vfResourceStructure.getVfModuleStructure() != null + && !vfResourceStructure.getVfModuleStructure().isEmpty()) { Set<CvnfcCustomization> existingCvnfcSet = new HashSet<>(); Set<VnfcCustomization> existingVnfcSet = new HashSet<>(); List<CvnfcConfigurationCustomization> existingCvnfcConfigurationCustom = new ArrayList<>(); @@ -1036,34 +1035,33 @@ public class ToscaResourceInstaller { + vfMetadata.getVfModuleModelCustomizationUUID()); } + } - // Check for VNFC Instance Group info and add it if there is - List<IEntityDetails> vfcEntityList = getEntityDetails(toscaResourceStruct, - EntityQuery.newBuilder("org.openecomp.groups.VfcInstanceGroup"), - TopologyTemplateQuery.newBuilder(SdcTypes.VF).customizationUUID(vfCustomizationUUID), false); + // Check for VNFC Instance Group info and add it if there is + List<IEntityDetails> vfcEntityList = getEntityDetails(toscaResourceStruct, + EntityQuery.newBuilder("org.openecomp.groups.VfcInstanceGroup"), + TopologyTemplateQuery.newBuilder(SdcTypes.VF).customizationUUID(vfCustomizationUUID), false); - for (IEntityDetails groupEntity : vfcEntityList) { - VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = - createVNFCInstanceGroup(groupEntity, nodeTemplate, vnfResource, toscaResourceStruct); - vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization); - } + for (IEntityDetails groupEntity : vfcEntityList) { + VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = + createVNFCInstanceGroup(groupEntity, nodeTemplate, vnfResource, toscaResourceStruct); + vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization); + } - List<String> seqResult = processVNFCGroupSequence(toscaResourceStruct, vfcEntityList); - if (!CollectionUtils.isEmpty(seqResult)) { - String resultStr = seqResult.stream().collect(Collectors.joining(",")); - vnfResource.setVnfcInstanceGroupOrder(resultStr); - logger.debug( - "vnfcGroupOrder result for service uuid(" + service.getModelUUID() + ") : " + resultStr); - } - // add this vnfResource with existing vnfResource for this service - addVnfCustomization(service, vnfResource); - } else { - logger.debug("Notification VF ResourceCustomizationUUID: " - + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " - + "Tosca VF Customization UUID: " + vfCustomizationUUID); + List<String> seqResult = processVNFCGroupSequence(toscaResourceStruct, vfcEntityList); + if (!CollectionUtils.isEmpty(seqResult)) { + String resultStr = seqResult.stream().collect(Collectors.joining(",")); + vnfResource.setVnfcInstanceGroupOrder(resultStr); + logger.debug("vnfcGroupOrder result for service uuid(" + service.getModelUUID() + ") : " + resultStr); } + // add this vnfResource with existing vnfResource for this service + addVnfCustomization(service, vnfResource); + } else { + logger.debug("Notification VF ResourceCustomizationUUID: " + + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " + + "Tosca VF Customization UUID: " + vfCustomizationUUID); } } @@ -1494,17 +1492,17 @@ public class ToscaResourceInstaller { Optional<ToscaCsar> toscaCsarOpt = toscaCsarRepo.findById(toscaResourceStructure.getToscaArtifact().getArtifactUUID()); ToscaCsar toscaCsar; - if (toscaCsarOpt.isPresent()) { - toscaCsar = toscaCsarOpt.get(); - } else { + if (!toscaCsarOpt.isPresent()) { toscaCsar = new ToscaCsar(); + toscaCsar.setArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID()); + } else { + toscaCsar = toscaCsarOpt.get(); } if (toscaResourceStructure.getToscaArtifact().getArtifactChecksum() != null) { toscaCsar.setArtifactChecksum(toscaResourceStructure.getToscaArtifact().getArtifactChecksum()); } else { toscaCsar.setArtifactChecksum(MANUAL_RECORD); } - toscaCsar.setArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID()); toscaCsar.setName(toscaResourceStructure.getToscaArtifact().getArtifactName()); toscaCsar.setVersion(toscaResourceStructure.getToscaArtifact().getArtifactVersion()); toscaCsar.setDescription(toscaResourceStructure.getToscaArtifact().getArtifactDescription()); @@ -1878,10 +1876,11 @@ public class ToscaResourceInstaller { InstanceGroup existingInstanceGroup = instanceGroupRepo.findByModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup(); + VFCInstanceGroup vfcInstanceGroup; if (existingInstanceGroup == null) { // Populate InstanceGroup + vfcInstanceGroup = new VFCInstanceGroup(); vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); vfcInstanceGroup .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); @@ -2154,6 +2153,7 @@ public class ToscaResourceInstaller { cvnfcCustomization.setNfcNamingCode(getLeafPropertyValue(cvfcEntity, "nfc_naming_code")); cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization); + // ***************************************************************************************************************************************** // * Extract Fabric Configuration // ***************************************************************************************************************************************** @@ -2162,31 +2162,39 @@ public class ToscaResourceInstaller { getEntityDetails(toscaResourceStructure, EntityQuery.newBuilder(SdcTypes.CONFIGURATION), TopologyTemplateQuery.newBuilder(SdcTypes.VF), false); - for (IEntityDetails fabricEntity : fabricEntityList) { - ConfigurationResource fabricConfig = null; + Map<String, RequirementAssignment> requirements = fabricEntity.getRequirements(); + + for (RequirementAssignment requirement : requirements.values()) { + + if (requirement.getNodeTemplateName().equals(cvfcEntity.getName())) { - ConfigurationResource existingConfig = - findExistingConfiguration(existingCvnfcConfigurationCustom, + ConfigurationResource fabricConfig = null; + + ConfigurationResource existingConfig = findExistingConfiguration( + existingCvnfcConfigurationCustom, fabricEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - if (existingConfig == null) { + if (existingConfig == null) { - fabricConfig = createFabricConfiguration(fabricEntity, toscaResourceStructure); + fabricConfig = createFabricConfiguration(fabricEntity, toscaResourceStructure); - } else { - fabricConfig = existingConfig; - } + } else { + fabricConfig = existingConfig; + } + + CvnfcConfigurationCustomization cvnfcConfigurationCustomization = + createCvnfcConfigurationCustomization(fabricEntity, toscaResourceStructure, + vnfResource, vfModuleCustomization, cvnfcCustomization, + fabricConfig, vfModuleMemberName); - CvnfcConfigurationCustomization cvnfcConfigurationCustomization = - createCvnfcConfigurationCustomization(fabricEntity, toscaResourceStructure, - vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig, - vfModuleMemberName); + cvnfcConfigurationCustomizations.add(cvnfcConfigurationCustomization); - cvnfcConfigurationCustomizations.add(cvnfcConfigurationCustomization); + existingCvnfcConfigurationCustom.add(cvnfcConfigurationCustomization); - existingCvnfcConfigurationCustom.add(cvnfcConfigurationCustomization); + } + } } cvnfcCustomization.setCvnfcConfigurationCustomization(cvnfcConfigurationCustomizations); diff --git a/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java b/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java index cfcf5ac599..2a4b3aa6fb 100644 --- a/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java +++ b/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java @@ -43,6 +43,8 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.mockito.ArgumentMatchers; +import org.mockito.Mockito; import org.mockito.Spy; import org.onap.so.asdc.BaseTest; import org.onap.so.asdc.client.test.emulators.DistributionClientEmulator; @@ -67,6 +69,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.test.util.ReflectionTestUtils; public class ASDCRestInterfaceTest extends BaseTest { @@ -107,6 +110,7 @@ public class ASDCRestInterfaceTest extends BaseTest { public void setUp() { // ASDC Controller writes to this path System.setProperty("mso.config.path", folder.getRoot().toString()); + ReflectionTestUtils.setField(toscaInstaller, "toscaCsarRepo", toscaCsarRepo); } @Test @@ -310,9 +314,9 @@ public class ASDCRestInterfaceTest extends BaseTest { HttpMethod.POST, entity, String.class); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - Optional<Service> service = serviceRepo.findById("5c4d4793-67fb-4155-b7d8-60ec011138c9"); + Optional<Service> service = serviceRepo.findById("317887d3-a4e4-45cb-8971-2a78426fefac"); assertTrue(service.isPresent()); - assertEquals("SDWAN", service.get().getModelName()); + assertEquals("CCVPNService", service.get().getModelName()); } protected String createURLWithPort(String uri) { diff --git a/asdc-controller/src/test/resources/resource-examples/ccvpn/demo-ccvpn-notification.json b/asdc-controller/src/test/resources/resource-examples/ccvpn/demo-ccvpn-notification.json index bc7d7d7979..1ca96f7dc9 100644 --- a/asdc-controller/src/test/resources/resource-examples/ccvpn/demo-ccvpn-notification.json +++ b/asdc-controller/src/test/resources/resource-examples/ccvpn/demo-ccvpn-notification.json @@ -1,31 +1,31 @@ { - "distributionID": "cbc7ab24-7d96-4cb5-949c-f23ada265513", - "serviceName": "SDWAN", - "serviceVersion": "2.0", - "serviceUUID": "5c4d4793-67fb-4155-b7d8-60ec011138c9", - "serviceDescription": "SDWAN Service", - "serviceInvariantUUID": "e830c260-ee21-4830-980c-c802cd9bbb1c", + "distributionID": "8a01603d-606d-4e40-8bc4-37107ad97897", + "serviceName": "CCVPNService", + "serviceVersion": "1.0", + "serviceUUID": "317887d3-a4e4-45cb-8971-2a78426fefac", + "serviceDescription": "CCVPN", + "serviceInvariantUUID": "e43f9b81-3035-44df-b618-a787e1c49427", "resources": [ { - "resourceInstanceName": "siteVF 0", - "resourceName": "siteVF", + "resourceInstanceName": "siteResource", + "resourceCustomizationUUID": "e9e01777-bb2f-42f0-b825-aef0f4c37ccf", + "resourceName": "siteResource", "resourceVersion": "1.0", "resoucreType": "VF", - "resourceUUID": "2c10d85c-e492-4813-a2d6-d1fab757fe49", - "resourceInvariantUUID": "ed9b1fe5-1e94-4974-a48f-389571837fd6", - "resourceCustomizationUUID": "33de5105-edf3-48cb-bda0-37b2aa2f681f", + "resourceUUID": "5a641276-443b-45ca-ac9c-a0ee84f5007b", + "resourceInvariantUUID": "5338673f-df81-483a-afa4-b9766442ebf1", "category": "Configuration", "subcategory": "Configuration", "artifacts": [] }, { - "resourceInstanceName": "vpn 0", - "resourceName": "vpn", - "resourceVersion": "2.0", + "resourceInstanceName": "SDWANVPNResource", + "resourceCustomizationUUID": "7815f32c-bdbf-41f7-9a18-6f0e6d5a0d0e", + "resourceName": "SDWANVPNResource", + "resourceVersion": "1.0", "resoucreType": "VF", - "resourceUUID": "235861f1-ea93-4443-94fa-82f29903f54f", - "resourceInvariantUUID": "c4eff5e7-c4fe-4caf-989b-11efc8e42a73", - "resourceCustomizationUUID": "faa89d44-329b-4fcb-a5dc-6e6f84946537", + "resourceUUID": "5f9f2164-f7e4-461d-b8de-3470297ce2b3", + "resourceInvariantUUID": "5ca15886-9990-419c-a4bb-f0229eac0926", "category": "Configuration", "subcategory": "Configuration", "artifacts": [] @@ -33,24 +33,14 @@ ], "serviceArtifacts": [ { - "artifactName": "service-Sdwan-template.yml", - "artifactType": "TOSCA_TEMPLATE", - "artifactURL": "/sdc/v1/catalog/services/Sdwan/2.0/artifacts/service-Sdwan-template.yml", - "artifactChecksum": "Zjg4MmJmNzI1MTliYzBiZjA2ZmJjN2EwNzZhZTcxYTQ=", - "artifactDescription": "TOSCA representation of the asset", - "artifactTimeout": 0, - "artifactUUID": "5e7beb91-61f9-4613-8cc5-1d288a624abb", - "artifactVersion": "2" - }, - { - "artifactName": "service-Sdwan-csar.csar", + "artifactName": "service-Ccvpnservice-csar.csar", "artifactType": "TOSCA_CSAR", - "artifactURL": "/service-Sdwan-csar.csar", - "artifactChecksum": "ODA1ZGViMzI0NzIxMmRmNTIzYzE0ZTg5NmExYWFjZTE=", + "artifactURL": "/service-Ccvpnservice-csar.csar", + "artifactChecksum": "NTZlNGU4YTQwNzVkZWMwYWZkODE5M2MwYzcyNzM3M2U\u003d", "artifactDescription": "TOSCA definition package of the asset", "artifactTimeout": 0, - "artifactUUID": "771ec21a-1d14-4891-a56f-d4e47e2c8c91", - "artifactVersion": "2" + "artifactVersion": "2", + "artifactUUID": "59f34dcf-ec33-4a88-8dbe-aa7f4571ef59" } ], "workloadContext": "Production" diff --git a/asdc-controller/src/test/resources/resource-examples/ccvpn/service-Ccvpnservice-csar.csar b/asdc-controller/src/test/resources/resource-examples/ccvpn/service-Ccvpnservice-csar.csar Binary files differnew file mode 100644 index 0000000000..ce2ac5e0c9 --- /dev/null +++ b/asdc-controller/src/test/resources/resource-examples/ccvpn/service-Ccvpnservice-csar.csar diff --git a/asdc-controller/src/test/resources/resource-examples/ccvpn/service-Sdwan-csar.csar b/asdc-controller/src/test/resources/resource-examples/ccvpn/service-Sdwan-csar.csar Binary files differdeleted file mode 100644 index 7a508429f8..0000000000 --- a/asdc-controller/src/test/resources/resource-examples/ccvpn/service-Sdwan-csar.csar +++ /dev/null diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/LoggingAndURNMappingPlugin.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/LoggingAndURNMappingPlugin.java index 251464a34d..6de22825b7 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/LoggingAndURNMappingPlugin.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/LoggingAndURNMappingPlugin.java @@ -37,8 +37,10 @@ import org.camunda.bpm.engine.impl.pvm.process.ScopeImpl; import org.camunda.bpm.engine.impl.pvm.process.TransitionImpl; import org.camunda.bpm.engine.impl.util.xml.Element; import org.camunda.bpm.engine.impl.variable.VariableDeclaration; +import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -50,6 +52,9 @@ import org.springframework.stereotype.Component; @Component public class LoggingAndURNMappingPlugin extends AbstractProcessEnginePlugin { + public static final String SERVICE_INSTANCE_ID = "ServiceInstanceId"; + public static final String SERVICE_NAME = "ServiceName"; + @Autowired private LoggingParseListener loggingParseListener; @@ -294,6 +299,13 @@ public class LoggingAndURNMappingPlugin extends AbstractProcessEnginePlugin { String requestId = (String) execution.getVariable("mso-request-id"); String svcid = (String) execution.getVariable("mso-service-instance-id"); + try { + MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId); + MDC.put(SERVICE_INSTANCE_ID, svcid); + MDC.put(SERVICE_NAME, processName); + } catch (Exception e) { + logger.error("Error trying to add variables to MDC", e); + } } } catch (Exception e) { logger.error("Exception occurred", e); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java index 9340609ffc..d9c6857ef1 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java @@ -33,6 +33,7 @@ import org.camunda.bpm.engine.delegate.JavaDelegate; import org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables; import org.camunda.bpm.engine.variable.VariableMap; import org.onap.so.bpmn.core.WorkflowException; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBFailure; import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBTasks; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; @@ -79,6 +80,8 @@ public class ExecuteActivity implements JavaDelegate { @Autowired private ExceptionBuilder exceptionBuilder; @Autowired + private WorkflowActionBBFailure workflowActionBBFailure; + @Autowired private WorkflowActionBBTasks workflowActionBBTasks; @Override @@ -178,13 +181,15 @@ public class ExecuteActivity implements JavaDelegate { protected void buildAndThrowException(DelegateExecution execution, String msg, Exception ex) { logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue(), msg, ex); - execution.setVariable("ExecuteActivityErrorMessage", msg); + execution.setVariable(EXECUTE_ACTIVITY_ERROR_MESSAGE, msg); + workflowActionBBFailure.updateRequestStatusToFailed(execution); exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); } protected void buildAndThrowException(DelegateExecution execution, String msg) { logger.error(msg); execution.setVariable(EXECUTE_ACTIVITY_ERROR_MESSAGE, msg); + workflowActionBBFailure.updateRequestStatusToFailed(execution); exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivityTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivityTest.java index 56ff813e73..c0056291ef 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivityTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivityTest.java @@ -22,22 +22,41 @@ package org.onap.so.bpmn.infrastructure.activity; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; import java.nio.file.Files; import java.nio.file.Paths; +import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.core.WorkflowException; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBFailure; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; -import org.springframework.beans.factory.annotation.Autowired; +import org.onap.so.client.exception.ExceptionBuilder; public class ExecuteActivityTest extends BaseTaskTest { @InjectMocks protected ExecuteActivity executeActivity = new ExecuteActivity(); + @InjectMocks + @Spy + private ExceptionBuilder exceptionBuilder; + + @Mock + private WorkflowActionBBFailure workflowActionBBFailure; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + private DelegateExecution execution; @Before @@ -72,4 +91,17 @@ public class ExecuteActivityTest extends BaseTaskTest { assertEquals(ebb.getBuildingBlock(), bb); } + @Test + public void buildAndThrowException_Test() throws Exception { + doNothing().when(workflowActionBBFailure).updateRequestStatusToFailed(execution); + doReturn("Process key").when(exceptionBuilder).getProcessKey(execution); + thrown.expect(BpmnError.class); + executeActivity.buildAndThrowException(execution, "TEST EXCEPTION MSG"); + String errorMessage = (String) execution.getVariable("ExecuteActivityErrorMessage"); + assertEquals(errorMessage, "TEST EXCEPTION MSG"); + WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException"); + assertEquals(workflowException.getErrorMessage(), "TEST EXCEPTION MSG"); + assertEquals(workflowException.getErrorCode(), 7000); + } + } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java index a5ccb1b29b..8896e93175 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java @@ -83,6 +83,7 @@ import io.swagger.annotations.ApiOperation; public class OrchestrationRequests { private static Logger logger = LoggerFactory.getLogger(OrchestrationRequests.class); + private static final String ERROR_MESSAGE_PREFIX = "Error Source: %s, Error Message: %s"; @Autowired private RequestsDbClient requestsDbClient; @@ -449,7 +450,12 @@ public class OrchestrationRequests { String statusMessages = null; if (iar.getStatusMessage() != null) { - statusMessages = "STATUS: " + iar.getStatusMessage(); + if (StringUtils.isNotBlank(iar.getExtSystemErrorSource())) { + statusMessages = "STATUS: " + + String.format(ERROR_MESSAGE_PREFIX, iar.getExtSystemErrorSource(), iar.getStatusMessage()); + } else { + statusMessages = "STATUS: " + iar.getStatusMessage(); + } } if (OrchestrationRequestFormat.STATUSDETAIL.toString().equalsIgnoreCase(format)) { diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java index f672648a6b..627bbc631d 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java @@ -25,6 +25,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.doReturn; import javax.ws.rs.core.Response; import org.apache.commons.lang.StringUtils; @@ -232,6 +233,21 @@ public class OrchestrationRequestsUnitTest { } @Test + public void mapRequestStatusAndExtSysErrSrcToRequestErrorMessageTest() throws ApiException { + InstanceReferences instanceReferences = new InstanceReferences(); + instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID); + iar.setExtSystemErrorSource(ROLLBACK_EXT_SYSTEM_ERROR_SOURCE); + iar.setFlowStatus(null); + iar.setStatusMessage("Error retrieving cloud region from AAI"); + + Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, + OrchestrationRequestFormat.DETAIL.toString()); + + assertTrue(actual.getRequestStatus().getStatusMessage() + .contains("Error Source: " + ROLLBACK_EXT_SYSTEM_ERROR_SOURCE)); + } + + @Test public void mapRequestStatusAndExtSysErrSrcToRequestFlowStatusSuccessfulCompletionTest() throws ApiException { InstanceReferences instanceReferences = new InstanceReferences(); instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID); |