diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main')
4 files changed, 89 insertions, 11 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java index 0d2844d08b..99cff932c5 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java @@ -23,7 +23,6 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; import java.util.ArrayList; -import java.util.Arrays; import java.util.Comparator; import java.util.List; @@ -37,6 +36,7 @@ public class Resource { private String vnfCustomizationId; private String vfModuleCustomizationId; private String cvnfModuleCustomizationId; + private String instanceName; private int processingPriority; private Resource parent; private List<Resource> children; @@ -121,6 +121,14 @@ public class Resource { this.cvnfModuleCustomizationId = cvnfModuleCustomizationId; } + public String getInstanceName() { + return instanceName; + } + + public void setInstanceName(String instanceName) { + this.instanceName = instanceName; + } + public int getProcessingPriority() { return processingPriority == 0 ? (isBaseVfModule() ? Integer.MIN_VALUE + 1 : 0) : processingPriority; } 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 ce775af476..e49aed8b25 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 @@ -43,14 +43,18 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import org.apache.commons.lang3.SerializationUtils; +import org.apache.commons.lang3.StringUtils; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.javatuples.Pair; import org.onap.aai.domain.yang.Vnfc; @@ -666,11 +670,12 @@ public class WorkflowAction { for (Pair<WorkflowType, String> pair : aaiResourceIds) { 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.getResourceId(), - retrieveAAIResourceId(aaiResourceIds, type), null, serviceInstanceId))); + .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource, + retrieveAAIResourceId(aaiResourceIds, type), null, serviceInstanceId, + resourceInstanceIds))); } private String retrieveAAIResourceId(List<Pair<WorkflowType, String>> aaiResourceIds, WorkflowType resource) { @@ -687,27 +692,45 @@ 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())) - .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource.getResourceId(), - null, resource.getVirtualLinkKey(), serviceInstanceId))); + .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource, null, + resource.getVirtualLinkKey(), serviceInstanceId, resourceInstanceIds))); } protected void updateWorkflowResourceIds(List<ExecuteBuildingBlock> flowsToExecute, WorkflowType resourceType, - String key, String id, String virtualLinkKey, String serviceInstanceId) { + Resource resource, String id, String virtualLinkKey, String serviceInstanceId, + Map<Resource, String> resourceInstanceIds) { + String key = resource.getResourceId(); String resourceId = id; if (resourceId == null) { resourceId = UUID.randomUUID().toString(); } + resourceInstanceIds.put(resource, resourceId); + Set<String> assignedFlows = new LinkedHashSet<>(); for (ExecuteBuildingBlock ebb : flowsToExecute) { - if (key != null && key.equalsIgnoreCase(ebb.getBuildingBlock().getKey()) && (ebb.getBuildingBlock() - .getBpmnFlowName().contains(resourceType.toString()) - || (ebb.getBuildingBlock().getBpmnFlowName().contains(CONTROLLER) - && ebb.getBuildingBlock().getBpmnScope().equalsIgnoreCase(resourceType.toString())))) { + String resourceTypeStr = resourceType.toString(); + String flowName = ebb.getBuildingBlock().getBpmnFlowName(); + String scope = StringUtils.defaultString(ebb.getBuildingBlock().getBpmnScope()); + String action = StringUtils.defaultString(ebb.getBuildingBlock().getBpmnAction()); + + if (key != null && key.equalsIgnoreCase(ebb.getBuildingBlock().getKey()) + && isFlowAssignable(assignedFlows, ebb, resourceType, flowName + action) + && (flowName.contains(resourceTypeStr) + || (flowName.contains(CONTROLLER) && resourceTypeStr.equalsIgnoreCase(scope)))) { WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); workflowResourceIds.setServiceInstanceId(serviceInstanceId); + Resource parent = resource.getParent(); + if (parent != null && resourceInstanceIds.containsKey(parent)) { + WorkflowResourceIdsUtils.setResourceIdByWorkflowType(workflowResourceIds, parent.getResourceType(), + resourceInstanceIds.get(parent)); + } + WorkflowResourceIdsUtils.setInstanceNameByWorkflowType(workflowResourceIds, resourceType, + resource.getInstanceName()); WorkflowResourceIdsUtils.setResourceIdByWorkflowType(workflowResourceIds, resourceType, resourceId); ebb.setWorkflowResourceIds(workflowResourceIds); + assignedFlows.add(flowName + action); } if (virtualLinkKey != null && ebb.getBuildingBlock().isVirtualLink() && virtualLinkKey.equalsIgnoreCase(ebb.getBuildingBlock().getVirtualLinkKey())) { @@ -719,6 +742,12 @@ public class WorkflowAction { } } + private boolean isFlowAssignable(Set<String> assignedFlows, ExecuteBuildingBlock ebb, WorkflowType resourceType, + String assignedFlowName) { + String id = WorkflowResourceIdsUtils.getResourceIdByWorkflowType(ebb.getWorkflowResourceIds(), resourceType); + return !assignedFlows.contains(assignedFlowName) && id.isEmpty(); + } + protected WorkflowResourceIds populateResourceIdsFromApiHandler(DelegateExecution execution) { return WorkflowResourceIdsUtils.getWorkflowResourceIdsFromExecution(execution); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java index 1f932743ca..c383b4a73a 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java @@ -114,6 +114,7 @@ public class UserParamsServiceTraversal { Resource vnfResource = new Resource(WorkflowType.VNF, vnf.getModelInfo().getModelCustomizationId(), false, serviceResource); vnfResource.setProcessingPriority(vnf.getProcessingPriority()); + vnfResource.setInstanceName(vnf.getInstanceName()); resourceList.add(vnfResource); setResourceListForVfModules(execution, resourceList, vnfResource, validate, vnf); } @@ -170,6 +171,7 @@ public class UserParamsServiceTraversal { resource.setProcessingPriority(vfModule.getProcessingPriority()); resource.setBaseVfModule(vfModuleCustomization.getVfModule().getIsBase() != null && vfModuleCustomization.getVfModule().getIsBase()); + resource.setInstanceName(vfModule.getInstanceName()); resourceList.add(resource); return resource; } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/utils/WorkflowResourceIdsUtils.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/utils/WorkflowResourceIdsUtils.java index d16eac147e..9cabf6665c 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/utils/WorkflowResourceIdsUtils.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/utils/WorkflowResourceIdsUtils.java @@ -20,6 +20,7 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks.utils; +import org.apache.commons.lang3.StringUtils; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; @@ -63,6 +64,42 @@ public final class WorkflowResourceIdsUtils { } } + public static void setInstanceNameByWorkflowType(WorkflowResourceIds workflowResourceIds, WorkflowType resourceType, + String instanceName) { + if (resourceType == WorkflowType.VNF) { + workflowResourceIds.setVnfInstanceName(instanceName); + } else if (resourceType == WorkflowType.VFMODULE) { + workflowResourceIds.setVfModuleInstanceName(instanceName); + } + } + + public static String getResourceIdByWorkflowType(WorkflowResourceIds workflowResourceIds, + WorkflowType resourceType) { + switch (resourceType) { + case SERVICE: + return StringUtils.defaultString(workflowResourceIds.getServiceInstanceId()); + case VNF: + return StringUtils.defaultString(workflowResourceIds.getVnfId()); + case PNF: + return StringUtils.defaultString(workflowResourceIds.getPnfId()); + case VFMODULE: + return StringUtils.defaultString(workflowResourceIds.getVfModuleId()); + case VOLUMEGROUP: + return StringUtils.defaultString(workflowResourceIds.getVolumeGroupId()); + case NETWORK: + return StringUtils.defaultString(workflowResourceIds.getNetworkId()); + case NETWORKCOLLECTION: + return StringUtils.defaultString(workflowResourceIds.getNetworkCollectionId()); + case CONFIGURATION: + return StringUtils.defaultString(workflowResourceIds.getConfigurationId()); + case INSTANCE_GROUP: + return StringUtils.defaultString(workflowResourceIds.getInstanceGroupId()); + default: + return ""; + } + } + + public static WorkflowResourceIds getWorkflowResourceIdsFromExecution(DelegateExecution execution) { WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); workflowResourceIds.setServiceInstanceId((String) execution.getVariable("serviceInstanceId")); @@ -71,6 +108,8 @@ public final class WorkflowResourceIdsUtils { workflowResourceIds.setVnfId((String) execution.getVariable("vnfId")); workflowResourceIds.setVolumeGroupId((String) execution.getVariable("volumeGroupId")); workflowResourceIds.setInstanceGroupId((String) execution.getVariable("instanceGroupId")); + workflowResourceIds.setVnfInstanceName((String) execution.getVariable("vnfInstanceName")); + workflowResourceIds.setVfModuleInstanceName((String) execution.getVariable("vfModuleInstanceName")); return workflowResourceIds; } |