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