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