2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.mso.bpmn.infrastructure.scripts
22 import java.util.UUID;
24 import org.json.JSONObject;
25 import org.json.JSONArray;
27 import org.camunda.bpm.engine.delegate.BpmnError
28 import org.camunda.bpm.engine.runtime.Execution;
30 import static org.apache.commons.lang3.StringUtils.*;
32 import org.openecomp.mso.bpmn.core.json.JsonUtils
33 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
34 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
35 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
36 import org.openecomp.mso.bpmn.common.scripts.VidUtils
37 import org.openecomp.mso.bpmn.core.RollbackData
38 import org.openecomp.mso.bpmn.core.WorkflowException
43 * This class supports the macro VID Flow
44 * with the creation of a generic vnf and related VF modules.
46 class DoCreateVnfAndModules extends AbstractServiceTaskProcessor {
48 String Prefix="DCVAM_"
49 ExceptionUtil exceptionUtil = new ExceptionUtil()
50 JsonUtils jsonUtil = new JsonUtils()
51 VidUtils vidUtils = new VidUtils(this)
52 CatalogDbUtils cutils = new CatalogDbUtils()
55 * This method gets and validates the incoming
60 public void preProcessRequest(Execution execution) {
61 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
62 execution.setVariable("prefix",Prefix)
63 utils.log("DEBUG", " *** STARTED DoCreateVnfAndModules PreProcessRequest Process*** ", isDebugEnabled)
69 String cloudConfiguration = execution.getVariable("cloudConfiguration")
70 String vnfModelInfo = execution.getVariable("vnfModelInfo")
72 String requestId = execution.getVariable("requestId")
73 execution.setVariable("mso-request-id", requestId)
74 utils.log("DEBUG", "Incoming Request Id is: " + requestId, isDebugEnabled)
76 String serviceInstanceId = execution.getVariable("serviceInstanceId")
77 utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)
79 String vnfType = execution.getVariable("vnfType")
80 utils.log("DEBUG", "Incoming Vnf Type is: " + vnfType, isDebugEnabled)
82 String vnfName = execution.getVariable("vnfName")
83 execution.setVariable("CREVI_vnfName", vnfName)
84 utils.log("DEBUG", "Incoming Vnf Name is: " + vnfName, isDebugEnabled)
86 String productFamilyId = execution.getVariable("productFamilyId")
87 utils.log("DEBUG", "Incoming Product Family Id is: " + productFamilyId, isDebugEnabled)
90 execution.setVariable("source", source)
91 utils.log("DEBUG", "Incoming Source is: " + source, isDebugEnabled)
93 String disableRollback = execution.getVariable("disableRollback")
94 utils.log("DEBUG", "Incoming Disable Rollback is: " + disableRollback, isDebugEnabled)
96 String asdcServiceModelVersion = execution.getVariable("asdcServiceModelVersion")
97 utils.log("DEBUG", "Incoming asdcServiceModelVersion: " + asdcServiceModelVersion, isDebugEnabled)
99 String vnfId = execution.getVariable("testVnfId") // for junits
101 vnfId = execution.getVariable("vnfId")
102 if (isBlank(vnfId)) {
103 vnfId = UUID.randomUUID().toString()
104 utils.log("DEBUG", "Generated Vnf Id is: " + vnfId, isDebugEnabled)
107 execution.setVariable("vnfId", vnfId)
110 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
113 utils.log("DEBUG", " Error Occured in DoCreateVnfAndModules PreProcessRequest method!" + e.getMessage(), isDebugEnabled)
114 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnf PreProcessRequest")
117 utils.log("DEBUG", "*** COMPLETED DoCreateVnfAndModules PreProcessRequest Process ***", isDebugEnabled)
121 public void queryCatalogDB (Execution execution) {
122 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
123 execution.setVariable("prefix",Prefix)
125 utils.log("DEBUG", " *** STARTED DoCreateVnfAndModules QueryCatalogDB Process *** ", isDebugEnabled)
128 String vnfModelInfo = execution.getVariable("vnfModelInfo")
129 String vnfModelCustomizationUuid = jsonUtil.getJsonValueForKey(vnfModelInfo, "modelCustomizationId")
130 utils.log("DEBUG", "querying Catalog DB by vnfModelCustomizationUuid: " + vnfModelCustomizationUuid)
131 String catalogDbEndpoint = execution.getVariable("URN_mso_catalog_db_endpoint")
133 JSONArray vnfs = cutils.getAllVnfsByVnfModelCustomizationUuid(catalogDbEndpoint,
134 vnfModelCustomizationUuid)
135 utils.log("DEBUG", "obtained VNF list")
136 // Only one match here
137 JSONObject vnf = vnfs[0]
138 JSONArray vfModules = vnf.getJSONArray("vfModules")
139 JSONArray addOnModules = new JSONArray()
141 // Set up base Vf Module info
142 for (int i = 0; i < vfModules.length(); i++) {
143 utils.log("DEBUG", "handling VF Module ")
144 JSONObject vfModule = vfModules[i]
145 String isBase = jsonUtil.getJsonValueForKey(vfModule, "isBase")
146 if (isBase.equals("true")) {
147 JSONObject baseVfModuleModelInfoObject = vfModule.getJSONObject("modelInfo")
148 String baseVfModuleModelInfo = baseVfModuleModelInfoObject.toString()
149 execution.setVariable("baseVfModuleModelInfo", baseVfModuleModelInfo)
150 String baseVfModuleLabel = jsonUtil.getJsonValueForKey(vfModule, "vfModuleLabel")
151 execution.setVariable("baseVfModuleLabel", baseVfModuleLabel)
152 String basePersonaModelId = jsonUtil.getJsonValueForKey(baseVfModuleModelInfoObject, "modelInvariantId")
153 execution.setVariable("basePersonaModelId", basePersonaModelId)
156 addOnModules.add(vfModules[i])
160 execution.setVariable("addOnModules", addOnModules)
161 execution.setVariable("addOnModulesToDeploy", addOnModules.length())
162 execution.setVariable("addOnModulesDeployed", 0)
164 }catch(Exception ex) {
165 utils.log("DEBUG", "Error Occured in DoCreateVnfAndModules QueryCatalogDB Process " + ex.getMessage(), isDebugEnabled)
166 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnfAndModules QueryCatalogDB Process")
169 // Generate vfModuleId for base VF Module
170 def baseVfModuleId = UUID.randomUUID().toString()
171 execution.setVariable("baseVfModuleId", baseVfModuleId)
172 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra PrepareCreateGenericVnf Process ***", isDebugEnabled)
175 public void preProcessAddOnModule(Execution execution){
176 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
177 execution.setVariable("prefix", Prefix)
178 logDebug(" ======== STARTED preProcessAddOnModule ======== ", isDebugLogEnabled)
181 JSONArray addOnModules = (JSONArray) execution.getVariable("addOnModules")
182 int addOnIndex = (int) execution.getVariable("addOnModulesDeployed")
184 JSONObject addOnModule = addOnModules[addOnIndex]
186 def newVfModuleId = UUID.randomUUID().toString()
187 execution.setVariable("addOnVfModuleId", newVfModuleId)
189 execution.setVariable("instancesOfThisModelDeployed", 0)
191 JSONObject addOnVfModuleModelInfoObject = jsonUtil.getJsonValueForKey(addOnModule, "modelInfo")
192 String addOnVfModuleModelInfo = addOnVfModuleModelInfoObject.toString()
193 execution.setVariable("addOnVfModuleModelInfo", addOnVfModuleModelInfo)
194 String addOnVfModuleLabel = jsonUtil.getJsonValueForKey(addOnModule, "vfModuleLabel")
195 execution.setVariable("addOnVfModuleLabel", addOnVfModuleLabel)
196 String addOnPersonaModelId = jsonUtil.getJsonValueForKey(addOnVfModuleModelInfoObject, "modelInvariantId")
197 execution.setVariable("addOnPersonaModelId", addOnPersonaModelId)
198 String addOnInitialCount = jsonUtil.getJsonValueForKey(addOnModule, "initialCount")
199 execution.setVariable("initialCount", addOnInitialCount)
203 utils.log("ERROR", "Exception Occured Processing preProcessAddOnModule. Exception is:\n" + e, isDebugLogEnabled)
204 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessAddOnModule Method:\n" + e.getMessage())
206 logDebug("======== COMPLETED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
209 public void validateAddOnModule(Execution execution){
210 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
211 execution.setVariable("prefix", Prefix)
212 logDebug(" ======== STARTED validateAddOnModule ======== ", isDebugLogEnabled)
215 int instancesOfThisModuleDeployed = execution.getVariable("instancesOfThisModuleDeployed")
216 execution.setVariable("instancesOfThisModuleDeployed", instancesOfThisModuleDeployed + 1)
218 utils.log("ERROR", "Exception Occured Processing preProcessAddOnModule. Exception is:\n" + e, isDebugLogEnabled)
219 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessAddOnModule Method:\n" + e.getMessage())
221 logDebug("======== COMPLETED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
224 public void finishProcessingInitialCountDeployment(Execution execution){
225 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
226 execution.setVariable("prefix", Prefix)
227 logDebug(" ======== STARTED finishProcessingInitialCountDeployment ======== ", isDebugLogEnabled)
230 int addOnModulesDeployed = execution.getVariable("addOnModulesDeployed")
231 execution.setVariable("addOnModulesDeployed", addOnModulesDeployed + 1)
233 utils.log("ERROR", "Exception Occured Processing preProcessAddOnModule. Exception is:\n" + e, isDebugLogEnabled)
234 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessAddOnModule Method:\n" + e.getMessage())
236 logDebug("======== COMPLETED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)