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