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=========================================================
21 package org.onap.so.bpmn.common.scripts
22 import org.camunda.bpm.engine.delegate.DelegateExecution
23 import org.onap.so.bpmn.core.RollbackData
24 import org.onap.so.bpmn.core.UrnPropertiesReader
25 import org.onap.so.logger.MessageEnum
26 import org.onap.so.logger.MsoLogger
27 import org.onap.so.rest.APIResponse
28 import org.springframework.web.util.UriUtils
30 public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
31 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CreateAAIVfModule.class);
33 def Prefix="CAAIVfMod_"
34 ExceptionUtil exceptionUtil = new ExceptionUtil()
35 public void initProcessVariables(DelegateExecution execution) {
36 execution.setVariable("prefix",Prefix)
37 execution.setVariable("CAAIVfMod_vnfId",null)
38 execution.setVariable("CAAIVfMod_vnfName",null)
39 execution.setVariable("CAAIVfMod_vnfType",null)
40 execution.setVariable("CAAIVfMod_serviceId",null)
41 execution.setVariable("CAAIVfMod_personaId",null)
42 execution.setVariable("CAAIVfMod_personaVer",null)
43 execution.setVariable("CAAIVfMod_modelCustomizationId",null)
44 execution.setVariable("CAAIVfMod_vnfPersonaId",null)
45 execution.setVariable("CAAIVfMod_vnfPersonaVer",null)
46 execution.setVariable("CAAIVfMod_isBaseVfModule", false)
47 execution.setVariable("CAAIVfMod_moduleName",null)
48 execution.setVariable("CAAIVfMod_moduleModelName",null)
49 execution.setVariable("CAAIVfMod_newGenericVnf",false)
50 execution.setVariable("CAAIVfMod_genericVnfGetEndpoint",null)
51 execution.setVariable("CAAIVfMod_genericVnfPutEndpoint",null)
52 execution.setVariable("CAAIVfMod_aaiNamespace",null)
53 execution.setVariable("CAAIVfMod_moduleExists",false)
54 execution.setVariable("CAAIVfMod_baseModuleConflict", false)
55 execution.setVariable("CAAIVfMod_vnfNameFromAAI", null)
58 // CreateAAIVfModule workflow response variable placeholders
59 execution.setVariable("CAAIVfMod_queryGenericVnfResponseCode",null)
60 execution.setVariable("CAAIVfMod_queryGenericVnfResponse","")
61 execution.setVariable("CAAIVfMod_createGenericVnfResponseCode",null)
62 execution.setVariable("CAAIVfMod_createGenericVnfResponse","")
63 execution.setVariable("CAAIVfMod_createVfModuleResponseCode",null)
64 execution.setVariable("CAAIVfMod_createVfModuleResponse","")
65 execution.setVariable("CAAIVfMod_parseModuleResponse","")
66 execution.setVariable("CAAIVfMod_deleteGenericVnfResponseCode",null)
67 execution.setVariable("CAAIVfMod_deleteGenericVnfResponse","")
68 execution.setVariable("CAAIVfMod_deleteVfModuleResponseCode",null)
69 execution.setVariable("CAAIVfMod_deleteVfModuleResponse","")
70 // execution.setVariable("CAAIVfMod_ResponseCode",null)
71 // execution.setVariable("CAAIVfMod_ErrorResponse","")
72 execution.setVariable("CreateAAIVfModuleResponse","")
73 execution.setVariable("RollbackData", null)
77 // parse the incoming CREATE_VF_MODULE request and store the Generic VNF
78 // and VF Module data in the flow DelegateExecution
79 public void preProcessRequest(DelegateExecution execution) {
80 initProcessVariables(execution)
82 def vnfId = execution.getVariable("vnfId")
83 if (vnfId == null || vnfId.isEmpty()) {
84 execution.setVariable("CAAIVfMod_newGenericVnf", true)
85 execution.setVariable("CAAIVfMod_vnfId","")
88 execution.setVariable("CAAIVfMod_vnfId",vnfId)
91 def vnfName = execution.getVariable("vnfName")
92 execution.setVariable("CAAIVfMod_vnfName", vnfName)
94 String vnfType = execution.getVariable("vnfType")
95 if (vnfType != null && !vnfType.isEmpty()) {
96 execution.setVariable("CAAIVfMod_vnfType", vnfType)
98 execution.setVariable("CAAIVfMod_vnfType","")
101 execution.setVariable("CAAIVfMod_serviceId", execution.getVariable("serviceId"))
103 String personaModelId = execution.getVariable("personaModelId")
105 if (personaModelId != null && !personaModelId.isEmpty()) {
106 execution.setVariable("CAAIVfMod_personaId",personaModelId)
108 execution.setVariable("CAAIVfMod_personaId","")
111 String personaModelVersion = execution.getVariable("personaModelVersion")
113 if (personaModelVersion != null && !personaModelVersion.isEmpty()) {
114 execution.setVariable("CAAIVfMod_personaVer", personaModelVersion)
116 execution.setVariable("CAAIVfMod_personaVer","")
120 String modelCustomizationId = execution.getVariable("modelCustomizationId")
122 if (modelCustomizationId != null && !modelCustomizationId.isEmpty()) {
123 execution.setVariable("CAAIVfMod_modelCustomizationId",modelCustomizationId)
125 execution.setVariable("CAAIVfMod_modelCustomizationId","")
128 String vnfPersonaModelId = execution.getVariable("vnfPersonaModelId")
130 if (vnfPersonaModelId != null && !vnfPersonaModelId.isEmpty()) {
131 execution.setVariable("CAAIVfMod_vnfPersonaId",vnfPersonaModelId)
133 execution.setVariable("CAAIVfMod_vnfPersonaId","")
136 String vnfPersonaModelVersion = execution.getVariable("vnfPersonaModelVersion")
138 if (vnfPersonaModelVersion != null && !vnfPersonaModelVersion.isEmpty()) {
139 execution.setVariable("CAAIVfMod_vnfPersonaVer",vnfPersonaModelVersion)
141 execution.setVariable("CAAIVfMod_vnfPersonaVer","")
145 Boolean isBaseVfModule = false
146 String isBaseVfModuleString = execution.getVariable("isBaseVfModule")
147 if (isBaseVfModuleString != null && isBaseVfModuleString.equals("true")) {
148 isBaseVfModule = true
150 execution.setVariable("CAAIVfMod_isBaseVfModule", isBaseVfModule)
152 String isVidRequest = execution.getVariable("isVidRequest")
153 if (isVidRequest != null && "true".equals(isVidRequest)) {
154 msoLogger.debug("VID Request received")
157 execution.setVariable("CAAIVfMod_moduleName",execution.getVariable("vfModuleName"))
158 execution.setVariable("CAAIVfMod_moduleModelName",execution.getVariable("vfModuleModelName"))
160 AaiUtil aaiUriUtil = new AaiUtil(this)
161 def aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
162 msoLogger.debug('AAI URI is: ' + aai_uri)
163 String aaiNamespace = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
164 msoLogger.debug('AAI namespace is: ' + aaiNamespace)
166 execution.setVariable("CAAIVfMod_aaiNamespace","${aaiNamespace}")
168 if (vnfId == null || vnfId.isEmpty()) {
169 // TBD - assert that the vnfName is not empty
170 execution.setVariable("CAAIVfMod_genericVnfGetEndpoint",
171 "${aai_uri}/?vnf-name=" +
172 UriUtils.encode(vnfName,"UTF-8") + "&depth=1")
174 execution.setVariable("CAAIVfMod_genericVnfGetEndpoint",
175 "${aai_uri}/" + UriUtils.encode(vnfId,"UTF-8") + "?depth=1")
178 msoLogger.debug("CreateAAIVfModule VNF PUT Endpoint: ${aai_uri}/")
179 execution.setVariable("CAAIVfMod_genericVnfPutEndpoint","${aai_uri}/")
182 // send a GET request to AA&I to retrieve the Generic VNF/VF Module information based on a Vnf Name
183 // expect a 200 response with the information in the response body or a 404 if the Generic VNF does not exist
184 public void queryAAIForGenericVnf(DelegateExecution execution) {
185 def endPoint = UrnPropertiesReader.getVariable("aai.endpoint", execution) + execution.getVariable("CAAIVfMod_genericVnfGetEndpoint")
188 msoLogger.debug("queryAAIForGenericVnf() endpoint-" + endPoint)
189 msoLogger.debug("invoking GET call to AAI endpoint :"+System.lineSeparator()+endPoint)
190 msoLogger.debug("CreateAAIVfModule sending GET call to AAI Endpoint: " + endPoint)
192 AaiUtil aaiUtil = new AaiUtil(this)
193 APIResponse response = aaiUtil.executeAAIGetCall(execution, endPoint)
194 def responseData = response.getResponseBodyAsString()
195 def statusCode = response.getStatusCode()
196 execution.setVariable("CAAIVfMod_queryGenericVnfResponseCode", statusCode)
197 execution.setVariable("CAAIVfMod_queryGenericVnfResponse", responseData)
199 msoLogger.debug("CreateAAIVfModule Response Code: " + statusCode)
200 msoLogger.debug("CreateAAIVfModule Response data: " + responseData)
201 msoLogger.debug("Response code:" + statusCode)
202 msoLogger.debug("Response:" + System.lineSeparator()+responseData)
203 } catch (Exception ex) {
204 msoLogger.debug("Exception occurred while executing AAI GET:" + ex.getMessage())
205 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error - Occured in queryAAIForGenericVnf.")
210 // process the result from queryAAIForGenericVnf()
211 // note: this method is primarily for logging as the actual decision logic is embedded in the bpmn flow
212 public void processAAIGenericVnfQuery(DelegateExecution execution) {
213 def result = execution.getVariable("CAAIVfMod_queryGenericVnfResponse")
215 if (execution.getVariable("CAAIVfMod_queryGenericVnfResponseCode") == 404 &&
216 execution.getVariable("CAAIVfMod_vnfId").isEmpty()) {
217 msoLogger.debug("New Generic VNF requested and it does not already exist")
218 } else if (execution.getVariable("CAAIVfMod_queryGenericVnfResponseCode") == 200 &&
219 !execution.getVariable("CAAIVfMod_vnfId").isEmpty()) {
220 msoLogger.debug("Adding module to existing Generic VNF")
221 } else if (execution.getVariable("CAAIVfMod_queryGenericVnfResponseCode") == 200 &&
222 execution.getVariable("CAAIVfMod_vnfId").isEmpty()) {
223 msoLogger.debug("Invalid request for new Generic VNF which already exists")
224 execution.setVariable("CAAIVfMod_queryGenericVnfResponse",
225 "Invalid request for new Generic VNF which already exists, Vnf Name=" +
226 execution.getVariable("CAAIVfMod_vnfName"))
227 } else { // execution.getVariable("CAAIVfMod_queryGenericVnfResponseCode") == 404 &&
228 // !execution.getVariable("CAAIVfMod_vnfId").isEmpty())
229 msoLogger.debug("Invalid request for Add-on Module requested for non-existant Generic VNF")
230 execution.setVariable("CAAIVfMod_createVfModuleResponse",
231 "Invalid request for Add-on Module requested for non-existant Generic VNF, VNF Id=" +
232 execution.getVariable("CAAIVfMod_vnfId"))
236 // construct and send a PUT request to A&AI to create a new Generic VNF
237 // note: to get here, the vnf-id in the original CREATE_VF_MODULE request was absent or ""
238 public void createGenericVnf(DelegateExecution execution) {
239 // TBD - is this how we want to generate the Id for the new Generic VNF?
240 def newVnfId = UUID.randomUUID().toString()
241 def endPoint = UrnPropertiesReader.getVariable("aai.endpoint", execution) +
242 execution.getVariable("CAAIVfMod_genericVnfPutEndpoint") + newVnfId
243 // update the flow execution with the new Vnf Id
244 execution.setVariable("CAAIVfMod_vnfId",newVnfId)
246 // AaiUriUtil aaiUriUtil = new AaiUriUtil(this)
247 // def aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
248 // msoLogger.debug('AAI URI is: ' + aai_uri)
249 // String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
250 // msoLogger.debug('AAI namespace is: ' + namespace)
253 String payload = """<generic-vnf xmlns="${execution.getVariable("CAAIVfMod_aaiNamespace")}">
254 <vnf-id>${MsoUtils.xmlEscape(newVnfId)}</vnf-id>
255 <vnf-name>${MsoUtils.xmlEscape(execution.getVariable("CAAIVfMod_vnfName"))}</vnf-name>
256 <vnf-type>${MsoUtils.xmlEscape(execution.getVariable("CAAIVfMod_vnfType"))}</vnf-type>
257 <service-id>${MsoUtils.xmlEscape(execution.getVariable("CAAIVfMod_serviceId"))}</service-id>
258 <orchestration-status>Active</orchestration-status>
259 <model-invariant-id>${MsoUtils.xmlEscape(execution.getVariable("CAAIVfMod_vnfPersonaId"))}</model-invariant-id>
260 <model-version-id>${MsoUtils.xmlEscape(execution.getVariable("CAAIVfMod_vnfPersonaVer"))}</model-version-id>
261 </generic-vnf>""" as String
262 execution.setVariable("CAAIVfMod_createGenericVnfPayload", payload)
265 msoLogger.debug("createGenericVnf() endpoint-" + endPoint)
266 msoLogger.debug("invoking PUT call to AAI with payload:"+System.lineSeparator()+payload)
267 msoLogger.debug("Sending PUT call to AAI with Endpoint /n" + endPoint + " with payload /n" + payload)
269 AaiUtil aaiUtil = new AaiUtil(this);
270 APIResponse response = aaiUtil.executeAAIPutCall(execution, endPoint, payload);
271 def responseData = response.getResponseBodyAsString()
272 def responseStatusCode = response.getStatusCode()
273 execution.setVariable("CAAIVfMod_createGenericVnfResponseCode", responseStatusCode)
274 execution.setVariable("CAAIVfMod_createGenericVnfResponse", responseData)
276 msoLogger.debug("Response Code: " + responseStatusCode)
277 msoLogger.debug("Response Data: " + responseData)
278 msoLogger.debug("Response code:" + responseStatusCode)
279 msoLogger.debug("Response:" + System.lineSeparator()+responseData)
280 } catch (Exception ex) {
282 msoLogger.debug("Exception occurred while executing AAI PUT:" + ex.getMessage())
283 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error - Occured in createGenericVnf.")
287 // construct and send a PUT request to A&AI to create a Base or Add-on VF Module
288 public void createVfModule(DelegateExecution execution, Boolean isBaseModule) {
289 // TBD - is this how we want to generate the Id for the new (Base) VF Module?
291 // Generate the new VF Module ID here if it has not been provided by the parent process
292 def newModuleId = execution.getVariable('newVfModuleId')
293 if (newModuleId == null || newModuleId.isEmpty()) {
294 newModuleId = UUID.randomUUID().toString()
296 def endPoint = UrnPropertiesReader.getVariable("aai.endpoint", execution) + execution.getVariable("CAAIVfMod_genericVnfPutEndpoint")
297 // need to append the existing Vnf Id or the one generated in createGenericVnf() to the url
298 endPoint = endPoint + UriUtils.encode(execution.getVariable("CAAIVfMod_vnfId"), "UTF-8") +
299 "/vf-modules/vf-module/" + newModuleId;
302 def aaiVnfResponse = execution.getVariable("CAAIVfMod_queryGenericVnfResponse")
303 AaiUtil aaiUtil = new AaiUtil(this)
304 def personaModelId = execution.getVariable("CAAIVfMod_personaId")
306 // Check if the response includes model-invariant-id or persona-model-id
307 // note: getRequiredNodeText() throws an exception if the field is missing
308 // need to retun a null for the subsequent "either/or" logic to work properly
309 // def modelInvariantId = getRequiredNodeText(execution, aaiVnfResponse,'model-invariant-id')
310 def modelInvariantId = getNodeText(aaiVnfResponse,'model-invariant-id', null)
311 def fieldToCheck = 'model-invariant-id'
312 if (!modelInvariantId) {
313 fieldToCheck = 'persona-model-id'
316 moduleIndex = aaiUtil.getLowestUnusedVfModuleIndexFromAAIVnfResponse(execution, aaiVnfResponse,
317 fieldToCheck, personaModelId)
319 def moduleIndexString = String.valueOf(moduleIndex)
321 // if we get to this point, we may be about to create the Vf Module,
322 // add rollback information about the Generic VNF for this base/add-on module
323 def rollbackData = execution.getVariable("RollbackData")
324 if (rollbackData == null) {
325 rollbackData = new RollbackData();
327 rollbackData.put("VFMODULE", "vnfId", execution.getVariable("CAAIVfMod_vnfId"))
328 rollbackData.put("VFMODULE", "vnfName", execution.getVariable("CAAIVfMod_vnfName"))
329 rollbackData.put("VFMODULE", "isBaseModule", isBaseModule.toString())
330 execution.setVariable("RollbackData", rollbackData)
331 msoLogger.debug("RollbackData:" + rollbackData)
332 String payload = """<vf-module xmlns="${execution.getVariable("CAAIVfMod_aaiNamespace")}">
333 <vf-module-id>${MsoUtils.xmlEscape(newModuleId)}</vf-module-id>
334 <vf-module-name>${MsoUtils.xmlEscape(execution.getVariable("CAAIVfMod_moduleName"))}</vf-module-name>
335 <model-invariant-id>${MsoUtils.xmlEscape(execution.getVariable("CAAIVfMod_personaId"))}</model-invariant-id>
336 <model-version-id>${MsoUtils.xmlEscape(execution.getVariable("CAAIVfMod_personaVer"))}</model-version-id>
337 <model-customization-id>${MsoUtils.xmlEscape(execution.getVariable("CAAIVfMod_modelCustomizationId"))}</model-customization-id>
338 <is-base-vf-module>${MsoUtils.xmlEscape(isBaseModule)}</is-base-vf-module>
339 <orchestration-status>PendingCreate</orchestration-status>
340 <module-index>${MsoUtils.xmlEscape(moduleIndex)}</module-index>
341 </vf-module>""" as String
342 execution.setVariable("CAAIVfMod_createVfModulePayload", payload)
345 msoLogger.debug("createVfModule() endpoint-" + endPoint)
346 msoLogger.debug("invoking PUT call to AAI with payload:"+System.lineSeparator()+payload)
347 msoLogger.debug("CreateAAIVfModule sending PUT call to AAI with endpoint /n" + endPoint + " with payload /n " + payload)
349 AaiUtil aaiUtil = new AaiUtil(this)
350 APIResponse response = aaiUtil.executeAAIPutCall(execution, endPoint, payload)
351 def responseData = response.getResponseBodyAsString()
352 def statusCode = response.getStatusCode()
353 execution.setVariable("CAAIVfMod_createVfModuleResponseCode", statusCode)
354 execution.setVariable("CAAIVfMod_createVfModuleResponse", responseData)
356 msoLogger.debug("Response code:" + statusCode)
357 msoLogger.debug("Response:" + System.lineSeparator()+responseData)
358 msoLogger.debug("Response Code: " + statusCode)
359 msoLogger.debug("Response data: " + responseData)
360 // the base or add-on VF Module was successfully created,
361 // add the module name to the rollback data and the response
362 if (isOneOf(statusCode, 200, 201)) {
363 rollbackData.put("VFMODULE", "vfModuleId", newModuleId)
364 rollbackData.put("VFMODULE", "vfModuleName", execution.getVariable("CAAIVfMod_moduleName"))
365 execution.setVariable("RollbackData", rollbackData)
366 msoLogger.debug("RollbackData:" + rollbackData)
368 String responseOut = ""
370 String isVidRequest = execution.getVariable("isVidRequest")
372 if (isBaseModule && (isVidRequest == null || "false".equals(isVidRequest))) {
374 responseOut = """<CreateAAIVfModuleResponse>
375 <vnf-id>${MsoUtils.xmlEscape(execution.getVariable("CAAIVfMod_vnfId"))}</vnf-id>
376 <vf-module-id>${MsoUtils.xmlEscape(newModuleId)}</vf-module-id>
377 <vf-module-index>${MsoUtils.xmlEscape(moduleIndexString)}</vf-module-index>
378 </CreateAAIVfModuleResponse>""" as String
381 responseOut = """<CreateAAIVfModuleResponse>
382 <vnf-name>${MsoUtils.xmlEscape(execution.getVariable("CAAIVfMod_vnfNameFromAAI"))}</vnf-name>
383 <vnf-id>${MsoUtils.xmlEscape(execution.getVariable("CAAIVfMod_vnfId"))}</vnf-id>
384 <vf-module-id>${MsoUtils.xmlEscape(newModuleId)}</vf-module-id>
385 <vf-module-index>${MsoUtils.xmlEscape(moduleIndexString)}</vf-module-index>
386 </CreateAAIVfModuleResponse>""" as String
389 execution.setVariable("CreateAAIVfModuleResponse", responseOut)
390 msoLogger.debug("CreateAAIVfModuleResponse:" + System.lineSeparator()+responseOut)
391 msoLogger.debug("CreateAAIVfModule Response /n " + responseOut)
393 } catch (Exception ex) {
394 msoLogger.debug("Exception occurred while executing AAI PUT:" + ex.getMessage())
395 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error - Occured in createVfModule.")
399 // parses the output from the result from queryAAIForGenericVnf() to determine if the vf-module-name
400 // requested for an Add-on VF Module does not already exist for the specified Generic VNF
401 // also retrieves VNF name from AAI response for existing VNF
402 public void parseForAddOnModule(DelegateExecution execution) {
403 def xml = execution.getVariable("CAAIVfMod_queryGenericVnfResponse")
404 def vnfNameFromAAI = utils.getNodeText(xml, "vnf-name")
405 execution.setVariable("CAAIVfMod_vnfNameFromAAI", vnfNameFromAAI)
406 msoLogger.debug("Obtained vnf-name from AAI for existing VNF: " + vnfNameFromAAI)
407 def newModuleName = execution.getVariable("CAAIVfMod_moduleName")
408 msoLogger.debug("VF Module to be added: " + newModuleName)
409 def qryModuleNameList = utils.getMultNodes(xml, "vf-module-name")
410 execution.setVariable("CAAIVfMod_moduleExists", false)
411 if (qryModuleNameList != null) {
412 msoLogger.debug("Existing VF Module List: " + qryModuleNameList)
413 for (String qryModuleName : qryModuleNameList) {
414 if (newModuleName.equals(qryModuleName)) {
415 // a module with the requested name already exists - failure
416 msoLogger.debug("VF Module " + qryModuleName + " already exists for Generic VNF " + execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
417 execution.setVariable("CAAIVfMod_moduleExists", true)
418 execution.setVariable("CAAIVfMod_parseModuleResponse",
419 "VF Module " + qryModuleName + " already exists for Generic VNF " +
420 execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
425 if (execution.getVariable("CAAIVfMod_moduleExists") == false) {
426 msoLogger.debug("VF Module " + execution.getVariable("CAAIVfMod_moduleName") + " does not exist for Generic VNF " + execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
427 execution.setVariable("CAAIVfMod_parseModuleResponse",
428 "VF Module " + newModuleName + " does not exist for Generic VNF " +
429 execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
433 // parses the output from the result from queryAAIForGenericVnf() to determine if the vf-module-name
434 // requested for an Add-on VF Module does not already exist for the specified Generic VNF;
435 // also retrieves VNF name from AAI response for existing VNF
436 public void parseForBaseModule(DelegateExecution execution) {
437 def xml = execution.getVariable("CAAIVfMod_queryGenericVnfResponse")
438 def vnfNameFromAAI = utils.getNodeText(xml, "vnf-name")
439 execution.setVariable("CAAIVfMod_vnfNameFromAAI", vnfNameFromAAI)
440 msoLogger.debug("Obtained vnf-name from AAI for existing VNF: " + vnfNameFromAAI)
441 def newModuleName = execution.getVariable("CAAIVfMod_moduleName")
442 msoLogger.debug("VF Module to be added: " + newModuleName)
443 def qryModuleNameList = utils.getMultNodes(xml, "vf-module-name")
444 execution.setVariable("CAAIVfMod_moduleExists", false)
445 if (qryModuleNameList != null) {
446 msoLogger.debug("Existing VF Module List: " + qryModuleNameList)
447 for (String qryModuleName : qryModuleNameList) {
448 if (newModuleName.equals(qryModuleName)) {
449 // a module with the requested name already exists - failure
450 msoLogger.debug("VF Module " + qryModuleName + " already exists for Generic VNF " + execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
451 execution.setVariable("CAAIVfMod_baseModuleConflict", true)
452 execution.setVariable("CAAIVfMod_parseModuleResponse",
453 "VF Module " + qryModuleName + " already exists for Generic VNF " +
454 execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
459 def isBaseVfModuleList = utils.getMultNodes(xml, "is-base-vf-module")
460 if (isBaseVfModuleList != null && !execution.getVariable("CAAIVfMod_baseModuleConflict")) {
462 for (String baseValue : isBaseVfModuleList) {
463 if (baseValue.equals("true")) {
464 // a base module already exists in this VNF - failure
465 msoLogger.debug("Base VF Module already exists for Generic VNF " + execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
466 execution.setVariable("CAAIVfMod_baseModuleConflict", true)
467 execution.setVariable("CAAIVfMod_parseModuleResponse",
468 "Base VF Module already exists for Generic VNF " +
469 execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
475 if (execution.getVariable("CAAIVfMod_moduleExists") == false && execution.getVariable("CAAIVfMod_baseModuleConflict") == false) {
476 msoLogger.debug("VF Module " + execution.getVariable("CAAIVfMod_moduleName") + " does not exist for Generic VNF " + execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
477 execution.setVariable("CAAIVfMod_parseModuleResponse",
478 "VF Module " + newModuleName + " does not exist for Generic VNF " +
479 execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
483 // generates a WorkflowException when the A&AI query returns a response code other than 200 or 404
484 public void handleAAIQueryFailure(DelegateExecution execution) {
485 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Error occurred attempting to query AAI, Response Code " + execution.getVariable("CAAIVfMod_queryGenericVnfResponseCode") + ", Error Response " + execution.getVariable("CAAIVfMod_queryGenericVnfResponse"), "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
486 int code = execution.getVariable("CAAIVfMod_queryGenericVnfResponseCode")
487 exceptionUtil.buildAndThrowWorkflowException(execution, code, "Error occurred attempting to query AAI")
491 // generates a WorkflowException if
492 // - the A&AI Generic VNF PUT returns a response code other than 200 or 201
493 // - the requested Generic VNF already exists but vnf-id == null
494 // - the requested Generic VNF does not exist but vnf-id != null
495 // - the A&AI VF Module PUT returns a response code other than 200 or 201
496 // - the requested VF Module already exists for the Generic VNF
497 public void handleCreateVfModuleFailure(DelegateExecution execution) {
500 if (execution.getVariable("CAAIVfMod_createGenericVnfResponseCode") != null &&
501 !isOneOf(execution.getVariable("CAAIVfMod_createGenericVnfResponseCode"), 200, 201)) {
502 msoLogger.debug("Failure creating Generic VNF: " + execution.getVariable("CAAIVfMod_createGenericVnfResponse"))
503 errorResponse = execution.getVariable("CAAIVfMod_createGenericVnfResponse")
505 } else if (execution.getVariable("CAAIVfMod_queryGenericVnfResponse") != null &&
506 execution.getVariable("CAAIVfMod_newGenericVnf") == true) {
507 // attempted to create a Generic VNF that already exists but vnf-id == null
508 msoLogger.debug(execution.getVariable("CAAIVfMod_queryGenericVnfResponse"))
509 errorResponse = execution.getVariable("CAAIVfMod_queryGenericVnfResponse")
511 } else if (execution.getVariable("CAAIVfMod_queryGenericVnfResponseCode") == 404 &&
512 execution.getVariable("CAAIVfMod_newGenericVnf") == false) {
513 // attempted to create a Generic VNF where vnf-name does not exist but vnf-id != null
514 msoLogger.debug(execution.getVariable("CAAIVfMod_queryGenericVnfResponse"))
515 errorResponse = execution.getVariable("CAAIVfMod_queryGenericVnfResponse")
517 } else if (execution.getVariable("CAAIVfMod_createVfModuleResponseCode") != null) {
518 msoLogger.debug("Failed to add VF Module: " + execution.getVariable("CAAIVfMod_createVfModuleResponse"))
519 errorResponse = execution.getVariable("CAAIVfMod_createVfModuleResponse")
521 } else if (execution.getVariable("CAAIVfMod_moduleExists") == true) {
522 msoLogger.debug("Attempting to add VF Module that already exists: " + execution.getVariable("CAAIVfMod_parseModuleResponse"))
523 errorResponse = execution.getVariable("CAAIVfMod_parseModuleResponse")
525 } else if (execution.getVariable("CAAIVfMod_baseModuleConflict") == true) {
526 msoLogger.debug("Attempting to add Base VF Module to VNF that already has a Base VF Module: " + execution.getVariable("CAAIVfMod_parseModuleResponse"))
527 errorResponse = execution.getVariable("CAAIVfMod_parseModuleResponse")
530 // if the responses get populated corerctly, we should never get here
531 errorResponse = "Unknown error occurred during CreateAAIVfModule flow"
535 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Error occurred during CreateAAIVfModule flow", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, errorResponse);
536 exceptionUtil.buildAndThrowWorkflowException(execution, errorCode, errorResponse)
537 msoLogger.debug("Workflow exception occurred in CreateAAIVfModule: " + errorResponse)
541 * Performs a rollback.
542 * TBD: This method requires additional testing once integrated with the
543 * main CreateVfModule flow.
544 * @param execution the execution
546 public void rollback(DelegateExecution execution) {
547 def method = getClass().getSimpleName() + ".rollback(" +
548 "execution=" + execution.getId() +
550 msoLogger.debug("Entered " + method)
553 RollbackData rollbackData = (RollbackData) execution.getVariable("RollbackData")
554 msoLogger.debug("RollbackData:" + rollbackData)
556 AaiUtil aaiUriUtil = new AaiUtil(this)
557 def aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
558 msoLogger.debug('AAI URI is: ' + aai_uri)
559 msoLogger.debug("CreateAAIVfModule rollback AAI URI: " + aai_uri)
561 if (rollbackData != null) {
562 if (rollbackData.hasType("VFMODULE")) {
563 // use the DeleteAAIVfModule groovy methods for the rollback
564 def vnfId = rollbackData.get("VFMODULE", "vnfId")
565 def vfModuleId = rollbackData.get("VFMODULE", "vfModuleId")
566 def isBaseModule = rollbackData.get("VFMODULE", "isBaseModule")
567 execution.setVariable("DAAIVfMod_vnfId", vnfId)
568 execution.setVariable("DAAIVfMod_vfModuleId", vfModuleId)
569 execution.setVariable("DAAIVfMod_genericVnfEndpoint", "${aai_uri}/" + vnfId)
570 execution.setVariable("DAAIVfMod_vfModuleEndpoint", "${aai_uri}/" + vnfId +
571 "/vf-modules/vf-module/" + vfModuleId)
572 DeleteAAIVfModule dvm = new DeleteAAIVfModule()
573 // query A&AI to get the needed information for the delete(s)
574 dvm.queryAAIForGenericVnf(execution)
575 dvm.parseForVfModule(execution)
577 // roll back the base or add-on module
578 dvm.deleteVfModule(execution)
579 def responseCode = execution.getVariable("DAAIVfMod_deleteVfModuleResponseCode")
580 def response = execution.getVariable("DAAIVfMod_deleteVfModuleResponseCode")
582 if (isOneOf(responseCode, 200, 204)) {
583 msoLogger.debug("Received " + responseCode + " to VF Module rollback request")
584 // execution.setVariable("RollbackResult", "SUCCESS")
586 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Received " + responseCode + " to VF Module rollback request", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, rollbackData + System.lineSeparator() + "Response: " + response);
589 // a new Generic VNF was created that needs to be rolled back
590 if (isBaseModule.equals("true")) {
591 dvm.deleteGenericVnf(execution)
592 responseCode = execution.getVariable("DAAIVfMod_deleteGenericVnfResponseCode")
593 response = execution.getVariable("DAAIVfMod_deleteGenericVnfResponse")
595 if (isOneOf(responseCode, 200, 204)) {
596 msoLogger.debug("Received " + responseCode + " to Generic VNF rollback request")
597 execution.setVariable("RollbackResult", "SUCCESS")
599 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Received " + responseCode + " to Generic VNF rollback request", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, rollbackData + System.lineSeparator() + "Response: " + response);
602 execution.setVariable("RollbackResult", "SUCCESS")
607 msoLogger.debug("Exited " + method)
608 } catch (Exception e) {
609 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Caught exception in " + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);