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 com.att.bpm.scripts
23 import groovy.util.Node
24 import groovy.xml.QName
26 import java.io.Serializable;
28 import org.springframework.web.util.UriUtils
30 import org.camunda.bpm.engine.delegate.BpmnError
31 import org.camunda.bpm.engine.runtime.Execution
33 import org.openecomp.mso.rest.APIResponse
34 import org.openecomp.mso.rest.RESTClient
35 import org.openecomp.mso.rest.RESTConfig
36 import org.openecomp.mso.bpmn.core.RollbackData
37 import org.openecomp.mso.bpmn.core.WorkflowException
39 public class DoUpdateVfModule extends VfModuleBase {
41 ExceptionUtil exceptionUtil = new ExceptionUtil()
44 * Initialize the flow's variables.
46 * @param execution The flow's execution instance.
48 public void initProcessVariables(Execution execution) {
49 execution.setVariable('prefix', 'DOUPVfMod_')
50 execution.setVariable('DOUPVfMod_requestInfo', null)
51 execution.setVariable('DOUPVfMod_serviceInstanceId', null)
52 execution.setVariable('DOUPVfMod_requestId', null)
53 execution.setVariable('DOUPVfMod_vnfInputs', null)
54 execution.setVariable('DOUPVfMod_vnfId', null)
55 execution.setVariable('DOUPVfMod_vnfName', null)
56 execution.setVariable('DOUPVfMod_vnfNameFromAAI', null)
57 execution.setVariable('DOUPVfMod_vfModuleName', null)
58 execution.setVariable('DOUPVfMod_vfModuleId', null)
59 execution.setVariable('DOUPVfMod_vnfType', null)
60 execution.setVariable('DOUPVfMod_asdcServiceModelVersion', null)
61 execution.setVariable('DOUPVfMod_vfModuleModelName', null)
62 execution.setVariable("DOUPVfMod_isBaseVfModule", "false")
63 execution.setVariable('DOUPVfMod_serviceId', null)
64 execution.setVariable('DOUPVfMod_aicCloudRegion', null)
65 execution.setVariable('DOUPVfMod_tenantId', null)
66 execution.setVariable('DOUPVfMod_volumeGroupId', null)
67 execution.setVariable('DOUPVfMod_vfModule', null)
68 execution.setVariable('DOUPVfMod_vnfParams', null)
69 execution.setVariable("DOUPVfMod_baseVfModuleId", "")
70 execution.setVariable("DOUPVfMod_baseVfModuleHeatStackId", "")
71 execution.setVariable('DOUPVfMod_prepareUpdateAAIVfModuleRequest', null)
72 execution.setVariable('DOUPVfMod_sdncTopologyRequest', null)
73 execution.setVariable('DOUPVfMod_sdncTopologyResponse', null)
74 execution.setVariable('DOUPVfMod_vnfAdapterRestRequest', null)
75 execution.setVariable('DOUPVfMod_updateAAIGenericVnfRequest', null)
76 execution.setVariable('DOUPVfMod_updateAAIVfModuleRequest', null)
77 execution.setVariable('DOUPVfMod_skipUpdateGenericVnf', false)
78 execution.setVariable('DoUpdateVfModuleSuccessIndicator', false)
82 * Check for missing elements in the received request.
84 * @param execution The flow's execution instance.
86 public void preProcessRequest(Execution execution) {
87 def method = getClass().getSimpleName() + '.preProcessRequest(' +
88 'execution=' + execution.getId() +
90 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
91 logDebug('Entered ' + method, isDebugLogEnabled)
94 initProcessVariables(execution)
95 def xml = getVariable(execution, 'DoUpdateVfModuleRequest')
96 utils.logAudit("DoUpdateVfModule request: " + xml)
97 logDebug('Received request xml:\n' + xml, isDebugLogEnabled)
99 def requestInfo = getRequiredNodeXml(execution, xml, 'request-info')
100 execution.setVariable('DOUPVfMod_requestInfo', requestInfo)
101 execution.setVariable('DOUPVfMod_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))
102 def serviceInstanceId = execution.getVariable('att-mso-service-instance-id')
103 if (serviceInstanceId == null) {
104 serviceInstanceId = ''
106 execution.setVariable('DOUPVfMod_serviceInstanceId', serviceInstanceId)
108 def vnfInputs = getRequiredNodeXml(execution, xml, 'vnf-inputs')
109 execution.setVariable('DOUPVfMod_vnfInputs', vnfInputs)
110 execution.setVariable('DOUPVfMod_vnfId', getRequiredNodeText(execution, vnfInputs, 'vnf-id'))
111 execution.setVariable('DOUPVfMod_vfModuleId', getRequiredNodeText(execution, vnfInputs, 'vf-module-id'))
112 execution.setVariable('DOUPVfMod_vfModuleName', getNodeTextForce(vnfInputs, 'vf-module-name'))
113 execution.setVariable('DOUPVfMod_vnfType', getNodeTextForce(vnfInputs, 'vnf-type'))
114 execution.setVariable('DOUPVfMod_vnfName', getNodeTextForce(vnfInputs, 'vnf-name'))
115 execution.setVariable('DOUPVfMod_asdcServiceModelVersion', getNodeTextForce(vnfInputs, 'asdc-service-model-version'))
116 execution.setVariable('DOUPVfMod_vfModuleModelName', getRequiredNodeText(execution, vnfInputs, 'vf-module-model-name'))
117 execution.setVariable('DOUPVfMod_serviceId', getRequiredNodeText(execution, vnfInputs, 'service-id'))
118 execution.setVariable('DOUPVfMod_aicCloudRegion', getRequiredNodeText(execution, vnfInputs, 'aic-cloud-region'))
119 execution.setVariable('DOUPVfMod_tenantId', getRequiredNodeText(execution, vnfInputs, 'tenant-id'))
121 def isBaseVfModule = "false"
122 if (utils.nodeExists(xml, "is-base-vf-module")) {
123 isBaseVfModule = utils.getNodeText(xml, "is-base-vf-module")
124 execution.setVariable("DOUPVfMod_isBaseVfModule", isBaseVfModule)
126 logDebug("isBaseVfModule: " + isBaseVfModule, isDebugLogEnabled)
128 NetworkUtils networkUtils = new NetworkUtils()
129 def backoutOnFailure = networkUtils.isRollbackEnabled(execution, xml)
130 execution.setVariable("DOUPVfMod_backoutOnFailure", backoutOnFailure)
132 def String vgi = getNodeTextForce(vnfInputs, 'volume-group-id')
133 execution.setVariable('DOUPVfMod_volumeGroupId', vgi)
135 execution.setVariable('DOUPVfMod_vnfParams', utils.getNodeXml(xml, 'vnf-params', false))
137 def sdncCallbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
138 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
139 def msg = 'Required variable \'URN_mso_workflow_sdncadapter_callback\' is missing'
141 createWorkflowException(execution, 2000, msg)
143 def vnfCallbackUrl = (String) execution.getVariable('URN_mso_workflow_vnfadapter_rest_callback')
144 if (vnfCallbackUrl == null || vnfCallbackUrl.trim().isEmpty()) {
145 def msg = 'Required variable \'URN_mso_workflow_vnfadapter_rest_callback\' is missing'
147 createWorkflowException(execution, 2000, msg)
150 logDebug('Exited ' + method, isDebugLogEnabled)
151 } catch (BpmnError e) {
153 } catch (Exception e) {
154 logError('Caught exception in ' + method, e)
155 createWorkflowException(execution, 1002, 'Error in preProcessRequest(): ' + e.getMessage())
160 * Prepare a Request for invoking the PrepareUpdateAAIVfModule subflow. This will
161 * set the orchestration-status to 'pending-update'.
163 * @param execution The flow's execution instance.
165 public void prepPrepareUpdateAAIVfModule(Execution execution) {
166 def method = getClass().getSimpleName() + '.preparePrepareUpdateAAIVfModule(' +
167 'execution=' + execution.getId() +
169 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
170 logDebug('Entered ' + method, isDebugLogEnabled)
173 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
174 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
175 def orchestrationStatus = 'pending-update'
177 String prepareUpdateAAIVfModuleRequest = """
178 <PrepareUpdateAAIVfModuleRequest>
179 <vnf-id>${vnfId}</vnf-id>
180 <vf-module-id>${vfModuleId}</vf-module-id>
181 <orchestration-status>${orchestrationStatus}</orchestration-status>
182 </PrepareUpdateAAIVfModuleRequest>
184 prepareUpdateAAIVfModuleRequest = utils.formatXml(prepareUpdateAAIVfModuleRequest)
185 execution.setVariable('DOUPVfMod_prepareUpdateAAIVfModuleRequest', prepareUpdateAAIVfModuleRequest)
186 utils.logAudit("DoUpdateAAIVfModule request: " + prepareUpdateAAIVfModuleRequest)
187 logDebug('Request for PrepareUpdateAAIVfModule:\n' + prepareUpdateAAIVfModuleRequest, isDebugLogEnabled)
189 logDebug('Exited ' + method, isDebugLogEnabled)
190 } catch (BpmnError e) {
192 } catch (Exception e) {
193 logError('Caught exception in ' + method, e)
194 createWorkflowException(execution, 1002, 'Error in preparePrepareUpdateAAIVfModule(): ' + e.getMessage())
199 * Prepare a Request for invoking the ConfirmVolumeGroupTenant subflow. Currently,
200 * there is really nothing to do, so we just log that we're passing through.
202 * @param execution The flow's execution instance.
204 public void prepConfirmVolumeGroupTenant(Execution execution) {
205 def method = getClass().getSimpleName() + '.prepConfirmVolumeGroupTenant(' +
206 'execution=' + execution.getId() +
208 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
209 logDebug('Entered ' + method, isDebugLogEnabled)
212 // Nothing to do - just log that we're passing through here
214 logDebug('Exited ' + method, isDebugLogEnabled)
215 } catch (BpmnError e) {
217 } catch (Exception e) {
218 logError('Caught exception in ' + method, e)
219 createWorkflowException(execution, 1002, 'Error in prepConfirmVolumeGroupTenant(): ' + e.getMessage())
224 * Prepare a Request for invoking the SDNC Adapter subflow to perform
225 * a VNF topology 'changeassign' operation.
227 * @param execution The flow's execution instance.
229 public void prepSDNCTopologyChg(Execution execution) {
230 def method = getClass().getSimpleName() + '.prepSDNCTopologyChg(' +
231 'execution=' + execution.getId() +
233 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
234 logDebug('Entered ' + method, isDebugLogEnabled)
237 def requestId = execution.getVariable('DOUPVfMod_requestId')
238 def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
239 def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
240 def serviceId = execution.getVariable('DOUPVfMod_serviceId')
241 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
242 def vnfType = execution.getVariable('DOUPVfMod_vnfType')
243 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
244 def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName')
245 def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
246 def vfModuleName = vfModule.getElementText('vf-module-name')
247 def tenantId = execution.getVariable('DOUPVfMod_tenantId')
248 def aicCloudRegion = execution.getVariable('DOUPVfMod_aicCloudRegion')
250 // Retrieve vnf name from AAI response
251 def vnfName = execution.getVariable('DOUPVfMod_vnfNameFromAAI')
252 execution.setVariable('DOUPVfMod_vnfName', vnfName)
254 def vnfParamsXml = execution.getVariable('DOUPVfMod_vnfParams')
255 def vnfNetworks = transformNetworkParamsToVnfNetworks(vnfParamsXml)
257 String sdncTopologyRequest = """
258 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
259 xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"
260 xmlns:sdncadapter="http://domain2.att.com/workflow/sdnc/adapter/schema/v1">
261 <sdncadapter:RequestHeader>
262 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
263 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
264 <sdncadapter:SvcAction>changeassign</sdncadapter:SvcAction>
265 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
266 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
267 </sdncadapter:RequestHeader>
268 <sdncadapterworkflow:SDNCRequestData>
269 <request-information>
270 <request-id>${requestId}</request-id>
271 <request-action>ChangeVNFActivateRequest</request-action>
272 <source>PORTAL</source>
276 </request-information>
277 <service-information>
278 <service-type>${serviceId}</service-type>
279 <service-instance-id>${vnfId}</service-instance-id>
280 <subscriber-name>dontcare</subscriber-name>
281 </service-information>
282 <vnf-request-information>
283 <vnf-id>${vfModuleId}</vnf-id>
284 <vnf-type>${vfModuleModelName}</vnf-type>
285 <vnf-name>${vfModuleName}</vnf-name>
286 <generic-vnf-id>${vnfId}</generic-vnf-id>
287 <generic-vnf-name>${vnfName}</generic-vnf-name>
288 <generic-vnf-type>${vnfType}</generic-vnf-type>
289 <tenant>${tenantId}</tenant>
290 <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>
292 </vnf-request-information>
293 </sdncadapterworkflow:SDNCRequestData>
294 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
296 sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
297 execution.setVariable('DOUPVfMod_sdncTopologyRequest', sdncTopologyRequest)
298 utils.logAudit("sdncTopologyRequest : " + sdncTopologyRequest)
299 logDebug('Request for SDNCAdapter topology/changeassign:\n' + sdncTopologyRequest, isDebugLogEnabled)
301 logDebug('Exited ' + method, isDebugLogEnabled)
302 } catch (BpmnError e) {
304 } catch (Exception e) {
305 logError('Caught exception in ' + method, e)
306 createWorkflowException(execution, 1002, 'Error in prepSDNCTopologyChg(): ' + e.getMessage())
311 * Prepare a Request for invoking the SDNC Adapter subflow to perform
312 * a VNF topology 'query' operation.
314 * @param execution The flow's execution instance.
316 public void prepSDNCTopologyQuery(Execution execution) {
317 def method = getClass().getSimpleName() + '.prepSDNCTopologyQuery(' +
318 'execution=' + execution.getId() +
320 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
321 logDebug('Entered ' + method, isDebugLogEnabled)
324 def requestId = execution.getVariable('DOUPVfMod_requestId')
325 def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
326 def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
327 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
330 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
331 svcInstId = vfModuleId
334 svcInstId = serviceInstanceId
337 //!!!! TEMPORARY WORKAROUND FOR SDNC REPLICATION ISSUE
340 String sdncTopologyRequest = """
341 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
342 xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"
343 xmlns:sdncadapter="http://domain2.att.com/workflow/sdnc/adapter/schema/v1">
344 <sdncadapter:RequestHeader>
345 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
346 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
347 <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
348 <sdncadapter:SvcOperation>/VNF-API:vnfs/vnf-list/${vfModuleId}</sdncadapter:SvcOperation>
349 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
350 <sdncadapter:MsoAction>mobility</sdncadapter:MsoAction>
351 </sdncadapter:RequestHeader>
352 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
354 sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
355 execution.setVariable('DOUPVfMod_sdncTopologyRequest', sdncTopologyRequest)
356 utils.logAudit("sdncTopologyRequest : " + sdncTopologyRequest)
357 logDebug('Request for SDNCAdapter query:\n' + sdncTopologyRequest, isDebugLogEnabled)
359 logDebug('Exited ' + method, isDebugLogEnabled)
360 } catch (BpmnError e) {
362 } catch (Exception e) {
363 logError('Caught exception in ' + method, e)
364 createWorkflowException(execution, 1002, 'Error in prepSDNCTopologyQuery(): ' + e.getMessage())
369 * Prepare a Request for invoking the VnfAdapterRest subflow.
371 * @param execution The flow's execution instance.
373 public void prepVnfAdapterRest(Execution execution) {
374 def method = getClass().getSimpleName() + '.prepVnfAdapterRest(' +
375 'execution=' + execution.getId() +
377 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
378 logDebug('Entered ' + method, isDebugLogEnabled)
381 def requestId = execution.getVariable('DOUPVfMod_requestId')
382 def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
383 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
384 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
385 def vfModuleName = execution.getVariable('DOUPVfMod_vfModuleName')
386 def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
387 def tenantId = execution.getVariable('DOUPVfMod_tenantId')
388 def volumeGroupId = execution.getVariable('DOUPVfMod_volumeGroupId')
389 def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
390 def heatStackId = vfModule.getElementText('heat-stack-id')
391 def cloudId = execution.getVariable('DOUPVfMod_aicCloudRegion')
392 def vnfType = execution.getVariable('DOUPVfMod_vnfType')
393 def vnfName = execution.getVariable('DOUPVfMod_vnfName')
394 def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName')
395 def baseVfModuleId = execution.getVariable("DOUPVfMod_baseVfModuleId")
396 def baseVfModuleStackId = execution.getVariable("DOUPVfMod_baseVfModuleHeatStackId")
397 def asdcServiceModelVersion = execution.getVariable('DOUPVfMod_asdcServiceModelVersion')
398 def backoutOnFailure = execution.getVariable("DOUPVfMod_backoutOnFailure")
400 def vnfParamsXml = execution.getVariable('DOUPVfMod_vnfParams')
401 def vfModuleParamsEntries = transformParamsToEntries(vnfParamsXml)
403 def messageId = execution.getVariable('att-mso-request-id') + '-' + System.currentTimeMillis()
404 def notificationUrl = execution.getVariable("URN_mso_workflow_vnfadapter_rest_callback")
405 def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
406 if ('true'.equals(useQualifiedHostName)) {
407 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
410 String sdncGetResponse = execution.getVariable('DOUPVfMod_sdncTopologyResponse')
412 String vfModuleParams = buildVfModuleParams(vfModuleParamsEntries, sdncGetResponse, vnfId, vnfName,
413 vfModuleId, vfModuleName)
416 String vnfAdapterRestRequest = """
417 <updateVfModuleRequest>
418 <cloudSiteId>${cloudId}</cloudSiteId>
419 <tenantId>${tenantId}</tenantId>
420 <vnfId>${vnfId}</vnfId>
421 <vfModuleId>${vfModuleId}</vfModuleId>
422 <vfModuleStackId>${heatStackId}</vfModuleStackId>
423 <vnfType>${vnfType}</vnfType>
424 <vnfVersion>${asdcServiceModelVersion}</vnfVersion>
425 <vfModuleType>${vfModuleModelName}</vfModuleType>
426 <volumeGroupId>${volumeGroupId}</volumeGroupId>
427 <baseVfModuleId>${baseVfModuleId}</baseVfModuleId>
428 <baseVfModuleStackId>${baseVfModuleStackId}</baseVfModuleStackId>
429 <skipAAI>true</skipAAI>
430 <backout>${backoutOnFailure}</backout>
431 <failIfExists>false</failIfExists>
436 <requestId>${requestId}</requestId>
437 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
439 <messageId>${messageId}</messageId>
440 <notificationUrl>${notificationUrl}</notificationUrl>
441 </updateVfModuleRequest>
443 vnfAdapterRestRequest = utils.formatXml(vnfAdapterRestRequest)
444 execution.setVariable('DOUPVfMod_vnfAdapterRestRequest', vnfAdapterRestRequest)
445 utils.logAudit("vnfAdapterRestRequest : " + vnfAdapterRestRequest)
446 logDebug('Request for VNFAdapter Rest:\n' + vnfAdapterRestRequest, isDebugLogEnabled)
448 logDebug('Exited ' + method, isDebugLogEnabled)
449 } catch (BpmnError e) {
451 } catch (Exception e) {
452 logError('Caught exception in ' + method, e)
453 createWorkflowException(execution, 1002, 'Error in prepVnfAdapterRest(): ' + e.getMessage())
458 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
460 * @param execution The flow's execution instance.
462 public void prepUpdateAAIGenericVnf(Execution execution) {
463 def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
464 'execution=' + execution.getId() +
466 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
467 logDebug('Entered ' + method, isDebugLogEnabled)
470 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
471 def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
473 def personaModelId = utils.getNodeText1(vnfInputs, 'vnf-persona-model-id')
474 def personaModelVersion = utils.getNodeText1(vnfInputs, 'vnf-persona-model-version')
475 if ((personaModelId == null) || (personaModelVersion == null)) {
476 logDebug('Skipping update for Generic VNF ' + vnfId +
477 ' because either \'vnf-persona-model-id\' or \'vnf-persona-model-version\' is absent', isDebugLogEnabled)
478 execution.setVariable('DOUPVfMod_skipUpdateGenericVnf', true)
480 def personaModelIdElement = '<persona-model-id>' + personaModelId + '</persona-model-id>'
481 def personaModelVersionElement = '<persona-model-version>' + personaModelVersion + '</persona-model-version>'
483 String updateAAIGenericVnfRequest = """
484 <UpdateAAIGenericVnfRequest>
485 <vnf-id>${vnfId}</vnf-id>
486 ${personaModelIdElement}
487 ${personaModelVersionElement}
488 </UpdateAAIGenericVnfRequest>
490 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
491 execution.setVariable('DOUPVfMod_updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
492 utils.logAudit("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
493 logDebug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest, isDebugLogEnabled)
496 logDebug('Exited ' + method, isDebugLogEnabled)
497 } catch (BpmnError e) {
499 } catch (Exception e) {
500 logError('Caught exception in ' + method, e)
501 createWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
506 * Prepare a Request for invoking the UpdateAAIVfModule subflow.
508 * @param execution The flow's execution instance.
510 public void prepUpdateAAIVfModule(Execution execution) {
511 def method = getClass().getSimpleName() + '.prepUpdateAAIVfModule(' +
512 'execution=' + execution.getId() +
514 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
515 logDebug('Entered ' + method, isDebugLogEnabled)
518 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
519 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
520 def orchestrationStatus = 'updated'
521 def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
523 def volumeGroupIdElement = ''
524 def volumeGroupId = execution.getVariable('DOUPVfMod_volumeGroupId')
525 if (volumeGroupId != null) {
526 volumeGroupIdElement = '<volume-group-id>' + volumeGroupId + '</volume-group-id>'
528 def personaModelIdElement = ''
529 def personaModelId = utils.getNodeText1(vnfInputs, 'persona-model-id')
530 if (personaModelId != null) {
531 personaModelIdElement = '<persona-model-id>' + personaModelId + '</persona-model-id>'
533 def personaModelVersionElement = ''
534 def personaModelVersion = utils.getNodeText1(vnfInputs, 'persona-model-version')
535 if (personaModelVersion != null) {
536 personaModelVersionElement = '<persona-model-version>' + personaModelVersion + '</persona-model-version>'
538 def contrailServiceInstanceFqdnElement = ''
539 def contrailServiceInstanceFqdn = utils.getNodeText1(vnfInputs, 'contrail-service-instance-fqdn')
540 if (contrailServiceInstanceFqdn != null) {
541 contrailServiceInstanceFqdnElement = '<contrail-service-instance-fqdn>' + contrailServiceInstanceFqdn + '</contrail-service-instance-fqdn>'
544 String updateAAIVfModuleRequest = """
545 <UpdateAAIVfModuleRequest>
546 <vnf-id>${vnfId}</vnf-id>
547 <vf-module-id>${vfModuleId}</vf-module-id>
548 <orchestration-status>${orchestrationStatus}</orchestration-status>
549 ${volumeGroupIdElement}
550 ${personaModelIdElement}
551 ${personaModelVersionElement}
552 ${contrailServiceInstanceFqdnElement}
553 </UpdateAAIVfModuleRequest>
555 updateAAIVfModuleRequest = utils.formatXml(updateAAIVfModuleRequest)
556 execution.setVariable('DOUPVfMod_updateAAIVfModuleRequest', updateAAIVfModuleRequest)
557 utils.logAudit("updateAAIVfModuleRequest : " + updateAAIVfModuleRequest)
558 logDebug('Request for UpdateAAIVfModule:\n' + updateAAIVfModuleRequest, isDebugLogEnabled)
560 logDebug('Exited ' + method, isDebugLogEnabled)
561 } catch (BpmnError e) {
563 } catch (Exception e) {
564 logError('Caught exception in ' + method, e)
565 createWorkflowException(execution, 1002, 'Error in prepUpdateAAIVfModule(): ' + e.getMessage())
570 * Prepare a Request for invoking the SDNC Adapter subflow to perform
571 * a VNF topology 'activate' operation.
573 * @param execution The flow's execution instance.
575 public void prepSDNCTopologyAct(Execution execution) {
576 def method = getClass().getSimpleName() + '.prepSDNCTopologyAct(' +
577 'execution=' + execution.getId() +
579 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
580 logDebug('Entered ' + method, isDebugLogEnabled)
583 def requestId = execution.getVariable('DOUPVfMod_requestId')
584 def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
585 def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
586 def serviceId = execution.getVariable('DOUPVfMod_serviceId')
587 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
588 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
589 def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName')
590 def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
591 def vfModuleName = vfModule.getElementText('vf-module-name')
592 def tenantId = execution.getVariable('DOUPVfMod_tenantId')
593 def aicCloudRegion = execution.getVariable('DOUPVfMod_aicCloudRegion')
595 def vnfParamsXml = execution.getVariable('DOUPVfMod_vnfParams')
596 def vnfNetworks = transformNetworkParamsToVnfNetworks(vnfParamsXml)
598 String sdncTopologyRequest = """
599 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
600 xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"
601 xmlns:sdncadapter="http://domain2.att.com/workflow/sdnc/adapter/schema/v1">
602 <sdncadapter:RequestHeader>
603 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
604 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
605 <sdncadapter:SvcAction>activate</sdncadapter:SvcAction>
606 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
607 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
608 </sdncadapter:RequestHeader>
609 <sdncadapterworkflow:SDNCRequestData>
610 <request-information>
611 <request-id>${requestId}</request-id>
612 <request-action>ChangeVNFActivateRequest</request-action>
613 <source>PORTAL</source>
617 </request-information>
618 <service-information>
619 <service-type>${serviceId}</service-type>
620 <service-instance-id>${vnfId}</service-instance-id>
621 <subscriber-name>dontcare</subscriber-name>
622 </service-information>
623 <vnf-request-information>
624 <vnf-id>${vfModuleId}</vnf-id>
625 <vnf-type>${vfModuleModelName}</vnf-type>
626 <vnf-name>${vfModuleName}</vnf-name>
627 <tenant>${tenantId}</tenant>
628 <aic-clli>${aicCloudRegion}</aic-clli> <!-- Optional -->
629 ${vnfNetworks} <!-- Optional -->
630 </vnf-request-information>
631 </sdncadapterworkflow:SDNCRequestData>
632 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
634 sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
635 execution.setVariable('DOUPVfMod_sdncTopologyRequest', sdncTopologyRequest)
636 utils.logAudit("sdncTopologyRequest : " + sdncTopologyRequest)
637 logDebug('Request for SDNCAdapter topology/activate:\n' + sdncTopologyRequest, isDebugLogEnabled)
640 logDebug('Exited ' + method, isDebugLogEnabled)
641 } catch (BpmnError e) {
643 } catch (Exception e) {
644 logError('Caught exception in ' + method, e)
645 createWorkflowException(execution, 1002, 'Error in prepSDNCTopologyAct(): ' + e.getMessage())
650 * Log a WorkflowException that has been created.
652 * @param execution The flow's execution instance.
654 public void handleWorkflowException(Execution execution) {
655 def method = getClass().getSimpleName() + '.handleWorkflowException(' +
656 'execution=' + execution.getId() +
658 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
659 logDebug('Entered ' + method, isDebugLogEnabled)
662 def WorkflowException workflowException = (WorkflowException) execution.getVariable('WorkflowException')
663 logError(method + ' caught WorkflowException: ' + workflowException.getErrorMessage())
665 logDebug('Exited ' + method, isDebugLogEnabled)
666 } catch (BpmnError e) {
668 } catch (Exception e) {
669 logError('Caught exception in ' + method, e)
670 createWorkflowException(execution, 1002, 'Error in handleWorkflowException(): ' + e.getMessage())
674 public void validateSDNCResponse(Execution execution, String response, String method){
675 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
676 def prefix = execution.getVariable("prefix")
678 logDebug(" *** STARTED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
680 WorkflowException workflowException = execution.getVariable("WorkflowException")
681 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
683 utils.logAudit("workflowException: " + workflowException)
685 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
686 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
688 utils.logAudit("SDNCResponse: " + response)
690 String sdncResponse = response
691 if(execution.getVariable(prefix + 'sdncResponseSuccess') == true){
692 logDebug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse, isDebugLogEnabled)
694 logDebug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
695 throw new BpmnError("MSOWorkflowException")
697 logDebug(" *** COMPLETED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
701 * Using the received vnfId and vfModuleId, query AAI to get the corresponding VNF info.
702 * A 200 response is expected with the VNF info in the response body. Will find out the base module info.
704 * @param execution The flow's execution instance.
706 public void queryAAIVfModule(Execution execution) {
707 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
708 def method = getClass().getSimpleName() + '.getVfModule(' +
709 'execution=' + execution.getId() +
711 logDebug('Entered ' + method, isDebugLogEnabled)
714 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
715 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
717 AaiUtil aaiUriUtil = new AaiUtil(this)
718 String aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
719 logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
721 String endPoint = execution.getVariable("URN_aai_endpoint") + "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8")
722 utils.logAudit("AAI endPoint: " + endPoint)
724 String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
727 RESTConfig config = new RESTConfig(endPoint);
728 def responseData = ''
729 def aaiRequestId = UUID.randomUUID().toString()
730 RESTClient client = new RESTClient(config).
731 addHeader('X-TransactionId', aaiRequestId).
732 addHeader('X-FromAppId', 'MSO').
733 addHeader('Content-Type', 'application/xml').
734 addHeader('Accept','application/xml');
735 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
736 client.addAuthorizationHeader(basicAuthCred)
738 logDebug('sending GET to AAI endpoint \'' + endPoint + '\'', isDebugLogEnabled)
739 APIResponse response = client.httpGet()
740 utils.logAudit("createVfModule - invoking httpGet() to AAI")
742 responseData = response.getResponseBodyAsString()
743 if (responseData != null) {
744 logDebug("Received generic VNF data: " + responseData, isDebugLogEnabled)
748 utils.logAudit("createVfModule - queryAAIVfModule Response: " + responseData)
749 utils.logAudit("createVfModule - queryAAIVfModule ResponseCode: " + response.getStatusCode())
751 execution.setVariable('DOUPVfMod_queryAAIVfModuleResponseCode', response.getStatusCode())
752 execution.setVariable('DOUPVfMod_queryAAIVfModuleResponse', responseData)
753 logDebug('Response code:' + response.getStatusCode(), isDebugLogEnabled)
754 logDebug('Response:' + System.lineSeparator() + responseData, isDebugLogEnabled)
755 if (response.getStatusCode() == 200) {
756 // Parse the VNF record from A&AI to find base module info
757 logDebug('Parsing the VNF data to find base module info', isDebugLogEnabled)
758 if (responseData != null) {
759 def vfModulesText = utils.getNodeXml(responseData, "vf-modules")
760 def xmlVfModules= new XmlSlurper().parseText(vfModulesText)
761 def vfModules = xmlVfModules.'**'.findAll {it.name() == "vf-module"}
762 int vfModulesSize = 0
763 for (i in 0..vfModules.size()-1) {
764 def vfModuleXml = groovy.xml.XmlUtil.serialize(vfModules[i])
765 def isBaseVfModule = utils.getNodeText(vfModuleXml, "is-base-vf-module")
767 if (isBaseVfModule == "true") {
768 String baseModuleId = utils.getNodeText1(vfModuleXml, "vf-module-id")
769 execution.setVariable("DOUPVfMod_baseVfModuleId", baseModuleId)
770 logDebug('Received baseVfModuleId: ' + baseModuleId, isDebugLogEnabled)
771 String baseModuleHeatStackId = utils.getNodeText1(vfModuleXml, "heat-stack-id")
772 execution.setVariable("DOUPVfMod_baseVfModuleHeatStackId", baseModuleHeatStackId)
773 logDebug('Received baseVfModuleHeatStackId: ' + baseModuleHeatStackId, isDebugLogEnabled)
778 } catch (Exception ex) {
780 logDebug('Exception occurred while executing AAI GET:' + ex.getMessage(),isDebugLogEnabled)
781 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
783 logDebug('Exited ' + method, isDebugLogEnabled)
784 } catch (BpmnError e) {
786 } catch (Exception e) {
787 logError('Caught exception in ' + method, e)
788 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModule(): ' + e.getMessage())