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