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
43 * This class supports the macro VID Flow
\r
44 * with the creation of a generic vnf and related VF modules.
\r
46 class DoCreateVnfAndModules extends AbstractServiceTaskProcessor {
\r
48 String Prefix="DCVAM_"
\r
49 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
50 JsonUtils jsonUtil = new JsonUtils()
\r
51 VidUtils vidUtils = new VidUtils(this)
\r
52 CatalogDbUtils cutils = new CatalogDbUtils()
\r
55 * This method gets and validates the incoming
\r
58 * @param - execution
\r
60 public void preProcessRequest(Execution execution) {
\r
61 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
62 execution.setVariable("prefix",Prefix)
\r
63 utils.log("DEBUG", " *** STARTED DoCreateVnfAndModules PreProcessRequest Process*** ", isDebugEnabled)
\r
69 String cloudConfiguration = execution.getVariable("cloudConfiguration")
\r
70 String vnfModelInfo = execution.getVariable("vnfModelInfo")
\r
72 String requestId = execution.getVariable("requestId")
\r
73 execution.setVariable("mso-request-id", requestId)
\r
74 utils.log("DEBUG", "Incoming Request Id is: " + requestId, isDebugEnabled)
\r
76 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
77 utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)
\r
79 String vnfType = execution.getVariable("vnfType")
\r
80 utils.log("DEBUG", "Incoming Vnf Type is: " + vnfType, isDebugEnabled)
\r
82 String vnfName = execution.getVariable("vnfName")
\r
83 execution.setVariable("CREVI_vnfName", vnfName)
\r
84 utils.log("DEBUG", "Incoming Vnf Name is: " + vnfName, isDebugEnabled)
\r
86 String productFamilyId = execution.getVariable("productFamilyId")
\r
87 utils.log("DEBUG", "Incoming Product Family Id is: " + productFamilyId, isDebugEnabled)
\r
89 String source = "VID"
\r
90 execution.setVariable("source", source)
\r
91 utils.log("DEBUG", "Incoming Source is: " + source, isDebugEnabled)
\r
93 String disableRollback = execution.getVariable("disableRollback")
\r
94 utils.log("DEBUG", "Incoming Disable Rollback is: " + disableRollback, isDebugEnabled)
\r
96 String asdcServiceModelVersion = execution.getVariable("asdcServiceModelVersion")
\r
97 utils.log("DEBUG", "Incoming asdcServiceModelVersion: " + asdcServiceModelVersion, isDebugEnabled)
\r
99 String vnfId = execution.getVariable("testVnfId") // for junits
\r
100 if(isBlank(vnfId)){
\r
101 vnfId = execution.getVariable("vnfId")
\r
102 if (isBlank(vnfId)) {
\r
103 vnfId = UUID.randomUUID().toString()
\r
104 utils.log("DEBUG", "Generated Vnf Id is: " + vnfId, isDebugEnabled)
\r
107 execution.setVariable("vnfId", vnfId)
\r
109 def rollbackData = execution.getVariable("RollbackData")
\r
110 if (rollbackData == null) {
\r
111 rollbackData = new RollbackData()
\r
114 execution.setVariable("numOfCreatedAddOnModules", 0)
\r
116 rollbackData.put("VNFANDMODULES", "numOfCreatedAddOnModules", 0)
\r
117 execution.setVariable("RollbackData", rollbackData)
\r
119 }catch(BpmnError b){
\r
120 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
\r
122 }catch(Exception e){
\r
123 utils.log("DEBUG", " Error Occured in DoCreateVnfAndModules PreProcessRequest method!" + e.getMessage(), isDebugEnabled)
\r
124 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnf PreProcessRequest")
\r
127 utils.log("DEBUG", "*** COMPLETED DoCreateVnfAndModules PreProcessRequest Process ***", isDebugEnabled)
\r
131 public void queryCatalogDB (Execution execution) {
\r
132 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
133 execution.setVariable("prefix",Prefix)
\r
135 utils.log("DEBUG", " *** STARTED DoCreateVnfAndModules QueryCatalogDB Process *** ", isDebugEnabled)
\r
138 String vnfModelInfo = execution.getVariable("vnfModelInfo")
\r
139 String vnfModelCustomizationUuid = jsonUtil.getJsonValueForKey(vnfModelInfo, "modelCustomizationId")
\r
140 utils.log("DEBUG", "querying Catalog DB by vnfModelCustomizationUuid: " + vnfModelCustomizationUuid)
\r
141 String catalogDbEndpoint = execution.getVariable("URN_mso_catalog_db_endpoint")
\r
143 JSONArray vnfs = cutils.getAllVnfsByVnfModelCustomizationUuid(catalogDbEndpoint,
\r
144 vnfModelCustomizationUuid)
\r
145 utils.log("DEBUG", "obtained VNF list")
\r
146 // Only one match here
\r
147 JSONObject vnf = vnfs[0]
\r
148 JSONArray vfModules = vnf.getJSONArray("vfModules")
\r
149 JSONArray addOnModules = new JSONArray()
\r
151 // Set up base Vf Module info
\r
152 for (int i = 0; i < vfModules.length(); i++) {
\r
153 utils.log("DEBUG", "handling VF Module ")
\r
154 JSONObject vfModule = vfModules[i]
\r
155 String isBase = jsonUtil.getJsonValueForKey(vfModule, "isBase")
\r
156 if (isBase.equals("true")) {
\r
157 JSONObject baseVfModuleModelInfoObject = vfModule.getJSONObject("modelInfo")
\r
158 String baseVfModuleModelInfo = baseVfModuleModelInfoObject.toString()
\r
159 execution.setVariable("baseVfModuleModelInfo", baseVfModuleModelInfo)
\r
160 String baseVfModuleLabel = jsonUtil.getJsonValueForKey(vfModule, "vfModuleLabel")
\r
161 execution.setVariable("baseVfModuleLabel", baseVfModuleLabel)
\r
162 String basePersonaModelId = jsonUtil.getJsonValueForKey(baseVfModuleModelInfoObject, "modelInvariantId")
\r
163 execution.setVariable("basePersonaModelId", basePersonaModelId)
\r
166 addOnModules.add(vfModules[i])
\r
170 execution.setVariable("addOnModules", addOnModules)
\r
171 execution.setVariable("addOnModulesToDeploy", addOnModules.length())
\r
172 execution.setVariable("addOnModulesDeployed", 0)
\r
174 }catch(Exception ex) {
\r
175 utils.log("DEBUG", "Error Occured in DoCreateVnfAndModules QueryCatalogDB Process " + ex.getMessage(), isDebugEnabled)
\r
176 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnfAndModules QueryCatalogDB Process")
\r
179 // Generate vfModuleId for base VF Module
\r
180 def baseVfModuleId = UUID.randomUUID().toString()
\r
181 execution.setVariable("baseVfModuleId", baseVfModuleId)
\r
182 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra PrepareCreateGenericVnf Process ***", isDebugEnabled)
\r
185 public void preProcessAddOnModule(Execution execution){
\r
186 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
187 execution.setVariable("prefix", Prefix)
\r
188 logDebug(" ======== STARTED preProcessAddOnModule ======== ", isDebugLogEnabled)
\r
191 JSONArray addOnModules = (JSONArray) execution.getVariable("addOnModules")
\r
192 int addOnIndex = (int) execution.getVariable("addOnModulesDeployed")
\r
194 JSONObject addOnModule = addOnModules[addOnIndex]
\r
196 def newVfModuleId = UUID.randomUUID().toString()
\r
197 execution.setVariable("addOnVfModuleId", newVfModuleId)
\r
199 execution.setVariable("instancesOfThisModelDeployed", 0)
\r
201 JSONObject addOnVfModuleModelInfoObject = jsonUtil.getJsonValueForKey(addOnModule, "modelInfo")
\r
202 String addOnVfModuleModelInfo = addOnVfModuleModelInfoObject.toString()
\r
203 execution.setVariable("addOnVfModuleModelInfo", addOnVfModuleModelInfo)
\r
204 String addOnVfModuleLabel = jsonUtil.getJsonValueForKey(addOnModule, "vfModuleLabel")
\r
205 execution.setVariable("addOnVfModuleLabel", addOnVfModuleLabel)
\r
206 String addOnPersonaModelId = jsonUtil.getJsonValueForKey(addOnVfModuleModelInfoObject, "modelInvariantId")
\r
207 execution.setVariable("addOnPersonaModelId", addOnPersonaModelId)
\r
208 String addOnInitialCount = jsonUtil.getJsonValueForKey(addOnModule, "initialCount")
\r
209 execution.setVariable("initialCount", addOnInitialCount)
\r
212 }catch(Exception e){
\r
213 utils.log("ERROR", "Exception Occured Processing preProcessAddOnModule. Exception is:\n" + e, isDebugLogEnabled)
\r
214 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessAddOnModule Method:\n" + e.getMessage())
\r
216 logDebug("======== COMPLETED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
\r
219 public void validateBaseModule(Execution execution){
\r
220 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
221 execution.setVariable("prefix", Prefix)
\r
222 logDebug(" ======== STARTED validateBaseModule ======== ", isDebugLogEnabled)
\r
225 def baseRollbackData = execution.getVariable("DCVAM_baseRollbackData")
\r
226 def rollbackData = execution.getVariable("RollbackData")
\r
228 def baseModuleMap = baseRollbackData.get("VFMODULE")
\r
229 baseModuleMap.each{ k, v -> rollbackData.put("VFMODULE_BASE", "${k}","${v}") }
\r
230 execution.setVariable("RollbackData", rollbackData)
\r
232 }catch(Exception e){
\r
233 utils.log("ERROR", "Exception Occured Processing validateBaseModule. Exception is:\n" + e, isDebugLogEnabled)
\r
234 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during validateBaseModule Method:\n" + e.getMessage())
\r
236 logDebug("======== COMPLETED validateBaseModule ======== ", isDebugLogEnabled)
\r
239 public void validateAddOnModule(Execution execution){
\r
240 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
241 execution.setVariable("prefix", Prefix)
\r
242 logDebug(" ======== STARTED validateAddOnModule ======== ", isDebugLogEnabled)
\r
245 int instancesOfThisModuleDeployed = execution.getVariable("instancesOfThisModuleDeployed")
\r
246 int numOfCreatedAddOnModules = execution.getVariable("numOfCreatedAddOnModules")
\r
247 def addOnRollbackData = execution.getVariable("DCVAM_addOnRollbackData")
\r
248 def rollbackData = execution.getVariable("RollbackData")
\r
250 def addOnModuleMap = addOnRollbackData.get("VFMODULE")
\r
251 numOfCreatedAddOnModules = numOfCreatedAddOnModules + 1
\r
252 addOnModuleMap.each{ k, v -> rollbackData.put("VFMODULE_ADDON_" + numOfCreatedAddOnModules, "${k}","${v}") }
\r
254 execution.setVariable("DCVAM_addOnRollbackData", null)
\r
256 execution.setVariable("instancesOfThisModuleDeployed", instancesOfThisModuleDeployed + 1)
\r
258 execution.setVariable("numOfCreatedAddOnModules", numOfCreatedAddOnModules)
\r
259 rollbackData.put("VNFANDMODULES", "numOfCreatedAddOnModules", numOfCreatedAddOnModules)
\r
260 execution.setVariable("RollbackData", rollbackData)
\r
261 }catch(Exception e){
\r
262 utils.log("ERROR", "Exception Occured Processing preProcessAddOnModule. Exception is:\n" + e, isDebugLogEnabled)
\r
263 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessAddOnModule Method:\n" + e.getMessage())
\r
265 logDebug("======== COMPLETED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
\r
268 public void finishProcessingInitialCountDeployment(Execution execution){
\r
269 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
270 execution.setVariable("prefix", Prefix)
\r
271 logDebug(" ======== STARTED finishProcessingInitialCountDeployment ======== ", isDebugLogEnabled)
\r
274 int addOnModulesDeployed = execution.getVariable("addOnModulesDeployed")
\r
275 execution.setVariable("addOnModulesDeployed", addOnModulesDeployed + 1)
\r
276 }catch(Exception e){
\r
277 utils.log("ERROR", "Exception Occured Processing preProcessAddOnModule. Exception is:\n" + e, isDebugLogEnabled)
\r
278 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessAddOnModule Method:\n" + e.getMessage())
\r
280 logDebug("======== COMPLETED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
\r