diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
28 files changed, 965 insertions, 345 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterUpgradeTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterUpgradeTasks.java new file mode 100644 index 0000000000..2eebde0687 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterUpgradeTasks.java @@ -0,0 +1,129 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * 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.adapter.cnf.tasks; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.adapter.cnf.CnfAdapterClient; +import org.onap.so.client.adapter.cnf.entities.UpgradeInstanceRequest; +import org.onap.so.client.adapter.cnf.entities.UpgradeInstanceResponse; +import org.onap.so.client.adapter.vnf.mapper.AttributeNameValue; +import org.onap.so.client.adapter.vnf.mapper.Attributes; +import org.onap.so.client.adapter.vnf.mapper.VnfAdapterVfModuleObjectMapper; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.openstack.utils.MsoMulticloudUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Component +public class CnfAdapterUpgradeTasks { + private static final Logger logger = LoggerFactory.getLogger(CnfAdapterUpgradeTasks.class); + + public static final String SDNCQUERY_RESPONSE = "SDNCQueryResponse_"; + + @Autowired + private ExtractPojosForBB extractPojosForBB; + @Autowired + private ExceptionBuilder exceptionUtil; + @Autowired + private CnfAdapterClient cnfAdapterClient; + @Autowired + private VnfAdapterVfModuleObjectMapper vfModuleMapper; + + private ObjectMapper mapper = new ObjectMapper(); + + /** + * This method is used for updating the request for an Instance in Multicloud K8s Plugin. + * + * @param execution + * @return + */ + public void upgradeInstance(BuildingBlockExecution execution) { + try { + GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); + ServiceInstance serviceInstance = + gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0); + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); + VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); + RequestContext requestContext = gBBInput.getRequestContext(); + CloudRegion cloudRegion = gBBInput.getCloudRegion(); + String sdncVfModuleQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + vfModule.getVfModuleId()); + String sdncVnfQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + genericVnf.getVnfId()); + Map<String, Object> paramsMap = vfModuleMapper.buildVfModuleParamsMap(requestContext, serviceInstance, + genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse); + Map<String, String> sdncDirectives = getSdncDirectives(paramsMap); + UpgradeInstanceRequest upgradeInstanceRequest = + upgradeInstanceRequest(vfModule, cloudRegion, sdncDirectives); + UpgradeInstanceResponse response = cnfAdapterClient.upgradeVfModule(upgradeInstanceRequest); + execution.setVariable("heatStackId", response.getId()); + } catch (Exception ex) { + logger.error("Exception occurred", ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + protected Map<String, String> getSdncDirectives(Map<String, Object> paramsMap) + throws JsonParseException, JsonMappingException, IOException { + Map<String, String> sdncDirectivesMap = new HashMap<>(); + String sdncDirectivesString = (String) paramsMap.get(MsoMulticloudUtils.SDNC_DIRECTIVES); + Attributes sdncDirectives = mapper.readValue(sdncDirectivesString, Attributes.class); + for (AttributeNameValue nameVal : sdncDirectives.getAttributes()) { + sdncDirectivesMap.put(nameVal.getAttributeName(), (String) nameVal.getAttributeValue()); + } + return sdncDirectivesMap; + } + + protected UpgradeInstanceRequest upgradeInstanceRequest(VfModule vfModule, CloudRegion cloudRegion, + Map<String, String> sdncDirectives) { + + UpgradeInstanceRequest request = new UpgradeInstanceRequest(); + + request.setModelInvariantId(vfModule.getModelInfoVfModule().getModelInvariantUUID()); + request.setModelCustomizationId(vfModule.getModelInfoVfModule().getModelCustomizationUUID()); + request.setCloudRegion(cloudRegion.getLcpCloudRegionId()); + request.setVfModuleUUID(vfModule.getVfModuleId()); + request.setProfileName(sdncDirectives.get("k8s-rb-profile-name")); + request.setLabels(sdncDirectives); + if (sdncDirectives.containsKey("k8s-rb-instance-status-check")) + request.setStatusCheck(sdncDirectives.get("k8s-rb-instance-status-check").equalsIgnoreCase("true")); + request.setOverrideValues(sdncDirectives); + return request; + } + +} 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 index b0182c1b00..d7f2b85ea0 100755 --- 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 @@ -55,6 +55,7 @@ public class ExecuteBuildingBlockBuilder { private static final String VFMODULE = "VfModule"; private static final String NETWORK = "Network"; private static final String HEALTH_CHECK = "HealthCheckBB"; + private static final String UPGRADE_CNF = "UpgradeVfModuleBB"; protected List<ExecuteBuildingBlock> buildExecuteBuildingBlockList(List<OrchestrationFlow> orchFlows, List<Resource> originalResourceList, String requestId, String apiVersion, String resourceId, @@ -133,6 +134,10 @@ public class ExecuteBuildingBlockBuilder { && (VNF).equalsIgnoreCase(orchFlow.getBpmnScope())) { addBuildingBlockToExecuteBBList(flowsToExecute, resource, WorkflowType.VNF, orchFlow, requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false, false); + } else if ((orchFlow.getFlowName().equalsIgnoreCase(UPGRADE_CNF)) + && (VNF).equalsIgnoreCase(orchFlow.getBpmnScope())) { + addBuildingBlockToExecuteBBList(flowsToExecute, resource, 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, resource, WorkflowType.PNF, orchFlow, requestId, apiVersion, 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 0214a3f998..3617512d7b 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 @@ -40,6 +40,8 @@ public class Resource implements Serializable { private String cvnfModuleCustomizationId; private String instanceName; private String modelInvariantId; + private String modelVersionId; + private String modelCustomizationId; private int processingPriority; private Resource parent; private List<Resource> children; @@ -140,6 +142,21 @@ public class Resource implements Serializable { this.modelInvariantId = modelInvariantId; } + public String getModelVersionId() { + return modelVersionId; + } + + public void setModelVersionId(String modelVersionId) { + this.modelVersionId = modelVersionId; + } + + public String getModelCustomizationId() { + return modelCustomizationId; + } + + public void setModelCustomizationId(String modelCustomizationId) { + this.modelCustomizationId = modelCustomizationId; + } 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 31a7caacda..35e11963a3 100755 --- 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 @@ -42,6 +42,7 @@ import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConst import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.UPDATE_INSTANCE; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.HEALTH_CHECK; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.UPGRADE_CNF; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -306,6 +307,9 @@ public class WorkflowAction { } else if (resourceType == WorkflowType.VNF && HEALTH_CHECK.equalsIgnoreCase(requestAction)) { vnfEBBLoader.customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), workflowResourceIds.getVnfId(), aaiResourceIds); + } else if (resourceType == WorkflowType.VNF && UPGRADE_CNF.equalsIgnoreCase(requestAction)) { + vnfEBBLoader.customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), + workflowResourceIds.getVnfId(), aaiResourceIds); } else { buildAndThrowException(execution, "Current Macro Request is not supported"); } 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 dda217fc79..22d78bb672 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 @@ -23,6 +23,7 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; @@ -49,6 +50,7 @@ import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.catalog.beans.BuildingBlockRollback; import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.InfraActiveRequests; @@ -86,6 +88,9 @@ public class WorkflowActionBBTasks { private static final String VFMODULE = "VfModule"; private static final String CONFIGURATION_PATTERN = "(Ad|De)(.*)FabricConfiguration(.*)"; protected String maxRetries = "mso.rainyDay.maxRetries"; + private static final String ROLLBACK_TO_ASSIGNED = "RollbackToAssigned"; + private static final String UNASSIGN = "Unassign"; + private static final String DELETE = "Delete"; private static final Logger logger = LoggerFactory.getLogger(WorkflowActionBBTasks.class); @Autowired @@ -316,94 +321,98 @@ public class WorkflowActionBBTasks { public void rollbackExecutionPath(DelegateExecution execution) { final String action = (String) execution.getVariable(BBConstants.G_ACTION); final String resourceName = (String) execution.getVariable("resourceName"); - if (!(boolean) execution.getVariable("isRollback")) { - List<ExecuteBuildingBlock> flowsToExecute = - (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); - - List<ExecuteBuildingBlock> flowsToExecuteChangeBBs = flowsToExecute.stream() - .filter(buildingBlock -> buildingBlock.getBuildingBlock().getBpmnFlowName().startsWith("Change")) - .collect(Collectors.toList()); - - List<ExecuteBuildingBlock> rollbackFlows = new ArrayList<>(); - int currentSequence = (int) execution.getVariable(BBConstants.G_CURRENT_SEQUENCE); - int listSize = flowsToExecute.size(); + if ((boolean) execution.getVariable("isRollback")) { + workflowAction.buildAndThrowException(execution, + "Rollback has already been called. Cannot rollback a request that is currently in the rollback state."); + } + List<ExecuteBuildingBlock> flowsToExecute = + (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); - for (int i = listSize - 1; i >= 0; i--) { - if (i > currentSequence - 1) { - flowsToExecute.remove(i); - } else { - String flowName = flowsToExecute.get(i).getBuildingBlock().getBpmnFlowName(); - if (flowName.startsWith("Assign")) { - flowName = flowName.replaceFirst("Assign", "Unassign"); - } else if (flowName.startsWith("Create")) { - flowName = flowName.replaceFirst("Create", "Delete"); - } else if (flowName.startsWith("Activate")) { - flowName = flowName.replaceFirst("Activate", "Deactivate"); - } else if (flowName.startsWith("Add")) { - flowName = flowName.replaceFirst("Add", "Delete"); - } else if (flowName.startsWith("VNF")) { - if (flowName.startsWith("VNFSet")) { - flowName = flowName.replaceFirst("VNFSet", "VNFUnset"); - } else if (flowName.startsWith("VNFLock")) { - flowName = flowName.replaceFirst("VNFLock", "VNFUnlock"); - } else if (flowName.startsWith("VNFStop")) { - flowName = flowName.replaceFirst("VNFStop", "VNFStart"); - } else if (flowName.startsWith("VNFQuiesce")) { - flowName = flowName.replaceFirst("VNFQuiesce", "VNFResume"); - } else { - continue; - } - } else { - continue; + List<ExecuteBuildingBlock> flowsToExecuteChangeBBs = flowsToExecute.stream() + .filter(buildingBlock -> buildingBlock.getBuildingBlock().getBpmnFlowName().startsWith("Change")) + .collect(Collectors.toList()); + List<ExecuteBuildingBlock> rollbackFlows = new ArrayList<>(); + int currentSequence = (int) execution.getVariable(BBConstants.G_CURRENT_SEQUENCE); + int listSize = flowsToExecute.size(); + List<BuildingBlockRollback> bbRollbackList = catalogDbClient.getBuildingBlockRollbackEntries(); + + for (int i = listSize - 1; i >= 0; i--) { + if (i > currentSequence - 1) { + flowsToExecute.remove(i); + } else { + // filter bbRollbackList for bbrollback, and check if action exists, then filter by action + BuildingBlock bb = flowsToExecute.get(i).getBuildingBlock(); + String flowName = bb.getBpmnFlowName(); + String scope = Objects.toString(bb.getBpmnScope(), ""); + String bbAction = Objects.toString(bb.getBpmnAction(), ""); + ExecuteBuildingBlock currentBB = (ExecuteBuildingBlock) execution.getVariable("buildingBlock"); + + List<BuildingBlockRollback> filteredList = bbRollbackList.stream() + .filter(k -> k.getBuildingBlockName().equals((flowName))).collect(Collectors.toList()); + Optional<BuildingBlockRollback> matchedBBRollback = + "".equals(bbAction) ? filteredList.stream().findFirst() + : filteredList.stream().filter(k -> bbAction.equals(k.getAction())).findFirst(); + if (matchedBBRollback.isPresent()) { + final BuildingBlockRollback buildingBlockRollbackItem = matchedBBRollback.get(); + String rollbackFlow = buildingBlockRollbackItem.getRollbackBuildingBlockName(); + flowsToExecute.get(i).getBuildingBlock().setBpmnFlowName(rollbackFlow); + // if we have an action, search the filtered list for the bbrollback that matches the given action. + if (null != buildingBlockRollbackItem.getRollbackAction()) { + logger.info("Setting rollback_action {} for BB: {} action: {}", + buildingBlockRollbackItem.getRollbackAction(), + buildingBlockRollbackItem.getBuildingBlockName(), + buildingBlockRollbackItem.getAction()); + flowsToExecute.get(i).getBuildingBlock() + .setBpmnAction(buildingBlockRollbackItem.getRollbackAction()); } - flowsToExecute.get(i).getBuildingBlock().setBpmnFlowName(flowName); rollbackFlows.add(flowsToExecute.get(i)); } } + } - String handlingCode = (String) execution.getVariable(HANDLINGCODE); - List<ExecuteBuildingBlock> rollbackFlowsFiltered = new ArrayList<>(rollbackFlows); - if ("RollbackToAssigned".equals(handlingCode) || ROLLBACKTOCREATED.equals(handlingCode) - || ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)) { - for (ExecuteBuildingBlock rollbackFlow : rollbackFlows) { - if (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("Unassign") - && !rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("FabricConfiguration")) { - rollbackFlowsFiltered.remove(rollbackFlow); - } else if (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("Delete") - && ((!rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("FabricConfiguration") - && (ROLLBACKTOCREATED.equals(handlingCode) - || ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode))) - || (rollbackFlow.getBuildingBlock().getBpmnFlowName() - .contains("FabricConfiguration") - && ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)))) { - rollbackFlowsFiltered.remove(rollbackFlow); - } + String handlingCode = (String) execution.getVariable(HANDLINGCODE); + List<ExecuteBuildingBlock> rollbackFlowsFiltered = new ArrayList<>(rollbackFlows); + if (ROLLBACK_TO_ASSIGNED.equals(handlingCode) || ROLLBACKTOCREATED.equals(handlingCode) + || ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)) { + for (ExecuteBuildingBlock rollbackFlow : rollbackFlows) { + if (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains(UNASSIGN) + && !rollbackFlow.getBuildingBlock().getBpmnFlowName().contains(FABRIC_CONFIGURATION)) { + rollbackFlowsFiltered.remove(rollbackFlow); + } else if (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains(DELETE) + && ((!rollbackFlow.getBuildingBlock().getBpmnFlowName().contains(FABRIC_CONFIGURATION) + && (ROLLBACKTOCREATED.equals(handlingCode) + || ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode))) + || (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains(FABRIC_CONFIGURATION) + && ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)))) { + rollbackFlowsFiltered.remove(rollbackFlow); } } + } - List<ExecuteBuildingBlock> rollbackFlowsFilteredNonChangeBBs = new ArrayList<>(); - if (action.equals(REPLACEINSTANCE) && resourceName.equals(VFMODULE)) { - for (ExecuteBuildingBlock executeBuildingBlock : rollbackFlowsFiltered) { - if (!executeBuildingBlock.getBuildingBlock().getBpmnFlowName().startsWith("Change")) { - rollbackFlowsFilteredNonChangeBBs.add(executeBuildingBlock); - } + List<ExecuteBuildingBlock> rollbackFlowsFilteredNonChangeBBs = new ArrayList<>(); + if (action.equals(REPLACEINSTANCE) && resourceName.equals(VFMODULE)) { + for (ExecuteBuildingBlock executeBuildingBlock : rollbackFlowsFiltered) { + if (!executeBuildingBlock.getBuildingBlock().getBpmnFlowName().startsWith("Change")) { + rollbackFlowsFilteredNonChangeBBs.add(executeBuildingBlock); } - rollbackFlowsFiltered.clear(); - rollbackFlowsFiltered.addAll(flowsToExecuteChangeBBs); - rollbackFlowsFiltered.addAll(rollbackFlowsFilteredNonChangeBBs); } - - workflowActionBBFailure.updateRequestErrorStatusMessage(execution); - execution.setVariable("isRollbackNeeded", !rollbackFlows.isEmpty()); - execution.setVariable("flowsToExecute", rollbackFlowsFiltered); - execution.setVariable(HANDLINGCODE, "PreformingRollback"); - execution.setVariable("isRollback", true); - execution.setVariable(BBConstants.G_CURRENT_SEQUENCE, 0); - execution.setVariable(RETRY_COUNT, 0); - } else { - workflowAction.buildAndThrowException(execution, - "Rollback has already been called. Cannot rollback a request that is currently in the rollback state."); + rollbackFlowsFiltered.clear(); + rollbackFlowsFiltered.addAll(flowsToExecuteChangeBBs); + rollbackFlowsFiltered.addAll(rollbackFlowsFilteredNonChangeBBs); } + + logger.info("List of BuildingBlocks to execute for rollback"); + rollbackFlowsFiltered.forEach(item -> { + logger.info(item.getBuildingBlock().getBpmnFlowName()); + }); + + workflowActionBBFailure.updateRequestErrorStatusMessage(execution); + execution.setVariable("isRollbackNeeded", !rollbackFlows.isEmpty()); + execution.setVariable("flowsToExecute", rollbackFlowsFiltered); + execution.setVariable(HANDLINGCODE, "PreformingRollback"); + execution.setVariable("isRollback", true); + execution.setVariable(BBConstants.G_CURRENT_SEQUENCE, 0); + execution.setVariable(RETRY_COUNT, 0); } protected void updateInstanceId(DelegateExecution execution) { 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 7bbc9f3739..7ffd066de5 100755 --- 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 @@ -53,5 +53,6 @@ public final class WorkflowActionConstants { public static final String VOLUMEGROUP = "VolumeGroup"; public static final String HEALTH_CHECK = "healthCheck"; public static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage"; + public static final String UPGRADE_CNF = "upgradeCnf"; } 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 f16365b742..9d76707e5a 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 @@ -42,6 +42,8 @@ import org.onap.so.bpmn.infrastructure.workflow.tasks.VrfBondingServiceException import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoPnf; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; import org.onap.so.client.exception.ExceptionBuilder; @@ -207,6 +209,7 @@ public class ServiceEBBLoader { var serviceResource = new Resource(WorkflowType.SERVICE, serviceInstanceMSO.getServiceInstanceId(), false, null); serviceResource.setModelInvariantId(serviceInstanceAAI.getModelInvariantId()); + serviceResource.setModelVersionId(serviceInstanceAAI.getModelVersionId()); resourceList.add(serviceResource); traverseServiceInstanceChildService(resourceList, serviceResource, serviceInstanceAAI); traverseServiceInstanceMSOVnfs(resourceList, serviceResource, aaiResourceIds, serviceInstanceMSO); @@ -215,8 +218,15 @@ public class ServiceEBBLoader { for (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network : serviceInstanceMSO .getNetworks()) { aaiResourceIds.add(new Pair<>(WorkflowType.NETWORK, network.getNetworkId())); - resourceList - .add(new Resource(WorkflowType.NETWORK, network.getNetworkId(), false, serviceResource)); + Resource networkResource = + new Resource(WorkflowType.NETWORK, network.getNetworkId(), false, serviceResource); + ModelInfoNetwork modelInfoNetwork = network.getModelInfoNetwork(); + if (modelInfoNetwork != null) { + networkResource.setModelCustomizationId(modelInfoNetwork.getModelCustomizationUUID()); + networkResource.setModelVersionId(modelInfoNetwork.getModelUUID()); + networkResource.setModelCustomizationId(modelInfoNetwork.getModelCustomizationUUID()); + } + resourceList.add(networkResource); } } if (serviceInstanceMSO.getCollection() != null) { @@ -261,6 +271,8 @@ public class ServiceEBBLoader { GenericVnf genericVnf = bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId()); Resource vnfResource = new Resource(WorkflowType.VNF, vnf.getVnfId(), false, serviceResource); vnfResource.setVnfCustomizationId(genericVnf.getModelCustomizationId()); + vnfResource.setModelCustomizationId(genericVnf.getModelCustomizationId()); + vnfResource.setModelVersionId(genericVnf.getModelVersionId()); resourceList.add(vnfResource); traverseVnfModules(resourceList, vnfResource, aaiResourceIds, vnf); if (vnf.getVolumeGroups() != null) { @@ -281,7 +293,13 @@ public class ServiceEBBLoader { } for (org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf pnf : serviceInstanceMSO.getPnfs()) { aaiResourceIds.add(new Pair<>(WorkflowType.PNF, pnf.getPnfId())); - resourceList.add(new Resource(WorkflowType.PNF, pnf.getPnfId(), false, serviceResource)); + Resource resource = new Resource(WorkflowType.PNF, pnf.getPnfId(), false, serviceResource); + ModelInfoPnf modelInfo = pnf.getModelInfoPnf(); + if (modelInfo != null) { + resource.setModelVersionId(modelInfo.getModelUuid()); + resource.setModelCustomizationId(modelInfo.getModelCustomizationUuid()); + } + resourceList.add(resource); } } @@ -494,6 +512,10 @@ public class ServiceEBBLoader { for (VfModule vfModule : vnf.getVfModules()) { aaiResourceIds.add(new Pair<>(WorkflowType.VFMODULE, vfModule.getVfModuleId())); Resource resource = new Resource(WorkflowType.VFMODULE, vfModule.getVfModuleId(), false, vnfResource); + org.onap.aai.domain.yang.VfModule aaiVfModule = + bbInputSetupUtils.getAAIVfModule(vnf.getVnfId(), vfModule.getVfModuleId()); + resource.setModelCustomizationId(aaiVfModule.getModelCustomizationId()); + resource.setModelInvariantId(aaiVfModule.getModelInvariantId()); resource.setBaseVfModule(vfModule.getModelInfoVfModule().getIsBaseBoolean()); resourceList.add(resource); } 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 b8b9c458fa..b56bd905a6 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 @@ -38,6 +38,7 @@ import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; import org.onap.so.db.catalog.beans.CvnfcCustomization; import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.Networks; import org.onap.so.serviceinstancebeans.Pnfs; import org.onap.so.serviceinstancebeans.Service; @@ -93,6 +94,11 @@ public class UserParamsServiceTraversal { List<Resource> resourceList = new ArrayList<>(); Resource serviceResource = new Resource(WorkflowType.SERVICE, validate.getModelInfo().getModelVersionId(), false, null); + ModelInfo modelInfo = validate.getModelInfo(); + if (modelInfo != null) { + serviceResource.setModelVersionId(modelInfo.getModelVersionId()); + serviceResource.setModelInvariantId(modelInfo.getModelInvariantUuid()); + } resourceList.add(serviceResource); if (validate.getResources().getServices() != null) { setResourceListForChildServices(execution, resourceList, serviceResource, validate); @@ -129,6 +135,11 @@ public class UserParamsServiceTraversal { serviceResource); vnfResource.setProcessingPriority(vnf.getProcessingPriority()); vnfResource.setInstanceName(vnf.getInstanceName()); + ModelInfo modelInfo = vnf.getModelInfo(); + if (modelInfo != null) { + vnfResource.setModelCustomizationId(modelInfo.getModelCustomizationUuid()); + vnfResource.setModelVersionId(modelInfo.getModelVersionId()); + } resourceList.add(vnfResource); setResourceListForVfModules(execution, resourceList, vnfResource, validate, vnf); } @@ -174,6 +185,11 @@ public class UserParamsServiceTraversal { foundVfModuleOrVG = true; Resource resource = setVfModuleWorkFlowTypeToResourceList(resourceList, vnfResource, vfModuleCustomization, vfModule); + if (vnf.getModelInfo() != null) { + resource.setModelVersionId(vnf.getModelInfo().getModelVersionId()); + } + resource.setVfModuleCustomizationId(vfModuleCustomization.getModelCustomizationUUID()); + resource.setModelCustomizationId(vfModuleCustomization.getModelCustomizationUUID()); setConfigurationWorkFlowTypeToResourceList(resourceList, vnfResource, validate, vnf, vfModule, resource); } } @@ -225,6 +241,11 @@ public class UserParamsServiceTraversal { for (Pnfs pnf : validate.getResources().getPnfs()) { Resource pnfResource = new Resource(WorkflowType.PNF, pnf.getModelInfo().getModelCustomizationId(), false, serviceResource); + ModelInfo modelInfo = pnf.getModelInfo(); + if (modelInfo != null) { + pnfResource.setModelCustomizationId(modelInfo.getModelCustomizationUuid()); + pnfResource.setModelVersionId(modelInfo.getModelVersionId()); + } pnfResource.setProcessingPriority(pnf.getProcessingPriority()); resourceList.add(pnfResource); } @@ -236,6 +257,11 @@ public class UserParamsServiceTraversal { Resource networkResource = new Resource(WorkflowType.NETWORK, network.getModelInfo().getModelCustomizationId(), false, serviceResource); networkResource.setProcessingPriority(network.getProcessingPriority()); + ModelInfo modelInfo = network.getModelInfo(); + if (modelInfo != null) { + networkResource.setModelCustomizationId(modelInfo.getModelCustomizationUuid()); + networkResource.setModelVersionId(modelInfo.getModelVersionId()); + } resourceList.add(networkResource); } if (requestAction.equals(CREATE_INSTANCE)) { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java index b950eb41be..3778f64612 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java @@ -40,7 +40,6 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; import org.onap.so.client.exception.ExceptionBuilder; @@ -117,6 +116,9 @@ public class VnfEBBLoader { if (vnf.getVnfId().equals(vnfId)) { aaiResourceIds.add(new Pair<>(WorkflowType.VNF, vnf.getVnfId())); Resource vnfResource = new Resource(WorkflowType.VNF, vnf.getVnfId(), false, serviceResource); + org.onap.aai.domain.yang.GenericVnf aaiGenericVnf = bbInputSetupUtils.getAAIGenericVnf(vnfId); + vnfResource.setModelCustomizationId(aaiGenericVnf.getModelCustomizationId()); + vnfResource.setModelVersionId(aaiGenericVnf.getModelVersionId()); resourceList.add(vnfResource); processVfModules(vnf, aaiResourceIds, resourceList, vnfResource, execution); processVolumeGroups(vnf, aaiResourceIds, resourceList, vnfResource); @@ -131,8 +133,11 @@ public class VnfEBBLoader { for (GenericVnf vnf : serviceInstanceMSO.getVnfs()) { if (vnf.getVnfId().equals(vnfId)) { aaiResourceIds.add(new Pair<>(WorkflowType.VNF, vnf.getVnfId())); - Resource vnfResource = new Resource(WorkflowType.VNF, - bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId(), false, serviceResource); + org.onap.aai.domain.yang.GenericVnf aaiGenericVnf = bbInputSetupUtils.getAAIGenericVnf(vnfId); + Resource vnfResource = + new Resource(WorkflowType.VNF, aaiGenericVnf.getModelCustomizationId(), false, serviceResource); + vnfResource.setModelCustomizationId(aaiGenericVnf.getModelCustomizationId()); + vnfResource.setModelVersionId(aaiGenericVnf.getModelVersionId()); resourceList.add(vnfResource); processVfModules(vnf, aaiResourceIds, resourceList, vnfResource, execution); processVolumeGroups(vnf, aaiResourceIds, resourceList, vnfResource); @@ -141,10 +146,10 @@ public class VnfEBBLoader { } } - private void findConfigurationsInsideVfModule(DelegateExecution execution, String vnfId, String vfModuleId, - List<Resource> resourceList, Resource vfModuleResource, List<Pair<WorkflowType, String>> aaiResourceIds) { + private void findConfigurationsInsideVfModule(DelegateExecution execution, + org.onap.aai.domain.yang.VfModule aaiVfModule, List<Resource> resourceList, Resource vfModuleResource, + List<Pair<WorkflowType, String>> aaiResourceIds) { try { - org.onap.aai.domain.yang.VfModule aaiVfModule = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId); AAIResultWrapper vfModuleWrapper = new AAIResultWrapper( new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiVfModule)); Optional<Relationships> relationshipsOp; @@ -166,11 +171,14 @@ public class VnfEBBLoader { aaiResourceIds.add(new Pair<>(WorkflowType.VFMODULE, vfModule.getVfModuleId())); Resource vfModuleResource = new Resource(WorkflowType.VFMODULE, vfModule.getVfModuleId(), false, vnfResource); - Optional.ofNullable(vfModule.getModelInfoVfModule()).map(ModelInfoVfModule::getIsBaseBoolean) - .ifPresent(vfModuleResource::setBaseVfModule); + org.onap.aai.domain.yang.VfModule aaiVfModule = + bbInputSetupUtils.getAAIVfModule(vnf.getVnfId(), vfModule.getVfModuleId()); + vfModuleResource.setModelInvariantId(aaiVfModule.getModelInvariantId()); + vfModuleResource.setModelCustomizationId(aaiVfModule.getModelCustomizationId()); + vfModuleResource.setBaseVfModule(aaiVfModule.isIsBaseVfModule()); resourceList.add(vfModuleResource); - findConfigurationsInsideVfModule(execution, vnf.getVnfId(), vfModule.getVfModuleId(), resourceList, - vfModuleResource, aaiResourceIds); + findConfigurationsInsideVfModule(execution, aaiVfModule, resourceList, vfModuleResource, + aaiResourceIds); } } } 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 ff6c113af3..dc77ea1f0c 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 @@ -24,12 +24,10 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; -import org.apache.logging.log4j.util.Strings; 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.infrastructure.workflow.tasks.Resource; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.db.catalog.beans.PnfResourceCustomization; import org.onap.so.db.catalog.beans.Service; @@ -40,7 +38,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; @Component public class SkipCDSBuildingBlockListener implements PreFlowManipulator { @@ -76,43 +73,37 @@ public class SkipCDSBuildingBlockListener implements PreFlowManipulator { @Override public void run(List<ExecuteBuildingBlock> flowsToExecute, ExecuteBuildingBlock currentBB, BuildingBlockExecution execution) { - String customizationUUID = currentBB.getBuildingBlock().getKey(); + String resourceKey = currentBB.getBuildingBlock().getKey(); + List<Resource> resources = execution.getVariable("resources"); + Resource resource = resources.stream().filter(r -> resourceKey.equals(r.getResourceId())).findFirst() + .orElseThrow(() -> new IllegalArgumentException("Resource not found for key:" + resourceKey)); - 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( - currentBB.getRequestDetails().getModelInfo().getModelUuid()); - if (!CollectionUtils.isEmpty(vnfResourceCustomizations)) { - VnfResourceCustomization vrc = catalogDbClient.findVnfResourceCustomizationInList(customizationUUID, - vnfResourceCustomizations); - if (null != vrc) { - logger.debug("getSkipPostInstConf value: " + vrc.getSkipPostInstConf().booleanValue()); - boolean skipConfigVNF = vrc.getSkipPostInstConf().booleanValue(); - currentSequenceSkipCheck(execution, skipConfigVNF); - } + String scope = currentBB.getBuildingBlock().getBpmnScope(); + if ("SERVICE".equalsIgnoreCase(scope)) { + Service service = catalogDbClient.getServiceByID(resource.getModelVersionId()); + currentSequenceSkipCheck(execution, service.getSkipPostInstConf()); + } else if ("VNF".equalsIgnoreCase(scope) && containsIgnoreCaseAction(currentBB, vnfActions)) { + VnfResourceCustomization vrc = catalogDbClient + .getVnfResourceCustomizationByModelCustomizationUUID(resource.getModelCustomizationId()); + if (vrc != null) { + logger.debug("getSkipPostInstConf value: " + vrc.getSkipPostInstConf()); + boolean skipConfigVNF = vrc.getSkipPostInstConf(); + currentSequenceSkipCheck(execution, skipConfigVNF); } } else if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("VFModule") && containsIgnoreCaseAction(currentBB, vFModuleAction)) { - - VfModuleCustomization vfc = - catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(customizationUUID); - + VfModuleCustomization vfc = catalogDbClient + .getVfModuleCustomizationByModelCuztomizationUUID(resource.getModelCustomizationId()); if (null != vfc) { logger.debug("getSkipPostInstConf value: " + vfc.getSkipPostInstConf().booleanValue()); boolean skipVfModule = vfc.getSkipPostInstConf(); currentSequenceSkipCheck(execution, skipVfModule); } - } else if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("PNF") && containsIgnoreCaseAction(currentBB, pnfActions)) { - PnfResourceCustomization pnfResourceCustomization = - catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(customizationUUID); + PnfResourceCustomization pnfResourceCustomization = catalogDbClient + .getPnfResourceCustomizationByModelCustomizationUUID(resource.getModelCustomizationId()); if (null != pnfResourceCustomization) { logger.debug("getSkipPostInstConf value: " + pnfResourceCustomization.getSkipPostInstConf()); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java index da36a6f040..e8122e7784 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java @@ -27,6 +27,8 @@ import javax.ws.rs.core.UriBuilder; import org.apache.http.HttpStatus; import org.onap.so.client.adapter.cnf.entities.InstanceRequest; import org.onap.so.client.adapter.cnf.entities.InstanceResponse; +import org.onap.so.client.adapter.cnf.entities.UpgradeInstanceResponse; +import org.onap.so.client.adapter.cnf.entities.UpgradeInstanceRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -115,6 +117,25 @@ public class CnfAdapterClient { } } + @Retryable(value = {HttpServerErrorException.class}, maxAttempts = 3, backoff = @Backoff(delay = 3000)) + public UpgradeInstanceResponse upgradeVfModule(UpgradeInstanceRequest request) throws CnfAdapterClientException { + try { + String uri = "http://so-cnf-adapter:8090"; + String endpoint = UriBuilder.fromUri(uri).path("/api/cnf-adapter/v1/instance/{instanceID}/upgrade").build() + .toString(); + HttpEntity<?> entity = getHttpEntity(request); + ResponseEntity<UpgradeInstanceResponse> result = + restTemplate.exchange(endpoint, HttpMethod.POST, entity, UpgradeInstanceResponse.class); + return result.getBody(); + } catch (HttpClientErrorException e) { + logger.error("Error Calling CNF Adapter, e"); + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException(e.getResponseBodyAsString()); + } + throw e; + } + } + protected HttpHeaders getHttpHeaders() { HttpHeaders headers = new HttpHeaders(); List<MediaType> acceptableMediaTypes = new ArrayList<>(); @@ -135,4 +156,8 @@ public class CnfAdapterClient { return new HttpEntity<>(request, headers); } + protected HttpEntity<?> getHttpEntity(UpgradeInstanceRequest request) { + HttpHeaders headers = getHttpHeaders(); + return new HttpEntity<>(request, headers); + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/UpgradeInstanceRequest.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/UpgradeInstanceRequest.java new file mode 100644 index 0000000000..ef516d4967 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/UpgradeInstanceRequest.java @@ -0,0 +1,100 @@ + +package org.onap.so.client.adapter.cnf.entities; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UpgradeInstanceRequest { + + @JsonProperty("modelInvariantId") + private String modelInvariantId; + + @JsonProperty("modelCustomizationId") + private String modelCustomizationId; + + @JsonProperty("k8sRBProfileName") + private String profileName; + + @JsonProperty("k8sRBInstanceStatusCheck") + private Boolean statusCheck = false; + + @JsonProperty("cloudRegionId") + private String cloudRegion; + + @JsonProperty("vfModuleUUID") + private String vfModuleUUID; + + @JsonProperty("labels") + private Map<String, String> labels; + + @JsonProperty("override-values") + private Map<String, String> overrideValues; + + public String getModelInvariantId() { + return modelInvariantId; + } + + public void setModelInvariantId(String modelInvariantId) { + this.modelInvariantId = modelInvariantId; + } + + public String getModelCustomizationId() { + return modelCustomizationId; + } + + public void setModelCustomizationId(String modelCustomizationId) { + this.modelCustomizationId = modelCustomizationId; + } + + public String getProfileName() { + return profileName; + } + + public void setProfileName(String profileName) { + this.profileName = profileName; + } + + public Boolean getStatusCheck() { + return statusCheck; + } + + public void setStatusCheck(Boolean statusCheck) { + this.statusCheck = statusCheck; + } + + public String getCloudRegion() { + return cloudRegion; + } + + public void setCloudRegion(String cloudRegion) { + this.cloudRegion = cloudRegion; + } + + public Map<String, String> getLabels() { + return labels; + } + + public void setLabels(Map<String, String> labels) { + this.labels = labels; + } + + public String getVfModuleUUID() { + return vfModuleUUID; + } + + public void setVfModuleUUID(String vfModuleUUID) { + this.vfModuleUUID = vfModuleUUID; + } + + public Map<String, String> getOverrideValues() { + return overrideValues; + } + + public void setOverrideValues(Map<String, String> overrideValues) { + this.overrideValues = overrideValues; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/UpgradeInstanceResponse.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/UpgradeInstanceResponse.java new file mode 100644 index 0000000000..6498279870 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/UpgradeInstanceResponse.java @@ -0,0 +1,78 @@ + +package org.onap.so.client.adapter.cnf.entities; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"id", "request", "namespace", "release-name", "resources"}) +public class UpgradeInstanceResponse { + + @JsonProperty("id") + private String id; + + @JsonProperty("request") + private InstanceRequest request; + + @JsonProperty("namespace") + private String namespace; + + @JsonProperty("release-name") + private String releaseName; + + @JsonProperty("resources") + private List<Resource> resources = null; + + @JsonProperty("id") + public String getId() { + return id; + } + + @JsonProperty("id") + public void setId(String id) { + this.id = id; + } + + @JsonProperty("request") + public InstanceRequest getRequest() { + return request; + } + + @JsonProperty("request") + public void setRequest(InstanceRequest request) { + this.request = request; + } + + @JsonProperty("namespace") + public String getNamespace() { + return namespace; + } + + @JsonProperty("namespace") + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + @JsonProperty("resources") + public List<Resource> getResources() { + return resources; + } + + @JsonProperty("resources") + public void setResources(List<Resource> resources) { + this.resources = resources; + } + + @JsonProperty("release-name") + public String getReleaseName() { + return releaseName; + } + + @JsonProperty("release-name") + public void setReleaseName(String releaseName) { + this.releaseName = releaseName; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java index 28d2abc792..7d4267efbb 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java @@ -25,13 +25,16 @@ package org.onap.so.bpmn.infrastructure.aai.tasks; import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.adapters.nwrest.CreateNetworkResponse; import org.onap.so.adapters.nwrest.UpdateNetworkResponse; -import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; @@ -42,7 +45,17 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.orchestration.AAICollectionResources; +import org.onap.so.client.orchestration.AAIConfigurationResources; +import org.onap.so.client.orchestration.AAINetworkResources; +import org.onap.so.client.orchestration.AAIPnfResources; +import org.onap.so.client.orchestration.AAIServiceInstanceResources; +import org.onap.so.client.orchestration.AAIVfModuleResources; +import org.onap.so.client.orchestration.AAIVnfResources; +import org.onap.so.client.orchestration.AAIVolumeGroupResources; import org.onap.so.db.catalog.beans.OrchestrationStatus; import java.util.HashMap; import static org.junit.Assert.assertEquals; @@ -57,8 +70,29 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class AAIUpdateTasksTest extends BaseTaskTest { - +@RunWith(MockitoJUnitRunner.Silent.class) +public class AAIUpdateTasksTest extends TestDataSetup { + + @Mock + protected ExtractPojosForBB extractPojosForBB; + @Mock + protected ExceptionBuilder exceptionUtil; + @Mock + protected AAIServiceInstanceResources aaiServiceInstanceResources; + @Mock + protected AAIPnfResources aaiPnfResources; + @Mock + protected AAIVnfResources aaiVnfResources; + @Mock + protected AAIVfModuleResources aaiVfModuleResources; + @Mock + protected AAIVolumeGroupResources aaiVolumeGroupResources; + @Mock + protected AAINetworkResources aaiNetworkResources; + @Mock + protected AAICollectionResources aaiCollectionResources; + @Mock + protected AAIConfigurationResources aaiConfigurationResources; @InjectMocks private AAIUpdateTasks aaiUpdateTasks = new AAIUpdateTasks(); @@ -99,7 +133,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusAssignedServiceTest() throws Exception { + public void updateOrchestrationStatusAssignedServiceTest() { doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED); @@ -110,7 +144,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusAssignedServiceExceptionTest() throws Exception { + public void updateOrchestrationStatusAssignedServiceExceptionTest() { expectedException.expect(BpmnError.class); doThrow(RuntimeException.class).when(aaiServiceInstanceResources) @@ -120,7 +154,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusActiveServiceTest() throws Exception { + public void updateOrchestrationStatusActiveServiceTest() { doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE); @@ -131,7 +165,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusActiveServiceExceptionTest() throws Exception { + public void updateOrchestrationStatusActiveServiceExceptionTest() { expectedException.expect(BpmnError.class); doThrow(RuntimeException.class).when(aaiServiceInstanceResources) @@ -221,7 +255,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusAssignedVnfTest() throws Exception { + public void updateOrchestrationStatusAssignedVnfTest() { doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED); aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution); @@ -230,7 +264,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception { + public void updateOrchestrationStatusAssignedVnfExceptionTest() { expectedException.expect(BpmnError.class); doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, @@ -240,7 +274,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusActiveVnfTest() throws Exception { + public void updateOrchestrationStatusActiveVnfTest() { doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE); aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution); @@ -249,7 +283,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception { + public void updateOrchestrationStatusActiveVnfExceptionTest() { expectedException.expect(BpmnError.class); doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, @@ -259,7 +293,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusAssignVfModuleTest() throws Exception { + public void updateOrchestrationStatusAssignVfModuleTest() { doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED); aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution); @@ -269,7 +303,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception { + public void updateOrchestrationStatusAssignVfModuleExceptionTest() { doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED); @@ -279,7 +313,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception { + public void updateOrchestrationStatusCreatedVfModuleTest() { doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED); aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution); @@ -288,7 +322,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception { + public void updateOrchestrationStatusCreatedVfModuleExceptionTest() { doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED); @@ -298,7 +332,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception { + public void updateOrchestrationStatusPendingActivatefModuleTest() { doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION); @@ -309,7 +343,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception { + public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() { doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION); @@ -319,7 +353,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception { + public void updateOrchestrationStatusDectivateVfModuleTest() { doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED); @@ -330,7 +364,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception { + public void updateOrchestrationStatusDectivateVfModuleExceptionTest() { doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED); @@ -340,7 +374,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateHeatStackIdVfModuleTest() throws Exception { + public void updateHeatStackIdVfModuleTest() { execution.setVariable("heatStackId", "newHeatStackId"); doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf); @@ -351,18 +385,18 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateHeatStackIdVfModuleToNullTest() throws Exception { + public void updateHeatStackIdVfModuleToNullTest() { execution.setVariable("heatStackId", null); doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf); aaiUpdateTasks.updateHeatStackIdVfModule(execution); verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf); - assertEquals(vfModule.getHeatStackId(), ""); + assertEquals("", vfModule.getHeatStackId()); } @Test - public void updateHeatStackIdVfModuleExceptionTest() throws Exception { + public void updateHeatStackIdVfModuleExceptionTest() { doThrow(RuntimeException.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf); expectedException.expect(BpmnError.class); @@ -371,7 +405,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception { + public void updateOrchestrationStatusActiveVolumeGroupTest() { doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE); @@ -382,7 +416,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception { + public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() { expectedException.expect(BpmnError.class); doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE); @@ -390,7 +424,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception { + public void updateOrchestrationStatusCreatedVolumeGroupTest() { doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED); @@ -401,7 +435,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception { + public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() { expectedException.expect(BpmnError.class); doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED); @@ -409,7 +443,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception { + public void test_updateOrchestrationStatusAssignedVolumeGroup() { doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED); @@ -421,7 +455,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception { + public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() { expectedException.expect(BpmnError.class); doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED); @@ -429,7 +463,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateHeatStackIdVolumeGroupTest() throws Exception { + public void updateHeatStackIdVolumeGroupTest() { execution.setVariable("heatStackId", "newHeatStackId"); doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion); @@ -440,18 +474,18 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateHeatStackIdVolumeGroupToNullTest() throws Exception { + public void updateHeatStackIdVolumeGroupToNullTest() { execution.setVariable("heatStackId", null); doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion); aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution); verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion); - assertEquals(volumeGroup.getHeatStackId(), ""); + assertEquals("", volumeGroup.getHeatStackId()); } @Test - public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception { + public void updateHeatStackIdVolumeGroupExceptionTest() { expectedException.expect(BpmnError.class); doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion); @@ -459,7 +493,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateNetworkExceptionTest() throws Exception { + public void updateNetworkExceptionTest() { expectedException.expect(BpmnError.class); doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network); @@ -468,21 +502,21 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOstatusActivedNetworkCollectionTest() throws Exception { + public void updateOstatusActivedNetworkCollectionTest() { doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection()); aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution); verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection()); } @Test - public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception { + public void updateOstatusActiveNetworkColectionExceptionTest() { expectedException.expect(BpmnError.class); doThrow(RuntimeException.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection()); aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution); } @Test - public void updateOrchestrationStatusActivateVfModuleTest() throws Exception { + public void updateOrchestrationStatusActivateVfModuleTest() { doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE); @@ -493,7 +527,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception { + public void updateOrchestrationStatusActivateVfModuleExceptionTest() { doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE); @@ -642,7 +676,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception { + public void updateOrchestrationStatusDeleteVfModuleTest() { doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED); @@ -668,7 +702,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusDeactivateFabricConfigurationTest() throws Exception { + public void updateOrchestrationStatusDeactivateFabricConfigurationTest() { gBBInput = execution.getGeneralBuildingBlock(); doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ASSIGNED); @@ -680,7 +714,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusActivateFabricConfigurationTest() throws Exception { + public void updateOrchestrationStatusActivateFabricConfigurationTest() { gBBInput = execution.getGeneralBuildingBlock(); doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ACTIVE); @@ -692,7 +726,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusAssignedFabricConfigurationTest() throws Exception { + public void updateOrchestrationStatusAssignedFabricConfigurationTest() { gBBInput = execution.getGeneralBuildingBlock(); doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ASSIGNED); @@ -704,7 +738,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateContrailServiceInstanceFqdnVfModuleTest() throws Exception { + public void updateContrailServiceInstanceFqdnVfModuleTest() { execution.setVariable("contrailServiceInstanceFqdn", "newContrailServiceInstanceFqdn"); doNothing().when(aaiVfModuleResources).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf); @@ -715,13 +749,13 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateContrailServiceInstanceFqdnVfModuleNoUpdateTest() throws Exception { + public void updateContrailServiceInstanceFqdnVfModuleNoUpdateTest() { aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution); verify(aaiVfModuleResources, times(0)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf); } @Test - public void updateIpv4OamAddressVnfTest() throws Exception { + public void updateIpv4OamAddressVnfTest() { execution.setVariable("oamManagementV4Address", "newIpv4OamAddress"); doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf); @@ -732,13 +766,13 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateIpv4OamAddressVnfNoUpdateTest() throws Exception { + public void updateIpv4OamAddressVnfNoUpdateTest() { aaiUpdateTasks.updateIpv4OamAddressVnf(execution); verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf); } @Test - public void updateManagementV6AddressVnfTest() throws Exception { + public void updateManagementV6AddressVnfTest() { execution.setVariable("oamManagementV6Address", "newManagementV6Address"); doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf); @@ -749,13 +783,13 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateManagementV6AddressVnfNoUpdateTest() throws Exception { + public void updateManagementV6AddressVnfNoUpdateTest() { aaiUpdateTasks.updateManagementV6AddressVnf(execution); verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf); } @Test - public void updateOrchestrationStatusVnfConfigureTest() throws Exception { + public void updateOrchestrationStatusVnfConfigureTest() { doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CONFIGURE); @@ -763,7 +797,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusVnfConfiguredTest() throws Exception { + public void updateOrchestrationStatusVnfConfiguredTest() { doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CONFIGURED); @@ -777,7 +811,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusVnfConfigAssignedTest() throws Exception { + public void updateOrchestrationStatusVnfConfigAssignedTest() { doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.CONFIGASSIGNED); aaiUpdateTasks.updateOrchestrationStatus(execution, "vnf", "config-assign"); @@ -786,7 +820,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusVnfConfigDeployedTest() throws Exception { + public void updateOrchestrationStatusVnfConfigDeployedTest() { doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.CONFIGDEPLOYED); aaiUpdateTasks.updateOrchestrationStatus(execution, "vnf", "config-deploy"); @@ -795,7 +829,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusVfModuleConfigDeployedTest() throws Exception { + public void updateOrchestrationStatusVfModuleConfigDeployedTest() { doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CONFIGDEPLOYED); aaiUpdateTasks.updateOrchestrationStatus(execution, "vfmodule", "config-deploy"); @@ -804,7 +838,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusVfModuleConfigAssignedTest() throws Exception { + public void updateOrchestrationStatusVfModuleConfigAssignedTest() { doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CONFIGASSIGNED); aaiUpdateTasks.updateOrchestrationStatus(execution, "vfmodule", "config-assign"); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java index 60bed17447..9e70a66b76 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java @@ -31,11 +31,14 @@ import java.util.Map; import java.util.Optional; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.adapters.nwrest.CreateNetworkRequest; import org.onap.so.adapters.nwrest.CreateNetworkResponse; -import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; @@ -43,9 +46,20 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.adapter.network.mapper.NetworkAdapterObjectMapper; import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.orchestration.NetworkAdapterResources; -public class NetworkAdapterCreateTasksTest extends BaseTaskTest { +@RunWith(MockitoJUnitRunner.Silent.class) +public class NetworkAdapterCreateTasksTest extends TestDataSetup { + + @Mock + protected ExtractPojosForBB extractPojosForBB; + @Mock + protected NetworkAdapterObjectMapper networkAdapterObjectMapper; + @Mock + protected NetworkAdapterResources networkAdapterResources; @InjectMocks private NetworkAdapterCreateTasks networkAdapterCreateTasks = new NetworkAdapterCreateTasks(); @@ -77,7 +91,7 @@ public class NetworkAdapterCreateTasksTest extends BaseTaskTest { } @Test - public void createNetworkTest() throws Exception { + public void createNetworkTest() { String cloudRegionPo = "cloudRegionPo"; CreateNetworkRequest createNetworkRequest = new CreateNetworkRequest(); execution.setVariable("cloudRegionPo", cloudRegionPo); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasksTest.java index eb481651f0..6c9ec5932e 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasksTest.java @@ -27,27 +27,36 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.io.UnsupportedEncodingException; import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.adapters.nwrest.DeleteNetworkRequest; -import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; -import org.onap.so.client.adapter.network.NetworkAdapterClientException; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.adapter.network.mapper.NetworkAdapterObjectMapper; import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.ExceptionBuilder; +@RunWith(MockitoJUnitRunner.Silent.class) +public class NetworkAdapterDeleteTasksTest extends TestDataSetup { -public class NetworkAdapterDeleteTasksTest extends BaseTaskTest { - + @Mock + protected ExtractPojosForBB extractPojosForBB; + @Mock + protected ExceptionBuilder exceptionUtil; + @Mock + protected NetworkAdapterObjectMapper networkAdapterObjectMapper; @InjectMocks private NetworkAdapterDeleteTasks networkAdapterDeleteTasks = new NetworkAdapterDeleteTasks(); @@ -72,7 +81,7 @@ public class NetworkAdapterDeleteTasksTest extends BaseTaskTest { } @Test - public void test_deleteNetwork() throws UnsupportedEncodingException, NetworkAdapterClientException { + public void test_deleteNetwork() { DeleteNetworkRequest deleteNetworkRequest = new DeleteNetworkRequest(); doReturn(deleteNetworkRequest).when(networkAdapterObjectMapper).deleteNetworkRequestMapper(requestContext, cloudRegion, serviceInstance, l3Network); @@ -83,7 +92,7 @@ public class NetworkAdapterDeleteTasksTest extends BaseTaskTest { } @Test - public void test_deleteNetwork_exception() throws UnsupportedEncodingException, NetworkAdapterClientException { + public void test_deleteNetwork_exception() { expectedException.expect(BpmnError.class); doThrow(RuntimeException.class).when(networkAdapterObjectMapper).deleteNetworkRequestMapper( diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImplTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImplTest.java index 10cc09cdcc..cf97fa0b82 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImplTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImplTest.java @@ -5,13 +5,20 @@ import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertNotNull; import javax.xml.bind.JAXBException; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.FileUtil; import org.onap.so.adapters.nwrest.CreateNetworkResponse; -import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; -public class NetworkAdapterImplTest extends BaseTaskTest { +@RunWith(MockitoJUnitRunner.Silent.class) +public class NetworkAdapterImplTest extends TestDataSetup { + @Mock + protected ExtractPojosForBB extractPojosForBB; @InjectMocks private NetworkAdapterImpl networkAdapterImpl = new NetworkAdapterImpl(); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java index 64a315ad4d..082d410f96 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java @@ -21,28 +21,22 @@ package org.onap.so.bpmn.infrastructure.adapter.network.tasks; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.io.UnsupportedEncodingException; import java.util.Map; -import java.util.Optional; -import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; -import org.onap.so.adapters.nwrest.CreateNetworkRequest; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.adapters.nwrest.UpdateNetworkRequest; -import org.onap.so.adapters.nwrest.UpdateNetworkResponse; -import org.onap.so.bpmn.BaseTaskTest; -import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; @@ -50,11 +44,16 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; -import org.onap.so.client.adapter.network.NetworkAdapterClientException; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.adapter.network.mapper.NetworkAdapterObjectMapper; import org.onap.so.client.exception.BBObjectNotFoundException; -import org.springframework.beans.factory.annotation.Autowired; -public class NetworkAdapterUpdateTasksTest extends BaseTaskTest { +@RunWith(MockitoJUnitRunner.Silent.class) +public class NetworkAdapterUpdateTasksTest extends TestDataSetup { + @Mock + protected ExtractPojosForBB extractPojosForBB; + @Mock + protected NetworkAdapterObjectMapper networkAdapterObjectMapper; @InjectMocks private NetworkAdapterUpdateTasks networkAdapterUpdateTasks = new NetworkAdapterUpdateTasks(); @@ -84,7 +83,7 @@ public class NetworkAdapterUpdateTasksTest extends BaseTaskTest { } @Test - public void updateNetworkTest() throws Exception { + public void updateNetworkTest() { String cloudRegionPo = "cloudRegionPo"; UpdateNetworkRequest updateNetworkRequest = new UpdateNetworkRequest(); execution.setVariable("cloudRegionPo", cloudRegionPo); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterCreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterCreateTasksTest.java index 13f2b81fd9..ef2e742795 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterCreateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterCreateTasksTest.java @@ -30,12 +30,15 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.adapters.vnfrest.CreateVfModuleRequest; import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest; -import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; @@ -44,9 +47,22 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.orchestration.VnfAdapterVfModuleResources; +import org.onap.so.client.orchestration.VnfAdapterVolumeGroupResources; import org.onap.so.db.catalog.beans.OrchestrationStatus; -public class VnfAdapterCreateTasksTest extends BaseTaskTest { +@RunWith(MockitoJUnitRunner.Silent.class) +public class VnfAdapterCreateTasksTest extends TestDataSetup { + @Mock + protected ExceptionBuilder exceptionUtil; + @Mock + protected ExtractPojosForBB extractPojosForBB; + @Mock + protected VnfAdapterVolumeGroupResources vnfAdapterVolumeGroupResources; + @Mock + protected VnfAdapterVfModuleResources vnfAdapterVfModuleResources; @InjectMocks private VnfAdapterCreateTasks vnfAdapterCreateTasks = new VnfAdapterCreateTasks(); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterDeleteTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterDeleteTasksTest.java index c680978953..e7b3d3e403 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterDeleteTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterDeleteTasksTest.java @@ -31,12 +31,15 @@ import static org.mockito.Mockito.when; import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest; import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest; -import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; @@ -45,8 +48,22 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; - -public class VnfAdapterDeleteTasksTest extends BaseTaskTest { +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.orchestration.VnfAdapterVfModuleResources; +import org.onap.so.client.orchestration.VnfAdapterVolumeGroupResources; + +@RunWith(MockitoJUnitRunner.Silent.class) +public class VnfAdapterDeleteTasksTest extends TestDataSetup { + + @Mock + protected ExceptionBuilder exceptionUtil; + @Mock + protected ExtractPojosForBB extractPojosForBB; + @Mock + protected VnfAdapterVfModuleResources vnfAdapterVfModuleResources; + @Mock + protected VnfAdapterVolumeGroupResources vnfAdapterVolumeGroupResources; @InjectMocks private VnfAdapterDeleteTasks vnfAdapterDeleteTasks = new VnfAdapterDeleteTasks(); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImplTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImplTest.java index 16e8c2de7d..51bd77065b 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImplTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImplTest.java @@ -30,22 +30,30 @@ import static org.mockito.Mockito.when; import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.FileUtil; -import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.exception.BBObjectNotFoundException; -import org.springframework.beans.factory.annotation.Autowired; - -public class VnfAdapterImplTest extends BaseTaskTest { - +import org.onap.so.client.exception.ExceptionBuilder; + +@RunWith(MockitoJUnitRunner.Silent.class) +public class VnfAdapterImplTest extends TestDataSetup { + @Mock + protected ExceptionBuilder exceptionUtil; + @Mock + protected ExtractPojosForBB extractPojosForBB; @InjectMocks private VnfAdapterImpl vnfAdapterImpl = new VnfAdapterImpl(); @@ -159,12 +167,12 @@ public class VnfAdapterImplTest extends BaseTaskTest { execution.setVariable("WorkflowResponse", VNF_ADAPTER_REST_DELETE_RESPONSE); vnfAdapterImpl.postProcessVnfAdapter(execution); assertNull(vfModule.getHeatStackId()); - assertEquals(vfModule.getContrailServiceInstanceFqdn(), ""); - assertEquals(execution.getVariable("contrailServiceInstanceFqdn"), ""); - assertEquals(genericVnf.getIpv4OamAddress(), ""); - assertEquals(execution.getVariable("oamManagementV4Address"), ""); - assertEquals(genericVnf.getManagementV6Address(), ""); - assertEquals(execution.getVariable("oamManagementV6Address"), ""); + assertEquals("", vfModule.getContrailServiceInstanceFqdn()); + assertEquals("", execution.getVariable("contrailServiceInstanceFqdn")); + assertEquals("", genericVnf.getIpv4OamAddress()); + assertEquals("", execution.getVariable("oamManagementV4Address")); + assertEquals("", genericVnf.getManagementV6Address()); + assertEquals("", execution.getVariable("oamManagementV6Address")); assertEquals(TEST_CONTRAIL_NETWORK_POLICY_FQDNS, execution.getVariable("contrailNetworkPolicyFqdnList")); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcOrchestratorPreProcessorTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcOrchestratorPreProcessorTest.java index d7d6da209e..ad965373dc 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcOrchestratorPreProcessorTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcOrchestratorPreProcessorTest.java @@ -34,13 +34,16 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Optional; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.Vserver; import org.onap.appc.client.lcm.model.Action; import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest; import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerVnf; -import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; @@ -48,14 +51,23 @@ import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.orchestration.AAIVnfResources; import org.onap.so.client.policy.JettisonStyleMapperProvider; import org.onap.so.db.catalog.beans.ControllerSelectionReference; import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.so.db.catalog.client.CatalogDbClient; -public class AppcOrchestratorPreProcessorTest extends BaseTaskTest { +@RunWith(MockitoJUnitRunner.Silent.class) +public class AppcOrchestratorPreProcessorTest extends TestDataSetup { private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; - + @Mock + protected ExtractPojosForBB extractPojosForBB; + @Mock + protected AAIVnfResources aaiVnfResources; + @Mock + protected CatalogDbClient catalogDbClient; @InjectMocks private AppcOrchestratorPreProcessor appcOrchestratorPreProcessor = new AppcOrchestratorPreProcessor(); @@ -111,7 +123,7 @@ public class AppcOrchestratorPreProcessorTest extends BaseTaskTest { } @Test - public void addVmInfoToAppcTaskRequestTest() throws Exception { + public void addVmInfoToAppcTaskRequestTest() { ApplicationControllerTaskRequest appcTaskRequest = new ApplicationControllerTaskRequest(); ApplicationControllerVnf applicationControllerVnf = new ApplicationControllerVnf(); appcTaskRequest.setApplicationControllerVnf(applicationControllerVnf); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java index d2a38cb693..e386dff4a1 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java @@ -37,25 +37,43 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.Vserver; import org.onap.appc.client.lcm.model.Action; -import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.appc.ApplicationControllerAction; import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.orchestration.AAIVnfResources; import org.onap.so.db.catalog.beans.ControllerSelectionReference; import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.so.db.catalog.client.CatalogDbClient; -public class AppcRunTasksTest extends BaseTaskTest { +@RunWith(MockitoJUnitRunner.Silent.class) +public class AppcRunTasksTest extends TestDataSetup { private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; - + @Mock + protected ExtractPojosForBB extractPojosForBB; + @Mock + protected CatalogDbClient catalogDbClient; + @Mock + protected ExceptionBuilder exceptionUtil; + @Mock + protected ApplicationControllerAction appCClient; + @Mock + protected AAIVnfResources aaiVnfResources; @InjectMocks private AppcRunTasks appcRunTasks = new AppcRunTasks(); @@ -171,7 +189,7 @@ public class AppcRunTasksTest extends BaseTaskTest { } @Test - public void testUserParams() throws Exception { + public void testUserParams() { Map<String, Object> userParams = new HashMap<String, Object>(); userParams.put("existing_software_version", "3.1"); userParams.put("new_software_version", "3.2"); 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 cbb746d514..2e4d99f9c6 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 @@ -35,6 +35,8 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.util.Arrays; +import java.util.Collections; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -64,6 +66,7 @@ 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.BuildingBlockRollback; import org.onap.so.db.catalog.beans.ConfigurationResource; import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; import org.onap.so.db.catalog.beans.VnfResourceCustomization; @@ -109,6 +112,11 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { private DelegateExecution mockExecution; @Before + public void initCatalogDBRollbackTable() { + when(catalogDbClient.getBuildingBlockRollbackEntries()).thenReturn(getRollbackBuildingBlockList()); + } + + @Before public void before() throws Exception { execution = new DelegateExecutionFake(); ServiceInstance servInstance = new ServiceInstance(); @@ -614,6 +622,52 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { } @Test + public void rollbackExecutionRollbackControllerExecutionBBTest() { + execution.setVariable("isRollback", false); + execution.setVariable("handlingCode", "Rollback"); + execution.setVariable("requestAction", EMPTY_STRING); + execution.setVariable("resourceName", EMPTY_STRING); + List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>(); + BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignServiceInstanceBB"); + ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1); + flowsToExecute.add(ebb1); + + BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("AssignNetworkBB"); + ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2); + flowsToExecute.add(ebb2); + + BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("AssignVnfBB"); + ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3); + flowsToExecute.add(ebb3); + + BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB"); + ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4); + flowsToExecute.add(ebb4); + + BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("ControllerExecutionBB"); + buildingBlock5.setBpmnScope("vnf"); + buildingBlock5.setBpmnAction("config-assign"); + ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5); + flowsToExecute.add(ebb5); + + BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB"); + ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6); + flowsToExecute.add(ebb6); + + execution.setVariable("flowsToExecute", flowsToExecute); + execution.setVariable("gCurrentSequence", 5); + + workflowActionBBTasks.rollbackExecutionPath(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + BuildingBlock bb = ebbs.get(0).getBuildingBlock(); + assertEquals("ControllerExecutionBB", bb.getBpmnFlowName()); + assertEquals("vnf", bb.getBpmnScope()); + assertEquals("config-unassign", bb.getBpmnAction()); + assertEquals(0, execution.getVariable("gCurrentSequence")); + assertEquals(5, ebbs.size()); + } + + @Test public void postProcessingExecuteBBActivateVfModuleNotReplaceInstanceTest() throws CloneNotSupportedException { WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); workflowResourceIds.setServiceInstanceId("1"); @@ -1061,4 +1115,40 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("homing", false); execution.setVariable("calledHoming", false); } + + private List<BuildingBlockRollback> getRollbackBuildingBlockList() { + List<BuildingBlockRollback> rollbackBBList = Collections.unmodifiableList(Arrays.asList( + new BuildingBlockRollback(1, "ActivateNetworkBB", null, "DeactivateNetworkBB", null), + new BuildingBlockRollback(2, "ActivatePnfBB", null, "DeactivatePnfBB", null), + new BuildingBlockRollback(3, "ActivateServiceInstanceBB", null, "DeactivateServiceInstanceBB", null), + new BuildingBlockRollback(4, "ActivateVfModuleBB", null, "DeactivateVfModuleBB", null), + new BuildingBlockRollback(5, "ActivateVnfBB", null, "DeactivateVnfBB", null), + new BuildingBlockRollback(6, "ActivateVolumeGroupBB", null, "DeactivateVolumeGroupBB", null), + new BuildingBlockRollback(7, "AssignNetworkBB", null, "UnassignNetworkBB", null), + new BuildingBlockRollback(8, "AssignServiceInstanceBB", null, "UnassignServiceInstanceBB", null), + new BuildingBlockRollback(9, "AssignVfModuleBB", null, "UnassignVfModuleBB", null), + new BuildingBlockRollback(10, "AssignVnfBB", null, "UnassignVnfBB", null), + new BuildingBlockRollback(11, "AssignVolumeGroupBB", null, "UnassignVolumeGroupBB", null), + new BuildingBlockRollback(12, "ControllerExecutionBB", "config-assign", "ControllerExecutionBB", + "config-unassign"), + new BuildingBlockRollback(13, "ControllerExecutionBB", "config-deploy", "ControllerExecutionBB", + "config-undeploy"), + new BuildingBlockRollback(14, "ControllerExecutionBB", "service-config-deploy", "ControllerExecutionBB", + "service-config-undeploy"), + new BuildingBlockRollback(15, "CreateNetworkBB", null, "DeleteNetworkBB", null), + new BuildingBlockRollback(16, "CreateNetworkCollectionBB", null, "DeleteNetworkCollectionBB", null), + new BuildingBlockRollback(17, "CreateVfModuleBB", null, "DeleteVfModuleBB", null), + new BuildingBlockRollback(18, "CreateVolumeGroupBB", null, "DeleteVolumeGroupBB", null), + new BuildingBlockRollback(19, "VNFSetInMaintFlagActivity", null, "VNFUnsetInMaintFlagActivity", null), + new BuildingBlockRollback(20, "VNFSetClosedLoopDisabledFlagActivity", null, + "VNFUnsetClosedLoopDisabledFlagActivity", null), + new BuildingBlockRollback(21, "VNFLockActivity", null, "VNFUnlockActivity", null), + new BuildingBlockRollback(22, "VNFStopActivity", null, "VNFStartActivity", null), + new BuildingBlockRollback(23, "VNFQuiesceTrafficActivity", null, "VNFResumeTrafficActivity", null), + new BuildingBlockRollback(24, "EtsiVnfInstantiateBB", null, "EtsiVnfDeleteBB", null), + // AddFabricConfigurationBB this does not seem to be present as a bpmn in Guilin + new BuildingBlockRollback(25, "AddFabricConfigurationBB", null, "DeleteFabricConfigurationBB", null))); + return rollbackBBList; + } + } 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 52196aae49..a044944f29 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 @@ -409,6 +409,10 @@ public class WorkflowActionTest extends BaseTaskTest { serviceInstanceMSO.getVnfs().add(vnf); + VfModule aaiVfModule = new VfModule(); + aaiVfModule.setIsBaseVfModule(false); + + doReturn(aaiVfModule).when(bbSetupUtils).getAAIVfModule(any(), any()); doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("si0"); doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI); doReturn(Mockito.mock(GenericVnf.class)).when(bbSetupUtils).getAAIGenericVnf(any()); @@ -932,6 +936,10 @@ public class WorkflowActionTest extends BaseTaskTest { serviceInstanceMSO.getVnfs().add(vnf); serviceInstanceMSO.getPnfs().add(pnf); + VfModule aaiVfModule = new VfModule(); + aaiVfModule.setIsBaseVfModule(false); + + doReturn(aaiVfModule).when(bbSetupUtils).getAAIVfModule(any(), any()); doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("123"); doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI); doReturn(Mockito.mock(GenericVnf.class)).when(bbSetupUtils).getAAIGenericVnf(any()); @@ -1013,6 +1021,10 @@ public class WorkflowActionTest extends BaseTaskTest { serviceInstanceMSO.getVnfs().add(vnf); + VfModule aaiVfModule = new VfModule(); + aaiVfModule.setIsBaseVfModule(false); + + doReturn(aaiVfModule).when(bbSetupUtils).getAAIVfModule(any(), any()); doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("123"); doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI); doReturn(Mockito.mock(GenericVnf.class)).when(bbSetupUtils).getAAIGenericVnf(any()); @@ -1104,6 +1116,11 @@ public class WorkflowActionTest extends BaseTaskTest { serviceInstanceMSO.getVnfs().add(vnf); + org.onap.aai.domain.yang.VfModule aaiVfModule = new org.onap.aai.domain.yang.VfModule(); + aaiVfModule.setIsBaseVfModule(false); + + doReturn(aaiVfModule).when(bbSetupUtils).getAAIVfModule(any(), any()); + doReturn(new org.onap.aai.domain.yang.GenericVnf()).when(bbSetupUtils).getAAIGenericVnf(vnf.getVnfId()); doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("123"); doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI); when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, @@ -1151,21 +1168,26 @@ public class WorkflowActionTest extends BaseTaskTest { vfModule2.setVfModuleId("vfModule2"); vnf.getVfModules().add(vfModule2); serviceInstanceMSO.getVnfs().add(vnf); - VfModule vfModuleAAI = new VfModule(); - vfModuleAAI.setVfModuleId("vfModule2"); + VfModule vfModuleAAI1 = new VfModule(); + vfModuleAAI1.setIsBaseVfModule(false); + VfModule vfModuleAAI2 = new VfModule(); + vfModuleAAI2.setIsBaseVfModule(false); + vfModuleAAI2.setVfModuleId("vfModule2"); RelationshipList relationshipList = new RelationshipList(); Relationship relationship = new Relationship(); relationshipList.getRelationship().add(relationship); - vfModuleAAI.setRelationshipList(relationshipList); + vfModuleAAI2.setRelationshipList(relationshipList); Relationships relationships = new Relationships("abc"); Configuration config = new Configuration(); config.setConfigurationId("configId"); Optional<Configuration> configOp = Optional.of(config); Optional<Relationships> relationshipsOp = Optional.of(relationships); + doReturn(new org.onap.aai.domain.yang.GenericVnf()).when(bbSetupUtils).getAAIGenericVnf(vnf.getVnfId()); doReturn(relationshipsOp).when(workflowActionUtils).extractRelationshipsVnfc(isA(Relationships.class)); doReturn(configOp).when(workflowActionUtils).extractRelationshipsConfiguration(isA(Relationships.class)); - doReturn(vfModuleAAI).when(bbSetupUtils).getAAIVfModule("1234", "vfModule2"); + doReturn(vfModuleAAI1).when(bbSetupUtils).getAAIVfModule("1234", "vfModule1"); + doReturn(vfModuleAAI2).when(bbSetupUtils).getAAIVfModule("1234", "vfModule2"); doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("123"); doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI); when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoaderTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoaderTest.java index 9377daea5e..2d41a24ac3 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoaderTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoaderTest.java @@ -243,6 +243,9 @@ public class ServiceEBBLoaderTest extends BaseTaskTest { aaiConfiguration2.setConfigurationId("testConfigurationId2"); aaiConfiguration2.setRelationshipList(relationshipList1); + org.onap.aai.domain.yang.VfModule aaiVfModule = new org.onap.aai.domain.yang.VfModule(); + aaiVfModule.setIsBaseVfModule(true); + try { doReturn(genericVnfAai).when(mockBbInputSetupUtils).getAAIGenericVnf(genericVnf.getVnfId()); doReturn(serviceInstanceAAI).when(mockBbInputSetupUtils).getAAIServiceInstanceById(resourceId); @@ -251,6 +254,7 @@ public class ServiceEBBLoaderTest extends BaseTaskTest { .getConfiguration("testConfigurationId"); doReturn(Optional.of(aaiConfiguration2)).when(mockAaiConfigurationResources) .getConfiguration("testConfigurationId2"); + doReturn(aaiVfModule).when(mockBbInputSetupUtils).getAAIVfModule(any(), any()); serviceEBBLoader.traverseAAIService(execution, resourceCounter, resourceId, aaiResourceIds); assertEquals(8, resourceCounter.size()); assertTrue(resourceCounter.get(2).isBaseVfModule()); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoaderTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoaderTest.java index 78a9628243..2775c6d7b9 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoaderTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoaderTest.java @@ -47,12 +47,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.only; public class VnfEBBLoaderTest { private String serviceId; private String vnfId; + private String vfModuleId; private BBInputSetupUtils bbInputSetupUtils; private BBInputSetup bbInputSetup; private WorkflowActionExtractResourcesAAI workflowActionUtils; @@ -67,6 +69,7 @@ public class VnfEBBLoaderTest { public void setup() { serviceId = "service123"; vnfId = "vnf123"; + vfModuleId = "vfModule123"; serviceInstanceAAI = mock(org.onap.aai.domain.yang.ServiceInstance.class); serviceInstanceMSO = mock(ServiceInstance.class); bbInputSetupUtils = mock(BBInputSetupUtils.class); @@ -95,11 +98,19 @@ public class VnfEBBLoaderTest { GenericVnf genericVnf = mock(GenericVnf.class); doReturn(vnfId).when(genericVnf).getVnfId(); + org.onap.aai.domain.yang.GenericVnf aaiVnf = mock(org.onap.aai.domain.yang.GenericVnf.class); + doReturn(aaiVnf).when(bbInputSetupUtils).getAAIGenericVnf(vnfId); + VfModule vfModule = mock(VfModule.class); + doReturn(vfModuleId).when(vfModule).getVfModuleId(); ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); modelInfoVfModule.setIsBaseBoolean(true); doReturn(modelInfoVfModule).when(vfModule).getModelInfoVfModule(); + org.onap.aai.domain.yang.VfModule aaiVfModule = new org.onap.aai.domain.yang.VfModule(); + aaiVfModule.setIsBaseVfModule(true); + doReturn(aaiVfModule).when(bbInputSetupUtils).getAAIVfModule(vnfId, vfModuleId); + doReturn(serviceInstanceAAI).when(bbInputSetupUtils).getAAIServiceInstanceById(serviceId); doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI); doReturn(List.of(genericVnf)).when(serviceInstanceMSO).getVnfs(); 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 b23147e351..1fbee2dbc8 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 @@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; import org.junit.Before; import org.junit.Test; @@ -34,6 +35,8 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.bpmn.common.BBConstants; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.common.DelegateExecutionImpl; +import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.db.catalog.beans.PnfResourceCustomization; @@ -41,7 +44,6 @@ 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; -import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.RequestDetails; @RunWith(MockitoJUnitRunner.Silent.class) @@ -51,25 +53,24 @@ public class SkipCDSBuildingBlockListenerTest { private static final String VNF_SCOPE = "VNF"; private static final String VF_SCOPE = "VFModule"; private static final String PNF_SCOPE = "pnf"; - private static final String TEST_MODELUUID = "123456789"; private static final String VNF_TEST_ACTION = "VnfConfigAssign"; private static final String VFModule_TEST_ACTION = "VfModuleConfigAssign"; private static final String PNFModule_TEST_ACTION = "config-assign"; - private static final String MODELCUSTOMIZATIONUUID = "123456789"; + private static final String SERVICE_MODEL_VERSION_ID = UUID.randomUUID().toString(); + private static final String VNF_MODEL_CUSTOMIZATION_ID = UUID.randomUUID().toString(); + private static final String VF_MODULE_CUSTOMIZATION_ID = UUID.randomUUID().toString(); + private static final String PNF_CUSTOMIZATION_ID = UUID.randomUUID().toString(); private static final String BBNAME = "ControllerExecutionBB"; private static final boolean ISFIRST = true; - private int actual; private List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>(); - private List<VnfResourceCustomization> vnfResourceCustomization; - private List<VfModuleCustomization> vfModuleCustomization; - private ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock(); + private ExecuteBuildingBlock executeBuildingBlock; private RequestDetails reqDetail = new RequestDetails(); private BuildingBlockExecution buildingBlockExecution = new DelegateExecutionImpl(new DelegateExecutionFake()); - private VnfResourceCustomization vnfCust = new VnfResourceCustomization(); - private VfModuleCustomization vfCust = new VfModuleCustomization(); - private PnfResourceCustomization pnfResourceCustomization = new PnfResourceCustomization(); - private BuildingBlock buildingBlock = new BuildingBlock(); + private VnfResourceCustomization vnfCust; + private VfModuleCustomization vfCust; + private PnfResourceCustomization pnfResourceCustomization; + private BuildingBlock buildingBlock; @InjectMocks private SkipCDSBuildingBlockListener skipCDSBuildingBlockListener; @@ -78,10 +79,27 @@ public class SkipCDSBuildingBlockListenerTest { @Before public void before() { - ModelInfo model = new ModelInfo(); - model.setModelUuid(TEST_MODELUUID); - reqDetail.setModelInfo(model); - executeBuildingBlock.setRequestDetails(reqDetail); + executeBuildingBlock = new ExecuteBuildingBlock(); + buildingBlock = new BuildingBlock(); + + ArrayList<Resource> resources = new ArrayList<>(); + Resource service = new Resource(WorkflowType.SERVICE, SERVICE_MODEL_VERSION_ID, false, null); + service.setModelVersionId(SERVICE_MODEL_VERSION_ID); + resources.add(service); + Resource vnf = new Resource(WorkflowType.VNF, VNF_MODEL_CUSTOMIZATION_ID, false, null); + vnf.setModelCustomizationId(VNF_MODEL_CUSTOMIZATION_ID); + resources.add(vnf); + Resource vfModule = new Resource(WorkflowType.VFMODULE, VF_MODULE_CUSTOMIZATION_ID, false, null); + vfModule.setModelCustomizationId(VF_MODULE_CUSTOMIZATION_ID); + resources.add(vfModule); + Resource pnf = new Resource(WorkflowType.PNF, PNF_CUSTOMIZATION_ID, false, null); + pnf.setModelCustomizationId(PNF_CUSTOMIZATION_ID); + resources.add(pnf); + buildingBlockExecution.setVariable("resources", resources); + + vnfCust = new VnfResourceCustomization(); + vfCust = new VfModuleCustomization(); + pnfResourceCustomization = new PnfResourceCustomization(); } @Test @@ -93,133 +111,83 @@ 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); + setBuildingBlockAndCurrentSequence(SERVICE_SCOPE, "service-config-assign", SERVICE_MODEL_VERSION_ID, 0); + when(catalogDbClient.getServiceByID(SERVICE_MODEL_VERSION_ID)).thenReturn(new Service()); skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution); - actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE); - assertEquals(1, actual); + assertEquals(1, (int) buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE)); } @Test public void testProcessForVNFToSkipCDSBB() { - // given - setBuildingBlockAndCurrentSequence(VNF_SCOPE, VNF_TEST_ACTION, 0); - vnfResourceCustomization = getVnfResourceCustomizationList(true); + setBuildingBlockAndCurrentSequence(VNF_SCOPE, VNF_TEST_ACTION, VNF_MODEL_CUSTOMIZATION_ID, 0); + when(catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(VNF_MODEL_CUSTOMIZATION_ID)) + .thenReturn(vnfCust); - when(catalogDbClient.getVnfResourceCustomizationByModelUuid( - executeBuildingBlock.getRequestDetails().getModelInfo().getModelUuid())) - .thenReturn(vnfResourceCustomization); - when(catalogDbClient.findVnfResourceCustomizationInList(executeBuildingBlock.getBuildingBlock().getKey(), - vnfResourceCustomization)).thenReturn(vnfCust); - - // when skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution); - // then - actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE); - assertEquals(1, actual); - + assertEquals(1, (int) buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE)); } @Test public void testProcessForVNFNotToSkipCDSBB() { - // given - setBuildingBlockAndCurrentSequence(VNF_SCOPE, VNF_TEST_ACTION, 0); - vnfResourceCustomization = getVnfResourceCustomizationList(false); - - when(catalogDbClient.getVnfResourceCustomizationByModelUuid( - executeBuildingBlock.getRequestDetails().getModelInfo().getModelUuid())) - .thenReturn(vnfResourceCustomization); - when(catalogDbClient.findVnfResourceCustomizationInList(executeBuildingBlock.getBuildingBlock().getKey(), - vnfResourceCustomization)).thenReturn(vnfCust); + setBuildingBlockAndCurrentSequence(VNF_SCOPE, VNF_TEST_ACTION, VNF_MODEL_CUSTOMIZATION_ID, 0); + vnfCust.setSkipPostInstConf(false); + when(catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(VNF_MODEL_CUSTOMIZATION_ID)) + .thenReturn(vnfCust); - // when skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution); - // then - actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE); - assertEquals(0, actual); - + assertEquals(0, (int) buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE)); } @Test public void testProcessForVFToSkipCDSBB() { - // given - setBuildingBlockAndCurrentSequence(VF_SCOPE, VFModule_TEST_ACTION, 0); - vfModuleCustomization = getVfModuleCustomizationList(true); - - when(catalogDbClient - .getVfModuleCustomizationByModelCuztomizationUUID(executeBuildingBlock.getBuildingBlock().getKey())) - .thenReturn(vfCust); + setBuildingBlockAndCurrentSequence(VF_SCOPE, VFModule_TEST_ACTION, VF_MODULE_CUSTOMIZATION_ID, 0); + when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(VF_MODULE_CUSTOMIZATION_ID)) + .thenReturn(vfCust); - // when skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution); - // then - actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE); - assertEquals(1, actual); - + assertEquals(1, (int) buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE)); } @Test public void testProcessForVFNotToSkipCDSBB() { - // given - setBuildingBlockAndCurrentSequence(VF_SCOPE, VFModule_TEST_ACTION, 0); - vfModuleCustomization = getVfModuleCustomizationList(false); - + setBuildingBlockAndCurrentSequence(VF_SCOPE, VFModule_TEST_ACTION, VF_MODULE_CUSTOMIZATION_ID, 0); + vfCust.setSkipPostInstConf(false); when(catalogDbClient .getVfModuleCustomizationByModelCuztomizationUUID(executeBuildingBlock.getBuildingBlock().getKey())) .thenReturn(vfCust); - // when skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution); - // then - actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE); - assertEquals(0, actual); - + assertEquals(0, (int) buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE)); } @Test public void testProcessForPNFToSkipCDSBB() { - // given - setBuildingBlockAndCurrentSequence(PNF_SCOPE, PNFModule_TEST_ACTION, 0); - pnfResourceCustomization = getPnfResourceCustomization(true); - - when(catalogDbClient - .getPnfResourceCustomizationByModelCustomizationUUID(executeBuildingBlock.getBuildingBlock().getKey())) - .thenReturn(pnfResourceCustomization); + setBuildingBlockAndCurrentSequence(PNF_SCOPE, PNFModule_TEST_ACTION, PNF_CUSTOMIZATION_ID, 0); + when(catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(PNF_CUSTOMIZATION_ID)) + .thenReturn(pnfResourceCustomization); - // when skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution); - // then - actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE); - assertEquals(1, actual); - + assertEquals(1, (int) buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE)); } @Test public void testProcessForPNFNotToSkipCDSBB() { - // given - setBuildingBlockAndCurrentSequence(PNF_SCOPE, PNFModule_TEST_ACTION, 0); - pnfResourceCustomization = getPnfResourceCustomization(false); - - when(catalogDbClient - .getPnfResourceCustomizationByModelCustomizationUUID(executeBuildingBlock.getBuildingBlock().getKey())) - .thenReturn(pnfResourceCustomization); + setBuildingBlockAndCurrentSequence(PNF_SCOPE, PNFModule_TEST_ACTION, PNF_CUSTOMIZATION_ID, 0); + pnfResourceCustomization.setSkipPostInstConf(false); + when(catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(PNF_CUSTOMIZATION_ID)) + .thenReturn(pnfResourceCustomization); - // when skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution); - // then - actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE); - assertEquals(0, actual); - + assertEquals(0, (int) buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE)); } /** @@ -229,37 +197,13 @@ public class SkipCDSBuildingBlockListenerTest { * @param action * @param squence */ - private void setBuildingBlockAndCurrentSequence(String scope, String action, int sequence) { + private void setBuildingBlockAndCurrentSequence(String scope, String action, String key, int sequence) { buildingBlock.setBpmnScope(scope); buildingBlock.setBpmnAction(action); buildingBlock.setBpmnFlowName("ControllerExecutionBB"); - buildingBlock.setKey(MODELCUSTOMIZATIONUUID); + buildingBlock.setKey(key); executeBuildingBlock.setBuildingBlock(buildingBlock); buildingBlockExecution.setVariable(BBConstants.G_CURRENT_SEQUENCE, sequence); - - } - - private List<VnfResourceCustomization> getVnfResourceCustomizationList(boolean setSkippost) { - List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>(); - vnfCust.setModelCustomizationUUID(MODELCUSTOMIZATIONUUID); - vnfCust.setSkipPostInstConf(setSkippost); - vnfResourceCustomizations.add(vnfCust); - return vnfResourceCustomizations; - } - - private List<VfModuleCustomization> getVfModuleCustomizationList(boolean setSkippost) { - List<VfModuleCustomization> vfModuleCustomizations = new ArrayList<>(); - vfCust.setModelCustomizationUUID(MODELCUSTOMIZATIONUUID); - vfCust.setSkipPostInstConf(setSkippost); - vfModuleCustomizations.add(vfCust); - return vfModuleCustomizations; - } - - private PnfResourceCustomization getPnfResourceCustomization(boolean setSkippost) { - PnfResourceCustomization pnfResourceCustomization = new PnfResourceCustomization(); - pnfResourceCustomization.setModelCustomizationUUID(MODELCUSTOMIZATIONUUID); - pnfResourceCustomization.setSkipPostInstConf(setSkippost); - return pnfResourceCustomization; } } |