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