X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=bpmn%2Fso-bpmn-tasks%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fso%2Fbpmn%2Finfrastructure%2Fworkflow%2Ftasks%2FWorkflowAction.java;h=64e623ba986f5764bf60ffd555db9f279df1d13a;hb=7a475e244b329f9f179d30c8fc96aed6045037ce;hp=79c846bb12be1ec4d78caf4d4fba375fbe0dd97c;hpb=63dcede0648aeed18c64d9947eb6fa02865e6c32;p=so.git 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 old mode 100644 new mode 100755 index 79c846bb12..64e623ba98 --- 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 @@ -6,10 +6,12 @@ * ================================================================================ * Modifications Copyright (c) 2019 Samsung * ================================================================================ - * Modifications Copyright (c) 2020 Nokia + * Modifications Copyright (c) 2021 Nokia * ================================================================================ * Modifications Copyright (c) 2020 Tech Mahindra * ================================================================================ + * Modifications Copyright (c) 2021 Orange + * ================================================================================ * 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 @@ -26,21 +28,41 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +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; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.DELETE_INSTANCE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.FABRIC_CONFIGURATION; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.RECREATE_INSTANCE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.REPLACEINSTANCE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.REPLACEINSTANCERETAINASSIGNMENTS; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.SERVICE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.UPDATE_INSTANCE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.HEALTH_CHECK; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.UPGRADE_CNF; +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.GenericVnf; -import org.onap.aai.domain.yang.GenericVnfs; -import org.onap.aai.domain.yang.L3Network; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aai.domain.yang.ServiceInstances; import org.onap.aai.domain.yang.Vnfc; import org.onap.aai.domain.yang.VolumeGroup; -import org.onap.aai.domain.yang.VpnBinding; -import org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider; import org.onap.aaiclient.client.aai.AAIObjectName; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.aai.entities.Relationships; @@ -49,24 +71,17 @@ 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.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; import org.onap.so.bpmn.infrastructure.workflow.tasks.utils.WorkflowResourceIdsUtils; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; -import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; -import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; -import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; 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.servicedecomposition.tasks.exceptions.DuplicateNameException; -import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException; import org.onap.so.client.exception.ExceptionBuilder; -import org.onap.so.client.orchestration.AAIConfigurationResources; import org.onap.so.client.orchestration.AAIEntityNotFoundException; -import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization; -import org.onap.so.db.catalog.beans.CollectionResourceCustomization; -import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization; -import org.onap.so.db.catalog.beans.InstanceGroup; import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.beans.macro.NorthBoundRequest; import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; @@ -84,62 +99,28 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE; -import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.FABRIC_CONFIGURATION; -import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.USER_PARAM_SERVICE; -import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.so.serviceinstancebeans.InstanceDirection; @Component public class WorkflowAction { + private static final Logger logger = LoggerFactory.getLogger(WorkflowAction.class); + private static final String SERVICE_INSTANCES = "serviceInstances"; - private static final String SERVICE_INSTANCE = "serviceInstance"; private static final String VF_MODULES = "vfModules"; - private static final String WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI = - "WorkflowAction was unable to verify if the instance name already exist in AAI."; private static final String VNF_TYPE = "vnfType"; - private static final String SERVICE = "Service"; - private static final String VNF = "Vnf"; - private static final String PNF = "Pnf"; - private static final String VFMODULE = "VfModule"; - private static final String VOLUMEGROUP = "VolumeGroup"; - private static final String NETWORK = "Network"; - private static final String NETWORKCOLLECTION = "NetworkCollection"; private static final String CONFIGURATION = "Configuration"; - private static final String ASSIGNINSTANCE = "assignInstance"; - private static final String REPLACEINSTANCE = "replaceInstance"; - private static final String REPLACEINSTANCERETAINASSIGNMENTS = "replaceInstanceRetainAssignments"; private static final String SUPPORTEDTYPES = - "vnfs|vfModules|networks|networkCollections|volumeGroups|serviceInstances|instanceGroups"; + "vnfs|pnfs|vfModules|networks|networkCollections|volumeGroups|serviceInstances|instanceGroups"; private static final String HOMINGSOLUTION = "Homing_Solution"; private static final String SERVICE_TYPE_TRANSPORT = "TRANSPORT"; private static final String SERVICE_TYPE_BONDING = "BONDING"; private static final String CLOUD_OWNER = "DEFAULT"; - private static final Logger logger = LoggerFactory.getLogger(WorkflowAction.class); - private static final String NAME_EXISTS_WITH_DIFF_VERSION_ID = "(%s) and different version id (%s)"; - private static final String NAME_EXISTS_MULTIPLE = - "(%s) and multiple combination of model-version-id + service-type + global-customer-id"; - private static final String NAME_EXISTS_WITH_DIFF_COMBINATION = - "(%s) and global-customer-id (%s), service-type (%s), model-version-id (%s)"; - private static final String NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID = - "(%s), same parent and different customization id (%s)"; - private static final String NAME_EXISTS_WITH_DIFF_PARENT = "(%s) id (%s) and different parent relationship"; private static final String CREATENETWORKBB = "CreateNetworkBB"; private static final String ACTIVATENETWORKBB = "ActivateNetworkBB"; private static final String VOLUMEGROUP_DELETE_PATTERN = "(Un|De)(.*)Volume(.*)"; private static final String VOLUMEGROUP_CREATE_PATTERN = "(A|C)(.*)Volume(.*)"; - private static final String CONTROLLER = "Controller"; private static final String DEFAULT_CLOUD_OWNER = "org.onap.so.cloud-owner"; private static final String HOMING = "homing"; @@ -152,15 +133,17 @@ public class WorkflowAction { @Autowired private CatalogDbClient catalogDbClient; @Autowired - private AAIConfigurationResources aaiConfigurationResources; + private Environment environment; @Autowired - private WorkflowActionExtractResourcesAAI workflowActionUtils; + private AaiResourceIdValidator aaiResourceIdValidator; @Autowired - private VrfValidation vrfValidation; + private ExecuteBuildingBlockBuilder executeBuildingBlockBuilder; @Autowired - private Environment environment; + private VnfEBBLoader vnfEBBLoader; + @Autowired + private PnfEBBLoader pnfEBBLoader; @Autowired - private UserParamsServiceTraversal userParamsServiceTraversal; + private ServiceEBBLoader serviceEBBLoader; public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) { this.bbInputSetupUtils = bbInputSetupUtils; @@ -194,8 +177,7 @@ public class WorkflowAction { String serviceInstanceId = getServiceInstanceId(execution, resourceId, resourceType); fillExecution(execution, requestDetails.getRequestInfo().getSuppressRollback(), resourceId, resourceType); - List flowsToExecute = new ArrayList<>(); - + List flowsToExecute; if (isRequestMacroServiceResume(isALaCarte, resourceType, requestAction, serviceInstanceId)) { String errorMessage = "Could not resume Macro flow. Error loading execution path."; flowsToExecute = loadExecuteBuildingBlocks(execution, requestId, errorMessage); @@ -212,146 +194,21 @@ public class WorkflowAction { final String serviceType = Optional.ofNullable((String) execution.getVariable(BBConstants.G_SERVICE_TYPE)).orElse(""); if (isALaCarte) { - if (orchFlows == null || orchFlows.isEmpty()) { - orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, true, - cloudOwner, serviceType); - } - Resource resourceKey = getResourceKey(sIRequest, resourceType); - - ReplaceInstanceRelatedInformation replaceInfo = new ReplaceInstanceRelatedInformation(); - if ((requestAction.equalsIgnoreCase(REPLACEINSTANCE) - || requestAction.equalsIgnoreCase(REPLACEINSTANCERETAINASSIGNMENTS)) - && resourceType.equals(WorkflowType.VFMODULE)) { - logger.debug("Build a BB list for replacing BB modules"); - ConfigBuildingBlocksDataObject cbbdo = createConfigBuildingBlocksDataObject(execution, - sIRequest, requestId, workflowResourceIds, requestDetails, requestAction, resourceId, - vnfType, orchFlows, apiVersion, resourceKey, replaceInfo); - orchFlows = getVfModuleReplaceBuildingBlocks(cbbdo); - - createBuildingBlocksForOrchFlows(execution, sIRequest, requestId, workflowResourceIds, - requestDetails, requestAction, resourceId, flowsToExecute, vnfType, orchFlows, - apiVersion, resourceKey, replaceInfo); - } else { - if (isConfiguration(orchFlows) && !requestAction.equalsIgnoreCase(CREATE_INSTANCE)) { - addConfigBuildingBlocksToFlowsToExecuteList(execution, sIRequest, requestId, - workflowResourceIds, requestDetails, requestAction, resourceId, flowsToExecute, - vnfType, apiVersion, resourceKey, replaceInfo, orchFlows); - } - orchFlows = - orchFlows.stream().filter(item -> !item.getFlowName().contains(FABRIC_CONFIGURATION)) - .collect(Collectors.toList()); - - for (OrchestrationFlow orchFlow : orchFlows) { - ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, requestId, resourceKey, - apiVersion, resourceId, requestAction, true, vnfType, workflowResourceIds, - requestDetails, false, null, null, false, replaceInfo); - flowsToExecute.add(ebb); - } - } + flowsToExecute = loadExecuteBuildingBlocksForAlaCarte(orchFlows, execution, requestAction, + resourceType, cloudOwner, serviceType, sIRequest, requestId, workflowResourceIds, + requestDetails, resourceId, vnfType, apiVersion); } else { - boolean containsService = false; - List resourceList = new ArrayList<>(); - List> aaiResourceIds = new ArrayList<>(); - List> userParams = - sIRequest.getRequestDetails().getRequestParameters().getUserParams(); - if (resourceType == WorkflowType.SERVICE && requestAction.equalsIgnoreCase(ASSIGNINSTANCE)) { - // SERVICE-MACRO-ASSIGN will always get user params with a - // service. - - if (userParams != null) { - containsService = isContainsService(sIRequest); - if (containsService) { - resourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution, - userParams, serviceInstanceId, requestAction); - } - } else { - buildAndThrowException(execution, - "Service-Macro-Assign request details must contain user params with a service"); - } - } else if (resourceType == WorkflowType.SERVICE - && requestAction.equalsIgnoreCase(CREATE_INSTANCE)) { - // SERVICE-MACRO-CREATE will get user params with a service, - // a service with a network, a service with a - // network collection, OR an empty service. - // If user params is just a service or null and macro - // queries the SI and finds a VNF, macro fails. - - if (userParams != null) { - containsService = isContainsService(sIRequest); - } - if (containsService) { - resourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution, - userParams, serviceInstanceId, requestAction); - } - if (!foundRelated(resourceList)) { - traverseCatalogDbService(execution, sIRequest, resourceList, aaiResourceIds); - } - } else if (resourceType == WorkflowType.SERVICE - && ("activateInstance".equalsIgnoreCase(requestAction) - || "unassignInstance".equalsIgnoreCase(requestAction) - || "deleteInstance".equalsIgnoreCase(requestAction) - || requestAction.equalsIgnoreCase("activate" + FABRIC_CONFIGURATION))) { - // SERVICE-MACRO-ACTIVATE, SERVICE-MACRO-UNASSIGN, and - // SERVICE-MACRO-DELETE - // Will never get user params with service, macro will have - // to query the SI in AAI to find related instances. - traverseAAIService(execution, resourceList, resourceId, aaiResourceIds); - } else if (resourceType == WorkflowType.SERVICE - && "deactivateInstance".equalsIgnoreCase(requestAction)) { - resourceList.add(new Resource(WorkflowType.SERVICE, "", false)); - } else if (resourceType == WorkflowType.VNF && (REPLACEINSTANCE.equalsIgnoreCase(requestAction) - || ("recreateInstance".equalsIgnoreCase(requestAction)))) { - traverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), - workflowResourceIds.getVnfId(), aaiResourceIds); - } else if (resourceType == WorkflowType.VNF && "updateInstance".equalsIgnoreCase(requestAction)) { - customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), - workflowResourceIds.getVnfId(), aaiResourceIds); - } else { - buildAndThrowException(execution, "Current Macro Request is not supported"); - } - StringBuilder foundObjects = new StringBuilder(); - for (WorkflowType type : WorkflowType.values()) { - foundObjects.append(type).append(" - ").append( - (int) resourceList.stream().filter(x -> type.equals(x.getResourceType())).count()) - .append(" "); - } - logger.info("Found {}", foundObjects); - - if (orchFlows == null || orchFlows.isEmpty()) { - orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, isALaCarte, - cloudOwner, serviceType); - } - boolean vnfReplace = false; - if (resourceType.equals(WorkflowType.VNF) && (REPLACEINSTANCE.equalsIgnoreCase(requestAction) - || REPLACEINSTANCERETAINASSIGNMENTS.equalsIgnoreCase(requestAction))) { - vnfReplace = true; - } - flowsToExecute = buildExecuteBuildingBlockList(orchFlows, resourceList, requestId, apiVersion, - resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, vnfReplace); - if (isNetworkCollectionInTheResourceList(resourceList)) { - logger.info("Sorting for Vlan Tagging"); - flowsToExecute = sortExecutionPathByObjectForVlanTagging(flowsToExecute, requestAction); - } - // By default, enable homing at VNF level for CREATE_INSTANCE and ASSIGNINSTANCE - if (resourceType == WorkflowType.SERVICE - && (requestAction.equals(CREATE_INSTANCE) || requestAction.equals(ASSIGNINSTANCE)) - && resourceList.stream().anyMatch(x -> WorkflowType.VNF.equals(x.getResourceType()))) { - execution.setVariable(HOMING, true); - execution.setVariable("calledHoming", false); - } - if (resourceType == WorkflowType.SERVICE && (requestAction.equalsIgnoreCase(ASSIGNINSTANCE) - || requestAction.equalsIgnoreCase(CREATE_INSTANCE))) { - generateResourceIds(flowsToExecute, resourceList, serviceInstanceId); - } else { - updateResourceIdsFromAAITraversal(flowsToExecute, resourceList, aaiResourceIds, - serviceInstanceId); - } + flowsToExecute = loadExecuteBuildingBlocksForMacro(sIRequest, resourceType, requestAction, + execution, serviceInstanceId, resourceId, workflowResourceIds, orchFlows, cloudOwner, + serviceType, requestId, apiVersion, vnfType, requestDetails); } } // If the user set "Homing_Solution" to "none", disable homing, else if "Homing_Solution" is specified, // enable it. - List> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams(); - if (sIRequest.getRequestDetails().getRequestParameters() != null && userParams != null) { + if (sIRequest.getRequestDetails().getRequestParameters() != null + && sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { + List> userParams = + sIRequest.getRequestDetails().getRequestParameters().getUserParams(); for (Map params : userParams) { if (params.containsKey(HOMINGSOLUTION)) { execution.setVariable(HOMING, !"none".equals(params.get(HOMINGSOLUTION))); @@ -386,6 +243,168 @@ public class WorkflowAction { } } + private List loadExecuteBuildingBlocksForAlaCarte(List orchFlows, + DelegateExecution execution, String requestAction, WorkflowType resourceType, String cloudOwner, + String serviceType, ServiceInstancesRequest sIRequest, String requestId, + WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails, String resourceId, String vnfType, + String apiVersion) throws Exception { + List flowsToExecute = new ArrayList<>(); + if (orchFlows == null || orchFlows.isEmpty()) { + orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, true, cloudOwner, + serviceType); + } + Resource resourceKey = getResourceKey(sIRequest, resourceType); + + ReplaceInstanceRelatedInformation replaceInfo = new ReplaceInstanceRelatedInformation(); + if ((requestAction.equalsIgnoreCase(REPLACEINSTANCE) + || requestAction.equalsIgnoreCase(REPLACEINSTANCERETAINASSIGNMENTS)) + && resourceType.equals(WorkflowType.VFMODULE)) { + logger.debug("Build a BB list for replacing BB modules"); + ConfigBuildingBlocksDataObject cbbdo = createConfigBuildingBlocksDataObject(execution, sIRequest, requestId, + workflowResourceIds, requestDetails, requestAction, resourceId, vnfType, orchFlows, apiVersion, + resourceKey, replaceInfo); + orchFlows = getVfModuleReplaceBuildingBlocks(cbbdo); + + createBuildingBlocksForOrchFlows(execution, sIRequest, requestId, workflowResourceIds, requestDetails, + requestAction, resourceId, flowsToExecute, vnfType, orchFlows, apiVersion, resourceKey, + replaceInfo); + } else { + if (isConfiguration(orchFlows) && !requestAction.equalsIgnoreCase(CREATE_INSTANCE)) { + addConfigBuildingBlocksToFlowsToExecuteList(execution, sIRequest, requestId, workflowResourceIds, + requestDetails, requestAction, resourceId, flowsToExecute, vnfType, apiVersion, resourceKey, + replaceInfo, orchFlows); + } + orchFlows = orchFlows.stream().filter(item -> !item.getFlowName().contains(FABRIC_CONFIGURATION)) + .collect(Collectors.toList()); + + for (OrchestrationFlow orchFlow : orchFlows) { + ExecuteBuildingBlock ebb = executeBuildingBlockBuilder.buildExecuteBuildingBlock(orchFlow, requestId, + resourceKey, apiVersion, resourceId, requestAction, true, vnfType, workflowResourceIds, + requestDetails, false, null, null, false, replaceInfo); + flowsToExecute.add(ebb); + } + } + return flowsToExecute; + } + + private List loadExecuteBuildingBlocksForMacro(ServiceInstancesRequest sIRequest, + WorkflowType resourceType, String requestAction, DelegateExecution execution, String serviceInstanceId, + String resourceId, WorkflowResourceIds workflowResourceIds, List orchFlows, + String cloudOwner, String serviceType, String requestId, String apiVersion, String vnfType, + RequestDetails requestDetails) throws IOException, VrfBondingServiceException { + List flowsToExecute; + List resourceList = new ArrayList<>(); + List> aaiResourceIds = new ArrayList<>(); + + if (resourceType == WorkflowType.SERVICE || isVNFCreate(resourceType, requestAction) + || isPNFCreate(resourceType, requestAction)) { + resourceList = serviceEBBLoader.getResourceListForService(sIRequest, requestAction, execution, + serviceInstanceId, resourceId, aaiResourceIds); + } 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)))) { + vnfEBBLoader.traverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), + workflowResourceIds.getVnfId(), aaiResourceIds); + } else if (resourceType == WorkflowType.VNF && UPDATE_INSTANCE.equalsIgnoreCase(requestAction)) { + vnfEBBLoader.customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), + workflowResourceIds.getVnfId(), aaiResourceIds); + } else if (resourceType == WorkflowType.VNF && HEALTH_CHECK.equalsIgnoreCase(requestAction)) { + vnfEBBLoader.customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), + workflowResourceIds.getVnfId(), aaiResourceIds); + } else if (resourceType == WorkflowType.VNF && UPGRADE_CNF.equalsIgnoreCase(requestAction)) { + vnfEBBLoader.customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), + workflowResourceIds.getVnfId(), aaiResourceIds); + } else { + buildAndThrowException(execution, "Current Macro Request is not supported"); + } + StringBuilder foundObjects = new StringBuilder(); + for (WorkflowType type : WorkflowType.values()) { + foundObjects.append(type).append(" - ") + .append((int) resourceList.stream().filter(x -> type.equals(x.getResourceType())).count()) + .append(" "); + } + logger.info("Found {}", foundObjects); + + if (orchFlows == null || orchFlows.isEmpty()) { + orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, false, cloudOwner, + serviceType); + } + boolean vnfReplace = false; + if (resourceType.equals(WorkflowType.VNF) && (REPLACEINSTANCE.equalsIgnoreCase(requestAction) + || REPLACEINSTANCERETAINASSIGNMENTS.equalsIgnoreCase(requestAction))) { + vnfReplace = true; + } + flowsToExecute = executeBuildingBlockBuilder.buildExecuteBuildingBlockList(orchFlows, resourceList, requestId, + apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, vnfReplace); + if (serviceEBBLoader.isNetworkCollectionInTheResourceList(resourceList)) { + logger.info("Sorting for Vlan Tagging"); + flowsToExecute = sortExecutionPathByObjectForVlanTagging(flowsToExecute, requestAction); + } + logger.info("Building Block Execution Order"); + for (ExecuteBuildingBlock block : flowsToExecute) { + Resource res = resourceList.stream() + .filter(resource -> resource.getResourceId() == block.getBuildingBlock().getKey()).findAny() + .orElse(null); + String log = "Block: " + block.getBuildingBlock().getBpmnFlowName(); + if (res != null) { + log += ", Resource: " + res.getResourceType() + "[" + res.getResourceId() + "]"; + log += ", Priority: " + res.getProcessingPriority(); + if (res.getResourceType() == WorkflowType.VFMODULE) + log += ", Base: " + res.isBaseVfModule(); + } + if (block.getBuildingBlock().getBpmnScope() != null) + log += ", Scope: " + block.getBuildingBlock().getBpmnScope(); + if (block.getBuildingBlock().getBpmnAction() != null) + 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)) + && resourceList.stream().anyMatch(x -> WorkflowType.VNF.equals(x.getResourceType()))) { + execution.setVariable(HOMING, true); + execution.setVariable("calledHoming", false); + } + if (resourceType == WorkflowType.SERVICE && (requestAction.equalsIgnoreCase(ASSIGN_INSTANCE) + || requestAction.equalsIgnoreCase(CREATE_INSTANCE))) { + generateResourceIds(flowsToExecute, resourceList, serviceInstanceId); + } else { + updateResourceIdsFromAAITraversal(flowsToExecute, resourceList, aaiResourceIds, serviceInstanceId); + } + execution.setVariable("resources", resourceList); + return flowsToExecute; + } + + private boolean isVNFCreate(WorkflowType resourceType, String requestAction) { + 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 flowsToExecute, List flowNames) { execution.setVariable("flowNames", flowNames); @@ -396,15 +415,6 @@ public class WorkflowAction { execution.setVariable("isRollbackComplete", false); } - private boolean isContainsService(ServiceInstancesRequest sIRequest) { - boolean containsService; - List> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams(); - containsService = userParams.stream().anyMatch(param -> param.containsKey(USER_PARAM_SERVICE)); - return containsService; - } - - - private List loadExecuteBuildingBlocks(DelegateExecution execution, String requestId, String errorMessage) { List flowsToExecute; @@ -442,9 +452,9 @@ public class WorkflowAction { requestDetails, requestAction, resourceId, flowsToExecute, vnfType, apiVersion, resourceKey, replaceInfo, configOrchFlows); } else { - ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, requestId, resourceKey, apiVersion, - resourceId, requestAction, true, vnfType, workflowResourceIds, requestDetails, false, null, - null, false, replaceInfo); + ExecuteBuildingBlock ebb = executeBuildingBlockBuilder.buildExecuteBuildingBlock(orchFlow, requestId, + resourceKey, apiVersion, resourceId, requestAction, true, vnfType, workflowResourceIds, + requestDetails, false, null, null, false, replaceInfo); flowsToExecute.add(ebb); } } @@ -473,7 +483,7 @@ public class WorkflowAction { resourceId = modelInfo.getModelCustomizationId(); } } - return new Resource(resourceType, resourceId, true); + return new Resource(resourceType, resourceId, true, null); } private String getCloudOwner(CloudConfiguration cloudConfiguration) { @@ -491,7 +501,7 @@ public class WorkflowAction { AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId)); AAIResultWrapper vfModuleResultsWrapper = bbInputSetupUtils.getAAIResourceDepthOne(uri); Optional relationshipsOp = vfModuleResultsWrapper.getRelationships(); - if (!relationshipsOp.isPresent()) { + if (relationshipsOp.isEmpty()) { logger.debug("No relationships were found for vfModule in AAI"); } else { Relationships relationships = relationshipsOp.get(); @@ -504,21 +514,20 @@ public class WorkflowAction { return vnfcs; } - protected T getRelatedResourcesInVnfc(Vnfc vnfc, Class resultClass, AAIObjectName name) throws Exception { + protected T getRelatedResourcesInVnfc(Vnfc vnfc, Class resultClass, AAIObjectName name) + throws VnfcMultipleRelationshipException { T configuration = null; AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vnfc(vnfc.getVnfcName())); AAIResultWrapper vnfcResultsWrapper = bbInputSetupUtils.getAAIResourceDepthOne(uri); Optional relationshipsOp = vnfcResultsWrapper.getRelationships(); - if (!relationshipsOp.isPresent()) { + if (relationshipsOp.isEmpty()) { logger.debug("No relationships were found for VNFC in AAI"); } else { Relationships relationships = relationshipsOp.get(); List configurationResultWrappers = this.getResultWrappersFromRelationships(relationships, name); if (configurationResultWrappers.size() > 1) { - String multipleRelationshipsError = - "Multiple relationships exist from VNFC " + vnfc.getVnfcName() + " to Configurations"; - throw new Exception(multipleRelationshipsError); + throw new VnfcMultipleRelationshipException(vnfc.getVnfcName()); } if (!configurationResultWrappers.isEmpty()) { Optional configurationOp = configurationResultWrappers.get(0).asBean(resultClass); @@ -545,7 +554,7 @@ public class WorkflowAction { } protected List getConfigBuildingBlocks(ConfigBuildingBlocksDataObject dataObj) - throws Exception { + throws AAIEntityNotFoundException, VnfcMultipleRelationshipException { List flowsToExecuteConfigs = new ArrayList<>(); List result = dataObj.getOrchFlows().stream() @@ -592,30 +601,33 @@ public class WorkflowAction { } workflowIdsCopy.setConfigurationId(configuration.getConfigurationId()); for (OrchestrationFlow orchFlow : result) { - if (!isReplace) { - dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID); - dataObj.getResourceKey().setVnfCustomizationId(vnfCustomizationUUID); - } else { - if (orchFlow.getFlowName().contains("Delete")) { + if (!isReplace || (isReplace && (orchFlow.getFlowName().contains("Delete")))) { + if (!isReplace) { dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID); dataObj.getResourceKey().setVnfCustomizationId(vnfCustomizationUUID); } else { - dataObj.getResourceKey().setVfModuleCustomizationId(replaceVfModuleCustomizationUUID); - dataObj.getResourceKey().setVnfCustomizationId(replaceVnfModuleCustomizationUUID); + if (orchFlow.getFlowName().contains("Delete")) { + dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID); + dataObj.getResourceKey().setVnfCustomizationId(vnfCustomizationUUID); + } else { + dataObj.getResourceKey().setVfModuleCustomizationId(replaceVfModuleCustomizationUUID); + dataObj.getResourceKey().setVnfCustomizationId(replaceVnfModuleCustomizationUUID); + } } + dataObj.getResourceKey().setCvnfModuleCustomizationId(vnfc.getModelCustomizationId()); + String vnfcName = vnfc.getVnfcName(); + if (vnfcName == null || vnfcName.isEmpty()) { + buildAndThrowException(dataObj.getExecution(), "Exception in create execution list " + + ": VnfcName does not exist or is null while there is a configuration for the vfModule", + new Exception("Vnfc and Configuration do not match")); + } + ExecuteBuildingBlock ebb = + executeBuildingBlockBuilder.buildExecuteBuildingBlock(orchFlow, dataObj.getRequestId(), + dataObj.getResourceKey(), dataObj.getApiVersion(), dataObj.getResourceId(), + dataObj.getRequestAction(), dataObj.isaLaCarte(), dataObj.getVnfType(), + workflowIdsCopy, dataObj.getRequestDetails(), false, null, vnfcName, true, null); + flowsToExecuteConfigs.add(ebb); } - dataObj.getResourceKey().setCvnfModuleCustomizationId(vnfc.getModelCustomizationId()); - String vnfcName = vnfc.getVnfcName(); - if (vnfcName == null || vnfcName.isEmpty()) { - buildAndThrowException(dataObj.getExecution(), "Exception in create execution list " - + ": VnfcName does not exist or is null while there is a configuration for the vfModule", - new Exception("Vnfc and Configuration do not match")); - } - ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, dataObj.getRequestId(), - dataObj.getResourceKey(), dataObj.getApiVersion(), dataObj.getResourceId(), - dataObj.getRequestAction(), dataObj.isaLaCarte(), dataObj.getVnfType(), workflowIdsCopy, - dataObj.getRequestDetails(), false, null, vnfcName, true, null); - flowsToExecuteConfigs.add(ebb); } } return flowsToExecuteConfigs; @@ -656,7 +668,7 @@ public class WorkflowAction { if (volumeGroupFromVfModule.isPresent()) { String volumeGroupId = volumeGroupFromVfModule.get().getVolumeGroupId(); volumeGroupName = volumeGroupFromVfModule.get().getVolumeGroupName(); - logger.debug("Volume group id of the existing volume group is: " + volumeGroupId); + logger.debug("Volume group id of the existing volume group is: {}", volumeGroupId); volumeGroupExisted = true; dataObj.getWorkflowResourceIds().setVolumeGroupId(volumeGroupId); dataObj.getReplaceInformation().setOldVolumeGroupName(volumeGroupName); @@ -673,7 +685,7 @@ public class WorkflowAction { String newVolumeGroupId = UUID.randomUUID().toString(); dataObj.getWorkflowResourceIds().setVolumeGroupId(newVolumeGroupId); dataObj.getReplaceInformation().setOldVolumeGroupName(volumeGroupName); - logger.debug("newVolumeGroupId: " + newVolumeGroupId); + logger.debug("newVolumeGroupId: {}", newVolumeGroupId); } } @@ -695,40 +707,17 @@ public class WorkflowAction { return orchFlows; } - protected List sortVfModulesByBaseFirst(List vfModuleResources) { - int count = 0; - for (Resource resource : vfModuleResources) { - if (resource.isBaseVfModule()) { - Collections.swap(vfModuleResources, 0, count); - break; - } - count++; - } - return vfModuleResources; - } - - protected List sortVfModulesByBaseLast(List vfModuleResources) { - int count = 0; - for (Resource resource : vfModuleResources) { - if (resource.isBaseVfModule()) { - Collections.swap(vfModuleResources, vfModuleResources.size() - 1, count); - break; - } - count++; - } - return vfModuleResources; - } - private void updateResourceIdsFromAAITraversal(List flowsToExecute, List resourceList, List> aaiResourceIds, String serviceInstanceId) { for (Pair pair : aaiResourceIds) { - logger.debug(pair.getValue0() + ", " + pair.getValue1()); + logger.debug("{}, {}", pair.getValue0(), pair.getValue1()); } - - 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))); + Map resourceInstanceIds = new HashMap<>(); + 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> aaiResourceIds, WorkflowType resource) { @@ -745,27 +734,53 @@ public class WorkflowAction { private void generateResourceIds(List flowsToExecute, List resourceList, String serviceInstanceId) { - 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))); + Map resourceInstanceIds = new HashMap<>(); + 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))); } protected void updateWorkflowResourceIds(List flowsToExecute, WorkflowType resourceType, - String key, String id, String virtualLinkKey, String serviceInstanceId) { + Resource resource, String id, String virtualLinkKey, String serviceInstanceId, + Map resourceInstanceIds) { + String key = resource.getResourceId(); String resourceId = id; if (resourceId == null) { resourceId = UUID.randomUUID().toString(); } + resourceInstanceIds.put(resource, resourceId); + Set 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); - WorkflowResourceIdsUtils.setResourceIdByWorkflowType(workflowResourceIds, resourceType, resourceId); + Resource parent = resource.getParent(); + if (resource.hasParent() && resourceInstanceIds.containsKey(parent)) { + WorkflowResourceIdsUtils.setResourceIdByWorkflowType(workflowResourceIds, parent.getResourceType(), + resourceInstanceIds.get(parent)); + } + 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); } if (virtualLinkKey != null && ebb.getBuildingBlock().isVirtualLink() && virtualLinkKey.equalsIgnoreCase(ebb.getBuildingBlock().getVirtualLinkKey())) { @@ -777,449 +792,12 @@ public class WorkflowAction { } } - protected CollectionResourceCustomization findCatalogNetworkCollection(DelegateExecution execution, - org.onap.so.db.catalog.beans.Service service) { - CollectionResourceCustomization networkCollection = null; - int count = 0; - for (CollectionResourceCustomization collectionCust : service.getCollectionResourceCustomizations()) { - if (catalogDbClient.getNetworkCollectionResourceCustomizationByID( - collectionCust.getModelCustomizationUUID()) != null) { - networkCollection = collectionCust; - count++; - } - } - if (count == 0) { - return null; - } else if (count > 1) { - buildAndThrowException(execution, - "Found multiple Network Collections in the Service model, only one per Service is supported."); - } - return networkCollection; - } - - protected void traverseCatalogDbService(DelegateExecution execution, ServiceInstancesRequest sIRequest, - List resourceList, List> aaiResourceIds) - throws JsonProcessingException, VrfBondingServiceException { - String modelUUID = sIRequest.getRequestDetails().getModelInfo().getModelVersionId(); - org.onap.so.db.catalog.beans.Service service = catalogDbClient.getServiceByID(modelUUID); - - if (service == null) { - buildAndThrowException(execution, "Could not find the service model in catalog db."); - } else { - resourceList.add(new Resource(WorkflowType.SERVICE, service.getModelUUID(), false)); - RelatedInstance relatedVpnBinding = - bbInputSetupUtils.getRelatedInstanceByType(sIRequest.getRequestDetails(), ModelType.vpnBinding); - RelatedInstance relatedLocalNetwork = - bbInputSetupUtils.getRelatedInstanceByType(sIRequest.getRequestDetails(), ModelType.network); - - if (relatedVpnBinding != null && relatedLocalNetwork != null) { - traverseVrfConfiguration(aaiResourceIds, resourceList, service, relatedVpnBinding, relatedLocalNetwork); - } else { - traverseNetworkCollection(execution, resourceList, service); - } - } - } - - protected void traverseVrfConfiguration(List> aaiResourceIds, - List resourceList, org.onap.so.db.catalog.beans.Service service, - RelatedInstance relatedVpnBinding, RelatedInstance relatedLocalNetwork) - throws VrfBondingServiceException, JsonProcessingException { - org.onap.aai.domain.yang.L3Network aaiLocalNetwork = - bbInputSetupUtils.getAAIL3Network(relatedLocalNetwork.getInstanceId()); - vrfValidation.vrfServiceValidation(service); - vrfValidation.vrfCatalogDbChecks(service); - vrfValidation.aaiVpnBindingValidation(relatedVpnBinding.getInstanceId(), - bbInputSetupUtils.getAAIVpnBinding(relatedVpnBinding.getInstanceId())); - vrfValidation.aaiNetworkValidation(relatedLocalNetwork.getInstanceId(), aaiLocalNetwork); - vrfValidation.aaiSubnetValidation(aaiLocalNetwork); - vrfValidation.aaiAggregateRouteValidation(aaiLocalNetwork); - vrfValidation.aaiRouteTargetValidation(aaiLocalNetwork); - String existingAAIVrfConfiguration = getExistingAAIVrfConfiguration(relatedVpnBinding, aaiLocalNetwork); - if (existingAAIVrfConfiguration != null) { - aaiResourceIds.add(new Pair<>(WorkflowType.CONFIGURATION, existingAAIVrfConfiguration)); - } - resourceList.add(new Resource(WorkflowType.CONFIGURATION, - service.getConfigurationCustomizations().get(0).getModelCustomizationUUID(), false)); - - } - - protected String getExistingAAIVrfConfiguration(RelatedInstance relatedVpnBinding, - org.onap.aai.domain.yang.L3Network aaiLocalNetwork) - throws JsonProcessingException, VrfBondingServiceException { - Optional relationshipsOp = new AAIResultWrapper( - new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiLocalNetwork)).getRelationships(); - if (relationshipsOp.isPresent()) { - List configurationsRelatedToLocalNetwork = - relationshipsOp.get().getByType(Types.CONFIGURATION); - if (configurationsRelatedToLocalNetwork.size() > 1) { - throw new VrfBondingServiceException( - "Network: " + aaiLocalNetwork.getNetworkId() + " has more than 1 configuration related to it"); - } - if (configurationsRelatedToLocalNetwork.size() == 1) { - AAIResultWrapper configWrapper = configurationsRelatedToLocalNetwork.get(0); - Optional relatedConfiguration = configWrapper.asBean(Configuration.class); - if (relatedConfiguration.isPresent() && vrfConfigurationAlreadyExists(relatedVpnBinding, - relatedConfiguration.get(), configWrapper)) { - return relatedConfiguration.get().getConfigurationId(); - } - } - } - return null; - } - - protected boolean vrfConfigurationAlreadyExists(RelatedInstance relatedVpnBinding, Configuration vrfConfiguration, - AAIResultWrapper configWrapper) throws VrfBondingServiceException { - if ("VRF-ENTRY".equalsIgnoreCase(vrfConfiguration.getConfigurationType())) { - Optional relationshipsConfigOp = configWrapper.getRelationships(); - if (relationshipsConfigOp.isPresent()) { - Optional relatedInfraVpnBindingOp = - workflowActionUtils.extractRelationshipsVpnBinding(relationshipsConfigOp.get()); - if (relatedInfraVpnBindingOp.isPresent()) { - VpnBinding relatedInfraVpnBinding = relatedInfraVpnBindingOp.get(); - if (!relatedInfraVpnBinding.getVpnId().equalsIgnoreCase(relatedVpnBinding.getInstanceId())) { - throw new VrfBondingServiceException("Configuration: " + vrfConfiguration.getConfigurationId() - + " is not connected to the same vpn binding id provided in request: " - + relatedVpnBinding.getInstanceId()); - } else { - return true; - } - } - } - } - return false; - } - - protected void traverseNetworkCollection(DelegateExecution execution, List resourceList, - org.onap.so.db.catalog.beans.Service service) { - if (isVnfCustomizationsInTheService(service)) { - buildAndThrowException(execution, - "Cannot orchestrate Service-Macro-Create without user params with a vnf. Please update ASDC model for new macro orchestration support or add service_recipe records to route to old macro flows"); - } - if (isPnfCustomizationsInTheService(service)) { - buildAndThrowException(execution, - "Cannot orchestrate Service-Macro-Create without user params with a pnf. Please update ASDC model for new macro orchestration support or add service_recipe records to route to old macro flows"); - } - List customizations = service.getCollectionResourceCustomizations(); - if (customizations.isEmpty()) { - logger.debug("No Collections found. CollectionResourceCustomization list is empty."); - } else { - CollectionResourceCustomization collectionResourceCustomization = - findCatalogNetworkCollection(execution, service); - traverseNetworkCollectionResourceCustomization(resourceList, collectionResourceCustomization); - } - traverseNetworkCollectionCustomization(resourceList, service); - } - - private void traverseNetworkCollectionResourceCustomization(List resourceList, - CollectionResourceCustomization collectionResourceCustomization) { - if (collectionResourceCustomizationShouldNotBeProcessed(resourceList, collectionResourceCustomization)) - return; - int minNetworks = 0; - org.onap.so.db.catalog.beans.InstanceGroup instanceGroup = - collectionResourceCustomization.getCollectionResource().getInstanceGroup(); - CollectionResourceInstanceGroupCustomization collectionInstCust = null; - if (!instanceGroup.getCollectionInstanceGroupCustomizations().isEmpty()) { - for (CollectionResourceInstanceGroupCustomization collectionInstanceGroupTemp : instanceGroup - .getCollectionInstanceGroupCustomizations()) { - if (collectionInstanceGroupTemp.getModelCustomizationUUID() - .equalsIgnoreCase(collectionResourceCustomization.getModelCustomizationUUID())) { - collectionInstCust = collectionInstanceGroupTemp; - break; - } - } - if (interfaceNetworkQuantityIsAvailableInCollection(collectionInstCust)) { - minNetworks = collectionInstCust.getSubInterfaceNetworkQuantity(); - } - } - logger.debug("minNetworks: {}", minNetworks); - CollectionNetworkResourceCustomization collectionNetworkResourceCust = - getCollectionNetworkResourceCustomization(collectionResourceCustomization, instanceGroup); - for (int i = 0; i < minNetworks; i++) { - if (collectionNetworkResourceCust != null) { - Resource resource = new Resource(WorkflowType.VIRTUAL_LINK, - collectionNetworkResourceCust.getModelCustomizationUUID(), false); - resource.setVirtualLinkKey(Integer.toString(i)); - resourceList.add(resource); - } - } - } - - private CollectionNetworkResourceCustomization getCollectionNetworkResourceCustomization( - CollectionResourceCustomization collectionResourceCustomization, InstanceGroup instanceGroup) { - CollectionNetworkResourceCustomization collectionNetworkResourceCust = null; - for (CollectionNetworkResourceCustomization collectionNetworkTemp : instanceGroup - .getCollectionNetworkResourceCustomizations()) { - if (collectionNetworkTemp.getNetworkResourceCustomization().getModelCustomizationUUID() - .equalsIgnoreCase(collectionResourceCustomization.getModelCustomizationUUID())) { - collectionNetworkResourceCust = collectionNetworkTemp; - break; - } - } - return collectionNetworkResourceCust; - } - - private boolean collectionResourceCustomizationShouldNotBeProcessed(List resourceList, - CollectionResourceCustomization collectionResourceCustomization) { - if (collectionResourceCustomization == null) { - logger.debug("No Network Collection Customization found"); - return true; - } - resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, - collectionResourceCustomization.getModelCustomizationUUID(), false)); - logger.debug("Found a network collection"); - if (collectionResourceCustomization.getCollectionResource() == null) { - logger.debug("No Network Collection found. collectionResource is null"); - return true; - } - if (collectionResourceCustomization.getCollectionResource().getInstanceGroup() == null) { - logger.debug("No Instance Group found for network collection."); - return true; - } - String toscaNodeType = - collectionResourceCustomization.getCollectionResource().getInstanceGroup().getToscaNodeType(); - if (!toscaNodeTypeHasNetworkCollection(toscaNodeType)) { - logger.debug("Instance Group tosca node type does not contain NetworkCollection: {}", toscaNodeType); - return true; - } - return false; - } - - private boolean interfaceNetworkQuantityIsAvailableInCollection( - CollectionResourceInstanceGroupCustomization collectionInstCust) { - return collectionInstCust != null && collectionInstCust.getSubInterfaceNetworkQuantity() != null; - } - - private boolean toscaNodeTypeHasNetworkCollection(String toscaNodeType) { - return toscaNodeType != null && toscaNodeType.contains(NETWORKCOLLECTION); - } - - private void traverseNetworkCollectionCustomization(List resourceList, - org.onap.so.db.catalog.beans.Service service) { - if (isNetworkCollectionInTheResourceList(resourceList)) { - return; - } - if (service.getNetworkCustomizations() == null) { - logger.debug("No networks were found on this service model"); - return; - } - for (int i = 0; i < service.getNetworkCustomizations().size(); i++) { - resourceList.add(new Resource(WorkflowType.NETWORK, - service.getNetworkCustomizations().get(i).getModelCustomizationUUID(), false)); - } - } - - private boolean isNetworkCollectionInTheResourceList(List resourceList) { - return resourceList.stream().anyMatch(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()); - } - - private boolean isVnfCustomizationsInTheService(org.onap.so.db.catalog.beans.Service service) { - return !(service.getVnfCustomizations() == null || service.getVnfCustomizations().isEmpty()); - } - - private boolean isPnfCustomizationsInTheService(org.onap.so.db.catalog.beans.Service service) { - return !(service.getPnfCustomizations() == null || service.getPnfCustomizations().isEmpty()); - } - - protected void traverseAAIService(DelegateExecution execution, List resourceList, String resourceId, - List> aaiResourceIds) { - try { - ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(resourceId); - org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = - bbInputSetup.getExistingServiceInstance(serviceInstanceAAI); - resourceList.add(new Resource(WorkflowType.SERVICE, serviceInstanceMSO.getServiceInstanceId(), false)); - traverseServiceInstanceMSOVnfs(resourceList, aaiResourceIds, serviceInstanceMSO); - traverseServiceInstanceMSOPnfs(resourceList, aaiResourceIds, serviceInstanceMSO); - if (serviceInstanceMSO.getNetworks() != null) { - for (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network : serviceInstanceMSO - .getNetworks()) { - aaiResourceIds.add(new Pair<>(WorkflowType.NETWORK, network.getNetworkId())); - resourceList.add(new Resource(WorkflowType.NETWORK, network.getNetworkId(), false)); - } - } - if (serviceInstanceMSO.getCollection() != null) { - logger.debug("found networkcollection"); - aaiResourceIds - .add(new Pair<>(WorkflowType.NETWORKCOLLECTION, serviceInstanceMSO.getCollection().getId())); - resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, - serviceInstanceMSO.getCollection().getId(), false)); - } - if (serviceInstanceMSO.getConfigurations() != null) { - for (Configuration config : serviceInstanceMSO.getConfigurations()) { - Optional aaiConfig = - aaiConfigurationResources.getConfiguration(config.getConfigurationId()); - if (aaiConfig.isPresent() && aaiConfig.get().getRelationshipList() != null) { - for (Relationship relationship : aaiConfig.get().getRelationshipList().getRelationship()) { - if (relationship.getRelatedTo().contains("vnfc") - || relationship.getRelatedTo().contains("vpn-binding")) { - aaiResourceIds.add(new Pair<>(WorkflowType.CONFIGURATION, config.getConfigurationId())); - resourceList.add( - new Resource(WorkflowType.CONFIGURATION, config.getConfigurationId(), false)); - break; - } - } - } - } - } - } catch (Exception ex) { - logger.error("Exception in traverseAAIService", ex); - buildAndThrowException(execution, - "Could not find existing Service Instance or related Instances to execute the request on."); - } - } - - private void traverseServiceInstanceMSOVnfs(List resourceList, - List> aaiResourceIds, - org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO) { - if (serviceInstanceMSO.getVnfs() == null) { - return; - } - for (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf : serviceInstanceMSO.getVnfs()) { - aaiResourceIds.add(new Pair<>(WorkflowType.VNF, vnf.getVnfId())); - resourceList.add(new Resource(WorkflowType.VNF, vnf.getVnfId(), false)); - traverseVnfModules(resourceList, aaiResourceIds, vnf); - 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)); - } - } - } - } - - private void traverseServiceInstanceMSOPnfs(List resourceList, - List> aaiResourceIds, - org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO) { - if (serviceInstanceMSO.getPnfs() == null) { - return; - } - for (org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf pnf : serviceInstanceMSO.getPnfs()) { - aaiResourceIds.add(new Pair<>(WorkflowType.PNF, pnf.getPnfId())); - resourceList.add(new Resource(WorkflowType.PNF, pnf.getPnfId(), false)); - } - } - - private void traverseVnfModules(List resourceList, List> aaiResourceIds, - org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf) { - if (vnf.getVfModules() == null) { - return; - } - for (VfModule vfModule : vnf.getVfModules()) { - aaiResourceIds.add(new Pair<>(WorkflowType.VFMODULE, vfModule.getVfModuleId())); - Resource resource = new Resource(WorkflowType.VFMODULE, vfModule.getVfModuleId(), false); - resource.setBaseVfModule(vfModule.getModelInfoVfModule().getIsBaseBoolean()); - resourceList.add(resource); - } - } - - private void traverseAAIVnf(DelegateExecution execution, List resourceList, String serviceId, - String vnfId, List> 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 resourceList, String serviceId, - String vnfId, List> 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 resourceList, List> aaiResourceIds) { - try { - org.onap.aai.domain.yang.VfModule aaiVfModule = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId); - AAIResultWrapper vfModuleWrapper = new AAIResultWrapper( - new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiVfModule)); - Optional relationshipsOp; - relationshipsOp = vfModuleWrapper.getRelationships(); - if (relationshipsOp.isPresent()) { - relationshipsOp = workflowActionUtils.extractRelationshipsVnfc(relationshipsOp.get()); - if (relationshipsOp.isPresent()) { - Optional 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 boolean isFlowAssignable(Set assignedFlows, ExecuteBuildingBlock ebb, WorkflowType resourceType, + String assignedFlowName) { + String id = WorkflowType.SERVICE.equals(resourceType) + ? StringUtils.defaultString(ebb.getWorkflowResourceIds().getChildServiceInstanceId()) + : WorkflowResourceIdsUtils.getResourceIdByWorkflowType(ebb.getWorkflowResourceIds(), resourceType); + return !assignedFlows.contains(assignedFlowName) && id.isEmpty(); } protected WorkflowResourceIds populateResourceIdsFromApiHandler(DelegateExecution execution) { @@ -1255,42 +833,12 @@ public class WorkflowAction { type = action; } } - return new Resource(WorkflowType.fromString(convertTypeFromPlural(type)), id, generated); + return new Resource(WorkflowType.fromString(convertTypeFromPlural(type)), id, generated, null); } else { throw new IllegalArgumentException("Uri could not be parsed: " + uri); } } - protected String validateResourceIdInAAI(String generatedResourceId, WorkflowType type, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws Exception { - try { - if ("SERVICE".equalsIgnoreCase(type.toString())) { - return validateServiceResourceIdInAAI(generatedResourceId, instanceName, reqDetails); - } else if ("NETWORK".equalsIgnoreCase(type.toString())) { - return validateNetworkResourceIdInAAI(generatedResourceId, instanceName, reqDetails, - workflowResourceIds); - } else if ("VNF".equalsIgnoreCase(type.toString())) { - return validateVnfResourceIdInAAI(generatedResourceId, instanceName, reqDetails, workflowResourceIds); - } else if ("VFMODULE".equalsIgnoreCase(type.toString())) { - return validateVfModuleResourceIdInAAI(generatedResourceId, instanceName, reqDetails, - workflowResourceIds); - } else if ("VOLUMEGROUP".equalsIgnoreCase(type.toString())) { - return validateVolumeGroupResourceIdInAAI(generatedResourceId, instanceName, reqDetails, - workflowResourceIds); - } else if ("CONFIGURATION".equalsIgnoreCase(type.toString())) { - return validateConfigurationResourceIdInAAI(generatedResourceId, instanceName, reqDetails, - workflowResourceIds); - } - return generatedResourceId; - } catch (DuplicateNameException dne) { - throw dne; - } catch (Exception ex) { - logger.error(WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI, ex); - throw new IllegalStateException( - WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI); - } - } - protected String convertTypeFromPlural(String type) { if (!type.matches(SUPPORTEDTYPES)) { return type; @@ -1374,134 +922,6 @@ public class WorkflowAction { return sortedOrchFlows; } - private void addBuildingBlockToExecuteBBList(List flowsToExecute, List resourceList, - WorkflowType workflowType, OrchestrationFlow orchFlow, String requestId, String apiVersion, - String resourceId, String requestAction, String vnfType, WorkflowResourceIds workflowResourceIds, - RequestDetails requestDetails, boolean isVirtualLink, boolean isConfiguration) { - - resourceList.stream().filter(resource -> resource.getResourceType().equals(workflowType)) - .forEach(resource -> flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resource, - apiVersion, resourceId, requestAction, false, vnfType, workflowResourceIds, requestDetails, - isVirtualLink, resource.getVirtualLinkKey(), null, isConfiguration, null))); - } - - protected List buildExecuteBuildingBlockList(List orchFlows, - List resourceList, String requestId, String apiVersion, String resourceId, String requestAction, - String vnfType, WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails, - boolean replaceVnf) { - List flowsToExecute = new ArrayList<>(); - for (OrchestrationFlow orchFlow : orchFlows) { - if (orchFlow.getFlowName().contains(SERVICE)) { - if (!replaceVnf) { - workflowResourceIds.setServiceInstanceId(resourceId); - } - addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.SERVICE, orchFlow, requestId, - apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false, - false); - } else if (orchFlow.getFlowName().contains(VNF) || (orchFlow.getFlowName().contains(CONTROLLER) - && (VNF).equalsIgnoreCase(orchFlow.getBpmnScope()))) { - addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.VNF, orchFlow, requestId, - apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false, - false); - } else if (orchFlow.getFlowName().contains(PNF) || (orchFlow.getFlowName().contains(CONTROLLER) - && (PNF).equalsIgnoreCase(orchFlow.getBpmnScope()))) { - addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.PNF, orchFlow, requestId, - apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false, - false); - } else if (orchFlow.getFlowName().contains(NETWORK) - && !orchFlow.getFlowName().contains(NETWORKCOLLECTION)) { - addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.NETWORK, orchFlow, requestId, - apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false, - false); - addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.VIRTUAL_LINK, orchFlow, - requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, - true, false); - } else if (orchFlow.getFlowName().contains(VFMODULE) || (orchFlow.getFlowName().contains(CONTROLLER) - && (VFMODULE).equalsIgnoreCase(orchFlow.getBpmnScope()))) { - List vfModuleResourcesSorted; - if (requestAction.equals(CREATE_INSTANCE) || requestAction.equals(ASSIGNINSTANCE) - || requestAction.equals("activateInstance")) { - vfModuleResourcesSorted = sortVfModulesByBaseFirst(resourceList.stream() - .filter(x -> WorkflowType.VFMODULE == x.getResourceType()).collect(Collectors.toList())); - } else { - vfModuleResourcesSorted = sortVfModulesByBaseLast(resourceList.stream() - .filter(x -> WorkflowType.VFMODULE == x.getResourceType()).collect(Collectors.toList())); - } - for (Resource resource : vfModuleResourcesSorted) { - flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resource, apiVersion, resourceId, - requestAction, false, vnfType, workflowResourceIds, requestDetails, false, null, null, - false, null)); - } - } else if (orchFlow.getFlowName().contains(VOLUMEGROUP)) { - if (requestAction.equalsIgnoreCase(REPLACEINSTANCE) - || requestAction.equalsIgnoreCase(REPLACEINSTANCERETAINASSIGNMENTS)) { - logger.debug("Replacing workflow resource id by volume group id"); - resourceId = workflowResourceIds.getVolumeGroupId(); - } - addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.VOLUMEGROUP, orchFlow, - requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, - false, false); - } else if (orchFlow.getFlowName().contains(NETWORKCOLLECTION)) { - addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.NETWORKCOLLECTION, orchFlow, - requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, - false, false); - } else if (orchFlow.getFlowName().contains(CONFIGURATION)) { - addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.CONFIGURATION, orchFlow, - requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, - false, true); - } else { - flowsToExecute - .add(buildExecuteBuildingBlock(orchFlow, requestId, null, apiVersion, resourceId, requestAction, - false, vnfType, workflowResourceIds, requestDetails, false, null, null, false, null)); - } - } - return flowsToExecute; - } - - protected ExecuteBuildingBlock buildExecuteBuildingBlock(OrchestrationFlow orchFlow, String requestId, - Resource resource, String apiVersion, String resourceId, String requestAction, boolean aLaCarte, - String vnfType, WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails, - boolean isVirtualLink, String virtualLinkKey, String vnfcName, boolean isConfiguration, - ReplaceInstanceRelatedInformation replaceInfo) { - - BuildingBlock buildingBlock = - new BuildingBlock().setBpmnFlowName(orchFlow.getFlowName()).setMsoId(UUID.randomUUID().toString()) - .setIsVirtualLink(isVirtualLink).setVirtualLinkKey(virtualLinkKey) - .setKey(Optional.ofNullable(resource).map(Resource::getResourceId).orElse("")); - Optional.ofNullable(orchFlow.getBpmnAction()).ifPresent(buildingBlock::setBpmnAction); - Optional.ofNullable(orchFlow.getBpmnScope()).ifPresent(buildingBlock::setBpmnScope); - String oldVolumeGroupName = ""; - if (replaceInfo != null) { - oldVolumeGroupName = replaceInfo.getOldVolumeGroupName(); - } - if (resource != null - && (orchFlow.getFlowName().contains(VOLUMEGROUP) && (requestAction.equalsIgnoreCase(REPLACEINSTANCE) - || requestAction.equalsIgnoreCase(REPLACEINSTANCERETAINASSIGNMENTS)))) { - logger.debug("Setting resourceId to volume group id for volume group flow on replace"); - resourceId = workflowResourceIds.getVolumeGroupId(); - } - - ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock().setApiVersion(apiVersion) - .setaLaCarte(aLaCarte).setRequestAction(requestAction).setResourceId(resourceId).setVnfType(vnfType) - .setWorkflowResourceIds(workflowResourceIds).setRequestId(requestId).setBuildingBlock(buildingBlock) - .setRequestDetails(requestDetails).setOldVolumeGroupName(oldVolumeGroupName); - - if (resource != null && (isConfiguration || resource.getResourceType().equals(WorkflowType.CONFIGURATION))) { - ConfigurationResourceKeys configurationResourceKeys = getConfigurationResourceKeys(resource, vnfcName); - executeBuildingBlock.setConfigurationResourceKeys(configurationResourceKeys); - } - return executeBuildingBlock; - } - - private ConfigurationResourceKeys getConfigurationResourceKeys(Resource resource, String vnfcName) { - ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys(); - Optional.ofNullable(vnfcName).ifPresent(configurationResourceKeys::setVnfcName); - configurationResourceKeys.setCvnfcCustomizationUUID(resource.getCvnfModuleCustomizationId()); - configurationResourceKeys.setVfModuleCustomizationUUID(resource.getVfModuleCustomizationId()); - configurationResourceKeys.setVnfResourceCustomizationUUID(resource.getVnfCustomizationId()); - return configurationResourceKeys; - } - protected List queryNorthBoundRequestCatalogDb(DelegateExecution execution, String requestAction, WorkflowType resourceName, boolean aLaCarte, String cloudOwner) { return this.queryNorthBoundRequestCatalogDb(execution, requestAction, resourceName, aLaCarte, cloudOwner, ""); @@ -1576,168 +996,11 @@ public class WorkflowAction { protected boolean isRequestMacroServiceResume(boolean aLaCarte, WorkflowType resourceType, String requestAction, String serviceInstanceId) { return (!aLaCarte && resourceType == WorkflowType.SERVICE - && (requestAction.equalsIgnoreCase(ASSIGNINSTANCE) || requestAction.equalsIgnoreCase(CREATE_INSTANCE)) + && (requestAction.equalsIgnoreCase(ASSIGN_INSTANCE) || requestAction.equalsIgnoreCase(CREATE_INSTANCE)) && (serviceInstanceId != null && serviceInstanceId.trim().length() > 1) && (bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId) != null)); } - protected String validateServiceResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails) throws DuplicateNameException { - String globalCustomerId = reqDetails.getSubscriberInfo().getGlobalSubscriberId(); - String serviceType = reqDetails.getRequestParameters().getSubscriptionServiceType(); - if (instanceName != null) { - Optional serviceInstanceAAI = - bbInputSetupUtils.getAAIServiceInstanceByName(globalCustomerId, serviceType, instanceName); - if (serviceInstanceAAI.isPresent()) { - if (serviceInstanceAAI.get().getModelVersionId() - .equalsIgnoreCase(reqDetails.getModelInfo().getModelVersionId())) { - return serviceInstanceAAI.get().getServiceInstanceId(); - } else { - throw new DuplicateNameException(SERVICE_INSTANCE, String.format(NAME_EXISTS_WITH_DIFF_VERSION_ID, - instanceName, reqDetails.getModelInfo().getModelVersionId())); - } - } else { - ServiceInstances aaiServiceInstances = - bbInputSetupUtils.getAAIServiceInstancesGloballyByName(instanceName); - if (aaiServiceInstances != null) { - if (aaiServiceInstances.getServiceInstance() != null - && !aaiServiceInstances.getServiceInstance().isEmpty()) { - if (aaiServiceInstances.getServiceInstance().size() > 1) { - throw new DuplicateNameException(SERVICE_INSTANCE, - String.format(NAME_EXISTS_MULTIPLE, instanceName)); - } else { - ServiceInstance si = aaiServiceInstances.getServiceInstance().stream().findFirst().get(); - Map keys = - bbInputSetupUtils.getURIKeysFromServiceInstance(si.getServiceInstanceId()); - - throw new DuplicateNameException(SERVICE_INSTANCE, String.format( - NAME_EXISTS_WITH_DIFF_COMBINATION, instanceName, - keys.get(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId), - keys.get( - AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType), - si.getModelVersionId())); - } - } - } - } - } - return generatedResourceId; - } - - protected String validateNetworkResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) - throws DuplicateNameException, MultipleObjectsFoundException { - Optional network = bbInputSetupUtils - .getRelatedNetworkByNameFromServiceInstance(workflowResourceIds.getServiceInstanceId(), instanceName); - if (network.isPresent()) { - if (network.get().getModelCustomizationId() - .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { - return network.get().getNetworkId(); - } else { - throw new DuplicateNameException("l3Network", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, - instanceName, network.get().getModelCustomizationId())); - } - } - if (bbInputSetupUtils.existsAAINetworksGloballyByName(instanceName)) { - throw new DuplicateNameException("l3Network", String.format(NAME_EXISTS_WITH_DIFF_PARENT, instanceName, - workflowResourceIds.getServiceInstanceId())); - } - return generatedResourceId; - } - - protected String validateVnfResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { - Optional vnf = bbInputSetupUtils - .getRelatedVnfByNameFromServiceInstance(workflowResourceIds.getServiceInstanceId(), instanceName); - if (vnf.isPresent()) { - if (vnf.get().getModelCustomizationId() - .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { - return vnf.get().getVnfId(); - } else { - throw new DuplicateNameException("generic-vnf", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, - instanceName, vnf.get().getModelCustomizationId())); - } - } - GenericVnfs vnfs = bbInputSetupUtils.getAAIVnfsGloballyByName(instanceName); - if (vnfs != null) { - throw new DuplicateNameException("generic-vnf", - String.format(NAME_EXISTS_WITH_DIFF_PARENT, instanceName, vnfs.getGenericVnf().get(0).getVnfId())); - } - return generatedResourceId; - } - - protected String validateVfModuleResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { - GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(workflowResourceIds.getVnfId()); - if (vnf != null && vnf.getVfModules() != null) { - for (org.onap.aai.domain.yang.VfModule vfModule : vnf.getVfModules().getVfModule()) { - if (vfModule.getVfModuleName().equalsIgnoreCase(instanceName)) { - if (vfModule.getModelCustomizationId() - .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { - return vfModule.getVfModuleId(); - } else { - throw new DuplicateNameException("vfModule", - String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, instanceName, - reqDetails.getModelInfo().getModelCustomizationId())); - } - } - } - } - if (bbInputSetupUtils.existsAAIVfModuleGloballyByName(instanceName)) { - throw new DuplicateNameException("vfModule", instanceName); - } - return generatedResourceId; - } - - protected String validateVolumeGroupResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { - Optional volumeGroup = - bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf(workflowResourceIds.getVnfId(), instanceName); - if (volumeGroup.isPresent()) { - if (volumeGroup.get().getVfModuleModelCustomizationId() - .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { - return volumeGroup.get().getVolumeGroupId(); - } else { - throw new DuplicateNameException("volumeGroup", volumeGroup.get().getVolumeGroupName()); - } - } - if (bbInputSetupUtils.existsAAIVolumeGroupGloballyByName(instanceName)) { - throw new DuplicateNameException("volumeGroup", instanceName); - } - return generatedResourceId; - } - - protected String validateConfigurationResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { - Optional configuration = - bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance( - workflowResourceIds.getServiceInstanceId(), instanceName); - if (configuration.isPresent()) { - if (configuration.get().getModelCustomizationId() - .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { - return configuration.get().getConfigurationId(); - } else { - throw new DuplicateNameException("configuration", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, - instanceName, configuration.get().getConfigurationId())); - } - } - if (bbInputSetupUtils.existsAAIConfigurationGloballyByName(instanceName)) { - throw new DuplicateNameException("configuration", instanceName); - } - return generatedResourceId; - } - - protected boolean foundRelated(List resourceList) { - return (containsWorkflowType(resourceList, WorkflowType.VNF) - || containsWorkflowType(resourceList, WorkflowType.PNF) - || containsWorkflowType(resourceList, WorkflowType.NETWORK) - || containsWorkflowType(resourceList, WorkflowType.NETWORKCOLLECTION)); - } - - protected boolean containsWorkflowType(List resourceList, WorkflowType workflowType) { - return resourceList.stream().anyMatch(resource -> resource.getResourceType().equals(workflowType)); - } - private void fillExecutionDefault(DelegateExecution execution) { execution.setVariable("sentSyncResponse", false); execution.setVariable(HOMING, false); @@ -1767,7 +1030,7 @@ public class WorkflowAction { WorkflowResourceIds workflowResourceIds) throws Exception { if (resource.isGenerated() && requestAction.equalsIgnoreCase("createInstance") && requestDetails.getRequestInfo().getInstanceName() != null) { - return validateResourceIdInAAI(resource.getResourceId(), resource.getResourceType(), + return aaiResourceIdValidator.validateResourceIdInAAI(resource.getResourceId(), resource.getResourceType(), requestDetails.getRequestInfo().getInstanceName(), requestDetails, workflowResourceIds); } else { return resource.getResourceId();