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.bpmn.core.json.JsonUtils;
33 import org.openecomp.mso.rest.APIResponse
34 import org.springframework.web.util.UriUtils
36 public class DoUpdateVfModule extends VfModuleBase {
38 ExceptionUtil exceptionUtil = new ExceptionUtil()
41 * Initialize the flow's variables.
43 * @param execution The flow's execution instance.
45 public void initProcessVariables(Execution execution) {
46 execution.setVariable('prefix', 'DOUPVfMod_')
47 execution.setVariable('DOUPVfMod_requestInfo', null)
48 execution.setVariable('DOUPVfMod_serviceInstanceId', null)
49 execution.setVariable('DOUPVfMod_requestId', null)
50 execution.setVariable('DOUPVfMod_vnfInputs', null)
51 execution.setVariable('DOUPVfMod_vnfId', null)
52 execution.setVariable('DOUPVfMod_vnfName', null)
53 execution.setVariable('DOUPVfMod_vnfNameFromAAI', null)
54 execution.setVariable('DOUPVfMod_vfModuleName', null)
55 execution.setVariable('DOUPVfMod_vfModuleId', null)
56 execution.setVariable('DOUPVfMod_vnfType', null)
57 execution.setVariable('DOUPVfMod_asdcServiceModelVersion', null)
58 execution.setVariable('DOUPVfMod_vfModuleModelName', null)
59 execution.setVariable('DOUPVfMod_modelCustomizationUuid', null)
60 execution.setVariable("DOUPVfMod_isBaseVfModule", "false")
61 execution.setVariable('DOUPVfMod_serviceId', null)
62 execution.setVariable('DOUPVfMod_aicCloudRegion', null)
63 execution.setVariable('DOUPVfMod_tenantId', null)
64 execution.setVariable('DOUPVfMod_volumeGroupId', null)
65 execution.setVariable('DOUPVfMod_vfModule', null)
66 execution.setVariable('DOUPVfMod_vnfParams', null)
67 execution.setVariable("DOUPVfMod_baseVfModuleId", "")
68 execution.setVariable("DOUPVfMod_baseVfModuleHeatStackId", "")
69 execution.setVariable('DOUPVfMod_prepareUpdateAAIVfModuleRequest', null)
70 execution.setVariable('DOUPVfMod_sdncChangeAssignRequest', null)
71 execution.setVariable('DOUPVfMod_sdncChangeAssignResponse', null)
72 execution.setVariable('DOUPVfMod_sdncActivateRequest', null)
73 execution.setVariable('DOUPVfMod_sdncActivateResponse', null)
74 execution.setVariable('DOUPVfMod_sdncTopologyRequest', null)
75 execution.setVariable('DOUPVfMod_sdncTopologyResponse', null)
76 execution.setVariable('DOUPVfMod_vnfAdapterRestRequest', null)
77 execution.setVariable('DOUPVfMod_updateAAIGenericVnfRequest', null)
78 execution.setVariable('DOUPVfMod_updateAAIVfModuleRequest', null)
79 execution.setVariable('DOUPVfMod_skipUpdateGenericVnf', false)
80 execution.setVariable('DoUpdateVfModuleSuccessIndicator', false)
84 * Check for missing elements in the received request.
86 * @param execution The flow's execution instance.
88 public void preProcessRequest(Execution execution) {
89 def method = getClass().getSimpleName() + '.preProcessRequest(' +
90 'execution=' + execution.getId() +
92 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
93 logDebug('Entered ' + method, isDebugLogEnabled)
96 initProcessVariables(execution)
97 def xml = getVariable(execution, 'DoUpdateVfModuleRequest')
98 utils.logAudit("DoUpdateVfModule request: " + xml)
99 logDebug('Received request xml:\n' + xml, isDebugLogEnabled)
101 if (xml == null || xml.isEmpty()) {
102 // Building Block-type request
104 String cloudConfiguration = execution.getVariable("cloudConfiguration")
105 String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
107 def serviceModelInfo = execution.getVariable("serviceModelInfo")
108 logDebug("serviceModelInfo: " + serviceModelInfo, isDebugLogEnabled)
109 def vnfModelInfo = execution.getVariable("vnfModelInfo")
113 def tenantId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.tenantId")
114 execution.setVariable("DOUPVfMod_tenantId", tenantId)
117 def volumeGroupId = execution.getVariable("volumeGroupId")
118 execution.setVariable("DOUPVfMod_volumeGroupId", volumeGroupId)
120 def volumeGroupName = execution.getVariable("volumeGroupName")
121 execution.setVariable("DOUPVfMod_volumeGroupName", volumeGroupName)
123 def cloudSiteId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.lcpCloudRegionId")
124 execution.setVariable("DOUPVfMod_cloudSiteId", cloudSiteId)
126 logDebug("cloudSiteId: " + cloudSiteId, isDebugLogEnabled)
128 def vnfType = execution.getVariable("vnfType")
129 execution.setVariable("DOUPVfMod_vnfType", vnfType)
131 logDebug("vnfType: " + vnfType, isDebugLogEnabled)
133 def vnfName = execution.getVariable("vnfName")
134 execution.setVariable("DOUPVfMod_vnfName", vnfName)
136 logDebug("vnfName: " + vnfName, isDebugLogEnabled)
138 def vnfId = execution.getVariable("vnfId")
139 execution.setVariable("DOUPVfMod_vnfId", vnfId)
141 logDebug("vnfId: " + vnfId, isDebugLogEnabled)
143 def vfModuleName = execution.getVariable("vfModuleName")
144 execution.setVariable("DOUPVfMod_vfModuleName", vfModuleName)
146 logDebug("vfModuleName: " + vfModuleName, isDebugLogEnabled)
148 def vfModuleModelName = jsonUtil.getJsonValue(vfModuleModelInfo, "modelName")
149 execution.setVariable("DOUPVfMod_vfModuleModelName", vfModuleModelName)
151 logDebug("vfModuleModelName: " + vfModuleModelName, isDebugLogEnabled)
152 //modelCustomizationUuid
153 def modelCustomizationUuid = jsonUtil.getJsonValue(vfModuleModelInfo, "modelCustomizationId")
154 execution.setVariable("DOUPVfMod_modelCustomizationUuid", modelCustomizationUuid)
156 logDebug("modelCustomizationUuid: " + modelCustomizationUuid, isDebugLogEnabled)
158 def vfModuleId = execution.getVariable("vfModuleId")
159 execution.setVariable("DOUPVfMod_vfModuleId", vfModuleId)
160 logDebug("vfModuleId: " + vfModuleId, isDebugLogEnabled)
161 def requestId = execution.getVariable("requestId")
162 execution.setVariable("DOUPVfMod_requestId", requestId)
163 logDebug("requestId: " + requestId, isDebugLogEnabled)
164 // Set mso-request-id to request-id for VNF Adapter interface
165 execution.setVariable("mso-request-id", requestId)
167 def serviceId = execution.getVariable("serviceId")
168 execution.setVariable("DOUPVfMod_serviceId", serviceId)
169 logDebug("serviceId: " + serviceId, isDebugLogEnabled)
171 def serviceInstanceId = execution.getVariable("serviceInstanceId")
172 execution.setVariable("DOUPVfMod_serviceInstanceId", serviceInstanceId)
174 logDebug("serviceInstanceId: " + serviceInstanceId, isDebugLogEnabled)
177 execution.setVariable("DOUPVfMod_source", source)
179 logDebug("source: " + source, isDebugLogEnabled)
181 def disableRollback = execution.getVariable("disableRollback")
182 def backoutOnFailure = true
183 if (disableRollback != null && disableRollback.equals("true")) {
184 backoutOnFailure = false
186 execution.setVariable("DOUPVfMod_backoutOnFailure", backoutOnFailure)
187 logDebug("backoutOnFailure: " + backoutOnFailure, isDebugLogEnabled)
189 def isBaseVfModule = execution.getVariable("isBaseVfModule")
190 execution.setVariable("DOUPVfMod_isBaseVfModule", isBaseVfModule)
191 logDebug("isBaseVfModule: " + isBaseVfModule, isDebugLogEnabled)
192 //asdcServiceModelVersion
193 def asdcServiceModelVersion = execution.getVariable("asdcServiceModelVersion")
194 execution.setVariable("DOUPVfMod_asdcServiceModelVersion", asdcServiceModelVersion)
195 logDebug("asdcServiceModelVersion: " + asdcServiceModelVersion, isDebugLogEnabled)
197 execution.setVariable("DOUPVfMod_personaModelId", jsonUtil.getJsonValue(vfModuleModelInfo, "modelInvariantId"))
198 //personaModelVersion
199 execution.setVariable("DOUPVfMod_personaModelVersion", jsonUtil.getJsonValue(vfModuleModelInfo, "modelVersion"))
200 //Get or Generate UUID
201 String uuid = execution.getVariable("DOUPVfMod_uuid")
203 uuid = UUID.randomUUID()
204 logDebug("Generated messageId (UUID) is: " + uuid, isDebugLogEnabled)
206 logDebug("Found messageId (UUID) is: " + uuid, isDebugLogEnabled)
209 String isVidRequest = execution.getVariable("isVidRequest")
211 if (isVidRequest == null || isVidRequest.isEmpty()) {
212 execution.setVariable("isVidRequest", "true")
215 String globalSubscriberId = execution.getVariable("globalSubscriberId")
216 execution.setVariable("DOUPVfMod_globalSubscriberId", globalSubscriberId)
217 logDebug("globalSubsrciberId: " + globalSubscriberId, isDebugLogEnabled)
219 String vnfQueryPath = execution.getVariable("vnfQueryPath")
220 execution.setVariable("DOUPVfMod_vnfQueryPath", vnfQueryPath)
221 logDebug("vnfQueryPath: " + vnfQueryPath, isDebugLogEnabled)
223 Map<String,String> vfModuleInputParams = execution.getVariable("vfModuleInputParams")
224 if (vfModuleInputParams != null) {
225 execution.setVariable("DOUPVfMod_vnfParamsMap", vfModuleInputParams)
230 def requestInfo = getRequiredNodeXml(execution, xml, 'request-info')
231 execution.setVariable('DOUPVfMod_requestInfo', requestInfo)
232 execution.setVariable('DOUPVfMod_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))
233 def serviceInstanceId = execution.getVariable('mso-service-instance-id')
234 if (serviceInstanceId == null) {
235 serviceInstanceId = ''
237 execution.setVariable('DOUPVfMod_serviceInstanceId', serviceInstanceId)
239 def vnfInputs = getRequiredNodeXml(execution, xml, 'vnf-inputs')
240 execution.setVariable('DOUPVfMod_vnfInputs', vnfInputs)
241 execution.setVariable('DOUPVfMod_vnfId', getRequiredNodeText(execution, vnfInputs, 'vnf-id'))
242 execution.setVariable('DOUPVfMod_vfModuleId', getRequiredNodeText(execution, vnfInputs, 'vf-module-id'))
243 execution.setVariable('DOUPVfMod_vfModuleName', getNodeTextForce(vnfInputs, 'vf-module-name'))
244 execution.setVariable('DOUPVfMod_vnfType', getNodeTextForce(vnfInputs, 'vnf-type'))
245 execution.setVariable('DOUPVfMod_vnfName', getNodeTextForce(vnfInputs, 'vnf-name'))
246 execution.setVariable('DOUPVfMod_asdcServiceModelVersion', getNodeTextForce(vnfInputs, 'asdc-service-model-version'))
247 execution.setVariable('DOUPVfMod_vfModuleModelName', getRequiredNodeText(execution, vnfInputs, 'vf-module-model-name'))
248 execution.setVariable('DOUPVfMod_modelCustomizationUuid', getNodeTextForce(vnfInputs, 'model-customization-id'))
249 execution.setVariable('DOUPVfMod_serviceId', getRequiredNodeText(execution, vnfInputs, 'service-id'))
250 execution.setVariable('DOUPVfMod_aicCloudRegion', getRequiredNodeText(execution, vnfInputs, 'aic-cloud-region'))
251 execution.setVariable('DOUPVfMod_tenantId', getRequiredNodeText(execution, vnfInputs, 'tenant-id'))
253 def isBaseVfModule = "false"
254 if (utils.nodeExists(xml, "is-base-vf-module")) {
255 isBaseVfModule = utils.getNodeText(xml, "is-base-vf-module")
256 execution.setVariable("DOUPVfMod_isBaseVfModule", isBaseVfModule)
258 logDebug("isBaseVfModule: " + isBaseVfModule, isDebugLogEnabled)
260 NetworkUtils networkUtils = new NetworkUtils()
261 def backoutOnFailure = networkUtils.isRollbackEnabled(execution, xml)
262 execution.setVariable("DOUPVfMod_backoutOnFailure", backoutOnFailure)
264 def String vgi = getNodeTextForce(vnfInputs, 'volume-group-id')
265 execution.setVariable('DOUPVfMod_volumeGroupId', vgi)
267 execution.setVariable('DOUPVfMod_vnfParams', utils.getNodeXml(xml, 'vnf-params', false))
270 def sdncCallbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
271 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
272 def msg = 'Required variable \'URN_mso_workflow_sdncadapter_callback\' is missing'
274 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
277 logDebug('Exited ' + method, isDebugLogEnabled)
278 } catch (BpmnError e) {
280 } catch (Exception e) {
281 logError('Caught exception in ' + method, e)
282 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessRequest(): ' + e.getMessage())
287 * Prepare a Request for invoking the PrepareUpdateAAIVfModule subflow. This will
288 * set the orchestration-status to 'pending-update'.
290 * @param execution The flow's execution instance.
292 public void prepPrepareUpdateAAIVfModule(Execution execution) {
293 def method = getClass().getSimpleName() + '.preparePrepareUpdateAAIVfModule(' +
294 'execution=' + execution.getId() +
296 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
297 logDebug('Entered ' + method, isDebugLogEnabled)
300 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
301 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
302 def orchestrationStatus = 'pending-update'
304 String prepareUpdateAAIVfModuleRequest = """
305 <PrepareUpdateAAIVfModuleRequest>
306 <vnf-id>${vnfId}</vnf-id>
307 <vf-module-id>${vfModuleId}</vf-module-id>
308 <orchestration-status>${orchestrationStatus}</orchestration-status>
309 </PrepareUpdateAAIVfModuleRequest>
311 prepareUpdateAAIVfModuleRequest = utils.formatXml(prepareUpdateAAIVfModuleRequest)
312 execution.setVariable('DOUPVfMod_prepareUpdateAAIVfModuleRequest', prepareUpdateAAIVfModuleRequest)
313 utils.logAudit("DoUpdateAAIVfModule request: " + prepareUpdateAAIVfModuleRequest)
314 logDebug('Request for PrepareUpdateAAIVfModule:\n' + prepareUpdateAAIVfModuleRequest, isDebugLogEnabled)
316 logDebug('Exited ' + method, isDebugLogEnabled)
317 } catch (BpmnError e) {
319 } catch (Exception e) {
320 logError('Caught exception in ' + method, e)
321 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preparePrepareUpdateAAIVfModule(): ' + e.getMessage())
326 * Prepare a Request for invoking the ConfirmVolumeGroupTenant subflow. Currently,
327 * there is really nothing to do, so we just log that we're passing through.
329 * @param execution The flow's execution instance.
331 public void prepConfirmVolumeGroupTenant(Execution execution) {
332 def method = getClass().getSimpleName() + '.prepConfirmVolumeGroupTenant(' +
333 'execution=' + execution.getId() +
335 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
336 logDebug('Entered ' + method, isDebugLogEnabled)
339 // Nothing to do - just log that we're passing through here
341 logDebug('Exited ' + method, isDebugLogEnabled)
342 } catch (BpmnError e) {
344 } catch (Exception e) {
345 logError('Caught exception in ' + method, e)
346 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepConfirmVolumeGroupTenant(): ' + e.getMessage())
351 * Prepare a Request for invoking the SDNC Adapter subflow to perform
352 * a VNF topology 'changeassign' operation.
354 * @param execution The flow's execution instance.
356 public void prepSDNCTopologyChg(Execution execution) {
357 def method = getClass().getSimpleName() + '.prepSDNCTopologyChg(' +
358 'execution=' + execution.getId() +
360 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
361 logDebug('Entered ' + method, isDebugLogEnabled)
364 def requestId = execution.getVariable('DOUPVfMod_requestId')
365 def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
366 def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
367 def serviceId = execution.getVariable('DOUPVfMod_serviceId')
368 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
369 def vnfType = execution.getVariable('DOUPVfMod_vnfType')
370 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
371 def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName')
372 def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
373 def vfModuleName = vfModule.getElementText('vf-module-name')
374 def tenantId = execution.getVariable('DOUPVfMod_tenantId')
375 def aicCloudRegion = execution.getVariable('DOUPVfMod_aicCloudRegion')
377 // Retrieve vnf name from AAI response
378 def vnfName = execution.getVariable('DOUPVfMod_vnfNameFromAAI')
379 execution.setVariable('DOUPVfMod_vnfName', vnfName)
381 def vnfParamsXml = execution.getVariable('DOUPVfMod_vnfParams')
382 def vnfNetworks = transformNetworkParamsToVnfNetworks(vnfParamsXml)
384 String sdncTopologyRequest = """
385 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
386 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
387 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
388 <sdncadapter:RequestHeader>
389 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
390 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
391 <sdncadapter:SvcAction>changeassign</sdncadapter:SvcAction>
392 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
393 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
394 </sdncadapter:RequestHeader>
395 <sdncadapterworkflow:SDNCRequestData>
396 <request-information>
397 <request-id>${requestId}</request-id>
398 <request-action>ChangeVNFActivateRequest</request-action>
399 <source>PORTAL</source>
403 </request-information>
404 <service-information>
405 <service-type>${serviceId}</service-type>
406 <service-instance-id>${vnfId}</service-instance-id>
407 <subscriber-name>dontcare</subscriber-name>
408 </service-information>
409 <vnf-request-information>
410 <vnf-id>${vfModuleId}</vnf-id>
411 <vnf-type>${vfModuleModelName}</vnf-type>
412 <vnf-name>${vfModuleName}</vnf-name>
413 <generic-vnf-id>${vnfId}</generic-vnf-id>
414 <generic-vnf-name>${vnfName}</generic-vnf-name>
415 <generic-vnf-type>${vnfType}</generic-vnf-type>
416 <tenant>${tenantId}</tenant>
417 <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>
419 </vnf-request-information>
420 </sdncadapterworkflow:SDNCRequestData>
421 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
423 sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
424 execution.setVariable('DOUPVfMod_sdncChangeAssignRequest', sdncTopologyRequest)
425 utils.logAudit("sdncChangeAssignRequest : " + sdncTopologyRequest)
426 logDebug('Request for SDNCAdapter topology/changeassign:\n' + sdncTopologyRequest, isDebugLogEnabled)
428 logDebug('Exited ' + method, isDebugLogEnabled)
429 } catch (BpmnError e) {
431 } catch (Exception e) {
432 logError('Caught exception in ' + method, e)
433 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepSDNCTopologyChg(): ' + e.getMessage())
438 * Prepare a Request for invoking the SDNC Adapter subflow to perform
439 * a VNF topology 'query' operation.
441 * @param execution The flow's execution instance.
443 public void prepSDNCTopologyQuery(Execution execution) {
444 def method = getClass().getSimpleName() + '.prepSDNCTopologyQuery(' +
445 'execution=' + execution.getId() +
447 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
448 logDebug('Entered ' + method, isDebugLogEnabled)
451 def requestId = execution.getVariable('DOUPVfMod_requestId')
452 def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
453 def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
454 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
457 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
458 svcInstId = vfModuleId
461 svcInstId = serviceInstanceId
464 //!!!! TEMPORARY WORKAROUND FOR SDNC REPLICATION ISSUE
467 String sdncTopologyRequest = """
468 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
469 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
470 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
471 <sdncadapter:RequestHeader>
472 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
473 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
474 <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
475 <sdncadapter:SvcOperation>/VNF-API:vnfs/vnf-list/${vfModuleId}</sdncadapter:SvcOperation>
476 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
477 <sdncadapter:MsoAction>mobility</sdncadapter:MsoAction>
478 </sdncadapter:RequestHeader>
479 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
481 sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
482 execution.setVariable('DOUPVfMod_sdncTopologyRequest', sdncTopologyRequest)
483 utils.logAudit("sdncTopologyRequest : " + sdncTopologyRequest)
484 logDebug('Request for SDNCAdapter query:\n' + sdncTopologyRequest, isDebugLogEnabled)
486 logDebug('Exited ' + method, isDebugLogEnabled)
487 } catch (BpmnError e) {
489 } catch (Exception e) {
490 logError('Caught exception in ' + method, e)
491 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepSDNCTopologyQuery(): ' + e.getMessage())
496 * Prepare a Request for invoking the VnfAdapterRest subflow.
498 * @param execution The flow's execution instance.
500 public void prepVnfAdapterRest(Execution execution) {
501 def method = getClass().getSimpleName() + '.prepVnfAdapterRest(' +
502 'execution=' + execution.getId() +
504 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
505 logDebug('Entered ' + method, isDebugLogEnabled)
508 def requestId = execution.getVariable('DOUPVfMod_requestId')
509 def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
510 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
511 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
512 def vfModuleName = execution.getVariable('DOUPVfMod_vfModuleName')
513 def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
514 def tenantId = execution.getVariable('DOUPVfMod_tenantId')
515 def volumeGroupId = execution.getVariable('DOUPVfMod_volumeGroupId')
516 def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
517 def heatStackId = vfModule.getElementText('heat-stack-id')
518 def cloudId = execution.getVariable('DOUPVfMod_aicCloudRegion')
519 def vnfType = execution.getVariable('DOUPVfMod_vnfType')
520 def vnfName = execution.getVariable('DOUPVfMod_vnfName')
521 def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName')
522 def baseVfModuleId = execution.getVariable("DOUPVfMod_baseVfModuleId")
523 def baseVfModuleStackId = execution.getVariable("DOUPVfMod_baseVfModuleHeatStackId")
524 def asdcServiceModelVersion = execution.getVariable('DOUPVfMod_asdcServiceModelVersion')
525 def modelCustomizationUuid = execution.getVariable('DOUPVfMod_modelCustomizationUuid')
526 def backoutOnFailure = execution.getVariable("DOUPVfMod_backoutOnFailure")
528 def messageId = execution.getVariable('mso-request-id') + '-' + System.currentTimeMillis()
529 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
530 def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
531 if ('true'.equals(useQualifiedHostName)) {
532 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
535 Map<String, String> vnfParamsMap = execution.getVariable("DOUPVfMod_vnfParamsMap")
537 String sdncGetResponse = execution.getVariable('DOUPVfMod_sdncTopologyResponse')
539 String vfModuleParams = buildVfModuleParams(vnfParamsMap, sdncGetResponse, vnfId, vnfName,
540 vfModuleId, vfModuleName, null)
543 String vnfAdapterRestRequest = """
544 <updateVfModuleRequest>
545 <cloudSiteId>${cloudId}</cloudSiteId>
546 <tenantId>${tenantId}</tenantId>
547 <vnfId>${vnfId}</vnfId>
548 <vfModuleId>${vfModuleId}</vfModuleId>
549 <vfModuleStackId>${heatStackId}</vfModuleStackId>
550 <vnfType>${vnfType}</vnfType>
551 <vnfVersion>${asdcServiceModelVersion}</vnfVersion>
552 <modelCustomizationUuid>${modelCustomizationUuid}</modelCustomizationUuid>
553 <vfModuleType>${vfModuleModelName}</vfModuleType>
554 <volumeGroupId>${volumeGroupId}</volumeGroupId>
555 <baseVfModuleId>${baseVfModuleId}</baseVfModuleId>
556 <baseVfModuleStackId>${baseVfModuleStackId}</baseVfModuleStackId>
557 <skipAAI>true</skipAAI>
558 <backout>${backoutOnFailure}</backout>
559 <failIfExists>false</failIfExists>
564 <requestId>${requestId}</requestId>
565 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
567 <messageId>${messageId}</messageId>
568 <notificationUrl>${notificationUrl}</notificationUrl>
569 </updateVfModuleRequest>
571 vnfAdapterRestRequest = utils.formatXml(vnfAdapterRestRequest)
572 execution.setVariable('DOUPVfMod_vnfAdapterRestRequest', vnfAdapterRestRequest)
573 utils.logAudit("vnfAdapterRestRequest : " + vnfAdapterRestRequest)
574 logDebug('Request for VNFAdapter Rest:\n' + vnfAdapterRestRequest, isDebugLogEnabled)
576 logDebug('Exited ' + method, isDebugLogEnabled)
577 } catch (BpmnError e) {
579 } catch (Exception e) {
580 logError('Caught exception in ' + method, e)
581 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepVnfAdapterRest(): ' + e.getMessage())
586 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
588 * @param execution The flow's execution instance.
590 public void prepUpdateAAIGenericVnf(Execution execution) {
591 def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
592 'execution=' + execution.getId() +
594 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
595 logDebug('Entered ' + method, isDebugLogEnabled)
598 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
599 def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
601 def personaModelId = utils.getNodeText1(vnfInputs, 'vnf-persona-model-id')
602 def personaModelVersion = utils.getNodeText1(vnfInputs, 'vnf-persona-model-version')
603 if ((personaModelId == null) || (personaModelVersion == null)) {
604 logDebug('Skipping update for Generic VNF ' + vnfId +
605 ' because either \'vnf-persona-model-id\' or \'vnf-persona-model-version\' is absent', isDebugLogEnabled)
606 execution.setVariable('DOUPVfMod_skipUpdateGenericVnf', true)
608 def personaModelIdElement = '<model-invariant-id>' + personaModelId + '</model-invariant-id>'
609 def personaModelVersionElement = '<model-version-id>' + personaModelVersion + '</model-version-id>'
611 String updateAAIGenericVnfRequest = """
612 <UpdateAAIGenericVnfRequest>
613 <vnf-id>${vnfId}</vnf-id>
614 ${personaModelIdElement}
615 ${personaModelVersionElement}
616 </UpdateAAIGenericVnfRequest>
618 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
619 execution.setVariable('DOUPVfMod_updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
620 utils.logAudit("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
621 logDebug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest, isDebugLogEnabled)
624 logDebug('Exited ' + method, isDebugLogEnabled)
625 } catch (BpmnError e) {
627 } catch (Exception e) {
628 logError('Caught exception in ' + method, e)
629 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
634 * Prepare a Request for invoking the UpdateAAIVfModule subflow.
636 * @param execution The flow's execution instance.
638 public void prepUpdateAAIVfModule(Execution execution) {
639 def method = getClass().getSimpleName() + '.prepUpdateAAIVfModule(' +
640 'execution=' + execution.getId() +
642 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
643 logDebug('Entered ' + method, isDebugLogEnabled)
646 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
647 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
648 def orchestrationStatus = 'updated'
649 def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
651 def volumeGroupIdElement = ''
652 def volumeGroupId = execution.getVariable('DOUPVfMod_volumeGroupId')
653 if (volumeGroupId != null) {
654 volumeGroupIdElement = '<volume-group-id>' + volumeGroupId + '</volume-group-id>'
656 def personaModelIdElement = ''
657 def personaModelId = utils.getNodeText1(vnfInputs, 'persona-model-id')
658 if (personaModelId != null) {
659 personaModelIdElement = '<model-invariant-id>' + personaModelId + '</model-invariant-id>'
661 def personaModelVersionElement = ''
662 def personaModelVersion = utils.getNodeText1(vnfInputs, 'persona-model-version')
663 if (personaModelVersion != null) {
664 personaModelVersionElement = '<model-version-id>' + personaModelVersion + '</model-version-id>'
666 def contrailServiceInstanceFqdnElement = ''
667 def contrailServiceInstanceFqdn = utils.getNodeText1(vnfInputs, 'contrail-service-instance-fqdn')
668 if (contrailServiceInstanceFqdn != null) {
669 contrailServiceInstanceFqdnElement = '<contrail-service-instance-fqdn>' + contrailServiceInstanceFqdn + '</contrail-service-instance-fqdn>'
671 def personaModelCustomizationIdElement = ''
672 def modelCustomizationId = execution.getVariable('DOUPVfMod_modelCustomizationUuid')
673 if (modelCustomizationId != null) {
674 personaModelCustomizationIdElement = '<persona-model-customization-id>' + modelCustomizationId + '</persona-model-customization-id>'
677 String updateAAIVfModuleRequest = """
678 <UpdateAAIVfModuleRequest>
679 <vnf-id>${vnfId}</vnf-id>
680 <vf-module-id>${vfModuleId}</vf-module-id>
681 <orchestration-status>${orchestrationStatus}</orchestration-status>
682 ${volumeGroupIdElement}
683 ${personaModelIdElement}
684 ${personaModelVersionElement}
685 ${contrailServiceInstanceFqdnElement}
686 ${personaModelCustomizationIdElement}
687 </UpdateAAIVfModuleRequest>
690 logDebug('Unformatted updateAAIVfModuleRequest: ' + updateAAIVfModuleRequest, isDebugLogEnabled)
691 updateAAIVfModuleRequest = utils.formatXml(updateAAIVfModuleRequest)
692 execution.setVariable('DOUPVfMod_updateAAIVfModuleRequest', updateAAIVfModuleRequest)
693 utils.logAudit("updateAAIVfModuleRequest : " + updateAAIVfModuleRequest)
694 logDebug('Request for UpdateAAIVfModule:\n' + updateAAIVfModuleRequest, isDebugLogEnabled)
696 logDebug('Exited ' + method, isDebugLogEnabled)
697 } catch (BpmnError e) {
699 } catch (Exception e) {
700 logError('Caught exception in ' + method, e)
701 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIVfModule(): ' + e.getMessage())
706 * Prepare a Request for invoking the SDNC Adapter subflow to perform
707 * a VNF topology 'activate' operation.
709 * @param execution The flow's execution instance.
711 public void prepSDNCTopologyAct(Execution execution) {
712 def method = getClass().getSimpleName() + '.prepSDNCTopologyAct(' +
713 'execution=' + execution.getId() +
715 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
716 logDebug('Entered ' + method, isDebugLogEnabled)
719 def requestId = execution.getVariable('DOUPVfMod_requestId')
720 def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
721 def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
722 def serviceId = execution.getVariable('DOUPVfMod_serviceId')
723 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
724 def vnfName = execution.getVariable('DOUPVfMod_vnfName')
725 def vnfType = execution.getVariable('DOUPVfMod_vnfType')
726 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
727 def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName')
728 def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
729 def vfModuleName = vfModule.getElementText('vf-module-name')
730 def tenantId = execution.getVariable('DOUPVfMod_tenantId')
731 def aicCloudRegion = execution.getVariable('DOUPVfMod_aicCloudRegion')
733 def vnfParamsXml = execution.getVariable('DOUPVfMod_vnfParams')
734 def vnfNetworks = transformNetworkParamsToVnfNetworks(vnfParamsXml)
736 String sdncTopologyRequest = """
737 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
738 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
739 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
740 <sdncadapter:RequestHeader>
741 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
742 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
743 <sdncadapter:SvcAction>activate</sdncadapter:SvcAction>
744 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
745 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
746 </sdncadapter:RequestHeader>
747 <sdncadapterworkflow:SDNCRequestData>
748 <request-information>
749 <request-id>${requestId}</request-id>
750 <request-action>ChangeVNFActivateRequest</request-action>
751 <source>PORTAL</source>
755 </request-information>
756 <service-information>
757 <service-type>${serviceId}</service-type>
758 <service-instance-id>${vnfId}</service-instance-id>
759 <subscriber-name>dontcare</subscriber-name>
760 </service-information>
761 <vnf-request-information>
762 <vnf-id>${vfModuleId}</vnf-id>
763 <vnf-type>${vfModuleModelName}</vnf-type>
764 <vnf-name>${vfModuleName}</vnf-name>
765 <generic-vnf-id>${vnfId}</generic-vnf-id>
766 <generic-vnf-name>${vnfName}</generic-vnf-name>
767 <generic-vnf-type>${vnfType}</generic-vnf-type>
768 <tenant>${tenantId}</tenant>
769 <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>
770 </vnf-request-information>
771 </sdncadapterworkflow:SDNCRequestData>
772 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
774 sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
775 execution.setVariable('DOUPVfMod_sdncActivateRequest', sdncTopologyRequest)
776 utils.logAudit("sdncActivateRequest : " + sdncTopologyRequest)
777 logDebug('Request for SDNCAdapter topology/activate:\n' + sdncTopologyRequest, isDebugLogEnabled)
780 logDebug('Exited ' + method, isDebugLogEnabled)
781 } catch (BpmnError e) {
783 } catch (Exception e) {
784 logError('Caught exception in ' + method, e)
785 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepSDNCTopologyAct(): ' + e.getMessage())
790 * Log a WorkflowException that has been created.
792 * @param execution The flow's execution instance.
794 public void handleWorkflowException(Execution execution) {
795 def method = getClass().getSimpleName() + '.handleWorkflowException(' +
796 'execution=' + execution.getId() +
798 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
799 logDebug('Entered ' + method, isDebugLogEnabled)
802 def WorkflowException workflowException = (WorkflowException) execution.getVariable('WorkflowException')
803 logError(method + ' caught WorkflowException: ' + workflowException.getErrorMessage())
805 logDebug('Exited ' + method, isDebugLogEnabled)
806 } catch (BpmnError e) {
808 } catch (Exception e) {
809 logError('Caught exception in ' + method, e)
810 exceptionUtil.buildWorkflowException(execution, 1002, 'Error in handleWorkflowException(): ' + e.getMessage())
814 public void validateSDNCResponse(Execution execution, String response, String method){
815 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
816 def prefix = execution.getVariable("prefix")
818 logDebug(" *** STARTED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
820 WorkflowException workflowException = execution.getVariable("WorkflowException")
821 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
823 utils.logAudit("workflowException: " + workflowException)
825 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
826 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
828 utils.logAudit("SDNCResponse: " + response)
830 String sdncResponse = response
831 if(execution.getVariable(prefix + 'sdncResponseSuccess') == true){
832 logDebug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse, isDebugLogEnabled)
834 logDebug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
835 throw new BpmnError("MSOWorkflowException")
837 logDebug(" *** COMPLETED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
841 * Using the received vnfId and vfModuleId, query AAI to get the corresponding VNF info.
842 * A 200 response is expected with the VNF info in the response body. Will find out the base module info.
844 * @param execution The flow's execution instance.
846 public void queryAAIVfModule(Execution execution) {
847 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
848 def method = getClass().getSimpleName() + '.getVfModule(' +
849 'execution=' + execution.getId() +
851 logDebug('Entered ' + method, isDebugLogEnabled)
854 def vnfId = execution.getVariable('DOUPVfMod_vnfId')
855 def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
857 AaiUtil aaiUriUtil = new AaiUtil(this)
858 String aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
859 logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
861 String endPoint = execution.getVariable("URN_aai_endpoint") + "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8") + "?depth=1"
862 utils.logAudit("AAI endPoint: " + endPoint)
865 def aaiRequestId = UUID.randomUUID().toString()
866 logDebug('sending GET to AAI endpoint \'' + endPoint + '\'', isDebugLogEnabled)
867 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, endPoint)
868 utils.logAudit("createVfModule - invoking httpGet() to AAI")
870 def responseData = response.getResponseBodyAsString()
871 if (responseData != null) {
872 logDebug("Received generic VNF data: " + responseData, isDebugLogEnabled)
876 utils.logAudit("createVfModule - queryAAIVfModule Response: " + responseData)
877 utils.logAudit("createVfModule - queryAAIVfModule ResponseCode: " + response.getStatusCode())
879 execution.setVariable('DOUPVfMod_queryAAIVfModuleResponseCode', response.getStatusCode())
880 execution.setVariable('DOUPVfMod_queryAAIVfModuleResponse', responseData)
881 logDebug('Response code:' + response.getStatusCode(), isDebugLogEnabled)
882 logDebug('Response:' + System.lineSeparator() + responseData, isDebugLogEnabled)
883 if (response.getStatusCode() == 200) {
884 // Parse the VNF record from A&AI to find base module info
885 logDebug('Parsing the VNF data to find base module info', isDebugLogEnabled)
886 if (responseData != null) {
887 def vfModulesText = utils.getNodeXml(responseData, "vf-modules")
888 def xmlVfModules= new XmlSlurper().parseText(vfModulesText)
889 def vfModules = xmlVfModules.'**'.findAll {it.name() == "vf-module"}
890 int vfModulesSize = 0
891 for (i in 0..vfModules.size()-1) {
892 def vfModuleXml = groovy.xml.XmlUtil.serialize(vfModules[i])
893 def isBaseVfModule = utils.getNodeText(vfModuleXml, "is-base-vf-module")
895 if (isBaseVfModule == "true") {
896 String baseModuleId = utils.getNodeText1(vfModuleXml, "vf-module-id")
897 execution.setVariable("DOUPVfMod_baseVfModuleId", baseModuleId)
898 logDebug('Received baseVfModuleId: ' + baseModuleId, isDebugLogEnabled)
899 String baseModuleHeatStackId = utils.getNodeText1(vfModuleXml, "heat-stack-id")
900 execution.setVariable("DOUPVfMod_baseVfModuleHeatStackId", baseModuleHeatStackId)
901 logDebug('Received baseVfModuleHeatStackId: ' + baseModuleHeatStackId, isDebugLogEnabled)
906 } catch (Exception ex) {
908 logDebug('Exception occurred while executing AAI GET:' + ex.getMessage(),isDebugLogEnabled)
909 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
911 logDebug('Exited ' + method, isDebugLogEnabled)
912 } catch (BpmnError e) {
914 } catch (Exception e) {
915 logError('Caught exception in ' + method, e)
916 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModule(): ' + e.getMessage())