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