fix issues in e2e delete groovy flow
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoCustomDeleteE2EServiceInstance.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.openecomp.mso.bpmn.infrastructure.scripts
22
23 import org.json.JSONArray;
24
25 import static org.apache.commons.lang3.StringUtils.*;
26 import groovy.xml.XmlUtil
27 import groovy.json.*
28
29 import org.openecomp.mso.bpmn.core.json.JsonUtils
30 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
31 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
32 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
33 import org.openecomp.mso.bpmn.core.WorkflowException
34 import org.openecomp.mso.rest.APIResponse;
35 import org.openecomp.mso.rest.RESTClient
36 import org.openecomp.mso.rest.RESTConfig
37
38 import java.util.UUID;
39 import javax.xml.parsers.DocumentBuilder
40 import javax.xml.parsers.DocumentBuilderFactory
41
42 import org.camunda.bpm.engine.delegate.BpmnError
43 import org.camunda.bpm.engine.runtime.Execution
44 import org.json.JSONObject;
45 import org.apache.commons.lang3.*
46 import org.apache.commons.codec.binary.Base64;
47 import org.springframework.web.util.UriUtils;
48 import org.w3c.dom.Document
49 import org.w3c.dom.Element
50 import org.w3c.dom.Node
51 import org.w3c.dom.NodeList
52 import org.xml.sax.InputSource
53
54 /**
55  * This groovy class supports the <class>DoDeleteE2EServiceInstance.bpmn</class> process.
56  * 
57  * Inputs:
58  * @param - msoRequestId
59  * @param - globalSubscriberId - O
60  * @param - subscriptionServiceType - O
61  * @param - serviceInstanceId
62  * @param - serviceInstanceName - O
63  * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
64  * @param - sdncVersion 
65  * @param - failNotFound - TODO
66  * @param - serviceInputParams - TODO
67  *
68  * Outputs:
69  * @param - WorkflowException
70  * 
71  * Rollback - Deferred
72  */
73 public class DoCustomDeleteE2EServiceInstance extends AbstractServiceTaskProcessor {
74
75         String Prefix="DDELSI_"
76         ExceptionUtil exceptionUtil = new ExceptionUtil()
77         JsonUtils jsonUtil = new JsonUtils()
78
79         public void preProcessRequest (Execution execution) {
80                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
81                 utils.log("DEBUG"," ***** preProcessRequest *****",  isDebugEnabled)
82                 String msg = ""
83
84                 try {
85                         String requestId = execution.getVariable("msoRequestId")
86                         execution.setVariable("prefix",Prefix)
87
88                         //Inputs
89                         //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
90                         String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
91                         if (globalSubscriberId == null)
92                         {
93                                 execution.setVariable("globalSubscriberId", "")
94                         }
95
96                         //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
97                         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
98                         if (subscriptionServiceType == null)
99                         {
100                                 execution.setVariable("subscriptionServiceType", "")
101                         }
102
103                         //Generated in parent for AAI PUT
104                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
105                         if (isBlank(serviceInstanceId)){
106                                 msg = "Input serviceInstanceId is null"
107                                 utils.log("DEBUG", msg, isDebugEnabled)
108                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
109                         }
110
111                         String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
112                         if (isBlank(sdncCallbackUrl)) {
113                                 msg = "URN_mso_workflow_sdncadapter_callback is null"
114                                 utils.log("DEBUG", msg, isDebugEnabled)
115                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
116                         }
117                         execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
118                         utils.log("DEBUG","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
119
120                         StringBuilder sbParams = new StringBuilder()
121                         Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
122                         if (paramsMap != null)
123                         {
124                                 sbParams.append("<service-input-parameters>")
125                                 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
126                                         String paramsXml
127                                         String paramName = entry.getKey()
128                                         String paramValue = entry.getValue()
129                                         paramsXml =
130                                                         """     <param>
131                                                         <name>${paramName}</name>
132                                                         <value>${paramValue}</value>
133                                                         </param>
134                                                         """
135                                         sbParams.append(paramsXml)
136                                 }
137                                 sbParams.append("</service-input-parameters>")
138                         }
139                         String siParamsXml = sbParams.toString()
140                         if (siParamsXml == null)
141                                 siParamsXml = ""
142                         execution.setVariable("siParamsXml", siParamsXml)
143
144                 } catch (BpmnError e) {
145                         throw e;
146                 } catch (Exception ex){
147                         msg = "Exception in preProcessRequest " + ex.getMessage()
148                         utils.log("DEBUG", msg, isDebugEnabled)
149                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
150                 }
151                 utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)
152         }
153         
154
155         public void preProcessVFCDelete (Execution execution) {
156         }
157         
158         public void postProcessVFCDelete(Execution execution, String response, String method) {
159         }
160         
161         public void preProcessSDNCDelete (Execution execution) {
162                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
163                 utils.log("DEBUG"," ***** preProcessSDNCDelete *****", isDebugEnabled)
164                 String msg = ""
165
166                 try {
167                         def serviceInstanceId = execution.getVariable("serviceInstanceId")
168                         def serviceInstanceName = execution.getVariable("serviceInstanceName")
169                         def callbackURL = execution.getVariable("sdncCallbackUrl")
170                         def requestId = execution.getVariable("msoRequestId")
171                         def serviceId = execution.getVariable("productFamilyId")
172                         def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
173                         def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
174
175                         String serviceModelInfo = execution.getVariable("serviceModelInfo")
176                         def modelInvariantUuid = ""
177                         def modelVersion = ""
178                         def modelUuid = ""
179                         def modelName = ""
180                         if (!isBlank(serviceModelInfo))
181                         {
182                                 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
183                                 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")
184                                 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")
185                                 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")
186
187                                 if (modelInvariantUuid == null) {
188                                         modelInvariantUuid = ""
189                                 }
190                                 if (modelVersion == null) {
191                                         modelVersion = ""
192                                 }
193                                 if (modelUuid == null) {
194                                         modelUuid = ""
195                                 }
196                                 if (modelName == null) {
197                                         modelName = ""
198                                 }
199                         }
200                         if (serviceInstanceName == null) {
201                                 serviceInstanceName = ""
202                         }
203                         if (serviceId == null) {
204                                 serviceId = ""
205                         }
206
207                         def siParamsXml = execution.getVariable("siParamsXml")
208                         def serviceType = execution.getVariable("serviceType")
209                         if (serviceType == null)
210                         {
211                                 serviceType = ""
212                         }
213
214                         def sdncRequestId = UUID.randomUUID().toString()
215
216                         String sdncDelete =
217                                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
218                                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
219                                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
220                                    <sdncadapter:RequestHeader>
221                                                         <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>
222                                                         <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
223                                                         <sdncadapter:SvcAction>delete</sdncadapter:SvcAction>
224                                                         <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
225                                                         <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
226                                                         <sdncadapter:MsoAction>${serviceType}</sdncadapter:MsoAction>
227                                         </sdncadapter:RequestHeader>
228                                 <sdncadapterworkflow:SDNCRequestData>
229                                         <request-information>
230                                                 <request-id>${requestId}</request-id>
231                                                 <source>MSO</source>
232                                                 <notification-url/>
233                                                 <order-number/>
234                                                 <order-version/>
235                                                 <request-action>DeleteServiceInstance</request-action>
236                                         </request-information>
237                                         <service-information>
238                                                 <service-id>${serviceId}</service-id>
239                                                 <subscription-service-type>${subscriptionServiceType}</subscription-service-type>
240                                                 <onap-model-information>
241                                                  <model-invariant-uuid>${modelInvariantUuid}</model-invariant-uuid>
242                                                  <model-uuid>${modelUuid}</model-uuid>
243                                                  <model-version>${modelVersion}</model-version>
244                                                  <model-name>${modelName}</model-name>
245                                             </onap-model-information>
246                                                 <service-instance-id>${serviceInstanceId}</service-instance-id>
247                                                 <subscriber-name/>
248                                                 <global-customer-id>${globalSubscriberId}</global-customer-id>
249                                         </service-information>
250                                         <service-request-input>
251                                                 <service-instance-name>${serviceInstanceName}</service-instance-name>
252                                                 ${siParamsXml}
253                                         </service-request-input>
254                                 </sdncadapterworkflow:SDNCRequestData>
255                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
256
257                         sdncDelete = utils.formatXml(sdncDelete)
258                         def sdncRequestId2 = UUID.randomUUID().toString()
259                         String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
260                         execution.setVariable("sdncDelete", sdncDelete)
261                         execution.setVariable("sdncDeactivate", sdncDeactivate)
262                         utils.log("DEBUG","sdncDeactivate:\n" + sdncDeactivate, isDebugEnabled)
263                         utils.log("DEBUG","sdncDelete:\n" + sdncDelete, isDebugEnabled)
264
265                 } catch (BpmnError e) {
266                         throw e;
267                 } catch(Exception ex) {
268                         msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
269                         utils.log("DEBUG", msg, isDebugEnabled)
270                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception Occured in preProcessSDNCDelete.\n" + ex.getMessage())
271                 }
272                 utils.log("DEBUG"," *****Exit preProcessSDNCDelete *****", isDebugEnabled)
273         }
274
275         public void postProcessSDNCDelete(Execution execution, String response, String method) {
276
277                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
278                 utils.log("DEBUG"," ***** postProcessSDNC " + method + " *****", isDebugEnabled)
279                 String msg = ""
280
281                 try {
282                         WorkflowException workflowException = execution.getVariable("WorkflowException")
283                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
284                         utils.log("DEBUG", "SDNCResponse: " + response, isDebugEnabled)
285                         utils.log("DEBUG", "workflowException: " + workflowException, isDebugEnabled)
286
287                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
288                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
289                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == "true"){
290                                 utils.log("DEBUG","Good response from SDNC Adapter for service-instance " + method + "response:\n" + response, isDebugEnabled)
291
292                         }else{
293                                 msg = "Bad Response from SDNC Adapter for service-instance " + method
294                                 utils.log("DEBUG", msg, isDebugEnabled)
295                                 exceptionUtil.buildAndThrowWorkflowException(execution, 3500, msg)
296                         }
297                 } catch (BpmnError e) {
298                         throw e;
299                 } catch(Exception ex) {
300                         msg = "Exception in postProcessSDNC " + method + " Exception:" + ex.getMessage()
301                         utils.log("DEBUG", msg, isDebugEnabled)
302                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
303                 }
304                 utils.log("DEBUG"," *** Exit postProcessSDNC " + method + " ***", isDebugEnabled)
305         }
306
307         public void postProcessAAIGET(Execution execution) {
308                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
309                 utils.log("DEBUG"," ***** postProcessAAIGET ***** ", isDebugEnabled)
310                 String msg = ""
311
312                 try {
313                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
314                         boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
315                         String serviceType = ""
316
317                         if(foundInAAI == true){
318                                 utils.log("DEBUG","Found Service-instance in AAI", isDebugEnabled)
319
320                                 //Extract GlobalSubscriberId
321                                 String siRelatedLink = execution.getVariable("GENGS_siResourceLink")
322                                 if (isBlank(siRelatedLink))
323                                 {
324                                         msg = "Could not retrive ServiceInstance data from AAI to delete id:" + serviceInstanceId
325                                         utils.log("DEBUG", msg, isDebugEnabled)
326                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
327                                 }
328                                 else
329                                 {
330                                         utils.log("DEBUG","Found Service-instance in AAI. link: " + siRelatedLink, isDebugEnabled)
331                                         String  globalSubscriberId = execution.getVariable("globalSubscriberId")
332                                         if(isBlank(globalSubscriberId)){
333                                                 int custStart = siRelatedLink.indexOf("customer/")
334                                                 int custEnd = siRelatedLink.indexOf("/service-subscriptions")
335                                                 globalSubscriberId = siRelatedLink.substring(custStart + 9, custEnd)
336                                                 execution.setVariable("globalSubscriberId", globalSubscriberId)
337                                         }
338
339                                         //Extract Service Type if not provided on request
340                                         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
341                                         if(isBlank(subscriptionServiceType)){
342                                                 int serviceStart = siRelatedLink.indexOf("service-subscription/")
343                                                 int serviceEnd = siRelatedLink.indexOf("/service-instances/")
344                                                 String serviceTypeEncoded = siRelatedLink.substring(serviceStart + 21, serviceEnd)
345                                                 subscriptionServiceType = UriUtils.decode(serviceTypeEncoded, "UTF-8")
346                                                 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
347                                         }
348
349                                         if (isBlank(globalSubscriberId) || isBlank(subscriptionServiceType))
350                                         {
351                                                 msg = "Could not retrive global-customer-id & subscription-service-type from AAI to delete id:" + serviceInstanceId
352                                                 utils.log("DEBUG", msg, isDebugEnabled)
353                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
354                                         }
355                                 }
356
357                                 String siData = execution.getVariable("GENGS_service")
358                                 utils.log("DEBUG", "SI Data", isDebugEnabled)
359                                 if (isBlank(siData))
360                                 {
361                                         msg = "Could not retrive ServiceInstance data from AAI to delete id:" + serviceInstanceId
362                                         utils.log("DEBUG", msg, isDebugEnabled)
363                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
364                                 }
365                                 else
366                                 {
367                                         utils.log("DEBUG", "SI Data" + siData, isDebugEnabled)
368                                         serviceType = utils.getNodeText1(siData,"service-type")
369                                         execution.setVariable("serviceType", serviceType)
370                                         execution.setVariable("serviceRole", utils.getNodeText1(siData,"service-role"))
371                                         String orchestrationStatus =  utils.getNodeText1(siData,"orchestration-status")
372
373                                         //Confirm there are no related service instances (vnf/network or volume)
374                                         if (utils.nodeExists(siData, "relationship-list")) {
375                                                 utils.log("DEBUG", "SI Data relationship-list exists:", isDebugEnabled)
376                                                 InputSource source = new InputSource(new StringReader(siData));
377                                                 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
378                                                 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
379                                                 Document serviceXml = docBuilder.parse(source)
380                                                 serviceXml.getDocumentElement().normalize()
381                                                 //test(siData)
382                                                 NodeList nodeList = serviceXml.getElementsByTagName("relationship")
383                                                 for (int x = 0; x < nodeList.getLength(); x++) {
384                                                         Node node = nodeList.item(x)
385                                                         if (node.getNodeType() == Node.ELEMENT_NODE) {
386                                                                 Element eElement = (Element) node
387                                                                 def e = eElement.getElementsByTagName("related-to").item(0).getTextContent()
388                                                                 if(e.equals("generic-vnf") || e.equals("l3-network") || e.equals("allotted-resource") ){
389                                                                         utils.log("DEBUG", "ServiceInstance still has relationship(s) to generic-vnfs, l3-networks or allotted-resources", isDebugEnabled)
390                                                                         execution.setVariable("siInUse", true)
391                                                                         //there are relationship dependencies to this Service Instance
392                                                                         msg = " Stopped deleting Service Instance, it has dependencies. Service instance id: " + serviceInstanceId
393                                                                         utils.log("DEBUG", msg, isDebugEnabled)
394                                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
395                                                                 }else{
396                                                                         NodeList dataList = node.getChildNodes()
397                                                                         if(null != dataList) {
398                                                                                 JSONArray jArray = new JSONArray()
399                                                                                 for (int i = 0; i < dataList.getLength(); i++) {
400                                                                                         Node dNode = dataList.item(i)
401                                                                                         if(dNode.getNodeName() == "relationship-data") {
402                                                                                                 Element rDataEle = (Element)dNode
403
404                                                                                                 def eKey =  rDataEle.getElementsByTagName("relationship-key").item(0).getTextContent()
405                                                                                                 def eValue = rDataEle.getElementsByTagName("relationship-value").item(0).getTextContent()
406
407                                                                                                 JSONObject jObj = new JSONObject()
408                                                                                                 jObj.put("resourceInstanceId", eKey)
409                                                                                                 jObj.put("resourceType", eValue)
410                                                                                                 jArray.put(jObj)
411                                                                                         }
412                                                                                 }
413                                                                                 execution.setVariable("serviceRelationShip", jArray)
414                                                                         }
415                                                                         utils.log("DEBUG", "Relationship NOT related to OpenStack", isDebugEnabled)
416                                                                 }
417                                                         }
418                                                 }
419                                         }
420
421                                         if ("TRANSPORT".equalsIgnoreCase(serviceType))
422                                         {
423                                                 if ("PendingDelete".equals(orchestrationStatus))
424                                                 {
425                                                         execution.setVariable("skipDeactivate", true)
426                                                 }
427                                                 else
428                                                 {
429                                                         msg = "ServiceInstance of type TRANSPORT must in PendingDelete status to allow Delete. Orchestration-status:" + orchestrationStatus
430                                                         utils.log("DEBUG", msg, isDebugEnabled)
431                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
432                                                 }
433
434                                         }
435                                 }
436                         }else{
437                                 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
438                                 if(succInAAI != true){
439                                         utils.log("DEBUG","Error getting Service-instance from AAI", + serviceInstanceId, isDebugEnabled)
440                                         WorkflowException workflowException = execution.getVariable("WorkflowException")
441                                         utils.logAudit("workflowException: " + workflowException)
442                                         if(workflowException != null){
443                                                 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
444                                         }
445                                         else
446                                         {
447                                                 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
448                                                 utils.log("DEBUG", msg, isDebugEnabled)
449                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
450                                         }
451                                 }
452
453                                 utils.log("DEBUG","Service-instance NOT found in AAI. Silent Success", isDebugEnabled)
454                         }
455                 } catch (BpmnError e) {
456                         throw e;
457                 } catch (Exception ex) {
458                         msg = "Exception in DoDeleteE2EServiceInstance.postProcessAAIGET. " + ex.getMessage()
459                         utils.log("DEBUG", msg, isDebugEnabled)
460                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
461                 }
462                 utils.log("DEBUG"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
463         }
464
465         public void postProcessAAIDEL(Execution execution) {
466                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
467                 utils.log("DEBUG"," ***** postProcessAAIDEL ***** ", isDebugEnabled)
468                 String msg = ""
469                 try {
470                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
471                         boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
472                         if(succInAAI != true){
473                                 msg = "Error deleting Service-instance in AAI" + serviceInstanceId
474                                 utils.log("DEBUG", msg, isDebugEnabled)
475                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
476                                 utils.logAudit("workflowException: " + workflowException)
477                                 if(workflowException != null){
478                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
479                                 }
480                                 else
481                                 {
482                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
483                                 }
484                         }
485                 } catch (BpmnError e) {
486                         throw e;
487                 } catch (Exception ex) {
488                         msg = "Exception in DoDeleteE2EServiceInstance.postProcessAAIDEL. " + ex.getMessage()
489                         utils.log("DEBUG", msg, isDebugEnabled)
490                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
491                 }
492                 utils.log("DEBUG"," *** Exit postProcessAAIDEL *** ", isDebugEnabled)
493         }
494         
495         public void preInitResourcesOperStatus(Execution execution){
496         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
497
498         utils.log("DEBUG", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
499         try{
500             String serviceId = execution.getVariable("serviceInstanceId")
501             String operationId = execution.getVariable("operationId")
502             String operationType = execution.getVariable("operationType")
503             String resourceTemplateUUIDs = ""
504             String result = "processing"
505             String progress = "0"
506             String reason = ""
507             String operationContent = "Prepare service creation"
508             utils.log("DEBUG", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)
509             serviceId = UriUtils.encode(serviceId,"UTF-8")
510             execution.setVariable("serviceInstanceId", serviceId)
511             execution.setVariable("operationId", operationId)
512             execution.setVariable("operationType", operationType)
513             // we use resource instance ids for delete flow as resourceTemplateUUIDs
514             /*[
515              {
516                  "resourceInstanceId":"1111",
517                  "resourceType":"vIMS"
518              },
519              {
520                  "resourceInstanceId":"222",
521                  "resourceType":"vEPC"
522              },
523              {
524                  "resourceInstanceId":"3333",
525                  "resourceType":"overlay"
526              },
527              {
528                  "resourceInstanceId":"4444",
529                  "resourceType":"underlay"
530              }
531          ]*/
532             String serviceRelationShip = execution.getVariable("serviceRelationShip")
533             
534             def jsonSlurper = new JsonSlurper()
535             def jsonOutput = new JsonOutput()         
536             List relationShipList =  jsonSlurper.parseText(serviceRelationShip)
537                     
538             if (relationShipList != null) {
539                 relationShipList.each {
540                     resourceTemplateUUIDs  = resourceTemplateUUIDs + it.resourceInstanceId + ":"
541                 }
542             }           
543
544             def dbAdapterEndpoint = execution.getVariable("URN_mso_openecomp_adapters_db_endpoint")
545             execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
546             utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
547
548             String payload =
549                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
550                         xmlns:ns="http://org.openecomp.mso/requestsdb">
551                         <soapenv:Header/>
552                         <soapenv:Body>
553                             <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
554                             <serviceId>${serviceId}</serviceId>
555                             <operationId>${operationId}</operationId>
556                             <operationType>${operationType}</operationType>
557                             <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>
558                         </ns:initResourceOperationStatus>
559                     </soapenv:Body>
560                 </soapenv:Envelope>"""
561
562             payload = utils.formatXml(payload)
563             execution.setVariable("CVFMI_initResOperStatusRequest", payload)
564             utils.log("DEBUG", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)
565             utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
566
567         }catch(Exception e){
568             utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)
569             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
570         }
571         utils.log("DEBUG", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)  
572     }
573     
574    /**
575     * prepare delete parameters
576     */
577    public void preResourceDelete(execution, resourceName){
578        // we use resource instance ids for delete flow as resourceTemplateUUIDs
579        /*[
580         {
581             "resourceInstanceId":"1111",
582             "resourceType":"vIMS"
583         },
584         {
585             "resourceInstanceId":"222",
586             "resourceType":"vEPC"
587         },
588         {
589             "resourceInstanceId":"3333",
590             "resourceType":"overlay"
591         },
592         {
593             "resourceInstanceId":"4444",
594             "resourceType":"underlay"
595         }
596     ]*/
597        String serviceRelationShip = execution.getVariable("serviceRelationShip")       
598        def jsonSlurper = new JsonSlurper()
599        def jsonOutput = new JsonOutput()         
600        List relationShipList =  jsonSlurper.parseText(serviceRelationShip)
601                
602        if (relationShipList != null) {
603            relationShipList.each {
604                if(resourceName.equals(it.resourceType)) {
605                                    String resourceInstanceUUID = it.resourceInstanceId
606                                    String resourceTemplateUUID = it.resourceInstanceId
607                                    execution.setVariable("resourceTemplateId", resourceTemplateUUID)
608                                    execution.setVariable("resourceInstanceId", resourceInstanceUUID)
609                                    execution.setVariable("resourceType", resourceName)
610                            }
611            }
612        }    
613    }
614 }