2cbfeac23976ad00fd21dda3b7bf9b511047a58d
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DeleteVfModuleVolumeInfraV1.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.AbstractServiceTaskProcessor;
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
29 import org.onap.so.bpmn.common.scripts.MsoUtils
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 /**
41  * This groovy class supports the <class>DeleteVfModuleVolume.bpmn</class> process.
42  */
43 public class DeleteVfModuleVolumeInfraV1 extends AbstractServiceTaskProcessor {
44         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DeleteVfModuleVolumeInfraV1.class);
45
46         private XmlParser xmlParser = new XmlParser()
47         /**
48          * This method is executed during the preProcessRequest task of the <class>DeleteVfModuleVolume.bpmn</class> process.
49          * @param execution
50          */
51         public InitializeProcessVariables(DelegateExecution execution){
52                 execution.setVariable('prefix', 'DELVfModVol_')
53                 execution.setVariable("DELVfModVol_volumeRequest", null)
54                 execution.setVariable('DELVfModVol_requestInfo', null)
55                 execution.setVariable('DELVfModVol_requestId', null)
56                 execution.setVariable('DELVfModVol_source', null)
57                 execution.setVariable('DELVfModVol_volumeInputs', null)
58                 execution.setVariable('DELVfModVol_volumeOutputs', null)
59                 execution.setVariable('DELVfModVol_volumeGroupId', null)
60                 execution.setVariable('DELVfModVol_vnfType', null)
61                 execution.setVariable('DELVfModVol_serviceId', null)
62                 execution.setVariable('DELVfModVol_cloudRegion', null)
63                 execution.setVariable('DELVfModVol_tenantId', null)
64                 execution.setVariable('DELVfModVol_volumeParams', null)
65                 execution.setVariable('DELVfModVol_volumeGroupHeatStackId', null)
66                 execution.setVariable('DELVfModVol_volumeGroupTenantId', null)
67                 execution.setVariable("DELVfModVol_queryAAIVolGrpResponse", null)
68                 execution.setVariable('DELVfModVol_messageId', null)
69                 execution.setVariable('DELVfModVol_deleteVnfARequest', null)
70                 execution.setVariable('DELVfModVol_updateInfraRequest', null)
71                 execution.setVariable('DELVfModVol_CompleteMsoProcessRequest', null)
72                 execution.setVariable('DELVfModVol_WorkflowException', null)
73                 execution.setVariable('DELVfModVol_TransactionSuccessIndicator', false)
74                 execution.setVariable("DELVfModVol_isErrorMessageException", false)
75                 execution.setVariable('DELVfModVol_syncResponseSent', false)
76         }
77
78         /**
79          * Perform initial processing, such as request validation, initialization of variables, etc.
80          * * @param execution
81          */
82         public void preProcessRequest (DelegateExecution execution) {
83                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
84                 preProcessRequest(execution, isDebugEnabled)
85         }
86
87         /**
88          * This method is executed during the preProcessRequest task of the <class>DeleteVfModuleVolume.bpmn</class> process.
89          * @param execution
90          */
91         public void preProcessRequest (DelegateExecution execution, isDebugLogEnabled) {
92
93                 InitializeProcessVariables(execution)
94
95                 String createVolumeIncoming = validateRequest(execution)
96
97                 // check if request is xml or json
98                 try {
99                         def jsonSlurper = new JsonSlurper()
100                         Map reqMap = jsonSlurper.parseText(createVolumeIncoming)
101                         msoLogger.debug(" Request is in JSON format.")
102
103                         def serviceInstanceId = execution.getVariable('serviceInstanceId')
104                         def volumeGroupId = execution.getVariable('volumeGroupId')
105                         def vidUtils = new VidUtils(this)
106                         createVolumeIncoming = vidUtils.createXmlVolumeRequest(reqMap, 'DELETE_VF_MODULE_VOL', serviceInstanceId, volumeGroupId)
107                         execution.setVariable("DELVfModVol_isVidRequest", true)
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                 String request = utils.getNodeXml(createVolumeIncoming, "volume-request").drop(38).trim().replace("tag0:","").replace(":tag0","")
115                 execution.setVariable("DELVfModVol_volumeRequest", request)
116
117                 def requestInfo = getRequiredNodeXml(execution, request, 'request-info')
118                 execution.setVariable('DELVfModVol_requestInfo', requestInfo)
119                 String requestId = execution.getVariable("mso-request-id")
120                 if (requestId == null || requestId == "") {
121                         requestId = getRequiredNodeText(execution, requestInfo, 'request-id')
122                 }
123                 execution.setVariable('DELVfModVol_requestId', requestId)
124                 execution.setVariable('DELVfModVol_source', getNodeTextForce(requestInfo, 'source'))
125
126                 def volumeInputs = getRequiredNodeXml(execution, request, 'volume-inputs')
127                 execution.setVariable('DELVfModVol_volumeInputs', volumeInputs)
128                 execution.setVariable('DELVfModVol_volumeGroupId', getRequiredNodeText(execution, volumeInputs, 'volume-group-id'))
129                 execution.setVariable('DELVfModVol_vnfType', getRequiredNodeText(execution, volumeInputs, 'vnf-type'))
130                 execution.setVariable('DELVfModVol_serviceId', utils.getNodeText(volumeInputs, 'service-id'))
131                 execution.setVariable('DELVfModVol_tenantId', getRequiredNodeText(execution, volumeInputs, 'tenant-id'))
132                 execution.setVariable('DELVfModVol_messageId', UUID.randomUUID().toString())
133                 execution.setVariable('DELVfModVol_volumeOutputs', utils.getNodeXml(request, 'volume-outputs', false))
134                 execution.setVariable('DELVfModVol_volumeParams', utils.getNodeXml(request, 'volume-params'))
135                 execution.setVariable('DELVfModVol_cloudRegion', utils.getNodeText(request, 'aic-cloud-region'))
136
137                 setBasicDBAuthHeader(execution, isDebugLogEnabled)
138                 
139                 msoLogger.debug('Request: ' + createVolumeIncoming)
140         }
141
142         public void sendSyncResponse (DelegateExecution execution, isDebugEnabled) {
143
144                 String volumeRequest = execution.getVariable("DELVfModVol_volumeRequest")
145                 msoLogger.debug(" DELVfModVol_volumeRequest - " + "\n" + volumeRequest)
146                 // RESTResponse (for API Handler (APIH) Reply Task)
147                 String deleteVolumeRequest =
148                                 """<rest:RESTResponse xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd" statusCode="200">
149                 <rest:payload xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"
150                           contentType="text/xml">
151                                 ${volumeRequest}
152                 </rest:payload>
153                        </rest:RESTResponse>""".trim()
154
155                 def isVidRequest = execution.getVariable('DELVfModVol_isVidRequest')
156                 def syncResponse = ''
157
158                 if(isVidRequest) {
159                         def serviceInstanceId = execution.getVariable('serviceInstanceId')
160                         def volumeGroupId = execution.getVariable('volumeGroupId')
161                         def requestId = execution.getVariable('DELVfModVol_requestId')
162                         syncResponse = """{"requestReferences":{"instanceId":"${volumeGroupId}","requestId":"${requestId}"}}""".trim()
163                 }
164                 else {
165                         syncResponse = utils.formatXml(deleteVolumeRequest)
166                 }
167
168                 execution.setVariable('DELVfModVol_syncResponseSent', true)
169
170                 sendWorkflowResponse(execution, 200, syncResponse)
171         }
172
173
174         public void sendSyncError (DelegateExecution execution, isDebugEnabled) {
175                 WorkflowException we = execution.getVariable('WorkflowException')
176                 def errorCode = we?.getErrorCode()
177                 def errorMessage = we?.getErrorMessage()
178                 //default to 400 since only invalid request will trigger this method
179                 sendWorkflowResponse(execution, 400, errorMessage)
180         }
181
182
183         public void callRESTQueryAAICloudRegion (DelegateExecution execution, isDebugEnabled) {
184
185                 String cloudRegion = execution.getVariable('DELVfModVol_cloudRegion')
186
187                 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
188                 AaiUtil aaiUtil = new AaiUtil(this)
189                 String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
190                 String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
191                 execution.setVariable("DELVfModVol_queryCloudRegionRequest", queryCloudRegionRequest)
192                 msoLogger.debug(" DELVfModVol_queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest)
193
194                 cloudRegion = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "PO", cloudRegion)
195
196                 ExceptionUtil exceptionUtil = new ExceptionUtil()
197
198                 if ((cloudRegion != "ERROR")) {
199                         if(execution.getVariable("DELVfModVol_queryCloudRegionReturnCode") == "404"){
200                                 execution.setVariable("DELVfModVol_aicCloudRegion", "AAIAIC25")
201                         }else{
202                                 execution.setVariable("DELVfModVol_aicCloudRegion", cloudRegion)
203                         }
204                         execution.setVariable("DELVfModVol_cloudRegion", cloudRegion)
205                         execution.setVariable("DELVfModVol_isCloudRegionGood", true)
206
207                 } else {
208                         msoLogger.debug("AAI Query Cloud Region Unsuccessful.")
209                         execution.setVariable("DELVfModVol_isCloudRegionGood", false)
210                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "AAI Query Cloud Region Unsuccessful. Return Code: " + execution.getVariable("DELVfModVol_queryCloudRegionReturnCode"))
211                 }
212
213                 msoLogger.debug(" is Cloud Region Good: " + execution.getVariable("DELVfModVol_isCloudRegionGood"))
214         }
215
216         /**
217          * Query volume group by id
218          * @param execution
219          */
220         public void queryAAIForVolumeGroup(DelegateExecution execution, isDebugLogEnabled) {
221
222                 ExceptionUtil exceptionUtil = new ExceptionUtil()
223
224                 def volumeGroupId = execution.getVariable('DELVfModVol_volumeGroupId')
225                 if(volumeGroupId == null) {
226                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, 'volume-group-id is not provided in the request')
227                         throw new Exception('volume-group-id is not provided in the request')
228                 }
229                 String cloudRegion = execution.getVariable('DELVfModVol_aicCloudRegion')
230
231                 AaiUtil aaiUtil = new AaiUtil(this)
232                 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
233                 String queryAAIVolumeGroupRequest = aaiEndpoint + '/' + URLEncoder.encode(cloudRegion, "UTF-8") + "/volume-groups/volume-group/" + UriUtils.encode(volumeGroupId, "UTF-8")
234
235                 msoLogger.debug('Query AAI volume group by ID: ' + queryAAIVolumeGroupRequest)
236
237                 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIVolumeGroupRequest)
238
239                 String returnCode = response.getStatusCode()
240                 String aaiResponseAsString = response.getResponseBodyAsString()
241
242                 msoLogger.debug("AAI query volume group by id return code: " + returnCode)
243                 msoLogger.debug("AAI query volume group by id response: " + aaiResponseAsString)
244
245                 execution.setVariable("DELVfModVol_queryAAIVolGrpResponse", aaiResponseAsString)
246
247                 if (returnCode=='200' || returnCode == '204') {
248
249                         def heatStackId = getNodeTextForce(aaiResponseAsString, 'heat-stack-id')
250                         execution.setVariable('DELVfModVol_volumeGroupHeatStackId', heatStackId)
251
252                         if(hasVfModuleRelationship(aaiResponseAsString)){
253                                 msoLogger.debug('Volume Group ' + volumeGroupId + ' currently in use')
254                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume Group ${volumeGroupId} currently in use - found vf-module relationship.")
255                         }
256
257                         def volumeGroupTenantId = getTenantIdFromVolumeGroup(aaiResponseAsString)
258                         if (volumeGroupTenantId == null) {
259                                 msoLogger.debug("Could not find Tenant Id element in Volume Group with Volume Group Id ${volumeGroupId}")
260                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Could not find Tenant Id element in Volume Group with Volume Group Id ${volumeGroupId}")
261                         }
262
263                         execution.setVariable('DELVfModVol_volumeGroupTenantId', volumeGroupTenantId)
264                         msoLogger.debug('Received Tenant Id ' + volumeGroupTenantId + ' from AAI for Volume Group with Volume Group Id ' + volumeGroupId )
265                 }
266                 else {
267                         if (returnCode=='404') {
268                                 msoLogger.debug("Volume Group ${volumeGroupId} not found in AAI")
269                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume Group ${volumeGroupId} not found in AAI. Response code: 404")
270                         }
271                         else {
272                                 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
273                                 throw new BpmnError("MSOWorkflowException")
274                         }
275                 }
276         }
277
278         /**
279          * Extract the Tenant Id from the Volume Group information returned by AAI.
280          *
281          * @param volumeGroupXml Volume Group XML returned by AAI.
282          * @return the Tenant Id extracted from the Volume Group information. 'null' is returned if
283          * the Tenant Id is missing or could not otherwise be extracted.
284          */
285         private String getTenantIdFromVolumeGroup(String volumeGroupXml) {
286                 def Node volumeGroupNode = xmlParser.parseText(volumeGroupXml)
287                 def Node relationshipList = utils.getChildNode(volumeGroupNode, 'relationship-list')
288                 if (relationshipList != null) {
289                         def NodeList relationships = utils.getIdenticalChildren(relationshipList, 'relationship')
290                         for (Node relationship in relationships) {
291                                 def Node relatedTo = utils.getChildNode(relationship, 'related-to')
292                                 if ((relatedTo != null) && (relatedTo.text().equals('tenant'))) {
293                                         def NodeList relationshipDataList = utils.getIdenticalChildren(relationship, 'relationship-data')
294                                         for (Node relationshipData in relationshipDataList) {
295                                                 def Node relationshipKey = utils.getChildNode(relationshipData, 'relationship-key')
296                                                 if ((relationshipKey != null) && (relationshipKey.text().equals('tenant.tenant-id'))) {
297                                                         def Node relationshipValue = utils.getChildNode(relationshipData, 'relationship-value')
298                                                         if (relationshipValue != null) {
299                                                                 return relationshipValue.text()
300                                                         }
301                                                 }
302                                         }
303                                 }
304                         }
305                 }
306                 return null
307         }
308
309         private boolean hasVnfRelationship(String volumeGroupXml) {
310                 def Node volumeGroupNode = xmlParser.parseText(volumeGroupXml)
311                 def Node relationshipList = utils.getChildNode(volumeGroupNode, 'relationship-list')
312                 if (relationshipList != null) {
313                         def NodeList relationships = utils.getIdenticalChildren(relationshipList, 'relationship')
314                         for (Node relationship in relationships) {
315                                 def Node relatedTo = utils.getChildNode(relationship, 'related-to')
316                                 if ((relatedTo != null) && (relatedTo.text().equals('generic-vnf'))) {
317                                         def Node relatedLink = utils.getChildNode(relationship, 'related-link')
318                                         if (relatedLink !=null && relatedLink.text() != null){
319                                                 return true
320                                         }
321                                 }
322                         }
323                 }
324                 return false
325         }
326
327         private boolean hasVfModuleRelationship(String volumeGroupXml) {
328                 def Node volumeGroupNode = xmlParser.parseText(volumeGroupXml)
329                 def Node relationshipList = utils.getChildNode(volumeGroupNode, 'relationship-list')
330                 if (relationshipList != null) {
331                         def NodeList relationships = utils.getIdenticalChildren(relationshipList, 'relationship')
332                         for (Node relationship in relationships) {
333                                 def Node relatedTo = utils.getChildNode(relationship, 'related-to')
334                                 if ((relatedTo != null) && (relatedTo.text().equals('vf-module'))) {
335                                         def Node relatedLink = utils.getChildNode(relationship, 'related-link')
336                                         if (relatedLink !=null && relatedLink.text() != null){
337                                                 return true
338                                         }
339                                 }
340                         }
341                 }
342                 return false
343         }
344
345         public void prepareVnfAdapterDeleteRequest(DelegateExecution execution, isDebugLogEnabled) {
346                 def cloudRegion = execution.getVariable('DELVfModVol_cloudRegion')
347                 def tenantId = execution.getVariable('DELVfModVol_tenantId')
348                 def volumeGroupId = execution.getVariable('DELVfModVol_volumeGroupId')
349                 def volumeGroupHeatStackId = execution.getVariable('DELVfModVol_volumeGroupHeatStackId')
350                 def requestId = execution.getVariable('DELVfModVol_requestId')
351                 def serviceId = execution.getVariable('DELVfModVol_serviceId')
352
353                 def messageId = execution.getVariable('DELVfModVol_messageId')
354                 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId) 
355                 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host", execution)
356                 if ('true'.equals(useQualifiedHostName)) {
357                                 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
358                 }
359
360                 String vnfAdapterRestRequest = """
361                         <deleteVolumeGroupRequest>
362                                 <cloudSiteId>${MsoUtils.xmlEscape(cloudRegion)}</cloudSiteId>
363                                 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
364                                 <volumeGroupId>${MsoUtils.xmlEscape(volumeGroupId)}</volumeGroupId>
365                                 <volumeGroupStackId>${MsoUtils.xmlEscape(volumeGroupHeatStackId)}</volumeGroupStackId>
366                                 <skipAAI>true</skipAAI>
367                             <msoRequest>
368                                 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
369                                 <serviceInstanceId>${MsoUtils.xmlEscape(serviceId)}</serviceInstanceId>
370                             </msoRequest>
371                             <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
372                             <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
373                         </deleteVolumeGroupRequest>
374                 """
375                 vnfAdapterRestRequest = utils.formatXml(vnfAdapterRestRequest)
376                 execution.setVariable('DELVfModVol_deleteVnfARequest', vnfAdapterRestRequest)
377                 msoLogger.debug('Request for VNFAdapter Rest:\n' + vnfAdapterRestRequest)
378         }
379
380
381         public void deleteVolGrpId(DelegateExecution execution, isDebugEnabled) {
382
383                 // get variables
384                 String queryAAIVolGrpIdResponse = execution.getVariable("DELVfModVol_queryAAIVolGrpResponse")
385                 String groupId = utils.getNodeText(queryAAIVolGrpIdResponse, "volume-group-id")
386                 String resourceVersion = utils.getNodeText(queryAAIVolGrpIdResponse, "resource-version")
387                 String messageId = execution.getVariable('DELVfModVol_messageId')
388                 String cloudRegion = execution.getVariable('DELVfModVol_aicCloudRegion')
389
390                 AaiUtil aaiUtil = new AaiUtil(this)
391                 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
392                 String deleteAAIVolumeGrpIdRequest = aaiEndpoint + '/' + URLEncoder.encode(cloudRegion, "UTF-8")  + "/volume-groups/volume-group/" +  UriUtils.encode(groupId, "UTF-8")
393
394                 if(resourceVersion !=null){
395                         deleteAAIVolumeGrpIdRequest = deleteAAIVolumeGrpIdRequest +'?resource-version=' + UriUtils.encode(resourceVersion, 'UTF-8')
396                 }
397
398                 msoLogger.debug("Delete AAI volume group : " + deleteAAIVolumeGrpIdRequest)
399
400                 APIResponse response = aaiUtil.executeAAIDeleteCall(execution, deleteAAIVolumeGrpIdRequest)
401
402                 String returnCode = response.getStatusCode()
403                 String aaiResponseAsString = response.getResponseBodyAsString()
404
405                 msoLogger.debug("AAI delete volume group return code: " + returnCode)
406                 msoLogger.debug("AAI delete volume group response: " + aaiResponseAsString)
407
408                 ExceptionUtil exceptionUtil = new ExceptionUtil()
409                 if (returnCode=='200' || (returnCode == '204')) {
410                         msoLogger.debug("Volume group $groupId deleted.")
411                 } else {
412                         if (returnCode=='404') {
413                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $groupId not found for delete in AAI Response code: 404")
414                         } else {
415                                 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
416                                 throw new BpmnError("MSOWorkflowException")
417                         }
418                 }
419         }
420
421
422         public void prepareDBRequest (DelegateExecution execution, isDebugLogEnabled) {
423
424                 WorkflowException workflowExceptionObj = execution.getVariable("WorkflowException")
425                 ExceptionUtil exceptionUtil = new ExceptionUtil();
426                 def requestId = execution.getVariable('DELVfModVol_requestId')
427                 def volOutputs = execution.getVariable('DELVfModVol_volumeOutputs')
428                 def statusMessage = "VolumeGroup successfully deleted"
429                 def progress = "100"
430                 def requestStatus = "COMPLETE"
431
432                 if (workflowExceptionObj != null) {
433                         statusMessage = (workflowExceptionObj.getErrorMessage())
434                         execution.setVariable("DELVfModVol_WorkflowExceptionMessage", statusMessage)
435                         execution.setVariable("DELVfModVol_WorkflowExceptionCode", workflowExceptionObj.getErrorCode())
436                         requestStatus = "FAILURE"
437                         progress = ""
438                 }
439                 
440                 String updateInfraRequest = """
441                         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
442                                         xmlns:req="http://org.onap.so/requestsdb">
443                                 <soapenv:Header/>
444                                 <soapenv:Body>
445                                         <req:updateInfraRequest>
446                                                 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
447                                                 <lastModifiedBy>BPMN</lastModifiedBy>
448                                                 <statusMessage>${MsoUtils.xmlEscape(statusMessage)}</statusMessage>
449                                                 <requestStatus>${MsoUtils.xmlEscape(requestStatus)}</requestStatus>
450                                                 <progress>${MsoUtils.xmlEscape(progress)}</progress>
451                                                 <vnfOutputs>${MsoUtils.xmlEscape(volOutputs)}</vnfOutputs>
452                                         </req:updateInfraRequest>
453                                 </soapenv:Body>
454                         </soapenv:Envelope>
455                 """
456
457                 updateInfraRequest = utils.formatXml(updateInfraRequest)
458                 execution.setVariable('DELVfModVol_updateInfraRequest', updateInfraRequest)
459                 msoLogger.debug('Request for Update Infra Request:\n' + updateInfraRequest)
460
461         }
462
463
464         public void prepareCompletionHandlerRequest (DelegateExecution execution, isDebugLogEnabled) {
465                 def requestId = execution.getVariable("mso-request-id")
466                 def source = execution.getVariable("DELVfModVol_source")
467
468                 String msoCompletionRequest =
469                         """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
470                                                         xmlns:ns="http://org.onap/so/request/types/v1">
471                                         <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
472                                                 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
473                                                 <action>DELETE</action>
474                                                 <source>${MsoUtils.xmlEscape(source)}</source>
475                                         </request-info>
476                                         <aetgt:status-message>Volume Group has been deleted successfully.</aetgt:status-message>
477                                         <aetgt:mso-bpel-name>BPMN VF Module Volume action: DELETE</aetgt:mso-bpel-name>
478                                 </aetgt:MsoCompletionRequest>"""
479
480                 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
481                 execution.setVariable('DELVfModVol_CompleteMsoProcessRequest', xmlMsoCompletionRequest)
482                 msoLogger.debug(" Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
483
484         }
485
486
487
488         public void prepareFalloutHandler (DelegateExecution execution, isDebugEnabled) {
489
490                 execution.setVariable("DELVfModVol_Success", false)
491                 String requestId = execution.getVariable("DELVfModVol_requestId")
492                 String source = execution.getVariable("DELVfModVol_source")
493
494                 WorkflowException workflowExceptionObj = execution.getVariable("WorkflowException")
495                 def errorMessage = workflowExceptionObj.getErrorMessage()
496                 def errorCode =  workflowExceptionObj.getErrorCode()
497
498                 String falloutHandlerRequest =
499                     """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
500                                                              xmlns:ns="http://org.onap/so/request/types/v1"
501                                                              xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
502                                    <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
503                                       <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
504                                       <action>DELETE</action>
505                                       <source>${MsoUtils.xmlEscape(source)}</source>
506                                    </request-info>
507                                         <aetgt:WorkflowException>
508                                       <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
509                                       <aetgt:ErrorCode>${MsoUtils.xmlEscape(errorCode)}</aetgt:ErrorCode>
510                                         </aetgt:WorkflowException>
511                                 </aetgt:FalloutHandlerRequest>"""
512
513                 // Format Response
514                 String xmlHandlerRequest = utils.formatXml(falloutHandlerRequest)
515                 msoLogger.debug(xmlHandlerRequest)
516
517                 execution.setVariable("DELVfModVol_FalloutHandlerRequest", xmlHandlerRequest)
518                 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "  Overall Error Response going to FalloutHandler", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "\n" + xmlHandlerRequest);
519
520         }
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          *
527          * @param execution The flow's execution instance.
528          */
529         public void handleTenantIdMismatch(DelegateExecution execution, isDebugLogEnabled) {
530
531                 def volumeGroupId = execution.getVariable('DELVfModVol_volumeGroupId')
532                 def aicCloudRegion = execution.getVariable('DELVfModVol_aicCloudRegion')
533                 def tenantId = execution.getVariable('DELVfModVol_tenantId')
534                 def volumeGroupTenantId = execution.getVariable('DELVfModVol_volumeGroupTenantId')
535
536                 def String errorMessage = 'TenantId ' + tenantId + ' in incoming request does not match Tenant Id ' + volumeGroupTenantId +
537                         ' retrieved from AAI for Volume Group Id ' + volumeGroupId
538                 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Error in DeleteVfModuleVolume: " + "\n" + errorMessage, "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError);
539
540                 ExceptionUtil exceptionUtil = new ExceptionUtil()
541                 exceptionUtil.buildWorkflowException(execution, 5000, errorMessage)
542
543         }
544
545 }