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