diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main')
13 files changed, 533 insertions, 118 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; + } + +} |