87cf6fbd0f5b2a89cfea60c1d210aff6f3b015c7
[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                   /*
160                   * Extracting User Parameters from incoming Request and converting into a Map
161                   */
162                   def jsonSlurper = new JsonSlurper()
163                   def jsonOutput = new JsonOutput()
164   
165                   Map reqMap = jsonSlurper.parseText(createVcpeServiceRequest)
166   
167                   //InputParams
168                   def userParams = reqMap.requestDetails?.requestParameters?.userParams
169   
170                   Map<String, String> inputMap = [:]
171                   if (userParams) {
172                           userParams.each {
173                                   name, value -> inputMap.put(name, value)
174                                         if (name.equals("BRG_WAN_MAC_Address"))
175                                                         execution.setVariable("brgWanMacAddress", value)\r
176                           }
177                   }
178
179                   utils.log("DEBUG", "User Input Parameters map: " + userParams.toString(), isDebugEnabled)
180                   execution.setVariable("serviceInputParams", inputMap)
181
182                         utils.log("DEBUG", "Incoming brgWanMacAddress is: " + execution.getVariable('brgWanMacAddress'), isDebugEnabled)\r
183 \r
184                         //For Completion Handler & Fallout Handler\r
185                         String requestInfo =\r
186                         """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
187                                         <request-id>${requestId}</request-id>\r
188                                         <action>CREATE</action>\r
189                                         <source>${source}</source>\r
190                                    </request-info>"""\r
191 \r
192                         execution.setVariable(Prefix+"requestInfo", requestInfo)\r
193 \r
194                         utils.log("DEBUG", " ***** Completed preProcessRequest CreateVcpeResCustService Request ***** ", isDebugEnabled)\r
195 \r
196                 } catch (BpmnError e) {\r
197                         throw e;\r
198 \r
199                 } catch (Exception ex){\r
200                         String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()\r
201                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
202                 }\r
203         }\r
204 \r
205         public void sendSyncResponse(Execution execution) {\r
206                 def isDebugEnabled=execution.getVariable(DebugFlag)\r
207 \r
208                 utils.log("DEBUG", " ***** Inside sendSyncResponse of CreateVcpeResCustService ***** ", isDebugEnabled)\r
209 \r
210                 try {\r
211                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
212                         String requestId = execution.getVariable("mso-request-id")\r
213 \r
214                         // RESTResponse (for API Handler (APIH) Reply Task)\r
215                         String syncResponse ="""{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()\r
216 \r
217                         utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)\r
218                         sendWorkflowResponse(execution, 202, syncResponse)\r
219 \r
220                 } catch (Exception ex) {\r
221                         String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method sendSyncResponse() - " + ex.getMessage()\r
222                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
223                 }\r
224         }\r
225 \r
226         // *******************************\r
227         //\r
228         // *******************************\r
229         public void prepareDecomposeService(Execution execution) {\r
230                 def isDebugEnabled=execution.getVariable(DebugFlag)\r
231 \r
232                 try {\r
233                         utils.log("DEBUG", " ***** Inside prepareDecomposeService of CreateVcpeResCustService ***** ", isDebugEnabled)\r
234 \r
235                         String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")\r
236 \r
237                         //serviceModelInfo JSON string will be used as-is for DoCreateServiceInstance BB\r
238                         String serviceModelInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.modelInfo")\r
239                         execution.setVariable("serviceModelInfo", serviceModelInfo)\r
240 \r
241                         utils.log("DEBUG", " ***** Completed prepareDecomposeService of CreateVcpeResCustService ***** ", isDebugEnabled)\r
242                 } catch (Exception ex) {\r
243                         // try error in method block\r
244                         String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()\r
245                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
246                 }\r
247          }\r
248 \r
249         // *******************************\r
250         //\r
251         // *******************************\r
252         public void prepareCreateServiceInstance(Execution execution) {\r
253                 def isDebugEnabled=execution.getVariable(DebugFlag)\r
254 \r
255                 try {\r
256                         utils.log("DEBUG", " ***** Inside prepareCreateServiceInstance of CreateVcpeResCustService ***** ", isDebugEnabled)\r
257 \r
258                         /*\r
259                          * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject\r
260                          *              ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")\r
261                          *              ModelInfo modelInfo = serviceDecomposition.getModelInfo()\r
262                          *\r
263                          */\r
264                         String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")\r
265 //                      String serviceInputParams = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters")\r
266 //                      execution.setVariable("serviceInputParams", serviceInputParams)\r
267 \r
268
269                         String serviceInstanceName = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.instanceName")\r
270                         execution.setVariable("serviceInstanceName", serviceInstanceName)\r
271 \r
272                         ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")\r
273                         execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonString())\r
274 \r
275                         utils.log("DEBUG", " ***** Completed prepareCreateServiceInstance of CreateVcpeResCustService ***** ", isDebugEnabled)\r
276                 } catch (Exception ex) {\r
277                         // try error in method block\r
278                         String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()\r
279                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
280                 }\r
281          }\r
282 \r
283         public void postProcessServiceInstanceCreate (Execution execution){\r
284                 def method = getClass().getSimpleName() + '.postProcessServiceInstanceCreate(' +'execution=' + execution.getId() +')'\r
285                 def isDebugLogEnabled = execution.getVariable(DebugFlag)\r
286                 logDebug('Entered ' + method, isDebugLogEnabled)\r
287 \r
288                 String requestId = execution.getVariable("mso-request-id")\r
289                 String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
290                 String serviceInstanceName = execution.getVariable("serviceInstanceName")\r
291 \r
292                 try {\r
293 \r
294                         String payload = """\r
295                         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">\r
296                         <soapenv:Header/>\r
297                         <soapenv:Body>\r
298                         <req:updateInfraRequest>\r
299                                 <requestId>${requestId}</requestId>\r
300                                 <lastModifiedBy>BPEL</lastModifiedBy>\r
301                                 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>\r
302                                 <serviceInstanceName>${serviceInstanceName}</serviceInstanceName>\r
303                         </req:updateInfraRequest>\r
304                         </soapenv:Body>\r
305                         </soapenv:Envelope>\r
306                         """\r
307                         execution.setVariable(Prefix+"setUpdateDbInstancePayload", payload)\r
308                         utils.logAudit(Prefix+"setUpdateDbInstancePayload: " + payload)\r
309                         logDebug('Exited ' + method, isDebugLogEnabled)\r
310 \r
311                 } catch (BpmnError e) {\r
312                         throw e;\r
313                 } catch (Exception e) {\r
314                         logError('Caught exception in ' + method, e)\r
315                         exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)\r
316                 }\r
317         }\r
318 \r
319 \r
320         public void processDecomposition (Execution execution) {\r
321                 def isDebugEnabled=execution.getVariable(DebugFlag)\r
322 \r
323                 utils.log("DEBUG", " ***** Inside processDecomposition() of CreateVcpeResCustService ***** ", isDebugEnabled)\r
324 \r
325                 try {\r
326 \r
327                         ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")\r
328 \r
329                         // VNFs\r
330                         List<VnfResource> vnfList = serviceDecomposition.getServiceVnfs()\r
331                         execution.setVariable("vnfList", vnfList)\r
332                         execution.setVariable("vnfListString", vnfList.toString())\r
333 \r
334                         String vnfModelInfoString = ""\r
335                         if (vnfList != null && vnfList.size() > 0) {\r
336                                 execution.setVariable(Prefix+"VNFsCount", vnfList.size())\r
337                                 utils.log("DEBUG", "vnfs to create: "+ vnfList.size(), isDebugEnabled)\r
338                                 ModelInfo vnfModelInfo = vnfList[0].getModelInfo()\r
339 \r
340                                 vnfModelInfoString = vnfModelInfo.toString()\r
341                                 String vnfModelInfoWithRoot = vnfModelInfo.toString()\r
342                                 vnfModelInfoString = jsonUtil.getJsonValue(vnfModelInfoWithRoot, "modelInfo")\r
343                         } else {\r
344                                         execution.setVariable(Prefix+"VNFsCount", 0)\r
345                                         utils.log("DEBUG", "no vnfs to create based upon serviceDecomposition content", isDebugEnabled)\r
346                         }\r
347 \r
348                         execution.setVariable("vnfModelInfo", vnfModelInfoString)\r
349                         execution.setVariable("vnfModelInfoString", vnfModelInfoString)\r
350                         utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)\r
351 \r
352                         utils.log("DEBUG", " ***** Completed processDecomposition() of CreateVcpeResCustService ***** ", isDebugEnabled)\r
353                 } catch (Exception ex) {\r
354                         sendSyncError(execution)\r
355                    String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. processDecomposition() - " + ex.getMessage()\r
356                    utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
357                    exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
358                 }\r
359         }\r
360 \r
361 \r
362         public void prepareCreateAllottedResourceTXC(Execution execution) {\r
363                 def isDebugEnabled=execution.getVariable(DebugFlag)\r
364 \r
365                 try {\r
366                         utils.log("DEBUG", " ***** Inside prepareCreateAllottedResourceTXC of CreateVcpeResCustService ***** ", isDebugEnabled)\r
367 \r
368                         /*\r
369                          * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject\r
370                          *              ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")\r
371                          *              ModelInfo modelInfo = serviceDecomposition.getModelInfo()\r
372                          *\r
373                          */\r
374                         String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")\r
375                         ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")\r
376 \r
377                         //allottedResourceModelInfo\r
378                         //allottedResourceRole\r
379                         //The model Info parameters are a JSON structure as defined in the Service Instantiation API.\r
380                         //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
381                         List<AllottedResource> allottedResources = serviceDecomposition.getServiceAllottedResources()\r
382                         if (allottedResources != null) {\r
383                                 Iterator iter = allottedResources.iterator();\r
384                                 while (iter.hasNext()){\r
385                                         AllottedResource allottedResource = (AllottedResource)iter.next();\r
386 \r
387                                         utils.log("DEBUG", " getting model info for AllottedResource # :" + allottedResource.toJsonString(), isDebugEnabled)\r
388                                         utils.log("DEBUG", " allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType(), isDebugEnabled)\r
389                                         if("TunnelXConn".equalsIgnoreCase(allottedResource.getAllottedResourceType())){\r
390                                                 //set create flag to true\r
391                                                 execution.setVariable("createTXCAR", true)\r
392                                                 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()\r
393                                                 execution.setVariable("allottedResourceModelInfoTXC", allottedResourceModelInfo.toJsonString())\r
394                                                 execution.setVariable("allottedResourceRoleTXC", allottedResource.getAllottedResourceRole())\r
395                                                 execution.setVariable("allottedResourceTypeTXC", allottedResource.getAllottedResourceType())\r
396                                                 //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the TXC,\r
397                                                 //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
398                                                 execution.setVariable("parentServiceInstanceIdTXC", allottedResource.getHomingSolution().getServiceInstanceId())\r
399                                         }
400                                 }\r
401                         }\r
402 \r
403                         //unit test only\r
404                         String allottedResourceId = execution.getVariable("allottedResourceId")\r
405                         execution.setVariable("allottedResourceIdTXC", allottedResourceId)\r
406                         utils.log("DEBUG", "setting allottedResourceId CreateVcpeResCustService "+allottedResourceId, isDebugEnabled)\r
407                         \r
408                         utils.log("DEBUG", " ***** Completed prepareCreateAllottedResourceTXC of CreateVcpeResCustService ***** ", isDebugEnabled)\r
409                 } catch (Exception ex) {\r
410                         // try error in method block\r
411                         String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceTXC flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()\r
412                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
413                 }\r
414          }\r
415         public void prepareCreateAllottedResourceBRG(Execution execution) {\r
416                 def isDebugEnabled=execution.getVariable(DebugFlag)\r
417 \r
418                 try {\r
419                         utils.log("DEBUG", " ***** Inside prepareCreateAllottedResourceBRG of CreateVcpeResCustService ***** ", isDebugEnabled)\r
420 \r
421                         /*\r
422                          * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject\r
423                          *              ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")\r
424                          *              ModelInfo modelInfo = serviceDecomposition.getModelInfo()\r
425                          *\r
426                          */\r
427                         String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")\r
428                         ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")\r
429 \r
430                         //allottedResourceModelInfo\r
431                         //allottedResourceRole\r
432                         //The model Info parameters are a JSON structure as defined in the Service Instantiation API.\r
433                         //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
434                         List<AllottedResource> allottedResources = serviceDecomposition.getServiceAllottedResources()\r
435                         if (allottedResources != null) {\r
436                                 Iterator iter = allottedResources.iterator();\r
437                                 while (iter.hasNext()){\r
438                                         AllottedResource allottedResource = (AllottedResource)iter.next();\r
439 \r
440                                         utils.log("DEBUG", " getting model info for AllottedResource # :" + allottedResource.toJsonString(), isDebugEnabled)\r
441                                         utils.log("DEBUG", " allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType(), isDebugEnabled)\r
442                                         if("BRG".equalsIgnoreCase(allottedResource.getAllottedResourceType())){\r
443                                                 //set create flag to true\r
444                                                 execution.setVariable("createBRGAR", true)\r
445                                                 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()\r
446                                                 execution.setVariable("allottedResourceModelInfoBRG", allottedResourceModelInfo.toJsonString())\r
447                                                 execution.setVariable("allottedResourceRoleBRG", allottedResource.getAllottedResourceRole())\r
448                                                 execution.setVariable("allottedResourceTypeBRG", allottedResource.getAllottedResourceType())\r
449                                                 //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the BRG,\r
450                                                 //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
451                                                 execution.setVariable("parentServiceInstanceIdBRG", allottedResource.getHomingSolution().getServiceInstanceId())\r
452                                         }\r
453                                 }\r
454                         }\r
455 \r
456                         //unit test only\r
457                         String allottedResourceId = execution.getVariable("allottedResourceId")\r
458                         execution.setVariable("allottedResourceIdBRG", allottedResourceId)\r
459                         utils.log("DEBUG", "setting allottedResourceId CreateVcpeResCustService "+allottedResourceId, isDebugEnabled)\r
460                         \r
461                         utils.log("DEBUG", " ***** Completed prepareCreateAllottedResourceBRG of CreateVcpeResCustService ***** ", isDebugEnabled)\r
462                 } catch (Exception ex) {\r
463                         // try error in method block\r
464                         String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceBRG flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()\r
465                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
466                 }\r
467          }\r
468 \r
469
470
471         // *******************************\r
472         //     Generate Network request Section\r
473         // *******************************\r
474         public void prepareVnfAndModulesCreate (Execution execution) {\r
475                 def isDebugEnabled=execution.getVariable(DebugFlag)\r
476 \r
477                 try {\r
478                         utils.log("DEBUG", " ***** Inside prepareVnfAndModulesCreate of CreateVcpeResCustService ***** ", isDebugEnabled)\r
479 \r
480                         //                      String disableRollback = execution.getVariable("disableRollback")\r
481                         //                      def backoutOnFailure = ""\r
482                         //                      if(disableRollback != null){\r
483                         //                              if ( disableRollback == true) {\r
484                         //                                      backoutOnFailure = "false"\r
485                         //                              } else if ( disableRollback == false) {\r
486                         //                                      backoutOnFailure = "true"\r
487                         //                              }\r
488                         //                      }\r
489                                                 //failIfExists - optional\r
490 \r
491                         String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")\r
492                         String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")\r
493                         execution.setVariable("productFamilyId", productFamilyId)\r
494                         utils.log("DEBUG","productFamilyId: "+ productFamilyId, isDebugEnabled)\r
495 \r
496                         List<VnfResource> vnfList = execution.getVariable("vnfList")\r
497 \r
498                         Integer vnfsCreatedCount = execution.getVariable(Prefix+"VnfsCreatedCount")\r
499                         String vnfModelInfoString = null;\r
500 \r
501                         if (vnfList != null && vnfList.size() > 0 ) {\r
502                                 utils.log("DEBUG", "getting model info for vnf # " + vnfsCreatedCount, isDebugEnabled)\r
503                                 ModelInfo vnfModelInfo1 = vnfList[0].getModelInfo()\r
504                                 utils.log("DEBUG", "got 0 ", isDebugEnabled)\r
505                                 ModelInfo vnfModelInfo = vnfList[vnfsCreatedCount.intValue()].getModelInfo()\r
506                                 vnfModelInfoString = vnfModelInfo.toString()\r
507                         } else {\r
508                                 //TODO: vnfList does not contain data. Need to investigate why ... . Fro VCPE use model stored\r
509                                 vnfModelInfoString = execution.getVariable("vnfModelInfo")\r
510                         }\r
511 \r
512                         utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)\r
513 \r
514                         // extract cloud configuration\r
515                         String lcpCloudRegionId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")\r
516                         execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)\r
517                         utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)\r
518                         String tenantId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.tenantId")\r
519                         execution.setVariable("tenantId", tenantId)\r
520                         utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)\r
521 \r
522                         String sdncVersion = execution.getVariable("sdncVersion")\r
523                         utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)\r
524 \r
525                         utils.log("DEBUG", " ***** Completed prepareVnfAndModulesCreate of CreateVcpeResCustService ***** ", isDebugEnabled)\r
526                 } catch (Exception ex) {\r
527                         // try error in method block\r
528                         String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareVnfAndModulesCreate() - " + ex.getMessage()\r
529                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
530                 }\r
531          }\r
532 \r
533         // *******************************\r
534         //     Validate Vnf request Section -> increment count\r
535         // *******************************\r
536         public void validateVnfCreate (Execution execution) {\r
537                 def isDebugEnabled=execution.getVariable(DebugFlag)\r
538 \r
539                 try {\r
540                         utils.log("DEBUG", " ***** Inside validateVnfCreate of CreateVcpeResCustService ***** ", isDebugEnabled)\r
541 \r
542                         Integer vnfsCreatedCount = execution.getVariable(Prefix+"VnfsCreatedCount")\r
543                         vnfsCreatedCount++\r
544 \r
545                         execution.setVariable(Prefix+"VnfsCreatedCount", vnfsCreatedCount)\r
546 \r
547                         utils.log("DEBUG", " ***** Completed validateVnfCreate of CreateVcpeResCustService ***** "+" vnf # "+vnfsCreatedCount, 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 validateVnfCreate() - " + ex.getMessage()\r
551                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
552                 }\r
553          }\r
554 \r
555         // *****************************************\r
556         //     Prepare Completion request Section\r
557         // *****************************************\r
558         public void postProcessResponse (Execution execution) {\r
559                 def isDebugEnabled=execution.getVariable(DebugFlag)\r
560 \r
561                 utils.log("DEBUG", " ***** Inside postProcessResponse of CreateVcpeResCustService ***** ", isDebugEnabled)\r
562 \r
563                 try {\r
564                         String source = execution.getVariable("source")\r
565                         String requestId = execution.getVariable("mso-request-id")\r
566                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
567 \r
568                         String msoCompletionRequest =\r
569                                         """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
570                                                                         xmlns:ns="http://org.openecomp/mso/request/types/v1">\r
571                                                         <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
572                                                                 <request-id>${requestId}</request-id>\r
573                                                                 <action>CREATE</action>\r
574                                                                 <source>${source}</source>\r
575                                                         </request-info>\r
576                                                         <status-message>Service Instance has been created successfully via macro orchestration</status-message>\r
577                                                         <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>\r
578                                                         <mso-bpel-name>BPMN macro create</mso-bpel-name>\r
579                                                 </aetgt:MsoCompletionRequest>"""\r
580 \r
581                         // Format Response\r
582                         String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)\r
583 \r
584                         utils.logAudit(xmlMsoCompletionRequest)\r
585                         execution.setVariable(Prefix+"Success", true)\r
586                         execution.setVariable(Prefix+"CompleteMsoProcessRequest", xmlMsoCompletionRequest)\r
587                         utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)\r
588                 } catch (BpmnError e) {\r
589                         throw e;\r
590                 } catch (Exception ex) {\r
591                         // try error in method block\r
592                         String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()\r
593                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
594                 }\r
595         }\r
596 \r
597         public void preProcessRollback (Execution execution) {\r
598                 def isDebugEnabled=execution.getVariable(DebugFlag)\r
599                 utils.log("DEBUG"," ***** preProcessRollback of CreateVcpeResCustService ***** ", isDebugEnabled)\r
600                 try {\r
601 \r
602                         Object workflowException = execution.getVariable("WorkflowException");\r
603 \r
604                         if (workflowException instanceof WorkflowException) {\r
605                                 utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)\r
606                                 execution.setVariable("prevWorkflowException", workflowException);\r
607                                 //execution.setVariable("WorkflowException", null);\r
608                         }\r
609                 } catch (BpmnError e) {\r
610                         utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)\r
611                 } catch(Exception ex) {\r
612                         String msg = "Exception in preProcessRollback. " + ex.getMessage()\r
613                         utils.log("DEBUG", msg, isDebugEnabled)\r
614                 }\r
615                 utils.log("DEBUG"," *** Exit preProcessRollback of CreateVcpeResCustService *** ", isDebugEnabled)\r
616         }\r
617 \r
618         public void postProcessRollback (Execution execution) {\r
619                 def isDebugEnabled=execution.getVariable(DebugFlag)\r
620                 utils.log("DEBUG"," ***** postProcessRollback of CreateVcpeResCustService ***** ", isDebugEnabled)\r
621                 String msg = ""\r
622                 try {\r
623                         Object workflowException = execution.getVariable("prevWorkflowException");\r
624                         if (workflowException instanceof WorkflowException) {\r
625                                 utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)\r
626                                 execution.setVariable("WorkflowException", workflowException);\r
627                         }\r
628                 } catch (BpmnError b) {\r
629                         utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)\r
630                         throw b;\r
631                 } catch(Exception ex) {\r
632                         msg = "Exception in postProcessRollback. " + ex.getMessage()\r
633                         utils.log("DEBUG", msg, isDebugEnabled)\r
634                 }\r
635                 utils.log("DEBUG"," *** Exit postProcessRollback of CreateVcpeResCustService *** ", isDebugEnabled)\r
636         }\r
637 \r
638         public void prepareFalloutRequest(Execution execution){\r
639                 def isDebugEnabled=execution.getVariable(DebugFlag)\r
640 \r
641                 utils.log("DEBUG", " *** STARTED CreateVcpeResCustService prepareFalloutRequest Process *** ", isDebugEnabled)\r
642 \r
643                 try {\r
644                         WorkflowException wfex = execution.getVariable("WorkflowException")\r
645                         utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)\r
646                         String requestInfo = execution.getVariable(Prefix+"requestInfo")\r
647                         utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)\r
648 \r
649                         //TODO. hmmm. there is no way to UPDATE error message.\r
650 //                      String errorMessage = wfex.getErrorMessage()\r
651 //                      boolean successIndicator = execution.getVariable("DCRESI_rolledBack")\r
652 //                      if (successIndicator){\r
653 //                              errorMessage = errorMessage + ". Rollback successful."\r
654 //                      } else {\r
655 //                              errorMessage = errorMessage + ". Rollback not completed."\r
656 //                      }\r
657 \r
658                         String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)\r
659 \r
660                         execution.setVariable(Prefix+"falloutRequest", falloutRequest)\r
661 \r
662                 } catch (Exception ex) {\r
663                         utils.log("DEBUG", "Error Occured in CreateVcpeResCustService prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)\r
664                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVcpeResCustService prepareFalloutRequest Process")\r
665                 }\r
666                 utils.log("DEBUG", "*** COMPLETED CreateVcpeResCustService prepareFalloutRequest Process ***", isDebugEnabled)\r
667         }\r
668 \r
669 \r
670         public void sendSyncError (Execution execution) {\r
671                 def isDebugEnabled=execution.getVariable(DebugFlag)\r
672                 execution.setVariable("prefix", Prefix)\r
673 \r
674                 utils.log("DEBUG", " ***** Inside sendSyncError() of CreateVcpeResCustService ***** ", isDebugEnabled)\r
675 \r
676                 try {\r
677                         String errorMessage = ""\r
678                         def wfe = execution.getVariable("WorkflowException")\r
679                         if (wfe instanceof WorkflowException) {\r
680                                 errorMessage = wfe.getErrorMessage()\r
681                         } else {\r
682                                 errorMessage = "Sending Sync Error."\r
683                         }\r
684 \r
685                         String buildworkflowException =\r
686                                 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">\r
687                                         <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>\r
688                                         <aetgt:ErrorCode>7000</aetgt:ErrorCode>\r
689                                    </aetgt:WorkflowException>"""\r
690 \r
691                         utils.logAudit(buildworkflowException)\r
692                         sendWorkflowResponse(execution, 500, buildworkflowException)\r
693                 } catch (Exception ex) {\r
694                         utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)\r
695                 }\r
696         }\r
697 \r
698         public void processJavaException(Execution execution){\r
699                 def isDebugEnabled=execution.getVariable(DebugFlag)\r
700                 execution.setVariable("prefix",Prefix)\r
701                 try{\r
702                         utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)\r
703                         utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)\r
704                         utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)\r
705                         execution.setVariable(Prefix+"unexpectedError", "Caught a Java Lang Exception")  // Adding this line temporarily until this flows error handling gets updated\r
706                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")\r
707                 }catch(BpmnError b){\r
708                         utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)\r
709                         throw b\r
710                 }catch(Exception e){\r
711                         utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)\r
712                         execution.setVariable(Prefix+"unexpectedError", "Exception in processJavaException method")  // Adding this line temporarily until this flows error handling gets updated\r
713                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")\r
714                 }\r
715                 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)\r
716         }\r
717 }\r