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