88e2396078d8210a08d9e5f110c10379c8cfa1a0
[so.git] /
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * OPENECOMP - MSO\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.xml.XmlUtil\r
24 import groovy.json.*\r
25 \r
26 import org.openecomp.mso.bpmn.core.json.JsonUtils\r
27 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor\r
28 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils\r
29 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil\r
30 import org.openecomp.mso.bpmn.common.scripts.VidUtils\r
31 import org.openecomp.mso.bpmn.core.WorkflowException\r
32 import org.openecomp.mso.rest.APIResponse;\r
33 import org.openecomp.mso.rest.RESTClient\r
34 import org.openecomp.mso.rest.RESTConfig\r
35 \r
36 import java.util.UUID;\r
37 \r
38 import org.camunda.bpm.engine.delegate.BpmnError\r
39 import org.camunda.bpm.engine.runtime.Execution\r
40 import org.json.JSONObject;\r
41 import org.json.JSONArray;\r
42 import org.apache.commons.lang3.*\r
43 import org.apache.commons.codec.binary.Base64;\r
44 import org.springframework.web.util.UriUtils;\r
45 \r
46 /**\r
47  * This groovy class supports the <class>CreateGenericMacroServiceNetworkVnf.bpmn</class> process.\r
48  *\r
49  */\r
50 public class CreateGenericMacroServiceNetworkVnf extends AbstractServiceTaskProcessor {\r
51 \r
52         String Prefix="CREVAS_"\r
53         ExceptionUtil exceptionUtil = new ExceptionUtil()\r
54         JsonUtils jsonUtil = new JsonUtils()\r
55         VidUtils vidUtils = new VidUtils()\r
56         CatalogDbUtils catalogDbUtils = new CatalogDbUtils()\r
57 \r
58         /**\r
59          * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.\r
60          * @param execution\r
61          */\r
62         public InitializeProcessVariables(Execution execution){\r
63                 /* Initialize all the process variables in this block */\r
64 \r
65                 execution.setVariable("createGenericMacroServiceNetworkVnfRequest", "")\r
66                 execution.setVariable("globalSubscriberId", "")\r
67                 execution.setVariable("serviceInstanceName", "")\r
68                 execution.setVariable("msoRequestId", "")\r
69                 execution.setVariable("CREVAS_NetworksCreatedCount", 0)\r
70                 execution.setVariable("CREVAS_VnfsCreatedCount", 0)\r
71                 execution.setVariable("productFamilyId", "")\r
72                 \r
73                 \r
74                 //TODO\r
75                 execution.setVariable("sdncVersion", "1702")\r
76         }\r
77 \r
78         // **************************************************\r
79         //     Pre or Prepare Request Section\r
80         // **************************************************\r
81         /**\r
82          * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.\r
83          * @param execution\r
84          */\r
85         public void preProcessRequest (Execution execution) {\r
86                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
87                 execution.setVariable("prefix",Prefix)\r
88 \r
89                 utils.log("DEBUG", " ***** Inside preProcessRequest CreateGenericMacroServiceNetworkVnf Request ***** ", isDebugEnabled)\r
90 \r
91                 try {\r
92                         // initialize flow variables\r
93                         InitializeProcessVariables(execution)\r
94 \r
95                         // check for incoming json message/input\r
96                         String createGenericMacroServiceNetworkVnfRequest = execution.getVariable("bpmnRequest")\r
97                         utils.logAudit(createGenericMacroServiceNetworkVnfRequest)\r
98                         execution.setVariable("createGenericMacroServiceNetworkVnfRequest", createGenericMacroServiceNetworkVnfRequest);\r
99                         println 'createGenericMacroServiceNetworkVnfRequest - ' + createGenericMacroServiceNetworkVnfRequest\r
100 \r
101                         // extract requestId\r
102                         String requestId = execution.getVariable("mso-request-id")\r
103                         execution.setVariable("msoRequestId", requestId)\r
104 \r
105                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
106 \r
107                         if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {\r
108                                 serviceInstanceId = UUID.randomUUID().toString()\r
109                                 utils.log("DEBUG", " Generated new Service Instance: " + serviceInstanceId , isDebugEnabled)\r
110                         } else {\r
111                                 utils.log("DEBUG", "Using provided Service Instance ID: " + serviceInstanceId , isDebugEnabled)\r
112                         }\r
113 \r
114                         serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")\r
115                         execution.setVariable("serviceInstanceId", serviceInstanceId)\r
116                         \r
117                         String requestAction = execution.getVariable("requestAction")\r
118                         execution.setVariable("requestAction", requestAction)\r
119 \r
120                         String source = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.requestInfo.source")\r
121                         if ((source == null) || (source.isEmpty())) {\r
122                                 execution.setVariable("source", "VID")\r
123                         } else {\r
124                                 execution.setVariable("source", source)\r
125                         }\r
126 \r
127                         // extract globalSubscriberId\r
128                         String globalSubscriberId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.subscriberInfo.globalSubscriberId")\r
129 \r
130                         // verify element global-customer-id is sent from JSON input, throw exception if missing\r
131                         if ((globalSubscriberId == null) || (globalSubscriberId.isEmpty())) {\r
132                                 String dataErrorMessage = " Element 'globalSubscriberId' is missing. "\r
133                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)\r
134 \r
135                         } else {\r
136                                 execution.setVariable("globalSubscriberId", globalSubscriberId)\r
137                                 execution.setVariable("globalCustomerId", globalSubscriberId)\r
138                         }\r
139                         \r
140                         // extract subscriptionServiceType\r
141                         String subscriptionServiceType = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.requestParameters.subscriptionServiceType")\r
142                         execution.setVariable("subscriptionServiceType", subscriptionServiceType)\r
143                         utils.log("DEBUG", "Incoming subscriptionServiceType is: " + subscriptionServiceType, isDebugEnabled)\r
144 \r
145                         String suppressRollback = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.requestInfo.suppressRollback")\r
146                         execution.setVariable("disableRollback", suppressRollback)\r
147                         utils.log("DEBUG", "Incoming Suppress/Disable Rollback is: " + suppressRollback, isDebugEnabled)\r
148                         \r
149                         String productFamilyId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.requestInfo.productFamilyId")\r
150                         execution.setVariable("productFamilyId", productFamilyId)\r
151                         utils.log("DEBUG", "Incoming productFamilyId is: " + productFamilyId, isDebugEnabled)\r
152                         \r
153                         //For Completion Handler & Fallout Handler\r
154                         String requestInfo =\r
155                         """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
156                                         <request-id>${requestId}</request-id>\r
157                                         <action>CREATE</action>\r
158                                         <source>${source}</source>\r
159                                    </request-info>"""\r
160 \r
161                         execution.setVariable("CREVAS_requestInfo", requestInfo)\r
162                         \r
163                         utils.log("DEBUG", " ***** Completed preProcessRequest CreateGenericMacroServiceNetworkVnf Request ***** ", isDebugEnabled)\r
164 \r
165                 } catch (BpmnError e) {\r
166                         throw e;\r
167 \r
168                 } catch (Exception ex){\r
169                         String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected from method preProcessRequest() - " + ex.getMessage()\r
170                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
171                 }\r
172         }\r
173 \r
174         public void sendSyncResponse (Execution execution) {\r
175                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
176 \r
177                 utils.log("DEBUG", " ***** Inside sendSyncResponse of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
178 \r
179                 try {\r
180                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
181                         String requestId = execution.getVariable("mso-request-id")\r
182 \r
183                         // RESTResponse (for API Handler (APIH) Reply Task)\r
184                         String syncResponse ="""{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()\r
185 \r
186                         utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)\r
187                         sendWorkflowResponse(execution, 202, syncResponse)\r
188 \r
189                 } catch (Exception ex) {\r
190                         String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected from method sendSyncResponse() - " + ex.getMessage()\r
191                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
192                 }\r
193         }\r
194 \r
195         // *******************************\r
196         //     \r
197         // *******************************\r
198         public void prepareCreateServiceInstance(Execution execution) {\r
199                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
200 \r
201                 try {\r
202                         utils.log("DEBUG", " ***** Inside prepareCreateServiceInstance of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
203 \r
204                         String createGenericMacroServiceNetworkVnfRequest = execution.getVariable("createGenericMacroServiceNetworkVnfRequest")\r
205                         String serviceModelInfo = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.modelInfo")\r
206                         execution.setVariable("serviceModelInfo", serviceModelInfo)\r
207 \r
208                         String serviceInputParams = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.requestParameters")\r
209                         execution.setVariable("serviceInputParams", serviceInputParams)\r
210                         \r
211                         String serviceInstanceName = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.requestInfo.instanceName")\r
212                         execution.setVariable("serviceInstanceName", serviceInstanceName)\r
213 \r
214                         utils.log("DEBUG", " ***** Completed prepareCreateServiceInstance of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
215                 } catch (Exception ex) {\r
216                         // try error in method block\r
217                         String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method prepareCreateService() - " + ex.getMessage()\r
218                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
219                 }\r
220          }\r
221         \r
222         \r
223         public void postProcessServiceInstanceCreate (Execution execution){\r
224                 def method = getClass().getSimpleName() + '.postProcessServiceInstanceCreate(' +'execution=' + execution.getId() +')'\r
225                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
226                 logDebug('Entered ' + method, isDebugLogEnabled)\r
227                 \r
228                 String source = execution.getVariable("source")\r
229                 String requestId = execution.getVariable("mso-request-id")\r
230                 String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
231                 String serviceInstanceName = execution.getVariable("serviceInstanceName")\r
232                 \r
233                 try {\r
234 \r
235                         String payload = """\r
236                         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">\r
237                         <soapenv:Header/>\r
238                         <soapenv:Body>\r
239                         <req:updateInfraRequest>\r
240                                 <requestId>${requestId}</requestId>\r
241                                 <lastModifiedBy>BPEL</lastModifiedBy>\r
242                                 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>\r
243                                 <serviceInstanceName>${serviceInstanceName}</serviceInstanceName>\r
244                         </req:updateInfraRequest>\r
245                         </soapenv:Body>\r
246                         </soapenv:Envelope>\r
247                         """\r
248                         execution.setVariable("CREVAS_setUpdateDbInstancePayload", payload)\r
249                         utils.logAudit("CREVAS_setUpdateDbInstancePayload: " + payload)\r
250                         logDebug('Exited ' + method, isDebugLogEnabled)\r
251                         //println("CMSO_updateDBStatusToSuccessPayload --> " + execution.getVariable("CMSO_updateDBStatusToSuccessPayload"))\r
252 \r
253                 } catch (BpmnError e) {\r
254                         throw e;\r
255                 } catch (Exception e) {\r
256                         logError('Caught exception in ' + method, e)\r
257                         exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)\r
258                 }\r
259         }\r
260         \r
261         \r
262         public void callDBCatalog (Execution execution) {\r
263                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
264 \r
265                 utils.log("DEBUG", " ***** Inside callDBCatalog() of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
266                 \r
267                 try {\r
268                         \r
269                         // get variable within incoming json\r
270                         String createGenericMacroServiceNetworkVnfRequest = execution.getVariable("createGenericMacroServiceNetworkVnfRequest");\r
271                         \r
272                         String catalog_db_endpoint = execution.getVariable("URN_mso_catalog_db_endpoint")\r
273                         utils.log("DEBUG", "catalog_db_endpoint: "+catalog_db_endpoint, isDebugEnabled)\r
274                         \r
275                         String serviceModelInvariantId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.modelInfo.modelInvariantId")\r
276                         String serviceModelVersion = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.modelInfo.modelVersion")\r
277                         utils.log("DEBUG", "getting network list ", isDebugEnabled)\r
278                         \r
279                         JSONArray networkList = catalogDbUtils.getAllNetworksByServiceModelInvariantUuidAndServiceModelVersion(catalog_db_endpoint, serviceModelInvariantId, serviceModelVersion)\r
280 \r
281                         //utils.log("DEBUG", "got network list: "+ networkList.toString(), isDebugEnabled)\r
282                         execution.setVariable("networkList", networkList)\r
283                         execution.setVariable("networkListString", networkList.toString())\r
284                         \r
285                         networkList = execution.getVariable("networkList");\r
286                         utils.log("DEBUG", "networkList: "+ networkList, isDebugEnabled)\r
287 \r
288                         if (networkList != null && networkList.length() > 0) {\r
289 \r
290                                 execution.setVariable("CREVAS_NetworksCount", networkList.length())\r
291                                 utils.log("DEBUG", "networks to create: "+ networkList.length(), isDebugEnabled)\r
292                         } else {\r
293                                 execution.setVariable("CREVAS_NetworksCount", 0)\r
294                                 utils.log("DEBUG", "no networks to create based upon Catalog DB response", isDebugEnabled)\r
295                         }       \r
296                         \r
297                         // VNFs\r
298                         JSONArray vnfList = catalogDbUtils.getAllVnfsByServiceModelInvariantUuidAndServiceModelVersion(catalog_db_endpoint, serviceModelInvariantId, serviceModelVersion)\r
299                         execution.setVariable("vnfList", vnfList)                       \r
300                         \r
301                         String vnfModelInfoString = ""\r
302                         if (vnfList != null && vnfList.length() > 0) {\r
303                                 execution.setVariable("CREVAS_VNFsCount", vnfList.length())\r
304                                 utils.log("DEBUG", "vnfs to create: "+ vnfList.length(), isDebugEnabled)\r
305                                 JSONObject vnfModelInfo = vnfList.getJSONObject(0).getJSONObject("modelInfo")\r
306                                 vnfModelInfoString = vnfModelInfo.toString()\r
307                         } else {\r
308                                         execution.setVariable("CREVAS_VNFsCount", 0)\r
309                                         utils.log("DEBUG", "no vnfs to create based upon Catalog DB response", isDebugEnabled)\r
310                         }\r
311                                 \r
312                         execution.setVariable("vnfModelInfo", vnfModelInfoString)\r
313                         //utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)\r
314 \r
315                         utils.log("DEBUG", " ***** Completed callDBCatalog() of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
316                 } catch (Exception ex) {\r
317                         sendSyncError(execution)\r
318                    String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. callDBCatalog() - " + ex.getMessage()\r
319                    utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
320                    exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
321                 }\r
322         }\r
323         \r
324         // *******************************\r
325         //     Generate Network request Section\r
326         // *******************************\r
327         public void prepareNetworkCreate (Execution execution) {\r
328                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
329 \r
330                 try {\r
331                         utils.log("DEBUG", " ***** Inside preparenNetworkCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
332 \r
333 //                      String disableRollback = execution.getVariable("disableRollback")\r
334 //                      def backoutOnFailure = ""\r
335 //                      if(disableRollback != null){\r
336 //                              if ( disableRollback == true) {\r
337 //                                      backoutOnFailure = "false"\r
338 //                              } else if ( disableRollback == false) {\r
339 //                                      backoutOnFailure = "true"\r
340 //                              }\r
341 //                      }\r
342                         //failIfExists - optional\r
343 \r
344                         String createGenericMacroServiceNetworkVnfRequest = execution.getVariable("createGenericMacroServiceNetworkVnfRequest")\r
345                         \r
346                         JSONArray networkList = execution.getVariable("networkList")\r
347                         utils.log("DEBUG", "array networkList: "+ networkList, isDebugEnabled)\r
348                         \r
349                         if (networkList == null || networkList.length() < 1){\r
350                                 networkList = new JSONArray(execution.getVariable("networkListString"))\r
351                                 utils.log("DEBUG", "array from string networkList: "+ networkList, isDebugEnabled)\r
352                         }\r
353                         \r
354                         Integer networksCreatedCount = execution.getVariable("CREVAS_NetworksCreatedCount")\r
355                         String networkModelInfoString = ""\r
356                         \r
357                         if (networkList != null) {\r
358                                 utils.log("DEBUG", " getting model info for network # :" + networksCreatedCount, isDebugEnabled)\r
359                                 JSONObject networkModelInfo = networkList.getJSONObject(networksCreatedCount.intValue()).getJSONObject("modelInfo")\r
360                                 networkModelInfoString = networkModelInfo.toString()\r
361                         } else {\r
362                                 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected number of networks to create - " + ex.getMessage()\r
363                                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
364                         }\r
365                         \r
366                         execution.setVariable("networkModelInfo", networkModelInfoString)\r
367                         utils.log("DEBUG", " networkModelInfoString :" + networkModelInfoString, isDebugEnabled)\r
368                         \r
369 //                      String networkModelInfo = execution.getVariable("networkModelInfo")\r
370                         // extract cloud configuration\r
371                         String lcpCloudRegionId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")\r
372                         execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)\r
373                         utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)\r
374                         String tenantId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.cloudConfiguration.tenantId")\r
375                         execution.setVariable("tenantId", tenantId)\r
376                         utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)\r
377                         \r
378                         String sdncVersion = execution.getVariable("sdncVersion")\r
379                         utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)\r
380                         \r
381                         JSONArray vnfList = execution.getVariable("vnfList")\r
382                         utils.log("DEBUG", "vnfList: "+ vnfList, isDebugEnabled)\r
383                         \r
384                         String vnfModelInfo = execution.getVariable("vnfModelInfo")\r
385                         utils.log("DEBUG", "vnfModelInfo: "+ vnfModelInfo, isDebugEnabled)\r
386                         \r
387                         networkList = execution.getVariable("networkList")\r
388                         utils.log("DEBUG", "networkList: "+ networkList, isDebugEnabled)\r
389                         \r
390                         utils.log("DEBUG", " ***** Completed preparenNetworkCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
391                 } catch (Exception ex) {\r
392                         // try error in method block\r
393                         String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method prepareNetworkCreate() - " + ex.getMessage()\r
394                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
395                 }\r
396          }\r
397         \r
398         // *******************************\r
399         //     Validate Network request Section -> increment count\r
400         // *******************************\r
401         public void validateNetworkCreate (Execution execution) {\r
402                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
403 \r
404                 try {\r
405                         utils.log("DEBUG", " ***** Inside validateNetworkCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
406 \r
407                         Integer networksCreatedCount = execution.getVariable("CREVAS_NetworksCreatedCount")\r
408                         networksCreatedCount++\r
409                         \r
410                         execution.setVariable("CREVAS_NetworksCreatedCount", networksCreatedCount)\r
411                         \r
412                         execution.setVariable("DCRENI_rollbackData"+networksCreatedCount, execution.getVariable("DCRENI_rollbackData"))\r
413 \r
414                         utils.log("DEBUG", "networksCreatedCount: "+ networksCreatedCount, isDebugEnabled)\r
415                         utils.log("DEBUG", "DCRENI_rollbackData N : "+ execution.getVariable("DCRENI_rollbackData"+networksCreatedCount), isDebugEnabled)\r
416                         \r
417                         JSONArray vnfList = execution.getVariable("vnfList")\r
418                         utils.log("DEBUG", "vnfList: "+ vnfList, isDebugEnabled)\r
419                         \r
420                         String vnfModelInfo = execution.getVariable("vnfModelInfo")\r
421                         utils.log("DEBUG", "vnfModelInfo: "+ vnfModelInfo, isDebugEnabled)\r
422                         \r
423                         JSONArray networkList = execution.getVariable("networkList")\r
424                         utils.log("DEBUG", "networkList: "+ networkList, isDebugEnabled)\r
425                         \r
426                         utils.log("DEBUG", " ***** Completed validateNetworkCreate of CreateGenericMacroServiceNetworkVnf ***** "+" network # "+networksCreatedCount, isDebugEnabled)\r
427                 } catch (Exception ex) {\r
428                         // try error in method block\r
429                         String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method validateNetworkCreate() - " + ex.getMessage()\r
430                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
431                 }\r
432          }\r
433         \r
434         // *******************************\r
435         //     Generate Network request Section\r
436         // *******************************\r
437         public void prepareVnfAndModulesCreate (Execution execution) {\r
438                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
439 \r
440                 try {\r
441                         utils.log("DEBUG", " ***** Inside prepareVnfAndModulesCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
442 \r
443                         //                      String disableRollback = execution.getVariable("disableRollback")\r
444                         //                      def backoutOnFailure = ""\r
445                         //                      if(disableRollback != null){\r
446                         //                              if ( disableRollback == true) {\r
447                         //                                      backoutOnFailure = "false"\r
448                         //                              } else if ( disableRollback == false) {\r
449                         //                                      backoutOnFailure = "true"\r
450                         //                              }\r
451                         //                      }\r
452                                                 //failIfExists - optional\r
453 \r
454                         String createGenericMacroServiceNetworkVnfRequest = execution.getVariable("createGenericMacroServiceNetworkVnfRequest")\r
455                         String productFamilyId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.requestInfo.productFamilyId")\r
456                         execution.setVariable("productFamilyId", productFamilyId)\r
457                         utils.log("DEBUG","productFamilyId: "+ productFamilyId, isDebugEnabled)\r
458 \r
459                         JSONArray vnfList = execution.getVariable("vnfList")\r
460 \r
461                         Integer vnfsCreatedCount = execution.getVariable("CREVAS_VnfsCreatedCount")\r
462                         String vnfModelInfoString = null;\r
463                         \r
464                         if (vnfList != null && vnfList.length() > 0 ) {\r
465                                 utils.log("DEBUG", "getting model info for vnf # " + vnfsCreatedCount, isDebugEnabled)\r
466                                 JSONObject vnfModelInfo1 = vnfList.getJSONObject(0).getJSONObject("modelInfo")\r
467                                 utils.log("DEBUG", "got 0 ", isDebugEnabled)\r
468                                 JSONObject vnfModelInfo = vnfList.getJSONObject(vnfsCreatedCount.intValue()).getJSONObject("modelInfo")\r
469                                 vnfModelInfoString = vnfModelInfo.toString()\r
470                         } else {\r
471                                 //TODO: vnfList does not contain data. Need to investigate why ... . Fro VIPR use model stored\r
472                                 vnfModelInfoString = execution.getVariable("vnfModelInfo")\r
473                         }\r
474                                                         \r
475                         utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)\r
476                         \r
477                         // extract cloud configuration\r
478                         String lcpCloudRegionId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")\r
479                         execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)\r
480                         utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)\r
481                         String tenantId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.cloudConfiguration.tenantId")\r
482                         execution.setVariable("tenantId", tenantId)\r
483                         utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)\r
484                                                 \r
485                         String sdncVersion = execution.getVariable("sdncVersion")\r
486                         utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)\r
487 \r
488                         utils.log("DEBUG", " ***** Completed prepareVnfAndModulesCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
489                 } catch (Exception ex) {\r
490                         // try error in method block\r
491                         String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method prepareVnfAndModulesCreate() - " + ex.getMessage()\r
492                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
493                 }\r
494          }\r
495 \r
496         // *******************************\r
497         //     Validate Vnf request Section -> increment count\r
498         // *******************************\r
499         public void validateVnfCreate (Execution execution) {\r
500                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
501 \r
502                 try {\r
503                         utils.log("DEBUG", " ***** Inside validateVnfCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
504 \r
505                         Integer vnfsCreatedCount = execution.getVariable("CREVAS_VnfsCreatedCount")\r
506                         vnfsCreatedCount++\r
507                         \r
508                         execution.setVariable("CREVAS_VnfsCreatedCount", vnfsCreatedCount)\r
509                         \r
510                         utils.log("DEBUG", " ***** Completed validateVnfCreate of CreateGenericMacroServiceNetworkVnf ***** "+" vnf # "+vnfsCreatedCount, isDebugEnabled)\r
511                 } catch (Exception ex) {\r
512                         // try error in method block\r
513                         String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method validateVnfCreate() - " + ex.getMessage()\r
514                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
515                 }\r
516          }\r
517         \r
518         // *******************************\r
519         //     Validate Network request Section -> decrement count\r
520         // *******************************\r
521         public void validateNetworkRollback (Execution execution) {\r
522                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
523 \r
524                 try {\r
525                         utils.log("DEBUG", " ***** Inside validateNetworkRollback of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
526 \r
527                         Integer networksCreatedCount = execution.getVariable("CREVAS_NetworksCreatedCount")\r
528                         networksCreatedCount--\r
529                         \r
530                         execution.setVariable("CREVAS_NetworksCreatedCount", networksCreatedCount)\r
531                         \r
532                         execution.setVariable("DCRENI_rollbackData", execution.getVariable("DCRENI_rollbackData"+networksCreatedCount))\r
533                         \r
534                         utils.log("DEBUG", " ***** Completed validateNetworkRollback of CreateGenericMacroServiceNetworkVnf ***** "+" network # "+networksCreatedCount, isDebugEnabled)\r
535                 } catch (Exception ex) {\r
536                         // try error in method block\r
537                         String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method validateNetworkRollback() - " + ex.getMessage()\r
538                         //exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
539                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
540                         execution.setVariable("CREVAS_NetworksCreatedCount", 0)\r
541                         utils.log("ERROR", exceptionMessage, true)\r
542                 }\r
543          }\r
544         // *******************************\r
545         //     Build DB request Section\r
546         // *******************************\r
547 //      public void prepareDBRequest (Execution execution) {\r
548 //              def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
549 //\r
550 //              try {\r
551 //                      utils.log("DEBUG", " ***** Inside prepareDBRequest of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
552 //\r
553 //                      String requestId = execution.getVariable("CREVAS_requestId")\r
554 //                      String statusMessage = "vIPR ATM Service Instance successfully created."\r
555 //                      String serviceInstanceId = execution.getVariable("CREVAS_serviceInstanceId")\r
556 //\r
557 //                      //TODO - verify the format for Service Instance Create,\r
558 //                      String dbRequest =\r
559 //                                      """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">\r
560 //                                              <soapenv:Header/>\r
561 //                                              <soapenv:Body>\r
562 //                                                      <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">\r
563 //                                                              <requestId>${requestId}</requestId>\r
564 //                                                              <lastModifiedBy>BPMN</lastModifiedBy>\r
565 //                                                              <statusMessage>${statusMessage}</statusMessage>\r
566 //                                                              <responseBody></responseBody>\r
567 //                                                              <requestStatus>COMPLETED</requestStatus>\r
568 //                                                              <progress>100</progress>\r
569 //                                                              <vnfOutputs/>\r
570 //                                                              <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>\r
571 //                                                      </ns:updateInfraRequest>\r
572 //                                                 </soapenv:Body>\r
573 //                                         </soapenv:Envelope>"""\r
574 //\r
575 //                 String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)\r
576 //                 execution.setVariable("CREVAS_createDBRequest", buildDeleteDBRequestAsString)\r
577 //                 utils.logAudit(buildDeleteDBRequestAsString)\r
578 //\r
579 //                 utils.log("DEBUG", " ***** Completed prepareDBRequest of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
580 //              } catch (Exception ex) {\r
581 //                      // try error in method block\r
582 //                      String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method prepareDBRequest() - " + ex.getMessage()\r
583 //                      exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
584 //\r
585 //              }\r
586 //\r
587 //       }\r
588 \r
589 \r
590         // *****************************************\r
591         //     Prepare Completion request Section\r
592         // *****************************************\r
593         public void postProcessResponse (Execution execution) {\r
594                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
595 \r
596                 utils.log("DEBUG", " ***** Inside postProcessResponse of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
597 \r
598                 try {\r
599                         String source = execution.getVariable("source")\r
600                         String requestId = execution.getVariable("mso-request-id")\r
601                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
602 \r
603                         String msoCompletionRequest =\r
604                                         """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
605                                                                         xmlns:ns="http://org.openecomp/mso/request/types/v1">\r
606                                                         <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
607                                                                 <request-id>${requestId}</request-id>\r
608                                                                 <action>CREATE</action>\r
609                                                                 <source>${source}</source>\r
610                                                         </request-info>\r
611                                                         <status-message>Service Instance has been created successfully via macro orchestration</status-message>\r
612                                                         <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>\r
613                                                         <mso-bpel-name>BPMN macro create</mso-bpel-name>\r
614                                                 </aetgt:MsoCompletionRequest>"""\r
615 \r
616                         // Format Response\r
617                         String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)\r
618 \r
619                         utils.logAudit(xmlMsoCompletionRequest)\r
620                         execution.setVariable("CREVAS_Success", true)\r
621                         execution.setVariable("CREVAS_CompleteMsoProcessRequest", xmlMsoCompletionRequest)\r
622                         utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)\r
623                 } catch (BpmnError e) {\r
624                         throw e;\r
625                 } catch (Exception ex) {\r
626                         // try error in method block\r
627                         String exceptionMessage = "Bpmn error encountered in CreateServiceInstance flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()\r
628                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
629                 }\r
630         }\r
631 \r
632         public void preProcessRollback (Execution execution) {\r
633                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
634                 utils.log("DEBUG"," ***** preProcessRollback of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
635                 try {\r
636                         \r
637                         Object workflowException = execution.getVariable("WorkflowException");\r
638 \r
639                         if (workflowException instanceof WorkflowException) {\r
640                                 utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)\r
641                                 execution.setVariable("prevWorkflowException", workflowException);\r
642                                 //execution.setVariable("WorkflowException", null);\r
643                         }\r
644                 } catch (BpmnError e) {\r
645                         utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)\r
646                 } catch(Exception ex) {\r
647                         String msg = "Exception in preProcessRollback. " + ex.getMessage()\r
648                         utils.log("DEBUG", msg, isDebugEnabled)\r
649                 }\r
650                 utils.log("DEBUG"," *** Exit preProcessRollback of CreateGenericMacroServiceNetworkVnf *** ", isDebugEnabled)\r
651         }\r
652 \r
653         public void postProcessRollback (Execution execution) {\r
654                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
655                 utils.log("DEBUG"," ***** postProcessRollback of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)\r
656                 String msg = ""\r
657                 try {\r
658                         Object workflowException = execution.getVariable("prevWorkflowException");\r
659                         if (workflowException instanceof WorkflowException) {\r
660                                 utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)\r
661                                 execution.setVariable("WorkflowException", workflowException);\r
662                         }\r
663                 } catch (BpmnError b) {\r
664                         utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)\r
665                         throw b;\r
666                 } catch(Exception ex) {\r
667                         msg = "Exception in postProcessRollback. " + ex.getMessage()\r
668                         utils.log("DEBUG", msg, isDebugEnabled)\r
669                 }\r
670                 utils.log("DEBUG"," *** Exit postProcessRollback of CreateGenericMacroServiceNetworkVnf *** ", isDebugEnabled)\r
671         }\r
672 \r
673         public void prepareFalloutRequest(Execution execution){\r
674                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
675 \r
676                 utils.log("DEBUG", " *** STARTED CreateGenericMacroServiceNetworkVnf prepareFalloutRequest Process *** ", isDebugEnabled)\r
677 \r
678                 try {\r
679                         WorkflowException wfex = execution.getVariable("WorkflowException")\r
680                         utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)\r
681                         String requestInfo = execution.getVariable("CREVAS_requestInfo")\r
682                         utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)\r
683                         \r
684                         //TODO. hmmm. there is no way to UPDATE error message.\r
685 //                      String errorMessage = wfex.getErrorMessage()\r
686 //                      boolean successIndicator = execution.getVariable("DCRESI_rollbackSuccessful")\r
687 //                      if (successIndicator){\r
688 //                              errorMessage = errorMessage + ". Rollback successful."\r
689 //                      } else {\r
690 //                              errorMessage = errorMessage + ". Rollback not completed."\r
691 //                      }\r
692                         \r
693                         String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)\r
694 \r
695                         execution.setVariable("CREVAS_falloutRequest", falloutRequest)\r
696 \r
697                 } catch (Exception ex) {\r
698                         utils.log("DEBUG", "Error Occured in CreateGenericMacroServiceNetworkVnf prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)\r
699                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateGenericMacroServiceNetworkVnf prepareFalloutRequest Process")\r
700                 }\r
701                 utils.log("DEBUG", "*** COMPLETED CreateGenericMacroServiceNetworkVnf prepareFalloutRequest Process ***", isDebugEnabled)\r
702         }\r
703 \r
704 \r
705         public void sendSyncError (Execution execution) {\r
706                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
707                 execution.setVariable("prefix", Prefix)\r
708 \r
709                 utils.log("DEBUG", " ***** Inside sendSyncError() of CreateServiceInstanceInfra ***** ", isDebugEnabled)\r
710 \r
711                 try {\r
712                         String errorMessage = ""\r
713                         if (execution.getVariable("WorkflowException") instanceof WorkflowException) {\r
714                                 WorkflowException wfe = execution.getVariable("WorkflowException")\r
715                                 errorMessage = wfe.getErrorMessage()\r
716                         } else {\r
717                                 errorMessage = "Sending Sync Error."\r
718                         }\r
719 \r
720                         String buildworkflowException =\r
721                                 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">\r
722                                         <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>\r
723                                         <aetgt:ErrorCode>7000</aetgt:ErrorCode>\r
724                                    </aetgt:WorkflowException>"""\r
725 \r
726                         utils.logAudit(buildworkflowException)\r
727                         sendWorkflowResponse(execution, 500, buildworkflowException)\r
728                 } catch (Exception ex) {\r
729                         utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)\r
730                 }\r
731         }\r
732 \r
733         public void processJavaException(Execution execution){\r
734                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
735                 execution.setVariable("prefix",Prefix)\r
736                 try{\r
737                         utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)\r
738                         utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)\r
739                         utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)\r
740                         execution.setVariable("CRESI_unexpectedError", "Caught a Java Lang Exception")  // Adding this line temporarily until this flows error handling gets updated\r
741                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")\r
742                 }catch(BpmnError b){\r
743                         utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)\r
744                         throw b\r
745                 }catch(Exception e){\r
746                         utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)\r
747                         execution.setVariable("CRESI_unexpectedError", "Exception in processJavaException method")  // Adding this line temporarily until this flows error handling gets updated\r
748                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")\r
749                 }\r
750                 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)\r
751         }\r
752 }