Code changes in BPMN infra for RAN Slice Use case
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / workflow / tasks / WorkflowAction.java
index ef32ac5..82f44bc 100755 (executable)
@@ -28,6 +28,8 @@
 
 package org.onap.so.bpmn.infrastructure.workflow.tasks;
 
+import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.IS_CHILD_PROCESS;
+import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.PARENT_CORRELATION_ID;
 import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.ASSIGN_INSTANCE;
 import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CONTROLLER;
 import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE;
@@ -68,7 +70,9 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
 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.infrastructure.workflow.tasks.ebb.loader.NetworkSliceSubnetEBBLoader;
 import org.onap.so.bpmn.common.BBConstants;
+import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.PnfEBBLoader;
 import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.ServiceEBBLoader;
 import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.VnfEBBLoader;
 import org.onap.so.bpmn.infrastructure.workflow.tasks.excpetion.VnfcMultipleRelationshipException;
@@ -97,6 +101,7 @@ import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import org.onap.so.serviceinstancebeans.InstanceDirection;
 
 @Component
 public class WorkflowAction {
@@ -108,7 +113,7 @@ public class WorkflowAction {
     private static final String VNF_TYPE = "vnfType";
     private static final String CONFIGURATION = "Configuration";
     private static final String SUPPORTEDTYPES =
-            "vnfs|vfModules|networks|networkCollections|volumeGroups|serviceInstances|instanceGroups";
+            "vnfs|pnfs|cnfs|vfModules|networks|networkCollections|volumeGroups|serviceInstances|instanceGroups|NetworkSliceSubnet";
     private static final String HOMINGSOLUTION = "Homing_Solution";
     private static final String SERVICE_TYPE_TRANSPORT = "TRANSPORT";
     private static final String SERVICE_TYPE_BONDING = "BONDING";
@@ -137,7 +142,11 @@ public class WorkflowAction {
     @Autowired
     private VnfEBBLoader vnfEBBLoader;
     @Autowired
+    private PnfEBBLoader pnfEBBLoader;
+    @Autowired
     private ServiceEBBLoader serviceEBBLoader;
+    @Autowired
+    private NetworkSliceSubnetEBBLoader networkSliceSubnetEBBLoader;
 
     public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) {
         this.bbInputSetupUtils = bbInputSetupUtils;
@@ -290,9 +299,15 @@ public class WorkflowAction {
         List<Resource> resourceList = new ArrayList<>();
         List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>();
 
-        if (resourceType == WorkflowType.SERVICE || isVNFCreate(resourceType, requestAction)) {
+        if (resourceType == WorkflowType.SERVICE || isVNFCreate(resourceType, requestAction)
+                || isPNFCreate(resourceType, requestAction)) {
             resourceList = serviceEBBLoader.getResourceListForService(sIRequest, requestAction, execution,
                     serviceInstanceId, resourceId, aaiResourceIds);
+        } else if (resourceType == WorkflowType.NETWORK_SLICE_SUBNET) {
+            resourceList = networkSliceSubnetEBBLoader.setNetworkSliceSubnetResource(resourceId);
+        } else if (isPNFDelete(resourceType, requestAction)) {
+            pnfEBBLoader.traverseAAIPnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), resourceId,
+                    aaiResourceIds);
         } else if (resourceType == WorkflowType.VNF
                 && (DELETE_INSTANCE.equalsIgnoreCase(requestAction) || REPLACEINSTANCE.equalsIgnoreCase(requestAction)
                         || (RECREATE_INSTANCE.equalsIgnoreCase(requestAction)))) {
@@ -351,6 +366,19 @@ public class WorkflowAction {
                 log += ", Action: " + block.getBuildingBlock().getBpmnAction();
             logger.info(log);
         }
+
+        RelatedInstanceList[] instanceList = sIRequest.getRequestDetails().getRelatedInstanceList();
+        execution.setVariable(IS_CHILD_PROCESS, Boolean.FALSE);
+        if (instanceList != null) {
+            for (RelatedInstanceList relatedInstanceList : instanceList) {
+                RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
+                if (InstanceDirection.source.equals(relatedInstance.getInstanceDirection())) {
+                    execution.setVariable(IS_CHILD_PROCESS, Boolean.TRUE);
+                    execution.setVariable(PARENT_CORRELATION_ID, requestDetails.getRequestInfo().getCorrelator());
+                }
+            }
+        }
+
         // By default, enable homing at VNF level for CREATE_INSTANCE and ASSIGNINSTANCE
         if (resourceType == WorkflowType.SERVICE
                 && (requestAction.equals(CREATE_INSTANCE) || requestAction.equals(ASSIGN_INSTANCE))
@@ -372,6 +400,16 @@ public class WorkflowAction {
         return resourceType == WorkflowType.VNF && CREATE_INSTANCE.equalsIgnoreCase(requestAction);
     }
 
+
+    private boolean isPNFCreate(WorkflowType resourceType, String requestAction) {
+        return resourceType == WorkflowType.PNF && CREATE_INSTANCE.equalsIgnoreCase(requestAction);
+    }
+
+
+    private boolean isPNFDelete(WorkflowType resourceType, String requestAction) {
+        return resourceType == WorkflowType.PNF && DELETE_INSTANCE.equalsIgnoreCase(requestAction);
+    }
+
     private void setExecutionVariables(DelegateExecution execution, List<ExecuteBuildingBlock> flowsToExecute,
             List<String> flowNames) {
         execution.setVariable("flowNames", flowNames);
@@ -680,11 +718,11 @@ public class WorkflowAction {
             logger.debug("{}, {}", pair.getValue0(), pair.getValue1());
         }
         Map<Resource, String> resourceInstanceIds = new HashMap<>();
-        Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE))
-                .forEach(type -> resourceList.stream().filter(resource -> type.equals(resource.getResourceType()))
-                        .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource,
-                                retrieveAAIResourceId(aaiResourceIds, type), null, serviceInstanceId,
-                                resourceInstanceIds)));
+        Arrays.stream(WorkflowType.values()).forEach(type -> resourceList.stream()
+                .filter(resource -> type.equals(resource.getResourceType())
+                        && !(WorkflowType.SERVICE.equals(type) && !resource.hasParent()))
+                .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource,
+                        retrieveAAIResourceId(aaiResourceIds, type), null, serviceInstanceId, resourceInstanceIds)));
     }
 
     private String retrieveAAIResourceId(List<Pair<WorkflowType, String>> aaiResourceIds, WorkflowType resource) {
@@ -702,8 +740,9 @@ public class WorkflowAction {
     private void generateResourceIds(List<ExecuteBuildingBlock> flowsToExecute, List<Resource> resourceList,
             String serviceInstanceId) {
         Map<Resource, String> resourceInstanceIds = new HashMap<>();
-        Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE))
-                .forEach(type -> resourceList.stream().filter(resource -> type.equals(resource.getResourceType()))
+        Arrays.stream(WorkflowType.values())
+                .forEach(type -> resourceList.stream()
+                        .filter(resource -> resource.hasParent() && type.equals(resource.getResourceType()))
                         .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource, null,
                                 resource.getVirtualLinkKey(), serviceInstanceId, resourceInstanceIds)));
     }
