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