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
\r
24 import javax.xml.parsers.DocumentBuilderFactory
\r
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
\r
41 import org.w3c.dom.Document
\r
42 import org.w3c.dom.Element
\r
43 import org.w3c.dom.NamedNodeMap
\r
44 import org.w3c.dom.Node
\r
45 import org.w3c.dom.NodeList
46 import org.xml.sax.InputSource
\r
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, "modelVersion"))
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
683 // For VNF, serviceOperation (URI for topology GET) will be retrieved from "selflink" element
684 // in the response from GenericGetVnf
685 // For VF Module, in 1707 serviceOperation will be retrieved from "object-path" element
686 // in SDNC Assign Response
687 // For VF Module for older versions, serviceOperation is constructed using vfModuleId
689 String serviceOperation = ""
690 if (element.equals("vnf")) {
691 def vnfQueryResponse = execution.getVariable("DCVFM_vnfQueryResponse")
692 serviceOperation = utils.getNodeText1(vnfQueryResponse, "selflink")
693 utils.log("DEBUG", "VNF - service operation: " + serviceOperation, isDebugLogEnabled)
695 else if (element.equals("vfmodule")) {
696 String response = execution.getVariable("DCVFM_assignSDNCAdapterResponse")
697 utils.logAudit("DCVFM_assignSDNCAdapterResponse is: \n" + response)
699 if (!sdncVersion.equals("1707")) {
700 serviceOperation = "/VNF-API:vnfs/vnf-list/" + vfModuleId
701 utils.log("DEBUG", "VF Module with sdncVersion before 1707 - service operation: " + serviceOperation, isDebugLogEnabled)
704 String data = utils.getNodeXml(response, "response-data")
705 data = data.replaceAll("<", "<")
706 data = data.replaceAll(">", ">")
707 utils.log("DEBUG", "responseData: " + data, isDebugLogEnabled)
708 serviceOperation = utils.getNodeText1(data, "object-path")
709 utils.log("DEBUG", "VF Module with sdncVersion of 1707 - service operation: " + serviceOperation, isDebugLogEnabled)
713 //!!!! TEMPORARY WORKAROUND FOR SDNC REPLICATION ISSUE
716 String SDNCGetRequest =
717 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
718 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
719 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
720 <sdncadapter:RequestHeader>
721 <sdncadapter:RequestId>${uuid}</sdncadapter:RequestId>
722 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
723 <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
724 <sdncadapter:SvcOperation>${serviceOperation}</sdncadapter:SvcOperation>
725 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
726 <sdncadapter:MsoAction>mobility</sdncadapter:MsoAction>
727 </sdncadapter:RequestHeader>
728 <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData>
729 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
731 utils.logAudit("SDNCGetRequest: \n" + SDNCGetRequest)
732 execution.setVariable("DCVFM_getSDNCRequest", SDNCGetRequest)
733 utils.log("DEBUG", "Outgoing GetSDNCRequest is: \n" + SDNCGetRequest, isDebugLogEnabled)
736 utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + e, isDebugLogEnabled)
737 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareProvision Method:\n" + e.getMessage())
739 utils.log("DEBUG", "======== COMPLETED preProcessSDNCGetRequest Process ======== ", isDebugLogEnabled)
743 public void preProcessVNFAdapterRequest(Execution execution) {
744 def method = getClass().getSimpleName() + '.VNFAdapterCreateVfModule(' +
745 'execution=' + execution.getId() +
747 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
748 logDebug('Entered ' + method, isDebugLogEnabled)
750 //def xml = execution.getVariable("DoCreateVfModuleRequest")
751 //logDebug('VNF REQUEST is: ' + xml, isDebugLogEnabled)
755 def cloudSiteId = execution.getVariable("DCVFM_cloudSiteId")
757 def tenantId = execution.getVariable("DCVFM_tenantId")
759 def vnfType = execution.getVariable("DCVFM_vnfType")
761 def vnfName = execution.getVariable("DCVFM_vnfName")
763 def vnfId = execution.getVariable("DCVFM_vnfId")
765 def vfModuleName = execution.getVariable("DCVFM_vfModuleName")
767 def vfModuleModelName = execution.getVariable("DCVFM_vfModuleModelName")
769 def vfModuleId = execution.getVariable("DCVFM_vfModuleId")
771 def vfModuleIndex = execution.getVariable("DCVFM_vfModuleIndex")
773 def requestId = execution.getVariable("DCVFM_requestId")
775 def serviceId = execution.getVariable("DCVFM_serviceId")
777 def serviceInstanceId = execution.getVariable("DCVFM_serviceInstanceId")
779 def backoutOnFailure = execution.getVariable("DCVFM_backoutOnFailure")
781 def volumeGroupId = execution.getVariable("DCVFM_volumeGroupId")
783 def baseVfModuleId = execution.getVariable("DCVFM_baseVfModuleId")
784 // baseVfModuleStackId
785 def baseVfModuleStackId = execution.getVariable("DCVFM_baseVfModuleHeatStackId")
786 // asdcServiceModelVersion
787 def asdcServiceModelVersion = execution.getVariable("DCVFM_asdcServiceModelVersion")
789 def volumeGroupStackId = execution.getVariable("DCVFM_volumeGroupStackId")
790 //modelCustomizationUuid
791 def modelCustomizationUuid = execution.getVariable("DCVFM_modelCustomizationUuid")
793 def messageId = execution.getVariable('mso-request-id') + '-' +
794 System.currentTimeMillis()
796 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
797 def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
799 utils.logAudit("notificationUrl: " + notificationUrl)
800 utils.logAudit("QualifiedHostName: " + useQualifiedHostName)
802 if ('true'.equals(useQualifiedHostName)) {
803 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
806 Map<String, String> vnfParamsMap = execution.getVariable("DCVFM_vnfParamsMap")
808 //Get SDNC Response Data for VnfSubCreate Request
809 String sdncGetResponse = execution.getVariable('DCVFM_getSDNCAdapterResponse')
810 utils.logAudit("sdncGetResponse: " + sdncGetResponse)
812 String vfModuleParams = buildVfModuleParams(vnfParamsMap, sdncGetResponse, vnfId, vnfName,
813 vfModuleId, vfModuleName, vfModuleIndex)
816 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
817 svcInstId = serviceId
820 svcInstId = serviceInstanceId
823 def createVnfARequest = """
824 <createVfModuleRequest>
825 <cloudSiteId>${cloudSiteId}</cloudSiteId>
826 <tenantId>${tenantId}</tenantId>
827 <vnfId>${vnfId}</vnfId>
828 <vnfName>${vnfName}</vnfName>
829 <vfModuleName>${vfModuleName}</vfModuleName>
830 <vfModuleId>${vfModuleId}</vfModuleId>
831 <vnfType>${vnfType}</vnfType>
832 <vfModuleType>${vfModuleModelName}</vfModuleType>
833 <vnfVersion>${asdcServiceModelVersion}</vnfVersion>
834 <modelCustomizationUuid>${modelCustomizationUuid}</modelCustomizationUuid>
835 <requestType></requestType>
836 <volumeGroupId>${volumeGroupId}</volumeGroupId>
837 <volumeGroupStackId>${volumeGroupStackId}</volumeGroupStackId>
838 <baseVfModuleId>${baseVfModuleId}</baseVfModuleId>
839 <baseVfModuleStackId>${baseVfModuleStackId}</baseVfModuleStackId>
840 <skipAAI>true</skipAAI>
841 <backout>${backoutOnFailure}</backout>
842 <failIfExists>true</failIfExists>
847 <requestId>${requestId}</requestId>
848 <serviceInstanceId>${svcInstId}</serviceInstanceId>
850 <messageId>${messageId}</messageId>
851 <notificationUrl>${notificationUrl}</notificationUrl>
852 </createVfModuleRequest>"""
854 utils.logAudit("Create VfModule Request to VNF Adapter : " + createVnfARequest)
855 logDebug("Create VfModule Request to VNF Adapter: " + createVnfARequest, isDebugLogEnabled)
856 execution.setVariable("DCVFM_createVnfARequest", createVnfARequest)
860 * Validates the request, request id and service instance id. If a problem is found,
861 * a WorkflowException is generated and an MSOWorkflowException event is thrown. This
862 * method also sets up the log context for the workflow.
863 * @param execution the execution
864 * @return the validated request
866 public String validateInfraRequest(Execution execution) {
867 def method = getClass().getSimpleName() + '.validateInfraRequest(' +
868 'execution=' + execution.getId() +
870 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
871 logDebug('Entered ' + method, isDebugLogEnabled)
873 String processKey = getProcessKey(execution);
874 def prefix = execution.getVariable("prefix")
876 if (prefix == null) {
877 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " prefix is null")
881 def request = execution.getVariable(prefix + 'Request')
883 if (request == null) {
884 request = execution.getVariable(processKey + 'Request')
886 if (request == null) {
887 request = execution.getVariable('bpmnRequest')
890 setVariable(execution, processKey + 'Request', null);
891 setVariable(execution, 'bpmnRequest', null);
892 setVariable(execution, prefix + 'Request', request);
895 if (request == null) {
896 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request is null")
898 utils.logAudit("DoCreateVfModule Request: " + request)
902 def requestId = execution.getVariable("mso-request-id")
904 if (requestId == null) {
905 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request has no mso-request-id")
\r
908 def serviceInstanceId = execution.getVariable("mso-service-instance-id")
910 if (serviceInstanceId == null) {
911 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request message has no mso-service-instance-id")
\r
914 utils.logContext(requestId, serviceInstanceId)
916 logDebug('Incoming message: ' + System.lineSeparator() + request, isDebugLogEnabled)
917 logDebug('Exited ' + method, isDebugLogEnabled)
919 } catch (BpmnError e) {
921 } catch (Exception e) {
922 logError('Caught exception in ' + method, e)
923 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Invalid Message")
927 public boolean isVolumeGroupIdPresent(Execution execution) {
929 def method = getClass().getSimpleName() + '.isVolumeGroupIdPresent(' +
930 'execution=' + execution.getId() +
932 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
933 logDebug('Entered ' + method, isDebugLogEnabled)
935 def request = execution.getVariable('DoCreateVfModuleRequest')
936 String volumeGroupId = utils.getNodeText1(request, "volume-group-id")
937 if (volumeGroupId == null || volumeGroupId.isEmpty()) {
938 logDebug('No volume group id is present', isDebugLogEnabled)
942 logDebug('Volume group id is present', isDebugLogEnabled)
948 public boolean isVolumeGroupNamePresent(Execution execution) {
950 def method = getClass().getSimpleName() + '.isVolumeGroupNamePresent(' +
951 'execution=' + execution.getId() +
953 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
954 logDebug('Entered ' + method, isDebugLogEnabled)
956 def request = execution.getVariable('DoCreateVfModuleRequest')
957 String volumeGroupName = utils.getNodeText1(request, "volume-group-name")
958 if (volumeGroupName == null || volumeGroupName.isEmpty()) {
959 logDebug('No volume group name is present', isDebugLogEnabled)
963 logDebug('Volume group name is present', isDebugLogEnabled)
969 public String buildSDNCRequest(Execution execution, String svcInstId, String action){
971 String uuid = execution.getVariable('testReqId') // for junits
973 uuid = execution.getVariable("mso-request-id") + "-" + System.currentTimeMillis()
975 def callbackURL = execution.getVariable("DCVFM_sdncCallbackUrl")
976 def requestId = execution.getVariable("DCVFM_requestId")
977 def serviceId = execution.getVariable("DCVFM_serviceId")
978 def vnfType = execution.getVariable("DCVFM_vnfType")
979 def vnfName = execution.getVariable("DCVFM_vnfName")
980 def tenantId = execution.getVariable("DCVFM_tenantId")
981 def source = execution.getVariable("DCVFM_source")
982 def backoutOnFailure = execution.getVariable("DCVFM_backoutOnFailure")
983 def vfModuleId = execution.getVariable("DCVFM_vfModuleId")
984 def vfModuleName = execution.getVariable("DCVFM_vfModuleName")
985 def vfModuleModelName = execution.getVariable("DCVFM_vfModuleModelName")
986 def vnfId = execution.getVariable("DCVFM_vnfId")
987 def cloudSiteId = execution.getVariable("DCVFM_cloudSiteId")
988 def sdncVersion = execution.getVariable("DCVFM_sdncVersion")
989 def serviceModelInfo = execution.getVariable("serviceModelInfo")
990 def vnfModelInfo = execution.getVariable("vnfModelInfo")
991 def vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
992 String serviceEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(serviceModelInfo)
993 String vnfEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(vnfModelInfo)
994 String vfModuleEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(vfModuleModelInfo)
995 def globalSubscriberId = execution.getVariable("DCVFM_globalSubscriberId")
996 boolean usePreload = execution.getVariable("DCVFM_usePreload")
997 String usePreloadToSDNC = usePreload ? "Y" : "N"
998 def modelCustomizationUuid = execution.getVariable("DCVFM_modelCustomizationUuid")
999 def modelCustomizationUuidString = ""
1001 modelCustomizationUuidString = "<modelCustomizationUuid>" + modelCustomizationUuid + "</modelCustomizationUuid>"
1004 String sdncVNFParamsXml = ""
1006 if(execution.getVariable("DCVFM_vnfParamsExistFlag") == true){
1007 sdncVNFParamsXml = buildSDNCParamsXml(execution)
1009 sdncVNFParamsXml = ""
1012 String sdncRequest = ""
1014 if (!sdncVersion.equals("1707")) {
1017 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
1018 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
1019 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
\r
1020 <sdncadapter:RequestHeader>
1021 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
1022 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
1023 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
1024 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
1025 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
1026 </sdncadapter:RequestHeader>
1027 <sdncadapterworkflow:SDNCRequestData>
1028 <request-information>
1029 <request-id>${requestId}</request-id>
1030 <request-action>VNFActivateRequest</request-action>
1031 <source>${source}</source>
1033 </request-information>
1034 <service-information>
1035 <service-id>${serviceId}</service-id>
1036 <service-type>${serviceId}</service-type>
1037 <service-instance-id>${svcInstId}</service-instance-id>
1038 <subscriber-name>notsurewecare</subscriber-name>
1039 </service-information>
1040 <vnf-request-information>
1041 <vnf-id>${vfModuleId}</vnf-id>
1042 <vnf-type>${vfModuleModelName}</vnf-type>
1043 <vnf-name>${vfModuleName}</vnf-name>
1044 <generic-vnf-id>${vnfId}</generic-vnf-id>
1045 <generic-vnf-name>${vnfName}</generic-vnf-name>
1046 <generic-vnf-type>${vnfType}</generic-vnf-type>
1047 <aic-cloud-region>${cloudSiteId}</aic-cloud-region>
1048 <tenant>${tenantId}</tenant>
1049 ${modelCustomizationUuidString}
1050 <use-preload>${usePreloadToSDNC}</use-preload>
1052 </vnf-request-information>
1053 </sdncadapterworkflow:SDNCRequestData>
1054 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
1060 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
1061 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
1062 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
\r
1063 <sdncadapter:RequestHeader>
1064 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
1065 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
1066 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
1067 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
1068 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
1069 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
1070 </sdncadapter:RequestHeader>
1071 <sdncadapterworkflow:SDNCRequestData>
1072 <request-information>
1073 <request-id>${requestId}</request-id>
1074 <request-action>CreateVfModuleInstance</request-action>
1075 <source>${source}</source>
1077 </request-information>
1078 <service-information>
1079 <service-id>${serviceId}</service-id>
1080 <subscription-service-type>${serviceId}</subscription-service-type>
1081 ${serviceEcompModelInformation}
1082 <service-instance-id>${svcInstId}</service-instance-id>
1083 <global-customer-id>${globalSubscriberId}</global-customer-id>
1084 </service-information>
1085 <vnf-request-information>
1086 <vnf-type>${vfModuleModelName}</vnf-type>
1087 </vnf-request-information>
1089 <vnf-id>${vnfId}</vnf-id>
1090 <vnf-type>${vnfType}</vnf-type>
1091 ${vnfEcompModelInformation}
1093 <vf-module-information>
1094 <vf-module-id>${vfModuleId}</vf-module-id>
1095 <vf-module-type>${vfModuleModelName}</vf-module-type>
1096 ${vfModuleEcompModelInformation}
1097 </vf-module-information>
1098 <vf-module-request-input>
1099 <request-version>${sdncVersion}</request-version>
1100 <vf-module-name>${vfModuleName}</vf-module-name>
1101 <tenant>${tenantId}</tenant>
1102 <aic-cloud-region>${cloudSiteId}</aic-cloud-region>
1104 </vf-module-request-input>
1105 </sdncadapterworkflow:SDNCRequestData>
1106 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
1111 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
\r
1112 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
\r
1113 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
\r
1114 <sdncadapter:RequestHeader>
1115 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
1116 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
1117 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
1118 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
1119 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
1120 </sdncadapter:RequestHeader>
1121 <sdncadapterworkflow:SDNCRequestData>
1122 <request-information>
1123 <request-id>${requestId}</request-id>
1124 <request-action>CreateVfModuleInstance</request-action>
1125 <source>${source}</source>
1127 </request-information>
1128 <service-information>
1129 <service-id>${serviceId}</service-id>
1130 <service-type>${serviceId}</service-type>
1131 ${serviceEcompModelInformation}
1132 <service-instance-id>${svcInstId}</service-instance-id>
1133 <global-customer-id>${globalSubscriberId}</global-customer-id>
1134 </service-information>
1136 <vnf-id>${vnfId}</vnf-id>
1137 <vnf-type>${vnfType}</vnf-type>
1138 ${vnfEcompModelInformation}
1140 <vf-module-information>
1141 <vf-module-id>${vfModuleId}</vf-module-id>
1142 <vf-module-type>${vfModuleModelName}</vf-module-type>
1143 ${vfModuleEcompModelInformation}
1144 </vf-module-information>
1145 <vf-module-request-input>
1146 <request-version>${sdncVersion}</request-version>
1147 <vf-module-name>${vfModuleName}</vf-module-name>
1148 <tenant>${tenantId}</tenant>
1149 <aic-cloud-region>${cloudSiteId}</aic-cloud-region>
1151 </vf-module-request-input>
1152 </sdncadapterworkflow:SDNCRequestData>
1153 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
1158 utils.logAudit("sdncRequest: " + sdncRequest)
1163 public void preProcessSDNCActivateRequest(Execution execution) {
1164 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
1165 'execution=' + execution.getId() +
1167 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1168 logDebug('Entered ' + method, isDebugLogEnabled)
1169 execution.setVariable("prefix", Prefix)
1170 logDebug(" ======== STARTED preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
1172 String vnfId = execution.getVariable("DCVFM_vnfId")
1173 String vfModuleId = execution.getVariable("DCVFM_vfModuleId")
1174 String serviceInstanceId = execution.getVariable("DCVFM_serviceInstanceId")
1177 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
1178 svcInstId = vfModuleId
1181 svcInstId = serviceInstanceId
1183 String activateSDNCRequest = buildSDNCRequest(execution, svcInstId, "activate")
1185 execution.setVariable("DCVFM_activateSDNCRequest", activateSDNCRequest)
1186 logDebug("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest, isDebugLogEnabled)
1187 utils.logAudit("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest)
1189 }catch(Exception e){
1190 log.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e, isDebugLogEnabled)
1191 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
1193 logDebug("======== COMPLETED preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
1196 public void postProcessVNFAdapterRequest(Execution execution) {
1197 def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
1198 'execution=' + execution.getId() +
1200 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1201 logDebug('Entered ' + method, isDebugLogEnabled)
1202 execution.setVariable("prefix",Prefix)
1204 logDebug(" *** STARTED postProcessVNFAdapterRequest Process*** ", isDebugLogEnabled)
1206 String vnfResponse = execution.getVariable("DCVFM_createVnfAResponse")
1207 logDebug("VNF Adapter Response is: " + vnfResponse, isDebugLogEnabled)
1208 utils.logAudit("createVnfAResponse is: \n" + vnfResponse)
1210 RollbackData rollbackData = execution.getVariable("RollbackData")
1211 if(vnfResponse != null){
1213 if(vnfResponse.contains("createVfModuleResponse")){
1214 logDebug("Received a Good Response from VNF Adapter for CREATE_VF_MODULE Call.", isDebugLogEnabled)
1215 execution.setVariable("DCVFM_vnfVfModuleCreateCompleted", true)
1216 String heatStackId = utils.getNodeText1(vnfResponse, "vfModuleStackId")
1217 execution.setVariable("DCVFM_heatStackId", heatStackId)
1218 logDebug("Received heat stack id from VNF Adapter: " + heatStackId, isDebugLogEnabled)
1219 rollbackData.put("VFMODULE", "heatstackid", heatStackId)
1220 // Parse vnfOutputs for network_fqdn
1221 if (vnfResponse.contains("vfModuleOutputs")) {
1222 def vfModuleOutputsXml = utils.getNodeXml(vnfResponse, "vfModuleOutputs")
1223 InputSource source = new InputSource(new StringReader(vfModuleOutputsXml));
1224 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
1225 docFactory.setNamespaceAware(true)
1226 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
1227 Document outputsXml = docBuilder.parse(source)
1229 NodeList entries = outputsXml.getElementsByTagNameNS("*", "entry")
1230 List contrailNetworkPolicyFqdnList = []
1231 for (int i = 0; i< entries.getLength(); i++) {
1232 Node node = entries.item(i)
1233 if (node.getNodeType() == Node.ELEMENT_NODE) {
1234 Element element = (Element) node
1235 String key = element.getElementsByTagNameNS("*", "key").item(0).getTextContent()
1236 if (key.equals("contrail-service-instance-fqdn")) {
1237 String contrailServiceInstanceFqdn = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
1238 logDebug("Obtained contrailServiceInstanceFqdn: " + contrailServiceInstanceFqdn, isDebugLogEnabled)
1239 execution.setVariable("DCVFM_contrailServiceInstanceFqdn", contrailServiceInstanceFqdn)
1241 else if (key.endsWith("contrail_network_policy_fqdn")) {
1242 String contrailNetworkPolicyFqdn = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
1243 logDebug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn, isDebugLogEnabled)
1244 contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)
1246 else if (key.equals("oam_management_v4_address")) {
1247 String oamManagementV4Address = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
1248 logDebug("Obtained oamManagementV4Address: " + oamManagementV4Address, isDebugLogEnabled)
1249 execution.setVariable("DCVFM_oamManagementV4Address", oamManagementV4Address)
1251 else if (key.equals("oam_management_v6_address")) {
1252 String oamManagementV6Address = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
1253 logDebug("Obtained oamManagementV6Address: " + oamManagementV6Address, isDebugLogEnabled)
1254 execution.setVariable("DCVFM_oamManagementV6Address", oamManagementV6Address)
1259 if (!contrailNetworkPolicyFqdnList.isEmpty()) {
1260 execution.setVariable("DCVFM_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
1264 logDebug("Received a BAD Response from VNF Adapter for CREATE_VF_MODULE Call.", isDebugLogEnabled)
1265 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
1268 logDebug("Response from VNF Adapter is Null for CREATE_VF_MODULE Call.", isDebugLogEnabled)
1269 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Empty response from VNF Adapter")
1272 rollbackData.put("VFMODULE", "rollbackVnfAdapterCreate", "true")
1273 execution.setVariable("RollbackData", rollbackData)
1275 }catch(BpmnError b){
1277 }catch(Exception e){
1278 logDebug("Internal Error Occured in PostProcess Method", isDebugLogEnabled)
1279 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Internal Error Occured in PostProcess Method")
1281 logDebug(" *** COMPLETED postProcessVnfAdapterResponse Process*** ", isDebugLogEnabled)
1285 public void preProcessUpdateAAIVfModuleRequestOrch(Execution execution) {
1286 def method = getClass().getSimpleName() + '.preProcessUpdateAAIVfModuleRequestOrch(' +
1287 'execution=' + execution.getId() +
1289 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1290 logDebug('Entered ' + method, isDebugLogEnabled)
1291 execution.setVariable("prefix", Prefix)
1292 logDebug(" ======== STARTED preProcessUpdateAAIVfModuleRequestOrch ======== ", isDebugLogEnabled)
1296 //Build UpdateAAIVfModule Request
1297 boolean setContrailServiceInstanceFqdn = false
1298 def contrailServiceInstanceFqdn = execution.getVariable("DCVFM_contrailServiceInstanceFqdn")
1299 if (!contrailServiceInstanceFqdn.equals("")) {
1300 setContrailServiceInstanceFqdn = true
1303 String updateAAIVfModuleRequest = buildUpdateAAIVfModuleRequest(execution, false, true, true, setContrailServiceInstanceFqdn)
1305 updateAAIVfModuleRequest = utils.formatXml(updateAAIVfModuleRequest)
1306 execution.setVariable("DCVFM_updateAAIVfModuleRequest", updateAAIVfModuleRequest)
1307 logDebug("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest, isDebugLogEnabled)
1308 utils.logAudit("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest)
1310 }catch(Exception e){
1311 utils.log("ERROR", "Exception Occured Processing preProcessUpdateAAIVfModuleRequestOrch. Exception is:\n" + e, isDebugLogEnabled)
1312 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessUpdateAAIVfModuleRequestOrch Method:\n" + e.getMessage())
1314 logDebug("======== COMPLETED preProcessUpdateAAIVfModuleRequestOrch ======== ", isDebugLogEnabled)
1318 public void preProcessUpdateAAIVfModuleRequestGroup(Execution execution) {
1319 def method = getClass().getSimpleName() + '.preProcessUpdateAAIVfModuleRequestGroup(' +
1320 'execution=' + execution.getId() +
1322 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1323 logDebug('Entered ' + method, isDebugLogEnabled)
1324 execution.setVariable("prefix", Prefix)
1325 logDebug(" ======== STARTED preProcessUpdateAAIVfModuleRequestGroup ======== ", isDebugLogEnabled)
1329 //Build UpdateAAIVfModule Request
1331 String updateAAIVfModuleRequest = buildUpdateAAIVfModuleRequest(execution, true, false, false, false)
1333 updateAAIVfModuleRequest = utils.formatXml(updateAAIVfModuleRequest)
1334 execution.setVariable("DCVFM_updateAAIVfModuleRequest", updateAAIVfModuleRequest)
1335 logDebug("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest, isDebugLogEnabled)
1336 utils.logAudit("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest)
1338 }catch(Exception e){
1339 utils.log("ERROR", "Exception Occured Processing preProcessUpdateAAIVfModuleRequestGroup. Exception is:\n" + e, isDebugLogEnabled)
1340 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessUpdateAAIVfModuleRequestGroup Method:\n" + e.getMessage())
1342 logDebug("======== COMPLETED preProcessUpdateAAIVfModuleRequestGroup ======== ", isDebugLogEnabled)
1346 public void validateSDNCResponse(Execution execution, String response, String method){
1347 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
1348 execution.setVariable("prefix",Prefix)
1349 logDebug(" *** STARTED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
1351 WorkflowException workflowException = execution.getVariable("WorkflowException")
1352 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1354 utils.logAudit("workflowException: " + workflowException)
1356 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1357 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1359 utils.logAudit("SDNCResponse: " + response)
1361 String sdncResponse = response
1362 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
1363 logDebug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse, isDebugLogEnabled)
1364 RollbackData rollbackData = execution.getVariable("RollbackData")
1366 if(method.equals("assign")){
1367 rollbackData.put("VFMODULE", "rollbackSDNCRequestAssign", "true")
1368 execution.setVariable("CRTGVNF_sdncAssignCompleted", true)
1370 else if (method.equals("activate")) {
1371 rollbackData.put("VFMODULE", "rollbackSDNCRequestActivate", "true")
1373 execution.setVariable("RollbackData", rollbackData)
1375 logDebug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
1376 throw new BpmnError("MSOWorkflowException")
1378 logDebug(" *** COMPLETED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
1381 public void preProcessUpdateAfterCreateRequest(Execution execution){
1382 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
1383 execution.setVariable("prefix", Prefix)
1384 utils.log("DEBUG", " ======== STARTED preProcessRequest Process ======== ", isDebugLogEnabled)
1386 String response = execution.getVariable("DCVFM_assignSDNCAdapterResponse")
1387 utils.logAudit("DCVFM_assignSDNCAdapterResponse: " + response)
1389 String data = utils.getNodeXml(response, "response-data")
1390 data = data.replaceAll("<", "<")
1391 data = data.replaceAll(">", ">")
1392 String vnfId = utils.getNodeText1(data, "vnf-id")
1394 String uuid = execution.getVariable('testReqId') // for junits
1396 uuid = execution.getVariable("mso-request-id") + "-" + System.currentTimeMillis()
1399 String serviceOperation = "/VNF-API:vnfs/vnf-list/" + vnfId
1400 def callbackUrl = execution.getVariable("DCVFM_sdncCallbackUrl")
1401 utils.logAudit("callbackUrl: " + callbackUrl)
1403 String SDNCGetRequest =
1404 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
1405 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
1406 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
1407 <sdncadapter:RequestHeader>
1408 <sdncadapter:RequestId>${uuid}</sdncadapter:RequestId>
1409 <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
1410 <sdncadapter:SvcOperation>${serviceOperation}</sdncadapter:SvcOperation>
1411 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
1412 <sdncadapter:MsoAction>mobility</sdncadapter:MsoAction>
1413 </sdncadapter:RequestHeader>
1414 <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData>
1415 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
1417 execution.setVariable("DCVFM_getSDNCRequest", SDNCGetRequest)
1418 utils.log("DEBUG", "Outgoing GetSDNCRequest is: \n" + SDNCGetRequest, isDebugLogEnabled)
1419 utils.logAudit("Outgoing GetSDNCRequest: " + SDNCGetRequest)
1421 }catch(Exception e){
1422 utils.log("ERROR", "Exception Occured Processing preProcessSDNCGetRequest. Exception is:\n" + e, isDebugLogEnabled)
1423 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareProvision Method:\n" + e.getMessage())
1425 utils.log("DEBUG", "======== COMPLETED preProcessSDNCGetRequest Process ======== ", isDebugLogEnabled)
1428 public String buildUpdateAAIVfModuleRequest(Execution execution, boolean updateVolumeGroupId,
1429 boolean updateOrchestrationStatus, boolean updateHeatStackId, boolean updateContrailFqdn){
1431 def vnfId = execution.getVariable("DCVFM_vnfId")
1432 def vfModuleId = execution.getVariable("DCVFM_vfModuleId")
1433 def volumeGroupIdString = ""
1434 if (updateVolumeGroupId) {
1435 volumeGroupIdString = "<volume-group-id>" + execution.getVariable("DCVFM_volumeGroupId") +
1436 "</volume-group-id>"
1438 def orchestrationStatusString = ""
1439 if (updateOrchestrationStatus) {
1440 orchestrationStatusString = "<orchestration-status>Created</orchestration-status>"
1442 def heatStackIdString = ""
1443 if (updateHeatStackId) {
1444 heatStackIdString = "<heat-stack-id>" + execution.getVariable("DCVFM_heatStackId") + "</heat-stack-id>"
1446 def contrailFqdnString = ""
1447 if (updateContrailFqdn) {
1448 contrailFqdnString = "<contrail-service-instance-fqdn>" + execution.getVariable("DCVFM_contrailServiceInstanceFqdn") +
1449 "</contrail-service-instance-fqdn>"
1452 String updateAAIVfModuleRequest =
1453 """<UpdateAAIVfModuleRequest>
1454 <vnf-id>${vnfId}</vnf-id>
1455 <vf-module-id>${vfModuleId}</vf-module-id>
1456 ${heatStackIdString}
1457 ${orchestrationStatusString}
1458 ${volumeGroupIdString}
1459 ${contrailFqdnString}
1460 </UpdateAAIVfModuleRequest>"""
1462 utils.logAudit("updateAAIVfModule Request: " + updateAAIVfModuleRequest)
1463 return updateAAIVfModuleRequest
1467 public String buildSDNCParamsXml(Execution execution){
1470 StringBuilder sb = new StringBuilder()
1471 Map<String, String> paramsMap = execution.getVariable("DCVFM_vnfParamsMap")
1473 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
1475 String key = entry.getKey();
1476 if(key.endsWith("_network")){
1477 String requestKey = key.substring(0, key.indexOf("_network"))
1478 String requestValue = entry.getValue()
1481 <network-role>{ functx:substring-before-match(data($param/@name), '_network') }</network-role>
1482 <network-name>{ $param/text() }</network-name>
1487 params = sb.append(paramsXml)
1492 public void queryCloudRegion (Execution execution) {
1493 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
1494 execution.setVariable("prefix", Prefix)
1495 utils.log("DEBUG", " ======== STARTED queryCloudRegion ======== ", isDebugLogEnabled)
1498 String cloudRegion = execution.getVariable("DCVFM_cloudSiteId")
1501 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
1502 AaiUtil aaiUtil = new AaiUtil(this)
1503 String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
1504 String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
1505 utils.logAudit("CloudRegion Request: " + queryCloudRegionRequest)
1507 execution.setVariable("DCVFM_queryCloudRegionRequest", queryCloudRegionRequest)
1508 utils.log("DEBUG", "DCVFM_queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest, isDebugLogEnabled)
1510 cloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
1512 if ((cloudRegion != "ERROR")) {
1513 if(execution.getVariable("DCVFM_queryCloudRegionReturnCode") == "404"){
1514 execution.setVariable("DCVFM_cloudRegionForVolume", "AAIAIC25")
1516 execution.setVariable("DCVFM_cloudRegionForVolume", cloudRegion)
1518 execution.setVariable("DCVFM_isCloudRegionGood", true)
1520 String errorMessage = "AAI Query Cloud Region Unsuccessful. AAI Response Code: " + execution.getVariable("DCVFM_queryCloudRegionReturnCode")
1521 utils.log("DEBUG", errorMessage, isDebugLogEnabled)
1522 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1523 execution.setVariable("DCVFM_isCloudRegionGood", false)
1525 utils.log("DEBUG", " is Cloud Region Good: " + execution.getVariable("DCVFM_isCloudRegionGood"), isDebugLogEnabled)
1527 } catch(BpmnError b){
1528 utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugLogEnabled)
1530 }catch (Exception ex) {
1532 String errorMessage = "Bpmn error encountered in CreateVfModule flow. Unexpected Response from AAI - " + ex.getMessage()
1533 utils.log("ERROR", " AAI Query Cloud Region Failed. Exception - " + "\n" + errorMessage, isDebugLogEnabled)
1534 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception occured during queryCloudRegion method")
1540 *This method occurs when an MSOWorkflowException is caught. It logs the
1541 *variables and ensures that the "WorkflowException" Variable is set.
1544 public void processBPMNException(Execution execution){
1545 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1546 execution.setVariable("prefix",Prefix)
1548 utils.log("DEBUG", "Caught a BPMN Exception", isDebugEnabled)
1549 utils.log("DEBUG", "Started processBPMNException Method", isDebugEnabled)
1550 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
1551 if(execution.getVariable("WorkflowException") == null){
1552 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception occured during DoCreateVfModule Sub Process")
1555 }catch(Exception e){
1556 utils.log("DEBUG", "Caught Exception during processBPMNException Method: " + e, isDebugEnabled)
1558 utils.log("DEBUG", "Completed processBPMNException Method", isDebugEnabled)
1561 public void prepareCreateAAIVfModuleVolumeGroupRequest(Execution execution) {
1562 def method = getClass().getSimpleName() + '.prepareCreateAAIVfModuleVolumeGroupRequest(' +
1563 'execution=' + execution.getId() +
1565 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1566 logDebug('Entered ' + method, isDebugLogEnabled)
1567 execution.setVariable("prefix", Prefix)
1568 logDebug(" ======== STARTED prepareCreateAAIVfModuleVolumeGroupRequest ======== ", isDebugLogEnabled)
1572 //Build CreateAAIVfModuleVolumeGroup Request
1574 def vnfId = execution.getVariable("DCVFM_vnfId")
1575 def vfModuleId = execution.getVariable("DCVFM_vfModuleId")
1576 def volumeGroupId = execution.getVariable("DCVFM_volumeGroupId")
1577 //def aicCloudRegion = execution.getVariable("DCVFM_cloudSiteId")
1578 def aicCloudRegion = execution.getVariable("DCVFM_cloudRegionForVolume")
1579 String createAAIVfModuleVolumeGroupRequest =
1580 """<CreateAAIVfModuleVolumeGroupRequest>
1581 <vnf-id>${vnfId}</vnf-id>
1582 <vf-module-id>${vfModuleId}</vf-module-id>
1583 <volume-group-id>${volumeGroupId}</volume-group-id>
1584 <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>
1585 </CreateAAIVfModuleVolumeGroupRequest>"""
1587 createAAIVfModuleVolumeGroupRequest = utils.formatXml(createAAIVfModuleVolumeGroupRequest)
1588 execution.setVariable("DCVFM_createAAIVfModuleVolumeGroupRequest", createAAIVfModuleVolumeGroupRequest)
1589 logDebug("Outgoing CreateAAIVfModuleVolumeGroupRequest is: \n" + createAAIVfModuleVolumeGroupRequest, isDebugLogEnabled)
1590 utils.logAudit("Outgoing CreateAAIVfModuleVolumeGroupRequest is: \n" + createAAIVfModuleVolumeGroupRequest)
1592 }catch(Exception e){
1593 utils.log("ERROR", "Exception Occured Processing prepareCreateAAIVfModuleVolumeGroupRequest. Exception is:\n" + e, isDebugLogEnabled)
1594 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareCreateAAIVfModuleVolumeGroupRequest Method:\n" + e.getMessage())
1596 logDebug("======== COMPLETED prepareCreateAAIVfModuleVolumeGroupRequest ======== ", isDebugLogEnabled)
1600 public void createNetworkPoliciesInAAI(Execution execution) {
1601 def method = getClass().getSimpleName() + '.createNetworkPoliciesInAAI(' +
1602 'execution=' + execution.getId() +
1604 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1605 logDebug('Entered ' + method, isDebugLogEnabled)
1606 execution.setVariable("prefix", Prefix)
1607 logDebug(" ======== STARTED createNetworkPoliciesInAAI ======== ", isDebugLogEnabled)
1611 List fqdnList = execution.getVariable("DCVFM_contrailNetworkPolicyFqdnList")
1612 int fqdnCount = fqdnList.size()
1613 def rollbackData = execution.getVariable("RollbackData")
1615 execution.setVariable("DCVFM_networkPolicyFqdnCount", fqdnCount)
1616 logDebug("DCVFM_networkPolicyFqdnCount - " + fqdnCount, isDebugLogEnabled)
1618 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
1619 AaiUtil aaiUriUtil = new AaiUtil(this)
1620 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
1622 if (fqdnCount > 0) {
1624 // AII loop call over contrail network policy fqdn list
1625 for (i in 0..fqdnCount-1) {
1628 String fqdn = fqdnList[i]
1630 // Query AAI for this network policy FQDN
1632 String queryNetworkPolicyByFqdnAAIRequest = "${aai_endpoint}${aai_uri}?network-policy-fqdn=" + UriUtils.encode(fqdn, "UTF-8")
1633 utils.logAudit("AAI request endpoint: " + queryNetworkPolicyByFqdnAAIRequest)
1635 def aaiRequestId = UUID.randomUUID().toString()
1636 RESTConfig config = new RESTConfig(queryNetworkPolicyByFqdnAAIRequest);
1637 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", aaiRequestId)
1638 .addHeader("X-FromAppId", "MSO")
1639 .addHeader("Content-Type", "application/xml")
1640 .addHeader("Accept","application/xml");
1641 APIResponse response = client.get()
1642 int returnCode = response.getStatusCode()
1643 execution.setVariable("DCVFM_aaiQqueryNetworkPolicyByFqdnReturnCode", returnCode)
1644 logDebug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugLogEnabled)
1646 String aaiResponseAsString = response.getResponseBodyAsString()
1648 if (isOneOf(returnCode, 200, 201)) {
1649 logDebug("The return code is: " + returnCode, isDebugLogEnabled)
1650 // This network policy FQDN already exists in AAI
1651 utils.logAudit(aaiResponseAsString)
1652 execution.setVariable("DCVFM_queryNetworkPolicyByFqdnAAIResponse", aaiResponseAsString)
1653 logDebug(" QueryAAINetworkPolicyByFQDN Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugLogEnabled)
1656 if (returnCode == 404) {
1657 // This network policy FQDN is not in AAI yet. Add it now
1658 logDebug("The return code is: " + returnCode, isDebugLogEnabled)
1659 logDebug("This network policy FQDN is not in AAI yet: " + fqdn, isDebugLogEnabled)
1660 utils.logAudit("Network policy FQDN is not in AAI yet")
1661 // Add the network policy with this FQDN to AAI
1662 def networkPolicyId = UUID.randomUUID().toString()
1663 logDebug("Adding network-policy with network-policy-id " + networkPolicyId, isDebugLogEnabled)
1665 String aaiNamespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
1666 logDebug('AAI namespace is: ' + aaiNamespace, isDebugLogEnabled)
1667 String payload = """<network-policy xmlns="${aaiNamespace}">
1668 <network-policy-id>${networkPolicyId}</network-policy-id>
1669 <network-policy-fqdn>${fqdn}</network-policy-fqdn>
1670 <heat-stack-id>${execution.getVariable("DCVFM_heatStackId")}</heat-stack-id>
1671 </network-policy>""" as String
1673 execution.setVariable("DCVFM_addNetworkPolicyAAIRequestBody", payload)
1675 String addNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(networkPolicyId, "UTF-8")
1676 utils.logAudit("AAI request endpoint: " + addNetworkPolicyAAIRequest)
1677 logDebug("AAI request endpoint: " + addNetworkPolicyAAIRequest, isDebugLogEnabled)
1679 def aaiRequestIdPut = UUID.randomUUID().toString()
1680 RESTConfig configPut = new RESTConfig(addNetworkPolicyAAIRequest);
1681 RESTClient clientPut = new RESTClient(configPut).addHeader("X-TransactionId", aaiRequestIdPut)
1682 .addHeader("X-FromAppId", "MSO")
1683 .addHeader("Content-Type", "application/xml")
1684 .addHeader("Accept","application/xml");
1685 logDebug("invoking PUT call to AAI with payload:"+System.lineSeparator()+payload, isDebugLogEnabled)
1686 utils.logAudit("Sending PUT call to AAI with Endpoint /n" + addNetworkPolicyAAIRequest + " with payload /n" + payload)
1687 APIResponse responsePut = clientPut.httpPut(payload)
1688 int returnCodePut = responsePut.getStatusCode()
1689 execution.setVariable("DCVFM_aaiAddNetworkPolicyReturnCode", returnCodePut)
1690 logDebug(" ***** AAI add network policy Response Code, NetworkPolicy #" + counting + " : " + returnCodePut, isDebugLogEnabled)
1692 String aaiResponseAsStringPut = responsePut.getResponseBodyAsString()
1693 if (isOneOf(returnCodePut, 200, 201)) {
1694 logDebug("The return code from adding network policy is: " + returnCodePut, isDebugLogEnabled)
1695 // This network policy was created in AAI successfully
1696 utils.logAudit(aaiResponseAsStringPut)
1697 execution.setVariable("DCVFM_addNetworkPolicyAAIResponse", aaiResponseAsStringPut)
1698 logDebug(" AddAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsStringPut, isDebugLogEnabled)
1699 rollbackData.put("VFMODULE", "rollbackCreateNetworkPoliciesAAI", "true")
1700 rollbackData.put("VFMODULE", "contrailNetworkPolicyFqdn" + i, fqdn)
1701 execution.setVariable("RollbackData", rollbackData)
1705 String putErrorMessage = "Unable to add network-policy to AAI createNetworkPoliciesInAAI - " + returnCodePut
1706 logDebug(putErrorMessage, isDebugLogEnabled)
1707 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, putErrorMessage)
1711 if (aaiResponseAsString.contains("RESTFault")) {
1712 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
1713 execution.setVariable("WorkflowException", exceptionObject)
1714 throw new BpmnError("MSOWorkflowException")
1718 String dataErrorMessage = "Unexpected Response from createNetworkPoliciesInAAI - " + returnCode
1719 logDebug(dataErrorMessage, isDebugLogEnabled)
1720 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1730 logDebug("No contrail network policies to query/create", isDebugLogEnabled)
1734 } catch (BpmnError e) {
1737 } catch (Exception ex) {
1738 String exceptionMessage = "Bpmn error encountered in DoCreateVfModule flow. createNetworkPoliciesInAAI() - " + ex.getMessage()
1739 logDebug(exceptionMessage, isDebugLogEnabled)
1740 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1746 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
1748 * @param execution The flow's execution instance.
1750 public void prepUpdateAAIGenericVnf(Execution execution) {
1751 def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
1752 'execution=' + execution.getId() +
1754 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1755 logDebug('Entered ' + method, isDebugLogEnabled)
1758 def rollbackData = execution.getVariable("RollbackData")
1759 def vnfId = execution.getVariable('DCVFM_vnfId')
1760 def oamManagementV4Address = execution.getVariable("DCVFM_oamManagementV4Address")
1761 def oamManagementV6Address = execution.getVariable("DCVFM_oamManagementV6Address")
1762 def ipv4OamAddressElement = ''
1763 def managementV6AddressElement = ''
1765 if (oamManagementV4Address != null && !oamManagementV4Address.isEmpty()) {
1766 ipv4OamAddressElement = '<ipv4-oam-address>' + oamManagementV4Address + '</ipv4-oam-address>'
1769 if (oamManagementV6Address != null && !oamManagementV6Address.isEmpty()) {
1770 managementV6AddressElement = '<management-v6-address>' + oamManagementV6Address + '</management-v6-address>'
1773 rollbackData.put("VFMODULE", "oamManagementV4Address", oamManagementV4Address)
1776 String updateAAIGenericVnfRequest = """
1777 <UpdateAAIGenericVnfRequest>
1778 <vnf-id>${vnfId}</vnf-id>
1779 ${ipv4OamAddressElement}
1780 ${managementV6AddressElement}
1781 </UpdateAAIGenericVnfRequest>
1783 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
1784 execution.setVariable('DCVM_updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
1785 utils.logAudit("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
1786 logDebug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest, isDebugLogEnabled)
1789 logDebug('Exited ' + method, isDebugLogEnabled)
1790 } catch (BpmnError e) {
1792 } catch (Exception e) {
1793 logError('Caught exception in ' + method, e)
1794 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
1799 * Post process a result from invoking the UpdateAAIGenericVnf subflow.
1801 * @param execution The flow's execution instance.
1803 public void postProcessUpdateAAIGenericVnf(Execution execution) {
1804 def method = getClass().getSimpleName() + '.postProcessUpdateAAIGenericVnf(' +
1805 'execution=' + execution.getId() +
1807 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1808 logDebug('Entered ' + method, isDebugLogEnabled)
1811 def rollbackData = execution.getVariable("RollbackData")
1813 rollbackData.put("VFMODULE", "rollbackUpdateVnfAAI", "true")
1815 def vnfId = execution.getVariable('DCVFM_vnfId')
1816 def oamManagementV4Address = execution.getVariable("DCVFM_oamManagementV4Address")
1817 def oamManagementV6Address = execution.getVariable("DCVFM_oamManagementV6Address")
1818 def ipv4OamAddressElement = ''
1819 def managementV6AddressElement = ''
1821 if (oamManagementV4Address != null && !oamManagementV4Address.isEmpty()) {
1822 rollbackData.put("VFMODULE", "oamManagementV4Address", oamManagementV4Address)
1825 if (oamManagementV6Address != null && !oamManagementV6Address.isEmpty()) {
1826 rollbackData.put("VFMODULE", "oamManagementV6Address", oamManagementV6Address)
1829 execution.setVariable("RollbackData", rollbackData)
1831 logDebug('Exited ' + method, isDebugLogEnabled)
1832 } catch (BpmnError e) {
1834 } catch (Exception e) {
1835 logError('Caught exception in ' + method, e)
1836 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in postProcessUpdateAAIGenericVnf(): ' + e.getMessage())