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