ce93db522ea8f75a7a8b4a8abbd852e925365a7e
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / UpdateVfModuleVolumeInfraV1.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import org.apache.commons.lang3.*
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.onap.so.bpmn.common.scripts.AaiUtil;
27 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
28 import org.onap.so.bpmn.common.scripts.MsoUtils
29 import org.onap.so.bpmn.common.scripts.VfModuleBase;
30 import org.onap.so.bpmn.common.scripts.VidUtils;
31 import org.onap.so.bpmn.core.UrnPropertiesReader
32 import org.onap.so.bpmn.core.WorkflowException
33 import org.onap.so.client.aai.AAIObjectType;
34 import org.onap.so.client.aai.AAIResourcesClient
35 import org.onap.so.client.aai.entities.uri.AAIResourceUri
36 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
37 import org.onap.so.logger.MessageEnum
38 import org.onap.so.logger.MsoLogger
39 import org.onap.so.rest.APIResponse
40 import org.springframework.web.util.UriUtils
41
42 import groovy.json.JsonSlurper
43
44 class UpdateVfModuleVolumeInfraV1 extends VfModuleBase {
45         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, UpdateVfModuleVolumeInfraV1.class);
46
47         /**
48          * Initialize the flow's variables.
49          *
50          * @param execution The flow's execution instance.
51          */
52         private void initProcessVariables(DelegateExecution execution) {
53                 execution.setVariable('prefix', 'UPDVfModVol_')
54                 execution.setVariable('UPDVfModVol_Request', null)
55                 execution.setVariable('UPDVfModVol_requestInfo', null)
56                 execution.setVariable('UPDVfModVol_requestId', null)
57                 execution.setVariable('UPDVfModVol_source', null)
58                 execution.setVariable('UPDVfModVol_volumeInputs', null)
59                 execution.setVariable('UPDVfModVol_volumeGroupId', null)
60                 execution.setVariable('UPDVfModVol_vnfType', null)
61                 execution.setVariable('UPDVfModVol_serviceId', null)
62                 execution.setVariable('UPDVfModVol_aicCloudRegion', null)
63                 execution.setVariable('UPDVfModVol_tenantId', null)
64                 execution.setVariable('UPDVfModVol_volumeParams', null)
65                 execution.setVariable('UPDVfModVol_volumeGroupHeatStackId', null)
66                 execution.setVariable('UPDVfModVol_volumeGroupTenantId', null)
67                 execution.setVariable('UpdateVfModuleVolumeSuccessIndicator', false)
68         }
69
70
71         /**
72          * Perform initial processing, such as request validation, initialization of variables, etc.
73          * * @param execution
74          */
75         public void preProcessRequest (DelegateExecution execution) {
76                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
77                 preProcessRequest(execution, isDebugEnabled)
78         }
79
80         public void preProcessRequest(DelegateExecution execution, isDebugLogEnabled) {
81
82                 initProcessVariables(execution)
83                 String jsonRequest = validateRequest(execution)
84
85                 def request = ""
86
87                 try {
88                         def jsonSlurper = new JsonSlurper()
89                         Map reqMap = jsonSlurper.parseText(jsonRequest)
90
91                         def serviceInstanceId = execution.getVariable('serviceInstanceId')
92                         def volumeGroupId = execution.getVariable('volumeGroupId')
93                         //def vnfId = execution.getVariable('vnfId')
94
95                         def vidUtils = new VidUtils(this)
96                         request = vidUtils.createXmlVolumeRequest(reqMap, 'UPDATE_VF_MODULE_VOL', serviceInstanceId, volumeGroupId)
97
98                         execution.setVariable('UPDVfModVol_Request', request)
99                         execution.setVariable("UPDVfModVol_isVidRequest", true)
100
101                         //need to get persona-model-id aka model-invariantId to use later to validate vf-module relation in AAI
102
103                         def modelInvariantId = reqMap.requestDetails.modelInfo.modelInvariantUuid ?: ''
104                         execution.setVariable('UPDVfModVol_modelInvariantId', modelInvariantId)
105
106                         msoLogger.debug("modelInvariantId from request: " + modelInvariantId)
107                         msoLogger.debug("XML request:\n" + request)
108                 }
109                 catch(groovy.json.JsonException je) {
110                         msoLogger.debug(" Request is in XML format.")
111                         // assume request is in XML format - proceed as usual to process XML request
112                 }
113
114                 def requestId = execution.getVariable('mso-request-id')
115
116                 def requestInfo = getRequiredNodeXml(execution, request, 'request-info')
117                 execution.setVariable('UPDVfModVol_requestInfo', requestInfo)
118                 execution.setVariable('UPDVfModVol_requestId', requestId)
119                 //execution.setVariable('UPDVfModVol_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))
120                 execution.setVariable('UPDVfModVol_source', getNodeTextForce(requestInfo, 'source'))
121
122                 def volumeInputs = getRequiredNodeXml(execution, request, 'volume-inputs')
123                 execution.setVariable('UPDVfModVol_volumeInputs', volumeInputs)
124                 execution.setVariable('UPDVfModVol_volumeGroupId', getRequiredNodeText(execution, volumeInputs, 'volume-group-id'))
125                 execution.setVariable('UPDVfModVol_vnfType', getRequiredNodeText(execution, volumeInputs, 'vnf-type'))
126                 execution.setVariable('UPDVfModVol_vnfVersion', getRequiredNodeText(execution, volumeInputs, 'asdc-service-model-version'))
127                 execution.setVariable('UPDVfModVol_serviceId', utils.getNodeText(volumeInputs, 'service-id'))
128                 execution.setVariable('UPDVfModVol_aicCloudRegion', getRequiredNodeText(execution, volumeInputs, 'aic-cloud-region'))
129                 execution.setVariable('UPDVfModVol_tenantId', getRequiredNodeText(execution, volumeInputs, 'tenant-id'))
130                 //execution.setVariable('UPDVfModVol_modelCustomizationId', getRequiredNodeText(execution, volumeInputs, 'model-customization-id'))
131
132                 setBasicDBAuthHeader(execution, isDebugLogEnabled)
133
134                 def volumeParams = utils.getNodeXml(request, 'volume-params')
135                 execution.setVariable('UPDVfModVol_volumeParams', volumeParams)
136         }
137
138         /**
139          * Prepare and send the synchronous response.
140          *
141          * @param execution The flow's execution instance.
142          */
143         public void sendSynchResponse(DelegateExecution execution, isDebugLogEnabled) {
144
145                 def requestInfo = execution.getVariable('UPDVfModVol_requestInfo')
146                 def requestId = execution.getVariable('UPDVfModVol_requestId')
147                 def source = execution.getVariable('UPDVfModVol_source')
148                 def progress = getNodeTextForce(requestInfo, 'progress')
149                 if (progress.isEmpty()) {
150                         progress = '0'
151                 }
152                 def startTime = getNodeTextForce(requestInfo, 'start-time')
153                 if (startTime.isEmpty()) {
154                         startTime = System.currentTimeMillis()
155                 }
156                 def volumeInputs = execution.getVariable('UPDVfModVol_volumeInputs')
157
158                 String xmlSyncResponse = """
159                         <volume-request xmlns="http://org.onap/so/infra/vnf-request/v1">
160                                 <request-info>
161                                         <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
162                                         <action>UPDATE_VF_MODULE_VOL</action>
163                                         <request-status>IN_PROGRESS</request-status>
164                                         <progress>${MsoUtils.xmlEscape(progress)}</progress>
165                                         <start-time>${MsoUtils.xmlEscape(startTime)}</start-time>
166                                         <source>${MsoUtils.xmlEscape(source)}</source>
167                                 </request-info>
168                                 ${volumeInputs}
169                         </volume-request>
170                 """
171
172                 def syncResponse = ''
173                 def isVidRequest = execution.getVariable('UPDVfModVol_isVidRequest')
174
175                 if(isVidRequest) {
176                         def volumeGroupId = execution.getVariable('volumeGroupId')
177                         syncResponse = """{"requestReferences":{"instanceId":"${volumeGroupId}","requestId":"${requestId}"}}""".trim()
178                 }
179                 else {
180                         syncResponse = utils.formatXml(xmlSyncResponse)
181                 }
182
183                 msoLogger.debug('Sync response: ' + syncResponse)
184                 execution.setVariable('UPDVfModVol_syncResponseSent', true)
185                 sendWorkflowResponse(execution, 200, syncResponse)
186         }
187
188         /**
189          * Prepare a Request for querying AAI for Volume Group information using the
190          * Volume Group Id and Aic Cloud Region.
191          * @param execution The flow's execution instance.
192          */
193         public void queryAAIForVolumeGroup(DelegateExecution execution, isDebugLogEnabled) {
194
195                 def volumeGroupId = execution.getVariable('UPDVfModVol_volumeGroupId')
196                 def aicCloudRegion = execution.getVariable('UPDVfModVol_aicCloudRegion')
197
198                 AaiUtil aaiUtil = new AaiUtil(this)
199
200                 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), aicCloudRegion, volumeGroupId)
201                 def queryAAIVolumeGroupRequest = aaiUtil.createAaiUri(uri)
202
203                 msoLogger.debug('Query AAI volume group by ID: ' + queryAAIVolumeGroupRequest)
204                 msoLogger.debug('Query AAI volume group by ID: ' + queryAAIVolumeGroupRequest)
205
206                 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIVolumeGroupRequest)
207
208                 String returnCode = response.getStatusCode()
209                 String aaiResponseAsString = response.getResponseBodyAsString()
210
211                 msoLogger.debug("AAI query volume group by id return code: " + returnCode)
212                 msoLogger.debug("AAI query volume group by id response: " + aaiResponseAsString)
213
214                 msoLogger.debug("AAI Volume Group return code: " + returnCode)
215                 msoLogger.debug("AAI Volume Group response: " + aaiResponseAsString)
216
217                 ExceptionUtil exceptionUtil = new ExceptionUtil()
218
219                 if ((returnCode == '200') || (returnCode == '204')) {
220
221                         execution.setVariable('UPDVfModVol_aaiVolumeGroupResponse', aaiResponseAsString)
222                         //def heatStackId = getNodeTextForce(aaiResponseAsString, 'heat-stack-id')
223                         //execution.setVariable('UPDVfModVol_volumeGroupHeatStackId', heatStackId)
224
225                         def volumeGroupTenantId = getTenantIdFromVolumeGroup(aaiResponseAsString)
226                         if (volumeGroupTenantId == null) {
227                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Could not find Tenant Id element in Volume Group with Volume Group Id " + volumeGroupId
228                                         + ", AIC Cloud Region " + aicCloudRegion)
229                         }
230                         execution.setVariable('UPDVfModVol_volumeGroupTenantId', volumeGroupTenantId)
231                         msoLogger.debug("Received Tenant Id " + volumeGroupTenantId + " from AAI for Volume Group with Volume Group Id " + volumeGroupId + ", AIC Cloud Region " + aicCloudRegion)
232
233                         def relatedVfModuleLink = getRelatedVfModuleRelatedLink(aaiResponseAsString)
234                         msoLogger.debug("Related VF Module link: " + relatedVfModuleLink)
235                         execution.setVariable('UPDVfModVol_relatedVfModuleLink', relatedVfModuleLink)
236
237                 }
238                 else if (returnCode == '404') {
239                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume Group " + volumeGroupId + " not found at AAI")
240                 }
241                 else {
242                         WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
243                         throw new BpmnError("MSOWorkflowException")
244                 }
245         }
246
247         /**
248          * Query AAI service instance
249          * @param execution
250          * @param isDebugEnabled
251          */
252         public void queryAAIForGenericVnf(DelegateExecution execution, isDebugEnabled) {
253
254                 def vnfId = execution.getVariable('vnfId')
255
256                 AaiUtil aaiUtil = new AaiUtil(this)
257                 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
258                 String queryAAIRequest = aaiUtil.createAaiUri(uri)
259                 
260                 msoLogger.debug("AAI query generic vnf request: " + queryAAIRequest)
261
262                 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIRequest)
263
264                 String returnCode = response.getStatusCode()
265                 String aaiResponseAsString = response.getResponseBodyAsString()
266
267                 msoLogger.debug("AAI query generic vnf return code: " + returnCode)
268                 msoLogger.debug("AAI query generic vnf response: " + aaiResponseAsString)
269
270                 ExceptionUtil exceptionUtil = new ExceptionUtil()
271
272                 if (returnCode=='200') {
273                         msoLogger.debug('Generic vnf ' + vnfId + ' found in AAI.')
274                         execution.setVariable('UPDVfModVol_AAIQueryGenericVfnResponse', aaiResponseAsString)
275                 } else {
276                         if (returnCode=='404') {
277                                 def message = 'Generic vnf ' + vnfId + ' was not found in AAI. Return code: 404.'
278                                 msoLogger.debug(message)
279                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, message)
280                         } else {
281                                 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
282                                 throw new BpmnError("MSOWorkflowException")
283                         }
284                 }
285         }
286
287         /**
288          * Query AAI for VF Module using vf-module-id
289          * @param execution
290          * @param isDebugLogEnabled
291          */
292         public void queryAAIForVfModule(DelegateExecution execution, isDebugLogEnabled) {
293
294                         AaiUtil aaiUtil = new AaiUtil(this)
295                         String queryAAIVfModuleRequest = execution.getVariable('UPDVfModVol_relatedVfModuleLink')
296                         execution.setVariable('UPDVfModVol_personaModelId', '')
297
298                         msoLogger.debug('Query AAI VF Module: ' + queryAAIVfModuleRequest)
299                         msoLogger.debug('Query AAI VF Module: ' + queryAAIVfModuleRequest)
300
301                         def aaiUrl = UrnPropertiesReader.getVariable("aai.endpoint", execution)
302                         msoLogger.debug('A&AI URL: ' + aaiUrl)
303
304                         def requestEndpoint = aaiUrl + queryAAIVfModuleRequest
305                         msoLogger.debug('A&AI request endpoint: ' + requestEndpoint)
306
307                         APIResponse response = aaiUtil.executeAAIGetCall(execution, requestEndpoint)
308
309                         String returnCode = response.getStatusCode()
310                         String aaiResponseAsString = response.getResponseBodyAsString()
311
312                         msoLogger.debug("AAI query vf-module: " + returnCode)
313                         msoLogger.debug("AAI query vf-module response: " + aaiResponseAsString)
314
315                         msoLogger.debug("AAI query vf-module:: " + returnCode)
316                         msoLogger.debug("AAI query vf-module response: " + aaiResponseAsString)
317
318                         ExceptionUtil exceptionUtil = new ExceptionUtil()
319
320                         if ((returnCode == '200') || (returnCode == '204')) {
321                                 def personaModelId =  utils.getNodeText(aaiResponseAsString, 'model-invariant-id')
322                                 if(personaModelId == null) {
323                                         //check old attribute name
324                                         personaModelId =  utils.getNodeText(aaiResponseAsString, 'persona-model-id')
325                                 }
326                                 msoLogger.debug("vfModule personaModelId: " + personaModelId)
327                                 execution.setVariable('UPDVfModVol_personaModelId', personaModelId)
328                         }
329                         else if (returnCode == '404') {
330                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "VF Module not found at AAI")
331                         }
332                         else {
333                                 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
334                                 throw new BpmnError("MSOWorkflowException")
335                         }
336                 }
337         /**
338          *
339          */
340         public String getRelatedVfModuleRelatedLink(xml) {
341                 def list = new XmlSlurper().parseText(xml)
342                 def vfModuleRelationship = list.'**'.find { node -> node.'related-to'.text() == 'vf-module'     }
343                 return vfModuleRelationship?.'related-link'?.text() ?: ''
344         }
345
346         /**
347          * Prepare a Request for invoking the VnfAdapterRest subflow to do
348          * a Volume Group update.
349          *
350          * @param execution The flow's execution instance.
351          */
352         public void prepVnfAdapterRest(DelegateExecution execution, isDebugLogEnabled) {
353
354                 def aicCloudRegion = execution.getVariable('UPDVfModVol_aicCloudRegion')
355                 def tenantId = execution.getVariable('UPDVfModVol_tenantId')
356                 def volumeGroupId = execution.getVariable('UPDVfModVol_volumeGroupId')
357
358                 def aaiVolumeGroupResponse = execution.getVariable('UPDVfModVol_aaiVolumeGroupResponse')
359                 def volumeGroupHeatStackId = getNodeTextForce(aaiVolumeGroupResponse, 'heat-stack-id')
360                 def volumeGroupName = getNodeTextForce(aaiVolumeGroupResponse, 'volume-group-name')
361                 def modelCustomizationId = getNodeTextForce(aaiVolumeGroupResponse, 'vf-module-model-customization-id')
362                 if(modelCustomizationId == null) {
363                         // Check old attribute name
364                         modelCustomizationId = getNodeTextForce(aaiVolumeGroupResponse, 'vf-module-persona-model-customization-id')
365                 }
366
367                 def vnfType = execution.getVariable('UPDVfModVol_vnfType')
368                 def vnfVersion = execution.getVariable('UPDVfModVol_vnfVersion')
369
370                 def aaiGenericVnfResponse = execution.getVariable('UPDVfModVol_AAIQueryGenericVfnResponse')
371                 def vnfId = utils.getNodeText(aaiGenericVnfResponse, 'vnf-id')
372                 def vnfName = utils.getNodeText(aaiGenericVnfResponse, 'vnf-name')
373
374
375                 def volumeParamsXml = execution.getVariable('UPDVfModVol_volumeParams')
376                 def volumeGroupParams = transformVolumeParamsToEntries(volumeParamsXml)
377
378                 def requestId = execution.getVariable('UPDVfModVol_requestId')
379                 def serviceId = execution.getVariable('UPDVfModVol_serviceId')
380
381                 def messageId = execution.getVariable('mso-request-id') + '-' + System.currentTimeMillis()
382                 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
383                 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
384                 if ('true'.equals(useQualifiedHostName)) {
385                                 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
386                 }
387
388                 String vnfAdapterRestRequest = """
389                         <updateVolumeGroupRequest>
390                                 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
391                                 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
392                                 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
393                                 <vnfName>${MsoUtils.xmlEscape(vnfName)}</vnfName>
394                                 <volumeGroupId>${MsoUtils.xmlEscape(volumeGroupId)}</volumeGroupId>
395                                 <volumeGroupName>${MsoUtils.xmlEscape(volumeGroupName)}</volumeGroupName>
396                                 <volumeGroupStackId>${MsoUtils.xmlEscape(volumeGroupHeatStackId)}</volumeGroupStackId>
397                                 <vnfType>${MsoUtils.xmlEscape(vnfType)}</vnfType>
398                                 <vnfVersion>${MsoUtils.xmlEscape(vnfVersion)}</vnfVersion>
399                                 <vfModuleType></vfModuleType>
400                                 <modelCustomizationUuid>${MsoUtils.xmlEscape(modelCustomizationId)}</modelCustomizationUuid>
401                                 <volumeGroupParams>
402                                         <entry>
403                                                 <key>vnf_id</key>
404                                                 <value>${MsoUtils.xmlEscape(vnfId)}</value>
405                                         </entry>
406                                         <entry>
407                                                 <key>vnf_name</key>
408                                                 <value>${MsoUtils.xmlEscape(vnfName)}</value>
409                                         </entry>
410                                         <entry>
411                                                 <key>vf_module_id</key>
412                                                 <value>${MsoUtils.xmlEscape(volumeGroupId)}</value>
413                                         </entry>
414                                         <entry>
415                                                 <key>vf_module_name</key>
416                                                 <value>${MsoUtils.xmlEscape(volumeGroupName)}</value>
417                                         </entry>
418                                         ${volumeGroupParams}
419                             </volumeGroupParams>
420                                 <skipAAI>true</skipAAI>
421                             <msoRequest>
422                                 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
423                                 <serviceInstanceId>${MsoUtils.xmlEscape(serviceId)}</serviceInstanceId>
424                             </msoRequest>
425                             <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
426                             <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
427                         </updateVolumeGroupRequest>
428                 """
429                 vnfAdapterRestRequest = utils.formatXml(vnfAdapterRestRequest)
430                 execution.setVariable('UPDVfModVol_vnfAdapterRestRequest', vnfAdapterRestRequest)
431                 msoLogger.debug('Request for VNFAdapter Rest:\n' + vnfAdapterRestRequest)
432         }
433
434         /**
435          * Prepare a Request for updating the DB for this Infra request.
436          *
437          * @param execution The flow's execution instance.
438          */
439         public void prepDbInfraDbRequest(DelegateExecution execution, isDebugLogEnabled) {
440
441                 def requestId = execution.getVariable('UPDVfModVol_requestId')
442                 ExceptionUtil exceptionUtil = new ExceptionUtil();
443
444                 String updateInfraRequest = """
445                         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
446                                         xmlns:req="http://org.onap.so/requestsdb">
447                                 <soapenv:Header/>
448                                 <soapenv:Body>
449                                         <req:updateInfraRequest>
450                                                 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
451                                                 <lastModifiedBy>BPEL</lastModifiedBy>
452                                                 <requestStatus>COMPLETE</requestStatus>
453                                                 <progress>100</progress>
454                                         </req:updateInfraRequest>
455                                 </soapenv:Body>
456                         </soapenv:Envelope>
457                 """
458
459                 updateInfraRequest = utils.formatXml(updateInfraRequest)
460                 execution.setVariable('UPDVfModVol_updateInfraRequest', updateInfraRequest)
461                 msoLogger.debug('Request for Update Infra Request:\n' + updateInfraRequest)
462         }
463
464         /**
465          * Build a "CompletionHandler" request.
466          * @param execution The flow's execution instance.
467          */
468         public void prepCompletionHandlerRequest(DelegateExecution execution, requestId, action, source, isDebugLogEnabled) {
469
470                 String content = """
471                 <aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
472                                         xmlns:ns="http://org.onap/so/request/types/v1">
473                         <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
474                                 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
475                                 <action>UPDATE</action>
476                                 <source>${MsoUtils.xmlEscape(source)}</source>
477                         </request-info>
478                         <aetgt:mso-bpel-name>BPMN VF Module Volume action: UPDATE</aetgt:mso-bpel-name>
479                 </aetgt:MsoCompletionRequest>
480                 """
481
482                 content = utils.formatXml(content)
483                 msoLogger.debug('Request for Completion Handler:\n' + content)
484                 execution.setVariable('UPDVfModVol_CompletionHandlerRequest', content)
485         }
486
487
488         /**
489          * Build a "FalloutHandler" request.
490          * @param execution The flow's execution instance.
491          */
492         public void prepFalloutHandler(DelegateExecution execution, isDebugLogEnabled) {
493                 def requestId = execution.getVariable('UPDVfModVol_requestId')
494                 def source = execution.getVariable('UPDVfModVol_source')
495
496                 String requestInfo = """
497                 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
498                 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
499                 <action>UPDATE</action>
500                 <source>${MsoUtils.xmlEscape(source)}</source>
501            </request-info>"""
502
503                 def WorkflowException workflowException = execution.getVariable("WorkflowException")
504                 def errorResponseCode = workflowException.getErrorCode()
505                 def errorResponseMsg = workflowException.getErrorMessage()
506                 def encErrorResponseMsg = ""
507                 if (errorResponseMsg != null) {
508                         encErrorResponseMsg = errorResponseMsg
509                 }
510
511                 String content = """
512                         <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
513                                         xmlns:reqtype="http://org.onap/so/request/types/v1"
514                                         xmlns:msoservtypes="http://org.onap/so/request/types/v1"
515                                         xmlns:structuredtypes="http://org.onap/so/structured/types/v1">
516                                 ${requestInfo}
517                                 <sdncadapterworkflow:WorkflowException>
518                                         <sdncadapterworkflow:ErrorMessage>${MsoUtils.xmlEscape(encErrorResponseMsg)}</sdncadapterworkflow:ErrorMessage>
519                                         <sdncadapterworkflow:ErrorCode>${MsoUtils.xmlEscape(errorResponseCode)}</sdncadapterworkflow:ErrorCode>
520                                 </sdncadapterworkflow:WorkflowException>
521                         </sdncadapterworkflow:FalloutHandlerRequest>
522                 """
523                 content = utils.formatXml(content)
524                 msoLogger.debug('Request for Fallout Handler:\n' + content)
525                 execution.setVariable('UPDVfModVol_FalloutHandlerRequest', content)
526         }
527
528         /**
529          * Create a WorkflowException for the error case where the Tenant Id from
530          * AAI did not match the Tenant Id in the incoming request.
531          * @param execution The flow's execution instance.
532          */
533         public void handleTenantIdMismatch(DelegateExecution execution, isDebugLogEnabled) {
534
535                 def volumeGroupId = execution.getVariable('UPDVfModVol_volumeGroupId')
536                 def aicCloudRegion = execution.getVariable('UPDVfModVol_aicCloudRegion')
537                 def tenantId = execution.getVariable('UPDVfModVol_tenantId')
538                 def volumeGroupTenantId = execution.getVariable('UPDVfModVol_volumeGroupTenantId')
539
540                 def String errorMessage = "TenantId " + tenantId + " in incoming request does not match Tenant Id " + volumeGroupTenantId +
541                         " retrieved from AAI for Volume Group Id " + volumeGroupId + ", AIC Cloud Region " + aicCloudRegion
542
543                 ExceptionUtil exceptionUtil = new ExceptionUtil()
544                 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Error in UpdateVfModuleVol: ' + errorMessage, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception");
545                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
546         }
547
548         /**
549          * Create a WorkflowException for the error case where the Personal Model Id from
550          * AAI did not match the model invariant ID in the incoming request.
551          * @param execution The flow's execution instance.
552          */
553         public void handlePersonaModelIdMismatch(DelegateExecution execution, isDebugLogEnabled) {
554
555                 def modelInvariantId = execution.getVariable('UPDVfModVol_modelInvariantId')
556                 def personaModelId = execution.getVariable('UPDVfModVol_personaModelId')
557
558                 def String errorMessage = "Model Invariant ID " + modelInvariantId + " in incoming request does not match persona model ID " + personaModelId +
559                         " retrieved from AAI for Volume Group Id "
560
561                 ExceptionUtil exceptionUtil = new ExceptionUtil()
562                 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Error in UpdateVfModuleVol: ' + errorMessage, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception");
563                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
564         }
565
566 }