SO refactor - extract Workflow type VNF 27/119127/5
authorpwielebs <piotr.wielebski@nokia.com>
Tue, 9 Mar 2021 11:56:26 +0000 (12:56 +0100)
committerpwielebs <piotr.wielebski@nokia.com>
Mon, 15 Mar 2021 14:37:02 +0000 (15:37 +0100)
Issue-ID: SO-3581
Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Change-Id: If5fe112f618c8fa8f7063df69af341df2db6b8f7

bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java [new file with mode: 0644]
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java

index d1da38f..ee4e56b 100644 (file)
@@ -46,6 +46,7 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types;
 import org.onap.so.bpmn.common.BBConstants;
+import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.VnfEBBLoader;
 import org.onap.so.bpmn.infrastructure.workflow.tasks.excpetion.VnfcMultipleRelationshipException;
 import org.onap.so.bpmn.infrastructure.workflow.tasks.utils.WorkflowResourceIdsUtils;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
@@ -143,6 +144,8 @@ public class WorkflowAction {
     private AaiResourceIdValidator aaiResourceIdValidator;
     @Autowired
     private ExecuteBuildingBlockBuilder executeBuildingBlockBuilder;
+    @Autowired
+    private VnfEBBLoader vnfEBBLoader;
 
     public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) {
         this.bbInputSetupUtils = bbInputSetupUtils;
@@ -340,10 +343,10 @@ public class WorkflowAction {
             resourceList.add(new Resource(WorkflowType.SERVICE, "", false));
         } else if (resourceType == WorkflowType.VNF && (REPLACEINSTANCE.equalsIgnoreCase(requestAction)
                 || ("recreateInstance".equalsIgnoreCase(requestAction)))) {
-            traverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(),
+            vnfEBBLoader.traverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(),
                     workflowResourceIds.getVnfId(), aaiResourceIds);
         } else if (resourceType == WorkflowType.VNF && "updateInstance".equalsIgnoreCase(requestAction)) {
-            customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(),
+            vnfEBBLoader.customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(),
                     workflowResourceIds.getVnfId(), aaiResourceIds);
         } else {
             buildAndThrowException(execution, "Current Macro Request is not supported");
@@ -404,8 +407,6 @@ public class WorkflowAction {
         return containsService;
     }
 
-
-
     private List<ExecuteBuildingBlock> loadExecuteBuildingBlocks(DelegateExecution execution, String requestId,
             String errorMessage) {
         List<ExecuteBuildingBlock> flowsToExecute;
@@ -1092,116 +1093,7 @@ public class WorkflowAction {
         }
     }
 
-    private void traverseAAIVnf(DelegateExecution execution, List<Resource> resourceList, 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);
-            resourceList.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.VNF, vnf.getVnfId()));
-                        resourceList.add(new Resource(WorkflowType.VNF, vnf.getVnfId(), false));
-                        if (vnf.getVfModules() != null) {
-                            for (VfModule vfModule : vnf.getVfModules()) {
-                                aaiResourceIds.add(new Pair<>(WorkflowType.VFMODULE, vfModule.getVfModuleId()));
-                                resourceList.add(new Resource(WorkflowType.VFMODULE, vfModule.getVfModuleId(), false));
-                                findConfigurationsInsideVfModule(execution, vnf.getVnfId(), vfModule.getVfModuleId(),
-                                        resourceList, aaiResourceIds);
-                            }
-                        }
-                        if (vnf.getVolumeGroups() != null) {
-                            for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf
-                                    .getVolumeGroups()) {
-                                aaiResourceIds
-                                        .add(new Pair<>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId()));
-                                resourceList.add(
-                                        new Resource(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId(), false));
-                            }
-                        }
-                        break;
-                    }
-                }
-            }
-        } catch (Exception ex) {
-            logger.error("Exception in traverseAAIVnf", ex);
-            buildAndThrowException(execution,
-                    "Could not find existing Vnf or related Instances to execute the request on.");
-        }
-    }
-
-    private void customTraverseAAIVnf(DelegateExecution execution, List<Resource> resourceList, 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);
-            resourceList.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.VNF, vnf.getVnfId()));
-
-                        String vnfCustomizationUUID =
-                                bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
-                        resourceList.add(new Resource(WorkflowType.VNF, vnfCustomizationUUID, false));
-
-                        if (vnf.getVfModules() != null) {
-                            for (VfModule vfModule : vnf.getVfModules()) {
-                                aaiResourceIds.add(new Pair<>(WorkflowType.VFMODULE, vfModule.getVfModuleId()));
-                                resourceList.add(new Resource(WorkflowType.VFMODULE, vfModule.getVfModuleId(), false));
-                                findConfigurationsInsideVfModule(execution, vnf.getVnfId(), vfModule.getVfModuleId(),
-                                        resourceList, aaiResourceIds);
-                            }
-                        }
-                        if (vnf.getVolumeGroups() != null) {
-                            for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf
-                                    .getVolumeGroups()) {
-                                aaiResourceIds
-                                        .add(new Pair<>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId()));
-                                resourceList.add(
-                                        new Resource(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId(), false));
-                            }
-                        }
-                        break;
-                    }
-                }
-            }
-        } catch (Exception ex) {
-            logger.error("Exception in customTraverseAAIVnf", 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> resourceList, 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.CONFIGURATION, config.get().getConfigurationId()));
-                        resourceList.add(
-                                new Resource(WorkflowType.CONFIGURATION, config.get().getConfigurationId(), false));
-                    }
-                }
-            }
-        } catch (Exception ex) {
-            logger.error("Exception in findConfigurationsInsideVfModule", ex);
-            buildAndThrowException(execution, "Failed to find Configuration object from the vfModule.");
-        }
-    }
 
     protected WorkflowResourceIds populateResourceIdsFromApiHandler(DelegateExecution execution) {
         return WorkflowResourceIdsUtils.getWorkflowResourceIdsFromExecution(execution);
index 5e16097..9128e9e 100644 (file)
@@ -35,7 +35,7 @@ public final class WorkflowActionConstants {
     static final String USER_PARAM_SERVICE = "service";
     static final String CREATE_INSTANCE = "createInstance";
     static final String FABRIC_CONFIGURATION = "FabricConfiguration";
-    static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage";
+    public static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage";
     static final String SERVICE = "Service";
     static final String CONTROLLER = "Controller";
     static final String NETWORKCOLLECTION = "NetworkCollection";
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java
new file mode 100644 (file)
index 0000000..7db93e7
--- /dev/null
@@ -0,0 +1,185 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Nokia
+ * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
+ * Modifications Copyright (c) 2021 Nokia
+ * ================================================================================
+ * Modifications Copyright (c) 2020 Tech Mahindra
+ * ================================================================================
+ * 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.workflow.tasks.ebb.loader;
+
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.javatuples.Pair;
+import org.onap.aai.domain.yang.ServiceInstance;
+import org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider;
+import org.onap.aaiclient.client.aai.entities.AAIResultWrapper;
+import org.onap.aaiclient.client.aai.entities.Relationships;
+import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource;
+import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionExtractResourcesAAI;
+import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
+import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
+import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Optional;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE;
+
+@Component
+public class VnfEBBLoader {
+
+    private static final Logger logger = LoggerFactory.getLogger(VnfEBBLoader.class);
+
+    private final BBInputSetupUtils bbInputSetupUtils;
+    private final BBInputSetup bbInputSetup;
+    private final WorkflowActionExtractResourcesAAI workflowActionUtils;
+    private final ExceptionBuilder exceptionBuilder;
+
+    VnfEBBLoader(BBInputSetupUtils bbInputSetupUtils, BBInputSetup bbInputSetup,
+            WorkflowActionExtractResourcesAAI workflowActionUtils, ExceptionBuilder exceptionBuilder) {
+        this.bbInputSetupUtils = bbInputSetupUtils;
+        this.bbInputSetup = bbInputSetup;
+        this.workflowActionUtils = workflowActionUtils;
+        this.exceptionBuilder = exceptionBuilder;
+    }
+
+
+    public void traverseAAIVnf(DelegateExecution execution, List<Resource> resourceList, 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);
+            resourceList.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.VNF, vnf.getVnfId()));
+                        resourceList.add(new Resource(WorkflowType.VNF, vnf.getVnfId(), false));
+                        if (vnf.getVfModules() != null) {
+                            for (VfModule vfModule : vnf.getVfModules()) {
+                                aaiResourceIds.add(new Pair<>(WorkflowType.VFMODULE, vfModule.getVfModuleId()));
+                                resourceList.add(new Resource(WorkflowType.VFMODULE, vfModule.getVfModuleId(), false));
+                                findConfigurationsInsideVfModule(execution, vnf.getVnfId(), vfModule.getVfModuleId(),
+                                        resourceList, aaiResourceIds);
+                            }
+                        }
+                        if (vnf.getVolumeGroups() != null) {
+                            for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf
+                                    .getVolumeGroups()) {
+                                aaiResourceIds
+                                        .add(new Pair<>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId()));
+                                resourceList.add(
+                                        new Resource(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId(), false));
+                            }
+                        }
+                        break;
+                    }
+                }
+            }
+        } catch (Exception ex) {
+            logger.error("Exception in traverseAAIVnf", ex);
+            buildAndThrowException(execution,
+                    "Could not find existing Vnf or related Instances to execute the request on.");
+        }
+    }
+
+    public void customTraverseAAIVnf(DelegateExecution execution, List<Resource> resourceList, 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);
+            resourceList.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.VNF, vnf.getVnfId()));
+
+                        String vnfCustomizationUUID =
+                                bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
+                        resourceList.add(new Resource(WorkflowType.VNF, vnfCustomizationUUID, false));
+
+                        if (vnf.getVfModules() != null) {
+                            for (VfModule vfModule : vnf.getVfModules()) {
+                                aaiResourceIds.add(new Pair<>(WorkflowType.VFMODULE, vfModule.getVfModuleId()));
+                                resourceList.add(new Resource(WorkflowType.VFMODULE, vfModule.getVfModuleId(), false));
+                                findConfigurationsInsideVfModule(execution, vnf.getVnfId(), vfModule.getVfModuleId(),
+                                        resourceList, aaiResourceIds);
+                            }
+                        }
+                        if (vnf.getVolumeGroups() != null) {
+                            for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf
+                                    .getVolumeGroups()) {
+                                aaiResourceIds
+                                        .add(new Pair<>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId()));
+                                resourceList.add(
+                                        new Resource(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId(), false));
+                            }
+                        }
+                        break;
+                    }
+                }
+            }
+        } catch (Exception ex) {
+            logger.error("Exception in customTraverseAAIVnf", 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> resourceList, 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.CONFIGURATION, config.get().getConfigurationId()));
+                        resourceList.add(
+                                new Resource(WorkflowType.CONFIGURATION, config.get().getConfigurationId(), false));
+                    }
+                }
+            }
+        } catch (Exception ex) {
+            logger.error("Exception in findConfigurationsInsideVfModule", ex);
+            buildAndThrowException(execution, "Failed to find Configuration object from the vfModule.");
+        }
+    }
+
+    private void buildAndThrowException(DelegateExecution execution, String msg) {
+        logger.error(msg);
+        execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg);
+        exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg);
+    }
+}
index d0cd4b0..26e0d2f 100644 (file)
@@ -78,6 +78,7 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types;
 import org.onap.so.bpmn.BaseTaskTest;
+import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.VnfEBBLoader;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
@@ -136,6 +137,10 @@ public class WorkflowActionTest extends BaseTaskTest {
     @Spy
     protected ExecuteBuildingBlockBuilder executeBuildingBlockBuilder;
 
+    @InjectMocks
+    @Spy
+    protected VnfEBBLoader vnfEBBLoaderSpy;
+
     @Rule
     public ExpectedException thrown = ExpectedException.none();