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