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