8ab8d610198cfafe691a8f502d898b9f95074051
[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 static org.apache.commons.lang3.StringUtils.*;
24 import groovy.xml.XmlUtil
25 import groovy.json.*
26
27 import org.openecomp.mso.bpmn.core.json.JsonUtils
28 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
30 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
31 import org.openecomp.mso.bpmn.core.WorkflowException
32 import org.openecomp.mso.rest.APIResponse;
33 import org.openecomp.mso.rest.RESTClient
34 import org.openecomp.mso.rest.RESTConfig
35
36 import java.util.UUID;
37 import javax.xml.parsers.DocumentBuilder
38 import javax.xml.parsers.DocumentBuilderFactory
39
40 import org.camunda.bpm.engine.delegate.BpmnError
41 import org.camunda.bpm.engine.runtime.Execution
42 import org.json.JSONObject;
43 import org.apache.commons.lang3.*
44 import org.apache.commons.codec.binary.Base64;
45 import org.springframework.web.util.UriUtils;
46 import org.w3c.dom.Document
47 import org.w3c.dom.Element
48 import org.w3c.dom.Node
49 import org.w3c.dom.NodeList
50 import org.xml.sax.InputSource
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 - serviceModelInfo - O
62  * @param - productFamilyId
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 DoDeleteE2EServiceInstance 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                                                 <ecomp-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                                             </ecomp-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
290                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
291                                 utils.log("DEBUG","Good response from SDNC Adapter for service-instance " + method + "response:\n" + response, isDebugEnabled)
292
293                         }else{
294                                 msg = "Bad Response from SDNC Adapter for service-instance " + method
295                                 utils.log("DEBUG", msg, isDebugEnabled)
296                                 exceptionUtil.buildAndThrowWorkflowException(execution, 3500, msg)
297                         }
298                 } catch (BpmnError e) {
299                         throw e;
300                 } catch(Exception ex) {
301                         msg = "Exception in postProcessSDNC " + method + " Exception:" + ex.getMessage()
302                         utils.log("DEBUG", msg, isDebugEnabled)
303                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
304                 }
305                 utils.log("DEBUG"," *** Exit postProcessSDNC " + method + " ***", isDebugEnabled)
306         }
307
308         public void postProcessAAIGET(Execution execution) {
309                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
310                 utils.log("DEBUG"," ***** postProcessAAIGET ***** ", isDebugEnabled)
311                 String msg = ""
312
313                 try {
314
315                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
316                         boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
317                         String serviceType = ""
318
319                         if(foundInAAI == true){
320                                 utils.log("DEBUG","Found Service-instance in AAI", isDebugEnabled)
321
322                                 //Extract GlobalSubscriberId
323                                 String siRelatedLink = execution.getVariable("GENGS_siResourceLink")
324                                 if (isBlank(siRelatedLink))
325                                 {
326                                         msg = "Could not retrive ServiceInstance data from AAI to delete id:" + serviceInstanceId
327                                         utils.log("DEBUG", msg, isDebugEnabled)
328                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
329                                 }
330                                 else
331                                 {
332                                         utils.log("DEBUG","Found Service-instance in AAI. link: " + siRelatedLink, isDebugEnabled)
333                                         String  globalSubscriberId = execution.getVariable("globalSubscriberId")
334                                         if(isBlank(globalSubscriberId)){
335                                                 int custStart = siRelatedLink.indexOf("customer/")
336                                                 int custEnd = siRelatedLink.indexOf("/service-subscriptions")
337                                                 globalSubscriberId = siRelatedLink.substring(custStart + 9, custEnd)
338                                                 execution.setVariable("globalSubscriberId", globalSubscriberId)
339                                         }
340
341                                         //Extract Service Type if not provided on request
342                                         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
343                                         if(isBlank(subscriptionServiceType)){
344                                                 int serviceStart = siRelatedLink.indexOf("service-subscription/")
345                                                 int serviceEnd = siRelatedLink.indexOf("/service-instances/")
346                                                 String serviceTypeEncoded = siRelatedLink.substring(serviceStart + 21, serviceEnd)
347                                                 subscriptionServiceType = UriUtils.decode(serviceTypeEncoded, "UTF-8")
348                                                 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
349                                         }
350
351                                         if (isBlank(globalSubscriberId) || isBlank(subscriptionServiceType))
352                                         {
353                                                 msg = "Could not retrive global-customer-id & subscription-service-type from AAI to delete id:" + serviceInstanceId
354                                                 utils.log("DEBUG", msg, isDebugEnabled)
355                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
356                                         }
357                                 }
358
359                                 String siData = execution.getVariable("GENGS_service")
360                                 utils.log("DEBUG", "SI Data", isDebugEnabled)
361                                 if (isBlank(siData))
362                                 {
363                                         msg = "Could not retrive ServiceInstance data from AAI to delete id:" + serviceInstanceId
364                                         utils.log("DEBUG", msg, isDebugEnabled)
365                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
366                                 }
367                                 else
368                                 {
369                                         utils.log("DEBUG", "SI Data" + siData, isDebugEnabled)
370                                         serviceType = utils.getNodeText1(siData,"service-type")
371                                         execution.setVariable("serviceType", serviceType)
372                                         execution.setVariable("serviceRole", utils.getNodeText1(siData,"service-role"))
373                                         String orchestrationStatus =  utils.getNodeText1(siData,"orchestration-status")
374
375                                         //Confirm there are no related service instances (vnf/network or volume)
376                                         if (utils.nodeExists(siData, "relationship-list")) {
377                                                 utils.log("DEBUG", "SI Data relationship-list exists:", isDebugEnabled)
378                                                 InputSource source = new InputSource(new StringReader(siData));
379                                                 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
380                                                 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
381                                                 Document serviceXml = docBuilder.parse(source)
382
383                                                 NodeList nodeList = serviceXml.getElementsByTagName("relationship")
384                                                 for (int x = 0; x < nodeList.getLength(); x++) {
385                                                         Node node = nodeList.item(x)
386                                                         if (node.getNodeType() == Node.ELEMENT_NODE) {
387                                                                 Element eElement = (Element) node
388                                                                 def e = eElement.getElementsByTagName("related-to").item(0).getTextContent()
389                                                                 if(e.equals("generic-vnf") || e.equals("l3-network") || e.equals("allotted-resource") ){
390                                                                         utils.log("DEBUG", "ServiceInstance still has relationship(s) to generic-vnfs, l3-networks or allotted-resources", isDebugEnabled)
391                                                                         execution.setVariable("siInUse", true)
392                                                                         //there are relationship dependencies to this Service Instance
393                                                                         msg = " Stopped deleting Service Instance, it has dependencies. Service instance id: " + serviceInstanceId
394                                                                         utils.log("DEBUG", msg, isDebugEnabled)
395                                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
396                                                                 }else{
397                                                                         utils.log("DEBUG", "Relationship NOT related to OpenStack", isDebugEnabled)
398                                                                 }
399                                                         }
400                                                 }
401                                         }
402
403                                         if ("TRANSPORT".equalsIgnoreCase(serviceType))
404                                         {
405                                                 if ("PendingDelete".equals(orchestrationStatus))
406                                                 {
407                                                         execution.setVariable("skipDeactivate", true)
408                                                 }
409                                                 else
410                                                 {
411                                                         msg = "ServiceInstance of type TRANSPORT must in PendingDelete status to allow Delete. Orchestration-status:" + orchestrationStatus
412                                                         utils.log("DEBUG", msg, isDebugEnabled)
413                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
414                                                 }
415
416                                         }
417                                 }
418                         }else{
419                                 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
420                                 if(succInAAI != true){
421                                         utils.log("DEBUG","Error getting Service-instance from AAI", + serviceInstanceId, isDebugEnabled)
422                                         WorkflowException workflowException = execution.getVariable("WorkflowException")
423                                         utils.logAudit("workflowException: " + workflowException)
424                                         if(workflowException != null){
425                                                 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
426                                         }
427                                         else
428                                         {
429                                                 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
430                                                 utils.log("DEBUG", msg, isDebugEnabled)
431                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
432                                         }
433                                 }
434
435                                 utils.log("DEBUG","Service-instance NOT found in AAI. Silent Success", isDebugEnabled)
436                         }
437                 } catch (BpmnError e) {
438                         throw e;
439                 } catch (Exception ex) {
440                         msg = "Exception in DoDeleteE2EServiceInstance.postProcessAAIGET. " + ex.getMessage()
441                         utils.log("DEBUG", msg, isDebugEnabled)
442                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
443                 }
444                 utils.log("DEBUG"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
445         }
446
447         public void postProcessAAIDEL(Execution execution) {
448                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
449                 utils.log("DEBUG"," ***** postProcessAAIDEL ***** ", isDebugEnabled)
450                 String msg = ""
451                 try {
452                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
453                         boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
454                         if(succInAAI != true){
455                                 msg = "Error deleting Service-instance in AAI" + serviceInstanceId
456                                 utils.log("DEBUG", msg, isDebugEnabled)
457                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
458                                 utils.logAudit("workflowException: " + workflowException)
459                                 if(workflowException != null){
460                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
461                                 }
462                                 else
463                                 {
464                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
465                                 }
466                         }
467                 } catch (BpmnError e) {
468                         throw e;
469                 } catch (Exception ex) {
470                         msg = "Exception in DoDeleteE2EServiceInstance.postProcessAAIDEL. " + ex.getMessage()
471                         utils.log("DEBUG", msg, isDebugEnabled)
472                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
473                 }
474                 utils.log("DEBUG"," *** Exit postProcessAAIDEL *** ", isDebugEnabled)
475         }
476         
477    public void preInitResourcesOperStatus(Execution execution){
478         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
479
480         utils.log("DEBUG", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
481         try{
482             String serviceId = execution.getVariable("serviceInstanceId")
483             String operationId = execution.getVariable("operationId")
484             String operationType = execution.getVariable("operationType")
485             String resourceTemplateUUIDs = ""
486             String result = "processing"
487             String progress = "0"
488             String reason = ""
489             String operationContent = "Prepare service creation"
490             utils.log("DEBUG", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + oprationType, isDebugEnabled)
491             serviceId = UriUtils.encode(serviceId,"UTF-8")
492             execution.setVariable("serviceInstanceId", serviceId)
493             execution.setVariable("operationId", operationId)
494             execution.setVariable("operationType", operationType)
495             // we use resource instance ids for delete flow as resourceTemplateUUIDs
496             /*[
497              {
498                  "resourceInstanceId":"1111",
499                  "resourceType":"vIMS"
500              },
501              {
502                  "resourceInstanceId":"222",
503                  "resourceType":"vEPC"
504              },
505              {
506                  "resourceInstanceId":"3333",
507                  "resourceType":"overlay"
508              },
509              {
510                  "resourceInstanceId":"4444",
511                  "resourceType":"underlay"
512              }
513          ]*/
514             String serviceRelationShip = execution.getVariable("serviceRelationShip")
515             
516             def jsonSlurper = new JsonSlurper()
517             def jsonOutput = new JsonOutput()         
518             List relationShipList =  jsonSlurper.parseText(serviceRelationShip)
519                     
520             if (relationShipList != null) {
521                 relationShipList.each {
522                     resourceTemplateUUIDs  = resourceTemplateUUIDs + it.resourceInstanceId + ":"
523                 }
524             }           
525
526             def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
527             execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
528             utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
529
530             String payload =
531                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
532                         xmlns:ns="http://org.openecomp.mso/requestsdb">
533                         <soapenv:Header/>
534                         <soapenv:Body>
535                             <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
536                             <serviceId>${serviceId}</serviceId>
537                             <operationId>${operationId}</operationId>
538                             <operationType>${operationType}</operationType>
539                             <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>
540                         </ns:initResourceOperationStatus>
541                     </soapenv:Body>
542                 </soapenv:Envelope>"""
543
544             payload = utils.formatXml(payload)
545             execution.setVariable("CVFMI_initResOperStatusRequest", payload)
546             utils.log("DEBUG", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)
547             utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
548
549         }catch(Exception e){
550             utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)
551             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
552         }
553         utils.log("DEBUG", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)  
554     }
555    
556    /**
557     * prepare delete parameters
558     */
559    public void preResourceDelete(execution, resourceName){
560        // we use resource instance ids for delete flow as resourceTemplateUUIDs
561        /*[
562         {
563             "resourceInstanceId":"1111",
564             "resourceType":"vIMS"
565         },
566         {
567             "resourceInstanceId":"222",
568             "resourceType":"vEPC"
569         },
570         {
571             "resourceInstanceId":"3333",
572             "resourceType":"overlay"
573         },
574         {
575             "resourceInstanceId":"4444",
576             "resourceType":"underlay"
577         }
578     ]*/
579        String serviceRelationShip = execution.getVariable("serviceRelationShip")       
580        def jsonSlurper = new JsonSlurper()
581        def jsonOutput = new JsonOutput()         
582        List relationShipList =  jsonSlurper.parseText(serviceRelationShip)
583                
584        if (relationShipList != null) {
585            relationShipList.each {
586                if(resouceName.equals(it.resouceType))
587                String resouceTemplateUUID = it.resourceInstanceId
588                String resouceInstanceUUID = it.resouceInstanceId
589                execution.setVariable("resouceTemplateUUID", resouceTemplateUUID)
590                execution.setVariable("resouceInstanceId", resouceInstanceUUID)
591                execution.setResourceType("resourceType", resouceName)
592            }
593        }    
594    }
595 }