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 org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.runtime.Execution
25 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
26 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
27 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
28 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
29 import org.openecomp.mso.bpmn.common.scripts.VfModule
30 import org.openecomp.mso.bpmn.common.scripts.VfModuleBase
31 import org.openecomp.mso.bpmn.core.WorkflowException
32 import org.openecomp.mso.rest.APIResponse
33 import org.springframework.web.util.UriUtils
35 public class DoUpdateVfModule extends VfModuleBase {
37 ExceptionUtil exceptionUtil = new ExceptionUtil()
40 * Initialize the flow's variables.
42 * @param execution The flow's execution instance.
44 public void initProcessVariables(Execution execution) {
45 execution.setVariable('prefix', 'DOUPVfMod_')
46 execution.setVariable('DOUPVfMod_requestInfo', null)
47 execution.setVariable('DOUPVfMod_serviceInstanceId', null)
48 execution.setVariable('DOUPVfMod_requestId', null)
49 execution.setVariable('DOUPVfMod_vnfInputs', null)
50 execution.setVariable('DOUPVfMod_vnfId', null)
51 execution.setVariable('DOUPVfMod_vnfName', null)
52 execution.setVariable('DOUPVfMod_vnfNameFromAAI', null)
53 execution.setVariable('DOUPVfMod_vfModuleName', null)
54 execution.setVariable('DOUPVfMod_vfModuleId', null)
55 execution.setVariable('DOUPVfMod_vnfType', null)
56 execution.setVariable('DOUPVfMod_asdcServiceModelVersion', null)
57 execution.setVariable('DOUPVfMod_vfModuleModelName', null)
58 execution.setVariable('DOUPVfMod_modelCustomizationUuid', null)
59 execution.setVariable("DOUPVfMod_isBaseVfModule", "false")
60 execution.setVariable('DOUPVfMod_serviceId', null)
61 execution.setVariable('DOUPVfMod_aicCloudRegion', null)
62 execution.setVariable('DOUPVfMod_tenantId', null)
63 execution.setVariable('DOUPVfMod_volumeGroupId', null)
64 execution.setVariable('DOUPVfMod_vfModule', null)
65 execution.setVariable('DOUPVfMod_vnfParams', null)
66 execution.setVariable("DOUPVfMod_baseVfModuleId", "")
67 execution.setVariable("DOUPVfMod_baseVfModuleHeatStackId", "")
68 execution.setVariable('DOUPVfMod_prepareUpdateAAIVfModuleRequest', null)
69 execution.setVariable('DOUPVfMod_sdncChangeAssignRequest', null)
70 execution.setVariable('DOUPVfMod_sdncChangeAssignResponse', null)
71 execution.setVariable('DOUPVfMod_sdncActivateRequest', null)
72 execution.setVariable('DOUPVfMod_sdncActivateResponse', null)
73 execution.setVariable('DOUPVfMod_sdncTopologyRequest', null)
74 execution.setVariable('DOUPVfMod_sdncTopologyResponse', null)
75 execution.setVariable('DOUPVfMod_vnfAdapterRestRequest', null)
76 execution.setVariable('DOUPVfMod_updateAAIGenericVnfRequest', null)
77 execution.setVariable('DOUPVfMod_updateAAIVfModuleRequest', null)
78 execution.setVariable('DOUPVfMod_skipUpdateGenericVnf', false)
79 execution.setVariable('DoUpdateVfModuleSuccessIndicator', false)
83 * Check for missing elements in the received request.
85 * @param execution The flow's execution instance.
87 public void preProcessRequest(Execution execution) {
88 def method = getClass().getSimpleName() + '.preProcessRequest(' +
89 'execution=' + execution.getId() +
91 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
92 logDebug('Entered ' + method, isDebugLogEnabled)
95 initProcessVariables(execution)
96 def xml = getVariable(execution, 'DoUpdateVfModuleRequest')
97 utils.logAudit("DoUpdateVfModule request: " + xml)
98 logDebug('Received request xml:\n' + xml, isDebugLogEnabled)
100 def requestInfo = getRequiredNodeXml(execution, xml, 'request-info')
101 execution.setVariable('DOUPVfMod_requestInfo', requestInfo)
102 execution.setVariable('DOUPVfMod_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))
103 def serviceInstanceId = execution.getVariable('mso-service-instance-id')
104 if (serviceInstanceId == null) {
105 serviceInstanceId = ''
107 execution.setVariable('DOUPVfMod_serviceInstanceId', serviceInstanceId)
109 def vnfInputs = getRequiredNodeXml(execution, xml, 'vnf-inputs')
110 execution.setVariable('DOUPVfMod_vnfInputs', vnfInputs)
111 execution.setVariable('DOUPVfMod_vnfId', getRequiredNodeText(execution, vnfInputs, 'vnf-id'))
112 execution.setVariable('DOUPVfMod_vfModuleId', getRequiredNodeText(execution, vnfInputs, 'vf-module-id'))
113 execution.setVariable('DOUPVfMod_vfModuleName', getNodeTextForce(vnfInputs, 'vf-module-name'))
114 execution.setVariable('DOUPVfMod_vnfType', getNodeTextForce(vnfInputs, 'vnf-type'))
115 execution.setVariable('DOUPVfMod_vnfName', getNodeTextForce(vnfInputs, 'vnf-name'))
116 execution.setVariable('DOUPVfMod_asdcServiceModelVersion', getNodeTextForce(vnfInputs, 'asdc-service-model-version'))
117 execution.setVariable('DOUPVfMod_vfModuleModelName', getRequiredNodeText(execution, vnfInputs, 'vf-module-model-name'))
118 execution.setVariable('DOUPVfMod_modelCustomizationUuid', getNodeTextForce(vnfInputs, 'model-customization-id'))
119 execution.setVariable('DOUPVfMod_serviceId', getRequiredNodeText(execution, vnfInputs, 'service-id'))
120 execution.setVariable('DOUPVfMod_aicCloudRegion', getRequiredNodeText(execution, vnfInputs, 'aic-cloud-region'))
121 execution.setVariable('DOUPVfMod_tenantId', getRequiredNodeText(execution, vnfInputs, 'tenant-id'))
123 def isBaseVfModule = "false"
124 if (utils.nodeExists(xml, "is-base-vf-module")) {
125 isBaseVfModule = utils.getNodeText(xml, "is-base-vf-module")
126 execution.setVariable("DOUPVfMod_isBaseVfModule", isBaseVfModule)
128 logDebug("isBaseVfModule: " + isBaseVfModule, isDebugLogEnabled)
130 NetworkUtils networkUtils = new NetworkUtils()
131 def backoutOnFailure = networkUtils.isRollbackEnabled(execution, xml)
132 execution.setVariable("DOUPVfMod_backoutOnFailure", backoutOnFailure)
134 def String vgi = getNodeTextForce(vnfInputs, 'volume-group-id')
135 execution.setVariable('DOUPVfMod_volumeGroupId', vgi)
137 execution.setVariable('DOUPVfMod_vnfParams', utils.getNodeXml(xml, 'vnf-params', false))
139 def sdncCallbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
140 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
141 def msg = 'Required variable \'URN_mso_workflow_sdncadapter_callback\' is missing'
143 createWorkflowException(execution, 2000, msg)
146 logDebug('Exited ' + method, isDebugLogEnabled)
147 } catch (BpmnError e) {
149 } catch (Exception e) {
150 logError('Caught exception in ' + method, e)
151 createWorkflowException(execution, 1002, 'Error in preProcessRequest(): ' + e.getMessage())
156 * Prepare a Request for invoking the PrepareUpdateAAIVfModule subflow. This will
157 * set the orchestration-status to 'pending-update'.
159 * @param execution The flow's execution instance.
161 public void prepPrepareUpdateAAIVfModule(Execution execution) {
162 def method = getClass().getSimpleName() + '.preparePrepareUpdateAAIVfModule(' +
163 'execution=' + execution.getId() +
165 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
166 logDebug('Entered ' + method, isDebugLogEnabled)
169 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
170 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
171 def orchestrationStatus = 'pending-update'
173 String prepareUpdateAAIVfModuleRequest = """
174 <PrepareUpdateAAIVfModuleRequest>
175 <vnf-id>${vnfId}</vnf-id>
176 <vf-module-id>${vfModuleId}</vf-module-id>
177 <orchestration-status>${orchestrationStatus}</orchestration-status>
178 </PrepareUpdateAAIVfModuleRequest>
180 prepareUpdateAAIVfModuleRequest = utils.formatXml(prepareUpdateAAIVfModuleRequest)
181 execution.setVariable('DOUPVfMod_prepareUpdateAAIVfModuleRequest', prepareUpdateAAIVfModuleRequest)
182 utils.logAudit("DoUpdateAAIVfModule request: " + prepareUpdateAAIVfModuleRequest)
183 logDebug('Request for PrepareUpdateAAIVfModule:\n' + prepareUpdateAAIVfModuleRequest, isDebugLogEnabled)
185 logDebug('Exited ' + method, isDebugLogEnabled)
186 } catch (BpmnError e) {
188 } catch (Exception e) {
189 logError('Caught exception in ' + method, e)
190 createWorkflowException(execution, 1002, 'Error in preparePrepareUpdateAAIVfModule(): ' + e.getMessage())
195 * Prepare a Request for invoking the ConfirmVolumeGroupTenant subflow. Currently,
196 * there is really nothing to do, so we just log that we're passing through.
198 * @param execution The flow's execution instance.
200 public void prepConfirmVolumeGroupTenant(Execution execution) {
201 def method = getClass().getSimpleName() + '.prepConfirmVolumeGroupTenant(' +
202 'execution=' + execution.getId() +
204 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
205 logDebug('Entered ' + method, isDebugLogEnabled)
208 // Nothing to do - just log that we're passing through here
210 logDebug('Exited ' + method, isDebugLogEnabled)
211 } catch (BpmnError e) {
213 } catch (Exception e) {
214 logError('Caught exception in ' + method, e)
215 createWorkflowException(execution, 1002, 'Error in prepConfirmVolumeGroupTenant(): ' + e.getMessage())
220 * Prepare a Request for invoking the SDNC Adapter subflow to perform
221 * a VNF topology 'changeassign' operation.
223 * @param execution The flow's execution instance.
225 public void prepSDNCTopologyChg(Execution execution) {
226 def method = getClass().getSimpleName() + '.prepSDNCTopologyChg(' +
227 'execution=' + execution.getId() +
229 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
230 logDebug('Entered ' + method, isDebugLogEnabled)
233 def requestId = execution.getVariable('DOUPVfMod_requestId')
234 def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
235 def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
236 def serviceId = execution.getVariable('DOUPVfMod_serviceId')
237 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
238 def vnfType = execution.getVariable('DOUPVfMod_vnfType')
239 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
240 def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName')
241 def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
242 def vfModuleName = vfModule.getElementText('vf-module-name')
243 def tenantId = execution.getVariable('DOUPVfMod_tenantId')
244 def aicCloudRegion = execution.getVariable('DOUPVfMod_aicCloudRegion')
246 // Retrieve vnf name from AAI response
247 def vnfName = execution.getVariable('DOUPVfMod_vnfNameFromAAI')
248 execution.setVariable('DOUPVfMod_vnfName', vnfName)
250 def vnfParamsXml = execution.getVariable('DOUPVfMod_vnfParams')
251 def vnfNetworks = transformNetworkParamsToVnfNetworks(vnfParamsXml)
253 String sdncTopologyRequest = """
254 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
255 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
256 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
257 <sdncadapter:RequestHeader>
258 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
259 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
260 <sdncadapter:SvcAction>changeassign</sdncadapter:SvcAction>
261 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
262 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
263 </sdncadapter:RequestHeader>
264 <sdncadapterworkflow:SDNCRequestData>
265 <request-information>
266 <request-id>${requestId}</request-id>
267 <request-action>ChangeVNFActivateRequest</request-action>
268 <source>PORTAL</source>
272 </request-information>
273 <service-information>
274 <service-type>${serviceId}</service-type>
275 <service-instance-id>${vnfId}</service-instance-id>
276 <subscriber-name>dontcare</subscriber-name>
277 </service-information>
278 <vnf-request-information>
279 <vnf-id>${vfModuleId}</vnf-id>
280 <vnf-type>${vfModuleModelName}</vnf-type>
281 <vnf-name>${vfModuleName}</vnf-name>
282 <generic-vnf-id>${vnfId}</generic-vnf-id>
283 <generic-vnf-name>${vnfName}</generic-vnf-name>
284 <generic-vnf-type>${vnfType}</generic-vnf-type>
285 <tenant>${tenantId}</tenant>
286 <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>
288 </vnf-request-information>
289 </sdncadapterworkflow:SDNCRequestData>
290 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
292 sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
293 execution.setVariable('DOUPVfMod_sdncChangeAssignRequest', sdncTopologyRequest)
294 utils.logAudit("sdncChangeAssignRequest : " + sdncTopologyRequest)
295 logDebug('Request for SDNCAdapter topology/changeassign:\n' + sdncTopologyRequest, isDebugLogEnabled)
297 logDebug('Exited ' + method, isDebugLogEnabled)
298 } catch (BpmnError e) {
300 } catch (Exception e) {
301 logError('Caught exception in ' + method, e)
302 createWorkflowException(execution, 1002, 'Error in prepSDNCTopologyChg(): ' + e.getMessage())
307 * Prepare a Request for invoking the SDNC Adapter subflow to perform
308 * a VNF topology 'query' operation.
310 * @param execution The flow's execution instance.
312 public void prepSDNCTopologyQuery(Execution execution) {
313 def method = getClass().getSimpleName() + '.prepSDNCTopologyQuery(' +
314 'execution=' + execution.getId() +
316 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
317 logDebug('Entered ' + method, isDebugLogEnabled)
320 def requestId = execution.getVariable('DOUPVfMod_requestId')
321 def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
322 def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
323 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
326 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
327 svcInstId = vfModuleId
330 svcInstId = serviceInstanceId
333 //!!!! TEMPORARY WORKAROUND FOR SDNC REPLICATION ISSUE
336 String sdncTopologyRequest = """
337 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
338 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
339 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
340 <sdncadapter:RequestHeader>
341 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
342 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
343 <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
344 <sdncadapter:SvcOperation>/VNF-API:vnfs/vnf-list/${vfModuleId}</sdncadapter:SvcOperation>
345 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
346 <sdncadapter:MsoAction>mobility</sdncadapter:MsoAction>
347 </sdncadapter:RequestHeader>
348 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
350 sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
351 execution.setVariable('DOUPVfMod_sdncTopologyRequest', sdncTopologyRequest)
352 utils.logAudit("sdncTopologyRequest : " + sdncTopologyRequest)
353 logDebug('Request for SDNCAdapter query:\n' + sdncTopologyRequest, isDebugLogEnabled)
355 logDebug('Exited ' + method, isDebugLogEnabled)
356 } catch (BpmnError e) {
358 } catch (Exception e) {
359 logError('Caught exception in ' + method, e)
360 createWorkflowException(execution, 1002, 'Error in prepSDNCTopologyQuery(): ' + e.getMessage())
365 * Prepare a Request for invoking the VnfAdapterRest subflow.
367 * @param execution The flow's execution instance.
369 public void prepVnfAdapterRest(Execution execution) {
370 def method = getClass().getSimpleName() + '.prepVnfAdapterRest(' +
371 'execution=' + execution.getId() +
373 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
374 logDebug('Entered ' + method, isDebugLogEnabled)
377 def requestId = execution.getVariable('DOUPVfMod_requestId')
378 def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
379 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
380 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
381 def vfModuleName = execution.getVariable('DOUPVfMod_vfModuleName')
382 def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
383 def tenantId = execution.getVariable('DOUPVfMod_tenantId')
384 def volumeGroupId = execution.getVariable('DOUPVfMod_volumeGroupId')
385 def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
386 def heatStackId = vfModule.getElementText('heat-stack-id')
387 def cloudId = execution.getVariable('DOUPVfMod_aicCloudRegion')
388 def vnfType = execution.getVariable('DOUPVfMod_vnfType')
389 def vnfName = execution.getVariable('DOUPVfMod_vnfName')
390 def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName')
391 def baseVfModuleId = execution.getVariable("DOUPVfMod_baseVfModuleId")
392 def baseVfModuleStackId = execution.getVariable("DOUPVfMod_baseVfModuleHeatStackId")
393 def asdcServiceModelVersion = execution.getVariable('DOUPVfMod_asdcServiceModelVersion')
394 def modelCustomizationUuid = execution.getVariable('DOUPVfMod_modelCustomizationUuid')
395 def backoutOnFailure = execution.getVariable("DOUPVfMod_backoutOnFailure")
397 def vnfParamsXml = execution.getVariable('DOUPVfMod_vnfParams')
398 def vfModuleParamsEntries = transformParamsToEntries(vnfParamsXml)
400 def messageId = execution.getVariable('mso-request-id') + '-' + System.currentTimeMillis()
401 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
402 def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
403 if ('true'.equals(useQualifiedHostName)) {
404 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
407 String sdncGetResponse = execution.getVariable('DOUPVfMod_sdncTopologyResponse')
409 String vfModuleParams = buildVfModuleParams(vfModuleParamsEntries, sdncGetResponse, vnfId, vnfName,
410 vfModuleId, vfModuleName)
413 String vnfAdapterRestRequest = """
414 <updateVfModuleRequest>
415 <cloudSiteId>${cloudId}</cloudSiteId>
416 <tenantId>${tenantId}</tenantId>
417 <vnfId>${vnfId}</vnfId>
418 <vfModuleId>${vfModuleId}</vfModuleId>
419 <vfModuleStackId>${heatStackId}</vfModuleStackId>
420 <vnfType>${vnfType}</vnfType>
421 <vnfVersion>${asdcServiceModelVersion}</vnfVersion>
422 <modelCustomizationUuid>${modelCustomizationUuid}</modelCustomizationUuid>
423 <vfModuleType>${vfModuleModelName}</vfModuleType>
424 <volumeGroupId>${volumeGroupId}</volumeGroupId>
425 <baseVfModuleId>${baseVfModuleId}</baseVfModuleId>
426 <baseVfModuleStackId>${baseVfModuleStackId}</baseVfModuleStackId>
427 <skipAAI>true</skipAAI>
428 <backout>${backoutOnFailure}</backout>
429 <failIfExists>false</failIfExists>
434 <requestId>${requestId}</requestId>
435 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
437 <messageId>${messageId}</messageId>
438 <notificationUrl>${notificationUrl}</notificationUrl>
439 </updateVfModuleRequest>
441 vnfAdapterRestRequest = utils.formatXml(vnfAdapterRestRequest)
442 execution.setVariable('DOUPVfMod_vnfAdapterRestRequest', vnfAdapterRestRequest)
443 utils.logAudit("vnfAdapterRestRequest : " + vnfAdapterRestRequest)
444 logDebug('Request for VNFAdapter Rest:\n' + vnfAdapterRestRequest, isDebugLogEnabled)
446 logDebug('Exited ' + method, isDebugLogEnabled)
447 } catch (BpmnError e) {
449 } catch (Exception e) {
450 logError('Caught exception in ' + method, e)
451 createWorkflowException(execution, 1002, 'Error in prepVnfAdapterRest(): ' + e.getMessage())
456 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
458 * @param execution The flow's execution instance.
460 public void prepUpdateAAIGenericVnf(Execution execution) {
461 def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
462 'execution=' + execution.getId() +
464 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
465 logDebug('Entered ' + method, isDebugLogEnabled)
468 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
469 def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
471 def personaModelId = utils.getNodeText1(vnfInputs, 'vnf-persona-model-id')
472 def personaModelVersion = utils.getNodeText1(vnfInputs, 'vnf-persona-model-version')
473 if ((personaModelId == null) || (personaModelVersion == null)) {
474 logDebug('Skipping update for Generic VNF ' + vnfId +
475 ' because either \'vnf-persona-model-id\' or \'vnf-persona-model-version\' is absent', isDebugLogEnabled)
476 execution.setVariable('DOUPVfMod_skipUpdateGenericVnf', true)
478 def personaModelIdElement = '<persona-model-id>' + personaModelId + '</persona-model-id>'
479 def personaModelVersionElement = '<persona-model-version>' + personaModelVersion + '</persona-model-version>'
481 String updateAAIGenericVnfRequest = """
482 <UpdateAAIGenericVnfRequest>
483 <vnf-id>${vnfId}</vnf-id>
484 ${personaModelIdElement}
485 ${personaModelVersionElement}
486 </UpdateAAIGenericVnfRequest>
488 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
489 execution.setVariable('DOUPVfMod_updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
490 utils.logAudit("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
491 logDebug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest, isDebugLogEnabled)
494 logDebug('Exited ' + method, isDebugLogEnabled)
495 } catch (BpmnError e) {
497 } catch (Exception e) {
498 logError('Caught exception in ' + method, e)
499 createWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
504 * Prepare a Request for invoking the UpdateAAIVfModule subflow.
506 * @param execution The flow's execution instance.
508 public void prepUpdateAAIVfModule(Execution execution) {
509 def method = getClass().getSimpleName() + '.prepUpdateAAIVfModule(' +
510 'execution=' + execution.getId() +
512 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
513 logDebug('Entered ' + method, isDebugLogEnabled)
516 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
517 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
518 def orchestrationStatus = 'updated'
519 def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
521 def volumeGroupIdElement = ''
522 def volumeGroupId = execution.getVariable('DOUPVfMod_volumeGroupId')
523 if (volumeGroupId != null) {
524 volumeGroupIdElement = '<volume-group-id>' + volumeGroupId + '</volume-group-id>'
526 def personaModelIdElement = ''
527 def personaModelId = utils.getNodeText1(vnfInputs, 'persona-model-id')
528 if (personaModelId != null) {
529 personaModelIdElement = '<persona-model-id>' + personaModelId + '</persona-model-id>'
531 def personaModelVersionElement = ''
532 def personaModelVersion = utils.getNodeText1(vnfInputs, 'persona-model-version')
533 if (personaModelVersion != null) {
534 personaModelVersionElement = '<persona-model-version>' + personaModelVersion + '</persona-model-version>'
536 def contrailServiceInstanceFqdnElement = ''
537 def contrailServiceInstanceFqdn = utils.getNodeText1(vnfInputs, 'contrail-service-instance-fqdn')
538 if (contrailServiceInstanceFqdn != null) {
539 contrailServiceInstanceFqdnElement = '<contrail-service-instance-fqdn>' + contrailServiceInstanceFqdn + '</contrail-service-instance-fqdn>'
541 def personaModelCustomizationIdElement = ''
542 def modelCustomizationId = execution.getVariable('DOUPVfMod_modelCustomizationUuid')
543 if (modelCustomizationId != null) {
544 personaModelCustomizationIdElement = '<persona-model-customization-id>' + modelCustomizationId + '</persona-model-customization-id>'
547 String updateAAIVfModuleRequest = """
548 <UpdateAAIVfModuleRequest>
549 <vnf-id>${vnfId}</vnf-id>
550 <vf-module-id>${vfModuleId}</vf-module-id>
551 <orchestration-status>${orchestrationStatus}</orchestration-status>
552 ${volumeGroupIdElement}
553 ${personaModelIdElement}
554 ${personaModelVersionElement}
555 ${contrailServiceInstanceFqdnElement}
556 ${personaModelCustomizationIdElement}
557 </UpdateAAIVfModuleRequest>
559 updateAAIVfModuleRequest = utils.formatXml(updateAAIVfModuleRequest)
560 execution.setVariable('DOUPVfMod_updateAAIVfModuleRequest', updateAAIVfModuleRequest)
561 utils.logAudit("updateAAIVfModuleRequest : " + updateAAIVfModuleRequest)
562 logDebug('Request for UpdateAAIVfModule:\n' + updateAAIVfModuleRequest, isDebugLogEnabled)
564 logDebug('Exited ' + method, isDebugLogEnabled)
565 } catch (BpmnError e) {
567 } catch (Exception e) {
568 logError('Caught exception in ' + method, e)
569 createWorkflowException(execution, 1002, 'Error in prepUpdateAAIVfModule(): ' + e.getMessage())
574 * Prepare a Request for invoking the SDNC Adapter subflow to perform
575 * a VNF topology 'activate' operation.
577 * @param execution The flow's execution instance.
579 public void prepSDNCTopologyAct(Execution execution) {
580 def method = getClass().getSimpleName() + '.prepSDNCTopologyAct(' +
581 'execution=' + execution.getId() +
583 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
584 logDebug('Entered ' + method, isDebugLogEnabled)
587 def requestId = execution.getVariable('DOUPVfMod_requestId')
588 def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
589 def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
590 def serviceId = execution.getVariable('DOUPVfMod_serviceId')
591 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
592 def vnfName = execution.getVariable('DOUPVfMod_vnfName')
593 def vnfType = execution.getVariable('DOUPVfMod_vnfType')
594 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
595 def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName')
596 def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
597 def vfModuleName = vfModule.getElementText('vf-module-name')
598 def tenantId = execution.getVariable('DOUPVfMod_tenantId')
599 def aicCloudRegion = execution.getVariable('DOUPVfMod_aicCloudRegion')
601 def vnfParamsXml = execution.getVariable('DOUPVfMod_vnfParams')
602 def vnfNetworks = transformNetworkParamsToVnfNetworks(vnfParamsXml)
604 String sdncTopologyRequest = """
605 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
606 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
607 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
608 <sdncadapter:RequestHeader>
609 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
610 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
611 <sdncadapter:SvcAction>activate</sdncadapter:SvcAction>
612 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
613 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
614 </sdncadapter:RequestHeader>
615 <sdncadapterworkflow:SDNCRequestData>
616 <request-information>
617 <request-id>${requestId}</request-id>
618 <request-action>ChangeVNFActivateRequest</request-action>
619 <source>PORTAL</source>
623 </request-information>
624 <service-information>
625 <service-type>${serviceId}</service-type>
626 <service-instance-id>${vnfId}</service-instance-id>
627 <subscriber-name>dontcare</subscriber-name>
628 </service-information>
629 <vnf-request-information>
630 <vnf-id>${vfModuleId}</vnf-id>
631 <vnf-type>${vfModuleModelName}</vnf-type>
632 <vnf-name>${vfModuleName}</vnf-name>
633 <generic-vnf-id>${vnfId}</generic-vnf-id>
634 <generic-vnf-name>${vnfName}</generic-vnf-name>
635 <generic-vnf-type>${vnfType}</generic-vnf-type>
636 <tenant>${tenantId}</tenant>
637 <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>
638 </vnf-request-information>
639 </sdncadapterworkflow:SDNCRequestData>
640 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
642 sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
643 execution.setVariable('DOUPVfMod_sdncActivateRequest', sdncTopologyRequest)
644 utils.logAudit("sdncActivateRequest : " + sdncTopologyRequest)
645 logDebug('Request for SDNCAdapter topology/activate:\n' + sdncTopologyRequest, isDebugLogEnabled)
648 logDebug('Exited ' + method, isDebugLogEnabled)
649 } catch (BpmnError e) {
651 } catch (Exception e) {
652 logError('Caught exception in ' + method, e)
653 createWorkflowException(execution, 1002, 'Error in prepSDNCTopologyAct(): ' + e.getMessage())
658 * Log a WorkflowException that has been created.
660 * @param execution The flow's execution instance.
662 public void handleWorkflowException(Execution execution) {
663 def method = getClass().getSimpleName() + '.handleWorkflowException(' +
664 'execution=' + execution.getId() +
666 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
667 logDebug('Entered ' + method, isDebugLogEnabled)
670 def WorkflowException workflowException = (WorkflowException) execution.getVariable('WorkflowException')
671 logError(method + ' caught WorkflowException: ' + workflowException.getErrorMessage())
673 logDebug('Exited ' + method, isDebugLogEnabled)
674 } catch (BpmnError e) {
676 } catch (Exception e) {
677 logError('Caught exception in ' + method, e)
678 createWorkflowException(execution, 1002, 'Error in handleWorkflowException(): ' + e.getMessage())
682 public void validateSDNCResponse(Execution execution, String response, String method){
683 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
684 def prefix = execution.getVariable("prefix")
686 logDebug(" *** STARTED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
688 WorkflowException workflowException = execution.getVariable("WorkflowException")
689 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
691 utils.logAudit("workflowException: " + workflowException)
693 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
694 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
696 utils.logAudit("SDNCResponse: " + response)
698 String sdncResponse = response
699 if(execution.getVariable(prefix + 'sdncResponseSuccess') == true){
700 logDebug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse, isDebugLogEnabled)
702 logDebug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
703 throw new BpmnError("MSOWorkflowException")
705 logDebug(" *** COMPLETED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
709 * Using the received vnfId and vfModuleId, query AAI to get the corresponding VNF info.
710 * A 200 response is expected with the VNF info in the response body. Will find out the base module info.
712 * @param execution The flow's execution instance.
714 public void queryAAIVfModule(Execution execution) {
715 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
716 def method = getClass().getSimpleName() + '.getVfModule(' +
717 'execution=' + execution.getId() +
719 logDebug('Entered ' + method, isDebugLogEnabled)
722 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
723 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
725 AaiUtil aaiUriUtil = new AaiUtil(this)
726 String aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
727 logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
729 String endPoint = execution.getVariable("URN_aai_endpoint") + "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8") + "?depth=1"
730 utils.logAudit("AAI endPoint: " + endPoint)
733 def aaiRequestId = UUID.randomUUID().toString()
734 logDebug('sending GET to AAI endpoint \'' + endPoint + '\'', isDebugLogEnabled)
735 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, endPoint)
736 utils.logAudit("createVfModule - invoking httpGet() to AAI")
738 def responseData = response.getResponseBodyAsString()
739 if (responseData != null) {
740 logDebug("Received generic VNF data: " + responseData, isDebugLogEnabled)
744 utils.logAudit("createVfModule - queryAAIVfModule Response: " + responseData)
745 utils.logAudit("createVfModule - queryAAIVfModule ResponseCode: " + response.getStatusCode())
747 execution.setVariable('DOUPVfMod_queryAAIVfModuleResponseCode', response.getStatusCode())
748 execution.setVariable('DOUPVfMod_queryAAIVfModuleResponse', responseData)
749 logDebug('Response code:' + response.getStatusCode(), isDebugLogEnabled)
750 logDebug('Response:' + System.lineSeparator() + responseData, isDebugLogEnabled)
751 if (response.getStatusCode() == 200) {
752 // Parse the VNF record from A&AI to find base module info
753 logDebug('Parsing the VNF data to find base module info', isDebugLogEnabled)
754 if (responseData != null) {
755 def vfModulesText = utils.getNodeXml(responseData, "vf-modules")
756 def xmlVfModules= new XmlSlurper().parseText(vfModulesText)
757 def vfModules = xmlVfModules.'**'.findAll {it.name() == "vf-module"}
758 int vfModulesSize = 0
759 for (i in 0..vfModules.size()-1) {
760 def vfModuleXml = groovy.xml.XmlUtil.serialize(vfModules[i])
761 def isBaseVfModule = utils.getNodeText(vfModuleXml, "is-base-vf-module")
763 if (isBaseVfModule == "true") {
764 String baseModuleId = utils.getNodeText1(vfModuleXml, "vf-module-id")
765 execution.setVariable("DOUPVfMod_baseVfModuleId", baseModuleId)
766 logDebug('Received baseVfModuleId: ' + baseModuleId, isDebugLogEnabled)
767 String baseModuleHeatStackId = utils.getNodeText1(vfModuleXml, "heat-stack-id")
768 execution.setVariable("DOUPVfMod_baseVfModuleHeatStackId", baseModuleHeatStackId)
769 logDebug('Received baseVfModuleHeatStackId: ' + baseModuleHeatStackId, isDebugLogEnabled)
774 } catch (Exception ex) {
776 logDebug('Exception occurred while executing AAI GET:' + ex.getMessage(),isDebugLogEnabled)
777 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
779 logDebug('Exited ' + method, isDebugLogEnabled)
780 } catch (BpmnError e) {
782 } catch (Exception e) {
783 logError('Caught exception in ' + method, e)
784 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModule(): ' + e.getMessage())