Merge "Reorder modifiers"
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoCustomDeleteE2EServiceInstanceV2.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 \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.WorkflowException\r
34 import org.openecomp.mso.bpmn.core.json.JsonUtils\r
35 import org.openecomp.mso.rest.APIResponse;\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>DoDeleteE2EServiceInstance.bpmn</class> process.\r
42  * \r
43  * Inputs:\r
44  * @param - msoRequestId\r
45  * @param - globalSubscriberId - O\r
46  * @param - subscriptionServiceType - O\r
47  * @param - serviceInstanceId\r
48  * @param - serviceInstanceName - O\r
49  * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)\r
50  * @param - sdncVersion \r
51  * @param - failNotFound - TODO\r
52  * @param - serviceInputParams - TODO\r
53  *\r
54  * Outputs:\r
55  * @param - WorkflowException\r
56  * \r
57  * Rollback - Deferred\r
58  */\r
59 public class DoCustomDeleteE2EServiceInstanceV2 extends AbstractServiceTaskProcessor {\r
60 \r
61         String Prefix="DDELSI_"\r
62         private static final String DebugFlag = "isDebugEnabled"\r
63         ExceptionUtil exceptionUtil = new ExceptionUtil()\r
64         JsonUtils jsonUtil = new JsonUtils()\r
65 \r
66         public void preProcessRequest (DelegateExecution execution) {\r
67                 \r
68                 def method = getClass().getSimpleName() + '.buildAPPCRequest(' +'execution=' + execution.getId() +')'\r
69                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
70                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
71                 utils.log("INFO"," ***** preProcessRequest *****",  isDebugEnabled)\r
72                 String msg = ""\r
73 \r
74                 try {\r
75                         String requestId = execution.getVariable("msoRequestId")\r
76                         execution.setVariable("prefix",Prefix)\r
77 \r
78                         //Inputs\r
79                         //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology\r
80                         String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId\r
81                         if (globalSubscriberId == null)\r
82                         {\r
83                                 execution.setVariable("globalSubscriberId", "")\r
84                         }\r
85 \r
86                         //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology\r
87                         String serviceType = execution.getVariable("serviceType")\r
88                         if (serviceType == null)\r
89                         {\r
90                                 execution.setVariable("serviceType", "")\r
91                         }\r
92 \r
93                         //Generated in parent for AAI PUT\r
94                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
95                         if (isBlank(serviceInstanceId)){\r
96                                 msg = "Input serviceInstanceId is null"\r
97                                 utils.log("INFO", msg, isDebugEnabled)\r
98                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
99                         }\r
100 \r
101                         String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')\r
102                         if (isBlank(sdncCallbackUrl)) {\r
103                                 msg = "URN_mso_workflow_sdncadapter_callback is null"\r
104                                 utils.log("INFO", msg, isDebugEnabled)\r
105                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
106                         }\r
107                         execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)\r
108                         utils.log("INFO","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)\r
109 \r
110                         StringBuilder sbParams = new StringBuilder()\r
111                         Map<String, String> paramsMap = execution.getVariable("serviceInputParams")\r
112                         if (paramsMap != null)\r
113                         {\r
114                                 sbParams.append("<service-input-parameters>")\r
115                                 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {\r
116                                         String paramsXml\r
117                                         String paramName = entry.getKey()\r
118                                         String paramValue = entry.getValue()\r
119                                         paramsXml =\r
120                                                         """     <param>\r
121                                                         <name>${paramName}</name>\r
122                                                         <value>${paramValue}</value>\r
123                                                         </param>\r
124                                                         """\r
125                                         sbParams.append(paramsXml)\r
126                                 }\r
127                                 sbParams.append("</service-input-parameters>")\r
128                         }\r
129                         String siParamsXml = sbParams.toString()\r
130                         if (siParamsXml == null)\r
131                                 siParamsXml = ""\r
132                         execution.setVariable("siParamsXml", siParamsXml)\r
133                         execution.setVariable("operationStatus", "Waiting delete resource...")\r
134                         execution.setVariable("progress", "0")                  \r
135 \r
136                 } catch (BpmnError e) {\r
137                         throw e;\r
138                 } catch (Exception ex){\r
139                         msg = "Exception in preProcessRequest " + ex.getMessage()\r
140                         utils.log("INFO", msg, isDebugEnabled)\r
141                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
142                 }\r
143                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
144         }\r
145         \r
146 \r
147 \r
148         public void postProcessAAIGET(DelegateExecution execution) {\r
149                 def method = getClass().getSimpleName() + '.postProcessAAIGET(' +'execution=' + execution.getId() +')'\r
150                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
151                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
152                 \r
153                 String msg = ""\r
154 \r
155                 try {\r
156                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
157                         utils.log("INFO","serviceInstanceId: "+serviceInstanceId, isDebugEnabled)\r
158                         \r
159                         boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")\r
160                         utils.log("INFO","foundInAAI: "+foundInAAI, isDebugEnabled)\r
161                         \r
162                         String serviceType = ""\r
163                         \r
164 \r
165                         if(foundInAAI){\r
166                                 utils.log("INFO","Found Service-instance in AAI", isDebugEnabled)\r
167 \r
168                                 String siData = execution.getVariable("GENGS_service")\r
169                                 utils.log("INFO", "SI Data", isDebugEnabled)\r
170                                 if (isBlank(siData))\r
171                                 {\r
172                                         msg = "Could not retrive ServiceInstance data from AAI to delete id:" + serviceInstanceId\r
173                                         utils.log("INFO", msg, isDebugEnabled)\r
174                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
175                                 }\r
176                                 \r
177                         }else{\r
178                                 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")\r
179                                 if(!succInAAI){\r
180                                         utils.log("INFO","Error getting Service-instance from AAI", + serviceInstanceId, isDebugEnabled)\r
181                                         WorkflowException workflowException = execution.getVariable("WorkflowException")\r
182                                         utils.logAudit("workflowException: " + workflowException)\r
183                                         if(workflowException != null){\r
184                                                 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())\r
185                                         }\r
186                                         else\r
187                                         {\r
188                                                 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI\r
189                                                 utils.log("INFO", msg, isDebugEnabled)\r
190                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)\r
191                                         }\r
192                                 }\r
193 \r
194                                 utils.log("INFO","Service-instance NOT found in AAI. Silent Success", isDebugEnabled)\r
195                         }\r
196                 }catch (BpmnError e) {\r
197                         throw e;\r
198                 } catch (Exception ex) {\r
199                         msg = "Bpmn error encountered in " + method + "--" + ex.getMessage()\r
200                         utils.log("INFO", msg, isDebugEnabled)\r
201                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
202                 }\r
203                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
204         }\r
205         \r
206         private void loadResourcesProperties(DelegateExecution execution) {\r
207                 def method = getClass().getSimpleName() + '.loadResourcesProperties(' +'execution=' + execution.getId() +')'\r
208                 def isDebugEnabled = execution.getVariable("isDebugEnabled")\r
209                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
210                 String loadFilePath = "/etc/mso/config.d/reources.json"\r
211                 try{\r
212                         def jsonPayload = new File(loadFilePath).text\r
213                         utils.log("INFO","jsonPayload: " + jsonPayload, isDebugEnabled)\r
214 \r
215                         String resourcesProperties = jsonUtil.prettyJson(jsonPayload.toString())\r
216                         utils.log("INFO","resourcesProperties: " + resourcesProperties, isDebugEnabled)\r
217                         \r
218                         String createResourceSort = jsonUtil.getJsonValue(resourcesProperties, "CreateResourceSort")\r
219                         //utils.log("INFO","createResourceSort: " + createResourceSort, isDebugEnabled)\r
220                         execution.setVariable("createResourceSort", createResourceSort)\r
221                         \r
222                         String deleteResourceSort = jsonUtil.getJsonValue(resourcesProperties, "DeleteResourceSort")\r
223                         //utils.log("INFO","deleteResourceSort: " + deleteResourceSort, isDebugEnabled)\r
224                         execution.setVariable("deleteResourceSort", deleteResourceSort)\r
225                         \r
226                         \r
227                         String resourceControllerType = jsonUtil.getJsonValue(resourcesProperties, "ResourceControllerType")\r
228                         //utils.log("INFO","resourceControllerType: " + resourceControllerType, isDebugEnabled)\r
229                         execution.setVariable("resourceControllerType", resourceControllerType)                 \r
230                         \r
231                         \r
232                 }catch(Exception ex){\r
233             // try error in method block\r
234                         String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()\r
235                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
236                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
237         }\r
238             utils.log("INFO", "Exited " + method, isDebugEnabled)\r
239         }\r
240         private void sortDeleteResource(DelegateExecution execution) {\r
241                 def method = getClass().getSimpleName() + '.sortDeleteResource(' +'execution=' + execution.getId() +')'\r
242                 def isDebugEnabled = execution.getVariable("isDebugEnabled")\r
243                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
244                 String deleteResourceSortDef = """[\r
245                 {\r
246                     "resourceType":"GRE_SAR"\r
247                 },\r
248                 {\r
249                     "resourceType":"VPN_SAR"\r
250                 },\r
251                 {\r
252                     "resourceType":"APN_AAR"\r
253                 },\r
254                                 {\r
255                     "resourceType":"GRE_AAR"\r
256                 },\r
257                 {\r
258                     "resourceType":"Overlay"\r
259                 },\r
260                                 {\r
261                     "resourceType":"Underlay"\r
262                 },\r
263                 {\r
264                     "resourceType":"vIMS"\r
265                 },\r
266                 {\r
267                     "resourceType":"vCPE"\r
268                 },\r
269                 {\r
270                     "resourceType":"vFW"\r
271                 },\r
272                 {\r
273                     "resourceType":"vEPC"\r
274                 }\r
275                                 \r
276                 \r
277             ]""".trim()\r
278                 \r
279         try{\r
280                         loadResourcesProperties(execution)\r
281                         String deleteResourceSort = execution.getVariable("deleteResourceSort")\r
282                         if (isBlank(deleteResourceSort)) {\r
283                                 deleteResourceSort = deleteResourceSortDef;\r
284                         }\r
285                         \r
286                         List<String> sortResourceList = jsonUtil.StringArrayToList(execution, deleteResourceSort)\r
287                 utils.log("INFO", "sortResourceList : " + sortResourceList, isDebugEnabled)              \r
288 \r
289                         JSONArray newResourceList      = new JSONArray()\r
290                         int resSortCount = sortResourceList.size()\r
291                         \r
292                         for ( int currentResource = 0 ; currentResource < resSortCount ; currentResource++ ) { \r
293                                 String currentSortResource = sortResourceList[currentResource]\r
294                                 String sortResourceType = jsonUtil.getJsonValue(currentSortResource, "resourceType")                            \r
295                                 List<String> resourceList = execution.getVariable(Prefix+"resourceList")\r
296 \r
297                                 for (String resource : resourceList) {\r
298                                         //utils.log("INFO", "resource : " + resource, isDebugEnabled)\r
299                                         String resourceType = jsonUtil.getJsonValue(resource, "resourceType")\r
300         \r
301                                         if (StringUtils.containsIgnoreCase(resourceType, sortResourceType)) {\r
302                                                 JSONObject jsonObj = new JSONObject(resource)\r
303                                                 newResourceList.put(jsonObj)\r
304                                         }\r
305                                         utils.log("INFO", "Get next sort type " , isDebugEnabled)\r
306                                 }\r
307                         } \r
308 \r
309             String newResourceStr = newResourceList.toString()          \r
310             List<String> newResourceListStr = jsonUtil.StringArrayToList(execution, newResourceStr)                     \r
311                 \r
312                         execution.setVariable(Prefix+"resourceList", newResourceListStr)\r
313                         utils.log("INFO", "newResourceList : " + newResourceListStr, isDebugEnabled) \r
314                         \r
315                 }catch(Exception ex){\r
316             // try error in method block\r
317                         String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()\r
318                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
319                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
320         }\r
321             utils.log("INFO", "Exited " + method, isDebugEnabled)\r
322                 \r
323         }\r
324         public void prepareServiceDeleteResource(DelegateExecution execution) {\r
325                 def method = getClass().getSimpleName() + '.prepareServiceDeleteResource(' +'execution=' + execution.getId() +')'\r
326                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
327                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
328                 \r
329                 try {\r
330                         \r
331                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
332                         \r
333                         // confirm if ServiceInstance was found\r
334                         if ( !execution.getVariable("GENGS_FoundIndicator") )\r
335                         {\r
336                                 String exceptionMessage = "Bpmn error encountered in DeleteMobileAPNCustService flow. Service Instance was not found in AAI by id: " + serviceInstanceId\r
337                                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
338                         }\r
339                         \r
340                         execution.setVariable(Prefix+"resourceList", "")\r
341                         execution.setVariable(Prefix+"resourceCount", 0)\r
342                         execution.setVariable(Prefix+"nextResource", 0)\r
343                         execution.setVariable(Prefix+"resourceFinish", true)\r
344                         \r
345                         // get SI extracted by GenericGetService\r
346                         String serviceInstanceAaiRecord = execution.getVariable("GENGS_service");\r
347                         utils.log("INFO", "serviceInstanceAaiRecord: " +serviceInstanceAaiRecord, isDebugEnabled)\r
348                         \r
349                         String aaiJsonRecord = jsonUtil.xml2json(serviceInstanceAaiRecord)\r
350                         \r
351                         //utils.log("INFO", "aaiJsonRecord: " +aaiJsonRecord, isDebugEnabled)\r
352                         def serviceInstanceName = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-instance-name")\r
353                         execution.setVariable("serviceInstanceName",serviceInstanceName)\r
354                         \r
355                         def serviceType = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-type")\r
356                         execution.setVariable("serviceType",serviceType)\r
357                         \r
358                         \r
359                         String relationshipList = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.relationship-list")  \r
360                         //utils.log("INFO", "relationship-list:" + relationshipList, isDebugEnabled)\r
361                         if (! isBlank(relationshipList)){\r
362                                 utils.log("INFO", "relationship-list exists" , isDebugEnabled)\r
363                                 String relationShip = jsonUtil.getJsonValue(relationshipList, "relationship")\r
364                                 utils.log("INFO", "relationship: " + relationShip, isDebugEnabled)\r
365                                 JSONArray allResources      = new JSONArray()\r
366                                 JSONArray serviceResources  = new JSONArray()\r
367                                 JSONArray networkResources  = new JSONArray()\r
368                                 JSONArray allottedResources = new JSONArray()\r
369                                 \r
370                                 \r
371                                 if (! isBlank(relationShip)){\r
372                                         JSONArray jsonArray = new JSONArray();\r
373                                         if (relationShip.startsWith("{") && relationShip.endsWith("}")) {\r
374                                                 JSONObject jsonObject = new JSONObject(relationShip);\r
375                                                 jsonArray.put(jsonObject);\r
376                                         } else if (relationShip.startsWith("[") && relationShip.endsWith("]")) {\r
377                                                 jsonArray = new JSONArray(relationShip);\r
378                                         } else {\r
379                                                 utils.log("INFO", "The relationShip fomart is error" , isDebugEnabled)                  \r
380                                         }\r
381                                 \r
382                                         List<String> relationList = jsonUtil.StringArrayToList(execution, jsonArray.toString())\r
383                                         \r
384                                         utils.log("INFO", "relationList: " + relationList, isDebugEnabled)\r
385                                         \r
386                                         int relationNum =relationList.size()\r
387                                         utils.log("INFO", "**************relationList size: " + relationNum, isDebugEnabled)\r
388                                         \r
389                                         for ( int currentRelation = 0 ; currentRelation < relationNum ; currentRelation++ ) {  \r
390                                                 utils.log("INFO", "current Relation num: " + currentRelation, isDebugEnabled)\r
391                                                 String relation = relationList[currentRelation]\r
392                                                 utils.log("INFO", "relation: " + relation, isDebugEnabled)\r
393                                                 \r
394                                                 String relatedTo = jsonUtil.getJsonValue(relation, "related-to")  \r
395                                 utils.log("INFO", "relatedTo: " + relatedTo, isDebugEnabled)\r
396                                                 \r
397                                                 String relatedLink = jsonUtil.getJsonValue(relation, "related-link")  \r
398                                                 utils.log("INFO", "relatedLink: " + relatedLink, isDebugEnabled)\r
399                                                 \r
400                                 if (StringUtils.equalsIgnoreCase(relatedTo, "allotted-resource")) {\r
401                                         utils.log("INFO", "allotted-resource exists ", isDebugEnabled)\r
402 \r
403                                                         String aaiArRsp = getAaiAr(execution, relatedLink)\r
404                                                         utils.log("INFO", "aaiArRsp: " + aaiArRsp, isDebugEnabled)\r
405                                                         if (! isBlank(aaiArRsp)) {\r
406                                                                 def type = utils.getNodeText1(aaiArRsp, "type")\r
407                                                                 def id = utils.getNodeText1(aaiArRsp, "id")\r
408                                                             def role = utils.getNodeText1(aaiArRsp, "role")\r
409                                                                 def resourceVersion = utils.getNodeText1(aaiArRsp, "resource-version")\r
410                                                                 \r
411                                                                 JSONObject jObject = new JSONObject()\r
412                                                                 jObject.put("resourceType", type)\r
413                                                                 jObject.put("resourceInstanceId", id)\r
414                                                                 jObject.put("resourceRole", role)\r
415                                                                 jObject.put("resourceVersion", resourceVersion)\r
416                                                                 \r
417                                                                 allResources.put(jObject)                                                       \r
418                                                                 utils.log("INFO", "allResources: " + allResources, isDebugEnabled)\r
419                                                                 allottedResources.put(jObject)\r
420                                                                 utils.log("INFO", "allottedResources: " + allottedResources, isDebugEnabled)\r
421                                                         }\r
422                                                 }\r
423                                                 else if (StringUtils.equalsIgnoreCase(relatedTo, "service-instance")){\r
424                                         utils.log("INFO", "service-instance exists ", isDebugEnabled)\r
425                                                         JSONObject jObject = new JSONObject()\r
426                                                         \r
427                                                         //relationship-data\r
428                                                         String rsDataStr  = jsonUtil.getJsonValue(relation, "relationship-data")\r
429                                                         utils.log("INFO", "rsDataStr: " + rsDataStr, isDebugEnabled)\r
430                                                         List<String> rsDataList = jsonUtil.StringArrayToList(execution, rsDataStr)\r
431                                                         utils.log("INFO", "rsDataList: " + rsDataList, isDebugEnabled)\r
432                                                         for(String rsData : rsDataList){ \r
433                                                                 utils.log("INFO", "rsData: " + rsData, isDebugEnabled)                                                          \r
434                                                                 def eKey =  jsonUtil.getJsonValue(rsData, "relationship-key")\r
435                                                                 def eValue = jsonUtil.getJsonValue(rsData, "relationship-value")\r
436                                                                 if(eKey.equals("service-instance.service-instance-id")){\r
437                                                                         jObject.put("resourceInstanceId", eValue)\r
438                                                                 }\r
439                                                                 if(eKey.equals("service-subscription.service-type")){\r
440                                                                         jObject.put("resourceType", eValue)\r
441                                                                 }\r
442                                                         }\r
443                                                         \r
444                                                         //related-to-property\r
445                                                         String rPropertyStr  = jsonUtil.getJsonValue(relation, "related-to-property")\r
446                                                         utils.log("INFO", "related-to-property: " + rPropertyStr, isDebugEnabled)\r
447                                                         if (rPropertyStr instanceof JSONArray){\r
448                                                                 List<String> rPropertyList = jsonUtil.StringArrayToList(execution, rPropertyStr)\r
449                                                                 for (String rProperty : rPropertyList) { \r
450                                                                         utils.log("INFO", "rProperty: " + rProperty, isDebugEnabled)                                                            \r
451                                                                         def eKey =  jsonUtil.getJsonValue(rProperty, "property-key")\r
452                                                                         def eValue = jsonUtil.getJsonValue(rProperty, "property-value")\r
453                                                                         if(eKey.equals("service-instance.service-instance-name")){\r
454                                                                                 jObject.put("resourceName", eValue)\r
455                                                                         }\r
456                                                                 }\r
457                                                         }\r
458                                                         else {\r
459                                                                 String rProperty = rPropertyStr\r
460                                                                 utils.log("INFO", "rProperty: " + rProperty, isDebugEnabled)                                                            \r
461                                                                 def eKey =  jsonUtil.getJsonValue(rProperty, "property-key")\r
462                                                                 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")\r
463                                                                 if (eKey.equals("service-instance.service-instance-name")) {\r
464                                                                         jObject.put("resourceName", eValue)\r
465                                                                 }       \r
466                                                         }\r
467                                                         \r
468                                                         allResources.put(jObject)\r
469                                                         utils.log("INFO", "allResources: " + allResources, isDebugEnabled)\r
470                                                         \r
471                                                         serviceResources.put(jObject)\r
472                                                         utils.log("INFO", "serviceResources: " + serviceResources, isDebugEnabled)\r
473                                                 }\r
474                                                 else if (StringUtils.equalsIgnoreCase(relatedTo, "configuration")) {\r
475                                         utils.log("INFO", "configuration ", isDebugEnabled)\r
476                                                         JSONObject jObject = new JSONObject()\r
477                                                         \r
478                                                         //relationship-data\r
479                                                         String rsDataStr  = jsonUtil.getJsonValue(relation, "relationship-data")\r
480                                                         utils.log("INFO", "rsDataStr: " + rsDataStr, isDebugEnabled)\r
481                                                         List<String> rsDataList = jsonUtil.StringArrayToList(execution, rsDataStr)\r
482                                                         utils.log("INFO", "rsDataList: " + rsDataList, isDebugEnabled)\r
483                                                         for (String rsData : rsDataList) { \r
484                                                                 utils.log("INFO", "rsData: " + rsData, isDebugEnabled)                                                          \r
485                                                                 def eKey =  jsonUtil.getJsonValue(rsData, "relationship-key")\r
486                                                                 def eValue = jsonUtil.getJsonValue(rsData, "relationship-value")\r
487                                                                 if(eKey.equals("configuration.configuration-id")){\r
488                                                                         jObject.put("resourceInstanceId", eValue)\r
489                                                                 }\r
490                                                         }\r
491 \r
492                                                         \r
493                                                         //related-to-property\r
494                                                         String rPropertyStr  = jsonUtil.getJsonValue(relation, "related-to-property")\r
495                                                         utils.log("INFO", "related-to-property: " + rPropertyStr, isDebugEnabled)\r
496                                                         if (rPropertyStr instanceof JSONArray){\r
497                                                                 List<String> rPropertyList = jsonUtil.StringArrayToList(execution, rPropertyStr)\r
498                                                                 for(String rProperty : rPropertyList){ \r
499                                                                         utils.log("INFO", "rProperty: " + rProperty, isDebugEnabled)                                                            \r
500                                                                         def eKey =  jsonUtil.getJsonValue(rProperty, "property-key")\r
501                                                                         def eValue = jsonUtil.getJsonValue(rProperty, "property-value")\r
502                                                                         if(eKey.equals("configuration.configuration-type")){\r
503                                                                                 jObject.put("resourceType", eValue)\r
504                                                                         }\r
505                                                                 }\r
506                                                         }\r
507                                                         else {\r
508                                                                 String rProperty = rPropertyStr\r
509                                                                 utils.log("INFO", "rProperty: " + rProperty, isDebugEnabled)                                                            \r
510                                                                 def eKey =  jsonUtil.getJsonValue(rProperty, "property-key")\r
511                                                                 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")\r
512                                                                 if(eKey.equals("configuration.configuration-type")){\r
513                                                                         jObject.put("resourceType", eValue)\r
514                                                                 }       \r
515                                                         }\r
516                                                         allResources.put(jObject)\r
517                                                         utils.log("INFO", "allResources: " + allResources, isDebugEnabled)\r
518                                                         \r
519                                                         networkResources.put(jObject)\r
520                                                         utils.log("INFO", "networkResources: " + networkResources, isDebugEnabled)\r
521                                                 }\r
522                                                 utils.log("INFO", "Get Next releation resource " , isDebugEnabled)\r
523                                                 \r
524                                         }\r
525                                         utils.log("INFO", "Get releation finished. " , isDebugEnabled)\r
526                                 }\r
527                                 \r
528                                 execution.setVariable("serviceRelationShip", allResources.toString())\r
529                             utils.log("INFO", "allResources: " + allResources.toString(), isDebugEnabled)\r
530                                 String serviceRelationShip = execution.getVariable("serviceRelationShip")  \r
531                                 utils.log("INFO", "serviceRelationShip: " + serviceRelationShip, isDebugEnabled)\r
532                                 if ((! isBlank(serviceRelationShip)) && (! serviceRelationShip.isEmpty())) {\r
533  \r
534                                         List<String> relationShipList = jsonUtil.StringArrayToList(execution, serviceRelationShip) \r
535                                         utils.log("INFO", "relationShipList: " + relationShipList, isDebugEnabled) \r
536                                         execution.setVariable(Prefix+"resourceList", relationShipList)\r
537                                 \r
538                                         int resourceCount = relationShipList.size()\r
539                                         utils.log("INFO", "resourceCount: " + resourceCount, isDebugEnabled)\r
540                                         execution.setVariable(Prefix+"resourceCount",resourceCount )\r
541                                 \r
542                                         int resourceNum = 0\r
543                                         execution.setVariable(Prefix+"nextResource", resourceNum)\r
544                                         utils.log("INFO", "start sort delete resource: ", isDebugEnabled)\r
545                                         sortDeleteResource(execution)\r
546                                         \r
547                                         \r
548                                         if (resourceNum < resourceCount) {\r
549                                                 execution.setVariable(Prefix+"resourceFinish", false)\r
550                                         }\r
551                                         else {\r
552                                         execution.setVariable(Prefix+"resourceFinish", true)\r
553                                         }\r
554                                         utils.log("INFO", "Resource  list set end : " + resourceCount, isDebugEnabled) \r
555                 }\r
556                                 \r
557                                 execution.setVariable("serviceResources", serviceResources.toString()) \r
558                                 utils.log("INFO", "serviceResources: " + serviceResources, isDebugEnabled) \r
559                                 String serviceResourcesShip = execution.getVariable("serviceResources") \r
560                                 utils.log("INFO", "serviceResourcesShip: " + serviceResourcesShip, isDebugEnabled)\r
561                                 \r
562                                 if ((! isBlank(serviceResourcesShip)) && (! serviceResourcesShip.isEmpty())) {\r
563                     List<String> serviceResourcesList = jsonUtil.StringArrayToList(execution, serviceResourcesShip)   \r
564                                         utils.log("INFO", "serviceResourcesList: " + serviceResourcesList, isDebugEnabled) \r
565                                         execution.setVariable(Prefix+"serviceResourceList", serviceResourcesList)       \r
566                                 execution.setVariable(Prefix+"serviceResourceCount", serviceResourcesList.size())\r
567                                 execution.setVariable(Prefix+"nextServiceResource", 0)\r
568                                 utils.log("INFO", "Service Resource  list set end : " + serviceResourcesList.size(), isDebugEnabled) \r
569                    \r
570                 }\r
571                                 \r
572                                 execution.setVariable("allottedResources", allottedResources.toString())\r
573                                 utils.log("INFO", "allottedResources: " + allottedResources, isDebugEnabled)\r
574                                 String allottedResourcesShip = execution.getVariable("allottedResources") \r
575                                 utils.log("INFO", "allottedResourcesShip: " + allottedResourcesShip, isDebugEnabled)\r
576                                 if ((! isBlank(allottedResourcesShip)) && (! allottedResourcesShip.isEmpty())) {\r
577                     List<String> allottedResourcesList = jsonUtil.StringArrayToList(execution, allottedResourcesShip)\r
578                                         utils.log("INFO", "allottedResourcesList: " + allottedResourcesList, isDebugEnabled)\r
579                                         execution.setVariable(Prefix+"allottedResourcesList", allottedResourcesList)    \r
580                                 execution.setVariable(Prefix+"allottedResourcesListCount", allottedResourcesList.size())\r
581                                 execution.setVariable(Prefix+"nextAllottedResourcesList", 0)\r
582                                 utils.log("INFO", "Allotted Resource  list set end : " + allottedResourcesList.size(), isDebugEnabled) \r
583                    \r
584                 }\r
585                                 execution.setVariable("networkResources", networkResources.toString())\r
586                                 utils.log("INFO", "networkResources: " + networkResources, isDebugEnabled)\r
587                                 String networkResourcesShip = execution.getVariable("networkResources") \r
588                                 utils.log("INFO", "networkResourcesShip: " + networkResourcesShip, isDebugEnabled)\r
589                                 if ((! isBlank(networkResourcesShip)) && (! networkResourcesShip.isEmpty())) {\r
590                     List<String> networkResourcesList = jsonUtil.StringArrayToList(execution, networkResourcesShip)       \r
591                                         utils.log("INFO", "networkResourcesList: " + networkResourcesList, isDebugEnabled)\r
592                                         execution.setVariable(Prefix+"networkResourcesList", networkResourcesList)      \r
593                                 execution.setVariable(Prefix+"networkResourcesListCount", networkResourcesList.size())\r
594                                 execution.setVariable(Prefix+"nextNetworkResourcesList", 0)\r
595                                 utils.log("INFO", "Network Resource  list set end : " + networkResourcesList.size(), isDebugEnabled)\r
596                    \r
597                 }\r
598                         }\r
599                 } catch (BpmnError e){\r
600                         throw e;\r
601                 } catch (Exception ex) {\r
602                     String exceptionMessage = "Bpmn error encountered in DeleteMobileAPNCustService flow. prepareServiceDeleteResource() - " + ex.getMessage()\r
603                     utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
604                     exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
605                 }\r
606                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
607         }\r
608         \r
609         private String getAaiAr(DelegateExecution execution, String relink) {\r
610                 def method = getClass().getSimpleName() + '.getAaiAr(' +'execution=' + execution.getId() +')'\r
611                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
612                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
613                 AaiUtil aaiUtil = new AaiUtil(this)\r
614                 String aaiEndpoint = execution.getVariable("URN_aai_endpoint") + relink\r
615                 \r
616                 utils.log("DEBUG", "get AR info " + aaiEndpoint, isDebugEnabled)\r
617                 APIResponse response = aaiUtil.executeAAIGetCall(execution, aaiEndpoint)\r
618                 \r
619                 int responseCode = response.getStatusCode()\r
620                 utils.log("DEBUG", "get AR info responseCode:" + responseCode, isDebugEnabled)\r
621                 \r
622                 String aaiResponse = response.getResponseBodyAsString()\r
623                 utils.log("DEBUG", "get AR info " + aaiResponse, isDebugEnabled)\r
624                 \r
625                 if(responseCode < 200 || responseCode >= 300 || isBlank(aaiResponse)) {\r
626                         return null\r
627                 }\r
628         \r
629                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
630                 return aaiResponse\r
631         }\r
632         /**\r
633          * prepare Decompose next resource to create request\r
634          */\r
635         public void preProcessDecomposeNextResource(DelegateExecution execution){\r
636         def method = getClass().getSimpleName() + '.getAaiAr(' +'execution=' + execution.getId() +')'\r
637                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
638                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
639         utils.log("INFO", " ======== STARTED preProcessDecomposeNextResource Process ======== ", isDebugEnabled)\r
640         try{\r
641             int resourceNum = execution.getVariable(Prefix+"nextServiceResource")\r
642                         List<String> serviceResourceList = execution.getVariable(Prefix+"serviceResourceList")\r
643                         utils.log("INFO", "Service Resource List : " + serviceResourceList, isDebugEnabled)\r
644                         \r
645                         String serviceResource = serviceResourceList[resourceNum]\r
646             execution.setVariable(Prefix+"serviceResource", serviceResource)\r
647                         utils.log("INFO", "Current Service Resource : " + serviceResource, isDebugEnabled)\r
648                         \r
649                         String resourceType  = jsonUtil.getJsonValue(serviceResource, "resourceType")\r
650                         execution.setVariable("resourceType", resourceType)\r
651                         utils.log("INFO", "resourceType : " + resourceType, isDebugEnabled)\r
652             \r
653                         String resourceInstanceId  = jsonUtil.getJsonValue(serviceResource, "resourceInstanceId")\r
654                         execution.setVariable("resourceInstanceId", resourceInstanceId)\r
655                         utils.log("INFO", "resourceInstanceId : " + resourceInstanceId, isDebugEnabled)\r
656                         \r
657                         String resourceRole  = jsonUtil.getJsonValue(serviceResource, "resourceRole")\r
658                         execution.setVariable("resourceRole", resourceRole)\r
659                         utils.log("INFO", "resourceRole : " + resourceRole, isDebugEnabled)\r
660                         \r
661                         String resourceVersion  = jsonUtil.getJsonValue(serviceResource, "resourceVersion")\r
662                         execution.setVariable("resourceVersion", resourceVersion)\r
663                         utils.log("INFO", "resourceVersion : " + resourceVersion, isDebugEnabled)\r
664                         \r
665                         String resourceName = jsonUtil.getJsonValue(serviceResource, "resourceName")  \r
666                         if (isBlank(resourceName)){\r
667                                 resourceName = resourceInstanceId\r
668                         }\r
669                         execution.setVariable(Prefix+"resourceName", resourceName)\r
670                         utils.log("INFO", "resource Name : " + resourceName, isDebugEnabled)\r
671                         \r
672 \r
673                         execution.setVariable(Prefix+"nextServiceResource", resourceNum + 1)\r
674                         \r
675                         int serviceResourceCount = execution.getVariable(Prefix+"serviceResourceCount")\r
676                         if (serviceResourceCount >0 ){\r
677                             int progress = (resourceNum*100) / serviceResourceCount\r
678                                 execution.setVariable("progress", progress.toString() )\r
679                         }\r
680                         execution.setVariable("operationStatus", resourceName )\r
681 \r
682         }catch(Exception e){\r
683             // try error in method block\r
684                         String exceptionMessage = "Bpmn error encountered in CreateMobileAPNCustService flow. Unexpected Error from method preProcessDecomposeNextResource() - " + ex.getMessage()\r
685                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
686                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
687         }\r
688             utils.log("INFO", "Exited " + method, isDebugEnabled)  \r
689         }\r
690         /**\r
691          * post Decompose next resource to create request\r
692          */\r
693         public void postProcessDecomposeNextResource(DelegateExecution execution){\r
694         def method = getClass().getSimpleName() + '.postProcessDecomposeNextResource(' +'execution=' + execution.getId() +')'\r
695                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
696                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
697         utils.log("INFO", " ======== STARTED postProcessDecomposeNextResource Process ======== ", isDebugEnabled)\r
698         try{\r
699             String resourceName = execution.getVariable(Prefix+"resourceName")\r
700                         int resourceNum = execution.getVariable(Prefix+"nextServiceResource")\r
701                         utils.log("DEBUG", "Current Resource count:"+ execution.getVariable(Prefix+"nextServiceResource"), isDebugEnabled)\r
702                         \r
703                         int resourceCount = execution.getVariable(Prefix+"serviceResourceCount")\r
704                         utils.log("DEBUG", "Total Resource count:"+ execution.getVariable(Prefix+"serviceResourceCount"), isDebugEnabled)\r
705 \r
706             if (resourceNum < resourceCount) {\r
707                                 execution.setVariable(Prefix+"resourceFinish", false)\r
708                         }\r
709                         else {\r
710                             execution.setVariable(Prefix+"resourceFinish", true)\r
711                         }\r
712                         \r
713                         utils.log("DEBUG", "Resource Finished:"+ execution.getVariable(Prefix+"resourceFinish"), isDebugEnabled)\r
714                         \r
715                         if (resourceCount >0 ){\r
716                             int progress = (resourceNum*100) / resourceCount\r
717 \r
718                                 execution.setVariable("progress", progress.toString() )\r
719                                 utils.log("DEBUG", "progress :"+ execution.getVariable("progress"), isDebugEnabled)\r
720                         }\r
721                         execution.setVariable("operationStatus", resourceName )\r
722 \r
723 \r
724         }catch(Exception e){\r
725             // try error in method block\r
726                         String exceptionMessage = "Bpmn error encountered in CreateMobileAPNCustService flow. Unexpected Error from method postProcessDecomposeNextResource() - " + ex.getMessage()\r
727                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
728                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
729         }\r
730             utils.log("INFO", "Exited " + method, isDebugEnabled)   \r
731         }\r
732         /**\r
733         * prepare post Unkown Resource Type \r
734         */\r
735         public void postOtherControllerType(DelegateExecution execution){\r
736         def method = getClass().getSimpleName() + '.postOtherControllerType(' +'execution=' + execution.getId() +')'\r
737                 def isDebugEnabled = execution.getVariable("isDebugEnabled")\r
738                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
739                 \r
740         try{\r
741 \r
742             String resourceName = execution.getVariable(Prefix+"resourceName") \r
743                         String resourceType = execution.getVariable(Prefix+"resourceType") \r
744                         String controllerType = execution.getVariable("controllerType")\r
745                         \r
746                     String msg = "Resource name: "+ resourceName + " resource Type: " + resourceType+ " controller Type: " + controllerType + " can not be processed  n the workflow"\r
747                         utils.log("DEBUG", msg, isDebugEnabled)\r
748                         \r
749         }catch(Exception e){\r
750             // try error in method block\r
751                         String exceptionMessage = "Bpmn error encountered in DoCreateMobileAPNServiceInstance flow. Unexpected Error from method postOtherControllerType() - " + ex.getMessage()\r
752                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
753                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
754         }\r
755             utils.log("INFO", "Exited " + method, isDebugEnabled)   \r
756         }\r
757 \r
758         /**\r
759     * prepare delete parameters\r
760     */\r
761     public void preSDNCResourceDelete(execution, resourceName){\r
762         // we use resource instance ids for delete flow as resourceTemplateUUIDs\r
763 \r
764         def method = getClass().getSimpleName() + '.preSDNCResourceDelete(' +'execution=' + execution.getId() +')'\r
765                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
766                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
767 \r
768         utils.log("INFO", " ======== STARTED preSDNCResourceDelete Process ======== ", isDebugEnabled)\r
769         String networkResources = execution.getVariable("networkResources") \r
770                         \r
771        \r
772         execution.setVariable("foundResource", false)       \r
773         if (networkResources != null) {\r
774             def jsonSlurper = new JsonSlurper()        \r
775             List relationShipList =  jsonSlurper.parseText(networkResources)\r
776                         relationShipList.each {\r
777                 if(StringUtils.containsIgnoreCase(it.resourceType, resourceName)) {\r
778                                     String resourceInstanceUUID = it.resourceInstanceId\r
779                                     String resourceTemplateUUID = it.resourceInstanceId\r
780                                     execution.setVariable("resourceTemplateId", resourceTemplateUUID)\r
781                                     execution.setVariable("resourceInstanceId", resourceInstanceUUID)\r
782                                     execution.setVariable("resourceType", resourceName)\r
783                                         execution.setVariable("foundResource", true)\r
784                                 utils.log("INFO", "Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + "  resourceInstanceId: " + resourceInstanceUUID + " resourceType: " + resourceName, isDebugEnabled)\r
785                                 }\r
786             }\r
787         }    \r
788         utils.log("INFO", "Exited " + method, isDebugEnabled)\r
789     }\r
790         public void preProcessSDNCDelete (DelegateExecution execution) {\r
791                 def method = getClass().getSimpleName() + '.preProcessSDNCDelete(' +'execution=' + execution.getId() +')'\r
792                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
793                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
794                 utils.log("INFO"," ***** preProcessSDNCDelete *****", isDebugEnabled)\r
795                 String msg = ""\r
796 \r
797                 try {\r
798                         def serviceInstanceId = execution.getVariable("serviceInstanceId")\r
799                         def serviceInstanceName = execution.getVariable("serviceInstanceName")\r
800                         def callbackURL = execution.getVariable("sdncCallbackUrl")\r
801                         def requestId = execution.getVariable("msoRequestId")\r
802                         def serviceId = execution.getVariable("productFamilyId")\r
803                         def subscriptionServiceType = execution.getVariable("subscriptionServiceType")\r
804                         def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId\r
805 \r
806                         String serviceModelInfo = execution.getVariable("serviceModelInfo")\r
807                         def modelInvariantUuid = ""\r
808                         def modelVersion = ""\r
809                         def modelUuid = ""\r
810                         def modelName = ""\r
811                         if (!isBlank(serviceModelInfo))\r
812                         {\r
813                                 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")\r
814                                 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")\r
815                                 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")\r
816                                 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")\r
817 \r
818                                 if (modelInvariantUuid == null) {\r
819                                         modelInvariantUuid = ""\r
820                                 }\r
821                                 if (modelVersion == null) {\r
822                                         modelVersion = ""\r
823                                 }\r
824                                 if (modelUuid == null) {\r
825                                         modelUuid = ""\r
826                                 }\r
827                                 if (modelName == null) {\r
828                                         modelName = ""\r
829                                 }\r
830                         }\r
831                         if (serviceInstanceName == null) {\r
832                                 serviceInstanceName = ""\r
833                         }\r
834                         if (serviceId == null) {\r
835                                 serviceId = ""\r
836                         }\r
837 \r
838                         def siParamsXml = execution.getVariable("siParamsXml")\r
839                         def serviceType = execution.getVariable("serviceType")\r
840                         if (serviceType == null)\r
841                         {\r
842                                 serviceType = ""\r
843                         }\r
844 \r
845                         def sdncRequestId = UUID.randomUUID().toString()\r
846 \r
847                         String sdncDelete =\r
848                                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"\r
849                                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"\r
850                                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">\r
851                                    <sdncadapter:RequestHeader>\r
852                                                         <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>\r
853                                                         <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>\r
854                                                         <sdncadapter:SvcAction>delete</sdncadapter:SvcAction>\r
855                                                         <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>\r
856                                                         <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>\r
857                                                         <sdncadapter:MsoAction>${serviceType}</sdncadapter:MsoAction>\r
858                                         </sdncadapter:RequestHeader>\r
859                                 <sdncadapterworkflow:SDNCRequestData>\r
860                                         <request-information>\r
861                                                 <request-id>${requestId}</request-id>\r
862                                                 <source>MSO</source>\r
863                                                 <notification-url/>\r
864                                                 <order-number/>\r
865                                                 <order-version/>\r
866                                                 <request-action>DeleteServiceInstance</request-action>\r
867                                         </request-information>\r
868                                         <service-information>\r
869                                                 <service-id>${serviceId}</service-id>\r
870                                                 <subscription-service-type>${subscriptionServiceType}</subscription-service-type>\r
871                                                 <onap-model-information>\r
872                                                  <model-invariant-uuid>${modelInvariantUuid}</model-invariant-uuid>\r
873                                                  <model-uuid>${modelUuid}</model-uuid>\r
874                                                  <model-version>${modelVersion}</model-version>\r
875                                                  <model-name>${modelName}</model-name>\r
876                                             </onap-model-information>\r
877                                                 <service-instance-id>${serviceInstanceId}</service-instance-id>\r
878                                                 <subscriber-name/>\r
879                                                 <global-customer-id>${globalSubscriberId}</global-customer-id>\r
880                                         </service-information>\r
881                                         <service-request-input>\r
882                                                 <service-instance-name>${serviceInstanceName}</service-instance-name>\r
883                                                 ${siParamsXml}\r
884                                         </service-request-input>\r
885                                 </sdncadapterworkflow:SDNCRequestData>\r
886                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""\r
887 \r
888                         sdncDelete = utils.formatXml(sdncDelete)\r
889                         def sdncRequestId2 = UUID.randomUUID().toString()\r
890                         String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")\r
891                         execution.setVariable("sdncDelete", sdncDelete)\r
892                         execution.setVariable("sdncDeactivate", sdncDeactivate)\r
893                         utils.log("INFO","sdncDeactivate:\n" + sdncDeactivate, isDebugEnabled)\r
894                         utils.log("INFO","sdncDelete:\n" + sdncDelete, isDebugEnabled)\r
895 \r
896                 } catch (BpmnError e) {\r
897                         throw e;\r
898                 } catch(Exception ex) {\r
899                         msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()\r
900                         utils.log("INFO", msg, isDebugEnabled)\r
901                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception Occured in preProcessSDNCDelete.\n" + ex.getMessage())\r
902                 }\r
903                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
904         }\r
905 \r
906         public void postProcessSDNCDelete(DelegateExecution execution, String response, String action) {\r
907 \r
908                 def method = getClass().getSimpleName() + '.postProcessSDNCDelete(' +'execution=' + execution.getId() +')'\r
909                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
910                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
911                 utils.log("INFO"," ***** postProcessSDNC " + action + " *****", isDebugEnabled)\r
912                 String msg = ""\r
913 \r
914                 /*try {\r
915                         WorkflowException workflowException = execution.getVariable("WorkflowException")\r
916                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")\r
917                         utils.log("INFO", "SDNCResponse: " + response, isDebugEnabled)\r
918                         utils.log("INFO", "workflowException: " + workflowException, isDebugEnabled)\r
919 \r
920                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)\r
921                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)\r
922                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == "true"){\r
923                                 utils.log("INFO","Good response from SDNC Adapter for service-instance " + action + "response:\n" + response, isDebugEnabled)\r
924 \r
925                         }else{\r
926                                 msg = "Bad Response from SDNC Adapter for service-instance " + action\r
927                                 utils.log("INFO", msg, isDebugEnabled)\r
928                                 exceptionUtil.buildAndThrowWorkflowException(execution, 3500, msg)\r
929                         }\r
930                 } catch (BpmnError e) {\r
931                         throw e;\r
932                 } catch(Exception ex) {\r
933                         msg = "Exception in postProcessSDNC " + action + " Exception:" + ex.getMessage()\r
934                         utils.log("INFO", msg, isDebugEnabled)\r
935                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
936                 }*/\r
937                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
938         }\r
939         \r
940         public void postProcessAAIDEL(DelegateExecution execution) {\r
941                 def method = getClass().getSimpleName() + '.postProcessAAIDEL(' +'execution=' + execution.getId() +')'\r
942                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
943                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
944                 utils.log("INFO"," ***** postProcessAAIDEL ***** ", isDebugEnabled)\r
945                 String msg = ""\r
946                 try {\r
947                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
948                         boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")\r
949                         if(!succInAAI){\r
950                                 msg = "Error deleting Service-instance in AAI" + serviceInstanceId\r
951                                 utils.log("INFO", msg, isDebugEnabled)\r
952                                 WorkflowException workflowException = execution.getVariable("WorkflowException")\r
953                                 utils.logAudit("workflowException: " + workflowException)\r
954                                 if(workflowException != null){\r
955                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())\r
956                                 }\r
957                                 else\r
958                                 {\r
959                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)\r
960                                 }\r
961                         }\r
962                 } catch (BpmnError e) {\r
963                         throw e;\r
964                 } catch (Exception ex) {\r
965                         msg = "Exception in DoDeleteE2EServiceInstance.postProcessAAIDEL. " + ex.getMessage()\r
966                         utils.log("INFO", msg, isDebugEnabled)\r
967                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
968                 }\r
969                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
970         }\r
971         /**\r
972          * Init the service Operation Status\r
973          */\r
974         public void preUpdateServiceOperationStatus(DelegateExecution execution){\r
975         def method = getClass().getSimpleName() + '.preUpdateServiceOperationStatus(' +'execution=' + execution.getId() +')'\r
976                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
977                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
978         \r
979         try{\r
980             String serviceId = execution.getVariable("serviceInstanceId")\r
981             String operationId = execution.getVariable("operationId")\r
982             String serviceName = execution.getVariable("serviceInstanceName")\r
983             String operationType = "DELETE"\r
984             String userId = ""\r
985             String result = "processing"\r
986             String progress = execution.getVariable("progress")\r
987                         utils.log("INFO", "progress: " + progress , isDebugEnabled)\r
988                         if ("100".equalsIgnoreCase(progress))\r
989                         {\r
990                                 result = "finished"\r
991                         }\r
992             String reason = ""\r
993             String operationContent = "Prepare service delete: " + execution.getVariable("operationStatus")\r
994             utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)\r
995             serviceId = UriUtils.encode(serviceId,"UTF-8")\r
996             execution.setVariable("serviceInstanceId", serviceId)\r
997             execution.setVariable("operationId", operationId)\r
998             execution.setVariable("operationType", operationType)\r
999 \r
1000             def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")\r
1001             execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)\r
1002             utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)\r
1003 \r
1004             execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")\r
1005                         \r
1006                         String payload =\r
1007                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
1008                         xmlns:ns="http://org.openecomp.mso/requestsdb">\r
1009                         <soapenv:Header/>\r
1010                         <soapenv:Body>\r
1011                             <ns:updateServiceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">\r
1012                             <serviceId>${serviceId}</serviceId>\r
1013                             <operationId>${operationId}</operationId>\r
1014                             <serviceName>${serviceName}</serviceName>\r
1015                             <operationType>${operationType}</operationType>\r
1016                             <userId>${userId}</userId>\r
1017                             <result>${result}</result>\r
1018                             <operationContent>${operationContent}</operationContent>\r
1019                             <progress>${progress}</progress>\r
1020                             <reason>${reason}</reason>\r
1021                         </ns:updateServiceOperationStatus>\r
1022                     </soapenv:Body>\r
1023                 </soapenv:Envelope>"""\r
1024 \r
1025             payload = utils.formatXml(payload)\r
1026             execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)\r
1027             utils.log("INFO", "Outgoing preUpdateServiceOperationStatus: \n" + payload, isDebugEnabled)\r
1028            \r
1029 \r
1030         }catch(Exception e){\r
1031             utils.log("ERROR", "Exception Occured Processing preUpdateServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)\r
1032             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preUpdateServiceOperationStatus Method:\n" + e.getMessage())\r
1033         }\r
1034         utils.log("INFO", "======== COMPLETED preUpdateServiceOperationStatus Process ======== ", isDebugEnabled)  \r
1035         utils.log("INFO", "Exited " + method, isDebugEnabled)\r
1036         }\r
1037         \r
1038         public void preInitResourcesOperStatus(DelegateExecution execution){\r
1039         def method = getClass().getSimpleName() + '.preInitResourcesOperStatus(' +'execution=' + execution.getId() +')'\r
1040                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
1041                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
1042 \r
1043         utils.log("INFO", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)\r
1044                 String msg=""\r
1045         try{\r
1046             String serviceId = execution.getVariable("serviceInstanceId")\r
1047             String operationId = execution.getVariable("operationId")\r
1048             String operationType = "DELETE"\r
1049             String resourceTemplateUUIDs = ""\r
1050             String result = "processing"\r
1051             String progress = "0"\r
1052             String reason = ""\r
1053             String operationContent = "Prepare service delete"\r
1054             utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)\r
1055             serviceId = UriUtils.encode(serviceId,"UTF-8")\r
1056             execution.setVariable("serviceInstanceId", serviceId)\r
1057             execution.setVariable("operationId", operationId)\r
1058             execution.setVariable("operationType", operationType)\r
1059 \r
1060             String serviceRelationShip = execution.getVariable("serviceRelationShip")\r
1061             utils.log("INFO", "serviceRelationShip: " + serviceRelationShip, isDebugEnabled)\r
1062                         if (! isBlank(serviceRelationShip)) {\r
1063                 def jsonSlurper = new JsonSlurper()\r
1064                 def jsonOutput = new JsonOutput()         \r
1065                 List relationShipList =  jsonSlurper.parseText(serviceRelationShip)\r
1066                     \r
1067                 if (relationShipList != null) {\r
1068                     relationShipList.each {\r
1069                         resourceTemplateUUIDs  = resourceTemplateUUIDs + it.resourceInstanceId + ":"\r
1070                     }\r
1071                 }\r
1072             }                   \r
1073             def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"\r
1074             execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)\r
1075             utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)\r
1076 \r
1077             String payload =\r
1078                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
1079                         xmlns:ns="http://org.openecomp.mso/requestsdb">\r
1080                         <soapenv:Header/>\r
1081                         <soapenv:Body>\r
1082                             <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">\r
1083                             <serviceId>${serviceId}</serviceId>\r
1084                             <operationId>${operationId}</operationId>\r
1085                             <operationType>${operationType}</operationType>\r
1086                             <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>\r
1087                         </ns:initResourceOperationStatus>\r
1088                     </soapenv:Body>\r
1089                 </soapenv:Envelope>"""\r
1090 \r
1091             payload = utils.formatXml(payload)\r
1092             execution.setVariable("CVFMI_initResOperStatusRequest", payload)\r
1093             utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)\r
1094             utils.logAudit("DoCustomDeleteE2EServiceInstanceV2 Outgoing initResourceOperationStatus Request: " + payload)\r
1095 \r
1096                 }catch (BpmnError e) {\r
1097                         throw e;\r
1098                 } catch (Exception ex) {\r
1099                         msg = "Exception in DoCustomDeleteE2EServiceInstanceV2.preInitResourcesOperStatus. " + ex.getMessage()\r
1100                         utils.log("INFO", msg, isDebugEnabled)\r
1101                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
1102                 }\r
1103         utils.log("INFO", "Exited " + method, isDebugEnabled)  \r
1104     }\r
1105     \r
1106 \r
1107    \r
1108         /**\r
1109     * prepare delete parameters\r
1110     */\r
1111         public void preProcessVFCResourceDelete(execution){\r
1112                 // we use resource instance ids for delete flow as resourceTemplateUUIDs\r
1113 \r
1114                 def method = getClass().getSimpleName() + '.preProcessVFCResourceDelete(' +'execution=' + execution.getId() +')'\r
1115                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
1116                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
1117 \r
1118                 utils.log("INFO", " ======== STARTED preProcessVFCResourceDelete Process ======== ", isDebugEnabled)\r
1119                 try{\r
1120                         String serviceResource = execution.getVariable("serviceResource")  \r
1121                         utils.log("INFO", "serviceResource : " + serviceResource, isDebugEnabled)\r
1122                                                 \r
1123                         String resourceInstanceId  =  execution.getVariable("resourceInstanceId")\r
1124                         utils.log("INFO", "resourceInstanceId : " + resourceInstanceId, isDebugEnabled)\r
1125                         \r
1126                         execution.setVariable("resourceTemplateId", resourceInstanceId)\r
1127                         utils.log("INFO", "resourceTemplateId : " + resourceInstanceId, isDebugEnabled)\r
1128                         \r
1129                         String resourceType = execution.getVariable("resourceType")\r
1130                         utils.log("INFO", "resourceType : " + resourceType, isDebugEnabled)\r
1131 \r
1132                         \r
1133                         String resourceName = execution.getVariable(Prefix+"resourceName") \r
1134                         if (isBlank(resourceName)){\r
1135                                 resourceName = resourceInstanceId\r
1136                         }\r
1137                         execution.setVariable("resourceName", resourceName)\r
1138                         utils.log("INFO", "resource Name : " + resourceName, isDebugEnabled)\r
1139                 \r
1140                         utils.log("INFO", "Delete Resource Info: resourceInstanceId :" + resourceInstanceId + "  resourceTemplateId: " + resourceInstanceId + " resourceType: " + resourceType, isDebugEnabled)\r
1141                 }catch (BpmnError e) {\r
1142                         throw e;\r
1143                 } catch (Exception ex) {\r
1144                         msg = "Exception in DoDeleteE2EServiceInstance.preProcessVFCResourceDelete. " + ex.getMessage()\r
1145                         utils.log("INFO", msg, isDebugEnabled)\r
1146                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
1147                 }\r
1148                 utils.log("INFO", "Exited " + method, isDebugEnabled)  \r
1149         }\r
1150 \r
1151         public void postProcessVFCDelete(DelegateExecution execution, String response, String action) {\r
1152                 def method = getClass().getSimpleName() + '.postProcessVFCDelete(' +'execution=' + execution.getId() +')'\r
1153                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
1154                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
1155 \r
1156                 utils.log("INFO", " ======== STARTED postProcessVFCDelete Process ======== ", isDebugEnabled)\r
1157                 try{\r
1158                 \r
1159                 }catch (BpmnError e) {\r
1160                         throw e;\r
1161                 } catch (Exception ex) {\r
1162                         msg = "Exception in DoDeleteE2EServiceInstance.postProcessVFCDelete. " + ex.getMessage()\r
1163                         utils.log("INFO", msg, isDebugEnabled)\r
1164                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
1165                 }\r
1166                 utils.log("INFO", "Exited " + method, isDebugEnabled)  \r
1167         }\r
1168 }\r
1169  \r