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