@@ -731,13 +770,20 @@ public class WorkflowAction {
                 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
                 workflowResourceIds.setServiceInstanceId(serviceInstanceId);
                 Resource parent = resource.getParent();
-                if (parent != null && resourceInstanceIds.containsKey(parent)) {
+                if (resource.hasParent() && resourceInstanceIds.containsKey(parent)) {
                     WorkflowResourceIdsUtils.setResourceIdByWorkflowType(workflowResourceIds, parent.getResourceType(),
                             resourceInstanceIds.get(parent));
                 }
-                WorkflowResourceIdsUtils.setInstanceNameByWorkflowType(workflowResourceIds, resourceType,
-                        resource.getInstanceName());
-                WorkflowResourceIdsUtils.setResourceIdByWorkflowType(workflowResourceIds, resourceType, resourceId);
+                if (resource.hasParent() && WorkflowType.SERVICE.equals(resourceType)
+                        && WorkflowType.SERVICE.equals(parent.getResourceType())) {
+                    String childServiceInstanceId = resource.isGenerated() ? resourceId : resource.getResourceId();
+                    workflowResourceIds.setChildServiceInstanceId(childServiceInstanceId);
+                    workflowResourceIds.setChildServiceInstanceName(resource.getInstanceName());
+                } else {
+                    WorkflowResourceIdsUtils.setInstanceNameByWorkflowType(workflowResourceIds, resourceType,
+                            resource.getInstanceName());
+                    WorkflowResourceIdsUtils.setResourceIdByWorkflowType(workflowResourceIds, resourceType, resourceId);
+                }
                 ebb.setWorkflowResourceIds(workflowResourceIds);
                 assignedFlows.add(flowName + action);
             }
@@ -753,7 +799,9 @@ public class WorkflowAction {
 
     private boolean isFlowAssignable(Set<String> assignedFlows, ExecuteBuildingBlock ebb, WorkflowType resourceType,
             String assignedFlowName) {
-        String id = WorkflowResourceIdsUtils.getResourceIdByWorkflowType(ebb.getWorkflowResourceIds(), resourceType);
+        String id = WorkflowType.SERVICE.equals(resourceType)
+                ? StringUtils.defaultString(ebb.getWorkflowResourceIds().getChildServiceInstanceId())
+                : WorkflowResourceIdsUtils.getResourceIdByWorkflowType(ebb.getWorkflowResourceIds(), resourceType);
         return !assignedFlows.contains(assignedFlowName) && id.isEmpty();
     }
 
@@ -797,7 +845,7 @@ public class WorkflowAction {
     }
 
     protected String convertTypeFromPlural(String type) {
-        if (!type.matches(SUPPORTEDTYPES)) {
+        if (!type.matches(SUPPORTEDTYPES) || type.equals("NetworkSliceSubnet")) {
             return type;
         } else {
             if (type.equals(SERVICE_INSTANCES)) {