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