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