summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java72
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java38
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java3
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java105
-rw-r--r--bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/VnfMacroReplace.json25
5 files changed, 242 insertions, 1 deletions
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 294fd56cfd..4eb4ffec2f 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
@@ -50,6 +50,10 @@ import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource;
+import org.onap.so.client.aai.AAICommonObjectMapperProvider;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.aai.entities.AAIResultWrapper;
+import org.onap.so.client.aai.entities.Relationships;
import org.onap.so.client.exception.ExceptionBuilder;
import org.onap.so.client.orchestration.AAIConfigurationResources;
import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
@@ -121,7 +125,10 @@ public class WorkflowAction {
@Autowired
private AAIConfigurationResources aaiConfigurationResources;
@Autowired
- private Environment environment;
+ private WorkflowActionExtractResourcesAAI workflowActionUtils;
+
+ @Autowired
+ private Environment environment;
private String defaultCloudOwner = "org.onap.so.cloud-owner";
public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) {
@@ -249,6 +256,8 @@ public class WorkflowAction {
} else if (resourceType == WorkflowType.SERVICE
&& requestAction.equalsIgnoreCase("deactivateInstance")) {
resourceCounter.add(new Resource(WorkflowType.SERVICE,"",false));
+ } else if (resourceType == WorkflowType.VNF && (requestAction.equalsIgnoreCase("replaceInstance") || (requestAction.equalsIgnoreCase("recreateInstance")))) {
+ traverseAAIVnf(execution, resourceCounter, workflowResourceIds.getServiceInstanceId(), workflowResourceIds.getVnfId(), aaiResourceIds);
} else {
buildAndThrowException(execution, "Current Macro Request is not supported");
}
@@ -550,6 +559,67 @@ public class WorkflowAction {
}
}
+ private void traverseAAIVnf(DelegateExecution execution, List<Resource> resourceCounter, String serviceId, String vnfId,
+ List<Pair<WorkflowType, String>> aaiResourceIds) {
+ try{
+ ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceId);
+ org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = bbInputSetup
+ .getExistingServiceInstance(serviceInstanceAAI);
+ resourceCounter.add(new Resource(WorkflowType.SERVICE,serviceInstanceMSO.getServiceInstanceId(),false));
+ if (serviceInstanceMSO.getVnfs() != null) {
+ for (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf : serviceInstanceMSO
+ .getVnfs()) {
+ if(vnf.getVnfId().equals(vnfId)){
+ aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VNF, vnf.getVnfId()));
+ resourceCounter.add(new Resource(WorkflowType.VNF,vnf.getVnfId(),false));
+ if (vnf.getVfModules() != null) {
+ for (VfModule vfModule : vnf.getVfModules()) {
+ aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VFMODULE, vfModule.getVfModuleId()));
+ resourceCounter.add(new Resource(WorkflowType.VFMODULE,vfModule.getVfModuleId(),false));
+ findConfigurationsInsideVfModule(execution, vnf.getVnfId(), vfModule.getVfModuleId(), resourceCounter, aaiResourceIds);
+ }
+ }
+ if (vnf.getVolumeGroups() != null) {
+ for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf
+ .getVolumeGroups()) {
+ aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId()));
+ resourceCounter.add(new Resource(WorkflowType.VOLUMEGROUP,volumeGroup.getVolumeGroupId(),false));
+ }
+ }
+ break;
+ }
+ }
+ }
+ } catch (Exception ex) {
+ buildAndThrowException(execution,
+ "Could not find existing Vnf or related Instances to execute the request on.");
+ }
+ }
+
+ private void findConfigurationsInsideVfModule(DelegateExecution execution, String vnfId, String vfModuleId, List<Resource> resourceCounter,
+ List<Pair<WorkflowType, String>> aaiResourceIds) {
+ try{
+ org.onap.aai.domain.yang.VfModule aaiVfModule = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId);
+ AAIResultWrapper vfModuleWrapper = new AAIResultWrapper(
+ new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiVfModule));
+ Optional<Relationships> relationshipsOp;
+ relationshipsOp = vfModuleWrapper.getRelationships();
+ if(relationshipsOp.isPresent()) {
+ relationshipsOp = workflowActionUtils.extractRelationshipsVnfc(relationshipsOp.get());
+ if(relationshipsOp.isPresent()){
+ Optional<Configuration> config = workflowActionUtils.extractRelationshipsConfiguration(relationshipsOp.get());
+ if(config.isPresent()){
+ aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.CONFIGURATION, config.get().getConfigurationId()));
+ resourceCounter.add(new Resource(WorkflowType.CONFIGURATION, config.get().getConfigurationId(), false));
+ }
+ }
+ }
+ }catch (Exception ex){
+ buildAndThrowException(execution,
+ "Failed to find Configuration object from the vfModule.");
+ }
+ }
+
protected boolean traverseUserParamsService(DelegateExecution execution, List<Resource> resourceCounter,
ServiceInstancesRequest sIRequest, String requestAction)
throws IOException {
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java
new file mode 100644
index 0000000000..81609d1ddd
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java
@@ -0,0 +1,38 @@
+package org.onap.so.bpmn.infrastructure.workflow.tasks;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.aai.entities.AAIResultWrapper;
+import org.onap.so.client.aai.entities.Relationships;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+public class WorkflowActionExtractResourcesAAI {
+ private static final Logger logger = LoggerFactory.getLogger(WorkflowActionExtractResourcesAAI.class);
+
+ public Optional<Configuration> extractRelationshipsConfiguration(Relationships relationships) {
+ List<AAIResultWrapper> configurations = relationships.getByType(AAIObjectType.CONFIGURATION);
+ for(AAIResultWrapper configWrapper : configurations) {
+ Optional<Configuration> config = configWrapper.asBean(Configuration.class);
+ if(config.isPresent()){
+ return config;
+ }
+ }
+ return Optional.empty();
+ }
+
+ public Optional<Relationships> extractRelationshipsVnfc(Relationships relationships) {
+ List<AAIResultWrapper> vnfcs = relationships.getByType(AAIObjectType.VNFC);
+ for(AAIResultWrapper vnfcWrapper : vnfcs){
+ if(vnfcWrapper.getRelationships().isPresent()){
+ return vnfcWrapper.getRelationships();
+ }
+ }
+ return Optional.empty();
+ }
+}
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 21b89c3731..f83c968c93 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
@@ -27,6 +27,7 @@ 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;
+import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionExtractResourcesAAI;
import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
@@ -149,5 +150,7 @@ public abstract class BaseTaskTest extends TestDataSetup {
@Mock
protected ExceptionBuilder exceptionUtil;
+ @Mock
+ protected WorkflowActionExtractResourcesAAI workflowActionUtils;
}
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 c3f3bb2139..5699c94137 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
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
@@ -52,15 +53,19 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.onap.aai.domain.yang.GenericVnf;
import org.onap.aai.domain.yang.L3Network;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.aai.domain.yang.RelationshipList;
import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.aai.domain.yang.VfModule;
import org.onap.aai.domain.yang.VfModules;
import org.onap.aai.domain.yang.VolumeGroup;
import org.onap.so.bpmn.BaseTaskTest;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
+import org.onap.so.client.aai.entities.Relationships;
import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
import org.onap.so.db.catalog.beans.CollectionResource;
import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
@@ -84,11 +89,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public class WorkflowActionTest extends BaseTaskTest {
+
@Mock
protected Environment environment;
@InjectMocks
protected WorkflowAction workflowAction;
private DelegateExecution execution;
+
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -685,6 +692,104 @@ public class WorkflowActionTest extends BaseTaskTest {
,"DeactivateServiceInstanceBB","UnassignServiceInstanceBB");
}
+ @Test
+ public void selectExecutionListVnfMacroRecreateTest() throws Exception{
+ String gAction = "recreateInstance";
+ String resource = "Vnf";
+ execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
+ execution.setVariable("requestAction", gAction);
+ String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/VnfMacroReplace.json")));
+ execution.setVariable("bpmnRequest", bpmnRequest);
+ execution.setVariable("aLaCarte", false);
+ execution.setVariable("apiVersion", "7");
+ execution.setVariable("requestUri", "v7/serviceInstances/123/vnfs/1234/recreate");
+ execution.setVariable("serviceInstanceId", "123");
+ execution.setVariable("vnfId", "1234");
+
+ NorthBoundRequest northBoundRequest = new NorthBoundRequest();
+ List<OrchestrationFlow> orchFlows = createFlowList("AAICheckVnfInMaintBB","AAISetVnfInMaintBB","DeactivateFabricConfigurationBB", "UnassignFabricConfigurationBB", "DeactivateVfModuleBB","DeleteVfModuleBB","DeactivateVnfBB","CreateVfModuleBB"
+ ,"ActivateVfModuleBB","AssignFabricConfigurationBB","ActivateFabricConfigurationBB","ActivateVnfBB","SDNOVnfHealthCheckBB","AAIUnsetVnfInMaintBB");
+ northBoundRequest.setOrchestrationFlowList(orchFlows);
+
+ ServiceInstance serviceInstanceAAI = new ServiceInstance();
+ serviceInstanceAAI.setServiceInstanceId("123");
+ org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = new org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance();
+ org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf = new org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf();
+ vnf.setVnfId("1234");
+
+ org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule = new org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule();
+ vfModule.setVfModuleId("vfModule1");
+ vnf.getVfModules().add(vfModule);
+ org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule2 = new org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule();
+ vfModule2.setVfModuleId("vfModule2");
+ vnf.getVfModules().add(vfModule2);
+
+ serviceInstanceMSO.getVnfs().add(vnf);
+
+ doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("123");
+ doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI);
+ when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction,resource,false,"cloud-owner")).thenReturn(northBoundRequest);
+ workflowAction.selectExecutionList(execution);
+ List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
+ assertEqualsBulkFlowName(ebbs,"AAICheckVnfInMaintBB","AAISetVnfInMaintBB","DeactivateVfModuleBB","DeactivateVfModuleBB","DeleteVfModuleBB","DeleteVfModuleBB","DeactivateVnfBB"
+ ,"CreateVfModuleBB","CreateVfModuleBB","ActivateVfModuleBB","ActivateVfModuleBB","ActivateVnfBB","SDNOVnfHealthCheckBB","AAIUnsetVnfInMaintBB");
+ }
+
+ @Test
+ public void selectExecutionListVnfMacroReplaceTest() throws Exception{
+ String gAction = "replaceInstance";
+ String resource = "Vnf";
+ execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
+ execution.setVariable("requestAction", gAction);
+ String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/VnfMacroReplace.json")));
+ execution.setVariable("bpmnRequest", bpmnRequest);
+ execution.setVariable("aLaCarte", false);
+ execution.setVariable("apiVersion", "7");
+ execution.setVariable("requestUri", "v7/serviceInstances/123/vnfs/1234/replace");
+ execution.setVariable("serviceInstanceId", "123");
+ execution.setVariable("vnfId", "1234");
+
+ NorthBoundRequest northBoundRequest = new NorthBoundRequest();
+ List<OrchestrationFlow> orchFlows = createFlowList("AAICheckVnfInMaintBB","AAISetVnfInMaintBB","DeactivateFabricConfigurationBB","UnassignFabricConfigurationBB","DeactivateVfModuleBB","DeleteVfModuleBB"
+ ,"DeactivateVnfBB","ChangeModelVfModuleBB","CreateVfModuleBB","ActivateVfModuleBB","AssignFabricConfigurationBB","ActivateFabricConfigurationBB","ChangeModelVnfBB","ActivateVnfBB","ChangeModelServiceInstanceBB","SDNOVnfHealthCheckBB","AAIUnsetVnfInMaintBB");
+ northBoundRequest.setOrchestrationFlowList(orchFlows);
+
+ ServiceInstance serviceInstanceAAI = new ServiceInstance();
+ serviceInstanceAAI.setServiceInstanceId("123");
+ org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = new org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance();
+ org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf = new org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf();
+ vnf.setVnfId("1234");
+ org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule = new org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule();
+ vfModule.setVfModuleId("vfModule1");
+ vnf.getVfModules().add(vfModule);
+ org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule2 = new org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule();
+ vfModule2.setVfModuleId("vfModule2");
+ vnf.getVfModules().add(vfModule2);
+ serviceInstanceMSO.getVnfs().add(vnf);
+ VfModule vfModuleAAI = new VfModule();
+ vfModuleAAI.setVfModuleId("vfModule2");
+ RelationshipList relationshipList = new RelationshipList();
+ Relationship relationship = new Relationship();
+ relationshipList.getRelationship().add(relationship);
+ vfModuleAAI.setRelationshipList(relationshipList);
+ Relationships relationships = new Relationships("abc");
+ Configuration config = new Configuration();
+ config.setConfigurationId("configId");
+ Optional<Configuration> configOp = Optional.of(config);
+ Optional<Relationships> relationshipsOp = Optional.of(relationships);
+
+ doReturn(relationshipsOp).when(workflowActionUtils).extractRelationshipsVnfc(isA(Relationships.class));
+ doReturn(configOp).when(workflowActionUtils).extractRelationshipsConfiguration(isA(Relationships.class));
+ doReturn(vfModuleAAI).when(bbSetupUtils).getAAIVfModule("1234", "vfModule2");
+ doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("123");
+ doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI);
+ when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction,resource,false,"cloud-owner")).thenReturn(northBoundRequest);
+ workflowAction.selectExecutionList(execution);
+ List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
+ assertEqualsBulkFlowName(ebbs,"AAICheckVnfInMaintBB","AAISetVnfInMaintBB", "DeactivateFabricConfigurationBB", "UnassignFabricConfigurationBB", "DeactivateVfModuleBB","DeactivateVfModuleBB","DeleteVfModuleBB","DeleteVfModuleBB","DeactivateVnfBB"
+ ,"ChangeModelVfModuleBB" ,"ChangeModelVfModuleBB" , "CreateVfModuleBB","CreateVfModuleBB", "ActivateVfModuleBB","ActivateVfModuleBB", "AssignFabricConfigurationBB", "ActivateFabricConfigurationBB", "ChangeModelVnfBB", "ActivateVnfBB","ChangeModelServiceInstanceBB","SDNOVnfHealthCheckBB","AAIUnsetVnfInMaintBB");
+ }
+
@Ignore
@Test
public void selectExecutionListNetworkCollectionMacroCreate() throws Exception{
diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/VnfMacroReplace.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/VnfMacroReplace.json
new file mode 100644
index 0000000000..5c34903e30
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/VnfMacroReplace.json
@@ -0,0 +1,25 @@
+{
+ "requestDetails": {
+ "modelInfo": {
+ "modelType": "vnf",
+ "modelInvariantId": "2b80014c-851a-4051-a2f0-2994fcf26164",
+ "modelVersionId": "038111e7-dfb6-4875-ba06-d1fc1306b471",
+ "modelName": "Resource",
+ "modelVersion": "4.0",
+ "modelCustomizationName": "Resource 0",
+ "modelCustomizationId": "5769aaa9-84f0-4b9d-bf8a-d891e5c461e1"
+ },
+ "cloudConfiguration": {
+ "cloudOwner": "cloud-owner",
+ "lcpCloudRegionId": "abc3",
+ "tenantId": "ab33582f8d3948078dc8c18d6834bf75"
+ },
+ "requestInfo": {
+ "source": "VID",
+ "requestorId": "test"
+ },
+ "requestParameters": {
+ "testApi": "GR_API"
+ }
+ }
+} \ No newline at end of file