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