From 01176bd6522e942175ce8429f74ef29e643142b8 Mon Sep 17 00:00:00 2001 From: "Kalkere Ramesh, Sharan (sk720x)" Date: Tue, 11 Dec 2018 12:12:32 -0500 Subject: Skip cloud regions and fix macro changed aai create tasks to use env instead of urn prop write serviceInstanceId from resource when exec is null Change-Id: I2c0acbeeded2b8a4b0afb0f27d65e24fa48b907b Issue-ID: SO-1329 Signed-off-by: Kalkere Ramesh, Sharan (sk720x) --- .../org/onap/so/bpmn/core/UrnPropertiesReader.java | 14 ++++++++++++++ .../bpmn/infrastructure/aai/tasks/AAICreateTasks.java | 19 +++++++++++++++++-- .../infrastructure/workflow/tasks/WorkflowAction.java | 5 ++++- .../src/test/java/org/onap/so/bpmn/BaseTaskTest.java | 16 ++++++---------- .../infrastructure/aai/tasks/AAICreateTasksTest.java | 12 ++++++++++++ .../src/test/resources/application-test.yaml | 1 + 6 files changed, 54 insertions(+), 13 deletions(-) (limited to 'bpmn') 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 750cd241e8..5100085020 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 @@ -87,6 +87,20 @@ public class UrnPropertiesReader { } } + /** + * Return the String array URN property value from the environment object + * @param variableName URN property name + * @return URN property value + */ + + public static String[] getVariablesArray(String variableName){ + if (environment != null) { + return environment.getProperty(variableName, String[].class); + } else { + return null; + } + } + public static String getVariable(String variableName, String defaultValue) { return Optional.ofNullable(getVariable(variableName)).orElse(defaultValue); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java index 54ee26d0ad..4a3cb01b74 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java @@ -20,8 +20,13 @@ package org.onap.so.bpmn.infrastructure.aai.tasks; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + import org.camunda.bpm.engine.delegate.BpmnError; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.core.UrnPropertiesReader; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; @@ -52,6 +57,7 @@ import org.onap.so.db.catalog.beans.OrchestrationStatus; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @Component @@ -78,6 +84,8 @@ public class AAICreateTasks { private AAIVpnBindingResources aaiVpnBindingResources; @Autowired private AAIConfigurationResources aaiConfigurationResources; + @Autowired + private Environment env; public void createServiceInstance(BuildingBlockExecution execution) { try { @@ -356,8 +364,15 @@ public class AAICreateTasks { */ public void connectVnfToCloudRegion(BuildingBlockExecution execution) { try { - GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); - aaiVnfResources.connectVnfToCloudRegion(vnf, execution.getGeneralBuildingBlock().getCloudRegion()); + boolean cloudRegionsToSkip = false; + String[] cloudRegions = env.getProperty("mso.bpmn.cloudRegionIdsToSkipAddingVnfEdgesTo", String[].class); + if (cloudRegions != null){ + cloudRegionsToSkip = Arrays.stream(cloudRegions).anyMatch(execution.getGeneralBuildingBlock().getCloudRegion().getLcpCloudRegionId()::equals); + } + if(!cloudRegionsToSkip) { + GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); + aaiVnfResources.connectVnfToCloudRegion(vnf, execution.getGeneralBuildingBlock().getCloudRegion()); + } } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } 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 ac31bc75c0..e04043a352 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 @@ -145,7 +145,7 @@ public class WorkflowAction { final String apiVersion = (String) execution.getVariable(G_APIVERSION); final String uri = (String) execution.getVariable(G_URI); final String vnfType = (String) execution.getVariable(VNF_TYPE); - final String serviceInstanceId = (String) execution.getVariable("serviceInstanceId"); + String serviceInstanceId = (String) execution.getVariable("serviceInstanceId"); List orchFlows = (List) execution.getVariable(G_ORCHESTRATION_FLOW); List flowsToExecute = new ArrayList<>(); WorkflowResourceIds workflowResourceIds = populateResourceIdsFromApiHandler(execution); @@ -177,6 +177,9 @@ public class WorkflowAction { } else { resourceId = resource.getResourceId(); } + if((serviceInstanceId == null || serviceInstanceId.equals("")) && resourceType == WorkflowType.SERVICE){ + serviceInstanceId = resourceId; + } execution.setVariable("resourceId", resourceId); execution.setVariable("resourceType", resourceType); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java index f83c968c93..7715de9672 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java @@ -21,9 +21,7 @@ package org.onap.so.bpmn; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; -import org.onap.so.bpmn.buildingblock.SniroHomingV2; import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils; @@ -53,13 +51,9 @@ import org.onap.so.client.orchestration.SDNCVfModuleResources; import org.onap.so.client.orchestration.SDNCVnfResources; import org.onap.so.client.orchestration.VnfAdapterVfModuleResources; import org.onap.so.client.orchestration.VnfAdapterVolumeGroupResources; -import org.onap.so.client.sdnc.SDNCClient; -import org.onap.so.client.sniro.SniroClient; import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.client.RequestsDbClient; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.core.env.Environment; @RunWith(MockitoJUnitRunner.Silent.class) public abstract class BaseTaskTest extends TestDataSetup { @@ -150,7 +144,9 @@ public abstract class BaseTaskTest extends TestDataSetup { @Mock protected ExceptionBuilder exceptionUtil; - @Mock - protected WorkflowActionExtractResourcesAAI workflowActionUtils; - + @Mock + protected WorkflowActionExtractResourcesAAI workflowActionUtils; + + @Mock + protected Environment env; } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java index b2e46f6130..da7e727488 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java @@ -426,6 +426,18 @@ public class AAICreateTasksTest extends BaseTaskTest{ verify(aaiVnfResources, times(1)).connectVnfToCloudRegion(genericVnf, gBBInput.getCloudRegion()); } + @Test + public void connectNoneToVnfToCloudRegionTest() throws Exception { + String[] arr = new String[1]; + arr[0] = "test25Region2"; + doReturn(arr).when(env).getProperty("mso.bpmn.cloudRegionIdsToSkipAddingVnfEdgesTo", String[].class); + gBBInput = execution.getGeneralBuildingBlock(); + gBBInput.getCloudRegion().setLcpCloudRegionId("test25Region2"); + doNothing().when(aaiVnfResources).connectVnfToCloudRegion(genericVnf, gBBInput.getCloudRegion()); + aaiCreateTasks.connectVnfToCloudRegion(execution); + verify(aaiVnfResources, times(0)).connectVnfToCloudRegion(genericVnf, gBBInput.getCloudRegion()); + } + @Test public void connectVnfTenantTest() throws Exception { gBBInput = execution.getGeneralBuildingBlock(); diff --git a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml index 210854e4d7..3d45caddce 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml +++ b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml @@ -93,6 +93,7 @@ mso: bpmn: optimisticlockingexception: retrycount: '3' + cloudRegionIdsToSkipAddingVnfEdgesTo: test25Region1,test25Region2,test25Region99 callbackRetryAttempts: '5' catalog: db: -- cgit 1.2.3-korg