From ac97466f6eae32ad13015b93527e8e6f18299bc3 Mon Sep 17 00:00:00 2001 From: pwielebs Date: Fri, 8 Jan 2021 07:53:41 +0100 Subject: SO WorkflowAction refactor II - extract buildExecuteBuildingBlock(), buildExecuteBuildingBlockList() methods from WorkflowAction class and move it to new ExecuteBuildingBlockBuilder class in the same package as WorkflowAction - all methods used only in traverseUserParamsService() also moved - all existing tests for moved methods, moved to corresponding test class Issue-ID: SO-3422 Signed-off-by: pwielebs Change-Id: I64110de339fed4a0c80c746e45302cefd5e194ff --- .../tasks/ExecuteBuildingBlockBuilder.java | 217 +++++++++++++++++++++ .../workflow/tasks/WorkflowAction.java | 193 +++--------------- .../workflow/tasks/WorkflowActionConstants.java | 12 ++ .../tasks/ExecuteBuildingBlockBuilderTest.java | 90 +++++++++ .../workflow/tasks/WorkflowActionTest.java | 55 +----- 5 files changed, 354 insertions(+), 213 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilderTest.java (limited to 'bpmn/so-bpmn-tasks/src') diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java new file mode 100644 index 0000000000..b8699838e2 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java @@ -0,0 +1,217 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * Modifications Copyright (c) 2021 Nokia + * ================================================================================ + * Modifications Copyright (c) 2020 Tech Mahindra + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +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.db.catalog.beans.macro.OrchestrationFlow; +import org.onap.so.serviceinstancebeans.RequestDetails; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.ASSIGNINSTANCE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CONFIGURATION; +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.NETWORKCOLLECTION; +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.VOLUMEGROUP; + +@Component +public class ExecuteBuildingBlockBuilder { + + private static final Logger logger = LoggerFactory.getLogger(ExecuteBuildingBlockBuilder.class); + + private static final String VNF = "Vnf"; + private static final String PNF = "Pnf"; + private static final String VFMODULE = "VfModule"; + private static final String NETWORK = "Network"; + + 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; + } + + 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 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))); + } + + 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; + } + + +} 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 7821463acd..aad8b51a48 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 @@ -6,7 +6,7 @@ * ================================================================================ * Modifications Copyright (c) 2019 Samsung * ================================================================================ - * Modifications Copyright (c) 2020 Nokia + * Modifications Copyright (c) 2021 Nokia * ================================================================================ * Modifications Copyright (c) 2020 Tech Mahindra * ================================================================================ @@ -48,7 +48,6 @@ import org.onap.so.bpmn.common.BBConstants; 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; @@ -80,7 +79,6 @@ 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; @@ -89,40 +87,36 @@ 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.ASSIGNINSTANCE; +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.FABRIC_CONFIGURATION; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.NETWORKCOLLECTION; +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.USER_PARAM_SERVICE; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE; @Component public class WorkflowAction { + private static final Logger logger = LoggerFactory.getLogger(WorkflowAction.class); + private static final String SERVICE_INSTANCES = "serviceInstances"; private static final String VF_MODULES = "vfModules"; 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"; 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 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"; @@ -146,6 +140,8 @@ public class WorkflowAction { private UserParamsServiceTraversal userParamsServiceTraversal; @Autowired private AaiResourceIdValidator aaiResourceIdValidator; + @Autowired + private ExecuteBuildingBlockBuilder executeBuildingBlockBuilder; public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) { this.bbInputSetupUtils = bbInputSetupUtils; @@ -227,9 +223,9 @@ public class WorkflowAction { .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); + ExecuteBuildingBlock ebb = executeBuildingBlockBuilder.buildExecuteBuildingBlock(orchFlow, + requestId, resourceKey, apiVersion, resourceId, requestAction, true, vnfType, + workflowResourceIds, requestDetails, false, null, null, false, replaceInfo); flowsToExecute.add(ebb); } } @@ -311,8 +307,9 @@ public class WorkflowAction { || REPLACEINSTANCERETAINASSIGNMENTS.equalsIgnoreCase(requestAction))) { vnfReplace = true; } - flowsToExecute = buildExecuteBuildingBlockList(orchFlows, resourceList, requestId, apiVersion, - resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, vnfReplace); + flowsToExecute = executeBuildingBlockBuilder.buildExecuteBuildingBlockList(orchFlows, resourceList, + requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, + requestDetails, vnfReplace); if (isNetworkCollectionInTheResourceList(resourceList)) { logger.info("Sorting for Vlan Tagging"); flowsToExecute = sortExecutionPathByObjectForVlanTagging(flowsToExecute, requestAction); @@ -427,9 +424,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); } } @@ -597,10 +594,11 @@ public class WorkflowAction { + ": 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); + 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); } } @@ -682,29 +680,7 @@ 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) { @@ -1331,125 +1307,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); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java index bffa2592c1..5e16097304 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java @@ -28,8 +28,20 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; public final class WorkflowActionConstants { + private WorkflowActionConstants() { + throw new IllegalStateException("Utility class"); + } + static final String USER_PARAM_SERVICE = "service"; static final String CREATE_INSTANCE = "createInstance"; static final String FABRIC_CONFIGURATION = "FabricConfiguration"; static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage"; + static final String SERVICE = "Service"; + static final String CONTROLLER = "Controller"; + static final String NETWORKCOLLECTION = "NetworkCollection"; + static final String CONFIGURATION = "Configuration"; + static final String ASSIGNINSTANCE = "assignInstance"; + static final String REPLACEINSTANCE = "replaceInstance"; + static final String VOLUMEGROUP = "VolumeGroup"; + static final String REPLACEINSTANCERETAINASSIGNMENTS = "replaceInstanceRetainAssignments"; } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilderTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilderTest.java new file mode 100644 index 0000000000..c8914f6e02 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilderTest.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * Modifications Copyright (c) 2021 Nokia + * ================================================================================ + * Modifications Copyright (c) 2020 Tech Mahindra + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import org.junit.Test; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; +import java.util.ArrayList; +import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +public class ExecuteBuildingBlockBuilderTest { + + final private ExecuteBuildingBlockBuilder executeBBBuilder = new ExecuteBuildingBlockBuilder(); + + @Test + public void sortVfModulesByBaseFirstTest() { + List resources = new ArrayList<>(); + Resource resource1 = new Resource(WorkflowType.VFMODULE, "111", false); + resource1.setBaseVfModule(false); + resources.add(resource1); + Resource resource2 = new Resource(WorkflowType.VFMODULE, "222", false); + resource2.setBaseVfModule(false); + resources.add(resource2); + Resource resource3 = new Resource(WorkflowType.VFMODULE, "333", false); + resource3.setBaseVfModule(true); + resources.add(resource3); + + List result = executeBBBuilder.sortVfModulesByBaseFirst(resources); + assertEquals("333", result.get(0).getResourceId()); + assertEquals("222", result.get(1).getResourceId()); + assertEquals("111", result.get(2).getResourceId()); + } + + @Test + public void sortVfModulesByBaseLastTest() { + List resources = new ArrayList<>(); + Resource resource1 = new Resource(WorkflowType.VFMODULE, "111", false); + resource1.setBaseVfModule(true); + resources.add(resource1); + Resource resource2 = new Resource(WorkflowType.VFMODULE, "222", false); + resource2.setBaseVfModule(false); + resources.add(resource2); + Resource resource3 = new Resource(WorkflowType.VFMODULE, "333", false); + resource3.setBaseVfModule(false); + resources.add(resource3); + List result = executeBBBuilder.sortVfModulesByBaseLast(resources); + assertEquals("333", result.get(0).getResourceId()); + assertEquals("222", result.get(1).getResourceId()); + assertEquals("111", result.get(2).getResourceId()); + } + + @Test + public void verifyLackOfNullPointerExceptionForNullResource() { + ExecuteBuildingBlock result = null; + try { + result = executeBBBuilder.buildExecuteBuildingBlock(new OrchestrationFlow(), null, null, null, null, null, + false, null, null, null, false, null, null, true, null); + } catch (NullPointerException e) { + fail("NullPointerException should not be thrown when 'resource' is null"); + } + assertNotNull(result); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index c916e09c79..100c32f1c2 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -120,6 +120,7 @@ public class WorkflowActionTest extends BaseTaskTest { protected Environment environment; @Mock protected UserParamsServiceTraversal userParamsServiceTraversal; + @Mock private AaiResourceIdValidator aaiResourceIdValidator; @InjectMocks @@ -131,6 +132,9 @@ public class WorkflowActionTest extends BaseTaskTest { @Spy protected WorkflowAction SPY_workflowAction; + @Spy + protected ExecuteBuildingBlockBuilder executeBuildingBlockBuilder; + @Rule public ExpectedException thrown = ExpectedException.none(); @@ -159,6 +163,7 @@ public class WorkflowActionTest extends BaseTaskTest { when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance); workflowAction.setBbInputSetupUtils(bbSetupUtils); workflowAction.setBbInputSetup(bbInputSetup); + } /** @@ -179,6 +184,7 @@ public class WorkflowActionTest extends BaseTaskTest { when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, true, "my-custom-cloud-owner")).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); List ebbs = (List) execution.getVariable("flowsToExecute"); assertEqualsBulkFlowName(ebbs, "AssignNetwork1802BB", "CreateNetworkBB", "ActivateNetworkBB"); @@ -199,6 +205,7 @@ public class WorkflowActionTest extends BaseTaskTest { when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, true, "my-custom-cloud-owner")).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); List ebbs = (List) execution.getVariable("flowsToExecute"); assertEqualsBulkFlowName(ebbs, "DeactivateNetworkBB", "DeleteNetworkBB", "UnassignNetwork1802BB"); @@ -219,6 +226,7 @@ public class WorkflowActionTest extends BaseTaskTest { when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, true, "my-custom-cloud-owner")).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); List ebbs = (List) execution.getVariable("flowsToExecute"); assertEqualsBulkFlowName(ebbs, "AssignServiceInstanceBB", "ActivateServiceInstanceBB"); @@ -292,6 +300,7 @@ public class WorkflowActionTest extends BaseTaskTest { .thenReturn(vfModuleCustomization2); when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("da4d4327-fb7d-4311-ac7a-be7ba60cf969")) .thenReturn(vfModuleCustomization3); + workflowAction.selectExecutionList(execution); List ebbs = (List) execution.getVariable("flowsToExecute"); assertEqualsBulkFlowName(ebbs, "AssignServiceInstanceBB", "AssignVnfBB", "AssignVolumeGroupBB", @@ -471,6 +480,7 @@ public class WorkflowActionTest extends BaseTaskTest { doReturn(service).when(catalogDbClient).getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a"); when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, false, "my-custom-cloud-owner")).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); List ebbs = (List) execution.getVariable("flowsToExecute"); assertEqualsBulkFlowName(ebbs, "AssignServiceInstanceBB", "AssignNetworkBB", "CreateNetworkBB", @@ -2063,41 +2073,7 @@ public class WorkflowActionTest extends BaseTaskTest { workflowAction.traverseCatalogDbService(execution, sIRequest, resourceCounter, aaiResourceIds); } - @Test - public void sortVfModulesByBaseFirstTest() { - List resources = new ArrayList<>(); - Resource resource1 = new Resource(WorkflowType.VFMODULE, "111", false); - resource1.setBaseVfModule(false); - resources.add(resource1); - Resource resource2 = new Resource(WorkflowType.VFMODULE, "222", false); - resource2.setBaseVfModule(false); - resources.add(resource2); - Resource resource3 = new Resource(WorkflowType.VFMODULE, "333", false); - resource3.setBaseVfModule(true); - resources.add(resource3); - List result = workflowAction.sortVfModulesByBaseFirst(resources); - assertEquals("333", result.get(0).getResourceId()); - assertEquals("222", result.get(1).getResourceId()); - assertEquals("111", result.get(2).getResourceId()); - } - @Test - public void sortVfModulesByBaseLastTest() { - List resources = new ArrayList<>(); - Resource resource1 = new Resource(WorkflowType.VFMODULE, "111", false); - resource1.setBaseVfModule(true); - resources.add(resource1); - Resource resource2 = new Resource(WorkflowType.VFMODULE, "222", false); - resource2.setBaseVfModule(false); - resources.add(resource2); - Resource resource3 = new Resource(WorkflowType.VFMODULE, "333", false); - resource3.setBaseVfModule(false); - resources.add(resource3); - List result = workflowAction.sortVfModulesByBaseLast(resources); - assertEquals("333", result.get(0).getResourceId()); - assertEquals("222", result.get(1).getResourceId()); - assertEquals("111", result.get(2).getResourceId()); - } @Test public void findCatalogNetworkCollectionTest() { @@ -2136,17 +2112,6 @@ public class WorkflowActionTest extends BaseTaskTest { execution.getVariable("WorkflowActionErrorMessage")); } - @Test - public void verifyLackOfNullPointerExceptionForNullResource() { - ExecuteBuildingBlock result = null; - try { - result = workflowAction.buildExecuteBuildingBlock(new OrchestrationFlow(), null, null, null, null, null, - false, null, null, null, false, null, null, true, null); - } catch (NullPointerException e) { - fail("NullPointerException should not be thrown when 'resource' is null"); - } - assertNotNull(result); - } @Test public void traverseAAIServiceTest() { -- cgit 1.2.3-korg