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