2d96ac771a0f8d265142785d67e78715461eae46
[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  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. \r
7  * ================================================================================\r
8  * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * you may not use this file except in compliance with the License.\r
10  * You may obtain a copy of the License at\r
11  * \r
12  *      http://www.apache.org/licenses/LICENSE-2.0\r
13  * \r
14  * Unless required by applicable law or agreed to in writing, software\r
15  * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * See the License for the specific language governing permissions and\r
18  * limitations under the License.\r
19  * ============LICENSE_END=========================================================\r
20  */\r
21 package org.openecomp.mso.bpmn.infrastructure.scripts;\r
22 \r
23 import static org.apache.commons.lang3.StringUtils.*;\r
24 \r
25 import org.apache.commons.lang3.*\r
26 import org.camunda.bpm.engine.delegate.BpmnError\r
27 import org.camunda.bpm.engine.delegate.DelegateExecution\r
28 import org.json.JSONArray;\r
29 import org.json.JSONObject;\r
30 import org.openecomp.mso.bpmn.common.scripts.AaiUtil\r
31 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor\r
32 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil\r
33 import org.openecomp.mso.bpmn.core.RollbackData\r
34 import org.openecomp.mso.bpmn.core.WorkflowException\r
35 import org.openecomp.mso.bpmn.core.json.JsonUtils\r
36 import org.springframework.web.util.UriUtils;\r
37 \r
38 import groovy.json.*\r
39 \r
40 /**\r
41  * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.\r
42  *\r
43  * Inputs:\r
44  * @param - msoRequestId\r
45  * @param - globalSubscriberId\r
46  * @param - subscriptionServiceType\r
47  * @param - serviceInstanceId\r
48  * @param - serviceInstanceName - O\r
49  * @param - serviceModelInfo\r
50  * @param - productFamilyId\r
51  * @param - disableRollback\r
52  * @param - failExists - TODO\r
53  * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)\r
54  * @param - sdncVersion ("1610")\r
55  * @param - serviceDecomposition - Decomposition for R1710 \r
56  * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)\r
57  *\r
58  * Outputs:\r
59  * @param - rollbackData (localRB->null)\r
60  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)\r
61  * @param - WorkflowException\r
62  * @param - serviceInstanceName - (GET from AAI if null in input)\r
63  *\r
64  */\r
65 public class DoCreateE2EServiceInstanceV2 extends AbstractServiceTaskProcessor {\r
66 \r
67         String Prefix="DCRESI_"\r
68         private static final String DebugFlag = "isDebugEnabled"\r
69         \r
70         ExceptionUtil exceptionUtil = new ExceptionUtil()\r
71         JsonUtils jsonUtil = new JsonUtils()\r
72 \r
73         public void preProcessRequest (DelegateExecution execution) {\r
74             //only for dug\r
75                 execution.setVariable("isDebugLogEnabled","true")\r
76                 execution.setVariable("unit_test", "true")\r
77                 execution.setVariable("skipVFC", "true")\r
78                 \r
79                 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'\r
80                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
81                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
82                 String msg = ""\r
83                 utils.log("INFO"," ***** Enter DoCreateE2EServiceInstanceV2 preProcessRequest *****",  isDebugEnabled)\r
84                 \r
85                 utils.log("INFO","  unit test : " + execution.getVariable("unit_test"),  isDebugEnabled)        \r
86 \r
87                 try {\r
88                         execution.setVariable("prefix", Prefix)\r
89                         //Inputs\r
90                         //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology\r
91                         String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId\r
92                         utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId,  isDebugEnabled)\r
93                         \r
94                         //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology\r
95                         String serviceType = execution.getVariable("serviceType")\r
96                         utils.log("INFO"," ***** serviceType *****" + serviceType,  isDebugEnabled)\r
97                         \r
98                         //requestDetails.requestParameters. for SDNC assignTopology\r
99                         String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId\r
100 \r
101                         if (isBlank(globalSubscriberId)) {\r
102                                 msg = "Input globalSubscriberId is null"\r
103                                 utils.log("INFO", msg, isDebugEnabled)\r
104                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
105                         }\r
106                         \r
107                         if (isBlank(serviceType)) {\r
108                                 msg = "Input serviceType is null"\r
109                                 utils.log("INFO", msg, isDebugEnabled)\r
110                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
111                         }\r
112                         \r
113                         if (productFamilyId == null) {\r
114                                 execution.setVariable("productFamilyId", "")\r
115                         }\r
116                         \r
117                         String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')\r
118                         if (isBlank(sdncCallbackUrl)) {\r
119                                 msg = "URN_mso_workflow_sdncadapter_callback is null"\r
120                                 utils.log("INFO", msg, isDebugEnabled)\r
121                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
122                         }\r
123                         execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)\r
124                         utils.log("INFO","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)\r
125 \r
126                         //requestDetails.modelInfo.for AAI PUT servieInstanceData                       \r
127                         //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData \r
128                         String serviceInstanceName = execution.getVariable("serviceInstanceName")\r
129                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
130                         String uuiRequest = execution.getVariable("uuiRequest")\r
131                         utils.log("INFO","uuiRequest: " + uuiRequest, isDebugEnabled)\r
132                         \r
133                         String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceDefId")\r
134                         utils.log("INFO","modelInvariantUuid: " + modelInvariantUuid, isDebugEnabled)\r
135                         \r
136                         String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.templateId")\r
137                         utils.log("INFO","modelUuid: " + modelUuid, isDebugEnabled)\r
138                         \r
139                         String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")\r
140                         utils.log("INFO","serviceModelName: " + serviceModelName, isDebugEnabled)\r
141                         execution.setVariable("serviceModelName", serviceModelName)\r
142                         \r
143             //aai serviceType and Role can be setted as fixed value now.\r
144                         String aaiServiceType = serviceType\r
145                         String aaiServiceRole = serviceType+"Role"\r
146                         \r
147                         execution.setVariable("modelInvariantUuid", modelInvariantUuid)\r
148                         execution.setVariable("modelUuid", modelUuid)\r
149 \r
150                         //AAI PUT\r
151                         String oStatus = execution.getVariable("initialStatus") ?: ""\r
152                         utils.log("INFO","oStatus: " + oStatus, isDebugEnabled)\r
153                         if ("TRANSPORT".equalsIgnoreCase(serviceType))\r
154                         {\r
155                                 oStatus = "Created"\r
156                         }\r
157                         \r
158                         \r
159 \r
160                         String statusLine = isBlank(oStatus) ? "" : "<orchestration-status>${oStatus}</orchestration-status>"\r
161                         utils.log("INFO","statusLine: " + statusLine, isDebugEnabled)   \r
162                         AaiUtil aaiUriUtil = new AaiUtil(this)\r
163                         utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled) \r
164                         String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)\r
165                         utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled)\r
166                         String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)\r
167                         utils.log("INFO","namespace: " + namespace, isDebugEnabled)\r
168                         /*\r
169                         String serviceInstanceData =\r
170                                         """<service-instance xmlns=\"${namespace}\">\r
171                                 <service-instance-id>${serviceInstanceId}</service-instance-id>\r
172                                 <service-instance-name>${serviceInstanceName}</service-instance-name>\r
173                                         <service-type>${aaiServiceType}</service-type>\r
174                                         <service-role>${aaiServiceRole}</service-role>\r
175                                         ${statusLine}\r
176                                     <model-invariant-id>${modelInvariantUuid}</model-invariant-id>\r
177                                     <model-version-id>${modelUuid}</model-version-id>\r
178                                         </service-instance>""".trim()\r
179             */\r
180             //begin only for test\r
181                         String serviceInstanceData =\r
182                                         """<service-instance xmlns=\"${namespace}\">\r
183                                 <service-instance-id>${serviceInstanceId}</service-instance-id>\r
184                                 <service-instance-name>${serviceInstanceName}</service-instance-name>\r
185                                         <service-type>${aaiServiceType}</service-type>\r
186                                         <service-role>${aaiServiceRole}</service-role>\r
187                                         ${statusLine}\r
188                                         </service-instance>""".trim()\r
189                         //end only for test\r
190                         execution.setVariable("serviceInstanceData", serviceInstanceData)\r
191                         utils.log("INFO","serviceInstanceData: " + serviceInstanceData, isDebugEnabled)\r
192                         utils.logAudit(serviceInstanceData)\r
193                         utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)\r
194                         utils.log("INFO", " 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)\r
195                         \r
196                         execution.setVariable("serviceSDNCCreate", "false")\r
197                         execution.setVariable("operationStatus", "Waiting deploy resource...")                  \r
198 \r
199                 } catch (BpmnError e) {\r
200                         throw e;\r
201                 } catch (Exception ex){\r
202                         msg = "Exception in preProcessRequest " + ex.getMessage()\r
203                         utils.log("INFO", msg, isDebugEnabled)\r
204                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
205                 }\r
206                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
207         }\r
208 \r
209         public void postProcessAAIGET(DelegateExecution execution) {\r
210                 def method = getClass().getSimpleName() + '.postProcessAAIGET(' +'execution=' + execution.getId() +')'\r
211                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
212                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
213                 utils.log("INFO"," ***** Enter DoCreateE2EServiceInstanceV2 postProcessAAIGET ***** ", isDebugEnabled)\r
214                 String msg = ""\r
215 \r
216                 try {\r
217                         String serviceInstanceName = execution.getVariable("serviceInstanceName")\r
218                         boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")\r
219                         if(!succInAAI){\r
220                                 utils.log("INFO","Error getting Service-instance from AAI", + serviceInstanceName, isDebugEnabled)\r
221                                 WorkflowException workflowException = execution.getVariable("WorkflowException")\r
222                                 utils.logAudit("workflowException: " + workflowException)\r
223                                 if(workflowException != null){\r
224                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())\r
225                                 }\r
226                                 else\r
227                                 {\r
228                                         msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI\r
229                                         utils.log("INFO", msg, isDebugEnabled)\r
230                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)\r
231                                 }\r
232                         }\r
233                         else\r
234                         {\r
235                                 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")\r
236                                 if(foundInAAI){\r
237                                         utils.log("INFO","Found Service-instance in AAI", isDebugEnabled)\r
238                                         msg = "ServiceInstance already exists in AAI:" + serviceInstanceName\r
239                                         utils.log("INFO", msg, isDebugEnabled)\r
240                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)\r
241                                 }\r
242                         }\r
243                 } catch (BpmnError e) {\r
244                         throw e;\r
245                 } catch (Exception ex) {\r
246                         msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()\r
247                         utils.log("INFO", msg, isDebugEnabled)\r
248                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
249                 }\r
250                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
251         }\r
252 \r
253         public void postProcessAAIPUT(DelegateExecution execution) {\r
254                 def method = getClass().getSimpleName() + '.postProcessAAIPUT(' +'execution=' + execution.getId() +')'\r
255                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
256                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
257                 utils.log("INFO"," ***** Enter DoCreateE2EServiceInstanceV2 postProcessAAIPUT ***** ", isDebugEnabled)\r
258                 String msg = ""\r
259                 try {\r
260                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
261                         boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")\r
262                         if(!succInAAI){\r
263                                 utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)\r
264                                 WorkflowException workflowException = execution.getVariable("WorkflowException")\r
265                                 utils.logAudit("workflowException: " + workflowException)\r
266                                 if(workflowException != null){\r
267                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())\r
268                                 }\r
269                         }\r
270                         else\r
271                         {\r
272                                 //start rollback set up\r
273                                 RollbackData rollbackData = new RollbackData()\r
274                                 def disableRollback = execution.getVariable("disableRollback")\r
275                                 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())\r
276                                 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")\r
277                                 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)\r
278                                 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))\r
279                                 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))\r
280                                 execution.setVariable("rollbackData", rollbackData)\r
281                         }\r
282 \r
283                 } catch (BpmnError e) {\r
284                         throw e;\r
285                 } catch (Exception ex) {\r
286                         msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()\r
287                         utils.log("INFO", msg, isDebugEnabled)\r
288                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
289                 }\r
290                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
291         }\r
292         \r
293         public void postProcessAAIGET2(DelegateExecution execution) {\r
294                 def method = getClass().getSimpleName() + '.postProcessAAIGET2(' +'execution=' + execution.getId() +')'\r
295                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
296                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
297                 utils.log("INFO"," ***** Enter DoCreateE2EServiceInstanceV2 postProcessAAIGET2 ***** ", isDebugEnabled)\r
298                 String msg = ""\r
299 \r
300                 try {\r
301                         String serviceInstanceName = execution.getVariable("serviceInstanceName")\r
302                         boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")\r
303                         if(!succInAAI){\r
304                                 utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName, isDebugEnabled)\r
305                                 WorkflowException workflowException = execution.getVariable("WorkflowException")\r
306                                 utils.logAudit("workflowException: " + workflowException)\r
307                                 if(workflowException != null){\r
308                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())\r
309                                 }\r
310                                 else\r
311                                 {\r
312                                         msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI\r
313                                         utils.log("INFO", msg, isDebugEnabled)\r
314                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)\r
315                                 }\r
316                         }\r
317                         else\r
318                         {\r
319                                 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")\r
320                                 if(foundInAAI){\r
321                                         String aaiService = execution.getVariable("GENGS_service")\r
322                                         if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {\r
323                                                 execution.setVariable("serviceInstanceName",  utils.getNodeText1(aaiService, "service-instance-name"))\r
324                                                 utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)\r
325                                         }\r
326                                 }\r
327                         }\r
328                 } catch (BpmnError e) {\r
329                         throw e;\r
330                 } catch (Exception ex) {\r
331                         msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()\r
332                         utils.log("INFO", msg, isDebugEnabled)\r
333                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
334                 }\r
335                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
336         }\r
337 \r
338         public void preProcessRollback (DelegateExecution execution) {\r
339                 def method = getClass().getSimpleName() + '.preProcessRollback(' +'execution=' + execution.getId() +')'\r
340                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
341                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
342                 utils.log("INFO"," ***** Enter DoCreateE2EServiceInstanceV2 preProcessRollback ***** ", isDebugEnabled)\r
343                 try {\r
344                         \r
345                         Object workflowException = execution.getVariable("WorkflowException");\r
346 \r
347                         if (workflowException instanceof WorkflowException) {\r
348                                 utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)\r
349                                 execution.setVariable("prevWorkflowException", workflowException);\r
350                                 //execution.setVariable("WorkflowException", null);\r
351                         }\r
352                 } catch (BpmnError e) {\r
353                         utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)\r
354                 } catch(Exception ex) {\r
355                         String msg = "Exception in preProcessRollback. " + ex.getMessage()\r
356                         utils.log("INFO", msg, isDebugEnabled)\r
357                 }\r
358                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
359         }\r
360 \r
361         public void postProcessRollback (DelegateExecution execution) {\r
362                 def method = getClass().getSimpleName() + '.postProcessRollback(' +'execution=' + execution.getId() +')'\r
363                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
364                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
365                 utils.log("INFO"," ***** Enter DoCreateE2EServiceInstanceV2 postProcessRollback ***** ", isDebugEnabled)\r
366                 String msg = ""\r
367                 try {\r
368                         Object workflowException = execution.getVariable("prevWorkflowException");\r
369                         if (workflowException instanceof WorkflowException) {\r
370                                 utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)\r
371                                 execution.setVariable("WorkflowException", workflowException);\r
372                         }\r
373                         execution.setVariable("rollbackData", null)\r
374                 } catch (BpmnError b) {\r
375                         utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)\r
376                         throw b;\r
377                 } catch(Exception ex) {\r
378                         msg = "Exception in postProcessRollback. " + ex.getMessage()\r
379                         utils.log("INFO", msg, isDebugEnabled)\r
380                 }\r
381                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
382         }\r
383         \r
384         /**\r
385          * Init the service Operation Status\r
386          */\r
387         public void preUpdateServiceOperationStatus(DelegateExecution execution){\r
388         def method = getClass().getSimpleName() + '.preUpdateServiceOperationStatus(' +'execution=' + execution.getId() +')'\r
389                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
390                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
391         \r
392         try{\r
393             String serviceId = execution.getVariable("serviceInstanceId")\r
394             String operationId = execution.getVariable("operationId")\r
395             String serviceName = execution.getVariable("serviceInstanceName")\r
396             String operationType = "CREATE"\r
397             String userId = ""\r
398             String result = "processing"\r
399             String progress = execution.getVariable("progress")\r
400                         utils.log("INFO", "progress: " + progress , isDebugEnabled)\r
401                         if ("100".equalsIgnoreCase(progress))\r
402                         {\r
403                                 result = "finished"\r
404                         }\r
405             String reason = ""\r
406             String operationContent = "Prepare service creation : " + execution.getVariable("operationStatus")\r
407                         \r
408             utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)\r
409             serviceId = UriUtils.encode(serviceId,"UTF-8")\r
410             execution.setVariable("serviceInstanceId", serviceId)\r
411             execution.setVariable("operationId", operationId)\r
412             execution.setVariable("operationType", operationType)\r
413 \r
414             def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"\r
415             execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)\r
416             utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)\r
417 \r
418             execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")\r
419                         String payload =\r
420                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
421                         xmlns:ns="http://org.openecomp.mso/requestsdb">\r
422                         <soapenv:Header/>\r
423                         <soapenv:Body>\r
424                             <ns:updateServiceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">\r
425                             <serviceId>${serviceId}</serviceId>\r
426                             <operationId>${operationId}</operationId>\r
427                             <serviceName>${serviceName}</serviceName>\r
428                             <operationType>${operationType}</operationType>\r
429                             <userId>${userId}</userId>\r
430                             <result>${result}</result>\r
431                             <operationContent>${operationContent}</operationContent>\r
432                             <progress>${progress}</progress>\r
433                             <reason>${reason}</reason>\r
434                         </ns:updateServiceOperationStatus>\r
435                     </soapenv:Body>\r
436                 </soapenv:Envelope>"""\r
437 \r
438             payload = utils.formatXml(payload)\r
439             execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)\r
440             utils.log("INFO", "Outgoing preUpdateServiceOperationStatus: \n" + payload, isDebugEnabled)\r
441            \r
442 \r
443         }catch(Exception e){\r
444             utils.log("ERROR", "Exception Occured Processing preUpdateServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)\r
445             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preUpdateServiceOperationStatus Method:\n" + e.getMessage())\r
446         }\r
447         utils.log("INFO", "======== COMPLETED preUpdateServiceOperationStatus Process ======== ", isDebugEnabled)  \r
448         utils.log("INFO", "Exited " + method, isDebugEnabled)\r
449         }\r
450         \r
451 \r
452         public void preInitResourcesOperStatus(DelegateExecution execution){\r
453         def method = getClass().getSimpleName() + '.preInitResourcesOperStatus(' +'execution=' + execution.getId() +')'\r
454                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
455                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
456 \r
457         utils.log("INFO", " ======== Enter DoCreateE2EServiceInstanceV2 preInitResourcesOperStatus Process ======== ", isDebugEnabled)\r
458         try{\r
459             String serviceId = execution.getVariable("serviceInstanceId")\r
460             String operationId = execution.getVariable("operationId")\r
461             String operationType = execution.getVariable("operationType")\r
462             String resourceTemplateUUIDs = ""\r
463             String result = "processing"\r
464             String progress = "0"\r
465             String reason = ""\r
466             String operationContent = "Prepare service creation"\r
467             utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)\r
468             serviceId = UriUtils.encode(serviceId,"UTF-8")\r
469             execution.setVariable("serviceInstanceId", serviceId)\r
470             execution.setVariable("operationId", operationId)\r
471             execution.setVariable("operationType", operationType)\r
472             String incomingRequest = execution.getVariable("uuiRequest")\r
473             String resourcesStr = jsonUtil.getJsonValue(incomingRequest, "service.parameters.resources")  \r
474             List<String> resourceList = jsonUtil.StringArrayToList(execution, resourcesStr)   \r
475             for(String resource : resourceList){\r
476                     resourceTemplateUUIDs  = resourceTemplateUUIDs + jsonUtil.getJsonValue(resource, "resourceId") + ":"\r
477             }           \r
478 \r
479             def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"\r
480             execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)\r
481             utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)\r
482 \r
483             String payload =\r
484                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
485                         xmlns:ns="http://org.openecomp.mso/requestsdb">\r
486                         <soapenv:Header/>\r
487                         <soapenv:Body>\r
488                             <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">\r
489                             <serviceId>${serviceId}</serviceId>\r
490                             <operationId>${operationId}</operationId>\r
491                             <operationType>${operationType}</operationType>\r
492                             <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>\r
493                         </ns:initResourceOperationStatus>\r
494                     </soapenv:Body>\r
495                 </soapenv:Envelope>"""\r
496 \r
497             payload = utils.formatXml(payload)\r
498             execution.setVariable("CVFMI_initResOperStatusRequest", payload)\r
499             utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)\r
500             utils.logAudit("DoCustomDeleteE2EServiceInstanceV2 Outgoing initResourceOperationStatus Request: " + payload)\r
501 \r
502         }catch(Exception e){\r
503             utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)\r
504             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())\r
505         }\r
506         utils.log("INFO", "Exited " + method, isDebugEnabled)\r
507         }\r
508         \r
509         /**\r
510          * prepare resource create request\r
511          */\r
512         public void preResourceRequest(execution){\r
513             def method = getClass().getSimpleName() + '.preResourceRequest(' +'execution=' + execution.getId() +')'\r
514                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
515                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
516                 \r
517         utils.log("INFO", " ======== Enter DoCreateE2EServiceInstanceV2 preResourceRequest Process ======== ", isDebugEnabled)\r
518                 try {\r
519                         String resourceType = execution.getVariable("resourceType")\r
520                 String serviceInstanceName = execution.getVariable("serviceInstanceName")\r
521                 String nsServiceName = resourceType + "_" + serviceInstanceName\r
522                 execution.setVariable("nsServiceName", nsServiceName)\r
523                 utils.log("INFO", "Prepare VFC Request nsServiceName:" + nsServiceName, isDebugEnabled)\r
524                 String globalSubscriberId = execution.getVariable("globalSubscriberId")\r
525                 String serviceType = execution.getVariable("serviceType")\r
526                 String serviceId = execution.getVariable("serviceInstanceId")\r
527                 execution.setVariable("serviceId", serviceId)\r
528                 String operationId = execution.getVariable("operationId")\r
529                 String incomingRequest = execution.getVariable("uuiRequest")\r
530                 String resourcesStr = jsonUtil.getJsonValue(incomingRequest, "service.parameters.resources")  \r
531                 String nsServiceDescription = jsonUtil.getJsonValue(incomingRequest, "service.description")  \r
532                 execution.setVariable("nsServiceDescription", nsServiceDescription)\r
533                 utils.log("INFO", "Prepare VFC Request nsServiceDescription:" + nsServiceDescription, isDebugEnabled)\r
534                 List<String> resourceList = jsonUtil.StringArrayToList(execution, resourcesStr)   \r
535                 for(String resource : resourceList){\r
536                 String resourceName = jsonUtil.getJsonValue(resource, "resourceName")  \r
537                 if(StringUtils.containsIgnoreCase(resourceName, resourceType)){\r
538                         String resourceUUID  = jsonUtil.getJsonValue(resource, "resourceId")\r
539                         String resourceInvariantUUID  = jsonUtil.getJsonValue(resource, "resourceDefId")\r
540                         String resourceParameters = jsonUtil.getJsonValue(resource, "nsParameters")                \r
541                         execution.setVariable("resourceUUID", resourceUUID)\r
542                         execution.setVariable("resourceInvariantUUID", resourceInvariantUUID)\r
543                         execution.setVariable("resourceParameters", resourceParameters)\r
544                         utils.log("INFO", "Prepare VFC Request resourceType:" + resourceType, isDebugEnabled)\r
545                         utils.log("INFO", "Prepare VFC Request resourceUUID:" + resourceUUID, isDebugEnabled)\r
546                         utils.log("INFO", "Prepare VFC Request resourceParameters:" + resourceParameters, isDebugEnabled)\r
547                 } \r
548                 }\r
549                 } catch (BpmnError b) {\r
550                         utils.log("INFO", "BPMN Error during preResourceRequest", isDebugEnabled)\r
551                         throw b;\r
552                 } catch(Exception ex) {\r
553                         msg = "Exception in preResourceRequest. " + ex.getMessage()\r
554                         utils.log("INFO", msg, isDebugEnabled)\r
555                 }\r
556            utils.log("INFO", "Exited " + method, isDebugEnabled)\r
557         }\r
558         \r
559          /**\r
560      * post config request.\r
561      */\r
562         public void postConfigRequest(execution){\r
563             //now do noting\r
564         }\r
565         \r
566     /***********************************************************************************************/\r
567 \r
568         private void loadResourcesProperties(DelegateExecution execution) {\r
569                 def method = getClass().getSimpleName() + '.loadResourcesProperties(' +'execution=' + execution.getId() +')'\r
570                 def isDebugEnabled = execution.getVariable("isDebugEnabled")\r
571                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
572                 String loadFilePath = "/etc/mso/config.d/reources.json"\r
573                 try{\r
574                         def jsonPayload = new File(loadFilePath).text\r
575                         utils.log("INFO","jsonPayload: " + jsonPayload, isDebugEnabled)\r
576 \r
577                         String resourcesProperties = jsonUtil.prettyJson(jsonPayload.toString())\r
578                         utils.log("INFO","resourcesProperties: " + resourcesProperties, isDebugEnabled)\r
579                         \r
580                         String createResourceSort = jsonUtil.getJsonValue(resourcesProperties, "CreateResourceSort")\r
581                         //utils.log("INFO","createResourceSort: " + createResourceSort, isDebugEnabled)\r
582                         execution.setVariable("createResourceSort", createResourceSort)\r
583                         \r
584                         String deleteResourceSort = jsonUtil.getJsonValue(resourcesProperties, "DeleteResourceSort")\r
585                         //utils.log("INFO","deleteResourceSort: " + deleteResourceSort, isDebugEnabled)\r
586                         execution.setVariable("deleteResourceSort", deleteResourceSort)\r
587                         \r
588                         \r
589                         String resourceControllerType = jsonUtil.getJsonValue(resourcesProperties, "ResourceControllerType")\r
590                         //utils.log("INFO","resourceControllerType: " + resourceControllerType, isDebugEnabled)\r
591                         execution.setVariable("resourceControllerType", resourceControllerType)                 \r
592                         \r
593                         \r
594                 }catch(Exception ex){\r
595             // try error in method block\r
596                         String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()\r
597                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
598                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
599         }\r
600             utils.log("INFO", "Exited " + method, isDebugEnabled)\r
601         }\r
602         private sortCreateResource(DelegateExecution execution) {\r
603                 def method = getClass().getSimpleName() + '.sortCreateResource(' +'execution=' + execution.getId() +')'\r
604                 def isDebugEnabled = execution.getVariable("isDebugEnabled")\r
605                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
606                 String createResourceSortDef = """[\r
607                 {\r
608                     "resourceType":"vEPC"\r
609                 },\r
610                 {\r
611                     "resourceType":"vIMS"\r
612                 },\r
613                 {\r
614                     "resourceType":"vCPE"\r
615                 },\r
616                 {\r
617                     "resourceType":"vFW"\r
618                 },\r
619                                 {\r
620                     "resourceType":"Underlay"\r
621                 },\r
622                 {\r
623                     "resourceType":"Overlay"\r
624                 },\r
625                                 {\r
626                     "resourceType":"GRE_AAR"\r
627                 },\r
628                 {\r
629                     "resourceType":"APN_AAR"\r
630                 },\r
631                 {\r
632                     "resourceType":"VPN_SAR"\r
633                 },\r
634                 {\r
635                     "resourceType":"GRE_SAR"\r
636                 }             \r
637                 \r
638             ]""".trim()\r
639                 \r
640         try{\r
641 \r
642                         loadResourcesProperties(execution)\r
643                         String createResourceSort = execution.getVariable("createResourceSort")\r
644                         if (isBlank(createResourceSort)) {\r
645                                 createResourceSort = createResourceSortDef;\r
646                         }\r
647                         \r
648                         List<String> sortResourceList = jsonUtil.StringArrayToList(execution, createResourceSort)\r
649                 utils.log("INFO", "sortResourceList : " + sortResourceList, isDebugEnabled)              \r
650 \r
651                         JSONArray newResourceList      = new JSONArray()\r
652                         int resSortCount = sortResourceList.size()\r
653   \r
654                         \r
655                         for ( int currentResource = 0 ; currentResource < resSortCount ; currentResource++ ) { \r
656                                 String sortResource = sortResourceList[currentResource]\r
657                                 String resourceType = jsonUtil.getJsonValue(sortResource, "resourceType")                               \r
658                                 List<String> resourceList = execution.getVariable(Prefix+"resourceList")\r
659 \r
660                                 for (String resource : resourceList) {\r
661                                         //utils.log("INFO", "resource : " + resource, isDebugEnabled)\r
662                                         String resourceName = jsonUtil.getJsonValue(resource, "resourceName")\r
663                                         //utils.log("INFO", "resource Name : " + resourceName, isDebugEnabled)\r
664                                         String[] split = resourceName.split("_")\r
665                                         \r
666                                         utils.log("INFO", "split : " + split, isDebugEnabled)\r
667                                         int strLen = split.size()\r
668                                         String allottedResourceType = ""\r
669                         \r
670                                         if (strLen <2) {\r
671                                                 allottedResourceType = split[0]\r
672                                         }\r
673                                         else {\r
674                                                 allottedResourceType = split[0] + "_" + split[1]\r
675                                         }\r
676                         \r
677                                         if (StringUtils.containsIgnoreCase(allottedResourceType, resourceType)) {\r
678                                                 utils.log("INFO", "allottedResourceType : " + allottedResourceType + " resourceType : " + resourceType, isDebugEnabled)\r
679                                                 utils.log("INFO", "resource : " + resource , isDebugEnabled)\r
680                                                 JSONObject jsonObj = new JSONObject(resource)\r
681                                                 newResourceList.put(jsonObj)\r
682                                                 \r
683                                         }\r
684                                         utils.log("INFO", "Get next sort type " , isDebugEnabled)\r
685                                 }\r
686                         } \r
687                         utils.log("INFO", "newResourceList : " + newResourceList, isDebugEnabled)\r
688             String newResourceStr = newResourceList.toString()          \r
689             List<String> newResourceListStr = jsonUtil.StringArrayToList(execution, newResourceStr)                     \r
690                 \r
691                         execution.setVariable(Prefix+"resourceList", newResourceListStr)\r
692                         utils.log("INFO", "newResourceList : " + newResourceListStr, isDebugEnabled) \r
693                         \r
694                 }catch(Exception ex){\r
695             // try error in method block\r
696                         String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()\r
697                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
698                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
699         }\r
700             utils.log("INFO", "Exited " + method, isDebugEnabled)\r
701                 \r
702         }\r
703         /**\r
704          * get service resources\r
705          */\r
706         public void getServiceResources(DelegateExecution execution){\r
707         def method = getClass().getSimpleName() + '.getServiceResources(' +'execution=' + execution.getId() +')'\r
708                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
709                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
710         utils.log("INFO", " ======== Enter DoCreateE2EServiceInstanceV2 getServiceResources Process ======== ", isDebugEnabled)\r
711         try{\r
712             execution.setVariable(Prefix+"resourceCount", 0)\r
713                         execution.setVariable(Prefix+"nextResource", 0)\r
714 \r
715                         String incomingRequest = execution.getVariable("uuiRequest")\r
716             String resourcesStr = jsonUtil.getJsonValue(incomingRequest, "service.parameters.resources")  \r
717             utils.log("INFO", "Resources String : " + resourcesStr, isDebugEnabled)\r
718                         if (!isBlank(resourcesStr)) {\r
719                                 List<String> resourceList = jsonUtil.StringArrayToList(execution, resourcesStr)   \r
720                 utils.log("INFO", "Resource List : " + resourceList, isDebugEnabled)\r
721                                 execution.setVariable(Prefix+"resourceList", resourceList)\r
722                                 execution.setVariable(Prefix+"resourceCount", resourceList.size())\r
723                                 execution.setVariable(Prefix+"nextResource", 0)\r
724                         }\r
725                         \r
726                         int resourceNum = execution.getVariable(Prefix+"nextResource")\r
727                         utils.log("DEBUG", "Current Resource count:"+ execution.getVariable(Prefix+"nextResource"), isDebugEnabled)\r
728                         \r
729                         int resourceCount = execution.getVariable(Prefix+"resourceCount")\r
730                         utils.log("DEBUG", "Total Resource count:"+ execution.getVariable(Prefix+"resourceCount"), isDebugEnabled)\r
731 \r
732             if (resourceNum < resourceCount) {\r
733                                 execution.setVariable(Prefix+"resourceFinish", false)\r
734                         }\r
735                         else {\r
736                             execution.setVariable(Prefix+"resourceFinish", true)\r
737                         }\r
738                         sortCreateResource(execution)\r
739 \r
740         }catch(Exception e){\r
741             utils.log("ERROR", "Exception Occured Processing getServiceResources. Exception is:\n" + e, isDebugEnabled)\r
742             execution.setVariable(Prefix+"ErrorResponse", "Error Occurred during getServiceResources Method:\n" + e.getMessage())\r
743         }\r
744             utils.log("INFO", "Exited " + method, isDebugEnabled)  \r
745         }\r
746         \r
747         /**\r
748          * prepare Decompose next resource to create request\r
749          */\r
750         public void preProcessDecomposeNextResource(DelegateExecution execution){\r
751         def method = getClass().getSimpleName() + '.preProcessDecomposeNextResource(' +'execution=' + execution.getId() +')'\r
752                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
753                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
754         utils.log("INFO", " ======== Enter DoCreateE2EServiceInstanceV2 preProcessDecomposeNextResource Process ======== ", isDebugEnabled)\r
755         try{\r
756             int resourceNum = execution.getVariable(Prefix+"nextResource")\r
757                         List<String> resourceList = execution.getVariable(Prefix+"resourceList")\r
758                         utils.log("INFO", "Resource List : " + resourceList, isDebugEnabled)\r
759                         \r
760                         String resource = resourceList[resourceNum]\r
761             execution.setVariable(Prefix+"resource", resource)\r
762                         utils.log("INFO", "Current Resource : " + resource, isDebugEnabled)\r
763 \r
764             String resourceName = jsonUtil.getJsonValue(resource, "resourceName")  \r
765                         execution.setVariable(Prefix+"resourceName", resourceName)\r
766                         utils.log("INFO", "resource Name : " + resourceName, isDebugEnabled)\r
767                         \r
768             String resourceUUID  = jsonUtil.getJsonValue(resource, "resourceId")\r
769                         execution.setVariable("resourceUUID", resourceUUID)\r
770                         utils.log("INFO", "resource UUID : " + resourceUUID, isDebugEnabled)\r
771                         \r
772             String resourceInvariantUUID  = jsonUtil.getJsonValue(resource, "resourceDefId")\r
773                         execution.setVariable("resourceInvariantUUID", resourceInvariantUUID)\r
774                         \r
775                         \r
776             String resourceParameters = jsonUtil.getJsonValue(resource, "nsParameters")             \r
777             execution.setVariable("resourceParameters", resourceParameters)\r
778                         utils.log("INFO", "resource Parameters : " + resourceParameters, isDebugEnabled)\r
779 \r
780                         execution.setVariable(Prefix+"nextResource", resourceNum + 1)\r
781                         utils.log("INFO", "next Resource num : " + execution.getVariable(Prefix+"nextResource"), isDebugEnabled)\r
782                         \r
783                         int resourceCount = execution.getVariable(Prefix+"resourceCount")\r
784                         if (resourceCount >0 ){\r
785                             int progress = (resourceNum*100) / resourceCount\r
786                                 execution.setVariable("progress", progress.toString() )\r
787                         }\r
788                         \r
789                         execution.setVariable("operationStatus", resourceName )\r
790 \r
791         }catch(Exception e){\r
792             utils.log("ERROR", "Exception Occured Processing preProcessDecomposeNextResource. Exception is:\n" + e, isDebugEnabled)\r
793             execution.setVariable(Prefix+"ErrorResponse", "Error Occurred during preProcessDecomposeNextResource Method:\n" + e.getMessage())\r
794         }\r
795             utils.log("INFO", "Exited " + method, isDebugEnabled)   \r
796         }\r
797         /**\r
798          * post Decompose next resource to create request\r
799          */\r
800         public void postProcessDecomposeNextResource(DelegateExecution execution){\r
801         def method = getClass().getSimpleName() + '.postProcessDecomposeNextResource(' +'execution=' + execution.getId() +')'\r
802                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
803                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
804         utils.log("INFO", " ======== STARTED DoCreateE2EServiceInstanceV2 postProcessDecomposeNextResource Process ======== ", isDebugEnabled)\r
805         try{\r
806             String resourceName = execution.getVariable(Prefix+"resourceName")\r
807                         \r
808                         int resourceNum = execution.getVariable(Prefix+"nextResource")\r
809                         utils.log("DEBUG", "Current Resource count:"+ execution.getVariable(Prefix+"nextResource"), isDebugEnabled)\r
810                         \r
811                         int resourceCount = execution.getVariable(Prefix+"resourceCount")\r
812                         utils.log("DEBUG", "Total Resource count:"+ execution.getVariable(Prefix+"resourceCount"), isDebugEnabled)\r
813 \r
814             if (resourceNum < resourceCount) {\r
815                                 execution.setVariable(Prefix+"resourceFinish", false)\r
816                         }\r
817                         else {\r
818                             execution.setVariable(Prefix+"resourceFinish", true)\r
819                         }\r
820                         \r
821                         utils.log("DEBUG", "Resource Finished:"+ execution.getVariable(Prefix+"resourceFinish"), isDebugEnabled)\r
822                         \r
823                         if (resourceCount >0 ){\r
824                             int progress = (resourceNum*100) / resourceCount\r
825                                 execution.setVariable("progress", progress.toString() )\r
826                                 utils.log("DEBUG", "progress :"+ execution.getVariable("progress"), isDebugEnabled)\r
827                         }\r
828                         execution.setVariable("operationStatus", resourceName )\r
829 \r
830         }catch(Exception e){\r
831             // try error in method block\r
832                         String exceptionMessage = "Bpmn error encountered in "+method + "- " + e.getMessage()\r
833                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
834                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
835         }\r
836             utils.log("INFO", "Exited " + method, isDebugEnabled)  \r
837         }\r
838         /**\r
839         * prepare check Resource Type \r
840         */\r
841         public void checkResourceType(DelegateExecution execution){\r
842         def method = getClass().getSimpleName() + '.checkResourceType(' +'execution=' + execution.getId() +')'\r
843                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
844                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
845                 String resourceControllerTypeDef = """[\r
846                 {\r
847                     "resourceType":"vEPC",\r
848                     "controllerType":"VFC"\r
849                 },\r
850                 {\r
851                     "resourceType":"vIMS",\r
852                     "controllerType":"VFC"\r
853                 },\r
854                 {\r
855                     "resourceType":"vCPE",\r
856                     "controllerType":"VFC"\r
857                 },\r
858                 {\r
859                     "resourceType":"vFW",\r
860                     "controllerType":"VFC"\r
861                 },\r
862                 {\r
863                     "resourceType":"Underlay",\r
864                     "controllerType":"SDNC"\r
865                 },\r
866                 {\r
867                     "resourceType":"Overlay",\r
868                     "controllerType":"SDNC"\r
869                 },\r
870                 {\r
871                     "resourceType":"VPN_SAR",\r
872                     "controllerType":"SDNC"\r
873                 },\r
874                 {\r
875                     "resourceType":"GRE_AAR",\r
876                     "controllerType":"APPC"\r
877                 },\r
878                 {\r
879                     "resourceType":"GRE_SAR",\r
880                     "controllerType":"SDNC"\r
881                 }  ,\r
882                 {\r
883                     "resourceType":"APN_AAR",\r
884                     "controllerType":"APPC"\r
885                 }               \r
886                 \r
887             ]""".trim()\r
888 \r
889         try{\r
890 \r
891             String resourceName = execution.getVariable(Prefix+"resourceName") \r
892                         utils.log("INFO", "resourceName : " + resourceName, isDebugEnabled)\r
893                         execution.setVariable("resourceName", resourceName)\r
894                         \r
895                         String[] split = resourceName.split("_")\r
896                         \r
897                         utils.log("INFO", "split : " + split, isDebugEnabled)\r
898                         int strLen = split.size()\r
899                         String allottedResourceType = ""\r
900                         \r
901                         if (strLen <2) {\r
902                                 allottedResourceType = split[0]\r
903                         }\r
904                         else {\r
905                                 allottedResourceType = split[0] + "_" + split[1]\r
906                         }\r
907 \r
908                         loadResourcesProperties(execution)\r
909                         String resourceControllerType= execution.getVariable("resourceControllerType") \r
910                         if (isBlank(resourceControllerType)) {\r
911                                 resourceControllerType = resourceControllerTypeDef;\r
912                         }\r
913                         utils.log("INFO", "resourceControllerType: " + resourceControllerType, isDebugEnabled)\r
914                 \r
915                         List<String> ResourceTypeList = jsonUtil.StringArrayToList(execution, resourceControllerType)\r
916                 utils.log("INFO", "ResourceTypeList : " + ResourceTypeList, isDebugEnabled)              \r
917                         execution.setVariable("controllerType", "Other") \r
918                         execution.setVariable(Prefix+"resourceType", "")\r
919                         for (String resourceMap : ResourceTypeList) {\r
920                                 String resourceType = jsonUtil.getJsonValue(resourceMap, "resourceType")                                \r
921                                 String controllerType = jsonUtil.getJsonValue(resourceMap, "controllerType")\r
922                                 //utils.log("INFO", "resourceMap.resourceType   : " + resourceType, isDebugEnabled)\r
923                                 //utils.log("INFO", "resourceMap.controllerType : " + controllerType, isDebugEnabled)\r
924                                 //utils.log("INFO", "resourceName               : " + resourceName, isDebugEnabled)\r
925                                 //utils.log("INFO", "allottedResourceType       : " + allottedResourceType, isDebugEnabled )\r
926                                 \r
927                                 if (StringUtils.containsIgnoreCase(allottedResourceType, resourceType)) {\r
928                                         execution.setVariable("controllerType", controllerType)\r
929                                         execution.setVariable(Prefix+"resourceType", resourceType)\r
930                                         utils.log("INFO", "found controller type : " + controllerType, isDebugEnabled)\r
931                                         break\r
932                                 }\r
933                         }\r
934                         utils.log("INFO", "controller Type : " + execution.getVariable("controllerType"), isDebugEnabled)\r
935                         utils.log("INFO", "resource Type : " + execution.getVariable(Prefix+"resourceType"), isDebugEnabled)\r
936                         \r
937                         if (execution.getVariable("controllerType") == "") {\r
938                                 String exceptionMessage = "Resource name can not find controller type,please check the resource Name: "+ resourceName\r
939                                 utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
940                                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
941                         }\r
942                         if (execution.getVariable(Prefix+"resourceType") == "vCPE") {\r
943                                 execution.setVariable("skipVFC", "false")\r
944                                 utils.log("INFO", "vCPE will deploy ", isDebugEnabled)\r
945                         }\r
946 \r
947         }catch(Exception e){\r
948             // try error in method block\r
949                         String exceptionMessage = "Bpmn error encountered in "+ method + " - " + e.getMessage()\r
950                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
951                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
952         }\r
953             utils.log("INFO", "Exited " + method, isDebugEnabled)  \r
954         }\r
955         /**\r
956         * prepare post Unkown Resource Type \r
957         */\r
958         public void postOtherControllerType(DelegateExecution execution){\r
959         def method = getClass().getSimpleName() + '.postOtherControllerType(' +'execution=' + execution.getId() +')'\r
960                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
961                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
962                 \r
963         utils.log("INFO", " ======== Enter DoCreateE2EServiceInstanceV2 postOtherControllerType Process ======== ", isDebugEnabled)\r
964         try{\r
965 \r
966             String resourceName = execution.getVariable(Prefix+"resourceName") \r
967                         String resourceType = execution.getVariable(Prefix+"resourceType") \r
968                         String controllerType = execution.getVariable("controllerType")\r
969                         \r
970                     String msg = "Resource name: "+ resourceName + " resource Type: " + resourceType+ " controller Type: " + controllerType + " can not be processed  n the workflow"\r
971                         utils.log("DEBUG", msg, isDebugEnabled)\r
972                         \r
973         }catch(Exception e){\r
974             // try error in method block\r
975                         String exceptionMessage = "Bpmn error encountered in "+ method + " - " + e.getMessage()\r
976                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
977                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
978         }\r
979             utils.log("INFO", "Exited " + method, isDebugEnabled)   \r
980         }\r
981         \r
982         /**\r
983          * prepare Controller resource create request\r
984          */\r
985         public void preProcessResourceRequestForController(execution){\r
986         def method = getClass().getSimpleName() + '.preProcessResourceRequestForController(' +'execution=' + execution.getId() +')'\r
987                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
988                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
989         utils.log("INFO", " ======== Enter DoCreateE2EServiceInstanceV2 preProcessResourceRequestForController Process ======== ", isDebugEnabled)\r
990         try{\r
991             String resourceName = execution.getVariable(Prefix+"resourceName") \r
992                 String resourceType = execution.getVariable(Prefix+"resourceType")\r
993                         String serviceInstanceName =execution.getVariable("serviceInstanceName") \r
994                         String nsServiceName = resourceType + "_" + serviceInstanceName\r
995                 execution.setVariable("nsServiceName", nsServiceName)\r
996                 utils.log("INFO", "Prepare Controller Request nsServiceName:" + nsServiceName, isDebugEnabled)\r
997 \r
998             String serviceId = execution.getVariable("serviceInstanceId")\r
999             execution.setVariable("serviceId", serviceId)\r
1000                 utils.log("INFO", "Prepare Controller Request serviceId:" + serviceId, isDebugEnabled) \r
1001                         \r
1002                         String globalSubscriberId = execution.getVariable("globalSubscriberId")\r
1003                         utils.log("INFO", "Prepare Controller Request globalSubscriberId:" + globalSubscriberId, isDebugEnabled) \r
1004                         \r
1005                         String incomingRequest = execution.getVariable("uuiRequest")\r
1006                         String nsServiceDescription = jsonUtil.getJsonValue(incomingRequest, "service.description")  \r
1007             execution.setVariable("nsServiceDescription", nsServiceDescription)\r
1008             utils.log("INFO", "Prepare Controller Request nsServiceDescription:" + nsServiceDescription, isDebugEnabled)\r
1009 \r
1010             String resourceUUID  = execution.getVariable("resourceUUID")\r
1011          \r
1012             utils.log("INFO", "Prepare Controller Request resourceUUID:" + resourceUUID, isDebugEnabled)\r
1013                         \r
1014             String resourceInvariantUUID  = execution.getVariable("resourceInvariantUUID")\r
1015                         utils.log("INFO", "Prepare Controller Request resourceInvariantUUID:" + resourceInvariantUUID, isDebugEnabled)\r
1016 \r
1017             String resourceParameters = execution.getVariable("resourceParameters")              \r
1018             execution.setVariable("resourceParameters", resourceParameters)\r
1019             utils.log("INFO", "Prepare Controller Request resourceParameters:" + resourceParameters, isDebugEnabled)\r
1020 \r
1021 \r
1022 \r
1023         }catch(Exception e){\r
1024             String exceptionMessage = "Bpmn error encountered in "+ method + " - " + e.getMessage()\r
1025                         utils.log("ERROR", exceptionMessage, isDebugEnabled)\r
1026             execution.setVariable(Prefix+"ErrorResponse", exceptionMessage)\r
1027         }\r
1028             utils.log("INFO", "Exited " + method, isDebugEnabled)  \r
1029         }\r
1030         /**\r
1031          * post process VFC resource create request\r
1032          */\r
1033         public void postProcessResourceRequestForVFC(execution){\r
1034         def method = getClass().getSimpleName() + '.postProcessResourceRequestForVFC(' +'execution=' + execution.getId() +')'\r
1035                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
1036                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
1037         utils.log("INFO", " ======== Enter DoCreateE2EServiceInstanceV2 postProcessResourceRequestForVFC Process ======== ", isDebugEnabled)\r
1038         try{\r
1039             \r
1040 \r
1041         }catch(Exception e){\r
1042             utils.log("ERROR", "Exception Occured Processing postProcessResourceRequestForVFC. Exception is:\n" + e, isDebugEnabled)\r
1043             execution.setVariable(Prefix+"ErrorResponse", "Error Occurred during postProcessResourceRequestForVFC Method:\n" + e.getMessage())\r
1044         }\r
1045             utils.log("INFO", "Exited " + method, isDebugEnabled)  \r
1046         }\r
1047 \r
1048 \r
1049         /**\r
1050          * post process SDNC resource create request\r
1051          */\r
1052         public void postProcessResourceRequestForSDNC(execution){\r
1053         def method = getClass().getSimpleName() + '.postProcessResourceRequestForSDNC(' +'execution=' + execution.getId() +')'\r
1054                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
1055                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
1056         utils.log("INFO", " ======== Enter DoCreateE2EServiceInstanceV2 postProcessResourceRequestForSDNC Process ======== ", isDebugEnabled)\r
1057         try{\r
1058                 \r
1059           execution.setVariable("serviceSDNCCreate", "true")\r
1060 \r
1061         }catch(Exception e){\r
1062             utils.log("ERROR", "Exception Occured Processing postProcessResourceRequestForSDNC. Exception is:\n" + e, isDebugEnabled)\r
1063             execution.setVariable(Prefix+"ErrorResponse", "Error Occurred during postProcessResourceRequestForSDNC Method:\n" + e.getMessage())\r
1064         }\r
1065             utils.log("INFO", "Exited " + method, isDebugEnabled)\r
1066         }\r
1067         \r
1068 \r
1069         \r
1070 }\r
1071         \r