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.openecomp.mso.bpmn.infrastructure.scripts;
23 import javax.xml.parsers.DocumentBuilder
24 import javax.xml.parsers.DocumentBuilderFactory
26 import org.apache.commons.lang3.*
27 import org.camunda.bpm.engine.delegate.BpmnError
28 import org.camunda.bpm.engine.runtime.Execution
29 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
30 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
31 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
32 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
33 import org.openecomp.mso.bpmn.common.scripts.VfModuleBase
34 import org.openecomp.mso.bpmn.core.RollbackData
35 import org.openecomp.mso.bpmn.core.WorkflowException
36 import org.openecomp.mso.bpmn.core.json.JsonUtils
37 import org.openecomp.mso.rest.APIResponse
38 import org.openecomp.mso.rest.RESTClient
39 import org.openecomp.mso.rest.RESTConfig
40 import org.springframework.web.util.UriUtils
41 import org.w3c.dom.Document
42 import org.w3c.dom.Element
43 import org.w3c.dom.NamedNodeMap
44 import org.w3c.dom.Node
45 import org.w3c.dom.NodeList
46 import org.xml.sax.InputSource
50 public class DoCreateVfModule extends VfModuleBase {
52 String Prefix="DCVFM_"
53 ExceptionUtil exceptionUtil = new ExceptionUtil()
54 JsonUtils jsonUtil = new JsonUtils()
55 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
58 * Validates the request message and sets up the workflow.
59 * @param execution the execution
61 public void preProcessRequest(Execution execution) {
62 def method = getClass().getSimpleName() + '.preProcessRequest(' +
63 'execution=' + execution.getId() +
65 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
66 logDebug('Entered ' + method, isDebugLogEnabled)
68 execution.setVariable('prefix', Prefix)
70 def rollbackData = execution.getVariable("RollbackData")
71 if (rollbackData == null) {
72 rollbackData = new RollbackData()
75 execution.setVariable("DCVFM_vnfParamsExistFlag", false)
76 execution.setVariable("DCVFM_oamManagementV4Address", "")
77 execution.setVariable("DCVFM_oamManagementV6Address", "")
79 String request = execution.getVariable("DoCreateVfModuleRequest")
81 if (request == null || request.isEmpty()) {
82 // Building Block-type request
84 String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
86 def serviceModelInfo = execution.getVariable("serviceModelInfo")
87 logDebug("serviceModelInfo: " + serviceModelInfo, isDebugLogEnabled)
88 def vnfModelInfo = execution.getVariable("vnfModelInfo")
92 def tenantId = execution.getVariable("tenantId")
93 execution.setVariable("DCVFM_tenantId", tenantId)
94 rollbackData.put("VFMODULE", "tenantid", tenantId)
96 def volumeGroupId = execution.getVariable("volumeGroupId")
97 execution.setVariable("DCVFM_volumeGroupId", volumeGroupId)
99 def volumeGroupName = execution.getVariable("volumeGroupName")
100 execution.setVariable("DCVFM_volumeGroupName", volumeGroupName)
102 def cloudSiteId = execution.getVariable("lcpCloudRegionId")
103 execution.setVariable("DCVFM_cloudSiteId", cloudSiteId)
104 rollbackData.put("VFMODULE", "aiccloudregion", cloudSiteId)
105 logDebug("cloudSiteId: " + cloudSiteId, isDebugLogEnabled)
107 def vnfType = execution.getVariable("vnfType")
108 execution.setVariable("DCVFM_vnfType", vnfType)
109 rollbackData.put("VFMODULE", "vnftype", vnfType)
110 logDebug("vnfType: " + vnfType, isDebugLogEnabled)
112 def vnfName = execution.getVariable("vnfName")
113 execution.setVariable("DCVFM_vnfName", vnfName)
114 rollbackData.put("VFMODULE", "vnfname", vnfName)
115 logDebug("vnfName: " + vnfName, isDebugLogEnabled)
117 def vnfId = execution.getVariable("vnfId")
118 execution.setVariable("DCVFM_vnfId", vnfId)
119 rollbackData.put("VFMODULE", "vnfid", vnfId)
120 logDebug("vnfId: " + vnfId, isDebugLogEnabled)
122 def vfModuleName = execution.getVariable("vfModuleName")
123 execution.setVariable("DCVFM_vfModuleName", vfModuleName)
124 rollbackData.put("VFMODULE", "vfmodulename", vfModuleName)
125 logDebug("vfModuleName: " + vfModuleName, isDebugLogEnabled)
127 def vfModuleModelName = jsonUtil.getJsonValue(vfModuleModelInfo, "modelName")
128 execution.setVariable("DCVFM_vfModuleModelName", vfModuleModelName)
129 rollbackData.put("VFMODULE", "vfmodulemodelname", vfModuleModelName)
130 logDebug("vfModuleModelName: " + vfModuleModelName, isDebugLogEnabled)
131 //modelCustomizationUuid
132 def modelCustomizationUuid = jsonUtil.getJsonValue(vfModuleModelInfo, "modelCustomizationUuid")
133 execution.setVariable("DCVFM_modelCustomizationUuid", modelCustomizationUuid)
134 rollbackData.put("VFMODULE", "modelcustomizationuuid", modelCustomizationUuid)
135 logDebug("modelCustomizationUuid: " + modelCustomizationUuid, isDebugLogEnabled)
137 def vfModuleId = execution.getVariable("vfModuleId")
138 execution.setVariable("DCVFM_vfModuleId", vfModuleId)
139 logDebug("vfModuleId: " + vfModuleId, isDebugLogEnabled)
140 def requestId = execution.getVariable("msoRequestId")
141 execution.setVariable("DCVFM_requestId", requestId)
142 logDebug("requestId: " + requestId, isDebugLogEnabled)
143 // Set mso-request-id to request-id for VNF Adapter interface
144 execution.setVariable("mso-request-id", requestId)
146 def serviceId = execution.getVariable("serviceId")
147 execution.setVariable("DCVFM_serviceId", serviceId)
148 logDebug("serviceId: " + serviceId, isDebugLogEnabled)
150 def serviceInstanceId = execution.getVariable("serviceInstanceId")
151 execution.setVariable("DCVFM_serviceInstanceId", serviceInstanceId)
152 rollbackData.put("VFMODULE", "serviceInstanceId", serviceInstanceId)
153 logDebug("serviceInstanceId: " + serviceInstanceId, isDebugLogEnabled)
156 execution.setVariable("DCVFM_source", source)
157 rollbackData.put("VFMODULE", "source", source)
158 logDebug("source: " + source, isDebugLogEnabled)
160 def disableRollback = execution.getVariable("disableRollback")
161 def backoutOnFailure = true
162 if (disableRollback != null && disableRollback.equals("true")) {
163 backoutOnFailure = false
165 execution.setVariable("DCVFM_backoutOnFailure", backoutOnFailure)
166 logDebug("backoutOnFailure: " + backoutOnFailure, isDebugLogEnabled)
168 def isBaseVfModule = execution.getVariable("isBaseVfModule")
169 execution.setVariable("DCVFM_isBaseVfModule", isBaseVfModule)
170 logDebug("isBaseVfModule: " + isBaseVfModule, isDebugLogEnabled)
171 //asdcServiceModelVersion
172 def asdcServiceModelVersion = execution.getVariable("asdcServiceModelVersion")
173 execution.setVariable("DCVFM_asdcServiceModelVersion", asdcServiceModelVersion)
174 logDebug("asdcServiceModelVersion: " + asdcServiceModelVersion, isDebugLogEnabled)
176 execution.setVariable("DCVFM_personaModelId", jsonUtil.getJsonValue(vfModuleModelInfo, "modelInvariantId"))
177 //personaModelVersion
178 execution.setVariable("DCVFM_personaModelVersion", jsonUtil.getJsonValue(vfModuleModelInfo, "modelVersionId"))
180 def vfModuleLabel = execution.getVariable("vfModuleLabel")
181 if (vfModuleLabel != null) {
182 execution.setVariable("DCVFM_vfModuleLabel", vfModuleLabel)
183 logDebug("vfModuleLabel: " + vfModuleLabel, isDebugLogEnabled)
185 //Get or Generate UUID
186 String uuid = execution.getVariable("DCVFM_uuid")
188 uuid = UUID.randomUUID()
189 logDebug("Generated messageId (UUID) is: " + uuid, isDebugLogEnabled)
191 logDebug("Found messageId (UUID) is: " + uuid, isDebugLogEnabled)
194 String isVidRequest = execution.getVariable("isVidRequest")
196 if (isVidRequest == null || isVidRequest.isEmpty()) {
197 execution.setVariable("isVidRequest", "true")
200 String globalSubscriberId = execution.getVariable("globalSubscriberId")
201 execution.setVariable("DCVFM_globalSubscriberId", globalSubscriberId)
202 logDebug("globalSubsrciberId: " + globalSubscriberId, isDebugLogEnabled)
203 Map<String,String> vfModuleInputParams = execution.getVariable("vfModuleInputParams")
204 if (vfModuleInputParams != null) {
205 execution.setVariable("DCVFM_vnfParamsMap", vfModuleInputParams)
206 execution.setVariable("DCVFM_vnfParamsExistFlag", true)
209 def usePreload = execution.getVariable("usePreload")
210 execution.setVariable("DCVFM_usePreload", usePreload)
211 logDebug("usePreload: " + usePreload, isDebugLogEnabled)
215 // The info is inside the request - DEAD CODE
216 utils.logAudit("DoCreateVfModule request: " + request)
220 if (utils.nodeExists(request, "tenant-id")) {
221 tenantId = utils.getNodeText(request, "tenant-id")
223 execution.setVariable("DCVFM_tenantId", tenantId)
224 rollbackData.put("VFMODULE", "tenantid", tenantId)
226 def volumeGroupId = ""
227 if (utils.nodeExists(request, "volume-group-id")) {
228 volumeGroupId = utils.getNodeText(request, "volume-group-id")
230 execution.setVariable("DCVFM_volumeGroupId", volumeGroupId)
232 def volumeGroupName = ""
233 if (utils.nodeExists(request, "volume-group-name")) {
234 volumeGroupName = utils.getNodeText(request, "volume-group-name")
236 execution.setVariable("DCVFM_volumeGroupName", volumeGroupName)
239 if (utils.nodeExists(request, "aic-cloud-region")) {
240 cloudSiteId = utils.getNodeText(request, "aic-cloud-region")
242 execution.setVariable("DCVFM_cloudSiteId", cloudSiteId)
243 rollbackData.put("VFMODULE", "aiccloudregion", cloudSiteId)
244 logDebug("cloudSiteId: " + cloudSiteId, isDebugLogEnabled)
247 if (utils.nodeExists(request, "vnf-type")) {
248 vnfType = utils.getNodeText(request, "vnf-type")
250 execution.setVariable("DCVFM_vnfType", vnfType)
251 rollbackData.put("VFMODULE", "vnftype", vnfType)
252 logDebug("vnfType: " + vnfType, isDebugLogEnabled)
255 if (utils.nodeExists(request, "vnf-name")) {
256 vnfName = utils.getNodeText(request, "vnf-name")
258 execution.setVariable("DCVFM_vnfName", vnfName)
259 rollbackData.put("VFMODULE", "vnfname", vnfName)
260 logDebug("vnfName: " + vnfName, isDebugLogEnabled)
263 if (utils.nodeExists(request, "vnf-id")) {
264 vnfId = utils.getNodeText(request, "vnf-id")
266 execution.setVariable("DCVFM_vnfId", vnfId)
267 rollbackData.put("VFMODULE", "vnfid", vnfId)
268 logDebug("vnfId: " + vnfId, isDebugLogEnabled)
270 def vfModuleName = ""
271 if (utils.nodeExists(request, "vf-module-name")) {
272 vfModuleName = utils.getNodeText(request, "vf-module-name")
274 execution.setVariable("DCVFM_vfModuleName", vfModuleName)
275 rollbackData.put("VFMODULE", "vfmodulename", vfModuleName)
276 logDebug("vfModuleName: " + vfModuleName, isDebugLogEnabled)
278 def vfModuleModelName = ""
279 if (utils.nodeExists(request, "vf-module-model-name")) {
280 vfModuleModelName = utils.getNodeText(request, "vf-module-model-name")
282 execution.setVariable("DCVFM_vfModuleModelName", vfModuleModelName)
283 rollbackData.put("VFMODULE", "vfmodulemodelname", vfModuleModelName)
284 logDebug("vfModuleModelName: " + vfModuleModelName, isDebugLogEnabled)
285 //modelCustomizationUuid
286 def modelCustomizationUuid = ""
287 if (utils.nodeExists(request, "model-customization-id")) {
288 modelCustomizationUuid = utils.getNodeText(request, "model-customization-id")
290 execution.setVariable("DCVFM_modelCustomizationUuid", modelCustomizationUuid)
291 rollbackData.put("VFMODULE", "modelcustomizationuuid", modelCustomizationUuid)
292 logDebug("modelCustomizationUuid: " + modelCustomizationUuid, isDebugLogEnabled)
295 if (utils.nodeExists(request, "vf-module-id")) {
296 vfModuleId = utils.getNodeText(request, "vf-module-id")
298 execution.setVariable("DCVFM_vfModuleId", vfModuleId)
299 logDebug("vfModuleId: " + vfModuleId, isDebugLogEnabled)
301 if (utils.nodeExists(request, "request-id")) {
302 requestId = utils.getNodeText(request, "request-id")
304 execution.setVariable("DCVFM_requestId", requestId)
305 logDebug("requestId: " + requestId, isDebugLogEnabled)
308 if (utils.nodeExists(request, "service-id")) {
309 serviceId = utils.getNodeText(request, "service-id")
311 execution.setVariable("DCVFM_serviceId", serviceId)
312 logDebug("serviceId: " + serviceId, isDebugLogEnabled)
314 def serviceInstanceId = ""
315 if (utils.nodeExists(request, "service-instance-id")) {
316 serviceInstanceId = utils.getNodeText(request, "service-instance-id")
318 execution.setVariable("DCVFM_serviceInstanceId", serviceInstanceId)
319 rollbackData.put("VFMODULE", "serviceInstanceId", serviceInstanceId)
320 logDebug("serviceInstanceId: " + serviceInstanceId, isDebugLogEnabled)
323 if (utils.nodeExists(request, "source")) {
324 source = utils.getNodeText(request, "source")
326 execution.setVariable("DCVFM_source", source)
327 rollbackData.put("VFMODULE", "source", source)
328 logDebug("source: " + source, isDebugLogEnabled)
330 NetworkUtils networkUtils = new NetworkUtils()
331 def backoutOnFailure = networkUtils.isRollbackEnabled(execution,request)
332 execution.setVariable("DCVFM_backoutOnFailure", backoutOnFailure)
333 logDebug("backoutOnFailure: " + backoutOnFailure, isDebugLogEnabled)
335 def isBaseVfModule = "false"
336 if (utils.nodeExists(request, "is-base-vf-module")) {
337 isBaseVfModule = utils.getNodeText(request, "is-base-vf-module")
339 execution.setVariable("DCVFM_isBaseVfModule", isBaseVfModule)
340 logDebug("isBaseVfModule: " + isBaseVfModule, isDebugLogEnabled)
342 //asdcServiceModelVersion
343 def asdcServiceModelVersion = ""
344 if (utils.nodeExists(request, "asdc-service-model-version")) {
345 asdcServiceModelVersion = utils.getNodeText(request, "asdc-service-model-version")
347 execution.setVariable("DCVFM_asdcServiceModelVersion", asdcServiceModelVersion)
348 logDebug("asdcServiceModelVersion: " + asdcServiceModelVersion, isDebugLogEnabled)
351 def personaModelId = ""
352 if (utils.nodeExists(request, "persona-model-id")) {
353 personaModelId = utils.getNodeText(request, "persona-model-id")
355 execution.setVariable("DCVFM_personaModelId", personaModelId)
356 logDebug("personaModelId: " + personaModelId, isDebugLogEnabled)
358 //personaModelVersion
359 def personaModelVersion = ""
360 if (utils.nodeExists(request, "persona-model-version")) {
361 personaModelVersion = utils.getNodeText(request, "persona-model-version")
363 execution.setVariable("DCVFM_personaModelVersion", personaModelVersion)
364 logDebug("personaModelVersion: " + personaModelVersion, isDebugLogEnabled)
366 // Process the parameters
368 String vnfParamsChildNodes = utils.getChildNodes(request, "vnf-params")
369 if(vnfParamsChildNodes == null || vnfParamsChildNodes.length() < 1){
370 utils.log("DEBUG", "Request contains NO VNF Params", isDebugLogEnabled)
372 utils.log("DEBUG", "Request does contain VNF Params", isDebugLogEnabled)
373 execution.setVariable("DCVFM_vnfParamsExistFlag", true)
375 InputSource xmlSource = new InputSource(new StringReader(request));
376 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
377 docFactory.setNamespaceAware(true)
378 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
379 Document xml = docBuilder.parse(xmlSource)
380 //Get params, build map
381 Map<String, String> paramsMap = new HashMap<String, String>()
382 NodeList paramsList = xml.getElementsByTagNameNS("*", "param")
384 for (int z = 0; z < paramsList.getLength(); z++) {
385 Node node = paramsList.item(z)
386 String paramValue = node.getTextContent()
387 NamedNodeMap e = node.getAttributes()
388 String paramName = e.getNamedItem("name").getTextContent()
389 paramsMap.put(paramName, paramValue)
391 execution.setVariable("DCVFM_vnfParamsMap", paramsMap)
395 //Get or Generate UUID
396 String uuid = execution.getVariable("DCVFM_uuid")
398 uuid = UUID.randomUUID()
399 logDebug("Generated messageId (UUID) is: " + uuid, isDebugLogEnabled)
401 logDebug("Found messageId (UUID) is: " + uuid, isDebugLogEnabled)
403 // Get sdncVersion, default to empty
404 String sdncVersion = execution.getVariable("sdncVersion")
405 if (sdncVersion == null) {
408 logDebug("sdncVersion: " + sdncVersion, isDebugLogEnabled)
409 execution.setVariable("DCVFM_sdncVersion", sdncVersion)
411 execution.setVariable("DCVFM_uuid", uuid)
412 execution.setVariable("DCVFM_baseVfModuleId", "")
413 execution.setVariable("DCVFM_baseVfModuleHeatStackId", "")
414 execution.setVariable("DCVFM_heatStackId", "")
415 execution.setVariable("DCVFM_contrailServiceInstanceFqdn", "")
416 execution.setVariable("DCVFM_volumeGroupStackId", "")
417 execution.setVariable("DCVFM_cloudRegionForVolume", "")
418 execution.setVariable("DCVFM_contrailNetworkPolicyFqdnList", "")
419 execution.setVariable("DCVFM_vnfTypeToQuery", "generic-vnf")
420 rollbackData.put("VFMODULE", "rollbackPrepareUpdateVfModule", "false")
421 rollbackData.put("VFMODULE", "rollbackUpdateAAIVfModule", "false")
422 rollbackData.put("VFMODULE", "rollbackVnfAdapterCreate", "false")
423 rollbackData.put("VFMODULE", "rollbackSDNCRequestActivate", "false")
424 rollbackData.put("VFMODULE", "rollbackSDNCRequestAssign", "false")
425 rollbackData.put("VFMODULE", "rollbackCreateAAIVfModule", "false")
426 rollbackData.put("VFMODULE", "rollbackCreateNetworkPoliciesAAI", "false")
427 rollbackData.put("VFMODULE", "rollbackUpdateVnfAAI", "false")
429 String sdncCallbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
430 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
431 def msg = 'Required variable \'URN_mso_workflow_sdncadapter_callback\' is missing'
433 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
435 execution.setVariable("DCVFM_sdncCallbackUrl", sdncCallbackUrl)
436 utils.logAudit("SDNC Callback URL: " + sdncCallbackUrl)
437 logDebug("SDNC Callback URL is: " + sdncCallbackUrl, isDebugLogEnabled)
440 execution.setVariable("RollbackData", rollbackData)
444 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error encountered in PreProcess method!")
447 logDebug('Exited ' + method, isDebugLogEnabled)
451 * Validates a workflow response.
452 * @param execution the execution
453 * @param responseVar the execution variable in which the response is stored
454 * @param responseCodeVar the execution variable in which the response code is stored
455 * @param errorResponseVar the execution variable in which the error response is stored
457 public void validateWorkflowResponse(Execution execution, String responseVar,
458 String responseCodeVar, String errorResponseVar) {
459 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
460 sdncAdapterUtils.validateSDNCResponse(execution, responseVar, responseCodeVar, errorResponseVar)
465 * Sends the empty, synchronous response back to the API Handler.
466 * @param execution the execution
468 public void sendResponse(Execution execution) {
469 def method = getClass().getSimpleName() + '.sendResponse(' +
470 'execution=' + execution.getId() +
472 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
473 logDebug('Entered ' + method, isDebugLogEnabled)
476 sendWorkflowResponse(execution, 200, "")
477 logDebug('Exited ' + method, isDebugLogEnabled)
478 } catch (BpmnError e) {
480 } catch (Exception e) {
481 logError('Caught exception in ' + method, e)
482 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Internal Error')
487 * Using the received vnfId and vfModuleId, query AAI to get the corresponding VNF info.
488 * A 200 response is expected with the VNF info in the response body. Will find out the base module info
489 * and existing VNF's name for add-on modules
491 * @param execution The flow's execution instance.
493 public void postProcessCreateAAIVfModule(Execution execution) {
494 def method = getClass().getSimpleName() + '.getVfModule(' +
495 'execution=' + execution.getId() +
497 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
498 logDebug('Entered ' + method, isDebugLogEnabled)
501 def createResponse = execution.getVariable('DCVFM_createVfModuleResponse')
502 utils.logAudit("createVfModule Response: " + createResponse)
504 def rollbackData = execution.getVariable("RollbackData")
505 String vnfName = utils.getNodeText1(createResponse, 'vnf-name')
506 if (vnfName != null) {
507 execution.setVariable('DCVFM_vnfName', vnfName)
508 logDebug("vnfName retrieved from AAI is: " + vnfName, isDebugLogEnabled)
509 rollbackData.put("VFMODULE", "vnfname", vnfName)
511 String vnfId = utils.getNodeText1(createResponse, 'vnf-id')
512 execution.setVariable('DCVFM_vnfId', vnfId)
513 logDebug("vnfId is: " + vnfId, isDebugLogEnabled)
514 String vfModuleId = utils.getNodeText1(createResponse, 'vf-module-id')
515 execution.setVariable('DCVFM_vfModuleId', vfModuleId)
516 logDebug("vfModuleId is: " + vfModuleId, isDebugLogEnabled)
517 String vfModuleIndex= utils.getNodeText1(createResponse, 'vf-module-index')
518 execution.setVariable('DCVFM_vfModuleIndex', vfModuleIndex)
519 logDebug("vfModuleIndex is: " + vfModuleIndex, isDebugLogEnabled)
520 rollbackData.put("VFMODULE", "vnfid", vnfId)
521 rollbackData.put("VFMODULE", "vfmoduleid", vfModuleId)
522 rollbackData.put("VFMODULE", "rollbackCreateAAIVfModule", "true")
523 rollbackData.put("VFMODULE", "rollbackPrepareUpdateVfModule", "true")
524 execution.setVariable("RollbackData", rollbackData)
525 } catch (Exception ex) {
527 logDebug('Exception occurred while postProcessing CreateAAIVfModule request:' + ex.getMessage(),isDebugLogEnabled)
528 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Bad response from CreateAAIVfModule' + ex.getMessage())
530 logDebug('Exited ' + method, isDebugLogEnabled)
535 * Using the received vnfId and vfModuleId, query AAI to get the corresponding VNF info.
536 * A 200 response is expected with the VNF info in the response body. Will find out the base module info.
538 * @param execution The flow's execution instance.
540 public void queryAAIVfModule(Execution execution) {
541 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
542 def method = getClass().getSimpleName() + '.getVfModule(' +
543 'execution=' + execution.getId() +
545 logDebug('Entered ' + method, isDebugLogEnabled)
548 def vnfId = execution.getVariable('DCVFM_vnfId')
549 def vfModuleId = execution.getVariable('DCVFM_vfModuleId')
551 AaiUtil aaiUriUtil = new AaiUtil(this)
552 String aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
553 logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
555 String endPoint = execution.getVariable("URN_aai_endpoint") + "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8") + "?depth=1"
556 utils.logAudit("AAI endPoint: " + endPoint)
559 RESTConfig config = new RESTConfig(endPoint);
560 def responseData = ''
561 def aaiRequestId = UUID.randomUUID().toString()
562 RESTClient client = new RESTClient(config).
563 addHeader('X-TransactionId', aaiRequestId).
564 addHeader('X-FromAppId', 'MSO').
565 addHeader('Content-Type', 'application/xml').
566 addHeader('Accept','application/xml');
567 logDebug('sending GET to AAI endpoint \'' + endPoint + '\'', isDebugLogEnabled)
568 APIResponse response = client.httpGet()
569 utils.logAudit("createVfModule - invoking httpGet() to AAI")
571 responseData = response.getResponseBodyAsString()
572 if (responseData != null) {
573 logDebug("Received generic VNF data: " + responseData, isDebugLogEnabled)
577 utils.logAudit("createVfModule - queryAAIVfModule Response: " + responseData)
578 utils.logAudit("createVfModule - queryAAIVfModule ResponseCode: " + response.getStatusCode())
580 execution.setVariable('DCVFM_queryAAIVfModuleResponseCode', response.getStatusCode())
581 execution.setVariable('DCVFM_queryAAIVfModuleResponse', responseData)
582 logDebug('Response code:' + response.getStatusCode(), isDebugLogEnabled)
583 logDebug('Response:' + System.lineSeparator() + responseData, isDebugLogEnabled)
584 if (response.getStatusCode() == 200) {
585 // Parse the VNF record from A&AI to find base module info
586 logDebug('Parsing the VNF data to find base module info', isDebugLogEnabled)
587 if (responseData != null) {
588 def vfModulesText = utils.getNodeXml(responseData, "vf-modules")
589 def xmlVfModules= new XmlSlurper().parseText(vfModulesText)
590 def vfModules = xmlVfModules.'**'.findAll {it.name() == "vf-module"}
591 int vfModulesSize = 0
592 for (i in 0..vfModules.size()-1) {
593 def vfModuleXml = groovy.xml.XmlUtil.serialize(vfModules[i])
594 def isBaseVfModule = utils.getNodeText(vfModuleXml, "is-base-vf-module")
596 if (isBaseVfModule == "true") {
597 String baseModuleId = utils.getNodeText1(vfModuleXml, "vf-module-id")
598 execution.setVariable("DCVFM_baseVfModuleId", baseModuleId)
599 logDebug('Received baseVfModuleId: ' + baseModuleId, isDebugLogEnabled)
600 String baseModuleHeatStackId = utils.getNodeText1(vfModuleXml, "heat-stack-id")
601 execution.setVariable("DCVFM_baseVfModuleHeatStackId", baseModuleHeatStackId)
602 logDebug('Received baseVfModuleHeatStackId: ' + baseModuleHeatStackId, isDebugLogEnabled)
607 } catch (Exception ex) {
609 logDebug('Exception occurred while executing AAI GET:' + ex.getMessage(),isDebugLogEnabled)
610 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
612 logDebug('Exited ' + method, isDebugLogEnabled)
613 } catch (BpmnError e) {
615 } catch (Exception e) {
616 logError('Caught exception in ' + method, e)
617 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModule(): ' + e.getMessage())
622 public void preProcessSDNCAssignRequest(Execution execution){
623 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
624 execution.setVariable("prefix", Prefix)
625 logDebug(" ======== STARTED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
626 def vnfId = execution.getVariable("DCVFM_vnfId")
627 def vfModuleId = execution.getVariable("DCVFM_vfModuleId")
628 def serviceInstanceId = execution.getVariable("DCVFM_serviceInstanceId")
629 logDebug("NEW VNF ID: " + vnfId, isDebugLogEnabled)
630 utils.logAudit("NEW VNF ID: " + vnfId)
637 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
638 svcInstId = vfModuleId
641 svcInstId = serviceInstanceId
644 String assignSDNCRequest = buildSDNCRequest(execution, svcInstId, "assign")
646 assignSDNCRequest = utils.formatXml(assignSDNCRequest)
647 execution.setVariable("DCVFM_assignSDNCRequest", assignSDNCRequest)
648 logDebug("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest, isDebugLogEnabled)
649 utils.logAudit("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest)
652 utils.log("ERROR", "Exception Occured Processing preProcessSDNCAssignRequest. Exception is:\n" + e, isDebugLogEnabled)
653 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during prepareProvision Method:\n" + e.getMessage())
655 logDebug("======== COMPLETED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
658 public void preProcessSDNCGetRequest(Execution execution, String element){
659 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
660 String sdncVersion = execution.getVariable("DCVFM_sdncVersion")
661 execution.setVariable("prefix", Prefix)
662 utils.log("DEBUG", " ======== STARTED preProcessSDNCGetRequest Process ======== ", isDebugLogEnabled)
664 def serviceInstanceId = execution.getVariable('DCVFM_serviceInstanceId')
666 String uuid = execution.getVariable('testReqId') // for junits
668 uuid = execution.getVariable("mso-request-id") + "-" + System.currentTimeMillis()
671 def callbackUrl = execution.getVariable("DCVFM_sdncCallbackUrl")
672 utils.logAudit("callbackUrl:" + callbackUrl)
674 def vfModuleId = execution.getVariable('DCVFM_vfModuleId')
677 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
678 svcInstId = vfModuleId
681 svcInstId = serviceInstanceId
685 if (!sdncVersion.equals("1707")) {
686 msoAction = "mobility"
689 msoAction = "vfmodule"
691 // For VNF, serviceOperation (URI for topology GET) will be retrieved from "selflink" element
692 // in the response from GenericGetVnf
693 // For VF Module, in 1707 serviceOperation will be retrieved from "object-path" element
694 // in SDNC Assign Response
695 // For VF Module for older versions, serviceOperation is constructed using vfModuleId
697 String serviceOperation = ""
698 if (element.equals("vnf")) {
699 def vnfQueryResponse = execution.getVariable("DCVFM_vnfQueryResponse")
700 serviceOperation = utils.getNodeText1(vnfQueryResponse, "selflink")
701 utils.log("DEBUG", "VNF - service operation: " + serviceOperation, isDebugLogEnabled)
703 else if (element.equals("vfmodule")) {
704 String response = execution.getVariable("DCVFM_assignSDNCAdapterResponse")
705 utils.logAudit("DCVFM_assignSDNCAdapterResponse is: \n" + response)
707 if (!sdncVersion.equals("1707")) {
708 serviceOperation = "/VNF-API:vnfs/vnf-list/" + vfModuleId
709 utils.log("DEBUG", "VF Module with sdncVersion before 1707 - service operation: " + serviceOperation, isDebugLogEnabled)
712 String data = utils.getNodeXml(response, "response-data")
713 data = data.replaceAll("<", "<")
714 data = data.replaceAll(">", ">")
715 utils.log("DEBUG", "responseData: " + data, isDebugLogEnabled)
716 serviceOperation = utils.getNodeText1(data, "object-path")
717 utils.log("DEBUG", "VF Module with sdncVersion of 1707 - service operation: " + serviceOperation, isDebugLogEnabled)
721 //!!!! TEMPORARY WORKAROUND FOR SDNC REPLICATION ISSUE
724 String SDNCGetRequest =
725 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
726 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
727 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
728 <sdncadapter:RequestHeader>
729 <sdncadapter:RequestId>${uuid}</sdncadapter:RequestId>
730 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
731 <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
732 <sdncadapter:SvcOperation>${serviceOperation}</sdncadapter:SvcOperation>
733 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
734 <sdncadapter:MsoAction>${msoAction}</sdncadapter:MsoAction>
735 </sdncadapter:RequestHeader>
736 <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData>
737 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
739 utils.logAudit("SDNCGetRequest: \n" + SDNCGetRequest)
740 execution.setVariable("DCVFM_getSDNCRequest", SDNCGetRequest)
741 utils.log("DEBUG", "Outgoing GetSDNCRequest is: \n" + SDNCGetRequest, isDebugLogEnabled)
744 utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + e, isDebugLogEnabled)
745 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareProvision Method:\n" + e.getMessage())
747 utils.log("DEBUG", "======== COMPLETED preProcessSDNCGetRequest Process ======== ", isDebugLogEnabled)
751 public void preProcessVNFAdapterRequest(Execution execution) {
752 def method = getClass().getSimpleName() + '.VNFAdapterCreateVfModule(' +
753 'execution=' + execution.getId() +
755 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
756 logDebug('Entered ' + method, isDebugLogEnabled)
758 //def xml = execution.getVariable("DoCreateVfModuleRequest")
759 //logDebug('VNF REQUEST is: ' + xml, isDebugLogEnabled)
763 def cloudSiteId = execution.getVariable("DCVFM_cloudSiteId")
765 def tenantId = execution.getVariable("DCVFM_tenantId")
767 def vnfType = execution.getVariable("DCVFM_vnfType")
769 def vnfName = execution.getVariable("DCVFM_vnfName")
771 def vnfId = execution.getVariable("DCVFM_vnfId")
773 def vfModuleName = execution.getVariable("DCVFM_vfModuleName")
775 def vfModuleModelName = execution.getVariable("DCVFM_vfModuleModelName")
777 def vfModuleId = execution.getVariable("DCVFM_vfModuleId")
779 def vfModuleIndex = execution.getVariable("DCVFM_vfModuleIndex")
781 def requestId = execution.getVariable("DCVFM_requestId")
783 def serviceId = execution.getVariable("DCVFM_serviceId")
785 def serviceInstanceId = execution.getVariable("DCVFM_serviceInstanceId")
787 def backoutOnFailure = execution.getVariable("DCVFM_backoutOnFailure")
789 def volumeGroupId = execution.getVariable("DCVFM_volumeGroupId")
791 def baseVfModuleId = execution.getVariable("DCVFM_baseVfModuleId")
792 // baseVfModuleStackId
793 def baseVfModuleStackId = execution.getVariable("DCVFM_baseVfModuleHeatStackId")
794 // asdcServiceModelVersion
795 def asdcServiceModelVersion = execution.getVariable("DCVFM_asdcServiceModelVersion")
797 def volumeGroupStackId = execution.getVariable("DCVFM_volumeGroupStackId")
798 //modelCustomizationUuid
799 def modelCustomizationUuid = execution.getVariable("DCVFM_modelCustomizationUuid")
801 def messageId = execution.getVariable('mso-request-id') + '-' +
802 System.currentTimeMillis()
804 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
805 def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
807 utils.logAudit("notificationUrl: " + notificationUrl)
808 utils.logAudit("QualifiedHostName: " + useQualifiedHostName)
810 if ('true'.equals(useQualifiedHostName)) {
811 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
814 Map<String, String> vnfParamsMap = execution.getVariable("DCVFM_vnfParamsMap")
816 //Get SDNC Response Data for VnfSubCreate Request
817 String sdncGetResponse = execution.getVariable('DCVFM_getSDNCAdapterResponse')
818 utils.logAudit("sdncGetResponse: " + sdncGetResponse)
820 String vfModuleParams = buildVfModuleParams(vnfParamsMap, sdncGetResponse, vnfId, vnfName,
821 vfModuleId, vfModuleName, vfModuleIndex)
824 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
825 svcInstId = serviceId
828 svcInstId = serviceInstanceId
831 def createVnfARequest = """
832 <createVfModuleRequest>
833 <cloudSiteId>${cloudSiteId}</cloudSiteId>
834 <tenantId>${tenantId}</tenantId>
835 <vnfId>${vnfId}</vnfId>
836 <vnfName>${vnfName}</vnfName>
837 <vfModuleName>${vfModuleName}</vfModuleName>
838 <vfModuleId>${vfModuleId}</vfModuleId>
839 <vnfType>${vnfType}</vnfType>
840 <vfModuleType>${vfModuleModelName}</vfModuleType>
841 <vnfVersion>${asdcServiceModelVersion}</vnfVersion>
842 <modelCustomizationUuid>${modelCustomizationUuid}</modelCustomizationUuid>
843 <requestType></requestType>
844 <volumeGroupId>${volumeGroupId}</volumeGroupId>
845 <volumeGroupStackId>${volumeGroupStackId}</volumeGroupStackId>
846 <baseVfModuleId>${baseVfModuleId}</baseVfModuleId>
847 <baseVfModuleStackId>${baseVfModuleStackId}</baseVfModuleStackId>
848 <skipAAI>true</skipAAI>
849 <backout>${backoutOnFailure}</backout>
850 <failIfExists>true</failIfExists>
855 <requestId>${requestId}</requestId>
856 <serviceInstanceId>${svcInstId}</serviceInstanceId>
858 <messageId>${messageId}</messageId>
859 <notificationUrl>${notificationUrl}</notificationUrl>
860 </createVfModuleRequest>"""
862 utils.logAudit("Create VfModule Request to VNF Adapter : " + createVnfARequest)
863 logDebug("Create VfModule Request to VNF Adapter: " + createVnfARequest, isDebugLogEnabled)
864 execution.setVariable("DCVFM_createVnfARequest", createVnfARequest)
868 * Validates the request, request id and service instance id. If a problem is found,
869 * a WorkflowException is generated and an MSOWorkflowException event is thrown. This
870 * method also sets up the log context for the workflow.
871 * @param execution the execution
872 * @return the validated request
874 public String validateInfraRequest(Execution execution) {
875 def method = getClass().getSimpleName() + '.validateInfraRequest(' +
876 'execution=' + execution.getId() +
878 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
879 logDebug('Entered ' + method, isDebugLogEnabled)
881 String processKey = getProcessKey(execution);
882 def prefix = execution.getVariable("prefix")
884 if (prefix == null) {
885 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " prefix is null")
889 def request = execution.getVariable(prefix + 'Request')
891 if (request == null) {
892 request = execution.getVariable(processKey + 'Request')
894 if (request == null) {
895 request = execution.getVariable('bpmnRequest')
898 setVariable(execution, processKey + 'Request', null);
899 setVariable(execution, 'bpmnRequest', null);
900 setVariable(execution, prefix + 'Request', request);
903 if (request == null) {
904 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request is null")
906 utils.logAudit("DoCreateVfModule Request: " + request)
910 def requestId = execution.getVariable("mso-request-id")
912 if (requestId == null) {
913 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request has no mso-request-id")
916 def serviceInstanceId = execution.getVariable("mso-service-instance-id")
918 if (serviceInstanceId == null) {
919 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request message has no mso-service-instance-id")
922 utils.logContext(requestId, serviceInstanceId)
924 logDebug('Incoming message: ' + System.lineSeparator() + request, isDebugLogEnabled)
925 logDebug('Exited ' + method, isDebugLogEnabled)
927 } catch (BpmnError e) {
929 } catch (Exception e) {
930 logError('Caught exception in ' + method, e)
931 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Invalid Message")
935 public boolean isVolumeGroupIdPresent(Execution execution) {
937 def method = getClass().getSimpleName() + '.isVolumeGroupIdPresent(' +
938 'execution=' + execution.getId() +
940 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
941 logDebug('Entered ' + method, isDebugLogEnabled)
943 def request = execution.getVariable('DoCreateVfModuleRequest')
944 String volumeGroupId = utils.getNodeText1(request, "volume-group-id")
945 if (volumeGroupId == null || volumeGroupId.isEmpty()) {
946 logDebug('No volume group id is present', isDebugLogEnabled)
950 logDebug('Volume group id is present', isDebugLogEnabled)
956 public boolean isVolumeGroupNamePresent(Execution execution) {
958 def method = getClass().getSimpleName() + '.isVolumeGroupNamePresent(' +
959 'execution=' + execution.getId() +
961 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
962 logDebug('Entered ' + method, isDebugLogEnabled)
964 def request = execution.getVariable('DoCreateVfModuleRequest')
965 String volumeGroupName = utils.getNodeText1(request, "volume-group-name")
966 if (volumeGroupName == null || volumeGroupName.isEmpty()) {
967 logDebug('No volume group name is present', isDebugLogEnabled)
971 logDebug('Volume group name is present', isDebugLogEnabled)
977 public String buildSDNCRequest(Execution execution, String svcInstId, String action){
979 String uuid = execution.getVariable('testReqId') // for junits
981 uuid = execution.getVariable("mso-request-id") + "-" + System.currentTimeMillis()
983 def callbackURL = execution.getVariable("DCVFM_sdncCallbackUrl")
984 def requestId = execution.getVariable("DCVFM_requestId")
985 def serviceId = execution.getVariable("DCVFM_serviceId")
986 def vnfType = execution.getVariable("DCVFM_vnfType")
987 def vnfName = execution.getVariable("DCVFM_vnfName")
988 def tenantId = execution.getVariable("DCVFM_tenantId")
989 def source = execution.getVariable("DCVFM_source")
990 def backoutOnFailure = execution.getVariable("DCVFM_backoutOnFailure")
991 def vfModuleId = execution.getVariable("DCVFM_vfModuleId")
992 def vfModuleName = execution.getVariable("DCVFM_vfModuleName")
993 def vfModuleModelName = execution.getVariable("DCVFM_vfModuleModelName")
994 def vnfId = execution.getVariable("DCVFM_vnfId")
995 def cloudSiteId = execution.getVariable("DCVFM_cloudSiteId")
996 def sdncVersion = execution.getVariable("DCVFM_sdncVersion")
997 def serviceModelInfo = execution.getVariable("serviceModelInfo")
998 def vnfModelInfo = execution.getVariable("vnfModelInfo")
999 def vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
1000 String serviceEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(serviceModelInfo)
1001 String vnfEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(vnfModelInfo)
1002 String vfModuleEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(vfModuleModelInfo)
1003 def globalSubscriberId = execution.getVariable("DCVFM_globalSubscriberId")
1004 boolean usePreload = execution.getVariable("DCVFM_usePreload")
1005 String usePreloadToSDNC = usePreload ? "Y" : "N"
1006 def modelCustomizationUuid = execution.getVariable("DCVFM_modelCustomizationUuid")
1007 def modelCustomizationUuidString = ""
1009 modelCustomizationUuidString = "<modelCustomizationUuid>" + modelCustomizationUuid + "</modelCustomizationUuid>"
1012 String sdncVNFParamsXml = ""
1014 if(execution.getVariable("DCVFM_vnfParamsExistFlag") == true){
1015 sdncVNFParamsXml = buildSDNCParamsXml(execution)
1017 sdncVNFParamsXml = ""
1020 String sdncRequest = ""
1022 if (!sdncVersion.equals("1707")) {
1025 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
1026 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
1027 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
1028 <sdncadapter:RequestHeader>
1029 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
1030 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
1031 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
1032 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
1033 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
1034 </sdncadapter:RequestHeader>
1035 <sdncadapterworkflow:SDNCRequestData>
1036 <request-information>
1037 <request-id>${requestId}</request-id>
1038 <request-action>VNFActivateRequest</request-action>
1039 <source>${source}</source>
1041 </request-information>
1042 <service-information>
1043 <service-id>${serviceId}</service-id>
1044 <service-type>${serviceId}</service-type>
1045 <service-instance-id>${svcInstId}</service-instance-id>
1046 <subscriber-name>notsurewecare</subscriber-name>
1047 </service-information>
1048 <vnf-request-information>
1049 <vnf-id>${vfModuleId}</vnf-id>
1050 <vnf-type>${vfModuleModelName}</vnf-type>
1051 <vnf-name>${vfModuleName}</vnf-name>
1052 <generic-vnf-id>${vnfId}</generic-vnf-id>
1053 <generic-vnf-name>${vnfName}</generic-vnf-name>
1054 <generic-vnf-type>${vnfType}</generic-vnf-type>
1055 <aic-cloud-region>${cloudSiteId}</aic-cloud-region>
1056 <tenant>${tenantId}</tenant>
1057 ${modelCustomizationUuidString}
1058 <use-preload>${usePreloadToSDNC}</use-preload>
1060 </vnf-request-information>
1061 </sdncadapterworkflow:SDNCRequestData>
1062 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
1068 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
1069 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
1070 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
1071 <sdncadapter:RequestHeader>
1072 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
1073 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
1074 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
1075 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
1076 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
1077 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
1078 </sdncadapter:RequestHeader>
1079 <sdncadapterworkflow:SDNCRequestData>
1080 <request-information>
1081 <request-id>${requestId}</request-id>
1082 <request-action>CreateVfModuleInstance</request-action>
1083 <source>${source}</source>
1085 </request-information>
1086 <service-information>
1087 <service-id>${serviceId}</service-id>
1088 <subscription-service-type>${serviceId}</subscription-service-type>
1089 ${serviceEcompModelInformation}
1090 <service-instance-id>${svcInstId}</service-instance-id>
1091 <global-customer-id>${globalSubscriberId}</global-customer-id>
1092 </service-information>
1094 <vnf-id>${vnfId}</vnf-id>
1095 <vnf-type>${vnfType}</vnf-type>
1096 ${vnfEcompModelInformation}
1098 <vf-module-information>
1099 <vf-module-id>${vfModuleId}</vf-module-id>
1100 <vf-module-type>${vfModuleModelName}</vf-module-type>
1101 ${vfModuleEcompModelInformation}
1102 </vf-module-information>
1103 <vf-module-request-input>
1104 <vf-module-name>${vfModuleName}</vf-module-name>
1105 <tenant>${tenantId}</tenant>
1106 <aic-cloud-region>${cloudSiteId}</aic-cloud-region>
1108 </vf-module-request-input>
1109 </sdncadapterworkflow:SDNCRequestData>
1110 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
1115 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
1116 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
1117 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
1118 <sdncadapter:RequestHeader>
1119 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
1120 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
1121 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
1122 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
1123 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
1124 </sdncadapter:RequestHeader>
1125 <sdncadapterworkflow:SDNCRequestData>
1126 <request-information>
1127 <request-id>${requestId}</request-id>
1128 <request-action>CreateVfModuleInstance</request-action>
1129 <source>${source}</source>
1131 </request-information>
1132 <service-information>
1133 <service-id>${serviceId}</service-id>
1134 <service-type>${serviceId}</service-type>
1135 ${serviceEcompModelInformation}
1136 <service-instance-id>${svcInstId}</service-instance-id>
1137 <global-customer-id>${globalSubscriberId}</global-customer-id>
1138 </service-information>
1140 <vnf-id>${vnfId}</vnf-id>
1141 <vnf-type>${vnfType}</vnf-type>
1142 ${vnfEcompModelInformation}
1144 <vf-module-information>
1145 <vf-module-id>${vfModuleId}</vf-module-id>
1146 <vf-module-type>${vfModuleModelName}</vf-module-type>
1147 ${vfModuleEcompModelInformation}
1148 </vf-module-information>
1149 <vf-module-request-input>
1150 <vf-module-name>${vfModuleName}</vf-module-name>
1151 <tenant>${tenantId}</tenant>
1152 <aic-cloud-region>${cloudSiteId}</aic-cloud-region>
1154 </vf-module-request-input>
1155 </sdncadapterworkflow:SDNCRequestData>
1156 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
1161 utils.logAudit("sdncRequest: " + sdncRequest)
1166 public void preProcessSDNCActivateRequest(Execution execution) {
1167 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
1168 'execution=' + execution.getId() +
1170 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1171 logDebug('Entered ' + method, isDebugLogEnabled)
1172 execution.setVariable("prefix", Prefix)
1173 logDebug(" ======== STARTED preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
1175 String vnfId = execution.getVariable("DCVFM_vnfId")
1176 String vfModuleId = execution.getVariable("DCVFM_vfModuleId")
1177 String serviceInstanceId = execution.getVariable("DCVFM_serviceInstanceId")
1180 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
1181 svcInstId = vfModuleId
1184 svcInstId = serviceInstanceId
1186 String activateSDNCRequest = buildSDNCRequest(execution, svcInstId, "activate")
1188 execution.setVariable("DCVFM_activateSDNCRequest", activateSDNCRequest)
1189 logDebug("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest, isDebugLogEnabled)
1190 utils.logAudit("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest)
1192 }catch(Exception e){
1193 log.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e, isDebugLogEnabled)
1194 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
1196 logDebug("======== COMPLETED preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
1199 public void postProcessVNFAdapterRequest(Execution execution) {
1200 def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
1201 'execution=' + execution.getId() +
1203 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1204 logDebug('Entered ' + method, isDebugLogEnabled)
1205 execution.setVariable("prefix",Prefix)
1207 logDebug(" *** STARTED postProcessVNFAdapterRequest Process*** ", isDebugLogEnabled)
1209 String vnfResponse = execution.getVariable("DCVFM_createVnfAResponse")
1210 logDebug("VNF Adapter Response is: " + vnfResponse, isDebugLogEnabled)
1211 utils.logAudit("createVnfAResponse is: \n" + vnfResponse)
1213 RollbackData rollbackData = execution.getVariable("RollbackData")
1214 if(vnfResponse != null){
1216 if(vnfResponse.contains("createVfModuleResponse")){
1217 logDebug("Received a Good Response from VNF Adapter for CREATE_VF_MODULE Call.", isDebugLogEnabled)
1218 execution.setVariable("DCVFM_vnfVfModuleCreateCompleted", true)
1219 String heatStackId = utils.getNodeText1(vnfResponse, "vfModuleStackId")
1220 execution.setVariable("DCVFM_heatStackId", heatStackId)
1221 logDebug("Received heat stack id from VNF Adapter: " + heatStackId, isDebugLogEnabled)
1222 rollbackData.put("VFMODULE", "heatstackid", heatStackId)
1223 // Parse vnfOutputs for network_fqdn
1224 if (vnfResponse.contains("vfModuleOutputs")) {
1225 def vfModuleOutputsXml = utils.getNodeXml(vnfResponse, "vfModuleOutputs")
1226 InputSource source = new InputSource(new StringReader(vfModuleOutputsXml));
1227 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
1228 docFactory.setNamespaceAware(true)
1229 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
1230 Document outputsXml = docBuilder.parse(source)
1232 NodeList entries = outputsXml.getElementsByTagNameNS("*", "entry")
1233 List contrailNetworkPolicyFqdnList = []
1234 for (int i = 0; i< entries.getLength(); i++) {
1235 Node node = entries.item(i)
1236 if (node.getNodeType() == Node.ELEMENT_NODE) {
1237 Element element = (Element) node
1238 String key = element.getElementsByTagNameNS("*", "key").item(0).getTextContent()
1239 if (key.equals("contrail-service-instance-fqdn")) {
1240 String contrailServiceInstanceFqdn = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
1241 logDebug("Obtained contrailServiceInstanceFqdn: " + contrailServiceInstanceFqdn, isDebugLogEnabled)
1242 execution.setVariable("DCVFM_contrailServiceInstanceFqdn", contrailServiceInstanceFqdn)
1244 else if (key.endsWith("contrail_network_policy_fqdn")) {
1245 String contrailNetworkPolicyFqdn = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
1246 logDebug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn, isDebugLogEnabled)
1247 contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)
1249 else if (key.equals("oam_management_v4_address")) {
1250 String oamManagementV4Address = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
1251 logDebug("Obtained oamManagementV4Address: " + oamManagementV4Address, isDebugLogEnabled)
1252 execution.setVariable("DCVFM_oamManagementV4Address", oamManagementV4Address)
1254 else if (key.equals("oam_management_v6_address")) {
1255 String oamManagementV6Address = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
1256 logDebug("Obtained oamManagementV6Address: " + oamManagementV6Address, isDebugLogEnabled)
1257 execution.setVariable("DCVFM_oamManagementV6Address", oamManagementV6Address)
1262 if (!contrailNetworkPolicyFqdnList.isEmpty()) {
1263 execution.setVariable("DCVFM_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
1267 logDebug("Received a BAD Response from VNF Adapter for CREATE_VF_MODULE Call.", isDebugLogEnabled)
1268 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
1271 logDebug("Response from VNF Adapter is Null for CREATE_VF_MODULE Call.", isDebugLogEnabled)
1272 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Empty response from VNF Adapter")
1275 rollbackData.put("VFMODULE", "rollbackVnfAdapterCreate", "true")
1276 execution.setVariable("RollbackData", rollbackData)
1278 }catch(BpmnError b){
1280 }catch(Exception e){
1281 logDebug("Internal Error Occured in PostProcess Method", isDebugLogEnabled)
1282 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Internal Error Occured in PostProcess Method")
1284 logDebug(" *** COMPLETED postProcessVnfAdapterResponse Process*** ", isDebugLogEnabled)
1288 public void preProcessUpdateAAIVfModuleRequestOrch(Execution execution) {
1289 def method = getClass().getSimpleName() + '.preProcessUpdateAAIVfModuleRequestOrch(' +
1290 'execution=' + execution.getId() +
1292 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1293 logDebug('Entered ' + method, isDebugLogEnabled)
1294 execution.setVariable("prefix", Prefix)
1295 logDebug(" ======== STARTED preProcessUpdateAAIVfModuleRequestOrch ======== ", isDebugLogEnabled)
1299 //Build UpdateAAIVfModule Request
1300 boolean setContrailServiceInstanceFqdn = false
1301 def contrailServiceInstanceFqdn = execution.getVariable("DCVFM_contrailServiceInstanceFqdn")
1302 if (!contrailServiceInstanceFqdn.equals("")) {
1303 setContrailServiceInstanceFqdn = true
1306 String updateAAIVfModuleRequest = buildUpdateAAIVfModuleRequest(execution, false, true, true, setContrailServiceInstanceFqdn)
1308 updateAAIVfModuleRequest = utils.formatXml(updateAAIVfModuleRequest)
1309 execution.setVariable("DCVFM_updateAAIVfModuleRequest", updateAAIVfModuleRequest)
1310 logDebug("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest, isDebugLogEnabled)
1311 utils.logAudit("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest)
1313 }catch(Exception e){
1314 utils.log("ERROR", "Exception Occured Processing preProcessUpdateAAIVfModuleRequestOrch. Exception is:\n" + e, isDebugLogEnabled)
1315 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessUpdateAAIVfModuleRequestOrch Method:\n" + e.getMessage())
1317 logDebug("======== COMPLETED preProcessUpdateAAIVfModuleRequestOrch ======== ", isDebugLogEnabled)
1321 public void preProcessUpdateAAIVfModuleRequestGroup(Execution execution) {
1322 def method = getClass().getSimpleName() + '.preProcessUpdateAAIVfModuleRequestGroup(' +
1323 'execution=' + execution.getId() +
1325 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1326 logDebug('Entered ' + method, isDebugLogEnabled)
1327 execution.setVariable("prefix", Prefix)
1328 logDebug(" ======== STARTED preProcessUpdateAAIVfModuleRequestGroup ======== ", isDebugLogEnabled)
1332 //Build UpdateAAIVfModule Request
1334 String updateAAIVfModuleRequest = buildUpdateAAIVfModuleRequest(execution, true, false, false, false)
1336 updateAAIVfModuleRequest = utils.formatXml(updateAAIVfModuleRequest)
1337 execution.setVariable("DCVFM_updateAAIVfModuleRequest", updateAAIVfModuleRequest)
1338 logDebug("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest, isDebugLogEnabled)
1339 utils.logAudit("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest)
1341 }catch(Exception e){
1342 utils.log("ERROR", "Exception Occured Processing preProcessUpdateAAIVfModuleRequestGroup. Exception is:\n" + e, isDebugLogEnabled)
1343 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessUpdateAAIVfModuleRequestGroup Method:\n" + e.getMessage())
1345 logDebug("======== COMPLETED preProcessUpdateAAIVfModuleRequestGroup ======== ", isDebugLogEnabled)
1349 public void validateSDNCResponse(Execution execution, String response, String method){
1350 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
1351 execution.setVariable("prefix",Prefix)
1352 logDebug(" *** STARTED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
1354 WorkflowException workflowException = execution.getVariable("WorkflowException")
1355 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1357 utils.logAudit("workflowException: " + workflowException)
1359 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1360 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1362 utils.logAudit("SDNCResponse: " + response)
1364 String sdncResponse = response
1365 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
1366 logDebug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse, isDebugLogEnabled)
1367 RollbackData rollbackData = execution.getVariable("RollbackData")
1369 if(method.equals("assign")){
1370 rollbackData.put("VFMODULE", "rollbackSDNCRequestAssign", "true")
1371 execution.setVariable("CRTGVNF_sdncAssignCompleted", true)
1373 else if (method.equals("activate")) {
1374 rollbackData.put("VFMODULE", "rollbackSDNCRequestActivate", "true")
1376 execution.setVariable("RollbackData", rollbackData)
1378 logDebug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
1379 throw new BpmnError("MSOWorkflowException")
1381 logDebug(" *** COMPLETED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
1384 public void preProcessUpdateAfterCreateRequest(Execution execution){
1385 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
1386 execution.setVariable("prefix", Prefix)
1387 utils.log("DEBUG", " ======== STARTED preProcessRequest Process ======== ", isDebugLogEnabled)
1389 String response = execution.getVariable("DCVFM_assignSDNCAdapterResponse")
1390 utils.logAudit("DCVFM_assignSDNCAdapterResponse: " + response)
1392 String data = utils.getNodeXml(response, "response-data")
1393 data = data.replaceAll("<", "<")
1394 data = data.replaceAll(">", ">")
1395 String vnfId = utils.getNodeText1(data, "vnf-id")
1397 String uuid = execution.getVariable('testReqId') // for junits
1399 uuid = execution.getVariable("mso-request-id") + "-" + System.currentTimeMillis()
1402 String serviceOperation = "/VNF-API:vnfs/vnf-list/" + vnfId
1403 def callbackUrl = execution.getVariable("DCVFM_sdncCallbackUrl")
1404 utils.logAudit("callbackUrl: " + callbackUrl)
1406 String SDNCGetRequest =
1407 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
1408 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
1409 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
1410 <sdncadapter:RequestHeader>
1411 <sdncadapter:RequestId>${uuid}</sdncadapter:RequestId>
1412 <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
1413 <sdncadapter:SvcOperation>${serviceOperation}</sdncadapter:SvcOperation>
1414 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
1415 <sdncadapter:MsoAction>mobility</sdncadapter:MsoAction>
1416 </sdncadapter:RequestHeader>
1417 <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData>
1418 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
1420 execution.setVariable("DCVFM_getSDNCRequest", SDNCGetRequest)
1421 utils.log("DEBUG", "Outgoing GetSDNCRequest is: \n" + SDNCGetRequest, isDebugLogEnabled)
1422 utils.logAudit("Outgoing GetSDNCRequest: " + SDNCGetRequest)
1424 }catch(Exception e){
1425 utils.log("ERROR", "Exception Occured Processing preProcessSDNCGetRequest. Exception is:\n" + e, isDebugLogEnabled)
1426 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareProvision Method:\n" + e.getMessage())
1428 utils.log("DEBUG", "======== COMPLETED preProcessSDNCGetRequest Process ======== ", isDebugLogEnabled)
1431 public String buildUpdateAAIVfModuleRequest(Execution execution, boolean updateVolumeGroupId,
1432 boolean updateOrchestrationStatus, boolean updateHeatStackId, boolean updateContrailFqdn){
1434 def vnfId = execution.getVariable("DCVFM_vnfId")
1435 def vfModuleId = execution.getVariable("DCVFM_vfModuleId")
1436 def volumeGroupIdString = ""
1437 if (updateVolumeGroupId) {
1438 volumeGroupIdString = "<volume-group-id>" + execution.getVariable("DCVFM_volumeGroupId") +
1439 "</volume-group-id>"
1441 def orchestrationStatusString = ""
1442 if (updateOrchestrationStatus) {
1443 orchestrationStatusString = "<orchestration-status>Created</orchestration-status>"
1445 def heatStackIdString = ""
1446 if (updateHeatStackId) {
1447 heatStackIdString = "<heat-stack-id>" + execution.getVariable("DCVFM_heatStackId") + "</heat-stack-id>"
1449 def contrailFqdnString = ""
1450 if (updateContrailFqdn) {
1451 contrailFqdnString = "<contrail-service-instance-fqdn>" + execution.getVariable("DCVFM_contrailServiceInstanceFqdn") +
1452 "</contrail-service-instance-fqdn>"
1455 String updateAAIVfModuleRequest =
1456 """<UpdateAAIVfModuleRequest>
1457 <vnf-id>${vnfId}</vnf-id>
1458 <vf-module-id>${vfModuleId}</vf-module-id>
1459 ${heatStackIdString}
1460 ${orchestrationStatusString}
1461 ${volumeGroupIdString}
1462 ${contrailFqdnString}
1463 </UpdateAAIVfModuleRequest>"""
1465 utils.logAudit("updateAAIVfModule Request: " + updateAAIVfModuleRequest)
1466 return updateAAIVfModuleRequest
1470 public String buildSDNCParamsXml(Execution execution){
1473 StringBuilder sb = new StringBuilder()
1474 Map<String, String> paramsMap = execution.getVariable("DCVFM_vnfParamsMap")
1476 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
1478 String key = entry.getKey();
1479 if(key.endsWith("_network")){
1480 String requestKey = key.substring(0, key.indexOf("_network"))
1481 String requestValue = entry.getValue()
1484 <network-role>{ functx:substring-before-match(data($param/@name), '_network') }</network-role>
1485 <network-name>{ $param/text() }</network-name>
1490 params = sb.append(paramsXml)
1495 public void queryCloudRegion (Execution execution) {
1496 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
1497 execution.setVariable("prefix", Prefix)
1498 utils.log("DEBUG", " ======== STARTED queryCloudRegion ======== ", isDebugLogEnabled)
1501 String cloudRegion = execution.getVariable("DCVFM_cloudSiteId")
1504 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
1505 AaiUtil aaiUtil = new AaiUtil(this)
1506 String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
1507 String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
1508 utils.logAudit("CloudRegion Request: " + queryCloudRegionRequest)
1510 execution.setVariable("DCVFM_queryCloudRegionRequest", queryCloudRegionRequest)
1511 utils.log("DEBUG", "DCVFM_queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest, isDebugLogEnabled)
1513 cloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
1515 if ((cloudRegion != "ERROR")) {
1516 if(execution.getVariable("DCVFM_queryCloudRegionReturnCode") == "404"){
1517 execution.setVariable("DCVFM_cloudRegionForVolume", "AAIAIC25")
1519 execution.setVariable("DCVFM_cloudRegionForVolume", cloudRegion)
1521 execution.setVariable("DCVFM_isCloudRegionGood", true)
1523 String errorMessage = "AAI Query Cloud Region Unsuccessful. AAI Response Code: " + execution.getVariable("DCVFM_queryCloudRegionReturnCode")
1524 utils.log("DEBUG", errorMessage, isDebugLogEnabled)
1525 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1526 execution.setVariable("DCVFM_isCloudRegionGood", false)
1528 utils.log("DEBUG", " is Cloud Region Good: " + execution.getVariable("DCVFM_isCloudRegionGood"), isDebugLogEnabled)
1530 } catch(BpmnError b){
1531 utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugLogEnabled)
1533 }catch (Exception ex) {
1535 String errorMessage = "Bpmn error encountered in CreateVfModule flow. Unexpected Response from AAI - " + ex.getMessage()
1536 utils.log("ERROR", " AAI Query Cloud Region Failed. Exception - " + "\n" + errorMessage, isDebugLogEnabled)
1537 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception occured during queryCloudRegion method")
1543 *This method occurs when an MSOWorkflowException is caught. It logs the
1544 *variables and ensures that the "WorkflowException" Variable is set.
1547 public void processBPMNException(Execution execution){
1548 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1549 execution.setVariable("prefix",Prefix)
1551 utils.log("DEBUG", "Caught a BPMN Exception", isDebugEnabled)
1552 utils.log("DEBUG", "Started processBPMNException Method", isDebugEnabled)
1553 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
1554 if(execution.getVariable("WorkflowException") == null){
1555 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception occured during DoCreateVfModule Sub Process")
1558 }catch(Exception e){
1559 utils.log("DEBUG", "Caught Exception during processBPMNException Method: " + e, isDebugEnabled)
1561 utils.log("DEBUG", "Completed processBPMNException Method", isDebugEnabled)
1564 public void prepareCreateAAIVfModuleVolumeGroupRequest(Execution execution) {
1565 def method = getClass().getSimpleName() + '.prepareCreateAAIVfModuleVolumeGroupRequest(' +
1566 'execution=' + execution.getId() +
1568 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1569 logDebug('Entered ' + method, isDebugLogEnabled)
1570 execution.setVariable("prefix", Prefix)
1571 logDebug(" ======== STARTED prepareCreateAAIVfModuleVolumeGroupRequest ======== ", isDebugLogEnabled)
1575 //Build CreateAAIVfModuleVolumeGroup Request
1577 def vnfId = execution.getVariable("DCVFM_vnfId")
1578 def vfModuleId = execution.getVariable("DCVFM_vfModuleId")
1579 def volumeGroupId = execution.getVariable("DCVFM_volumeGroupId")
1580 //def aicCloudRegion = execution.getVariable("DCVFM_cloudSiteId")
1581 def aicCloudRegion = execution.getVariable("DCVFM_cloudRegionForVolume")
1582 String createAAIVfModuleVolumeGroupRequest =
1583 """<CreateAAIVfModuleVolumeGroupRequest>
1584 <vnf-id>${vnfId}</vnf-id>
1585 <vf-module-id>${vfModuleId}</vf-module-id>
1586 <volume-group-id>${volumeGroupId}</volume-group-id>
1587 <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>
1588 </CreateAAIVfModuleVolumeGroupRequest>"""
1590 createAAIVfModuleVolumeGroupRequest = utils.formatXml(createAAIVfModuleVolumeGroupRequest)
1591 execution.setVariable("DCVFM_createAAIVfModuleVolumeGroupRequest", createAAIVfModuleVolumeGroupRequest)
1592 logDebug("Outgoing CreateAAIVfModuleVolumeGroupRequest is: \n" + createAAIVfModuleVolumeGroupRequest, isDebugLogEnabled)
1593 utils.logAudit("Outgoing CreateAAIVfModuleVolumeGroupRequest is: \n" + createAAIVfModuleVolumeGroupRequest)
1595 }catch(Exception e){
1596 utils.log("ERROR", "Exception Occured Processing prepareCreateAAIVfModuleVolumeGroupRequest. Exception is:\n" + e, isDebugLogEnabled)
1597 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareCreateAAIVfModuleVolumeGroupRequest Method:\n" + e.getMessage())
1599 logDebug("======== COMPLETED prepareCreateAAIVfModuleVolumeGroupRequest ======== ", isDebugLogEnabled)
1603 public void createNetworkPoliciesInAAI(Execution execution) {
1604 def method = getClass().getSimpleName() + '.createNetworkPoliciesInAAI(' +
1605 'execution=' + execution.getId() +
1607 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1608 logDebug('Entered ' + method, isDebugLogEnabled)
1609 execution.setVariable("prefix", Prefix)
1610 logDebug(" ======== STARTED createNetworkPoliciesInAAI ======== ", isDebugLogEnabled)
1614 List fqdnList = execution.getVariable("DCVFM_contrailNetworkPolicyFqdnList")
1615 int fqdnCount = fqdnList.size()
1616 def rollbackData = execution.getVariable("RollbackData")
1618 execution.setVariable("DCVFM_networkPolicyFqdnCount", fqdnCount)
1619 logDebug("DCVFM_networkPolicyFqdnCount - " + fqdnCount, isDebugLogEnabled)
1621 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
1622 AaiUtil aaiUriUtil = new AaiUtil(this)
1623 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
1625 if (fqdnCount > 0) {
1627 // AII loop call over contrail network policy fqdn list
1628 for (i in 0..fqdnCount-1) {
1631 String fqdn = fqdnList[i]
1633 // Query AAI for this network policy FQDN
1635 String queryNetworkPolicyByFqdnAAIRequest = "${aai_endpoint}${aai_uri}?network-policy-fqdn=" + UriUtils.encode(fqdn, "UTF-8")
1636 utils.logAudit("AAI request endpoint: " + queryNetworkPolicyByFqdnAAIRequest)
1638 def aaiRequestId = UUID.randomUUID().toString()
1639 RESTConfig config = new RESTConfig(queryNetworkPolicyByFqdnAAIRequest);
1640 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", aaiRequestId)
1641 .addHeader("X-FromAppId", "MSO")
1642 .addHeader("Content-Type", "application/xml")
1643 .addHeader("Accept","application/xml");
1644 APIResponse response = client.get()
1645 int returnCode = response.getStatusCode()
1646 execution.setVariable("DCVFM_aaiQqueryNetworkPolicyByFqdnReturnCode", returnCode)
1647 logDebug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugLogEnabled)
1649 String aaiResponseAsString = response.getResponseBodyAsString()
1651 if (isOneOf(returnCode, 200, 201)) {
1652 logDebug("The return code is: " + returnCode, isDebugLogEnabled)
1653 // This network policy FQDN already exists in AAI
1654 utils.logAudit(aaiResponseAsString)
1655 execution.setVariable("DCVFM_queryNetworkPolicyByFqdnAAIResponse", aaiResponseAsString)
1656 logDebug(" QueryAAINetworkPolicyByFQDN Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugLogEnabled)
1659 if (returnCode == 404) {
1660 // This network policy FQDN is not in AAI yet. Add it now
1661 logDebug("The return code is: " + returnCode, isDebugLogEnabled)
1662 logDebug("This network policy FQDN is not in AAI yet: " + fqdn, isDebugLogEnabled)
1663 utils.logAudit("Network policy FQDN is not in AAI yet")
1664 // Add the network policy with this FQDN to AAI
1665 def networkPolicyId = UUID.randomUUID().toString()
1666 logDebug("Adding network-policy with network-policy-id " + networkPolicyId, isDebugLogEnabled)
1668 String aaiNamespace = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
1669 logDebug('AAI namespace is: ' + aaiNamespace, isDebugLogEnabled)
1670 String payload = """<network-policy xmlns="${aaiNamespace}">
1671 <network-policy-id>${networkPolicyId}</network-policy-id>
1672 <network-policy-fqdn>${fqdn}</network-policy-fqdn>
1673 <heat-stack-id>${execution.getVariable("DCVFM_heatStackId")}</heat-stack-id>
1674 </network-policy>""" as String
1676 execution.setVariable("DCVFM_addNetworkPolicyAAIRequestBody", payload)
1678 String addNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(networkPolicyId, "UTF-8")
1679 utils.logAudit("AAI request endpoint: " + addNetworkPolicyAAIRequest)
1680 logDebug("AAI request endpoint: " + addNetworkPolicyAAIRequest, isDebugLogEnabled)
1682 def aaiRequestIdPut = UUID.randomUUID().toString()
1683 RESTConfig configPut = new RESTConfig(addNetworkPolicyAAIRequest);
1684 RESTClient clientPut = new RESTClient(configPut).addHeader("X-TransactionId", aaiRequestIdPut)
1685 .addHeader("X-FromAppId", "MSO")
1686 .addHeader("Content-Type", "application/xml")
1687 .addHeader("Accept","application/xml");
1688 logDebug("invoking PUT call to AAI with payload:"+System.lineSeparator()+payload, isDebugLogEnabled)
1689 utils.logAudit("Sending PUT call to AAI with Endpoint /n" + addNetworkPolicyAAIRequest + " with payload /n" + payload)
1690 APIResponse responsePut = clientPut.httpPut(payload)
1691 int returnCodePut = responsePut.getStatusCode()
1692 execution.setVariable("DCVFM_aaiAddNetworkPolicyReturnCode", returnCodePut)
1693 logDebug(" ***** AAI add network policy Response Code, NetworkPolicy #" + counting + " : " + returnCodePut, isDebugLogEnabled)
1695 String aaiResponseAsStringPut = responsePut.getResponseBodyAsString()
1696 if (isOneOf(returnCodePut, 200, 201)) {
1697 logDebug("The return code from adding network policy is: " + returnCodePut, isDebugLogEnabled)
1698 // This network policy was created in AAI successfully
1699 utils.logAudit(aaiResponseAsStringPut)
1700 execution.setVariable("DCVFM_addNetworkPolicyAAIResponse", aaiResponseAsStringPut)
1701 logDebug(" AddAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsStringPut, isDebugLogEnabled)
1702 rollbackData.put("VFMODULE", "rollbackCreateNetworkPoliciesAAI", "true")
1703 rollbackData.put("VFMODULE", "contrailNetworkPolicyFqdn" + i, fqdn)
1704 execution.setVariable("RollbackData", rollbackData)
1708 String putErrorMessage = "Unable to add network-policy to AAI createNetworkPoliciesInAAI - " + returnCodePut
1709 logDebug(putErrorMessage, isDebugLogEnabled)
1710 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, putErrorMessage)
1714 if (aaiResponseAsString.contains("RESTFault")) {
1715 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
1716 execution.setVariable("WorkflowException", exceptionObject)
1717 throw new BpmnError("MSOWorkflowException")
1721 String dataErrorMessage = "Unexpected Response from createNetworkPoliciesInAAI - " + returnCode
1722 logDebug(dataErrorMessage, isDebugLogEnabled)
1723 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1733 logDebug("No contrail network policies to query/create", isDebugLogEnabled)
1737 } catch (BpmnError e) {
1740 } catch (Exception ex) {
1741 String exceptionMessage = "Bpmn error encountered in DoCreateVfModule flow. createNetworkPoliciesInAAI() - " + ex.getMessage()
1742 logDebug(exceptionMessage, isDebugLogEnabled)
1743 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1749 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
1751 * @param execution The flow's execution instance.
1753 public void prepUpdateAAIGenericVnf(Execution execution) {
1754 def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
1755 'execution=' + execution.getId() +
1757 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1758 logDebug('Entered ' + method, isDebugLogEnabled)
1761 def rollbackData = execution.getVariable("RollbackData")
1762 def vnfId = execution.getVariable('DCVFM_vnfId')
1763 def oamManagementV4Address = execution.getVariable("DCVFM_oamManagementV4Address")
1764 def oamManagementV6Address = execution.getVariable("DCVFM_oamManagementV6Address")
1765 def ipv4OamAddressElement = ''
1766 def managementV6AddressElement = ''
1768 if (oamManagementV4Address != null && !oamManagementV4Address.isEmpty()) {
1769 ipv4OamAddressElement = '<ipv4-oam-address>' + oamManagementV4Address + '</ipv4-oam-address>'
1772 if (oamManagementV6Address != null && !oamManagementV6Address.isEmpty()) {
1773 managementV6AddressElement = '<management-v6-address>' + oamManagementV6Address + '</management-v6-address>'
1776 rollbackData.put("VFMODULE", "oamManagementV4Address", oamManagementV4Address)
1779 String updateAAIGenericVnfRequest = """
1780 <UpdateAAIGenericVnfRequest>
1781 <vnf-id>${vnfId}</vnf-id>
1782 ${ipv4OamAddressElement}
1783 ${managementV6AddressElement}
1784 </UpdateAAIGenericVnfRequest>
1786 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
1787 execution.setVariable('DCVM_updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
1788 utils.logAudit("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
1789 logDebug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest, isDebugLogEnabled)
1792 logDebug('Exited ' + method, isDebugLogEnabled)
1793 } catch (BpmnError e) {
1795 } catch (Exception e) {
1796 logError('Caught exception in ' + method, e)
1797 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
1802 * Post process a result from invoking the UpdateAAIGenericVnf subflow.
1804 * @param execution The flow's execution instance.
1806 public void postProcessUpdateAAIGenericVnf(Execution execution) {
1807 def method = getClass().getSimpleName() + '.postProcessUpdateAAIGenericVnf(' +
1808 'execution=' + execution.getId() +
1810 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1811 logDebug('Entered ' + method, isDebugLogEnabled)
1814 def rollbackData = execution.getVariable("RollbackData")
1816 rollbackData.put("VFMODULE", "rollbackUpdateVnfAAI", "true")
1818 def vnfId = execution.getVariable('DCVFM_vnfId')
1819 def oamManagementV4Address = execution.getVariable("DCVFM_oamManagementV4Address")
1820 def oamManagementV6Address = execution.getVariable("DCVFM_oamManagementV6Address")
1821 def ipv4OamAddressElement = ''
1822 def managementV6AddressElement = ''
1824 if (oamManagementV4Address != null && !oamManagementV4Address.isEmpty()) {
1825 rollbackData.put("VFMODULE", "oamManagementV4Address", oamManagementV4Address)
1828 if (oamManagementV6Address != null && !oamManagementV6Address.isEmpty()) {
1829 rollbackData.put("VFMODULE", "oamManagementV6Address", oamManagementV6Address)
1832 execution.setVariable("RollbackData", rollbackData)
1834 logDebug('Exited ' + method, isDebugLogEnabled)
1835 } catch (BpmnError e) {
1837 } catch (Exception e) {
1838 logError('Caught exception in ' + method, e)
1839 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in postProcessUpdateAAIGenericVnf(): ' + e.getMessage())