2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
20 package org.openecomp.mso.bpmn.infrastructure.scripts
\r
22 import java.util.UUID;
\r
24 import org.json.JSONObject;
\r
25 import org.json.JSONArray;
\r
27 import org.camunda.bpm.engine.delegate.BpmnError
\r
28 import org.camunda.bpm.engine.runtime.Execution;
\r
30 import static org.apache.commons.lang3.StringUtils.*;
\r
32 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
33 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
34 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
\r
35 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
36 import org.openecomp.mso.bpmn.common.scripts.VidUtils
\r
37 import org.openecomp.mso.bpmn.core.RollbackData
\r
38 import org.openecomp.mso.bpmn.core.WorkflowException
\r
41 * This class supports the macro VID Flow
\r
42 * with the rollback of a creation of a generic vnf and related VF modules.
\r
44 class DoCreateVnfAndModulesRollback extends AbstractServiceTaskProcessor {
\r
46 String Prefix="DCVAMR_"
\r
47 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
48 JsonUtils jsonUtil = new JsonUtils()
\r
52 * This method gets and validates the incoming
\r
55 * @param - execution
\r
58 public void preProcessRequest(Execution execution) {
\r
59 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
60 execution.setVariable("prefix",Prefix)
\r
61 utils.log("DEBUG", " *** STARTED DoCreateVnfAndModulesRollback PreProcessRequest Process*** ", isDebugEnabled)
\r
64 // Get Rollback Variables
\r
66 def rollbackData = execution.getVariable("RollbackData")
\r
67 utils.log("DEBUG", "Incoming RollbackData is: " + rollbackData.toString(), isDebugEnabled)
\r
68 String vnfId = rollbackData.get("VNF", "vnfId")
\r
69 utils.log("DEBUG", "Rollback vnfId is: " + vnfId, isDebugEnabled)
\r
70 execution.setVariable("DCVAMR_vnfId", vnfId)
\r
72 def numOfAddOnModulesString = rollbackData.get("VNFANDMODULES", "numOfCreatedAddOnModules")
\r
73 int numOfAddOnModules = 0
\r
74 if (numOfAddOnModulesString != null) {
\r
75 numOfAddOnModules = Integer.parseInt(numOfAddOnModulesString)
\r
77 execution.setVariable("DCVAMR_numOfAddOnModules", numOfAddOnModules)
\r
79 def baseVfModuleRollbackMap = rollbackData.get("VFMODULE_BASE")
\r
80 if (baseVfModuleRollbackMap == null) {
\r
81 // there are no VF Modules to delete
\r
82 execution.setVariable("DCVAMR_numOfModulesToDelete", 0)
\r
85 execution.setVariable("DCVAMR_numOfModulesToDelete", numOfAddOnModules + 1)
\r
88 }catch(BpmnError b){
\r
89 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
\r
91 }catch(Exception e){
\r
92 utils.log("DEBUG", " Error Occured in DoCreateVnfAndModulesRollback PreProcessRequest method!" + e.getMessage(), isDebugEnabled)
\r
93 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnfAndModulesRollback PreProcessRequest")
\r
96 utils.log("DEBUG", "*** COMPLETED DoCreateVnfAndModulesRollback PreProcessRequest Process ***", isDebugEnabled)
\r
101 public void preProcessCreateVfModuleRollback(Execution execution){
\r
102 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
103 execution.setVariable("prefix", Prefix)
\r
104 logDebug(" ======== STARTED preProcessCreateVfModuleRollback ======== ", isDebugLogEnabled)
\r
108 def rollbackData = execution.getVariable("RollbackData")
\r
110 def vfModuleRollbackData = new RollbackData()
\r
112 def numOfModulesToDelete = execution.getVariable("DCVAMR_numOfModulesToDelete")
\r
113 logDebug("numOfModulesToDelete: " + numOfModulesToDelete, isDebugLogEnabled)
\r
114 def moduleMap = null
\r
116 if (numOfModulesToDelete > 1) {
\r
117 int addOnModuleIndex = numOfModulesToDelete - 1
\r
118 moduleMap = rollbackData.get("VFMODULE_ADDON_" + addOnModuleIndex)
\r
119 logDebug("Removing ADDON VF module # " + addOnModuleIndex, isDebugLogEnabled)
\r
122 moduleMap = rollbackData.get("VFMODULE_BASE")
\r
123 logDebug("Removing BASE VF module", isDebugLogEnabled)
\r
125 moduleMap.each{ k, v -> vfModuleRollbackData.put("VFMODULE", "${k}","${v}") }
\r
126 execution.setVariable("DCVAMR_RollbackData", vfModuleRollbackData)
\r
128 }catch(Exception e){
\r
129 utils.log("ERROR", "Exception Occured Processing preProcessCreateVfModuleRollback. Exception is:\n" + e, isDebugLogEnabled)
\r
130 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessCreateVfModuleRollback Method:\n" + e.getMessage())
\r
132 logDebug("======== COMPLETED preProcessCreateVfModuleRollback ======== ", isDebugLogEnabled)
\r
136 public void postProcessCreateVfModuleRollback(Execution execution){
\r
137 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
138 execution.setVariable("prefix", Prefix)
\r
139 logDebug(" ======== STARTED postProcessCreateVfModuleRollback ======== ", isDebugLogEnabled)
\r
142 def numOfModulesToDelete = execution.getVariable("DCVAMR_numOfModulesToDelete")
\r
143 execution.setVariable("DCVAMR_numOfModulesToDelete", numOfModulesToDelete - 1)
\r
144 }catch(Exception e){
\r
145 utils.log("ERROR", "Exception Occured Processing postProcessCreateVfModuleRollback. Exception is:\n" + e, isDebugLogEnabled)
\r
146 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during postProcessCreateVfModuleRollback Method:\n" + e.getMessage())
\r
148 logDebug("======== COMPLETED postProcessCreateVfModuleRollback ======== ", isDebugLogEnabled)
\r