Merge "Fix the issue where response is built on rollback"
[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  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.scripts
24
25 import javax.ws.rs.NotFoundException
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.aai.domain.yang.VolumeGroup
29 import org.onap.aaiclient.client.aai.AAIObjectType
30 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
31 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
32 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
33 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
34 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
35 import org.onap.logging.filter.base.ErrorCode
36 import org.onap.so.bpmn.common.scripts.AaiUtil;
37 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor;
38 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
39 import org.onap.so.bpmn.common.scripts.MsoUtils
40 import org.onap.so.bpmn.common.scripts.VidUtils;
41 import org.onap.so.bpmn.core.UrnPropertiesReader
42 import org.onap.so.bpmn.core.WorkflowException
43 import org.onap.so.constants.Defaults
44 import org.onap.so.logger.LoggingAnchor
45 import org.onap.so.logger.MessageEnum
46 import org.slf4j.Logger
47 import org.slf4j.LoggerFactory
48 import groovy.json.JsonSlurper
49
50 /**
51  * This groovy class supports the <class>DeleteVfModuleVolume.bpmn</class> process.
52  */
53 public class DeleteVfModuleVolumeInfraV1 extends AbstractServiceTaskProcessor {
54     private static final Logger logger = LoggerFactory.getLogger( DeleteVfModuleVolumeInfraV1.class);
55
56         private XmlParser xmlParser = new XmlParser()
57         /**
58          * This method is executed during the preProcessRequest task of the <class>DeleteVfModuleVolume.bpmn</class> process.
59          * @param execution
60          */
61         public InitializeProcessVariables(DelegateExecution execution){
62                 execution.setVariable('prefix', 'DELVfModVol_')
63                 execution.setVariable("DELVfModVol_volumeRequest", null)
64                 execution.setVariable('DELVfModVol_requestInfo', null)
65                 execution.setVariable('DELVfModVol_requestId', null)
66                 execution.setVariable('DELVfModVol_source', null)
67                 execution.setVariable('DELVfModVol_volumeInputs', null)
68                 execution.setVariable('DELVfModVol_volumeOutputs', null)
69                 execution.setVariable('DELVfModVol_volumeGroupId', null)
70                 execution.setVariable('DELVfModVol_vnfType', null)
71                 execution.setVariable('DELVfModVol_serviceId', null)
72                 execution.setVariable('DELVfModVol_cloudRegion', null)
73                 execution.setVariable('DELVfModVol_cloudOwner', null)
74                 execution.setVariable('DELVfModVol_tenantId', null)
75                 execution.setVariable('DELVfModVol_volumeParams', null)
76                 execution.setVariable('DELVfModVol_volumeGroupHeatStackId', null)
77                 execution.setVariable('DELVfModVol_volumeGroupTenantId', null)
78                 execution.setVariable("DELVfModVol_queryAAIVolGrpResponse", null)
79                 execution.setVariable('DELVfModVol_messageId', null)
80                 execution.setVariable('DELVfModVol_deleteVnfARequest', null)
81                 execution.setVariable('DELVfModVol_updateInfraRequest', null)
82                 execution.setVariable('DELVfModVol_CompleteMsoProcessRequest', null)
83                 execution.setVariable('DELVfModVol_WorkflowException', null)
84                 execution.setVariable('DELVfModVol_TransactionSuccessIndicator', false)
85                 execution.setVariable("DELVfModVol_isErrorMessageException", false)
86                 execution.setVariable('DELVfModVol_syncResponseSent', false)
87         }
88
89         /**
90          * Perform initial processing, such as request validation, initialization of variables, etc.
91          * * @param execution
92          */
93         public void preProcessRequest (DelegateExecution execution) {
94                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
95                 preProcessRequest(execution, isDebugEnabled)
96         }
97
98         /**
99          * This method is executed during the preProcessRequest task of the <class>DeleteVfModuleVolume.bpmn</class> process.
100          * @param execution
101          */
102         public void preProcessRequest (DelegateExecution execution, isDebugLogEnabled) {
103
104                 InitializeProcessVariables(execution)
105
106                 String createVolumeIncoming = validateRequest(execution)
107
108                 // check if request is xml or json
109                 try {
110                         def jsonSlurper = new JsonSlurper()
111                         Map reqMap = jsonSlurper.parseText(createVolumeIncoming)
112                         logger.debug(" Request is in JSON format.")
113
114                         def serviceInstanceId = execution.getVariable('serviceInstanceId')
115                         def volumeGroupId = execution.getVariable('volumeGroupId')
116                         def vidUtils = new VidUtils(this)
117                         createVolumeIncoming = vidUtils.createXmlVolumeRequest(reqMap, 'DELETE_VF_MODULE_VOL', serviceInstanceId, volumeGroupId)
118                         execution.setVariable("DELVfModVol_isVidRequest", true)
119                 }
120                 catch(groovy.json.JsonException je) {
121                         logger.debug(" Request is in XML format.")
122                         // assume request is in XML format - proceed as usual to process XML request
123                 }
124
125                 String request = utils.getNodeXml(createVolumeIncoming, "volume-request").drop(38).trim().replace("tag0:","").replace(":tag0","")
126                 execution.setVariable("DELVfModVol_volumeRequest", request)
127
128                 def requestInfo = getRequiredNodeXml(execution, request, 'request-info')
129                 execution.setVariable('DELVfModVol_requestInfo', requestInfo)
130                 String requestId = execution.getVariable("mso-request-id")
131                 if (requestId == null || requestId == "") {
132                         requestId = getRequiredNodeText(execution, requestInfo, 'request-id')
133                 }
134                 execution.setVariable('DELVfModVol_requestId', requestId)
135                 execution.setVariable('DELVfModVol_source', getNodeTextForce(requestInfo, 'source'))
136
137                 def volumeInputs = getRequiredNodeXml(execution, request, 'volume-inputs')
138                 execution.setVariable('DELVfModVol_volumeInputs', volumeInputs)
139                 execution.setVariable('DELVfModVol_volumeGroupId', getRequiredNodeText(execution, volumeInputs, 'volume-group-id'))
140                 execution.setVariable('DELVfModVol_vnfType', getRequiredNodeText(execution, volumeInputs, 'vnf-type'))
141                 execution.setVariable('DELVfModVol_serviceId', utils.getNodeText(volumeInputs, 'service-id'))
142                 execution.setVariable('DELVfModVol_tenantId', getRequiredNodeText(execution, volumeInputs, 'tenant-id'))
143                 execution.setVariable('DELVfModVol_messageId', UUID.randomUUID().toString())
144                 execution.setVariable('DELVfModVol_volumeOutputs', utils.getNodeXml(request, 'volume-outputs', false))
145                 execution.setVariable('DELVfModVol_volumeParams', utils.getNodeXml(request, 'volume-params'))
146                 execution.setVariable('DELVfModVol_cloudRegion', utils.getNodeText(request, 'aic-cloud-region'))
147                 execution.setVariable('DELVfModVol_cloudOwner', utils.getNodeText(request, 'cloud-owner'))
148
149                 setBasicDBAuthHeader(execution, isDebugLogEnabled)
150
151                 logger.debug('Request: ' + createVolumeIncoming)
152         }
153
154         public void sendSyncResponse (DelegateExecution execution, isDebugEnabled) {
155
156                 String volumeRequest = execution.getVariable("DELVfModVol_volumeRequest")
157                 logger.debug(" DELVfModVol_volumeRequest - " + "\n" + volumeRequest)
158                 // RESTResponse (for API Handler (APIH) Reply Task)
159                 String deleteVolumeRequest =
160                                 """<rest:RESTResponse xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd" statusCode="200">
161                 <rest:payload xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"
162                           contentType="text/xml">
163                                 ${volumeRequest}
164                 </rest:payload>
165                        </rest:RESTResponse>""".trim()
166
167                 def isVidRequest = execution.getVariable('DELVfModVol_isVidRequest')
168                 def syncResponse = ''
169
170                 if(isVidRequest) {
171                         def serviceInstanceId = execution.getVariable('serviceInstanceId')
172                         def volumeGroupId = execution.getVariable('volumeGroupId')
173                         def requestId = execution.getVariable('DELVfModVol_requestId')
174                         syncResponse = """{"requestReferences":{"instanceId":"${volumeGroupId}","requestId":"${requestId}"}}""".trim()
175                 }
176                 else {
177                         syncResponse = utils.formatXml(deleteVolumeRequest)
178                 }
179
180                 execution.setVariable('DELVfModVol_syncResponseSent', true)
181
182                 sendWorkflowResponse(execution, 200, syncResponse)
183         }
184
185
186         public void sendSyncError (DelegateExecution execution, isDebugEnabled) {
187                 WorkflowException we = execution.getVariable('WorkflowException')
188                 def errorCode = we?.getErrorCode()
189                 def errorMessage = we?.getErrorMessage()
190                 //default to 400 since only invalid request will trigger this method
191                 sendWorkflowResponse(execution, 400, errorMessage)
192         }
193
194
195         public void callRESTQueryAAICloudRegion (DelegateExecution execution, isDebugEnabled) {
196
197                 String cloudRegion = execution.getVariable('DELVfModVol_cloudRegion')
198
199                 AaiUtil aaiUtil = new AaiUtil(this)
200
201                 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(Defaults.CLOUD_OWNER.toString(), cloudRegion))
202                 def queryCloudRegionRequest = aaiUtil.createAaiUri(uri)
203
204                 execution.setVariable("DELVfModVol_queryCloudRegionRequest", queryCloudRegionRequest)
205
206                 cloudRegion = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "PO", cloudRegion)
207
208                 ExceptionUtil exceptionUtil = new ExceptionUtil()
209
210                 if ((cloudRegion != "ERROR")) {
211                         if(execution.getVariable("DELVfModVol_queryCloudRegionReturnCode") == "404"){
212                                 execution.setVariable("DELVfModVol_aicCloudRegion", "AAIAIC25")
213                         }else{
214                                 execution.setVariable("DELVfModVol_aicCloudRegion", cloudRegion)
215                         }
216                         execution.setVariable("DELVfModVol_cloudRegion", cloudRegion)
217                         execution.setVariable("DELVfModVol_isCloudRegionGood", true)
218
219                 } else {
220                         logger.debug("AAI Query Cloud Region Unsuccessful.")
221                         execution.setVariable("DELVfModVol_isCloudRegionGood", false)
222                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "AAI Query Cloud Region Unsuccessful. Return Code: " + execution.getVariable("DELVfModVol_queryCloudRegionReturnCode"))
223                 }
224
225                 logger.debug(" is Cloud Region Good: " + execution.getVariable("DELVfModVol_isCloudRegionGood"))
226         }
227
228         /**
229          * Query volume group by id
230          * @param execution
231          */
232         public void queryAAIForVolumeGroup(DelegateExecution execution, isDebugLogEnabled) {
233
234                 ExceptionUtil exceptionUtil = new ExceptionUtil()
235
236                 def volumeGroupId = execution.getVariable('DELVfModVol_volumeGroupId')
237                 if(volumeGroupId == null) {
238                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, 'volume-group-id is not provided in the request')
239                         throw new Exception('volume-group-id is not provided in the request')
240                 }
241                 String cloudRegion = execution.getVariable('DELVfModVol_aicCloudRegion')
242
243         try {
244             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(Defaults.CLOUD_OWNER.toString(), cloudRegion).volumeGroup(volumeGroupId))
245             AAIResultWrapper volumeGroupWrapper = getAAIClient().get(uri)
246
247             if (!volumeGroupWrapper.isEmpty()) {
248                 Optional<VolumeGroup> volumeGroupOp = volumeGroupWrapper.asBean(VolumeGroup.class)
249                 execution.setVariable("DELVfModVol_queryAAIVolGrpResponse", volumeGroupOp.get())
250                 def heatStackId = volumeGroupOp.get().getHeatStackId() ?: ""
251                 execution.setVariable('DELVfModVol_volumeGroupHeatStackId', heatStackId)
252
253                 if ( volumeGroupWrapper.getRelationships().isPresent() && !volumeGroupWrapper.getRelationships().get().getRelatedUris(Types.VF_MODULE).isEmpty()) {
254                     logger.debug('Volume Group ' + volumeGroupId + ' currently in use')
255                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume Group ${volumeGroupId} currently in use - found vf-module relationship.")
256                 }
257
258                 def volumeGroupTenantId = getTenantIdFromVolumeGroup(volumeGroupWrapper)
259                 if (volumeGroupTenantId == null) {
260                     logger.debug("Could not find Tenant Id element in Volume Group with Volume Group Id ${volumeGroupId}")
261                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Could not find Tenant Id element in Volume Group with Volume Group Id ${volumeGroupId}")
262                 }
263
264                 execution.setVariable('DELVfModVol_volumeGroupTenantId', volumeGroupTenantId)
265                 logger.debug('Received Tenant Id ' + volumeGroupTenantId + ' from AAI for Volume Group with Volume Group Id ' + volumeGroupId)
266             } else {
267                 logger.debug("Volume Group ${volumeGroupId} not found in AAI")
268                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume Group ${volumeGroupId} not found in AAI. Response code: 404")
269             }
270         }catch (BpmnError e){
271             throw e
272         }catch (Exception e){
273             WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(e.getMessage(), execution)
274             throw new BpmnError("MSOWorkflowException")
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(AAIResultWrapper wrapper) {
286         if(wrapper.getRelationships().isPresent()) {
287             List<AAIResourceUri> tenantURIList = wrapper.getRelationships().get().getRelatedUris(Types.TENANT)
288             if(!tenantURIList.isEmpty()){
289                 return tenantURIList.get(0).getURIKeys().get(AAIFluentTypeBuilder.Types.TENANT.getUriParams().tenantId)
290             }
291         }
292                 return null
293         }
294
295         private boolean hasVnfRelationship(String volumeGroupXml) {
296                 def Node volumeGroupNode = xmlParser.parseText(volumeGroupXml)
297                 def Node relationshipList = utils.getChildNode(volumeGroupNode, 'relationship-list')
298                 if (relationshipList != null) {
299                         def NodeList relationships = utils.getIdenticalChildren(relationshipList, 'relationship')
300                         for (Node relationship in relationships) {
301                                 def Node relatedTo = utils.getChildNode(relationship, 'related-to')
302                                 if ((relatedTo != null) && (relatedTo.text().equals('generic-vnf'))) {
303                                         def Node relatedLink = utils.getChildNode(relationship, 'related-link')
304                                         if (relatedLink !=null && relatedLink.text() != null){
305                                                 return true
306                                         }
307                                 }
308                         }
309                 }
310                 return false
311         }
312
313         public void prepareVnfAdapterDeleteRequest(DelegateExecution execution, isDebugLogEnabled) {
314                 def cloudRegion = execution.getVariable('DELVfModVol_cloudRegion')
315                 def cloudOwner = execution.getVariable('DELVfModVol_cloudOwner')
316                 def tenantId = execution.getVariable('DELVfModVol_tenantId')
317                 def volumeGroupId = execution.getVariable('DELVfModVol_volumeGroupId')
318                 def volumeGroupHeatStackId = execution.getVariable('DELVfModVol_volumeGroupHeatStackId')
319                 def requestId = execution.getVariable('DELVfModVol_requestId')
320                 def serviceId = execution.getVariable('DELVfModVol_serviceId')
321
322                 def messageId = execution.getVariable('DELVfModVol_messageId')
323                 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
324                 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host", execution)
325                 if ('true'.equals(useQualifiedHostName)) {
326                                 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
327                 }
328
329                 String vnfAdapterRestRequest = """
330                         <deleteVolumeGroupRequest>
331                                 <cloudSiteId>${MsoUtils.xmlEscape(cloudRegion)}</cloudSiteId>
332                                 <cloudOwner>${MsoUtils.xmlEscape(cloudOwner)}</cloudOwner>
333                                 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
334                                 <volumeGroupId>${MsoUtils.xmlEscape(volumeGroupId)}</volumeGroupId>
335                                 <volumeGroupStackId>${MsoUtils.xmlEscape(volumeGroupHeatStackId)}</volumeGroupStackId>
336                                 <skipAAI>true</skipAAI>
337                             <msoRequest>
338                                 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
339                                 <serviceInstanceId>${MsoUtils.xmlEscape(serviceId)}</serviceInstanceId>
340                             </msoRequest>
341                             <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
342                             <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
343                         </deleteVolumeGroupRequest>
344                 """
345                 vnfAdapterRestRequest = utils.formatXml(vnfAdapterRestRequest)
346                 execution.setVariable('DELVfModVol_deleteVnfARequest', vnfAdapterRestRequest)
347                 logger.debug('Request for VNFAdapter Rest:\n' + vnfAdapterRestRequest)
348         }
349
350
351         public void deleteVolGrpId(DelegateExecution execution, isDebugEnabled) {
352
353                 // get variables
354         VolumeGroup volumeGroup = execution.getVariable("DELVfModVol_queryAAIVolGrpResponse")
355                 String groupId = volumeGroup.getVolumeGroupId()
356                 String cloudRegion = execution.getVariable('DELVfModVol_aicCloudRegion')
357
358         ExceptionUtil exceptionUtil = new ExceptionUtil()
359         try {
360             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(Defaults.CLOUD_OWNER.toString(), cloudRegion).volumeGroup(groupId))
361             getAAIClient().delete(uri)
362             logger.debug("Volume group $groupId deleted.")
363         }catch(NotFoundException e){
364             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $groupId not found for delete in AAI Response code: 404")
365         }catch(Exception e1){
366             WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(e1.getMessage(), execution)
367             throw new BpmnError("MSOWorkflowException")
368         }
369         }
370
371
372         public void prepareDBRequest (DelegateExecution execution, isDebugLogEnabled) {
373
374                 WorkflowException workflowExceptionObj = execution.getVariable("WorkflowException")
375                 ExceptionUtil exceptionUtil = new ExceptionUtil();
376                 def requestId = execution.getVariable('DELVfModVol_requestId')
377                 def volOutputs = execution.getVariable('DELVfModVol_volumeOutputs')
378                 def statusMessage = "VolumeGroup successfully deleted"
379                 def progress = "100"
380                 def requestStatus = "COMPLETE"
381
382                 if (workflowExceptionObj != null) {
383                         statusMessage = (workflowExceptionObj.getErrorMessage())
384                         execution.setVariable("DELVfModVol_WorkflowExceptionMessage", statusMessage)
385                         execution.setVariable("DELVfModVol_WorkflowExceptionCode", workflowExceptionObj.getErrorCode())
386                         requestStatus = "FAILURE"
387                         progress = ""
388                 }
389
390                 String updateInfraRequest = """
391                         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
392                                         xmlns:req="http://org.onap.so/requestsdb">
393                                 <soapenv:Header/>
394                                 <soapenv:Body>
395                                         <req:updateInfraRequest>
396                                                 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
397                                                 <lastModifiedBy>BPMN</lastModifiedBy>
398                                                 <statusMessage>${MsoUtils.xmlEscape(statusMessage)}</statusMessage>
399                                                 <requestStatus>${MsoUtils.xmlEscape(requestStatus)}</requestStatus>
400                                                 <progress>${MsoUtils.xmlEscape(progress)}</progress>
401                                                 <vnfOutputs>${MsoUtils.xmlEscape(volOutputs)}</vnfOutputs>
402                                         </req:updateInfraRequest>
403                                 </soapenv:Body>
404                         </soapenv:Envelope>
405                 """
406
407                 updateInfraRequest = utils.formatXml(updateInfraRequest)
408                 execution.setVariable('DELVfModVol_updateInfraRequest', updateInfraRequest)
409                 logger.debug('Request for Update Infra Request:\n' + updateInfraRequest)
410
411         }
412
413
414         public void prepareCompletionHandlerRequest (DelegateExecution execution, isDebugLogEnabled) {
415                 def requestId = execution.getVariable("mso-request-id")
416                 def source = execution.getVariable("DELVfModVol_source")
417
418                 String msoCompletionRequest =
419                         """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
420                                                         xmlns:ns="http://org.onap/so/request/types/v1">
421                                         <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
422                                                 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
423                                                 <action>DELETE</action>
424                                                 <source>${MsoUtils.xmlEscape(source)}</source>
425                                         </request-info>
426                                         <aetgt:status-message>Volume Group has been deleted successfully.</aetgt:status-message>
427                                         <aetgt:mso-bpel-name>BPMN VF Module Volume action: DELETE</aetgt:mso-bpel-name>
428                                 </aetgt:MsoCompletionRequest>"""
429
430                 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
431                 execution.setVariable('DELVfModVol_CompleteMsoProcessRequest', xmlMsoCompletionRequest)
432                 logger.debug(" Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
433
434         }
435
436
437
438         public void prepareFalloutHandler (DelegateExecution execution) {
439
440                 execution.setVariable("DELVfModVol_Success", false)
441                 String requestId = execution.getVariable("DELVfModVol_requestId")
442                 String source = execution.getVariable("DELVfModVol_source")
443
444                 WorkflowException workflowExceptionObj = execution.getVariable("WorkflowException")
445                 def errorMessage = workflowExceptionObj.getErrorMessage()
446                 def errorCode =  workflowExceptionObj.getErrorCode()
447
448                 String falloutHandlerRequest =
449                     """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
450                                                              xmlns:ns="http://org.onap/so/request/types/v1"
451                                                              xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
452                                    <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
453                                       <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
454                                       <action>DELETE</action>
455                                       <source>${MsoUtils.xmlEscape(source)}</source>
456                                    </request-info>
457                                         <aetgt:WorkflowException>
458                                       <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
459                                       <aetgt:ErrorCode>${MsoUtils.xmlEscape(errorCode)}</aetgt:ErrorCode>
460                                         </aetgt:WorkflowException>
461                                 </aetgt:FalloutHandlerRequest>"""
462
463                 // Format Response
464                 String xmlHandlerRequest = utils.formatXml(falloutHandlerRequest)
465                 logger.debug(xmlHandlerRequest)
466
467                 execution.setVariable("DELVfModVol_FalloutHandlerRequest", xmlHandlerRequest)
468                 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
469                                 "Overall Error Response going to FalloutHandler", "BPMN",
470                                 ErrorCode.UnknownError.getValue(), "\n" + xmlHandlerRequest);
471         }
472
473
474         /**
475          * Create a WorkflowException for the error case where the Tenant Id from
476          * AAI did not match the Tenant Id in the incoming request.
477          *
478          * @param execution The flow's execution instance.
479          */
480         public void handleTenantIdMismatch(DelegateExecution execution, isDebugLogEnabled) {
481
482                 def volumeGroupId = execution.getVariable('DELVfModVol_volumeGroupId')
483                 def aicCloudRegion = execution.getVariable('DELVfModVol_aicCloudRegion')
484                 def tenantId = execution.getVariable('DELVfModVol_tenantId')
485                 def volumeGroupTenantId = execution.getVariable('DELVfModVol_volumeGroupTenantId')
486
487                 def String errorMessage = 'TenantId ' + tenantId + ' in incoming request does not match Tenant Id ' + volumeGroupTenantId +
488                         ' retrieved from AAI for Volume Group Id ' + volumeGroupId
489                 logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
490                                 "Error in DeleteVfModuleVolume: " + "\n" + errorMessage, "BPMN",
491                                 ErrorCode.UnknownError.getValue());
492
493                 ExceptionUtil exceptionUtil = new ExceptionUtil()
494                 exceptionUtil.buildWorkflowException(execution, 5000, errorMessage)
495
496         }
497
498 }