Flows fail to update status in requests DB
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / CreateVfModuleInfra.groovy
index 7f5bd61..37ff494 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * OPENECOMP - MSO
+ * ONAP - SO
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
@@ -21,6 +21,7 @@
 package org.openecomp.mso.bpmn.infrastructure.scripts;
 
 import groovy.json.JsonSlurper
+import groovy.json.JsonOutput
 
 import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.runtime.Execution
@@ -32,9 +33,13 @@ import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils;
 import org.openecomp.mso.bpmn.common.scripts.VidUtils;
 import org.openecomp.mso.bpmn.core.RollbackData
 import org.openecomp.mso.bpmn.core.WorkflowException
+import org.openecomp.mso.bpmn.core.json.JsonUtils
 
 public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {
-       
+
+       ExceptionUtil exceptionUtil = new ExceptionUtil()
+       JsonUtils jsonUtil = new JsonUtils()
+
        /**
         * Validates the request message and sets up the workflow.
         * @param execution the execution
@@ -46,97 +51,185 @@ public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {
                def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
                logDebug('Entered ' + method, isDebugLogEnabled)
 
+               execution.setVariable("CVFMI_sentSyncResponse", false)
+               
                def prefix = 'CVFMI_'
                logDebug('Entered 1' + method, isDebugLogEnabled)
                execution.setVariable('prefix', prefix)
                logDebug('Entered 2' + method, isDebugLogEnabled)
                execution.setVariable("isVidRequest", "false")
-               
-               logDebug("Set variables", isDebugLogEnabled)    
-               
+
+               logDebug("Set variables", isDebugLogEnabled)
+
                def rollbackData = execution.getVariable("RollbackData")
                if (rollbackData == null) {
                        rollbackData = new RollbackData()
                }
                execution.setVariable("RollbackData", rollbackData)
-               
+
                logDebug("Set rollback data", isDebugLogEnabled)
                def incomingRequest = execution.getVariable('bpmnRequest')
-               
+
                utils.log("DEBUG", "Incoming Infra Request: " + incomingRequest, isDebugLogEnabled)
                utils.logAudit("CreateVfModule Infra incoming Request: " + incomingRequest)
+
+               setBasicDBAuthHeader(execution, isDebugLogEnabled)
                
                // check if request is xml or json
                try {
                        def jsonSlurper = new JsonSlurper()
+                       def jsonOutput = new JsonOutput()
                        Map reqMap = jsonSlurper.parseText(incomingRequest)
                        utils.log("DEBUG", " Request is in JSON format.", isDebugLogEnabled)
-                       
+
                        def serviceInstanceId = execution.getVariable('serviceInstanceId')
                        def vnfId = execution.getVariable('vnfId')
                        
-                       def vidUtils = new VidUtils(this)
+                       execution.setVariable(prefix + 'serviceInstanceId', serviceInstanceId)
+                       execution.setVariable(prefix+'vnfId', vnfId)
+                       execution.setVariable("isVidRequest", "true")
                        
-                       String requestInXmlFormat = vidUtils.createXmlVfModuleRequest(execution, reqMap, 'CREATE_VF_MODULE', serviceInstanceId)
+                       def vnfName = ''
+                       def asdcServiceModelVersion = ''
+                       def serviceModelInfo = null
+                       def vnfModelInfo = null
                        
-                       utils.log("DEBUG", " Request in XML format: " + requestInXmlFormat, isDebugLogEnabled)
+                       def relatedInstanceList = reqMap.requestDetails?.relatedInstanceList
+                                               
+                       if (relatedInstanceList != null) {
+                               relatedInstanceList.each {
+                                       if (it.relatedInstance.modelInfo?.modelType == 'service') {
+                                               asdcServiceModelVersion = it.relatedInstance.modelInfo?.modelVersion
+                                               serviceModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
+                                               
+                                       }
+                                       if (it.relatedInstance.modelInfo.modelType == 'vnf') {
+                                               vnfName = it.relatedInstance.instanceName ?: ''
+                                               vnfModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
+                                       }
+                               }
+                       }
                        
-                       execution.setVariable(prefix + 'Request', requestInXmlFormat)
-                       execution.setVariable(prefix+'vnfId', vnfId)
-                       execution.setVariable("isVidRequest", "true")                   
+                       execution.setVariable(prefix + 'vnfName', vnfName)
+                       execution.setVariable(prefix + 'asdcServiceModelVersion', asdcServiceModelVersion)
+                       execution.setVariable(prefix + 'serviceModelInfo', serviceModelInfo)
+                       execution.setVariable(prefix + 'vnfModelInfo', vnfModelInfo)
                        
-               }
-               catch(groovy.json.JsonException je) {
-                       utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)
-                       workflowException(execution, "Invalid request format", 400)
                        
-               }
-               catch(Exception e) {
-                       String restFaultMessage = e.getMessage()
-                       //execution.setVariable("CVFMODVOL2_RESTFault", restFaultMessage)
-                       //execution.setVariable("CVFMODVOL2_isDataOk", false)
-                       utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)
-                       workflowException(execution, restFaultMessage, 400)
-               }
-
-               try {
-                       String request = validateInfraRequest(execution)
+                       def vnfType = execution.getVariable('vnfType')
+                       execution.setVariable(prefix + 'vnfType', vnfType)      
+                       def vfModuleId = execution.getVariable('vfModuleId')
+                       execution.setVariable(prefix + 'vfModuleId', vfModuleId)
+                       def volumeGroupId = execution.getVariable('volumeGroupId')
+                       execution.setVariable(prefix + 'volumeGroupId', volumeGroupId)
+                       def userParams = reqMap.requestDetails?.requestParameters?.userParams                                   
+                       
+                       Map<String, String> userParamsMap = [:]
+                       if (userParams != null) {
+                               userParams.each { userParam ->
+                                       userParamsMap.put(userParam.name, userParam.value)
+                               }                                                       
+                       }               
+                                               
+                       utils.log("DEBUG", 'Processed user params: ' + userParamsMap, isDebugLogEnabled)                
+                       
+                       execution.setVariable(prefix + 'vfModuleInputParams', userParamsMap)
+                       
+                       def isBaseVfModule = "false"
+                       if (execution.getVariable('isBaseVfModule') == true) {
+                               isBaseVfModule = "true"
+                       }                       
+                       
+                       execution.setVariable(prefix + 'isBaseVfModule', isBaseVfModule)
+                                               
+                       def requestId = execution.getVariable("mso-request-id")
+                       execution.setVariable(prefix + 'requestId', requestId)
                        
+                       def vfModuleModelInfo = jsonOutput.toJson(reqMap.requestDetails?.modelInfo)
+                       execution.setVariable(prefix + 'vfModuleModelInfo', vfModuleModelInfo)
+                       
+                       def suppressRollback = reqMap.requestDetails?.requestInfo?.suppressRollback
+                       
+                       
+                       def backoutOnFailure = ""
+                       if(suppressRollback != null){
+                               if ( suppressRollback == true) {
+                                       backoutOnFailure = "false"
+                               } else if ( suppressRollback == false) {
+                                       backoutOnFailure = "true"
+                               }
+                       }
+                       
+                       execution.setVariable('disableRollback', suppressRollback)
+                       
+                       def vfModuleName = reqMap.requestDetails?.requestInfo?.instanceName ?: null
+                       execution.setVariable(prefix + 'vfModuleName', vfModuleName)
+                       
+                       def serviceId = reqMap.requestDetails?.requestParameters?.serviceId ?: ''
+                       execution.setVariable(prefix + 'serviceId', serviceId)
+                       
+                       def usePreload = reqMap.requestDetails?.requestParameters?.usePreload
+                       execution.setVariable(prefix + 'usePreload', usePreload)
+                       
+                       def cloudConfiguration = reqMap.requestDetails?.cloudConfiguration
+                       def lcpCloudRegionId    = cloudConfiguration.lcpCloudRegionId
+                       execution.setVariable(prefix + 'lcpCloudRegionId', lcpCloudRegionId)
+                       def tenantId = cloudConfiguration.tenantId
+                       execution.setVariable(prefix + 'tenantId', tenantId)
+                       
+                       def globalSubscriberId = reqMap.requestDetails?.subscriberInfo?.globalSubscriberId ?: ''
+                       execution.setVariable(prefix + 'globalSubscriberId', globalSubscriberId)
+                       
+                       execution.setVariable(prefix + 'sdncVersion', '1702')
+
                        execution.setVariable("CreateVfModuleInfraSuccessIndicator", false)
                        execution.setVariable("RollbackCompleted", false)
-                       execution.setVariable("DoCreateVfModuleRequest", request)
+                       
                        execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
-                       execution.setVariable("CVFMI_requestInfo",utils.getNodeXml(request,"request-info"))     
-                       execution.setVariable("CVFMI_requestId",utils.getNodeText1(request,"request-id"))
-                       execution.setVariable("CVFMI_source",utils.getNodeText1(request,"source"))
-                       execution.setVariable("CVFMI_serviceInstanceId", utils.getNodeText1(request, "service-instance-id"))            
-                       execution.setVariable("CVFMI_vnfInputs",utils.getNodeXml(request,"vnf-inputs"))
+                       
+                       
+                       def source = reqMap.requestDetails?.requestInfo?.source
+                       execution.setVariable("CVFMI_source", source)
+                       
+                       //For Completion Handler & Fallout Handler
+                       String requestInfo =
+                       """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
+                                       <request-id>${requestId}</request-id>
+                                       <action>CREATE</action>
+                                       <source>${source}</source>
+                                  </request-info>"""
+                       
+                       execution.setVariable("CVFMI_requestInfo", requestInfo)
+                       
                        //backoutOnFailure
                        
-                       NetworkUtils networkUtils = new NetworkUtils()
-                       execution.setVariable("CVFMI_rollbackEnabled", networkUtils.isRollbackEnabled(execution,request))
                        execution.setVariable("CVFMI_originalWorkflowException", null)
-                       def vnfParams = ""
-                       if (utils.nodeExists(request, "vnf-params")) {
-                               vnfParams = utils.getNodeXml(request,"vnf-params")
-                       }
-                       execution.setVariable("CVFMI_vnfParams", vnfParams)
                        
+
                        def newVfModuleId = UUID.randomUUID().toString()
                        execution.setVariable("newVfModuleId", newVfModuleId)
+                       execution.setVariable(prefix + 'vfModuleId', newVfModuleId)
+
+                       logDebug('RequestInfo: ' + execution.getVariable("CVFMI_requestInfo"), isDebugLogEnabled)                       
                        
-                       logDebug('RequestInfo: ' + execution.getVariable("CVFMI_requestInfo"), isDebugLogEnabled)
-                       logDebug('VnfInputs: ' + execution.getVariable("CVFMI_vnfInputs"), isDebugLogEnabled)
-                       logDebug('VnfParams: ' + execution.getVariable("CVFMI_vnfParams"), isDebugLogEnabled)
                        logDebug('rollbackEnabled: ' + execution.getVariable("CVFMI_rollbackEnabled"), isDebugLogEnabled)
-                       
+
                        logDebug('Exited ' + method, isDebugLogEnabled)
                } catch (BpmnError bpmnError) {
-                       buildErrorResponse(execution,bpmnError.getMessage(),"400")
                        throw bpmnError
-               } catch (Exception exception) {
-                       workflowException(execution, exception.getMessage(), 400)
-               }                
+               }
+               catch(groovy.json.JsonException je) {
+                       utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - During PreProcessRequest")
+               }
+               catch(Exception e) {
+                       String restFaultMessage = e.getMessage()
+                       //execution.setVariable("CVFMODVOL2_RESTFault", restFaultMessage)
+                       //execution.setVariable("CVFMODVOL2_isDataOk", false)
+                       utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - During PreProcessRequest")
+               }
+
        }
 
        /**
@@ -167,46 +260,38 @@ public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {
                try {
                        def requestInfo = execution.getVariable('CVFMI_requestInfo')
                        def requestId = execution.getVariable('CVFMI_requestId')
-                       def source = execution.getVariable('CVFMI_source')
-                       def progress = getNodeTextForce(requestInfo, 'progress')
-                       if (progress.isEmpty()) {
-                               progress = '0'
-                       }
-                       def startTime = getNodeTextForce(requestInfo, 'start-time')
-                       if (startTime.isEmpty()) {
-                               startTime = System.currentTimeMillis()
-                       }                       
-                               
+                       def source = execution.getVariable('CVFMI_source')                      
+                       
                        // RESTResponse (for API Handler (APIH) Reply Task)
                        def newVfModuleId = execution.getVariable("newVfModuleId")
                        String synchResponse = """{"requestReferences":{"instanceId":"${newVfModuleId}","requestId":"${requestId}"}}""".trim()
-                       
+
                        sendWorkflowResponse(execution, 200, synchResponse)
-                       
+
+                       execution.setVariable("CVFMI_sentSyncResponse", true)
                        utils.logAudit("CreateVfModule Infra Response: " + synchResponse)
                        logDebug('Exited ' + method, isDebugLogEnabled)
                } catch (BpmnError e) {
                        throw e;
                } catch (Exception e) {
                        logError('Caught exception in ' + method, e)
-                       createWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
                }
        }
 
        /**
-        * 
+        *
         * @param execution the execution
         */
        public void postProcessResponse(Execution execution){
                def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
-               
+
                utils.log("DEBUG", " ======== STARTED PostProcessResponse Process ======== ", isDebugEnabled)
-               try{
-                       def request = execution.getVariable("DoCreateVfModuleRequest")
-                       def requestInfo = utils.getNodeXml(request, 'request-info', false)
+               try{                    
+                       def requestInfo = execution.getVariable("CVFMI_requestInfo")
                        def action = utils.getNodeText1(requestInfo, "action")
-                       
-                       utils.log("DEBUG", "requestInfo is: " + requestInfo, isDebugEnabled)                    
+
+                       utils.log("DEBUG", "requestInfo is: " + requestInfo, isDebugEnabled)
                        utils.log("DEBUG", "action is: " + action, isDebugEnabled)
 
                        String payload =
@@ -233,10 +318,10 @@ public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {
                utils.log("DEBUG", "======== COMPLETED PostProcessResponse Process ======== ", isDebugEnabled)
        }
 
-       
-       
-       
-       
+
+
+
+
        /**
         * Validates the request, request id and service instance id.  If a problem is found,
         * a WorkflowException is generated and an MSOWorkflowException event is thrown. This
@@ -255,7 +340,7 @@ public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {
                def prefix = execution.getVariable("prefix")
 
                if (prefix == null) {
-                       createWorkflowException(execution, 1002, processKey + " prefix is null")
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " prefix is null")
                }
 
                try {
@@ -263,34 +348,34 @@ public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {
 
                        if (request == null) {
                                request = execution.getVariable(processKey + 'Request')
-       
+
                                if (request == null) {
                                        request = execution.getVariable('bpmnRequest')
                                }
-       
+
                                setVariable(execution, processKey + 'Request', null);
                                setVariable(execution, 'bpmnRequest', null);
                                setVariable(execution, prefix + 'Request', request);
                        }
 
                        if (request == null) {
-                               createWorkflowException(execution, 1002, processKey + " request is null")
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request is null")
                        }
-                       
+
                        /*
 
                        def requestId = execution.getVariable("mso-request-id")
-                       
+
                        if (requestId == null) {
-                               createWorkflowException(execution, 1002, processKey + " request has no mso-request-id")
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request has no mso-request-id")
                        }
-                       
+
                        setVariable(execution, prefix + 'requestId', requestId)
 
                        def serviceInstanceId = execution.getVariable("mso-service-instance-id")
 
                        if (serviceInstanceId == null) {
-                               createWorkflowException(execution, 1002, processKey + " request message has no mso-service-instance-id")
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request message has no mso-service-instance-id")
                        }
 
                        utils.logContext(requestId, serviceInstanceId)
@@ -303,41 +388,30 @@ public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {
                        throw e;
                } catch (Exception e) {
                        logError('Caught exception in ' + method, e)
-                       createWorkflowException(execution, 1002, "Invalid Message")
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Invalid Message")
                }
        }
-       
+
        public void prepareUpdateInfraRequest(Execution execution){
                def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
-               ExceptionUtil exceptionUtil = new ExceptionUtil()
-               
+
                utils.log("DEBUG", " ======== STARTED prepareUpdateInfraRequest Process ======== ", isDebugEnabled)
                try{
-
-                       String vnfInputs = execution.getVariable("CVFMI_vnfInputs")
-                       String requestInfo = execution.getVariable("CVFMI_requestInfo")
-                       def aicCloudRegion      = utils.getNodeText1(vnfInputs, "aic-cloud-region")
-                       def tenantId = utils.getNodeText1(vnfInputs, "tenant-id")
+                       
+                       
+                       String requestInfo = execution.getVariable("CVFMI_requestInfo")                 
+                       def aicCloudRegion      = execution.getVariable("CVFMI_lcpCloudRegionId")
+                       def tenantId = execution.getVariable("CVFMI_tenantId")
                        def requestId = utils.getNodeText1(requestInfo, "request-id")
                        def vnfId = execution.getVariable("CVFMI_vnfId")
                        def vfModuleId = execution.getVariable("CVFMI_vfModuleId")
+                       // vfModuleName may be generated by DoCreateVfModule subprocess if it is not specified on the input
+                       def vfModuleName = execution.getVariable("CVFMI_vfModuleName")
 
-                       def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_db_endpoint")
+                       def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
                        execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
                        utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
-                       
-                       try {
-                               String basicAuthValueDB = execution.getVariable("URN_mso_adapters_db_auth")
-                               utils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB, isDebugEnabled)
-                               
-                               def encodedString = utils.getBasicAuth(basicAuthValueDB, execution.getVariable("URN_mso_msoKey"))
-                               execution.setVariable("BasicAuthHeaderValueDB",encodedString)
-                       } catch (IOException ex) {
-                               String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage()
-                               utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
-                       }
-                       
+
                        String payload =
                                """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                                                xmlns:ns="http://org.openecomp.mso/requestsdb">
@@ -352,7 +426,8 @@ public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {
                                                        <progress>100</progress>
                                                        <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>
                                                        <vfModuleId>${vfModuleId}</vfModuleId>
-                                               </ns:updateInfraRequest> 
+                                                       <vfModuleName>${vfModuleName}</vfModuleName>
+                                               </ns:updateInfraRequest>
                                        </soapenv:Body>
                                </soapenv:Envelope>"""
 
@@ -360,17 +435,17 @@ public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {
                        execution.setVariable("CVFMI_updateInfraRequest", payload)
                        utils.log("DEBUG", "Outgoing UpdateInfraRequest: \n" + payload, isDebugEnabled)
                        utils.logAudit("CreateVfModuleInfra Outgoing UpdateInfra Request: " + payload)
-                       
+
                }catch(Exception e){
                        utils.log("ERROR", "Exception Occured Processing prepareUpdateInfraRequest. Exception is:\n" + e, isDebugEnabled)
                        execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareUpdateInfraRequest Method:\n" + e.getMessage())
                }
                utils.log("DEBUG", "======== COMPLETED prepareUpdateInfraRequest Process ======== ", isDebugEnabled)
        }
-       
+
        /**
         * Builds a "FalloutHandler" request and stores it in the specified execution variable.
-        * 
+        *
         * @param execution the execution
         * @param resultVar the execution variable in which the result will be stored
         */
@@ -381,12 +456,11 @@ public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {
                        ')'
                def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
                logDebug('Entered ' + method, isDebugLogEnabled)
-               
-               
+
+
                try {
-                       def WorkflowException workflowException = execution.getVariable("WorkflowException")
-                       def request = execution.getVariable("DoCreateVfModuleRequest")
-                       def requestInformation = utils.getNodeXml(request, 'request-info', false)
+                       def WorkflowException workflowException = execution.getVariable("WorkflowException")                    
+                       def requestInformation = execution.getVariable("CVFMI_requestInfo")
                        def errorResponseCode = workflowException.getErrorCode()
                        def errorResponseMsg = workflowException.getErrorMessage()
                        def encErrorResponseMsg = ""
@@ -399,14 +473,14 @@ public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {
                                                xmlns:reqtype="http://org.openecomp/mso/request/types/v1"
                                                xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"
                                                xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">
-                                               ${requestInformation}                                                                           
+                                               ${requestInformation}
                                        <aetgt:WorkflowException>
                                                <aetgt:ErrorMessage>${encErrorResponseMsg}</aetgt:ErrorMessage>
                                                <aetgt:ErrorCode>${errorResponseCode}</aetgt:ErrorCode>
-                                       </aetgt:WorkflowException>      
+                                       </aetgt:WorkflowException>
                                </aetgt:FalloutHandlerRequest>
                        """
-                       
+
                        logDebug("CONTENT before translation: " + content, isDebugLogEnabled)
                        content = utils.formatXml(content)
                        logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
@@ -418,34 +492,58 @@ public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {
                        throw e;
                } catch (Exception e) {
                        logError('Caught exception in ' + method, e)
-                       createWorkflowException(execution, 2000, 'Internal Error')
+                       exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')
                }
        }
-       
+
        public void logAndSaveOriginalException(Execution execution) {
                def method = getClass().getSimpleName() + '.validateRollbackResponse(' +
                        'execution=' + execution.getId() +
                        ')'
                def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
                logDebug('Entered ' + method, isDebugLogEnabled)
-               
+
                logWorkflowException(execution, 'CreateVfModuleInfra caught an event')
                saveWorkflowException(execution, 'CVFMI_originalWorkflowException')
        }
-       
+
        public void validateRollbackResponse(Execution execution) {
                def method = getClass().getSimpleName() + '.validateRollbackResponse(' +
                        'execution=' + execution.getId() +
                        ')'
                def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
                logDebug('Entered ' + method, isDebugLogEnabled)
-               
+
                def originalException = execution.getVariable("CVFMI_originalWorkflowException")
                execution.setVariable("WorkflowException", originalException)
-               
+
                execution.setVariable("RollbackCompleted", true)
-       
+
        }
        
-               
+       public void sendErrorResponse(Execution execution){
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+               utils.log("DEBUG", " *** STARTED CreateVfModulenfra sendErrorResponse Process *** ", isDebugEnabled)
+               try {
+                       def sentSyncResponse = execution.getVariable("CVFMI_sentSyncResponse")
+                       if(sentSyncResponse == false){
+                               WorkflowException wfex = execution.getVariable("WorkflowException")
+                               String response = exceptionUtil.buildErrorResponseXml(wfex)
+
+                               utils.logAudit(response)
+                               sendWorkflowResponse(execution, 500, response)
+                       }else{
+                               utils.log("DEBUG", "Not Sending Error Response.  Sync Response Already Sent", isDebugEnabled)
+                       }
+
+               } catch (Exception ex) {
+                       utils.log("DEBUG", "Error Occured in CreateVfModuleInfra sendErrorResponse Process " + ex.getMessage(), isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVfModuleInfra sendErrorResponse Process")
+
+               }
+               utils.log("DEBUG", "*** COMPLETED CreateVfModuleInfra sendErrorResponse Process ***", isDebugEnabled)
+       }
+
+
 }