3f0b8d11f15f37c7354e117058b8936112d2eab2
[so.git] /
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - SO\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.mso.bpmn.infrastructure.scripts;\r
22 \r
23 import groovy.json.JsonSlurper\r
24 import groovy.json.JsonOutput\r
25 \r
26 import org.camunda.bpm.engine.delegate.BpmnError\r
27 import org.camunda.bpm.engine.delegate.DelegateExecution\r
28 import org.onap.appc.client.lcm.model.Action\r
29 import org.apache.commons.lang3.*\r
30 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;\r
31 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil;\r
32 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils;\r
33 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils;\r
34 import org.openecomp.mso.bpmn.common.scripts.VidUtils;\r
35 import org.openecomp.mso.bpmn.core.RollbackData\r
36 import org.openecomp.mso.bpmn.core.WorkflowException\r
37 import org.openecomp.mso.bpmn.core.json.JsonUtils\r
38 \r
39 public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {\r
40 \r
41         ExceptionUtil exceptionUtil = new ExceptionUtil()\r
42         JsonUtils jsonUtil = new JsonUtils()\r
43 \r
44         /**\r
45          * Validates the request message and sets up the workflow.\r
46          * @param execution the execution\r
47          */\r
48         public void preProcessRequest(DelegateExecution execution) {\r
49                 def method = getClass().getSimpleName() + '.preProcessRequest(' +\r
50                         'execution=' + execution.getId() +\r
51                         ')'\r
52                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
53                 logDebug('Entered ' + method, isDebugLogEnabled)\r
54 \r
55                 execution.setVariable("CVFMI_sentSyncResponse", false)\r
56                 \r
57                 def prefix = 'CVFMI_'\r
58                 logDebug('Entered 1' + method, isDebugLogEnabled)\r
59                 execution.setVariable('prefix', prefix)\r
60                 logDebug('Entered 2' + method, isDebugLogEnabled)\r
61                 execution.setVariable("isVidRequest", "false")\r
62 \r
63                 logDebug("Set variables", isDebugLogEnabled)\r
64 \r
65                 def rollbackData = execution.getVariable("RollbackData")\r
66                 if (rollbackData == null) {\r
67                         rollbackData = new RollbackData()\r
68                 }\r
69                 execution.setVariable("RollbackData", rollbackData)\r
70 \r
71                 logDebug("Set rollback data", isDebugLogEnabled)\r
72                 def incomingRequest = execution.getVariable('bpmnRequest')\r
73 \r
74                 utils.log("DEBUG", "Incoming Infra Request: " + incomingRequest, isDebugLogEnabled)\r
75                 utils.logAudit("CreateVfModule Infra incoming Request: " + incomingRequest)\r
76 \r
77                 setBasicDBAuthHeader(execution, isDebugLogEnabled)\r
78                 \r
79                 // check if request is xml or json\r
80                 try {\r
81                         def jsonSlurper = new JsonSlurper()\r
82                         def jsonOutput = new JsonOutput()\r
83                         Map reqMap = jsonSlurper.parseText(incomingRequest)\r
84                         utils.log("DEBUG", " Request is in JSON format.", isDebugLogEnabled)\r
85 \r
86                         def serviceInstanceId = execution.getVariable('serviceInstanceId')\r
87                         def vnfId = execution.getVariable('vnfId')\r
88                         \r
89                         execution.setVariable(prefix + 'serviceInstanceId', serviceInstanceId)\r
90                         execution.setVariable(prefix+'vnfId', vnfId)\r
91                         execution.setVariable("isVidRequest", "true")\r
92                         \r
93                         def vnfName = ''\r
94                         def asdcServiceModelVersion = ''\r
95                         def serviceModelInfo = null\r
96                         def vnfModelInfo = null\r
97                         \r
98                         def relatedInstanceList = reqMap.requestDetails?.relatedInstanceList\r
99                                                 \r
100                         if (relatedInstanceList != null) {\r
101                                 relatedInstanceList.each {\r
102                                         if (it.relatedInstance.modelInfo?.modelType == 'service') {\r
103                                                 asdcServiceModelVersion = it.relatedInstance.modelInfo?.modelVersion\r
104                                                 serviceModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)\r
105                                                 \r
106                                         }\r
107                                         if (it.relatedInstance.modelInfo.modelType == 'vnf') {\r
108                                                 vnfName = it.relatedInstance.instanceName ?: ''\r
109                                                 vnfModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)\r
110                                         }\r
111                                 }\r
112                         }\r
113                         \r
114                         execution.setVariable(prefix + 'vnfName', vnfName)\r
115                         execution.setVariable(prefix + 'asdcServiceModelVersion', asdcServiceModelVersion)\r
116                         execution.setVariable(prefix + 'serviceModelInfo', serviceModelInfo)\r
117                         execution.setVariable(prefix + 'vnfModelInfo', vnfModelInfo)\r
118                         \r
119                         \r
120                         def vnfType = execution.getVariable('vnfType')\r
121                         execution.setVariable(prefix + 'vnfType', vnfType)      \r
122                         def vfModuleId = execution.getVariable('vfModuleId')\r
123                         execution.setVariable(prefix + 'vfModuleId', vfModuleId)\r
124                         def volumeGroupId = execution.getVariable('volumeGroupId')\r
125                         execution.setVariable(prefix + 'volumeGroupId', volumeGroupId)\r
126                         def userParams = reqMap.requestDetails?.requestParameters?.userParams                                   \r
127                         \r
128                         Map<String, String> userParamsMap = [:]\r
129                         if (userParams != null) {\r
130                                 userParams.each { userParam ->\r
131                                         userParamsMap.put(userParam.name, jsonOutput.toJson(userParam.value).toString())\r
132                                 }                                                       \r
133                         }               \r
134                                                 \r
135                         utils.log("DEBUG", 'Processed user params: ' + userParamsMap, isDebugLogEnabled)                \r
136                         \r
137                         execution.setVariable(prefix + 'vfModuleInputParams', userParamsMap)\r
138                         \r
139                         def isBaseVfModule = "false"\r
140                         if (execution.getVariable('isBaseVfModule') == true) {\r
141                                 isBaseVfModule = "true"\r
142                         }                       \r
143                         \r
144                         execution.setVariable(prefix + 'isBaseVfModule', isBaseVfModule)\r
145                                                 \r
146                         def requestId = execution.getVariable("mso-request-id")\r
147                         execution.setVariable(prefix + 'requestId', requestId)\r
148                         \r
149                         def vfModuleModelInfo = jsonOutput.toJson(reqMap.requestDetails?.modelInfo)\r
150                         execution.setVariable(prefix + 'vfModuleModelInfo', vfModuleModelInfo)\r
151                         \r
152                         def suppressRollback = reqMap.requestDetails?.requestInfo?.suppressRollback\r
153                         \r
154                         \r
155                         def backoutOnFailure = ""\r
156                         if(suppressRollback != null){\r
157                                 if ( suppressRollback == true) {\r
158                                         backoutOnFailure = "false"\r
159                                 } else if ( suppressRollback == false) {\r
160                                         backoutOnFailure = "true"\r
161                                 }\r
162                         }\r
163                         \r
164                         execution.setVariable('disableRollback', suppressRollback)\r
165                         \r
166                         def vfModuleName = reqMap.requestDetails?.requestInfo?.instanceName ?: null\r
167                         execution.setVariable(prefix + 'vfModuleName', vfModuleName)\r
168                         \r
169                         def serviceId = reqMap.requestDetails?.requestParameters?.serviceId ?: ''\r
170                         execution.setVariable(prefix + 'serviceId', serviceId)\r
171                         \r
172                         def usePreload = reqMap.requestDetails?.requestParameters?.usePreload\r
173                         execution.setVariable(prefix + 'usePreload', usePreload)\r
174                         \r
175                         // This is aLaCarte flow, so aLaCarte flag is always on                         \r
176                         execution.setVariable(prefix + 'aLaCarte', true)\r
177                         \r
178                         def cloudConfiguration = reqMap.requestDetails?.cloudConfiguration\r
179                         def lcpCloudRegionId    = cloudConfiguration.lcpCloudRegionId\r
180                         execution.setVariable(prefix + 'lcpCloudRegionId', lcpCloudRegionId)\r
181                         def tenantId = cloudConfiguration.tenantId\r
182                         execution.setVariable(prefix + 'tenantId', tenantId)\r
183                         \r
184                         def globalSubscriberId = reqMap.requestDetails?.subscriberInfo?.globalSubscriberId ?: ''\r
185                         execution.setVariable(prefix + 'globalSubscriberId', globalSubscriberId)\r
186                         \r
187                         execution.setVariable(prefix + 'sdncVersion', '1702')\r
188 \r
189                         execution.setVariable("CreateVfModuleInfraSuccessIndicator", false)\r
190                         execution.setVariable("RollbackCompleted", false)\r
191                         \r
192                         execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)\r
193                         \r
194                         \r
195                         def source = reqMap.requestDetails?.requestInfo?.source\r
196                         execution.setVariable("CVFMI_source", source)\r
197                         \r
198                         //For Completion Handler & Fallout Handler\r
199                         String requestInfo =\r
200                         """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
201                                         <request-id>${requestId}</request-id>\r
202                                         <action>CREATE</action>\r
203                                         <source>${source}</source>\r
204                                    </request-info>"""\r
205                         \r
206                         execution.setVariable("CVFMI_requestInfo", requestInfo)\r
207                         \r
208                         //backoutOnFailure\r
209                         \r
210                         execution.setVariable("CVFMI_originalWorkflowException", null)\r
211                         \r
212 \r
213                         def newVfModuleId = UUID.randomUUID().toString()\r
214                         execution.setVariable("newVfModuleId", newVfModuleId)\r
215                         execution.setVariable(prefix + 'vfModuleId', newVfModuleId)\r
216                         execution.setVariable('actionHealthCheck', Action.HealthCheck)\r
217                         execution.setVariable('actionConfigScaleOut', Action.ConfigScaleOut)\r
218                         def controllerType = execution.getVariable('controllerType')\r
219                         execution.setVariable(prefix + 'controllerType', controllerType)\r
220                         execution.setVariable('healthCheckIndex0', 0)\r
221 \r
222                         logDebug('RequestInfo: ' + execution.getVariable("CVFMI_requestInfo"), isDebugLogEnabled)                       \r
223                         \r
224                         logDebug('rollbackEnabled: ' + execution.getVariable("CVFMI_rollbackEnabled"), isDebugLogEnabled)\r
225 \r
226                         logDebug('Exited ' + method, isDebugLogEnabled)\r
227                 } catch (BpmnError bpmnError) {\r
228                         throw bpmnError\r
229                 }\r
230                 catch(groovy.json.JsonException je) {\r
231                         utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)\r
232                         exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - During PreProcessRequest")\r
233                 }\r
234                 catch(Exception e) {\r
235                         String restFaultMessage = e.getMessage()\r
236                         //execution.setVariable("CVFMODVOL2_RESTFault", restFaultMessage)\r
237                         //execution.setVariable("CVFMODVOL2_isDataOk", false)\r
238                         utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)\r
239                         exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - During PreProcessRequest")\r
240                 }\r
241 \r
242         }\r
243 \r
244         /**\r
245          * Validates a workflow response.\r
246          * @param execution the execution\r
247          * @param responseVar the execution variable in which the response is stored\r
248          * @param responseCodeVar the execution variable in which the response code is stored\r
249          * @param errorResponseVar the execution variable in which the error response is stored\r
250          */\r
251         public void validateWorkflowResponse(DelegateExecution execution, String responseVar,\r
252                         String responseCodeVar, String errorResponseVar) {\r
253                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)\r
254                 sdncAdapterUtils.validateSDNCResponse(execution, responseVar, responseCodeVar, errorResponseVar)\r
255         }\r
256 \r
257 \r
258         /**\r
259          * Sends the empty, synchronous response back to the API Handler.\r
260          * @param execution the execution\r
261          */\r
262         public void sendResponse(DelegateExecution execution) {\r
263                 def method = getClass().getSimpleName() + '.sendResponse(' +\r
264                         'execution=' + execution.getId() +\r
265                         ')'\r
266                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
267                 logDebug('Entered ' + method, isDebugLogEnabled)\r
268 \r
269                 try {\r
270                         def requestInfo = execution.getVariable('CVFMI_requestInfo')\r
271                         def requestId = execution.getVariable('CVFMI_requestId')\r
272                         def source = execution.getVariable('CVFMI_source')                      \r
273                         \r
274                         // RESTResponse (for API Handler (APIH) Reply Task)\r
275                         def newVfModuleId = execution.getVariable("newVfModuleId")\r
276                         String synchResponse = """{"requestReferences":{"instanceId":"${newVfModuleId}","requestId":"${requestId}"}}""".trim()\r
277 \r
278                         sendWorkflowResponse(execution, 200, synchResponse)\r
279 \r
280                         execution.setVariable("CVFMI_sentSyncResponse", true)\r
281                         utils.logAudit("CreateVfModule Infra Response: " + synchResponse)\r
282                         logDebug('Exited ' + method, isDebugLogEnabled)\r
283                 } catch (BpmnError e) {\r
284                         throw e;\r
285                 } catch (Exception e) {\r
286                         logError('Caught exception in ' + method, e)\r
287                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())\r
288                 }\r
289         }\r
290 \r
291         /**\r
292          *\r
293          * @param execution the execution\r
294          */\r
295         public void postProcessResponse(DelegateExecution execution){\r
296                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
297 \r
298                 utils.log("DEBUG", " ======== STARTED PostProcessResponse Process ======== ", isDebugEnabled)\r
299                 try{                    \r
300                         def requestInfo = execution.getVariable("CVFMI_requestInfo")\r
301                         def action = utils.getNodeText1(requestInfo, "action")\r
302 \r
303                         utils.log("DEBUG", "requestInfo is: " + requestInfo, isDebugEnabled)\r
304                         utils.log("DEBUG", "action is: " + action, isDebugEnabled)\r
305 \r
306                         String payload =\r
307                                         """  <aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
308                                xmlns:ns="http://org.openecomp/mso/request/types/v1"\r
309                                xmlns:ns8="http://org.openecomp/mso/workflow/schema/v1">\r
310                         <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
311                         ${requestInfo}\r
312                         </request-info>\r
313                         <ns8:status-message>Vf Module has been created successfully.</ns8:status-message>\r
314                         <ns8:mso-bpel-name>BPMN</ns8:mso-bpel-name>\r
315                         </aetgt:MsoCompletionRequest>"""\r
316 \r
317                         payload = utils.formatXml(payload)\r
318                         execution.setVariable("CVFMI_SuccessFlag", true)\r
319                         execution.setVariable("CVFMI_msoCompletionRequest", payload)\r
320                         utils.logAudit("CreateVfModuleInfra completion request: " + payload)\r
321                         utils.log("DEBUG", "Outgoing MsoCompletionRequest: \n" + payload, isDebugEnabled)\r
322 \r
323                 }catch(Exception e){\r
324                         utils.log("ERROR", "Exception Occured Processing PostProcessResponse. Exception is:\n" + e, isDebugEnabled)\r
325                         execution.setVariable("CVFMI_ErrorResponse", "Error Occured during PostProcessResponse Method:\n" + e.getMessage())\r
326                 }\r
327                 utils.log("DEBUG", "======== COMPLETED PostProcessResponse Process ======== ", isDebugEnabled)\r
328         }\r
329 \r
330 \r
331 \r
332 \r
333 \r
334         /**\r
335          * Validates the request, request id and service instance id.  If a problem is found,\r
336          * a WorkflowException is generated and an MSOWorkflowException event is thrown. This\r
337          * method also sets up the log context for the workflow.\r
338          * @param execution the execution\r
339          * @return the validated request\r
340          */\r
341         public String validateInfraRequest(DelegateExecution execution) {\r
342                 def method = getClass().getSimpleName() + '.validateInfraRequest(' +\r
343                         'execution=' + execution.getId() +\r
344                         ')'\r
345                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
346                 logDebug('Entered ' + method, isDebugLogEnabled)\r
347 \r
348                 String processKey = getProcessKey(execution);\r
349                 def prefix = execution.getVariable("prefix")\r
350 \r
351                 if (prefix == null) {\r
352                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " prefix is null")\r
353                 }\r
354 \r
355                 try {\r
356                         def request = execution.getVariable(prefix + 'Request')\r
357 \r
358                         if (request == null) {\r
359                                 request = execution.getVariable(processKey + 'Request')\r
360 \r
361                                 if (request == null) {\r
362                                         request = execution.getVariable('bpmnRequest')\r
363                                 }\r
364 \r
365                                 setVariable(execution, processKey + 'Request', null);\r
366                                 setVariable(execution, 'bpmnRequest', null);\r
367                                 setVariable(execution, prefix + 'Request', request);\r
368                         }\r
369 \r
370                         if (request == null) {\r
371                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request is null")\r
372                         }\r
373 \r
374                         /*\r
375 \r
376                         def requestId = execution.getVariable("mso-request-id")\r
377 \r
378                         if (requestId == null) {\r
379                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request has no mso-request-id")\r
380                         }\r
381 \r
382                         setVariable(execution, prefix + 'requestId', requestId)\r
383 \r
384                         def serviceInstanceId = execution.getVariable("mso-service-instance-id")\r
385 \r
386                         if (serviceInstanceId == null) {\r
387                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request message has no mso-service-instance-id")\r
388                         }\r
389 \r
390                         utils.logContext(requestId, serviceInstanceId)\r
391                         */\r
392                         utils.logAudit("CreateVfModule incoming request: " + request)\r
393                         logDebug('Incoming message: ' + System.lineSeparator() + request, isDebugLogEnabled)\r
394                         logDebug('Exited ' + method, isDebugLogEnabled)\r
395                         return request\r
396                 } catch (BpmnError e) {\r
397                         throw e;\r
398                 } catch (Exception e) {\r
399                         logError('Caught exception in ' + method, e)\r
400                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Invalid Message")\r
401                 }\r
402         }\r
403 \r
404         public void prepareUpdateInfraRequest(DelegateExecution execution){\r
405                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
406 \r
407                 utils.log("DEBUG", " ======== STARTED prepareUpdateInfraRequest Process ======== ", isDebugEnabled)\r
408                 try{\r
409                         \r
410                         \r
411                         String requestInfo = execution.getVariable("CVFMI_requestInfo")                 \r
412                         def aicCloudRegion      = execution.getVariable("CVFMI_lcpCloudRegionId")\r
413                         def tenantId = execution.getVariable("CVFMI_tenantId")\r
414                         def requestId = utils.getNodeText1(requestInfo, "request-id")\r
415                         def vnfId = execution.getVariable("CVFMI_vnfId")\r
416                         def vfModuleId = execution.getVariable("CVFMI_vfModuleId")\r
417                         // vfModuleName may be generated by DoCreateVfModule subprocess if it is not specified on the input\r
418                         def vfModuleName = execution.getVariable("CVFMI_vfModuleName")\r
419 \r
420                         def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")\r
421                         execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)\r
422                         utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)\r
423 \r
424                         String payload =\r
425                                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
426                                                 xmlns:ns="http://org.openecomp.mso/requestsdb">\r
427                                                 <soapenv:Header/>\r
428                                                 <soapenv:Body>\r
429                                                         <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">\r
430                                                         <requestId>${requestId}</requestId>\r
431                                                         <lastModifiedBy>BPMN</lastModifiedBy>\r
432                                                         <statusMessage>VF Module successfully created</statusMessage>\r
433                                                         <responseBody></responseBody>\r
434                                                         <requestStatus>COMPLETE</requestStatus>\r
435                                                         <progress>100</progress>\r
436                                                         <vnfOutputs>&lt;vnf-outputs xmlns="http://org.openecomp/mso/infra/vnf-request/v1" xmlns:aetgt="http://org.openecomp/mso/infra/vnf-request/v1" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"&gt;&lt;vnf-id&gt;${vnfId}&lt;/vnf-id&gt;&lt;vf-module-id&gt;${vfModuleId}&lt;/vf-module-id&gt;&lt;/vnf-outputs&gt;</vnfOutputs>\r
437                                                         <vfModuleId>${vfModuleId}</vfModuleId>\r
438                                                         <vfModuleName>${vfModuleName}</vfModuleName>\r
439                                                 </ns:updateInfraRequest>\r
440                                         </soapenv:Body>\r
441                                 </soapenv:Envelope>"""\r
442 \r
443                         payload = utils.formatXml(payload)\r
444                         execution.setVariable("CVFMI_updateInfraRequest", payload)\r
445                         utils.log("DEBUG", "Outgoing UpdateInfraRequest: \n" + payload, isDebugEnabled)\r
446                         utils.logAudit("CreateVfModuleInfra Outgoing UpdateInfra Request: " + payload)\r
447 \r
448                 }catch(Exception e){\r
449                         utils.log("ERROR", "Exception Occured Processing prepareUpdateInfraRequest. Exception is:\n" + e, isDebugEnabled)\r
450                         execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareUpdateInfraRequest Method:\n" + e.getMessage())\r
451                 }\r
452                 utils.log("DEBUG", "======== COMPLETED prepareUpdateInfraRequest Process ======== ", isDebugEnabled)\r
453         }\r
454 \r
455         /**\r
456          * Builds a "FalloutHandler" request and stores it in the specified execution variable.\r
457          *\r
458          * @param execution the execution\r
459          * @param resultVar the execution variable in which the result will be stored\r
460          */\r
461         public void falloutHandlerPrep(DelegateExecution execution, String resultVar) {\r
462                 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +\r
463                         'execution=' + execution.getId() +\r
464                         ', resultVar=' + resultVar +\r
465                         ')'\r
466                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
467                 logDebug('Entered ' + method, isDebugLogEnabled)\r
468 \r
469 \r
470                 try {\r
471                         def WorkflowException workflowException = execution.getVariable("WorkflowException")                    \r
472                         def requestInformation = execution.getVariable("CVFMI_requestInfo")\r
473                         def errorResponseCode = workflowException.getErrorCode()\r
474                         def errorResponseMsg = workflowException.getErrorMessage()\r
475                         def encErrorResponseMsg = ""\r
476                         if (errorResponseMsg != null) {\r
477                                 encErrorResponseMsg = errorResponseMsg.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")\r
478                         }\r
479 \r
480                         String content = """\r
481                                 <aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
482                                                 xmlns:reqtype="http://org.openecomp/mso/request/types/v1"\r
483                                                 xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"\r
484                                                 xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">\r
485                                                 ${requestInformation}\r
486                                         <aetgt:WorkflowException>\r
487                                                 <aetgt:ErrorMessage>${encErrorResponseMsg}</aetgt:ErrorMessage>\r
488                                                 <aetgt:ErrorCode>${errorResponseCode}</aetgt:ErrorCode>\r
489                                         </aetgt:WorkflowException>\r
490                                 </aetgt:FalloutHandlerRequest>\r
491                         """\r
492 \r
493                         logDebug("CONTENT before translation: " + content, isDebugLogEnabled)\r
494                         content = utils.formatXml(content)\r
495                         logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)\r
496                         utils.logAudit("CreateVfModuleInfra FallOutHander Request: " + content)\r
497                         execution.setVariable(resultVar, content)\r
498 \r
499                         logDebug('Exited ' + method, isDebugLogEnabled)\r
500                 } catch (BpmnError e) {\r
501                         throw e;\r
502                 } catch (Exception e) {\r
503                         logError('Caught exception in ' + method, e)\r
504                         exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')\r
505                 }\r
506         }\r
507 \r
508         public void logAndSaveOriginalException(DelegateExecution execution) {\r
509                 def method = getClass().getSimpleName() + '.validateRollbackResponse(' +\r
510                         'execution=' + execution.getId() +\r
511                         ')'\r
512                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
513                 logDebug('Entered ' + method, isDebugLogEnabled)\r
514 \r
515                 logWorkflowException(execution, 'CreateVfModuleInfra caught an event')\r
516                 saveWorkflowException(execution, 'CVFMI_originalWorkflowException')\r
517         }\r
518 \r
519         public void validateRollbackResponse(DelegateExecution execution) {\r
520                 def method = getClass().getSimpleName() + '.validateRollbackResponse(' +\r
521                         'execution=' + execution.getId() +\r
522                         ')'\r
523                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
524                 logDebug('Entered ' + method, isDebugLogEnabled)\r
525 \r
526                 def originalException = execution.getVariable("CVFMI_originalWorkflowException")\r
527                 execution.setVariable("WorkflowException", originalException)\r
528 \r
529                 execution.setVariable("RollbackCompleted", true)\r
530 \r
531         }\r
532         \r
533         public void sendErrorResponse(DelegateExecution execution){\r
534                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
535 \r
536                 utils.log("DEBUG", " *** STARTED CreateVfModulenfra sendErrorResponse Process *** ", isDebugEnabled)\r
537                 try {\r
538                         def sentSyncResponse = execution.getVariable("CVFMI_sentSyncResponse")\r
539                         if(sentSyncResponse == false){\r
540                                 WorkflowException wfex = execution.getVariable("WorkflowException")\r
541                                 String response = exceptionUtil.buildErrorResponseXml(wfex)\r
542 \r
543                                 utils.logAudit(response)\r
544                                 sendWorkflowResponse(execution, 500, response)\r
545                         }else{\r
546                                 utils.log("DEBUG", "Not Sending Error Response.  Sync Response Already Sent", isDebugEnabled)\r
547                         }\r
548 \r
549                 } catch (Exception ex) {\r
550                         utils.log("DEBUG", "Error Occured in CreateVfModuleInfra sendErrorResponse Process " + ex.getMessage(), isDebugEnabled)\r
551                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVfModuleInfra sendErrorResponse Process")\r
552 \r
553                 }\r
554                 utils.log("DEBUG", "*** COMPLETED CreateVfModuleInfra sendErrorResponse Process ***", isDebugEnabled)\r
555         }\r
556 \r
557 \r
558 }\r