6637d3c6670926a40a0bd89d9abff4df58b707b7
[so.git] /
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                         def controllerType = execution.getVariable('controllerType')\r
236                         execution.setVariable(prefix + 'controllerType', controllerType)\r
237                         execution.setVariable('healthCheckIndex0', 0)\r
238 \r
239                         logDebug('RequestInfo: ' + execution.getVariable("CVFMI_requestInfo"), isDebugLogEnabled)                       \r
240                         \r
241                         logDebug('rollbackEnabled: ' + execution.getVariable("CVFMI_rollbackEnabled"), isDebugLogEnabled)\r
242 \r
243                         logDebug('Exited ' + method, isDebugLogEnabled)\r
244                 } catch (BpmnError bpmnError) {\r
245                         throw bpmnError\r
246                 }\r
247                 catch(groovy.json.JsonException je) {\r
248                         utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)\r
249                         exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - During PreProcessRequest")\r
250                 }\r
251                 catch(Exception e) {\r
252                         String restFaultMessage = e.getMessage()\r
253                         //execution.setVariable("CVFMODVOL2_RESTFault", restFaultMessage)\r
254                         //execution.setVariable("CVFMODVOL2_isDataOk", false)\r
255                         utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)\r
256                         exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - During PreProcessRequest")\r
257                 }\r
258 \r
259         }\r
260 \r
261         /**\r
262          * Validates a workflow response.\r
263          * @param execution the execution\r
264          * @param responseVar the execution variable in which the response is stored\r
265          * @param responseCodeVar the execution variable in which the response code is stored\r
266          * @param errorResponseVar the execution variable in which the error response is stored\r
267          */\r
268         public void validateWorkflowResponse(DelegateExecution execution, String responseVar,\r
269                         String responseCodeVar, String errorResponseVar) {\r
270                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)\r
271                 sdncAdapterUtils.validateSDNCResponse(execution, responseVar, responseCodeVar, errorResponseVar)\r
272         }\r
273 \r
274 \r
275         /**\r
276          * Sends the empty, synchronous response back to the API Handler.\r
277          * @param execution the execution\r
278          */\r
279         public void sendResponse(DelegateExecution execution) {\r
280                 def method = getClass().getSimpleName() + '.sendResponse(' +\r
281                         'execution=' + execution.getId() +\r
282                         ')'\r
283                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
284                 logDebug('Entered ' + method, isDebugLogEnabled)\r
285 \r
286                 try {\r
287                         def requestInfo = execution.getVariable('CVFMI_requestInfo')\r
288                         def requestId = execution.getVariable('CVFMI_requestId')\r
289                         def source = execution.getVariable('CVFMI_source')                      \r
290                         \r
291                         // RESTResponse (for API Handler (APIH) Reply Task)\r
292                         def newVfModuleId = execution.getVariable("newVfModuleId")\r
293                         String synchResponse = """{"requestReferences":{"instanceId":"${newVfModuleId}","requestId":"${requestId}"}}""".trim()\r
294 \r
295                         sendWorkflowResponse(execution, 200, synchResponse)\r
296 \r
297                         execution.setVariable("CVFMI_sentSyncResponse", true)\r
298                         utils.logAudit("CreateVfModule Infra Response: " + synchResponse)\r
299                         logDebug('Exited ' + method, isDebugLogEnabled)\r
300                 } catch (BpmnError e) {\r
301                         throw e;\r
302                 } catch (Exception e) {\r
303                         logError('Caught exception in ' + method, e)\r
304                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())\r
305                 }\r
306         }\r
307         \r
308         /**\r
309          * Query AAI for vnf orchestration status to determine if health check and config scaling should be run\r
310          */\r
311         public void queryAAIForVnfOrchestrationStatus(DelegateExecution execution) {\r
312                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
313                 def vnfId = execution.getVariable("CVFMI_vnfId")\r
314                 execution.setVariable("runHealthCheck", false);\r
315                 execution.setVariable("runConfigScaleOut", false);\r
316                 AAICreateResources aaiCreateResources = new AAICreateResources();\r
317                 Optional<GenericVnf> vnf = aaiCreateResources.getVnfInstance(vnfId);\r
318                 if(vnf.isPresent()){\r
319                         def vnfOrchestrationStatus = vnf.get().getOrchestrationStatus();\r
320                         if("active".equalsIgnoreCase(vnfOrchestrationStatus)){\r
321                                 execution.setVariable("runHealthCheck", true);\r
322                                 execution.setVariable("runConfigScaleOut", true);\r
323                         }\r
324                 }\r
325         }\r
326         \r
327         /**\r
328          * Retrieve data for ConfigScaleOut from SDNC topology\r
329          */\r
330         \r
331         public void retreiveConfigScaleOutData(DelegateExecution execution){\r
332                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
333                 def vfModuleId = execution.getVariable("CVFMI_vfModuleId")\r
334                 String ipAddress = "";\r
335                 String oamIpAddress = "";\r
336                 String vnfHostIpAddress = "";\r
337 \r
338                 String vnfGetSDNC = execution.getVariable("DCVFM_getSDNCAdapterResponse");\r
339 \r
340                 String data = utils.getNodeXml(vnfGetSDNC, "response-data")\r
341                 data = data.replaceAll("&lt;", "<")\r
342                 data = data.replaceAll("&gt;", ">")\r
343 \r
344                 InputSource source = new InputSource(new StringReader(data));\r
345                 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();\r
346                 docFactory.setNamespaceAware(true)\r
347                 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()\r
348                 Document responseXml = docBuilder.parse(source)\r
349 \r
350                 NodeList paramsList = responseXml.getElementsByTagNameNS("*", "vnf-parameters")\r
351                 for (int z = 0; z < paramsList.getLength(); z++) {\r
352                         Node node = paramsList.item(z)\r
353                         Element eElement = (Element) node\r
354                         String vnfParameterName = utils.getElementText(eElement, "vnf-parameter-name")\r
355                         String vnfParameterValue = utils.getElementText(eElement, "vnf-parameter-value")\r
356                         if (vnfParameterName.equals("vlb_private_ip_1")) {\r
357                                 vnfHostIpAddress = vnfParameterValue\r
358                         }\r
359                         else if (vnfParameterName.equals("vdns_private_ip_0")) {\r
360                                 ipAddress = vnfParameterValue\r
361                         }\r
362                         else if (vnfParameterName.equals("vdns_private_ip_1")) {                        \r
363                                 oamIpAddress = vnfParameterValue\r
364                         }\r
365                 }\r
366 \r
367                 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
368                 execution.setVariable("payload", payload);\r
369         }\r
370 \r
371         /**\r
372          *\r
373          * @param execution the execution\r
374          */\r
375         public void postProcessResponse(DelegateExecution execution){\r
376                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
377 \r
378                 utils.log("DEBUG", " ======== STARTED PostProcessResponse Process ======== ", isDebugEnabled)\r
379                 try{                    \r
380                         def requestInfo = execution.getVariable("CVFMI_requestInfo")\r
381                         def action = utils.getNodeText1(requestInfo, "action")\r
382 \r
383                         utils.log("DEBUG", "requestInfo is: " + requestInfo, isDebugEnabled)\r
384                         utils.log("DEBUG", "action is: " + action, isDebugEnabled)\r
385 \r
386                         String payload =\r
387                                         """  <aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
388                                xmlns:ns="http://org.openecomp/mso/request/types/v1"\r
389                                xmlns:ns8="http://org.openecomp/mso/workflow/schema/v1">\r
390                         <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
391                         ${requestInfo}\r
392                         </request-info>\r
393                         <ns8:status-message>Vf Module has been created successfully.</ns8:status-message>\r
394                         <ns8:mso-bpel-name>BPMN</ns8:mso-bpel-name>\r
395                         </aetgt:MsoCompletionRequest>"""\r
396 \r
397                         payload = utils.formatXml(payload)\r
398                         execution.setVariable("CVFMI_SuccessFlag", true)\r
399                         execution.setVariable("CVFMI_msoCompletionRequest", payload)\r
400                         utils.logAudit("CreateVfModuleInfra completion request: " + payload)\r
401                         utils.log("DEBUG", "Outgoing MsoCompletionRequest: \n" + payload, isDebugEnabled)\r
402 \r
403                 }catch(Exception e){\r
404                         utils.log("ERROR", "Exception Occured Processing PostProcessResponse. Exception is:\n" + e, isDebugEnabled)\r
405                         execution.setVariable("CVFMI_ErrorResponse", "Error Occured during PostProcessResponse Method:\n" + e.getMessage())\r
406                 }\r
407                 utils.log("DEBUG", "======== COMPLETED PostProcessResponse Process ======== ", isDebugEnabled)\r
408         }\r
409 \r
410 \r
411 \r
412 \r
413 \r
414         /**\r
415          * Validates the request, request id and service instance id.  If a problem is found,\r
416          * a WorkflowException is generated and an MSOWorkflowException event is thrown. This\r
417          * method also sets up the log context for the workflow.\r
418          * @param execution the execution\r
419          * @return the validated request\r
420          */\r
421         public String validateInfraRequest(DelegateExecution execution) {\r
422                 def method = getClass().getSimpleName() + '.validateInfraRequest(' +\r
423                         'execution=' + execution.getId() +\r
424                         ')'\r
425                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
426                 logDebug('Entered ' + method, isDebugLogEnabled)\r
427 \r
428                 String processKey = getProcessKey(execution);\r
429                 def prefix = execution.getVariable("prefix")\r
430 \r
431                 if (prefix == null) {\r
432                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " prefix is null")\r
433                 }\r
434 \r
435                 try {\r
436                         def request = execution.getVariable(prefix + 'Request')\r
437 \r
438                         if (request == null) {\r
439                                 request = execution.getVariable(processKey + 'Request')\r
440 \r
441                                 if (request == null) {\r
442                                         request = execution.getVariable('bpmnRequest')\r
443                                 }\r
444 \r
445                                 setVariable(execution, processKey + 'Request', null);\r
446                                 setVariable(execution, 'bpmnRequest', null);\r
447                                 setVariable(execution, prefix + 'Request', request);\r
448                         }\r
449 \r
450                         if (request == null) {\r
451                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request is null")\r
452                         }\r
453 \r
454                         /*\r
455 \r
456                         def requestId = execution.getVariable("mso-request-id")\r
457 \r
458                         if (requestId == null) {\r
459                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request has no mso-request-id")\r
460                         }\r
461 \r
462                         setVariable(execution, prefix + 'requestId', requestId)\r
463 \r
464                         def serviceInstanceId = execution.getVariable("mso-service-instance-id")\r
465 \r
466                         if (serviceInstanceId == null) {\r
467                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request message has no mso-service-instance-id")\r
468                         }\r
469 \r
470                         utils.logContext(requestId, serviceInstanceId)\r
471                         */\r
472                         utils.logAudit("CreateVfModule incoming request: " + request)\r
473                         logDebug('Incoming message: ' + System.lineSeparator() + request, isDebugLogEnabled)\r
474                         logDebug('Exited ' + method, isDebugLogEnabled)\r
475                         return request\r
476                 } catch (BpmnError e) {\r
477                         throw e;\r
478                 } catch (Exception e) {\r
479                         logError('Caught exception in ' + method, e)\r
480                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Invalid Message")\r
481                 }\r
482         }\r
483 \r
484         public void prepareUpdateInfraRequest(DelegateExecution execution){\r
485                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
486 \r
487                 utils.log("DEBUG", " ======== STARTED prepareUpdateInfraRequest Process ======== ", isDebugEnabled)\r
488                 try{\r
489                         \r
490                         \r
491                         String requestInfo = execution.getVariable("CVFMI_requestInfo")                 \r
492                         def aicCloudRegion      = execution.getVariable("CVFMI_lcpCloudRegionId")\r
493                         def tenantId = execution.getVariable("CVFMI_tenantId")\r
494                         def requestId = utils.getNodeText1(requestInfo, "request-id")\r
495                         def vnfId = execution.getVariable("CVFMI_vnfId")\r
496                         def vfModuleId = execution.getVariable("CVFMI_vfModuleId")\r
497                         // vfModuleName may be generated by DoCreateVfModule subprocess if it is not specified on the input\r
498                         def vfModuleName = execution.getVariable("CVFMI_vfModuleName")\r
499 \r
500                         def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")\r
501                         execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)\r
502                         utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)\r
503 \r
504                         String payload =\r
505                                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
506                                                 xmlns:ns="http://org.openecomp.mso/requestsdb">\r
507                                                 <soapenv:Header/>\r
508                                                 <soapenv:Body>\r
509                                                         <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">\r
510                                                         <requestId>${requestId}</requestId>\r
511                                                         <lastModifiedBy>BPMN</lastModifiedBy>\r
512                                                         <statusMessage>VF Module successfully created</statusMessage>\r
513                                                         <responseBody></responseBody>\r
514                                                         <requestStatus>COMPLETE</requestStatus>\r
515                                                         <progress>100</progress>\r
516                                                         <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
517                                                         <vfModuleId>${vfModuleId}</vfModuleId>\r
518                                                         <vfModuleName>${vfModuleName}</vfModuleName>\r
519                                                 </ns:updateInfraRequest>\r
520                                         </soapenv:Body>\r
521                                 </soapenv:Envelope>"""\r
522 \r
523                         payload = utils.formatXml(payload)\r
524                         execution.setVariable("CVFMI_updateInfraRequest", payload)\r
525                         utils.log("DEBUG", "Outgoing UpdateInfraRequest: \n" + payload, isDebugEnabled)\r
526                         utils.logAudit("CreateVfModuleInfra Outgoing UpdateInfra Request: " + payload)\r
527 \r
528                 }catch(Exception e){\r
529                         utils.log("ERROR", "Exception Occured Processing prepareUpdateInfraRequest. Exception is:\n" + e, isDebugEnabled)\r
530                         execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareUpdateInfraRequest Method:\n" + e.getMessage())\r
531                 }\r
532                 utils.log("DEBUG", "======== COMPLETED prepareUpdateInfraRequest Process ======== ", isDebugEnabled)\r
533         }\r
534 \r
535         /**\r
536          * Builds a "FalloutHandler" request and stores it in the specified execution variable.\r
537          *\r
538          * @param execution the execution\r
539          * @param resultVar the execution variable in which the result will be stored\r
540          */\r
541         public void falloutHandlerPrep(DelegateExecution execution, String resultVar) {\r
542                 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +\r
543                         'execution=' + execution.getId() +\r
544                         ', resultVar=' + resultVar +\r
545                         ')'\r
546                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
547                 logDebug('Entered ' + method, isDebugLogEnabled)\r
548 \r
549 \r
550                 try {\r
551                         def WorkflowException workflowException = execution.getVariable("WorkflowException")                    \r
552                         def requestInformation = execution.getVariable("CVFMI_requestInfo")\r
553                         def errorResponseCode = workflowException.getErrorCode()\r
554                         def errorResponseMsg = workflowException.getErrorMessage()\r
555                         def encErrorResponseMsg = ""\r
556                         if (errorResponseMsg != null) {\r
557                                 encErrorResponseMsg = errorResponseMsg.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")\r
558                         }\r
559 \r
560                         String content = """\r
561                                 <aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
562                                                 xmlns:reqtype="http://org.openecomp/mso/request/types/v1"\r
563                                                 xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"\r
564                                                 xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">\r
565                                                 ${requestInformation}\r
566                                         <aetgt:WorkflowException>\r
567                                                 <aetgt:ErrorMessage>${encErrorResponseMsg}</aetgt:ErrorMessage>\r
568                                                 <aetgt:ErrorCode>${errorResponseCode}</aetgt:ErrorCode>\r
569                                         </aetgt:WorkflowException>\r
570                                 </aetgt:FalloutHandlerRequest>\r
571                         """\r
572 \r
573                         logDebug("CONTENT before translation: " + content, isDebugLogEnabled)\r
574                         content = utils.formatXml(content)\r
575                         logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)\r
576                         utils.logAudit("CreateVfModuleInfra FallOutHander Request: " + content)\r
577                         execution.setVariable(resultVar, content)\r
578 \r
579                         logDebug('Exited ' + method, isDebugLogEnabled)\r
580                 } catch (BpmnError e) {\r
581                         throw e;\r
582                 } catch (Exception e) {\r
583                         logError('Caught exception in ' + method, e)\r
584                         exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')\r
585                 }\r
586         }\r
587 \r
588         public void logAndSaveOriginalException(DelegateExecution execution) {\r
589                 def method = getClass().getSimpleName() + '.validateRollbackResponse(' +\r
590                         'execution=' + execution.getId() +\r
591                         ')'\r
592                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
593                 logDebug('Entered ' + method, isDebugLogEnabled)\r
594 \r
595                 logWorkflowException(execution, 'CreateVfModuleInfra caught an event')\r
596                 saveWorkflowException(execution, 'CVFMI_originalWorkflowException')\r
597         }\r
598 \r
599         public void validateRollbackResponse(DelegateExecution execution) {\r
600                 def method = getClass().getSimpleName() + '.validateRollbackResponse(' +\r
601                         'execution=' + execution.getId() +\r
602                         ')'\r
603                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
604                 logDebug('Entered ' + method, isDebugLogEnabled)\r
605 \r
606                 def originalException = execution.getVariable("CVFMI_originalWorkflowException")\r
607                 execution.setVariable("WorkflowException", originalException)\r
608 \r
609                 execution.setVariable("RollbackCompleted", true)\r
610 \r
611         }\r
612         \r
613         public void sendErrorResponse(DelegateExecution execution){\r
614                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
615 \r
616                 utils.log("DEBUG", " *** STARTED CreateVfModulenfra sendErrorResponse Process *** ", isDebugEnabled)\r
617                 try {\r
618                         def sentSyncResponse = execution.getVariable("CVFMI_sentSyncResponse")\r
619                         if(sentSyncResponse == false){\r
620                                 WorkflowException wfex = execution.getVariable("WorkflowException")\r
621                                 String response = exceptionUtil.buildErrorResponseXml(wfex)\r
622 \r
623                                 utils.logAudit(response)\r
624                                 sendWorkflowResponse(execution, 500, response)\r
625                         }else{\r
626                                 utils.log("DEBUG", "Not Sending Error Response.  Sync Response Already Sent", isDebugEnabled)\r
627                         }\r
628 \r
629                 } catch (Exception ex) {\r
630                         utils.log("DEBUG", "Error Occured in CreateVfModuleInfra sendErrorResponse Process " + ex.getMessage(), isDebugEnabled)\r
631                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVfModuleInfra sendErrorResponse Process")\r
632 \r
633                 }\r
634                 utils.log("DEBUG", "*** COMPLETED CreateVfModuleInfra sendErrorResponse Process ***", isDebugEnabled)\r
635         }\r
636 \r
637 \r
638 }\r