diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks')
23 files changed, 927 insertions, 48 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/AbstractControllerExecution.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/AbstractControllerExecution.java index f3b767a8f1..1da9ad584a 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/AbstractControllerExecution.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/AbstractControllerExecution.java @@ -157,6 +157,16 @@ public abstract class AbstractControllerExecution<T> { } /** + * Check whether the controller scope is SERVICE + * + * @param controllerScope controller scope, e.g, pnf, vnf, vfModule, service + * @return true if the controller scope is service, else return false + */ + protected boolean isServiceResourceScope(final String controllerScope) { + return "service".equalsIgnoreCase(controllerScope); + } + + /** * Check whether the controller scope is VNF resource related. * * @param controllerScope controller scope, e.g, pnf, vnf, vfModule diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBB.java index 39a695b0b6..92be824691 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBB.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBB.java @@ -109,6 +109,8 @@ public class ControllerExecutionBB extends AbstractControllerExecution<BuildingB PnfResourceCustomization pnfResourceCustomization = catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(resourceCustomizationUuid); controllerActor = pnfResourceCustomization.getControllerActor(); + } else if (isServiceResourceScope(controllerScope)) { + return controllerActor; } else if (isVnfResourceScope(controllerScope)) { VnfResourceCustomization vnfResourceCustomization = catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(resourceCustomizationUuid); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java index c56ab3e71d..f2f3b5da08 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java @@ -26,7 +26,9 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.exception.BBObjectNotFoundException; import org.onap.so.client.exception.ExceptionBuilder; @@ -87,6 +89,11 @@ public class ControllerExecution { execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId()); execution.setVariable(PRC_BLUEPRINT_VERSION, pnfResourceCustomization.getBlueprintVersion()); execution.setVariable(PRC_BLUEPRINT_NAME, pnfResourceCustomization.getBlueprintName()); + } else if ("service".equalsIgnoreCase(scope)) { + GeneralBuildingBlock gbb = execution.getGeneralBuildingBlock(); + ModelInfoServiceInstance modelInfoServiceInstance = + gbb.getServiceInstance().getModelInfoServiceInstance(); + controllerActor = Optional.ofNullable(modelInfoServiceInstance.getControllerActor()).orElse("CDS"); } else { GenericVnf genericVnf = getGenericVnf(execution); String modelUuid = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid(); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java index 1fae5ce06c..5442f444ee 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java @@ -46,6 +46,7 @@ public class GenericCDSProcessingBB implements ControllerRunnable<BuildingBlockE public static final String CDS_ACTOR = "cds"; public static final String VNF_SCOPE = "vnf"; public static final String VF_MODULE_SCOPE = "vfmodule"; + public static final String SERVICE_SCOPE = "service"; @Autowired private ExceptionBuilder exceptionBuilder; @@ -59,8 +60,8 @@ public class GenericCDSProcessingBB implements ControllerRunnable<BuildingBlockE @Override public Boolean understand(ControllerContext<BuildingBlockExecution> context) { String scope = context.getControllerScope(); - return CDS_ACTOR.equalsIgnoreCase(context.getControllerActor()) - && (VNF_SCOPE.equalsIgnoreCase(scope) || VF_MODULE_SCOPE.equalsIgnoreCase(scope)); + return CDS_ACTOR.equalsIgnoreCase(context.getControllerActor()) && (SERVICE_SCOPE.equalsIgnoreCase(scope) + || VNF_SCOPE.equalsIgnoreCase(scope) || VF_MODULE_SCOPE.equalsIgnoreCase(scope)); } @Override diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java index 0d2844d08b..2a8852a4bd 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java @@ -22,13 +22,14 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; +import java.io.Serializable; import java.util.ArrayList; -import java.util.Arrays; import java.util.Comparator; import java.util.List; -public class Resource { +public class Resource implements Serializable { + private static final long serialVersionUID = 4259534487473481127L; private String resourceId; private WorkflowType resourceType; private boolean generated; @@ -37,6 +38,8 @@ public class Resource { private String vnfCustomizationId; private String vfModuleCustomizationId; private String cvnfModuleCustomizationId; + private String instanceName; + private String modelInvariantId; private int processingPriority; private Resource parent; private List<Resource> children; @@ -121,6 +124,23 @@ public class Resource { this.cvnfModuleCustomizationId = cvnfModuleCustomizationId; } + public String getInstanceName() { + return instanceName; + } + + public void setInstanceName(String instanceName) { + this.instanceName = instanceName; + } + + public String getModelInvariantId() { + return modelInvariantId; + } + + public void setModelInvariantId(String modelInvariantId) { + this.modelInvariantId = modelInvariantId; + } + + public int getProcessingPriority() { return processingPriority == 0 ? (isBaseVfModule() ? Integer.MIN_VALUE + 1 : 0) : processingPriority; } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index ce775af476..02508b8867 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -43,14 +43,18 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import org.apache.commons.lang3.SerializationUtils; +import org.apache.commons.lang3.StringUtils; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.javatuples.Pair; import org.onap.aai.domain.yang.Vnfc; @@ -351,6 +355,7 @@ public class WorkflowAction { } else { updateResourceIdsFromAAITraversal(flowsToExecute, resourceList, aaiResourceIds, serviceInstanceId); } + execution.setVariable("resources", resourceList); return flowsToExecute; } @@ -666,11 +671,12 @@ public class WorkflowAction { for (Pair<WorkflowType, String> pair : aaiResourceIds) { logger.debug("{}, {}", pair.getValue0(), pair.getValue1()); } - + Map<Resource, String> resourceInstanceIds = new HashMap<>(); Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE)) .forEach(type -> resourceList.stream().filter(resource -> type.equals(resource.getResourceType())) - .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource.getResourceId(), - retrieveAAIResourceId(aaiResourceIds, type), null, serviceInstanceId))); + .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource, + retrieveAAIResourceId(aaiResourceIds, type), null, serviceInstanceId, + resourceInstanceIds))); } private String retrieveAAIResourceId(List<Pair<WorkflowType, String>> aaiResourceIds, WorkflowType resource) { @@ -687,27 +693,45 @@ public class WorkflowAction { private void generateResourceIds(List<ExecuteBuildingBlock> flowsToExecute, List<Resource> resourceList, String serviceInstanceId) { + Map<Resource, String> resourceInstanceIds = new HashMap<>(); Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE)) .forEach(type -> resourceList.stream().filter(resource -> type.equals(resource.getResourceType())) - .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource.getResourceId(), - null, resource.getVirtualLinkKey(), serviceInstanceId))); + .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource, null, + resource.getVirtualLinkKey(), serviceInstanceId, resourceInstanceIds))); } protected void updateWorkflowResourceIds(List<ExecuteBuildingBlock> flowsToExecute, WorkflowType resourceType, - String key, String id, String virtualLinkKey, String serviceInstanceId) { + Resource resource, String id, String virtualLinkKey, String serviceInstanceId, + Map<Resource, String> resourceInstanceIds) { + String key = resource.getResourceId(); String resourceId = id; if (resourceId == null) { resourceId = UUID.randomUUID().toString(); } + resourceInstanceIds.put(resource, resourceId); + Set<String> assignedFlows = new LinkedHashSet<>(); for (ExecuteBuildingBlock ebb : flowsToExecute) { - if (key != null && key.equalsIgnoreCase(ebb.getBuildingBlock().getKey()) && (ebb.getBuildingBlock() - .getBpmnFlowName().contains(resourceType.toString()) - || (ebb.getBuildingBlock().getBpmnFlowName().contains(CONTROLLER) - && ebb.getBuildingBlock().getBpmnScope().equalsIgnoreCase(resourceType.toString())))) { + String resourceTypeStr = resourceType.toString(); + String flowName = ebb.getBuildingBlock().getBpmnFlowName(); + String scope = StringUtils.defaultString(ebb.getBuildingBlock().getBpmnScope()); + String action = StringUtils.defaultString(ebb.getBuildingBlock().getBpmnAction()); + + if (key != null && key.equalsIgnoreCase(ebb.getBuildingBlock().getKey()) + && isFlowAssignable(assignedFlows, ebb, resourceType, flowName + action) + && (flowName.contains(resourceTypeStr) + || (flowName.contains(CONTROLLER) && resourceTypeStr.equalsIgnoreCase(scope)))) { WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); workflowResourceIds.setServiceInstanceId(serviceInstanceId); + Resource parent = resource.getParent(); + if (parent != null && resourceInstanceIds.containsKey(parent)) { + WorkflowResourceIdsUtils.setResourceIdByWorkflowType(workflowResourceIds, parent.getResourceType(), + resourceInstanceIds.get(parent)); + } + WorkflowResourceIdsUtils.setInstanceNameByWorkflowType(workflowResourceIds, resourceType, + resource.getInstanceName()); WorkflowResourceIdsUtils.setResourceIdByWorkflowType(workflowResourceIds, resourceType, resourceId); ebb.setWorkflowResourceIds(workflowResourceIds); + assignedFlows.add(flowName + action); } if (virtualLinkKey != null && ebb.getBuildingBlock().isVirtualLink() && virtualLinkKey.equalsIgnoreCase(ebb.getBuildingBlock().getVirtualLinkKey())) { @@ -719,6 +743,12 @@ public class WorkflowAction { } } + private boolean isFlowAssignable(Set<String> assignedFlows, ExecuteBuildingBlock ebb, WorkflowType resourceType, + String assignedFlowName) { + String id = WorkflowResourceIdsUtils.getResourceIdByWorkflowType(ebb.getWorkflowResourceIds(), resourceType); + return !assignedFlows.contains(assignedFlowName) && id.isEmpty(); + } + protected WorkflowResourceIds populateResourceIdsFromApiHandler(DelegateExecution execution) { return WorkflowResourceIdsUtils.getWorkflowResourceIdsFromExecution(execution); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java index cd151bafea..b76cf1eb5f 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java @@ -111,13 +111,15 @@ public class WorkflowActionBBTasks { } int currentSequence = (int) execution.getVariable(BBConstants.G_CURRENT_SEQUENCE); - ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence); - - execution.setVariable("buildingBlock", ebb); - currentSequence++; - execution.setVariable(COMPLETED, currentSequence >= flowsToExecute.size()); - execution.setVariable(BBConstants.G_CURRENT_SEQUENCE, currentSequence); - + boolean completed = false; + if (currentSequence < flowsToExecute.size()) { + ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence); + execution.setVariable("buildingBlock", ebb); + execution.setVariable(BBConstants.G_CURRENT_SEQUENCE, currentSequence + 1); + } else { + completed = true; + } + execution.setVariable(COMPLETED, completed); } catch (Exception e) { workflowAction.buildAndThrowException(execution, "Internal Error occured during selectBB", e); } @@ -425,6 +427,9 @@ public class WorkflowActionBBTasks { final boolean aLaCarte = (boolean) execution.getVariable(BBConstants.G_ALACARTE); int currentSequence = (int) execution.getVariable(BBConstants.G_CURRENT_SEQUENCE); logger.debug("Current Sequence: {}", currentSequence); + if (currentSequence >= flowsToExecute.size()) { + execution.setVariable(COMPLETED, true); + } ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence - 1); String bbFlowName = ebb.getBuildingBlock().getBpmnFlowName(); if ("ActivateVfModuleBB".equalsIgnoreCase(bbFlowName) && aLaCarte 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 38ba0077e2..8c6fb2b38b 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 @@ -39,6 +39,7 @@ public final class WorkflowActionConstants { public static final String CREATE_INSTANCE = "createInstance"; public static final String DEACTIVATE_INSTANCE = "deactivateInstance"; public static final String DELETE_INSTANCE = "deleteInstance"; + public static final String UPGRADE_INSTANCE = "upgradeInstance"; public static final String FABRIC_CONFIGURATION = "FabricConfiguration"; public static final String NETWORKCOLLECTION = "NetworkCollection"; public static final String RECREATE_INSTANCE = "recreateInstance"; diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java index e4c6d2951f..c000e9475c 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java @@ -61,6 +61,7 @@ import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConst import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.DEACTIVATE_INSTANCE; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.DELETE_INSTANCE; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.UNASSIGN_INSTANCE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.UPGRADE_INSTANCE; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.FABRIC_CONFIGURATION; @@ -136,6 +137,7 @@ public class ServiceEBBLoader { } } else if ((ACTIVATE_INSTANCE.equalsIgnoreCase(requestAction) || UNASSIGN_INSTANCE.equalsIgnoreCase(requestAction) || DELETE_INSTANCE.equalsIgnoreCase(requestAction) + || UPGRADE_INSTANCE.equalsIgnoreCase(requestAction) || requestAction.equalsIgnoreCase("activate" + FABRIC_CONFIGURATION))) { // SERVICE-MACRO-ACTIVATE, SERVICE-MACRO-UNASSIGN, and // SERVICE-MACRO-DELETE @@ -193,8 +195,9 @@ public class ServiceEBBLoader { ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(resourceId); org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = bbInputSetup.getExistingServiceInstance(serviceInstanceAAI); - Resource serviceResource = + var serviceResource = new Resource(WorkflowType.SERVICE, serviceInstanceMSO.getServiceInstanceId(), false, null); + serviceResource.setModelInvariantId(serviceInstanceAAI.getModelInvariantId()); resourceList.add(serviceResource); traverseServiceInstanceMSOVnfs(resourceList, serviceResource, aaiResourceIds, serviceInstanceMSO); traverseServiceInstanceMSOPnfs(resourceList, serviceResource, aaiResourceIds, serviceInstanceMSO); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java index 1f932743ca..c383b4a73a 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java @@ -114,6 +114,7 @@ public class UserParamsServiceTraversal { Resource vnfResource = new Resource(WorkflowType.VNF, vnf.getModelInfo().getModelCustomizationId(), false, serviceResource); vnfResource.setProcessingPriority(vnf.getProcessingPriority()); + vnfResource.setInstanceName(vnf.getInstanceName()); resourceList.add(vnfResource); setResourceListForVfModules(execution, resourceList, vnfResource, validate, vnf); } @@ -170,6 +171,7 @@ public class UserParamsServiceTraversal { resource.setProcessingPriority(vfModule.getProcessingPriority()); resource.setBaseVfModule(vfModuleCustomization.getVfModule().getIsBase() != null && vfModuleCustomization.getVfModule().getIsBase()); + resource.setInstanceName(vfModule.getInstanceName()); resourceList.add(resource); return resource; } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListener.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListener.java index 272c6189b4..ff6c113af3 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListener.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListener.java @@ -29,8 +29,10 @@ import org.onap.so.bpmn.common.BBConstants; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner; import org.onap.so.bpmn.common.listener.flowmanipulator.PreFlowManipulator; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.db.catalog.beans.PnfResourceCustomization; +import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.beans.VnfResourceCustomization; import org.onap.so.db.catalog.client.CatalogDbClient; @@ -76,11 +78,11 @@ public class SkipCDSBuildingBlockListener implements PreFlowManipulator { BuildingBlockExecution execution) { String customizationUUID = currentBB.getBuildingBlock().getKey(); - if (Strings.isEmpty(customizationUUID)) { - return; - } - - if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("VNF") + if ("SERVICE".equalsIgnoreCase(currentBB.getBuildingBlock().getBpmnScope())) { + String modelUUID = currentBB.getRequestDetails().getModelInfo().getModelUuid(); + Service service = catalogDbClient.getServiceByID(modelUUID); + currentSequenceSkipCheck(execution, service.getSkipPostInstConf()); + } else if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("VNF") && containsIgnoreCaseAction(currentBB, vnfActions)) { List<VnfResourceCustomization> vnfResourceCustomizations = catalogDbClient.getVnfResourceCustomizationByModelUuid( diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/utils/WorkflowResourceIdsUtils.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/utils/WorkflowResourceIdsUtils.java index d16eac147e..9cabf6665c 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/utils/WorkflowResourceIdsUtils.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/utils/WorkflowResourceIdsUtils.java @@ -20,6 +20,7 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks.utils; +import org.apache.commons.lang3.StringUtils; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; @@ -63,6 +64,42 @@ public final class WorkflowResourceIdsUtils { } } + public static void setInstanceNameByWorkflowType(WorkflowResourceIds workflowResourceIds, WorkflowType resourceType, + String instanceName) { + if (resourceType == WorkflowType.VNF) { + workflowResourceIds.setVnfInstanceName(instanceName); + } else if (resourceType == WorkflowType.VFMODULE) { + workflowResourceIds.setVfModuleInstanceName(instanceName); + } + } + + public static String getResourceIdByWorkflowType(WorkflowResourceIds workflowResourceIds, + WorkflowType resourceType) { + switch (resourceType) { + case SERVICE: + return StringUtils.defaultString(workflowResourceIds.getServiceInstanceId()); + case VNF: + return StringUtils.defaultString(workflowResourceIds.getVnfId()); + case PNF: + return StringUtils.defaultString(workflowResourceIds.getPnfId()); + case VFMODULE: + return StringUtils.defaultString(workflowResourceIds.getVfModuleId()); + case VOLUMEGROUP: + return StringUtils.defaultString(workflowResourceIds.getVolumeGroupId()); + case NETWORK: + return StringUtils.defaultString(workflowResourceIds.getNetworkId()); + case NETWORKCOLLECTION: + return StringUtils.defaultString(workflowResourceIds.getNetworkCollectionId()); + case CONFIGURATION: + return StringUtils.defaultString(workflowResourceIds.getConfigurationId()); + case INSTANCE_GROUP: + return StringUtils.defaultString(workflowResourceIds.getInstanceGroupId()); + default: + return ""; + } + } + + public static WorkflowResourceIds getWorkflowResourceIdsFromExecution(DelegateExecution execution) { WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); workflowResourceIds.setServiceInstanceId((String) execution.getVariable("serviceInstanceId")); @@ -71,6 +108,8 @@ public final class WorkflowResourceIdsUtils { workflowResourceIds.setVnfId((String) execution.getVariable("vnfId")); workflowResourceIds.setVolumeGroupId((String) execution.getVariable("volumeGroupId")); workflowResourceIds.setInstanceGroupId((String) execution.getVariable("instanceGroupId")); + workflowResourceIds.setVnfInstanceName((String) execution.getVariable("vnfInstanceName")); + workflowResourceIds.setVfModuleInstanceName((String) execution.getVariable("vfModuleInstanceName")); return workflowResourceIds; } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/validators/UpgradePreWorkflowValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/validators/UpgradePreWorkflowValidator.java new file mode 100644 index 0000000000..5e82b4f284 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/validators/UpgradePreWorkflowValidator.java @@ -0,0 +1,114 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks.validators; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import org.onap.so.bpmn.common.BBConstants; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.listener.validation.PreWorkflowValidator; +import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.serviceinstancebeans.RequestDetails; +import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; +import org.springframework.stereotype.Component; + +@Component +public class UpgradePreWorkflowValidator implements PreWorkflowValidator { + + private static final String ERR_MSG_INVARIANT_MISMATCH = + "Request service modelInvariantId: %s does not match AAI service modelInvariantId: %s"; + private static final String ERR_MSG_EXISTING_VNFS_NOT_SUPPORTED = + "Existing vnfs in AAI are not supported by service model. Unsupported vnfCustomizationIds: %s"; + + private final CatalogDbClient catalogDbClient; + + private static final Function<WorkflowType, Predicate<Resource>> resourceType = + workflowType -> resource -> resource.getResourceType() == workflowType; + + public UpgradePreWorkflowValidator(CatalogDbClient catalogDbClient) { + this.catalogDbClient = catalogDbClient; + } + + @Override + public boolean shouldRunFor(String requestAction) { + return "upgradeInstance".equalsIgnoreCase(requestAction); + } + + @Override + public Optional<String> validate(BuildingBlockExecution execution) { + final String bpmnRequest = execution.getVariable(BBConstants.G_BPMN_REQUEST); + List<Resource> resources = execution.getVariable("resources"); + + Optional<ServiceInstancesRequest> sir = parseBpmnRequest(bpmnRequest); + if (sir.isEmpty()) { + return Optional.of("Failed to parse bpmnRequest"); + } + var requestDetails = sir.get().getRequestDetails(); + String requestModelInvariantId = requestDetails.getModelInfo().getModelInvariantId(); + + Optional<String> modelInvariantMismatch = validateInvariantId(resources, requestModelInvariantId); + if (modelInvariantMismatch.isPresent()) { + return modelInvariantMismatch; + } + + List<Resource> aaiVnfResources = getVnfResources(resources); + if (aaiVnfResources.isEmpty()) { + return Optional.empty(); + } + + String serviceModelUuid = requestDetails.getModelInfo().getModelUuid(); + Optional<List<VnfResourceCustomization>> vnfResourceCustomizations = + getVnfResourceCustomizations(serviceModelUuid); + if (vnfResourceCustomizations.isEmpty()) { + return Optional.of(String.format("Service model: %s does not exist in catalog db.", serviceModelUuid)); + } + + return validateExistingVnfsSupported(aaiVnfResources, vnfResourceCustomizations.get()); + } + + private Optional<ServiceInstancesRequest> parseBpmnRequest(String bpmnRequest) { + try { + return Optional.of(new ObjectMapper().readValue(bpmnRequest, ServiceInstancesRequest.class)); + } catch (IOException e) { + return Optional.empty(); + } + } + + private Optional<String> validateInvariantId(List<Resource> resources, String requestModelInvariantId) { + return resources.stream().filter(resourceType.apply(WorkflowType.SERVICE)).findFirst() + .filter(r -> !r.getModelInvariantId().equals(requestModelInvariantId)) + .map(r -> String.format(ERR_MSG_INVARIANT_MISMATCH, requestModelInvariantId, r.getModelInvariantId())); + } + + private Optional<List<VnfResourceCustomization>> getVnfResourceCustomizations(String serviceModelUuid) { + return Optional.ofNullable(catalogDbClient.getServiceByModelUUID(serviceModelUuid)) + .map(Service::getVnfCustomizations); + } + + private List<Resource> getVnfResources(List<Resource> resources) { + return resources.stream().filter(resourceType.apply(WorkflowType.VNF)).collect(Collectors.toList()); + } + + private Optional<String> validateExistingVnfsSupported(List<Resource> vnfResources, + List<VnfResourceCustomization> vnfResourceCustomizations) { + Set<String> modeledVnfCustomizationIds = vnfResourceCustomizations.stream() + .map(VnfResourceCustomization::getModelCustomizationUUID).collect(Collectors.toSet()); + + String unsupportedVnfCustomizationIds = vnfResources.stream().map(Resource::getVnfCustomizationId) + .filter(id -> !modeledVnfCustomizationIds.contains(id)).collect(Collectors.joining(",")); + + if (unsupportedVnfCustomizationIds.isEmpty()) { + return Optional.empty(); + } + return Optional.of(String.format(ERR_MSG_EXISTING_VNFS_NOT_SUPPORTED, unsupportedVnfCustomizationIds)); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java index cc99f178bd..8c1e8f6d62 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java @@ -181,9 +181,27 @@ public class AAIServiceInstanceResources { .createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstance.getServiceInstanceId())); org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = aaiObjectMapper.mapServiceInstance(serviceInstance); + mapEmptyStringsToNull(aaiServiceInstance); injectionHelper.getAaiClient().update(serviceInstanceURI, aaiServiceInstance); } + /* + * Per serialization configurations in GraphInventoryCommonObjectMapperPatchProvider, empty strings are mapped to + * null and included in the payload. Null values are on the other hand excluded. Passing null values in a PATCH + * request to AAI will fail. We need to map empty strings to null before serialization in order to exclude these + * values from the payload. + */ + private void mapEmptyStringsToNull(org.onap.aai.domain.yang.ServiceInstance serviceInstance) { + if (serviceInstance != null) { + if ("".equals(serviceInstance.getServiceType())) + serviceInstance.setServiceType(null); + if ("".equals(serviceInstance.getServiceRole())) + serviceInstance.setServiceRole(null); + if ("".equals(serviceInstance.getServiceFunction())) + serviceInstance.setServiceFunction(null); + } + } + public boolean checkInstanceServiceNameInUse(ServiceInstance serviceInstance) { AAIPluralResourceUri uriSI = AAIUriFactory.createNodesUri(Types.SERVICE_INSTANCES.getFragment()) .queryParam("service-instance-name", serviceInstance.getServiceInstanceName()); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/GrpcNettyServer.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/GrpcNettyServer.java index a6e29227a0..a0a47a1d16 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/GrpcNettyServer.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/GrpcNettyServer.java @@ -31,7 +31,7 @@ import javax.annotation.PostConstruct; import org.junit.Rule; import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType; import org.onap.ccsdk.cds.controllerblueprints.common.api.Status; -import org.onap.ccsdk.cds.controllerblueprints.processing.api.BlueprintProcessingServiceGrpc.BlueprintProcessingServiceImplBase; +import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase; import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput; import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput; import org.slf4j.Logger; @@ -40,7 +40,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component -public class GrpcNettyServer extends BlueprintProcessingServiceImplBase { +public class GrpcNettyServer extends BluePrintProcessingServiceImplBase { private static final Logger logger = LoggerFactory.getLogger(GrpcNettyServer.class); @@ -60,7 +60,7 @@ public class GrpcNettyServer extends BlueprintProcessingServiceImplBase { @PostConstruct public void start() throws IOException { - final BlueprintProcessingServiceImplBase blueprintPrcessorImpl = new BlueprintProcessingServiceImplBase() { + final BluePrintProcessingServiceImplBase blueprintPrcessorImpl = new BluePrintProcessingServiceImplBase() { @Override public StreamObserver<ExecutionServiceInput> process( StreamObserver<ExecutionServiceOutput> responseObserver) { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java index fb15ffa2b3..f22932b988 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java @@ -25,7 +25,9 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; @@ -37,6 +39,8 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelConstants; import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.catalog.beans.Workflow; +import org.onap.so.db.catalog.client.CatalogDbClient; @RunWith(MockitoJUnitRunner.class) public class ServiceLevelTest { @@ -44,11 +48,15 @@ public class ServiceLevelTest { private static final String EXECUTION_KEY_PNF_NAME_LIST = "pnfNameList"; private static final String EXECUTION_KEY_PNF_COUNTER = "pnfCounter"; private static final String PARAM_NAME = "param1"; - private static final String SCOPE = "scope1"; private static final String PNF_NAME = "pnfName1"; + private static final String OPERATION_NAME = ServiceLevelConstants.HEALTH_CHECK_OPERATION; + private static final String SCOPE = ServiceLevelConstants.PNF; + private static final String WORKFLOW_NAME = "workflowTestName"; @Mock private ExceptionBuilder exceptionBuilderMock; + @Mock + private CatalogDbClient catalogDbClientMock; @InjectMocks private ServiceLevel testedObject; @@ -60,6 +68,31 @@ public class ServiceLevelTest { } @Test + public void fetchWorkflowUsingScope_catalogDBReturnsEmpty() { + // given + when(catalogDbClientMock.findWorkflowByOperationName(OPERATION_NAME)).thenReturn(Collections.emptyList()); + // when + String workflowResult = testedObject.fetchWorkflowUsingScope(SCOPE, OPERATION_NAME); + // then + assertThat(workflowResult).isEqualTo("GenericPnfHealthCheck"); + } + + @Test + public void fetchWorkflowUsingScope_catalogDBReturnsNotEmpty() { + // given + Workflow workflow = new Workflow(); + workflow.setResourceTarget(SCOPE); + workflow.setName(WORKFLOW_NAME); + List<Workflow> workflowList = new ArrayList<>(); + workflowList.add(workflow); + when(catalogDbClientMock.findWorkflowByOperationName(OPERATION_NAME)).thenReturn(workflowList); + // when + String workflowResult = testedObject.fetchWorkflowUsingScope(SCOPE, OPERATION_NAME); + // then + assertThat(workflowResult).isEqualTo(WORKFLOW_NAME); + } + + @Test public void pnfCounterExecution_success() { // given execution.setVariable(EXECUTION_KEY_PNF_NAME_LIST, createPnfNameList()); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java index 5cd3055b5f..cbb746d514 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java @@ -149,7 +149,7 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { workflowActionBBTasks.selectBB(execution); boolean success = (boolean) execution.getVariable("completed"); int currentSequence = (int) execution.getVariable("gCurrentSequence"); - assertTrue(success); + assertFalse(success); assertEquals(1, currentSequence); } 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 e52d2dfecf..021bac3a7a 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 @@ -51,8 +51,11 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; @@ -118,6 +121,8 @@ public class WorkflowActionTest extends BaseTaskTest { private static final String MACRO_CREATE_NETWORK_COLLECTION_JSON = "Macro/CreateNetworkCollection.json"; private static final String MACRO_VNF_MACRO_REPLACE_JSON = "Macro/VnfMacroReplace.json"; private static final String MACRO_CREATE_JSON = "Macro/ServiceMacroAssignVnfAndPnf.json"; + private static final String MACRO_CREATE_SERVICE_MULTIPLE_SAME_MODEL_VNF_VFMODULE = + "Macro/ServiceMacroCreateMultipleSameModelVnfsAndVfModules.json"; @Mock protected Environment environment; @@ -752,6 +757,139 @@ public class WorkflowActionTest extends BaseTaskTest { } @Test + public void selectExecutionListServiceMacroCreateWithMultipleSameModelVnfAndVfModules() throws Exception { + String gAction = "createInstance"; + String resource = "Service"; + String bpmnRequest = readBpmnRequestFromFile(MACRO_CREATE_SERVICE_MULTIPLE_SAME_MODEL_VNF_VFMODULE); + initExecution(gAction, bpmnRequest, false); + execution.setVariable("requestUri", "v7/serviceInstances"); + execution.setVariable("serviceInstanceId", UUID.randomUUID().toString()); + + // Service-Macro-Create + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = createFlowList("AssignServiceInstanceBB", "CreateNetworkCollectionBB", + "AssignNetworkBB", "AssignVnfBB", "AssignVolumeGroupBB", "AssignVfModuleBB", "ControllerExecutionBB", + "AssignPnfBB", "WaitForPnfReadyBB", "ControllerExecutionBB", "ControllerExecutionBB", "ActivatePnfBB", + "CreateNetworkBB", "ActivateNetworkBB", "CreateVolumeGroupBB", "ActivateVolumeGroupBB", + "CreateVfModuleBB", "ActivateVfModuleBB", "ControllerExecutionBB", "ActivateVnfBB", + "ActivateNetworkCollectionBB", "ActivateServiceInstanceBB"); + orchFlows.get(6).setBpmnAction("config-assign"); + orchFlows.get(6).setBpmnScope("vnf"); + orchFlows.get(9).setBpmnAction("config-assign"); + orchFlows.get(9).setBpmnScope("pnf"); + orchFlows.get(10).setBpmnAction("config-deploy"); + orchFlows.get(10).setBpmnScope("pnf"); + orchFlows.get(18).setBpmnAction("config-deploy"); + orchFlows.get(18).setBpmnScope("vnf"); + northBoundRequest.setOrchestrationFlowList(orchFlows); + + Service service = new Service(); + service.setModelUUID("f2444885-3c76-4ddc-8668-7741c0631495"); + + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + vfModuleCustomization.setModelCustomizationUUID("3bd19000-6d21-49f1-9eb3-ea76a6eac5e0"); + vfModuleCustomization.setVolumeHeatEnv(new HeatEnvironment()); + org.onap.so.db.catalog.beans.VfModule vfModule = new org.onap.so.db.catalog.beans.VfModule(); + vfModule.setVolumeHeatTemplate(new HeatTemplate()); + vfModuleCustomization.setVfModule(vfModule); + + VfModuleCustomization vfModuleCustomization2 = new VfModuleCustomization(); + vfModuleCustomization2.setModelCustomizationUUID("83677d89-428a-407b-b4ec-738e68275d84"); + vfModuleCustomization2.setHeatEnvironment(new HeatEnvironment()); + org.onap.so.db.catalog.beans.VfModule vfModule2 = new org.onap.so.db.catalog.beans.VfModule(); + vfModule2.setModuleHeatTemplate(new HeatTemplate()); + vfModuleCustomization2.setVfModule(vfModule2); + + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, + false, "DEFAULT")).thenReturn(northBoundRequest); + when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("3bd19000-6d21-49f1-9eb3-ea76a6eac5e0")) + .thenReturn(vfModuleCustomization); + when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("83677d89-428a-407b-b4ec-738e68275d84")) + .thenReturn(vfModuleCustomization2); + when(catalogDbClient.getServiceByID("f2444885-3c76-4ddc-8668-7741c0631495")).thenReturn(service); + + + Resource serviceResource = + new Resource(WorkflowType.SERVICE, "f2444885-3c76-4ddc-8668-7741c0631495", false, null); + Resource vnfResource1 = + new Resource(WorkflowType.VNF, "0d0ba1ee-6b7f-47fe-8266-2967993b2c08", false, serviceResource); + vnfResource1.setInstanceName("vnf-instanceName-1"); + Resource vfmResource1 = + new Resource(WorkflowType.VFMODULE, "3bd19000-6d21-49f1-9eb3-ea76a6eac5e0", false, vnfResource1); + vfmResource1.setInstanceName("demo-network-1"); + Resource vfmResource2 = + new Resource(WorkflowType.VFMODULE, "83677d89-428a-407b-b4ec-738e68275d84", false, vnfResource1); + vfmResource2.setInstanceName("demo-1"); + Resource vnfResource2 = + new Resource(WorkflowType.VNF, "0d0ba1ee-6b7f-47fe-8266-2967993b2c08", false, serviceResource); + vnfResource2.setInstanceName("vnf-instanceName-2"); + Resource vfmResource3 = + new Resource(WorkflowType.VFMODULE, "83677d89-428a-407b-b4ec-738e68275d84", false, vnfResource2); + vfmResource3.setInstanceName("demo-2"); + Resource vfmResource4 = + new Resource(WorkflowType.VFMODULE, "83677d89-428a-407b-b4ec-738e68275d84", false, vnfResource2); + vfmResource4.setInstanceName("demo-3"); + + when(userParamsServiceTraversal.getResourceListFromUserParams(any(), anyList(), anyString(), any())) + .thenReturn(Arrays.asList(serviceResource, vnfResource1, vnfResource2, vfmResource1, vfmResource2, + vfmResource3, vfmResource4)); + + workflowAction.selectExecutionList(execution); + + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + + Map<String, List<ExecuteBuildingBlock>> flowNamesToEbbList = + ebbs.stream().collect(Collectors.groupingBy(e -> e.getBuildingBlock().getBpmnFlowName())); + + assertEquals(1, flowNamesToEbbList.get("AssignServiceInstanceBB").size()); + assertEquals(2, flowNamesToEbbList.get("AssignVnfBB").size()); + assertEquals(4, flowNamesToEbbList.get("AssignVfModuleBB").size()); + assertEquals(4, flowNamesToEbbList.get("ControllerExecutionBB").size()); + assertEquals(4, flowNamesToEbbList.get("CreateVfModuleBB").size()); + assertEquals(4, flowNamesToEbbList.get("ActivateVfModuleBB").size()); + assertEquals(2, flowNamesToEbbList.get("ActivateVnfBB").size()); + assertEquals(1, flowNamesToEbbList.get("ActivateServiceInstanceBB").size()); + + String vnfInstanceId1 = flowNamesToEbbList.get("AssignVnfBB").get(0).getWorkflowResourceIds().getVnfId(); + String vnfInstanceId2 = flowNamesToEbbList.get("AssignVnfBB").get(1).getWorkflowResourceIds().getVnfId(); + + // should be 3 = 1 AssignVfModuleBB + 1 CreateVfModuleBB + 1 ActivateVfModuleBB + boolean allEbbsForVfModule1HaveCorrectParentVnfId = + 3 == ebbs.stream().map(ExecuteBuildingBlock::getWorkflowResourceIds) + .filter(w -> "demo-network-1".equals(w.getVfModuleInstanceName()) + && vnfInstanceId1.equals(w.getVnfId())) + .count(); + boolean allEbbsForVfModule2HaveCorrectParentVnfId = 3 == ebbs.stream() + .map(ExecuteBuildingBlock::getWorkflowResourceIds) + .filter(w -> "demo-1".equals(w.getVfModuleInstanceName()) && vnfInstanceId1.equals(w.getVnfId())) + .count(); + boolean allEbbsForVfModule3HaveCorrectParentVnfId = 3 == ebbs.stream() + .map(ExecuteBuildingBlock::getWorkflowResourceIds) + .filter(w -> "demo-2".equals(w.getVfModuleInstanceName()) && vnfInstanceId2.equals(w.getVnfId())) + .count(); + boolean allEbbsForVfModule4HaveCorrectParentVnfId = 3 == ebbs.stream() + .map(ExecuteBuildingBlock::getWorkflowResourceIds) + .filter(w -> "demo-3".equals(w.getVfModuleInstanceName()) && vnfInstanceId2.equals(w.getVnfId())) + .count(); + assertTrue(allEbbsForVfModule1HaveCorrectParentVnfId); + assertTrue(allEbbsForVfModule2HaveCorrectParentVnfId); + assertTrue(allEbbsForVfModule3HaveCorrectParentVnfId); + assertTrue(allEbbsForVfModule4HaveCorrectParentVnfId); + + boolean controllerExecutionBBsforVnf1HaveCorrectVnfId = flowNamesToEbbList.get("ControllerExecutionBB").stream() + .filter(e -> vnfInstanceId1.equals(e.getWorkflowResourceIds().getVnfId())) + .map(ExecuteBuildingBlock::getBuildingBlock).map(BuildingBlock::getBpmnAction) + .collect(Collectors.toSet()).containsAll(Set.of("config-assign", "config-deploy")); + assertTrue(controllerExecutionBBsforVnf1HaveCorrectVnfId); + + boolean controllerExecutionBBsforVnf2HaveCorrectVnfId = flowNamesToEbbList.get("ControllerExecutionBB").stream() + .filter(e -> vnfInstanceId2.equals(e.getWorkflowResourceIds().getVnfId())) + .map(ExecuteBuildingBlock::getBuildingBlock).map(BuildingBlock::getBpmnAction) + .collect(Collectors.toSet()).containsAll(Set.of("config-assign", "config-deploy")); + assertTrue(controllerExecutionBBsforVnf2HaveCorrectVnfId); + } + + @Test public void selectExecutionListServiceMacroDeleteTest() throws Exception { String gAction = "deleteInstance"; String resource = "Service"; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversalTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversalTest.java index 58fee86ade..cac7f872b3 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversalTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversalTest.java @@ -53,6 +53,7 @@ import java.util.stream.Collectors; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -63,6 +64,8 @@ public class UserParamsServiceTraversalTest extends BaseTaskTest { private static final String MACRO_ASSIGN_PNF_JSON = "Macro/ServiceMacroAssignPnf.json"; private static final String NETWORK_COLLECTION_JSON = "Macro/CreateNetworkCollection.json"; private static final String MACRO_CREATE_WITHOUT_RESOURCES_JSON = "Macro/ServiceMacroCreateWithoutResources.json"; + private static final String MACRO_CREATE_SVC_SAME_MODEL_VNF_VFMODULE = + "Macro/ServiceMacroCreateMultipleSameModelVnfsAndVfModules.json"; private static final String serviceInstanceId = "123"; private DelegateExecution execution; private CatalogDbClient mockCatalogDbClient; @@ -80,8 +83,6 @@ public class UserParamsServiceTraversalTest extends BaseTaskTest { @Test public void getResourceListFromUserParams() throws Exception { initExecution(requestAction, readBpmnRequestFromFile(MACRO_CREATE_WITHOUT_RESOURCES_JSON), false); - Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) - .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), anyString(), anyString()); @@ -96,9 +97,62 @@ public class UserParamsServiceTraversalTest extends BaseTaskTest { } @Test + public void getResourceListFromUserParamsMultipleSameModelVnfVfModule() throws Exception { + initExecution("createInstance", readBpmnRequestFromFile(MACRO_CREATE_SVC_SAME_MODEL_VNF_VFMODULE), false); + Mockito.doReturn(getVfModuleCustomization("3bd19000-6d21-49f1-9eb3-ea76a6eac5e0", false)) + .when(mockCatalogDbClient) + .getVfModuleCustomizationByModelCuztomizationUUID("3bd19000-6d21-49f1-9eb3-ea76a6eac5e0"); + Mockito.doReturn(getVfModuleCustomization("83677d89-428a-407b-b4ec-738e68275d84", false)) + .when(mockCatalogDbClient) + .getVfModuleCustomizationByModelCuztomizationUUID("83677d89-428a-407b-b4ec-738e68275d84"); + + List<Resource> resources = userParamsServiceTraversal.getResourceListFromUserParams(execution, getUserParams(), + serviceInstanceId, requestAction); + + assertEquals(7, resources.size()); + + Resource service = resources.get(0); + assertTrue(service.getResourceType() == WorkflowType.SERVICE); + assertEquals(2, service.getChildren().size()); + + Resource vnf1 = service.getChildren().get(0); + assertEquals(service, vnf1.getParent()); + assertEquals("vnf-instanceName-1", vnf1.getInstanceName()); + assertEquals("0d0ba1ee-6b7f-47fe-8266-2967993b2c08", vnf1.getResourceId()); + assertEquals(2, vnf1.getChildren().size()); + + Resource vnf2 = service.getChildren().get(1); + assertEquals(service, vnf2.getParent()); + assertEquals("vnf-instanceName-2", vnf2.getInstanceName()); + assertEquals("0d0ba1ee-6b7f-47fe-8266-2967993b2c08", vnf2.getResourceId()); + assertEquals(2, vnf2.getChildren().size()); + + Resource vfmodule1 = vnf1.getChildren().get(0); + assertEquals(vnf1, vfmodule1.getParent()); + assertEquals("demo-network-1", vfmodule1.getInstanceName()); + assertEquals("3bd19000-6d21-49f1-9eb3-ea76a6eac5e0", vfmodule1.getResourceId()); + + Resource vfmodule2 = vnf1.getChildren().get(1); + assertEquals(vnf1, vfmodule2.getParent()); + assertEquals("demo-1", vfmodule2.getInstanceName()); + assertEquals("83677d89-428a-407b-b4ec-738e68275d84", vfmodule2.getResourceId()); + + Resource vfmodule3 = vnf2.getChildren().get(0); + assertEquals(vnf2, vfmodule3.getParent()); + assertEquals("demo-2", vfmodule3.getInstanceName()); + assertEquals("83677d89-428a-407b-b4ec-738e68275d84", vfmodule3.getResourceId()); + + Resource vfmodule4 = vnf2.getChildren().get(1); + assertEquals(vnf2, vfmodule4.getParent()); + assertEquals("demo-3", vfmodule4.getInstanceName()); + assertEquals("83677d89-428a-407b-b4ec-738e68275d84", vfmodule4.getResourceId()); + } + + @Test public void getResourceListFromUserParamsForVnfs() throws Exception { initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_JSON), false); - Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) + Mockito.doReturn(getVfModuleCustomization("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f", true)) + .when(mockCatalogDbClient) .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), anyString(), anyString()); @@ -117,7 +171,8 @@ public class UserParamsServiceTraversalTest extends BaseTaskTest { @Test public void getResourceListFromUserParamsForVnfsWithPriorities() throws Exception { initExecution(requestAction, readBpmnRequestFromFile(MACRO_CREATE_JSON), false); - Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) + Mockito.doReturn(getVfModuleCustomization("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f", true)) + .when(mockCatalogDbClient) .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), anyString(), anyString()); @@ -137,8 +192,6 @@ public class UserParamsServiceTraversalTest extends BaseTaskTest { @Test public void getResourceListFromUserParamsForPnfs() throws Exception { initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_PNF_JSON), false); - Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) - .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), anyString(), anyString()); @@ -156,8 +209,6 @@ public class UserParamsServiceTraversalTest extends BaseTaskTest { public void getResourceListFromUserParamsForNetworks() throws Exception { requestAction = "createInstance"; initExecution(requestAction, readBpmnRequestFromFile(NETWORK_COLLECTION_JSON), false); - Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) - .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), anyString(), anyString()); Mockito.doReturn(getService()).when(mockCatalogDbClient).getServiceByID(anyString()); @@ -230,13 +281,17 @@ public class UserParamsServiceTraversalTest extends BaseTaskTest { return service; } - private VfModuleCustomization getVfModuleCustomization() { + private VfModuleCustomization getVfModuleCustomization(String modelCustomizationUUID, boolean includeVolumeGroup) { VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); - vfModuleCustomization.setVolumeHeatEnv(new HeatEnvironment()); - vfModuleCustomization.setModelCustomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + vfModuleCustomization.setModelCustomizationUUID(modelCustomizationUUID); VfModule vfModule = new VfModule(); - vfModule.setVolumeHeatTemplate(new HeatTemplate()); - vfModule.setModelName("helm"); + if (includeVolumeGroup) { + vfModuleCustomization.setVolumeHeatEnv(new HeatEnvironment()); + vfModule.setVolumeHeatTemplate(new HeatTemplate()); + vfModule.setModelName("helm"); + } else { + vfModuleCustomization.setHeatEnvironment(new HeatEnvironment()); + } vfModule.setModuleHeatTemplate(new HeatTemplate()); vfModuleCustomization.setVfModule(vfModule); return vfModuleCustomization; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListenerTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListenerTest.java index fdf4d36c89..b23147e351 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListenerTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListenerTest.java @@ -37,6 +37,7 @@ import org.onap.so.bpmn.common.DelegateExecutionImpl; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.db.catalog.beans.PnfResourceCustomization; +import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.beans.VnfResourceCustomization; import org.onap.so.db.catalog.client.CatalogDbClient; @@ -46,6 +47,7 @@ import org.onap.so.serviceinstancebeans.RequestDetails; @RunWith(MockitoJUnitRunner.Silent.class) public class SkipCDSBuildingBlockListenerTest { + private static final String SERVICE_SCOPE = "service"; private static final String VNF_SCOPE = "VNF"; private static final String VF_SCOPE = "VFModule"; private static final String PNF_SCOPE = "pnf"; @@ -90,6 +92,18 @@ public class SkipCDSBuildingBlockListenerTest { } @Test + public void testSkipCDSforService() { + setBuildingBlockAndCurrentSequence(SERVICE_SCOPE, "service-config-assign", 0); + Service service = new Service(); + when(catalogDbClient.getServiceByID(TEST_MODELUUID)).thenReturn(service); + + skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution); + + actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE); + assertEquals(1, actual); + } + + @Test public void testProcessForVNFToSkipCDSBB() { // given setBuildingBlockAndCurrentSequence(VNF_SCOPE, VNF_TEST_ACTION, 0); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/utils/WorkflowResourceIdsUtilsTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/utils/WorkflowResourceIdsUtilsTest.java index 0d68cf362b..996c0c07e1 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/utils/WorkflowResourceIdsUtilsTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/utils/WorkflowResourceIdsUtilsTest.java @@ -40,7 +40,8 @@ public class WorkflowResourceIdsUtilsTest { private static final String PNF_ID = "pnfId"; private static final String NETWORK_COLLECTION_ID = "networkCollectionId"; private static final String CONFIGURATION_ID = "configurationId"; - + private static final String VNF_INSTANCE_NAME = "vnfInstanceNameId"; + private static final String VF_MODULE_INSTANCE_NAME = "vfModuleInstanceNameId"; private WorkflowResourceIds workflowResourceIds; @Before @@ -57,6 +58,8 @@ public class WorkflowResourceIdsUtilsTest { execution.setVariable("vnfId", VNF_ID); execution.setVariable("volumeGroupId", VOLUME_GROUP_ID); execution.setVariable("instanceGroupId", INSTANCE_GROUP_ID); + execution.setVariable("vnfInstanceName", VNF_INSTANCE_NAME); + execution.setVariable("vfModuleInstanceName", VF_MODULE_INSTANCE_NAME); workflowResourceIds = WorkflowResourceIdsUtils.getWorkflowResourceIdsFromExecution(execution); @@ -66,54 +69,84 @@ public class WorkflowResourceIdsUtilsTest { assertEquals(VNF_ID, workflowResourceIds.getVnfId()); assertEquals(VOLUME_GROUP_ID, workflowResourceIds.getVolumeGroupId()); assertEquals(INSTANCE_GROUP_ID, workflowResourceIds.getInstanceGroupId()); + assertEquals(VNF_INSTANCE_NAME, workflowResourceIds.getVnfInstanceName()); + assertEquals(VF_MODULE_INSTANCE_NAME, workflowResourceIds.getVfModuleInstanceName()); } @Test public void shouldProperlySetServiceInstanceId() { assertFieldSetProperly(WorkflowType.SERVICE, SERVICE_ID, workflowResourceIds::getServiceInstanceId); + assertEquals(SERVICE_ID, + WorkflowResourceIdsUtils.getResourceIdByWorkflowType(workflowResourceIds, WorkflowType.SERVICE)); } @Test public void shouldProperlySetVnfId() { assertFieldSetProperly(WorkflowType.VNF, VNF_ID, workflowResourceIds::getVnfId); - + assertEquals(VNF_ID, + WorkflowResourceIdsUtils.getResourceIdByWorkflowType(workflowResourceIds, WorkflowType.VNF)); } @Test public void shouldProperlySetPnfId() { assertFieldSetProperly(WorkflowType.PNF, PNF_ID, workflowResourceIds::getPnfId); + assertEquals(PNF_ID, + WorkflowResourceIdsUtils.getResourceIdByWorkflowType(workflowResourceIds, WorkflowType.PNF)); } @Test public void shouldProperlySetVfModuleId() { assertFieldSetProperly(WorkflowType.VFMODULE, VF_MODULE_ID, workflowResourceIds::getVfModuleId); + assertEquals(VF_MODULE_ID, + WorkflowResourceIdsUtils.getResourceIdByWorkflowType(workflowResourceIds, WorkflowType.VFMODULE)); } @Test public void shouldProperlySetVolumeGroupId() { assertFieldSetProperly(WorkflowType.VOLUMEGROUP, VOLUME_GROUP_ID, workflowResourceIds::getVolumeGroupId); + assertEquals(VOLUME_GROUP_ID, + WorkflowResourceIdsUtils.getResourceIdByWorkflowType(workflowResourceIds, WorkflowType.VOLUMEGROUP)); } @Test public void shouldProperlySetNetworkId() { assertFieldSetProperly(WorkflowType.NETWORK, NETWORK_ID, workflowResourceIds::getNetworkId); + assertEquals(NETWORK_ID, + WorkflowResourceIdsUtils.getResourceIdByWorkflowType(workflowResourceIds, WorkflowType.NETWORK)); } @Test public void shouldProperlySetNetworkCollectionId() { assertFieldSetProperly(WorkflowType.NETWORKCOLLECTION, NETWORK_COLLECTION_ID, workflowResourceIds::getNetworkCollectionId); - + assertEquals(NETWORK_COLLECTION_ID, WorkflowResourceIdsUtils.getResourceIdByWorkflowType(workflowResourceIds, + WorkflowType.NETWORKCOLLECTION)); } @Test public void shouldProperlySetConfigurationId() { assertFieldSetProperly(WorkflowType.CONFIGURATION, CONFIGURATION_ID, workflowResourceIds::getConfigurationId); + assertEquals(CONFIGURATION_ID, + WorkflowResourceIdsUtils.getResourceIdByWorkflowType(workflowResourceIds, WorkflowType.CONFIGURATION)); } @Test public void shouldProperlySetInstanceGroupId() { assertFieldSetProperly(WorkflowType.INSTANCE_GROUP, INSTANCE_GROUP_ID, workflowResourceIds::getInstanceGroupId); + assertEquals(INSTANCE_GROUP_ID, + WorkflowResourceIdsUtils.getResourceIdByWorkflowType(workflowResourceIds, WorkflowType.INSTANCE_GROUP)); + } + + @Test + public void shouldPropertySetVnfInstanceName() { + assertFieldSetProperlyInstanceName(WorkflowType.VNF, VNF_INSTANCE_NAME, + workflowResourceIds::getVnfInstanceName); + } + + @Test + public void shouldPropertySetVfModuleInstanceName() { + assertFieldSetProperlyInstanceName(WorkflowType.VFMODULE, VF_MODULE_INSTANCE_NAME, + workflowResourceIds::getVfModuleInstanceName); } private void assertFieldSetProperly(WorkflowType workflowType, String expectedId, @@ -121,4 +154,13 @@ public class WorkflowResourceIdsUtilsTest { WorkflowResourceIdsUtils.setResourceIdByWorkflowType(workflowResourceIds, workflowType, expectedId); assertEquals(expectedId, testedObjectField.get()); } + + private void assertFieldSetProperlyInstanceName(WorkflowType workflowType, String expectedId, + Supplier<String> testedObjectField) { + WorkflowResourceIdsUtils.setInstanceNameByWorkflowType(workflowResourceIds, workflowType, expectedId); + assertEquals(expectedId, testedObjectField.get()); + } + + + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/validators/UpgradePreWorkflowValidatorTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/validators/UpgradePreWorkflowValidatorTest.java new file mode 100644 index 0000000000..1066ca1317 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/validators/UpgradePreWorkflowValidatorTest.java @@ -0,0 +1,156 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks.validators; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.so.bpmn.common.BBConstants; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.RequestDetails; +import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; + +public class UpgradePreWorkflowValidatorTest { + + @Mock + private CatalogDbClient catalogDbClient; + + private UpgradePreWorkflowValidator validator; + + private ObjectMapper objectMapper; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + validator = new UpgradePreWorkflowValidator(catalogDbClient); + objectMapper = new ObjectMapper(); + } + + @Test + public void shouldRunFor() { + assertTrue(validator.shouldRunFor("upgradeInstance")); + assertFalse(validator.shouldRunFor("createInstance")); + } + + private BuildingBlockExecution createExecution(ServiceInstancesRequest sir, List<Resource> resourceList) + throws JsonProcessingException { + BuildingBlockExecution mock = Mockito.mock(BuildingBlockExecution.class); + String jsonSir = objectMapper.writer().writeValueAsString(sir); + when(mock.getVariable(BBConstants.G_BPMN_REQUEST)).thenReturn(jsonSir); + when(mock.getVariable("resources")).thenReturn(resourceList); + return mock; + } + + @Test + public void validateModelInvariantMismatch() throws JsonProcessingException { + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + sir.setRequestDetails(new RequestDetails()); + sir.getRequestDetails().setModelInfo(new ModelInfo()); + sir.getRequestDetails().getModelInfo().setModelInvariantId(UUID.randomUUID().toString()); + + Resource serviceResource = new Resource(WorkflowType.SERVICE, "", false, null); + String aaiModelInvariantId = UUID.randomUUID().toString(); + serviceResource.setModelInvariantId(aaiModelInvariantId); + + BuildingBlockExecution execution = createExecution(sir, Arrays.asList(serviceResource)); + + Optional<String> message = validator.validate(execution); + + assertTrue(message.isPresent()); + assertTrue(message.get().startsWith("Request service modelInvariantId")); + } + + @Test + public void validateNoVnfsInAAI() throws JsonProcessingException { + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + sir.setRequestDetails(new RequestDetails()); + sir.getRequestDetails().setModelInfo(new ModelInfo()); + String modelInvariantId = UUID.randomUUID().toString(); + sir.getRequestDetails().getModelInfo().setModelInvariantId(modelInvariantId); + + Resource serviceResource = new Resource(WorkflowType.SERVICE, "", false, null); + serviceResource.setModelInvariantId(modelInvariantId); + + BuildingBlockExecution execution = createExecution(sir, Arrays.asList(serviceResource)); + + Optional<String> message = validator.validate(execution); + + assertThat(message).isEmpty(); + } + + @Test + public void validateAAIVnfsNotSupported() throws JsonProcessingException { + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + sir.setRequestDetails(new RequestDetails()); + sir.getRequestDetails().setModelInfo(new ModelInfo()); + sir.getRequestDetails().getModelInfo().setModelUuid(UUID.randomUUID().toString()); + String modelInvariantId = UUID.randomUUID().toString(); + sir.getRequestDetails().getModelInfo().setModelInvariantId(modelInvariantId); + + Resource serviceResource = new Resource(WorkflowType.SERVICE, "", false, null); + serviceResource.setModelInvariantId(modelInvariantId); + Resource vnfResource = new Resource(WorkflowType.VNF, "", false, serviceResource); + vnfResource.setVnfCustomizationId(UUID.randomUUID().toString()); + + Service service = new Service(); + VnfResourceCustomization vnfCustomization = new VnfResourceCustomization(); + vnfCustomization.setModelCustomizationUUID(UUID.randomUUID().toString()); + service.setVnfCustomizations(Arrays.asList(vnfCustomization)); + + when(catalogDbClient.getServiceByModelUUID(anyString())).thenReturn(service); + + BuildingBlockExecution execution = createExecution(sir, Arrays.asList(serviceResource, vnfResource)); + + Optional<String> message = validator.validate(execution); + + assertTrue(message.isPresent()); + assertTrue(message.get().startsWith("Existing vnfs in AAI are not supported by service model")); + } + + @Test + public void validateHappyCase() throws JsonProcessingException { + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + sir.setRequestDetails(new RequestDetails()); + sir.getRequestDetails().setModelInfo(new ModelInfo()); + sir.getRequestDetails().getModelInfo().setModelUuid(UUID.randomUUID().toString()); + String modelInvariantId = UUID.randomUUID().toString(); + sir.getRequestDetails().getModelInfo().setModelInvariantId(modelInvariantId); + + Resource serviceResource = new Resource(WorkflowType.SERVICE, "", false, null); + serviceResource.setModelInvariantId(modelInvariantId); + Resource vnfResource = new Resource(WorkflowType.VNF, "", false, serviceResource); + String vnfCustomiationId = UUID.randomUUID().toString(); + vnfResource.setVnfCustomizationId(vnfCustomiationId); + + Service service = new Service(); + VnfResourceCustomization vnfCustomization = new VnfResourceCustomization(); + vnfCustomization.setModelCustomizationUUID(vnfCustomiationId); + service.setVnfCustomizations(Arrays.asList(vnfCustomization)); + + when(catalogDbClient.getServiceByModelUUID(anyString())).thenReturn(service); + + BuildingBlockExecution execution = createExecution(sir, Arrays.asList(serviceResource, vnfResource)); + + Optional<String> message = validator.validate(execution); + + assertFalse(message.isPresent()); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroCreateMultipleSameModelVnfsAndVfModules.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroCreateMultipleSameModelVnfsAndVfModules.json new file mode 100644 index 0000000000..059754846a --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroCreateMultipleSameModelVnfsAndVfModules.json @@ -0,0 +1,187 @@ +{ + "requestDetails": { + "subscriberInfo": { + "globalSubscriberId": "test-customer" + }, + "requestInfo": { + "suppressRollback": false, + "instanceName": "test", + "productFamilyId": "6ea37d21-1a8d-4cd5-a727-e543191a5bb6", + "requestorId": "portal", + "source": "source" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "cloudid", + "tenantId": "tenantid", + "cloudOwner": "cloudowner" + }, + "requestParameters": { + "subscriptionServiceType": "ubuntu", + "userParams": [ + { + "Homing_Solution": "none" + }, + { + "service": { + "instanceParams": [], + "resources": { + "vnfs": [ + { + "modelInfo": { + "modelName": "UbuntuVF", + "modelVersionId": "744a1610-782e-47cf-bb45-d83319e33e17", + "modelInvariantUuid": "fc573bb4-d312-48ab-b81d-8b3313df4d07", + "modelVersion": "1.0", + "modelCustomizationId": "0d0ba1ee-6b7f-47fe-8266-2967993b2c08", + "modelInstanceName": "Ubuntu VF 0" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "cloudid", + "tenantId": "tenantid", + "cloudOwner": "cloudowner" + }, + "platform": { + "platformName": "platform" + }, + "lineOfBusiness": { + "lineOfBusinessName": "lob" + }, + "productFamilyId": "6ea37d21-1a8d-4cd5-a727-e543191a5bb6\n", + "instanceName": "vnf-instanceName-1", + "instanceParams": [ + { + "vnf-name": "vnf-vnf-name", + "vnf_name": "UbuntuVNFName" + } + ], + "vfModules": [ + { + "modelInfo": { + "modelName": "UbuntuVF..base..module-0", + "modelVersionId": "8fa495ac-d057-4060-b772-868d8e97766e", + "modelInvariantUuid": "71dcbf41-9838-4b3d-baa4-4024d22ef0cc", + "modelVersion": "1", + "modelCustomizationId": "3bd19000-6d21-49f1-9eb3-ea76a6eac5e0" + }, + "instanceName": "demo-network-1", + "instanceParams": [ + { + "name": "demo-network-1", + "cidr": "10.10.10.0/24" + } + ] + }, + { + "modelInfo": { + "modelName": "UbuntuVF..base..module-1", + "modelVersionId": "21954495-830f-48b7-b7b2-030d837789b3", + "modelInvariantUuid": "90355af6-55f3-460e-abe6-bec9a27a15e6", + "modelVersion": "1", + "modelCustomizationId": "83677d89-428a-407b-b4ec-738e68275d84" + }, + "instanceName": "demo-1", + "instanceParams": [ + { + "name": "demo-ubuntu-1", + "network_mgmt": "vlan101", + "network_name": "demo-network-1" + } + ] + } + ] + }, + { + "modelInfo": { + "modelName": "UbuntuVF", + "modelVersionId": "744a1610-782e-47cf-bb45-d83319e33e17", + "modelInvariantUuid": "fc573bb4-d312-48ab-b81d-8b3313df4d07", + "modelVersion": "1.0", + "modelCustomizationId": "0d0ba1ee-6b7f-47fe-8266-2967993b2c08", + "modelInstanceName": "Ubuntu VF 0" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "cloudid", + "tenantId": "tenantid", + "cloudOwner": "cloudowner" + }, + "platform": { + "platformName": "platform" + }, + "lineOfBusiness": { + "lineOfBusinessName": "lob" + }, + "productFamilyId": "6ea37d21-1a8d-4cd5-a727-e543191a5bb6\n", + "instanceName": "vnf-instanceName-2", + "instanceParams": [ + { + "vnf-name": "vnf-vnf-name", + "vnf_name": "UbuntuVNFName" + } + ], + "vfModules": [ + { + "modelInfo": { + "modelName": "UbuntuVF..base..module-1", + "modelVersionId": "21954495-830f-48b7-b7b2-030d837789b3", + "modelInvariantUuid": "90355af6-55f3-460e-abe6-bec9a27a15e6", + "modelVersion": "1", + "modelCustomizationId": "83677d89-428a-407b-b4ec-738e68275d84" + }, + "instanceName": "demo-2", + "instanceParams": [ + { + "name": "demo-ubuntu-2", + "network_mgmt": "vlan101", + "network_name": "demo-network-1" + } + ] + }, + { + "modelInfo": { + "modelName": "UbuntuVF..base..module-1", + "modelVersionId": "21954495-830f-48b7-b7b2-030d837789b3", + "modelInvariantUuid": "90355af6-55f3-460e-abe6-bec9a27a15e6", + "modelVersion": "1", + "modelCustomizationId": "83677d89-428a-407b-b4ec-738e68275d84" + }, + "instanceName": "demo-3", + "instanceParams": [ + { + "name": "demo-ubuntu-3", + "network_mgmt": "vlan101", + "network_name": "demo-network-1" + } + ] + } + ] + } + ] + }, + "modelInfo": { + "modelVersion": "1.0", + "modelVersionId": "f2444885-3c76-4ddc-8668-7741c0631495", + "modelInvariantId": "3bd19000-6d21-49f1-9eb3-ea76a6eac5e0", + "modelName": "UbuntuSVC", + "modelType": "service" + } + } + } + ], + "aLaCarte": false + }, + "project": { + "projectName": "Project-UbuntuDemo" + }, + "owningEntity": { + "owningEntityId": "33a8b609-1cfe-4d19-8dc2-5b95b921de1e", + "owningEntityName": "demo" + }, + "modelInfo": { + "modelVersion": "1.0", + "modelVersionId": "f2444885-3c76-4ddc-8668-7741c0631495", + "modelInvariantId": "3bd19000-6d21-49f1-9eb3-ea76a6eac5e0", + "modelName": "UbuntuSVC", + "modelType": "service" + } + } +}
\ No newline at end of file |