From dbb53cabbff772880134699eb81dee775d7df8df Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Wed, 31 Oct 2018 14:35:05 -0700 Subject: Send correct resourceModuleName Issue-ID: SO-1178 Change-Id: I593ec7db0bac3e0b343bd0eb960977d0110fd9b8 Signed-off-by: Marcus G K Williams --- .../main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'bpmn') diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy index 197589efa1..c7312c453c 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy @@ -159,6 +159,8 @@ class OofUtils { utils.log("DEBUG", "Allotted Resource: " + resource.toString(), isDebugEnabled) def serviceResourceId = resource.getResourceId() + def toscaNodeType = resource.getToscaNodeType() + def resourceModuleName = toscaNodeType.substring(toscaNodeType.lastIndexOf(".") + 1) def resourceModelInvariantId = resource.getModelInfo().getModelInvariantUuid() def resourceModelVersionId = resource.getModelInfo().getModelUuid() def resourceModelName = resource.getModelInfo().getModelName() @@ -174,7 +176,7 @@ class OofUtils { String demand = " {\n" + - " \"resourceModuleName\": \"${resourceModelName}\",\n" + + " \"resourceModuleName\": \"${resourceModuleName}\",\n" + " \"serviceResourceId\": \"${serviceResourceId}\",\n" + " \"tenantId\": \"${tenantId}\",\n" + " \"resourceModelInfo\": {\n" + @@ -200,6 +202,8 @@ class OofUtils { utils.log("DEBUG", "VNF Resource: " + vnfResource.toString(), isDebugEnabled) ModelInfo vnfResourceModelInfo = vnfResource.getModelInfo() + def toscaNodeType = vnfResource.getToscaNodeType() + def resourceModuleName = toscaNodeType.substring(toscaNodeType.lastIndexOf(".") + 1) def serviceResourceId = vnfResource.getResourceId() def resourceModelInvariantId = vnfResourceModelInfo.getModelInvariantUuid() def resourceModelName = vnfResourceModelInfo.getModelName() @@ -212,7 +216,7 @@ class OofUtils { String placementDemand = " {\n" + - " \"resourceModuleName\": \"${resourceModelName}\",\n" + + " \"resourceModuleName\": \"${resourceModuleName}\",\n" + " \"serviceResourceId\": \"${serviceResourceId}\",\n" + " \"tenantId\": \"${tenantId}\",\n" + " \"resourceModelInfo\": {\n" + -- cgit 1.2.3-korg From d3759e15184562647ea83b92cf02140fc705cb0d Mon Sep 17 00:00:00 2001 From: "Smokowski, Steve (ss835w)" Date: Thu, 1 Nov 2018 11:23:04 -0400 Subject: Update Logic Update Regex Logic to take into account new scale out URI and generate the UUID, Fix whitespace Issue-ID: SO-117 Change-Id: I1a3c3b31e18701fce3d622d501dd68efc7ab6969 Change-Id: I1a3c3b31e18701fce3d622d501dd68efc7ab6969 Signed-off-by: Smokowski, Steve (ss835w) --- .../workflow/tasks/WorkflowAction.java | 62 ++++++++++++---------- .../workflow/tasks/WorkflowActionTest.java | 6 ++- 2 files changed, 38 insertions(+), 30 deletions(-) (limited to 'bpmn') diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index 24246273e8..3fbdbbae1e 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -81,6 +81,7 @@ public class WorkflowAction { private static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage"; private static final String SERVICE_INSTANCES = "serviceInstances"; + private static final String VF_MODULES = "vfModules"; private static final String WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI = "WorkflowAction was unable to verify if the instance name already exist in AAI."; private static final String G_ORCHESTRATION_FLOW = "gOrchestrationFlow"; private static final String G_ACTION = "requestAction"; @@ -664,35 +665,38 @@ public class WorkflowAction { } protected Resource extractResourceIdAndTypeFromUri(String uri) { - Pattern patt = Pattern.compile( - "[vV]\\d+.*?(?:(?:/(?" + supportedTypes + ")(?:/(?[^/]+))?)(?:/(?[^/]+))?)?$"); - Matcher m = patt.matcher(uri); - Boolean generated = false; - - if (m.find()) { - logger.debug("found match on {} : {} " , uri , m); - String type = m.group("type"); - String id = m.group("id"); - String action = m.group("action"); - if (type == null) { - throw new IllegalArgumentException("Uri could not be parsed. No type found. " + uri); - } - if (action == null) { - if (type.equals(SERVICE_INSTANCES) && (id == null || id.equals("assign"))) { - id = UUID.randomUUID().toString(); - generated = true; - } - } else { - if (action.matches(supportedTypes)) { - id = UUID.randomUUID().toString(); - generated = true; - type = action; - } - } - return new Resource(WorkflowType.fromString(convertTypeFromPlural(type)), id, generated); - } else { - throw new IllegalArgumentException("Uri could not be parsed: " + uri); - } + Pattern patt = Pattern.compile( + "[vV]\\d+.*?(?:(?:/(?" + supportedTypes + ")(?:/(?[^/]+))?)(?:/(?[^/]+))?)?$"); + Matcher m = patt.matcher(uri); + Boolean generated = false; + + if (m.find()) { + logger.debug("found match on {} : {} " , uri , m); + String type = m.group("type"); + String id = m.group("id"); + String action = m.group("action"); + if (type == null) { + throw new IllegalArgumentException("Uri could not be parsed. No type found. " + uri); + } + if (action == null) { + if (type.equals(SERVICE_INSTANCES) && (id == null || id.equals("assign"))) { + id = UUID.randomUUID().toString(); + generated = true; + }else if (type.equals(VF_MODULES) && id.equals("scaleOut")) { + id = UUID.randomUUID().toString(); + generated = true; + } + } else { + if (action.matches(supportedTypes)) { + id = UUID.randomUUID().toString(); + generated = true; + type = action; + } + } + return new Resource(WorkflowType.fromString(convertTypeFromPlural(type)), id, generated); + } else { + throw new IllegalArgumentException("Uri could not be parsed: " + uri); + } } protected String validateResourceIdInAAI(String generatedResourceId, WorkflowType type, String instanceName, diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index 65d16adb40..c27b5dd655 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -1318,7 +1318,7 @@ public class WorkflowActionTest extends BaseTaskTest { String uri5 = "'/v6/serviceInstances/123/vnfs"; String uri6 = "/v6/serviceInstances/123/vnfs/1234/someAction"; String uri7 = "/v6/serviceInstances/123/vnfs/1234/vfModules/5678/replace"; - + String uri8 = "/v6/serviceInstances/123/vnfs/1234/vfModules/scaleOut"; Resource expected1 = new Resource(WorkflowType.SERVICE, "123", true); Resource expected2 = new Resource(WorkflowType.VNF, "1234", false); Resource expected3 = new Resource(WorkflowType.VNF, "1234", false); @@ -1344,6 +1344,10 @@ public class WorkflowActionTest extends BaseTaskTest { result = workflowAction.extractResourceIdAndTypeFromUri(uri7); assertEquals(expected4.getResourceId(),result.getResourceId()); assertEquals(expected4.getResourceType(),result.getResourceType()); + result = workflowAction.extractResourceIdAndTypeFromUri(uri8); + assertEquals(UUID.randomUUID().toString().length(),result.getResourceId().length()); + assertEquals("VfModule", result.getResourceType().toString()); + } @Test -- cgit 1.2.3-korg From 5dadc2c5790c961a74085d3d10b6f5aec6b7ba30 Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Thu, 1 Nov 2018 14:35:21 -0700 Subject: Fix msb url in homing cloudsite This change adds a getMsbHost method to homingUtils to enable correct configuration of the msburl used in identity_services for multicloud. Issue-ID: SO-1180 Change-Id: Ib7adecda98b1d5f5770e2d17a2e76c970619ab46 Signed-off-by: Marcus G K Williams --- .../org/onap/so/bpmn/common/scripts/OofHoming.groovy | 18 +++++++++++++----- .../org/onap/so/bpmn/common/scripts/OofUtils.groovy | 8 ++++++++ .../org/onap/so/bpmn/core/UrnPropertiesReader.java | 4 ++++ 3 files changed, 25 insertions(+), 5 deletions(-) (limited to 'bpmn') diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy index 533df72285..c8736b8f0e 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy @@ -250,7 +250,7 @@ class OofHoming extends AbstractServiceTaskProcessor { resource.getHomingSolution().setCloudOwner(cloudOwner) resource.getHomingSolution().setCloudRegionId(cloudRegionId) - CloudSite cloudSite = new CloudSite(); + CloudSite cloudSite = new CloudSite() cloudSite.setId(cloudRegionId) cloudSite.setRegionId(cloudRegionId) String orchestrator = execution.getVariable("orchestrator") @@ -258,10 +258,18 @@ class OofHoming extends AbstractServiceTaskProcessor { cloudSite.setOrchestrator(orchestrator) } - CloudIdentity cloudIdentity = new CloudIdentity(); - cloudIdentity.setId(cloudRegionId); - cloudIdentity.setIdentityUrl("/api/multicloud /v1/" + cloudOwner + "/" + cloudRegionId + "/infra_workload") - cloudSite.setIdentityService(cloudIdentity); + CloudIdentity cloudIdentity = new CloudIdentity() + cloudIdentity.setId(cloudRegionId) + // Get MSB Url + String msbHost = oofUtils.getMsbHost(execution) + String multicloudApiEndpoint = UrnPropertiesReader + .getVariable("mso.multicloud.api.endpoint", execution, + "/api/multicloud-titaniumcloud/v1") + cloudIdentity.setIdentityUrl(msbHost + multicloudApiEndpoint + + "/" + cloudOwner + "/" + + cloudRegionId + "/infra_workload") + + cloudSite.setIdentityService(cloudIdentity) // Set cloudsite in catalog DB here oofUtils.createCloudSiteCatalogDb(cloudSite) diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy index 197589efa1..ae1079a9bf 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy @@ -526,4 +526,12 @@ class OofUtils { exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from CatalogDB.") } } + + String getMsbHost(DelegateExecution execution) { + msbHost = UrnPropertiesReader.getVariable("mso.msb.host", execution, "msb-iag.onap") + + Integer msbPort = UrnPropertiesReader.getVariable("mso.msb.port", execution, "80").toInteger() + + return UriBuilder.fromPath("").host(msbHost).port(msbPort).scheme("http").build().toString() + } } diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/UrnPropertiesReader.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/UrnPropertiesReader.java index 968c8c1590..750cd241e8 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/UrnPropertiesReader.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/UrnPropertiesReader.java @@ -69,6 +69,10 @@ public class UrnPropertiesReader { return variableValue; } + public static String getVariable(String variableName, DelegateExecution execution, String defaultValue) { + return Optional.ofNullable(getVariable(variableName, execution)).orElse(defaultValue); + } + /** * Return the URN property value from the environment object * @param variableName URN property name -- cgit 1.2.3-korg From 3178cad6c756140b18eb658277598e3e2d2d3dcf Mon Sep 17 00:00:00 2001 From: Prema Bhatt Date: Fri, 2 Nov 2018 12:57:28 -0700 Subject: ConfigurationParameter is empty for scaleout Mapping for ConfigurationParameter List was missing in BBInputSetupMapperLayer class. Added mapping and updated Unit tests and test data Change-Id: Ice8c7c30c97a5b8a8444a2243ddbea4d5fb036af Issue-ID: SO-1083 Signed-off-by: Prema Bhatt --- .../bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java | 1 + .../ExecuteBuildingBlock/GeneralBuildingBlockExpected.json | 8 +++++++- .../__files/ExecuteBuildingBlock/RequestContextExpected.json | 9 +++++++-- .../ExecuteBuildingBlock/RequestDetailsInput_mapReqContext.json | 8 +++++++- 4 files changed, 22 insertions(+), 4 deletions(-) (limited to 'bpmn') diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java index 0f52c96d0e..9f284fc1fc 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java @@ -337,6 +337,7 @@ public class BBInputSetupMapperLayer { context.setRequestParameters(this.mapRequestParameters(requestDetails.getRequestParameters())); context.setUserParams(this.mapNameValueUserParams(requestDetails.getRequestParameters())); } + context.setConfigurationParameters(requestDetails.getConfigurationParameters()); return context; } diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpected.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpected.json index 926bf2ccb7..5eb9a26901 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpected.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpected.json @@ -27,7 +27,13 @@ "skip": "ignore" } ] - } + }, + "configurationParameters": [ + { + "availability-zone":"$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]", + "xtz-123":"$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]" + } + ] }, "orchContext": { "is-rollback-enabled": false diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestContextExpected.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestContextExpected.json index dfc6d4f555..906903e0b2 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestContextExpected.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestContextExpected.json @@ -25,6 +25,11 @@ "skip": "ignore" } ] - } - + }, + "configurationParameters": [ + { + "availability-zone":"$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]", + "xtz-123":"$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]" + } + ] } diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestDetailsInput_mapReqContext.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestDetailsInput_mapReqContext.json index 7386828d27..9afbdd9150 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestDetailsInput_mapReqContext.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestDetailsInput_mapReqContext.json @@ -23,6 +23,12 @@ } ] - } + }, + "configurationParameters": [ + { + "availability-zone":"$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]", + "xtz-123":"$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]" + } + ] } -- cgit 1.2.3-korg From 402bf528e9a796f6ce31ad36c16316c2b31acc48 Mon Sep 17 00:00:00 2001 From: Prema Bhatt Date: Fri, 2 Nov 2018 13:55:10 -0700 Subject: Added Null check for gtConfigurationParameter Change-Id: Icd21f579eebfe40b70344456420701fbc2408722 Issue-ID: SO-1179 Signed-off-by: Prema Bhatt --- .../so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'bpmn') diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java index 9f284fc1fc..1e77c35ee3 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java @@ -337,7 +337,9 @@ public class BBInputSetupMapperLayer { context.setRequestParameters(this.mapRequestParameters(requestDetails.getRequestParameters())); context.setUserParams(this.mapNameValueUserParams(requestDetails.getRequestParameters())); } - context.setConfigurationParameters(requestDetails.getConfigurationParameters()); + if (requestDetails.getConfigurationParameters() != null) { + context.setConfigurationParameters(requestDetails.getConfigurationParameters()); + } return context; } -- cgit 1.2.3-korg From fb6ab40a64e74876ba1f08c4d3bdb6a040c21b94 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Mon, 5 Nov 2018 19:12:02 -0500 Subject: Bug fixes November 5th building block validator test now passes added buildingblockvalidator process instance test Retrieve actual error from WorkflowExceptionErrorMessage when the error message is empty, not only when null. Propagate orchestrationStatusValidationResult values from BB to BB. corrected use of constructor for AaiUtil use AaiUtil method to create path for get call modified how allotted resource urls are constructed - Removed the findExistingVnfcInstanceGroup method. It is not required to check this because the vnfResourceCustomization is always a new object at this location. Enable multiStage VF Module Create processing only when aLaCarte flag is on. Change-Id: If8cf397a84abc290e67e287d5b2264dd226398bc Issue-ID: SO-1188 Signed-off-by: Benjamin, Max (mb388a) --- .../installer/heat/ToscaResourceInstaller.java | 36 +----- .../common/scripts/AllottedResourceUtils.groovy | 22 +++- .../src/main/resources/META-INF/processes.xml | 31 ------ .../scripts/AllottedResourceUtilsTest.groovy | 39 +++++++ .../subprocess/BuildingBlock/WorkflowActionBB.bpmn | 5 +- .../BuildingBlockValidatorRunnerTest.java | 44 ++++++++ .../src/test/resources/META-INF/processes.xml | 0 .../BuildingBlockValidatorRunnerTest.bpmn | 122 +++++++++++++++++++++ .../scripts/DoCreateAllottedResourceBRG.groovy | 29 +---- .../scripts/DoCreateAllottedResourceTXC.groovy | 44 +++----- .../infrastructure/aai/tasks/AAIUpdateTasks.java | 4 +- .../tasks/OrchestrationStatusValidator.java | 11 +- .../aai/tasks/AAIUpdateTasksTest.java | 15 +++ .../tasks/OrchestrationStatusValidatorTest.java | 50 ++++++++- .../so/client/aai/entities/uri/AAIUriFactory.java | 26 ++++- 15 files changed, 345 insertions(+), 133 deletions(-) delete mode 100644 bpmn/MSOCommonBPMN/src/main/resources/META-INF/processes.xml create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AllottedResourceUtilsTest.groovy create mode 100644 bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/BuildingBlockValidatorRunnerTest.java create mode 100644 bpmn/so-bpmn-building-blocks/src/test/resources/META-INF/processes.xml create mode 100644 bpmn/so-bpmn-building-blocks/src/test/resources/subprocess/BuildingBlock/BuildingBlockValidatorRunnerTest.bpmn (limited to 'bpmn') 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 f77a48a1f8..06da4e7e03 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 @@ -1170,27 +1170,7 @@ public class ToscaResourceInstaller { return vfcInstanceGroupCustom; } - - protected VFCInstanceGroup findExistingVnfcInstanceGroup(VnfResourceCustomization vnfResourceCustomization, - String modelUUID) { - VFCInstanceGroup vfcInstanceGroup = null; - List vnfInstanceGroupCustomizations = vnfResourceCustomization - .getVnfcInstanceGroupCustomizations(); - if(vnfInstanceGroupCustomizations != null){ - for (VnfcInstanceGroupCustomization vnfcInstanceGroupCustom : vnfResourceCustomization - .getVnfcInstanceGroupCustomizations()) { - if (vnfcInstanceGroupCustom.getInstanceGroup() != null - && vnfcInstanceGroupCustom.getInstanceGroup().getModelUUID().equals(modelUUID)) { - vfcInstanceGroup = (VFCInstanceGroup)vnfcInstanceGroupCustom.getInstanceGroup(); - } - } - } - if (vfcInstanceGroup == null) - vfcInstanceGroup = (VFCInstanceGroup) instanceGroupRepo.findByModelUUID(modelUUID); - - return vfcInstanceGroup; - } - + protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure, IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service, Set existingCvnfcSet, Set existingVnfcSet) { @@ -1606,16 +1586,10 @@ public class ToscaResourceInstaller { for (Group group : groupList) { - VFCInstanceGroup vfcInstanceGroup = findExistingVnfcInstanceGroup(vnfResourceCustomization, - group.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - if(vfcInstanceGroup == null){ - VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup( - vfNodeTemplate, group, vnfResourceCustomization); - - vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization); - } - } - + VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(vfNodeTemplate, group, vnfResourceCustomization); + + vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization); + } } return vnfResourceCustomization; } diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AllottedResourceUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AllottedResourceUtils.groovy index e4bc5f8fa2..c337a21987 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AllottedResourceUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AllottedResourceUtils.groovy @@ -137,7 +137,7 @@ class AllottedResourceUtils { try { AAIResourcesClient client = new AAIResourcesClient() AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.ALLOTTED_RESOURCE, allottedResourceId) - AaiUtil aaiUtil = new AaiUtil() + AaiUtil aaiUtil = new AaiUtil(taskProcessor) arLink = aaiUtil.createAaiUri(uri) } catch (NotFoundException e) { msoLogger.debug("GET AR received a Not Found (404) Response") @@ -323,5 +323,25 @@ class AllottedResourceUtils { msoLogger.trace("Exit BuildAAIErrorResponse Process") throw new BpmnError("MSOWorkflowException") } + + public String createARUrl(DelegateExecution execution, AAIResourceUri uri, String allottedResourceId) { + AaiUtil aaiUriUtil = new AaiUtil(taskProcessor) + AAIResourceUri siResourceLink= uri + + String siUri = "" + + if(siResourceLink != null) { + msoLogger.debug("Incoming PSI Resource Link is: " + siResourceLink.build().toString()) + } + else + { + String msg = "Parent Service Link in AAI is null" + msoLogger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + AAIResourceUri arUri = AAIUriFactory.createResourceFromParentURI(siResourceLink, AAIObjectType.ALLOTTED_RESOURCE, allottedResourceId) + + return aaiUriUtil.createAaiUri(arUri) + } } diff --git a/bpmn/MSOCommonBPMN/src/main/resources/META-INF/processes.xml b/bpmn/MSOCommonBPMN/src/main/resources/META-INF/processes.xml deleted file mode 100644 index 33c8cb1ac0..0000000000 --- a/bpmn/MSOCommonBPMN/src/main/resources/META-INF/processes.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - false - true - - - - diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AllottedResourceUtilsTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AllottedResourceUtilsTest.groovy new file mode 100644 index 0000000000..5058961992 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AllottedResourceUtilsTest.groovy @@ -0,0 +1,39 @@ +package org.onap.so.bpmn.common.scripts + +import static org.junit.Assert.assertEquals +import static org.mockito.Matchers.eq +import static org.mockito.Mockito.mock +import static org.mockito.Mockito.when + +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake +import org.junit.Test +import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.so.client.aai.entities.uri.AAIResourceUri +import org.springframework.core.env.Environment + +class AllottedResourceUtilsTest { + + + @Test + public void createARUrlTest() { + AllottedResourceUtils utils = new AllottedResourceUtils(mock(AbstractServiceTaskProcessor.class)) + DelegateExecution execution = new DelegateExecutionFake() + String allottedResourceId = "my-id" + UrnPropertiesReader reader = new UrnPropertiesReader() + Environment env = mock(Environment.class); + + when(env.getProperty(eq("mso.workflow.global.default.aai.version"))).thenReturn("14") + when(env.getProperty(eq("aai.endpoint"))).thenReturn("http://localhost:8080") + + + reader.setEnvironment(env) + + + AAIResourceUri uri = mock(AAIResourceUri.class) + when(uri.build()).thenReturn(new URI("/business/customers/customer/1/service-subscriptions/service-subscription/2/service-instances/service-instance/3")) + String actual = utils.createARUrl(execution, uri, allottedResourceId) + + assertEquals("http://localhost:8080/aai/v14/business/customers/customer/1/service-subscriptions/service-subscription/2/service-instances/service-instance/3/allotted-resources/allotted-resource/my-id", actual) + } +} diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn index 8cda1d7c7b..3b24ba390b 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_15s0okp @@ -17,6 +17,9 @@ + + + SequenceFlow_0mew9im SequenceFlow_07h9d4y diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/BuildingBlockValidatorRunnerTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/BuildingBlockValidatorRunnerTest.java new file mode 100644 index 0000000000..ea0fb95702 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/BuildingBlockValidatorRunnerTest.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.bpmn.subprocess; + +import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat; +import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.job; +import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.execute; +import org.camunda.bpm.engine.runtime.Job; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.camunda.bpm.engine.task.Task; +import org.junit.Test; +import org.onap.so.bpmn.BaseBPMNTest; + +public class BuildingBlockValidatorRunnerTest extends BaseBPMNTest{ + @Test + public void sunnyDayActivateNetwork_Test() throws InterruptedException { + variables.put("flowToBeCalled","CreateVolumeGroupBB"); + ProcessInstance pi = runtimeService.startProcessInstanceByKey("BuildingBlockValidatorRunnerTest", variables); + assertThat(pi).isNotNull(); + + execute(job()); + execute(job()); + assertThat(pi).isStarted().hasPassedInOrder("ServiceTask_1","ServiceTask_2","ServiceTask_3"); + assertThat(pi).isEnded(); + } +} diff --git a/bpmn/so-bpmn-building-blocks/src/test/resources/META-INF/processes.xml b/bpmn/so-bpmn-building-blocks/src/test/resources/META-INF/processes.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bpmn/so-bpmn-building-blocks/src/test/resources/subprocess/BuildingBlock/BuildingBlockValidatorRunnerTest.bpmn b/bpmn/so-bpmn-building-blocks/src/test/resources/subprocess/BuildingBlock/BuildingBlockValidatorRunnerTest.bpmn new file mode 100644 index 0000000000..446dfe3104 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/test/resources/subprocess/BuildingBlock/BuildingBlockValidatorRunnerTest.bpmn @@ -0,0 +1,122 @@ + + + + + SequenceFlow_0vof4nz + + + SequenceFlow_0vof4nz + SequenceFlow_14nr57b + + + SequenceFlow_1vsqhv8 + SequenceFlow_04xg7yh + + + + SequenceFlow_06wt67a + + + SequenceFlow_14nr57b + SequenceFlow_1vsqhv8 + + PT10S + + + + + + SequenceFlow_04xg7yh + SequenceFlow_0w8ajcb + + PT10S + + + + SequenceFlow_0w8ajcb + SequenceFlow_06wt67a + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRG.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRG.groovy index 3c08779513..1be4989490 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRG.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRG.groovy @@ -240,11 +240,9 @@ public class DoCreateAllottedResourceBRG extends AbstractServiceTaskProcessor{ if(obj.has("result-data")){ JSONObject ob = obj.getJSONArray("result-data").getJSONObject(0) String resourceLink = ob.getString("resource-link") + AAIResourceUri siUri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.SERVICE_INSTANCE, new URI(resourceLink)) - String[] split = resourceLink.split("/aai/") - String siRelatedLink = "/aai/" + split[1] - - execution.setVariable("PSI_resourceLink", resourceLink) + execution.setVariable("PSI_resourceLink", siUri) }else{ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai") } @@ -277,26 +275,9 @@ public class DoCreateAllottedResourceBRG extends AbstractServiceTaskProcessor{ //AAI PUT AaiUtil aaiUriUtil = new AaiUtil(this) - String aaiEndpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution) - String siResourceLink= execution.getVariable("PSI_resourceLink") - - String siUri = "" - msoLogger.debug("PSI_resourceLink:" + siResourceLink) - - if(!isBlank(siResourceLink)) { - msoLogger.debug("Incoming PSI Resource Link is: " + siResourceLink) - String[] split = siResourceLink.split("/aai/") - siUri = "/aai/" + split[1] - } - else - { - msg = "Parent Service Link in AAI is null" - msoLogger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) - } - - arUrl = "${aaiEndpoint}${siUri}" + "/allotted-resources/allotted-resource/" + UriUtils.encode(allottedResourceId,"UTF-8") - execution.setVariable("aaiARPath", arUrl) + AAIResourceUri siResourceLink= execution.getVariable("PSI_resourceLink") + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + execution.setVariable("aaiARPath", arUtils.createARUrl(execution, siResourceLink, allottedResourceId)) msoLogger.debug("GET AllottedResource AAI URL is:\n" + arUrl) String namespace = aaiUriUtil.getNamespaceFromUri(execution, arUrl) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceTXC.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceTXC.groovy index 5f9b4b8ecd..48eb1c85f9 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceTXC.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceTXC.groovy @@ -20,23 +20,22 @@ package org.onap.so.bpmn.vcpe.scripts; +import static org.apache.commons.lang3.StringUtils.* + +import org.apache.commons.lang3.* +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.so.bpmn.common.scripts.*; -import org.onap.so.bpmn.common.scripts.AaiUtil import org.onap.so.bpmn.core.RollbackData -import org.onap.so.bpmn.core.WorkflowException import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.so.bpmn.core.WorkflowException import org.onap.so.bpmn.core.json.JsonUtils -import org.onap.so.rest.APIResponse - -import java.util.UUID; -import org.camunda.bpm.engine.delegate.BpmnError -import org.camunda.bpm.engine.delegate.DelegateExecution -import org.apache.commons.lang3.* -import org.springframework.web.util.UriUtils; -import static org.apache.commons.lang3.StringUtils.* - +import org.onap.so.client.aai.AAIObjectType +import org.onap.so.client.aai.entities.uri.AAIResourceUri +import org.onap.so.client.aai.entities.uri.AAIUriFactory import org.onap.so.logger.MessageEnum import org.onap.so.logger.MsoLogger +import org.onap.so.rest.APIResponse /** * This groovy class supports the DoCreateAllottedResourceTXC.bpmn process. @@ -204,26 +203,9 @@ public class DoCreateAllottedResourceTXC extends AbstractServiceTaskProcessor{ //AAI PUT AaiUtil aaiUriUtil = new AaiUtil(this) - String aaiEndpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution) - String siResourceLink= execution.getVariable("PSI_resourceLink") - - String siUri = "" - msoLogger.debug("PSI_resourceLink:" + siResourceLink) - - if(!isBlank(siResourceLink)) { - msoLogger.debug("Incoming PSI Resource Link is: " + siResourceLink) - String[] split = siResourceLink.split("/aai/") - siUri = "/aai/" + split[1] - } - else - { - msg = "Parent Service Link in AAI is null" - msoLogger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) - } - - arUrl = "${aaiEndpoint}${siUri}" + "/allotted-resources/allotted-resource/" + UriUtils.encode(allottedResourceId,"UTF-8") - execution.setVariable("aaiARPath", arUrl) + AAIResourceUri siResourceLink= execution.getVariable("PSI_resourceLink") + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + execution.setVariable("aaiARPath", arUtils.createARUrl(execution, siResourceLink, allottedResourceId)) msoLogger.debug("GET AllottedResource AAI URL is:\n" + arUrl) String namespace = aaiUriUtil.getNamespaceFromUri(execution, arUrl) diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java index 87c04d7ecc..38261c0f1a 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java @@ -54,6 +54,7 @@ import org.springframework.stereotype.Component; @Component public class AAIUpdateTasks { private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AAIUpdateTasks.class); + private static final String ALACARTE = "aLaCarte"; private static final String MULTI_STAGE_DESIGN_OFF = "false"; private static final String MULTI_STAGE_DESIGN_ON = "true"; @Autowired @@ -196,7 +197,8 @@ public class AAIUpdateTasks { if (vnf.getModelInfoGenericVnf() != null) { multiStageDesign = vnf.getModelInfoGenericVnf().getMultiStageDesign(); } - if (multiStageDesign != null && multiStageDesign.equalsIgnoreCase(MULTI_STAGE_DESIGN_ON)) { + boolean aLaCarte = (boolean) execution.getVariable(ALACARTE); + if (aLaCarte && multiStageDesign != null && multiStageDesign.equalsIgnoreCase(MULTI_STAGE_DESIGN_ON)) { aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule,vnf,OrchestrationStatus.PENDING_ACTIVATION); } else { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidator.java index 88ae3746ab..b0063c1da1 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidator.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidator.java @@ -45,6 +45,7 @@ public class OrchestrationStatusValidator { private static final String UNKNOWN_RESOURCE_TYPE = "Building Block (%s) not set up correctly in Orchestration_Status_Validation table in CatalogDB. ResourceType=(%s), TargetAction=(%s)"; private static final String ORCHESTRATION_VALIDATION_FAIL = "Orchestration Status Validation failed. ResourceType=(%s), TargetAction=(%s), OrchestrationStatus=(%s)"; private static final String ORCHESTRATION_STATUS_VALIDATION_RESULT = "orchestrationStatusValidationResult"; + private static final String ALACARTE = "aLaCarte"; private static final String MULTI_STAGE_DESIGN_OFF = "false"; private static final String MULTI_STAGE_DESIGN_ON = "true"; @@ -62,8 +63,10 @@ public class OrchestrationStatusValidator { execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, null); - String buildingBlockFlowName = execution.getFlowToBeCalled(); + boolean aLaCarte = (boolean) execution.getVariable(ALACARTE); + String buildingBlockFlowName = execution.getFlowToBeCalled(); + BuildingBlockDetail buildingBlockDetail = catalogDbClient.getBuildingBlockDetail(buildingBlockFlowName); if (buildingBlockDetail == null) { @@ -112,7 +115,7 @@ public class OrchestrationStatusValidator { } OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = catalogDbClient.getOrchestrationStatusStateTransitionDirective(buildingBlockDetail.getResourceType(), orchestrationStatus, buildingBlockDetail.getTargetAction()); - if(ResourceType.VF_MODULE.equals(buildingBlockDetail.getResourceType()) && OrchestrationAction.CREATE.equals(buildingBlockDetail.getTargetAction()) && + if(aLaCarte && ResourceType.VF_MODULE.equals(buildingBlockDetail.getResourceType()) && OrchestrationAction.CREATE.equals(buildingBlockDetail.getTargetAction()) && OrchestrationStatus.PENDING_ACTIVATION.equals(orchestrationStatus)) { org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); orchestrationStatusStateTransitionDirective = processPossibleSecondStageofVfModuleCreate(execution, previousOrchestrationStatusValidationResult, @@ -138,11 +141,11 @@ public class OrchestrationStatusValidator { private OrchestrationStatusStateTransitionDirective processPossibleSecondStageofVfModuleCreate(BuildingBlockExecution execution, OrchestrationStatusValidationDirective previousOrchestrationStatusValidationResult, org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf, OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective) { if (previousOrchestrationStatusValidationResult != null && previousOrchestrationStatusValidationResult.equals(OrchestrationStatusValidationDirective.SILENT_SUCCESS)) { - String multiStageDesign = "false"; + String multiStageDesign = MULTI_STAGE_DESIGN_OFF; if (genericVnf.getModelInfoGenericVnf() != null) { multiStageDesign = genericVnf.getModelInfoGenericVnf().getMultiStageDesign(); } - if (multiStageDesign != null && multiStageDesign.equalsIgnoreCase("true")) { + if (multiStageDesign != null && multiStageDesign.equalsIgnoreCase(MULTI_STAGE_DESIGN_ON)) { orchestrationStatusStateTransitionDirective.setFlowDirective(OrchestrationStatusValidationDirective.CONTINUE); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java index 560f2a91bf..1a302c29a7 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java @@ -169,6 +169,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{ @Test public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleNoMultiStageTest() throws Exception { + execution.setVariable("aLaCarte", true); ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); modelInfoGenericVnf.setMultiStageDesign("false"); genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf); @@ -178,8 +179,21 @@ public class AAIUpdateTasksTest extends BaseTaskTest{ assertEquals("", vfModule.getHeatStackId()); } + @Test + public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleMultiStageButNotAlacarteTest() throws Exception { + execution.setVariable("aLaCarte", false); + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setMultiStageDesign("true"); + genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf); + doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED); + aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution); + verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED); + assertEquals("", vfModule.getHeatStackId()); + } + @Test public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleWithMultiStageTest() throws Exception { + execution.setVariable("aLaCarte", true); ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); modelInfoGenericVnf.setMultiStageDesign("true"); genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf); @@ -191,6 +205,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{ @Test public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleExceptionTest() throws Exception { + execution.setVariable("aLaCarte", true); doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED); expectedException.expect(BpmnError.class); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorTest.java index fa5081da2f..5ef020d6ed 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorTest.java @@ -51,7 +51,7 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { public void test_validateOrchestrationStatus() throws Exception { String flowToBeCalled = "AssignServiceInstanceBB"; setServiceInstance().setOrchestrationStatus(OrchestrationStatus.PRECREATED); - + execution.setVariable("aLaCarte", true); execution.setVariable("flowToBeCalled", flowToBeCalled); BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); @@ -91,6 +91,7 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { si.setConfigurations(configurations); execution.setVariable("flowToBeCalled", flowToBeCalled); + execution.setVariable("aLaCarte", true); BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); buildingBlockDetail.setBuildingBlockName("UnassignFabricConfigurationBB"); @@ -188,6 +189,7 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { String flowToBeCalled = "UnassignServiceInstanceBB"; execution.setVariable("flowToBeCalled", flowToBeCalled); + execution.setVariable("aLaCarte", true); BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); buildingBlockDetail.setBuildingBlockName("UnassignServiceInstanceBB"); @@ -209,7 +211,7 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { String flowToBeCalled = "CreateVfModuleBB"; execution.setVariable("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.SILENT_SUCCESS); - + execution.setVariable("aLaCarte", true); execution.setVariable("flowToBeCalled", flowToBeCalled); GenericVnf genericVnf = buildGenericVnf(); @@ -246,7 +248,7 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { String flowToBeCalled = "CreateVfModuleBB"; execution.setVariable("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.CONTINUE); - + execution.setVariable("aLaCarte", true); execution.setVariable("flowToBeCalled", flowToBeCalled); GenericVnf genericVnf = buildGenericVnf(); @@ -282,7 +284,7 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { String flowToBeCalled = "CreateVfModuleBB"; execution.setVariable("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.SILENT_SUCCESS); - + execution.setVariable("aLaCarte", true); execution.setVariable("flowToBeCalled", flowToBeCalled); GenericVnf genericVnf = buildGenericVnf(); @@ -318,7 +320,7 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { String flowToBeCalled = "CreateVfModuleBB"; execution.setVariable("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.SILENT_SUCCESS); - + execution.setVariable("aLaCarte", true); execution.setVariable("flowToBeCalled", flowToBeCalled); GenericVnf genericVnf = buildGenericVnf(); @@ -354,7 +356,7 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { String flowToBeCalled = "CreateVfModuleBB"; execution.setVariable("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.SILENT_SUCCESS); - + execution.setVariable("aLaCarte", true); execution.setVariable("flowToBeCalled", flowToBeCalled); GenericVnf genericVnf = buildGenericVnf(); @@ -384,4 +386,40 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { assertEquals(OrchestrationStatusValidationDirective.SILENT_SUCCESS, execution.getVariable("orchestrationStatusValidationResult")); } + + @Test + public void test_validateOrchestrationStatusSecondStageOfMultiStageWrongAlacarteValueVfModule() throws Exception { + String flowToBeCalled = "CreateVfModuleBB"; + + execution.setVariable("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.SILENT_SUCCESS); + execution.setVariable("aLaCarte", false); + execution.setVariable("flowToBeCalled", flowToBeCalled); + + GenericVnf genericVnf = buildGenericVnf(); + ModelInfoGenericVnf modelInfoGenericVnf = genericVnf.getModelInfoGenericVnf(); + modelInfoGenericVnf.setMultiStageDesign("true"); + setGenericVnf().setModelInfoGenericVnf(modelInfoGenericVnf); + setVfModule().setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); + + BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); + buildingBlockDetail.setBuildingBlockName("CreateVfModuleBB"); + buildingBlockDetail.setId(1); + buildingBlockDetail.setResourceType(ResourceType.VF_MODULE); + buildingBlockDetail.setTargetAction(OrchestrationAction.CREATE); + + doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); + + OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = new OrchestrationStatusStateTransitionDirective(); + orchestrationStatusStateTransitionDirective.setFlowDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS); + orchestrationStatusStateTransitionDirective.setId(1); + orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); + orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.VF_MODULE); + orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.ACTIVATE); + + doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient).getOrchestrationStatusStateTransitionDirective(ResourceType.VF_MODULE, OrchestrationStatus.PENDING_ACTIVATION, OrchestrationAction.CREATE); + + orchestrationStatusValidator.validateOrchestrationStatus(execution); + + assertEquals(OrchestrationStatusValidationDirective.SILENT_SUCCESS, execution.getVariable("orchestrationStatusValidationResult")); + } } diff --git a/common/src/main/java/org/onap/so/client/aai/entities/uri/AAIUriFactory.java b/common/src/main/java/org/onap/so/client/aai/entities/uri/AAIUriFactory.java index 3589075ee5..77c61089a4 100644 --- a/common/src/main/java/org/onap/so/client/aai/entities/uri/AAIUriFactory.java +++ b/common/src/main/java/org/onap/so/client/aai/entities/uri/AAIUriFactory.java @@ -25,6 +25,7 @@ import java.net.URI; import org.onap.so.client.aai.AAIObjectPlurals; import org.onap.so.client.aai.AAIObjectType; + public class AAIUriFactory { /** @@ -53,7 +54,12 @@ public class AAIUriFactory { return new NodesUri(type, values); } - + + public static AAIResourceUri createNodesUri(AAIObjectPlurals type) { + return new NodesUri(type); + + } + /** * This method should only be used to wrap a URI retrieved from A&AI contained within an object response * @@ -64,7 +70,21 @@ public class AAIUriFactory { public static AAIResourceUri createResourceFromExistingURI(AAIObjectType type, URI uri) { return new AAISimpleUri(type, uri); } - + + + /** + * creates an AAIResourceUri from a parentUri + * + * @param parentUri + * @param childType + * @param childValues + * @return + */ + public static AAIResourceUri createResourceFromParentURI(AAIResourceUri parentUri, AAIObjectType childType, Object... childValues) { + + return new AAISimpleUri(parentUri, childType, childValues); + } + /** * Creates a uri for a plural type e.g. /cloud-infrastructure/pservers * @@ -88,4 +108,4 @@ public class AAIUriFactory { return new AAISimpleUri(type, values); } -} +} \ No newline at end of file -- cgit 1.2.3-korg From ce37ae979311ed4e55150426d477db262773beb0 Mon Sep 17 00:00:00 2001 From: "Brittany Plummer (bp896r)" Date: Tue, 6 Nov 2018 09:51:10 -0500 Subject: Removed slashes and added catch block Issue-ID: SO-1183 Change-Id: Ib8581393d782f078fc844cf96cbf7a0228133581 Signed-off-by: Brittany Plummer (bp896r) --- .../flowspecific/tasks/ConfigurationScaleOut.java | 10 +++--- .../tasks/ConfigurationScaleOutTest.java | 36 ++++++++++++++++++---- .../__files/SDNCClientResponseIncorrectPath.json | 29 +++++++++++++++++ 3 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientResponseIncorrectPath.json (limited to 'bpmn') diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOut.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOut.java index d13c5db871..58dd5a1df6 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOut.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOut.java @@ -95,10 +95,13 @@ public class ConfigurationScaleOut { for (Map.Entry entry : param.entrySet()) { key = entry.getKey(); paramValue = entry.getValue(); - configScaleOutParam = JsonPath.parse(sdncVfModuleQueryResponse).read(paramValue); - if(configScaleOutParam != null){ - paramsMap.put(key, configScaleOutParam); + try{ + configScaleOutParam = JsonPath.parse(sdncVfModuleQueryResponse).read(paramValue); + }catch(ClassCastException e){ + configScaleOutParam = null; + msoLogger.warnSimple("Incorrect JSON path. Path points to object rather than value causing: ", e); } + paramsMap.put(key, configScaleOutParam); } } } @@ -107,7 +110,6 @@ public class ConfigurationScaleOut { configPayload.setConfigurationParameters(paramsMap); configPayload.setRequestParameters(requestParameters); configScaleOutPayloadString = mapper.writeValueAsString(configPayload); - configScaleOutPayloadString = configScaleOutPayloadString.replaceAll("\"", "\\\\\""); execution.setVariable(ACTION, actionCategory); execution.setVariable(MSO_REQUEST_ID, gBBInput.getRequestContext().getMsoRequestId()); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOutTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOutTest.java index dabdc6811c..8577de2537 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOutTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOutTest.java @@ -79,9 +79,9 @@ public class ConfigurationScaleOutTest extends BaseTaskTest { controllerSelectionReference.setActionCategory("testAction"); controllerSelectionReference.setVnfType("testVnfType"); String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNCClientGetResponse.json"))); - String expectedPayload = "{\\\"request-parameters\\\":{\\\"vnf-host-ip-address\\\":\\\"10.222.22.2\\\"," - + "\\\"vf-module-id\\\":\\\"testVfModuleId1\\\"},\\\"configuration-parameters\\\"" - + ":{\\\"vnf-id\\\":\\\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\\\",\\\"availability-zone\\\":\\\"AZ-MN02\\\"}}"; + String expectedPayload = "{\"request-parameters\":{\"vnf-host-ip-address\":\"10.222.22.2\"," + + "\"vf-module-id\":\"testVfModuleId1\"},\"configuration-parameters\"" + + ":{\"vnf-id\":\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\",\"availability-zone\":\"AZ-MN02\"}}"; execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), sdncResponse); doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.ConfigScaleOut.toString()); @@ -101,9 +101,9 @@ public class ConfigurationScaleOutTest extends BaseTaskTest { Action action = Action.ConfigScaleOut; String vnfId = genericVnf.getVnfId(); String controllerType = "testType"; - String payload = "{\\\"request-parameters\\\":{\\\"vnf-host-ip-address\\\":\\\"10.222.22.2\\\"," - + "\\\"vf-module-id\\\":\\\"testVfModuleId1\\\"},\\\"configuration-parameters\\\"" - + ":{\\\"vnf-id\\\":\\\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\\\",\\\"availability-zone\\\":\\\"AZ-MN02\\\"}}"; + String payload = "{\"request-parameters\":{\"vnf-host-ip-address\":\"10.222.22.2\"," + + "\"vf-module-id\":\"testVfModuleId1\"},\"configuration-parameters\"" + + ":{\"vnf-id\":\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\",\"availability-zone\":\"AZ-MN02\"}}"; HashMap payloadInfo = new HashMap(); payloadInfo.put("vnfName", "testVnfName"); payloadInfo.put("vfModuleId", "testVfModuleId"); @@ -121,5 +121,29 @@ public class ConfigurationScaleOutTest extends BaseTaskTest { configurationScaleOut.callAppcClient(execution); verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); } + @Test + public void setParamsForConfigurationScaleOutBadPathTest() throws Exception { + ControllerSelectionReference controllerSelectionReference = new ControllerSelectionReference(); + controllerSelectionReference.setControllerName("testName"); + controllerSelectionReference.setActionCategory("testAction"); + controllerSelectionReference.setVnfType("testVnfType"); + String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNCClientResponseIncorrectPath.json"))); + String expectedPayload = "{\"request-parameters\":{\"vnf-host-ip-address\":\"10.222.22.2\"," + + "\"vf-module-id\":\"testVfModuleId1\"},\"configuration-parameters\"" + + ":{\"vnf-id\":\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\",\"availability-zone\":null}}"; + execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), sdncResponse); + + doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.ConfigScaleOut.toString()); + + configurationScaleOut.setParamsForConfigurationScaleOut(execution); + + assertEquals(genericVnf.getVnfId(), execution.getVariable("vnfId")); + assertEquals(genericVnf.getVnfName(), execution.getVariable("vnfName")); + assertEquals("ConfigScaleOut", execution.getVariable("action")); + assertEquals(requestContext.getMsoRequestId(), execution.getVariable("msoRequestId")); + assertEquals(controllerSelectionReference.getControllerName(), execution.getVariable("controllerType")); + assertEquals(vfModule.getVfModuleId(), execution.getVariable("vfModuleId")); + assertEquals(expectedPayload, execution.getVariable("payload")); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientResponseIncorrectPath.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientResponseIncorrectPath.json new file mode 100644 index 0000000000..7e263b4465 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientResponseIncorrectPath.json @@ -0,0 +1,29 @@ +{ + "vnf-topology": { + "tenant": "0422ffb57ba042c0800a29dc85ca70f8", + "vnf-topology-identifier-structure": { + "vnf-id": "66dac89b-2a5b-4cb9-b22e-a7e4488fb3db", + "vnf-type": "InfraMSO_vSAMP10a_Service/InfraMSO_vSAMP10a-2 0", + "vnf-name": "MSO-DEV-VNF-1806HF1-InfraMSO_vSAMP10a-1XXX-GR_21" + }, + "aic-clli": "AUSTTXGR", + "vnf-resource-assignments": { + "availability-zones": { + "availability-zone": [ + { + "test":"AZ-MN02" + } + ], + "max-count": 1 + } + }, + "aic-cloud-region": "mtn6", + "onap-model-information": { + "model-customization-uuid": "034226ae-879a-46b5-855c-d02babcb6cb6", + "model-uuid": "cb79c25f-b30d-4d95-afb5-97be4021f3db", + "model-invariant-uuid": "e93d3a7a-446d-486b-ae48-d474a9156064", + "model-name": "InfraMSO_vSAMP10a-2", + "model-version": "1.0" + } + } +} \ No newline at end of file -- cgit 1.2.3-korg From 2073a3b4c20965252c7f3a0c1aea8e4407e876fa Mon Sep 17 00:00:00 2001 From: Prema Bhatt Date: Tue, 6 Nov 2018 13:10:30 -0800 Subject: Fixing scaleOut workflow looping issue Updated both GenericVnfHealthCheck and ConfigurationScaleOut BB with appropriate Exception catch block and added Exception unit test. Issue-ID: SO-1182 Change-Id: Ia29741a4a7d8e1bb759ace4fd888864141d224d6 Signed-off-by: Prema Bhatt --- .../flowspecific/tasks/ConfigurationScaleOut.java | 20 ++++++++++++-- .../flowspecific/tasks/GenericVnfHealthCheck.java | 23 +++++++++++++--- .../tasks/ConfigurationScaleOutTest.java | 27 +++++++++++++++++++ .../tasks/GenericVnfHealthCheckTest.java | 31 ++++++++++++++++++++++ 4 files changed, 95 insertions(+), 6 deletions(-) (limited to 'bpmn') diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOut.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOut.java index 58dd5a1df6..615b7279dc 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOut.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOut.java @@ -37,6 +37,7 @@ import org.onap.so.client.appc.ApplicationControllerAction; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.db.catalog.beans.ControllerSelectionReference; import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -124,6 +125,9 @@ public class ConfigurationScaleOut { } public void callAppcClient(BuildingBlockExecution execution) { + msoLogger.trace("Start runAppcCommand "); + String appcCode = "1002"; + String appcMessage = ""; try{ Action commandAction = Action.valueOf(execution.getVariable(ACTION)); String msoRequestId = execution.getVariable(MSO_REQUEST_ID); @@ -137,10 +141,22 @@ public class ConfigurationScaleOut { HashMap payloadInfo = new HashMap<>(); payloadInfo.put(VNF_NAME, execution.getVariable(VNF_NAME)); payloadInfo.put(VFMODULE_ID,execution.getVariable(VFMODULE_ID)); + msoLogger.debug("Running APP-C action: " + commandAction.toString()); + msoLogger.debug("VNFID: " + vnfId); //PayloadInfo contains extra information that adds on to payload before making request to appc appCClient.runAppCCommand(commandAction, msoRequestId, vnfId, payloadString, payloadInfo, controllerType); - }catch(Exception ex){ - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + appcCode = appCClient.getErrorCode(); + appcMessage = appCClient.getErrorMessage(); + + } catch (Exception e) { + msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "Caught exception in runAppcCommand in ConfigurationScaleOut", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "APPC Error", e); + appcMessage = e.getMessage(); + } + msoLogger.error("Error Message: " + appcMessage); + msoLogger.error("ERROR CODE: " + appcCode); + msoLogger.trace("End of runAppCommand "); + if (appcCode != null && !appcCode.equals("0")) { + exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage); } } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java index 61162f4d85..2dae820e95 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java @@ -32,6 +32,7 @@ import org.onap.so.client.appc.ApplicationControllerAction; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.catalog.beans.ControllerSelectionReference; +import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -78,7 +79,9 @@ public class GenericVnfHealthCheck { } public void callAppcClient(BuildingBlockExecution execution) { - + msoLogger.trace("Start runAppcCommand "); + String appcCode = "1002"; + String appcMessage = ""; try { Action action = null; action = Action.valueOf(execution.getVariable("action")); @@ -95,11 +98,23 @@ public class GenericVnfHealthCheck { payloadInfo.put("vfModuleId",execution.getVariable("vfModuleId")); payloadInfo.put("oamIpAddress",execution.getVariable("oamIpAddress")); payloadInfo.put("vnfHostIpAddress",execution.getVariable("vnfHostIpAddress")); + + msoLogger.debug("Running APP-C action: " + action.toString()); + msoLogger.debug("VNFID: " + vnfId); //PayloadInfo contains extra information that adds on to payload before making request to appc appCClient.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); + appcCode = appCClient.getErrorCode(); + appcMessage = appCClient.getErrorMessage(); - } catch (Exception ex) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); - } + } catch (Exception e) { + msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "Caught exception in runAppcCommand in GenericVnfHealthCheck", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "APPC Error", e); + appcMessage = e.getMessage(); + } + msoLogger.error("Error Message: " + appcMessage); + msoLogger.error("ERROR CODE: " + appcCode); + msoLogger.trace("End of runAppCommand "); + if (appcCode != null && !appcCode.equals("0")) { + exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage); + } } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOutTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOutTest.java index 8577de2537..85915bd4b4 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOutTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOutTest.java @@ -22,6 +22,7 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -34,6 +35,7 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; +import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; import org.onap.appc.client.lcm.model.Action; @@ -146,4 +148,29 @@ public class ConfigurationScaleOutTest extends BaseTaskTest { assertEquals(expectedPayload, execution.getVariable("payload")); } + @Test + public void callAppcClientExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + Action action = Action.ConfigScaleOut; + String vnfId = genericVnf.getVnfId(); + String controllerType = "testType"; + String payload = "{\"request-parameters\":{\"vnf-host-ip-address\":\"10.222.22.2\"," + + "\"vf-module-id\":\"testVfModuleId1\"},\"configuration-parameters\"" + + ":{\"vnf-id\":\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\",\"availability-zone\":\"AZ-MN02\"}}"; + HashMap payloadInfo = new HashMap(); + payloadInfo.put("vnfName", "testVnfName"); + payloadInfo.put("vfModuleId", "testVfModuleId"); + + execution.setVariable("action", Action.ConfigScaleOut.toString()); + execution.setVariable("msoRequestId", msoRequestId); + execution.setVariable("controllerType", controllerType); + execution.setVariable("vnfId", "testVnfId1"); + execution.setVariable("vnfName", "testVnfName"); + execution.setVariable("vfModuleId", "testVfModuleId"); + execution.setVariable("payload", payload); + + doThrow(Exception.class).when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); + configurationScaleOut.callAppcClient(execution); + verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java index 9f0bb910e6..e5e092aace 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java @@ -22,6 +22,7 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -29,6 +30,7 @@ import java.util.HashMap; import java.util.Optional; import java.util.UUID; +import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; import org.onap.appc.client.lcm.model.Action; @@ -97,6 +99,35 @@ public class GenericVnfHealthCheckTest extends BaseTaskTest { doNothing().when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); + genericVnfHealthCheck.callAppcClient(execution); + verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); + } + + @Test + public void callAppcClientExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + Action action = Action.HealthCheck; + String vnfId = genericVnf.getVnfId(); + String payload = "{\"testName\":\"testValue\",}"; + String controllerType = "testType"; + HashMap payloadInfo = new HashMap(); + payloadInfo.put("vnfName", "testVnfName"); + payloadInfo.put("vfModuleId", "testVfModuleId"); + payloadInfo.put("oamIpAddress", "testOamIpAddress"); + payloadInfo.put("vnfHostIpAddress", "testOamIpAddress"); + execution.setVariable("action", Action.HealthCheck.toString()); + execution.setVariable("msoRequestId", msoRequestId); + execution.setVariable("controllerType", controllerType); + execution.setVariable("vnfId", "testVnfId1"); + execution.setVariable("vnfName", "testVnfName"); + execution.setVariable("vfModuleId", "testVfModuleId"); + execution.setVariable("oamIpAddress", "testOamIpAddress"); + execution.setVariable("vnfHostIpAddress", "testOamIpAddress"); + execution.setVariable("payload", payload); + + doThrow(Exception.class).when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); + + genericVnfHealthCheck.callAppcClient(execution); verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); } -- cgit 1.2.3-korg From 5ca364a5e975877244ee51796602043a4b078a23 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Fri, 26 Oct 2018 09:54:46 -0400 Subject: Make homingBB optinal and fix homing process MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Properly defined whether or not to call homing at AssignVnfBB where by default homing doesn't get called, but if a homing solution is provided, then we resolve the solutions. The goal is to change the BPMN definition to use serviceTask rather than a scriptTask, allowing to use the Srping component to inject logic. Also we create a new HomingV2 component that is agnostic of the homing implementation, which goal is to route the homing request to the proper bbackend implementation; e.g. oof vs homing. Finally, we remove the un-needed variables set in the execution context. Change-Id: Ic9fb2a599c6375617c92a6d3462b62921ee47a6f Issue-ID: SO-1168 Signed-off-by: Alexis de Talhouët --- .../onap/so/bpmn/common/scripts/OofHoming.groovy | 5 +- .../subprocess/BuildingBlock/AssignVnfBB.bpmn | 12 +- .../subprocess/BuildingBlock/HomingBB.bpmn | 124 +++++++++------------ .../org/onap/so/bpmn/buildingblock/HomingV2.java | 59 ++++++++++ .../workflow/tasks/WorkflowAction.java | 32 +++--- 5 files changed, 138 insertions(+), 94 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/HomingV2.java (limited to 'bpmn') diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy index c8736b8f0e..806a144a48 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy @@ -18,13 +18,11 @@ * ============LICENSE_END========================================================= */ package org.onap.so.bpmn.common.scripts + import org.onap.so.bpmn.core.UrnPropertiesReader import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution -import org.onap.so.bpmn.common.scripts.AaiUtil -import org.onap.so.bpmn.common.scripts.ExceptionUtil - import org.onap.so.bpmn.core.domain.InventoryType import org.onap.so.bpmn.core.domain.Resource import org.onap.so.bpmn.core.domain.ResourceType @@ -37,7 +35,6 @@ import org.onap.so.db.catalog.beans.CloudSite import org.onap.so.rest.APIResponse import org.onap.so.rest.RESTClient import org.onap.so.rest.RESTConfig -import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.json.JSONArray import org.json.JSONObject diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignVnfBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignVnfBB.bpmn index 3355e627c3..9118b0ab5e 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignVnfBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignVnfBB.bpmn @@ -28,9 +28,11 @@ - + + + - + @@ -65,7 +67,7 @@ - + SequenceFlow_1nle8kc SequenceFlow_11jum90 SequenceFlow_1uiok7v @@ -218,7 +220,7 @@ - + @@ -229,4 +231,4 @@ - + \ No newline at end of file diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/HomingBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/HomingBB.bpmn index 344b7d8761..f775c96db0 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/HomingBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/HomingBB.bpmn @@ -1,22 +1,10 @@ - + SequenceFlow_1x9usa6 - - SequenceFlow_1x9usa6 - SequenceFlow_0lc15i7 - import org.onap.so.bpmn.common.scripts.* -if(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")).getVariable("homingService") == "oof"){ - OofHoming oofHoming = new OofHoming() - oofHoming.callOof(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution"))) -}else{ - SniroHomingV2 sniroHoming = new SniroHomingV2() - SniroHoming.callSniro(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution"))) -} - - + SequenceFlow_1rf4vs8 @@ -29,9 +17,9 @@ if(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecu SequenceFlow_00nlh7l SequenceFlow_1rf4vs8 - import org.onap.so.bpmn.common.scripts.* + +ex.processSubflowsBPMNException(execution)]]> @@ -40,9 +28,9 @@ ex.processSubflowsBPMNException(execution) SequenceFlow_0kamg53 SequenceFlow_1o7154s - import org.onap.so.bpmn.common.scripts.* + +ex.processJavaException(execution)]]> SequenceFlow_0kamg53 @@ -55,18 +43,6 @@ ex.processJavaException(execution) - - SequenceFlow_1fipbmk - SequenceFlow_01apjvo - import org.onap.so.bpmn.common.scripts.* -if(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")).getVariable("homingService") == "oof"){ - OofHoming oofHoming = new OofHoming() - oofHoming.processHomingSolution(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution"))) -}else{ - SniroHomingV2 sniroHoming = new SniroHomingV2 () - sniroHoming.processSolution(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")), asyncResponse) -} - @@ -76,32 +52,37 @@ if(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecu - SequenceFlow_0lc15i7 + SequenceFlow_1a2sya6 SequenceFlow_1fipbmk - - + - SequenceFlow_01apjvo + SequenceFlow_1yfelf5 - + + SequenceFlow_1x9usa6 + SequenceFlow_1a2sya6 + + + + SequenceFlow_1fipbmk + SequenceFlow_1yfelf5 + + - + - - - - - + + - + @@ -141,53 +122,43 @@ if(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecu - - + + - - - - + + + + - - + + - - + + - - - - - - - - - - - - + + - + @@ -196,13 +167,26 @@ if(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecu - - - + + + + + + + + + + + + + + + + - + - + \ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/HomingV2.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/HomingV2.java new file mode 100644 index 0000000000..612051f903 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/HomingV2.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2018 Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.so.bpmn.buildingblock; + +import java.util.Map; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class HomingV2 { + + @Autowired + private OofHomingV2 oofHomingV2; + @Autowired + private SniroHomingV2 sniroHomingV2; + + private static final String HOMINGSOLUTION = "Homing_Solution"; + + public void callHoming(BuildingBlockExecution execution) { + if (isOof(execution)) { + oofHomingV2.callOof(execution); + } else { + sniroHomingV2.callSniro(execution); + } + } + + public void processSolution(BuildingBlockExecution execution, String asyncResponse) { + if (isOof(execution)) { + oofHomingV2.processSolution(execution, asyncResponse); + } else { + sniroHomingV2.processSolution(execution, asyncResponse); + } + } + + // Default solution is SNIRO. OOF gets called only if specified. + private boolean isOof(BuildingBlockExecution execution) { + for (Map params : execution.getGeneralBuildingBlock().getRequestContext().getRequestParameters() + .getUserParams()) { + if (params.containsKey(HOMINGSOLUTION) && params.get(HOMINGSOLUTION).equals("oof")) { + return true; + } + } + return false; + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index d8a6fc2e1d..e9dcdade9f 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -163,19 +163,6 @@ public class WorkflowAction { execution.setVariable("resourceId", resourceId); execution.setVariable("resourceType", resourceType); - if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { - List> userParams = sIRequest.getRequestDetails().getRequestParameters() - .getUserParams(); - for (Map params : userParams) { - if (params.containsKey(HOMINGSOLUTION)) { - execution.setVariable("homing", true); - execution.setVariable("callHoming", true); - execution.setVariable("homingSolution", params.get(HOMINGSOLUTION)); - execution.setVariable("homingService", params.get(HOMINGSOLUTION)); - } - } - } - if (aLaCarte) { if (orchFlows == null || orchFlows.isEmpty()) { orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, aLaCarte); @@ -270,9 +257,10 @@ public class WorkflowAction { logger.info("Sorting for Vlan Tagging"); flowsToExecute = sortExecutionPathByObjectForVlanTagging(flowsToExecute, requestAction); } + // By default, enable homing at VNF level for CREATEINSTANCE and ASSIGNINSTANCE if (resourceType == WorkflowType.SERVICE - && (requestAction.equals(CREATEINSTANCE) || requestAction.equals(ASSIGNINSTANCE)) - && !resourceCounter.stream().filter(x -> WorkflowType.VNF.equals(x.getResourceType())).collect(Collectors.toList()).isEmpty()) { + && (requestAction.equals(CREATEINSTANCE) || requestAction.equals(ASSIGNINSTANCE)) + && !resourceCounter.stream().filter(x -> WorkflowType.VNF.equals(x.getResourceType())).collect(Collectors.toList()).isEmpty()) { execution.setVariable("homing", true); execution.setVariable("calledHoming", false); } @@ -283,6 +271,20 @@ public class WorkflowAction { } } + // If the user set "Homing_Solution" to "none", disable homing, else if "Homing_Solution" is specified, enable it. + if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { + List> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams(); + for (Map params : userParams) { + if (params.containsKey(HOMINGSOLUTION)) { + if (params.get(HOMINGSOLUTION).equals("none")) { + execution.setVariable("homing", false); + } else { + execution.setVariable("homing", true); + } + } + } + } + if (flowsToExecute.isEmpty()) { throw new IllegalStateException("Macro did not come up with a valid execution path."); } -- cgit 1.2.3-korg From 1c554c3332ccf6be4e576e9159bbb0f901197379 Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Wed, 7 Nov 2018 17:46:59 +0100 Subject: bug fixing with reading dmaap message Change-Id: I259337e866d1b401b574ba427219157dfc4987af Issue-ID: SO-1191 Signed-off-by: Lukasz Muszkieta --- .../pnf/dmaap/JsonUtilForCorrelationId.java | 35 +++++++++------------ .../pnf/dmaap/PnfEventReadyDmaapClient.java | 2 ++ .../pnf/dmaap/JsonUtilForCorrelationIdTest.java | 36 ++++++++-------------- .../pnf/dmaap/PnfEventReadyDmaapClientTest.java | 22 ++++--------- 4 files changed, 35 insertions(+), 60 deletions(-) (limited to 'bpmn') diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/JsonUtilForCorrelationId.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/JsonUtilForCorrelationId.java index 90b48ab2c1..159298b4ad 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/JsonUtilForCorrelationId.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/JsonUtilForCorrelationId.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2018 Nokia. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -31,41 +33,32 @@ import java.util.Spliterator; public final class JsonUtilForCorrelationId { - private static final String JSON_HEADER = "pnfRegistrationFields"; private static final String JSON_CORRELATION_ID_FIELD_NAME = "correlationId"; static List parseJsonToGelAllCorrelationId(String json) { - List list = new ArrayList<>(); JsonElement je = new JsonParser().parse(json); - if (je.isJsonObject()) { - getCorrelationIdFromJsonObject(je.getAsJsonObject()).ifPresent(corr -> list.add(corr)); - } else { - JsonArray array = je.getAsJsonArray(); - Spliterator spliterator = array.spliterator(); - spliterator.forEachRemaining(jsonElement -> { - parseJsonElementToJsonObject(jsonElement) - .ifPresent(jsonObject -> getCorrelationIdFromJsonObject(jsonObject) - .ifPresent(correlationId -> list.add(correlationId))); - }); - } + JsonArray array = je.getAsJsonArray(); + List list = new ArrayList<>(); + Spliterator spliterator = array.spliterator(); + spliterator.forEachRemaining(jsonElement -> { + handleEscapedCharacters(jsonElement) + .ifPresent(jsonObject -> getCorrelationId(jsonObject) + .ifPresent(correlationId -> list.add(correlationId))); + }); return list; } - private static Optional parseJsonElementToJsonObject(JsonElement jsonElement) { + private static Optional handleEscapedCharacters(JsonElement jsonElement) { if (jsonElement.isJsonObject()) { return Optional.ofNullable(jsonElement.getAsJsonObject()); } return Optional.ofNullable(new JsonParser().parse(jsonElement.getAsString()).getAsJsonObject()); } - private static Optional getCorrelationIdFromJsonObject(JsonObject jsonObject) { - if (jsonObject.has(JSON_HEADER)) { - JsonObject jo = jsonObject.getAsJsonObject(JSON_HEADER); - if (jo.has(JSON_CORRELATION_ID_FIELD_NAME)) { - return Optional.ofNullable(jo.get(JSON_CORRELATION_ID_FIELD_NAME).getAsString()); - } + private static Optional getCorrelationId(JsonObject jsonObject) { + if (jsonObject.has(JSON_CORRELATION_ID_FIELD_NAME)) { + return Optional.ofNullable(jsonObject.get(JSON_CORRELATION_ID_FIELD_NAME).getAsString()); } return Optional.empty(); } - } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java index 518d7ff194..373e84bb9d 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2018 Nokia. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/JsonUtilForCorrelationIdTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/JsonUtilForCorrelationIdTest.java index 24d1810ac6..fde112b009 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/JsonUtilForCorrelationIdTest.java +++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/JsonUtilForCorrelationIdTest.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2018 Nokia. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,30 +26,18 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.List; import org.junit.Test; -import org.onap.so.bpmn.infrastructure.pnf.dmaap.JsonUtilForCorrelationId; public class JsonUtilForCorrelationIdTest { - private static final String JSON_EXAMPLE_WITH_CORRELATION_ID = "[\n" - + " {\n" - + " \"pnfRegistrationFields\" : {\n" - + " \"correlationId\" : \"corrTest1\",\n" - + " \"value\" : \"value1\"\n" - + " }\n" - + " },\n" - + " {\n" - + " \"pnfRegistrationFields\" : {\n" - + " \"correlationId\" : \"corrTest2\",\n" - + " \"value\" : \"value2\"\n" - + " }\n" - + " }\n" - + "]"; + private static final String JSON_EXAMPLE_WITH_CORRELATION_ID = "[{\"correlationId\": \"corrTest1\"," + + "\"key1\":\"value1\"},{\"correlationId\": \"corrTest2\",\"key2\":\"value2\"}]"; + + private static final String JSON_WITH_ONE_CORRELATION_ID = "[{\"correlationId\":\"corrTest3\"}]"; + + private static final String JSON_WITH_TWO_CORRELATION_ID_AND_ESCAPED_CHARACTERS = + "[\"{\\\"correlationId\\\":\\\"corrTest4\\\"}\", \"{\\\"correlationId\\\":\\\"corrTest5\\\"}\"]"; - private static final String JSON_EXAMPLE_WITH_CORRELATION_ID2 = "{\"pnfRegistrationFields\":{\"correlationId\":\"corrTest3\"}}"; - private static final String JSON_EXAMPLE_WITH_CORRELATION_ID3 = "[\"{\\\"pnfRegistrationFields\\\":" - + "{\\\"correlationId\\\":\\\"corrTest4\\\"}}\", \"{\\\"pnfRegistrationFields\\\":" - + "{\\\"correlationId\\\":\\\"corrTest5\\\"}}\"]"; - private static final String JSON_EXAMPLE_WITH_CORRELATION_ID4 = "{\"header\":{\"key\":\"value\"}}"; + private static final String JSON_WITH_NO_CORRELATION_ID = "[{\"key1\":\"value1\"}]"; @Test public void parseJsonSuccessful() { @@ -56,21 +46,21 @@ public class JsonUtilForCorrelationIdTest { assertThat(expectedResult).containsExactly("corrTest1", "corrTest2"); List expectedResult2 = JsonUtilForCorrelationId - .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID2); + .parseJsonToGelAllCorrelationId(JSON_WITH_ONE_CORRELATION_ID); assertThat(expectedResult2).containsExactly("corrTest3"); } @Test public void parseJsonWithEscapeCharacters_Successful() { List expectedResult = JsonUtilForCorrelationId - .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID3); + .parseJsonToGelAllCorrelationId(JSON_WITH_TWO_CORRELATION_ID_AND_ESCAPED_CHARACTERS); assertThat(expectedResult).containsExactly("corrTest4", "corrTest5"); } @Test public void parseJson_emptyListReturnedWhenNothingFound() { List expectedResult = JsonUtilForCorrelationId - .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID4); + .parseJsonToGelAllCorrelationId(JSON_WITH_NO_CORRELATION_ID); assertThat(expectedResult).isEmpty(); } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java index aab01c0a3e..1b0169d6d3 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java +++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2018 Nokia. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -55,22 +57,10 @@ public class PnfEventReadyDmaapClientTest { private static final String CORRELATION_ID = "corrTestId"; private static final String CORRELATION_ID_NOT_FOUND_IN_MAP = "otherCorrId"; - private static final String JSON_EXAMPLE_WITH_CORRELATION_ID = "[\n" - + " {\n" - + " \"pnfRegistrationFields\" : {\n" - + " \"correlationId\" : \"%s\",\n" - + " \"value\" : \"value1\"\n" - + " }\n" - + " },\n" - + " {\n" - + " \"pnfRegistrationFields\" : {\n" - + " \"correlationId\" : \"corr\",\n" - + " \"value\" : \"value2\"\n" - + " }\n" - + " }\n" - + "]"; - private static final String JSON_EXAMPLE_WITH_NO_CORRELATION_ID = - "{\"pnfRegistrationFields\":{\"field\":\"value\"}}"; + private static final String JSON_EXAMPLE_WITH_CORRELATION_ID = "[{\"correlationId\": \"%s\"," + + "\"value\":\"value1\"},{\"correlationId\": \"corr\",\"value\":\"value2\"}]"; + + private static final String JSON_EXAMPLE_WITH_NO_CORRELATION_ID = "[{\"key1\":\"value1\"}]"; private static final String HOST = "hostTest"; private static final int PORT = 1234; -- cgit 1.2.3-korg