Containerization feature of SO
[so.git] / bpmn / so-bpmn-infrastructure-flows / src / main / groovy / org / onap / so / 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.onap.so.bpmn.infrastructure.scripts
22
23 import static org.apache.commons.lang3.StringUtils.*;
24
25 import javax.xml.parsers.DocumentBuilder
26 import javax.xml.parsers.DocumentBuilderFactory
27
28 import org.apache.commons.lang3.*
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.delegate.DelegateExecution
31 import org.json.JSONArray;
32 import org.json.JSONObject;
33 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
34 import org.onap.so.bpmn.common.scripts.ExceptionUtil
35 import org.onap.so.bpmn.common.scripts.MsoUtils
36 import org.onap.so.bpmn.core.UrnPropertiesReader
37 import org.onap.so.bpmn.core.WorkflowException
38 import org.onap.so.bpmn.core.json.JsonUtils
39 import org.onap.so.logger.MessageEnum
40 import org.onap.so.logger.MsoLogger
41 import org.springframework.web.util.UriUtils;
42 import org.w3c.dom.Document
43 import org.w3c.dom.Element
44 import org.w3c.dom.Node
45 import org.w3c.dom.NodeList
46 import org.xml.sax.InputSource
47 import org.onap.so.client.aai.entities.uri.AAIResourceUri
48 import org.onap.so.client.aai.entities.uri.AAIUriFactory
49 import org.onap.so.client.aai.AAIObjectType
50 import org.onap.so.client.aai.AAIResourcesClient
51
52 import groovy.json.*
53
54
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         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCustomDeleteE2EServiceInstance.class);
77
78
79         String Prefix="DDELSI_"
80         ExceptionUtil exceptionUtil = new ExceptionUtil()
81         JsonUtils jsonUtil = new JsonUtils()
82
83         public void preProcessRequest (DelegateExecution execution) {
84                 msoLogger.trace("preProcessRequest ")
85                 String msg = ""
86
87                 try {
88                         String requestId = execution.getVariable("msoRequestId")
89                         execution.setVariable("prefix",Prefix)
90
91                         //Inputs
92                         //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
93                         String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
94                         if (globalSubscriberId == null)
95                         {
96                                 execution.setVariable("globalSubscriberId", "")
97                         }
98
99                         //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
100                         String serviceType = execution.getVariable("serviceType")
101                         if (serviceType == null)
102                         {
103                                 execution.setVariable("serviceType", "")
104                         }
105
106                         //Generated in parent for AAI PUT
107                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
108                         if (isBlank(serviceInstanceId)){
109                                 msg = "Input serviceInstanceId is null"
110                                 msoLogger.info(msg)
111                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
112                         }
113
114                         String sdncCallbackUrl = UrnPropertiesReader.getVariable('mso.workflow.sdncadapter.callback',execution)
115                         if (isBlank(sdncCallbackUrl)) {
116                                 msg = "URN_mso_workflow_sdncadapter_callback is null"
117                                 msoLogger.info(msg)
118                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
119                         }
120                         execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
121                         msoLogger.info("SDNC Callback URL: " + sdncCallbackUrl)
122
123                         StringBuilder sbParams = new StringBuilder()
124                         Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
125                         if (paramsMap != null)
126                         {
127                                 sbParams.append("<service-input-parameters>")
128                                 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
129                                         String paramsXml
130                                         String paramName = entry.getKey()
131                                         String paramValue = entry.getValue()
132                                         paramsXml =
133                                                         """     <param>
134                                                         <name>${MsoUtils.xmlEscape(paramName)}</name>
135                                                         <value>${MsoUtils.xmlEscape(paramValue)}</value>
136                                                         </param>
137                                                         """
138                                         sbParams.append(paramsXml)
139                                 }
140                                 sbParams.append("</service-input-parameters>")
141                         }
142                         String siParamsXml = sbParams.toString()
143                         if (siParamsXml == null)
144                                 siParamsXml = ""
145                         execution.setVariable("siParamsXml", siParamsXml)
146
147                 } catch (BpmnError e) {
148                         throw e;
149                 } catch (Exception ex){
150                         msg = "Exception in preProcessRequest " + ex.getMessage()
151                         msoLogger.info(msg)
152                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
153                 }
154                 msoLogger.trace("Exit preProcessRequest ")
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                 msoLogger.trace("preProcessSDNCDelete ")
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.onap/so/request/types/v1"
220                                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
221                                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
222                                    <sdncadapter:RequestHeader>
223                                                         <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
224                                                         <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
225                                                         <sdncadapter:SvcAction>delete</sdncadapter:SvcAction>
226                                                         <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
227                                                         <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
228                                                         <sdncadapter:MsoAction>${MsoUtils.xmlEscape(serviceType)}</sdncadapter:MsoAction>
229                                         </sdncadapter:RequestHeader>
230                                 <sdncadapterworkflow:SDNCRequestData>
231                                         <request-information>
232                                                 <request-id>${MsoUtils.xmlEscape(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>${MsoUtils.xmlEscape(serviceId)}</service-id>
241                                                 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
242                                                 <onap-model-information>
243                                                  <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
244                                                  <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
245                                                  <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
246                                                  <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
247                                             </onap-model-information>
248                                                 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
249                                                 <subscriber-name/>
250                                                 <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
251                                         </service-information>
252                                         <service-request-input>
253                                                 <service-instance-name>${MsoUtils.xmlEscape(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                         msoLogger.info("sdncDeactivate:\n" + sdncDeactivate)
265                         msoLogger.info("sdncDelete:\n" + sdncDelete)
266
267                 } catch (BpmnError e) {
268                         throw e;
269                 } catch(Exception ex) {
270                         msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
271                         msoLogger.info(msg)
272                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception Occured in preProcessSDNCDelete.\n" + ex.getMessage())
273                 }
274                 msoLogger.info(" *****Exit preProcessSDNCDelete *****")
275         }
276
277         public void postProcessSDNCDelete(DelegateExecution execution, String response, String method) {
278
279                 msoLogger.trace("postProcessSDNC " + method + " ")
280                 String msg = ""
281
282                 /*try {
283                         WorkflowException workflowException = execution.getVariable("WorkflowException")
284                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
285                         msoLogger.info("SDNCResponse: " + response)
286                         msoLogger.info("workflowException: " + workflowException)
287
288                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
289                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
290                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == "true"){
291                                 msoLogger.info("Good response from SDNC Adapter for service-instance " + method + "response:\n" + response)
292
293                         }else{
294                                 msg = "Bad Response from SDNC Adapter for service-instance " + method
295                                 msoLogger.info(msg)
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                         msoLogger.info(msg)
303                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
304                 }*/
305                 msoLogger.trace("Exit postProcessSDNC " + method + " ")
306         }
307
308         public void postProcessAAIGET(DelegateExecution execution) {
309                 msoLogger.trace("postProcessAAIGET ")
310                 String msg = ""
311
312                 try {
313                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
314                         boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
315                         String serviceType = ""
316
317                         if(foundInAAI){
318                                 msoLogger.info("Found Service-instance in AAI")
319
320                                 String siData = execution.getVariable("GENGS_service")
321                                 msoLogger.info("SI Data")
322                                 if (isBlank(siData))
323                                 {
324                                         msg = "Could not retrive ServiceInstance data from AAI to delete id:" + serviceInstanceId
325                                         msoLogger.info(msg)
326                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
327                                 }
328                                 else
329                                 {
330                                         msoLogger.info("SI Data" + siData)
331                                         //Confirm there are no related service instances (vnf/network or volume)
332                                         if (utils.nodeExists(siData, "relationship-list")) {
333                                                 msoLogger.info("SI Data relationship-list exists:")
334                                                 InputSource source = new InputSource(new StringReader(siData));
335                                                 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
336                                                 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
337                                                 Document serviceXml = docBuilder.parse(source)
338                                                 serviceXml.getDocumentElement().normalize()
339                                                 //test(siData)
340                                                 NodeList nodeList = serviceXml.getElementsByTagName("relationship")
341                             JSONArray jArray = new JSONArray()
342                                                 for (int x = 0; x < nodeList.getLength(); x++) {
343                                                         Node node = nodeList.item(x)
344                                                         if (node.getNodeType() == Node.ELEMENT_NODE) {
345                                                                 Element eElement = (Element) node
346                                                                 def e = eElement.getElementsByTagName("related-to").item(0).getTextContent()                                                                    //for ns
347                                                                 if(e.equals("service-instance")){
348                                                                     def relatedObject = eElement.getElementsByTagName("related-link").item(0).getTextContent()
349                                                                         msoLogger.info("ServiceInstance Related NS :" + relatedObject)
350                                     NodeList dataList = node.getChildNodes()
351                                     if(null != dataList) {
352                                         JSONObject jObj = new JSONObject()
353                                         for (int i = 0; i < dataList.getLength(); i++) {
354                                             Node dNode = dataList.item(i)
355                                             if(dNode.getNodeName() == "relationship-data") {
356                                                 Element rDataEle = (Element)dNode
357                                                 def eKey =  rDataEle.getElementsByTagName("relationship-key").item(0).getTextContent()
358                                                 def eValue = rDataEle.getElementsByTagName("relationship-value").item(0).getTextContent()
359                                                 if(eKey.equals("service-instance.service-instance-id")){
360                                                     jObj.put("resourceInstanceId", eValue)
361                                                 }
362                                             }
363                                             else if(dNode.getNodeName() == "related-to-property"){
364                                                  Element rDataEle = (Element)dNode
365                                                  def eKey =  rDataEle.getElementsByTagName("property-key").item(0).getTextContent()
366                                                  def eValue = rDataEle.getElementsByTagName("property-value").item(0).getTextContent()
367                                                  if(eKey.equals("service-instance.service-instance-name")){
368                                                         jObj.put("resourceType", eValue)
369                                                     }
370                                             }
371                                         }
372                                         msoLogger.info("Relationship related to Resource:" + jObj.toString())
373                                         jArray.put(jObj)
374                                     }
375                                                         //for overlay/underlay
376                                                                 }else if (e.equals("configuration")){
377                                     def relatedObject = eElement.getElementsByTagName("related-link").item(0).getTextContent()
378                                     msoLogger.info("ServiceInstance Related Configuration :" + relatedObject)
379                                                                         NodeList dataList = node.getChildNodes()
380                                                                         if(null != dataList) {
381                                                                                 JSONObject jObj = new JSONObject()
382                                                                                 for (int i = 0; i < dataList.getLength(); i++) {
383                                                                                         Node dNode = dataList.item(i)
384                                                                                         if(dNode.getNodeName() == "relationship-data") {
385                                                                                                 Element rDataEle = (Element)dNode
386                                                                                                 def eKey =  rDataEle.getElementsByTagName("relationship-key").item(0).getTextContent()
387                                                                                                 def eValue = rDataEle.getElementsByTagName("relationship-value").item(0).getTextContent()
388                                                                                                 if(eKey.equals("configuration.configuration-id")){
389                                                                                                     jObj.put("resourceInstanceId", eValue)
390                                                                                                 }
391                                                                                         }
392                                                                                         else if(dNode.getNodeName() == "related-to-property"){
393                                                      Element rDataEle = (Element)dNode
394                                                      def eKey =  rDataEle.getElementsByTagName("property-key").item(0).getTextContent()
395                                                      def eValue = rDataEle.getElementsByTagName("property-value").item(0).getTextContent()
396                                                      if(eKey.equals("configuration.configuration-type")){
397                                                             jObj.put("resourceType", eValue)
398                                                         }
399                                                                                         }
400                                                                                 }
401                                                                                 msoLogger.info("Relationship related to Resource:" + jObj.toString())
402                                         jArray.put(jObj)
403                                                                         }
404                                                                 }
405                                                         }
406                                                 }
407                         execution.setVariable("serviceRelationShip", jArray.toString())
408                                         }
409                                 }
410                         }else{
411                                 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
412                                 if(!succInAAI){
413                                         msoLogger.info("Error getting Service-instance from AAI", + serviceInstanceId)
414                                         WorkflowException workflowException = execution.getVariable("WorkflowException")
415                                         msoLogger.debug("workflowException: " + workflowException)
416                                         if(workflowException != null){
417                                                 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
418                                         }
419                                         else
420                                         {
421                                                 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
422                                                 msoLogger.info(msg)
423                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
424                                         }
425                                 }
426
427                                 msoLogger.info("Service-instance NOT found in AAI. Silent Success")
428                         }
429                 }catch (BpmnError e) {
430                         throw e;
431                 } catch (Exception ex) {
432                         msg = "Exception in DoDeleteE2EServiceInstance.postProcessAAIGET. " + ex.getMessage()
433                         msoLogger.info(msg)
434                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
435                 }
436                 msoLogger.trace("Exit postProcessAAIGET ")
437         }
438
439         /**
440          * Deletes the service instance in aai
441          */
442         public void deleteServiceInstance(DelegateExecution execution) {
443                 msoLogger.trace("Entered deleteServiceInstance")
444                 try {
445                         String globalCustId = execution.getVariable("globalSubscriberId")
446                         String serviceType = execution.getVariable("serviceType")
447                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
448
449                         AAIResourcesClient resourceClient = new AAIResourcesClient();
450                         AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalCustId, serviceType, serviceInstanceId)
451                         resourceClient.delete(serviceInstanceUri)
452
453                         msoLogger.trace("Exited deleteServiceInstance")
454                 }catch(Exception e){
455                         msoLogger.debug("Error occured within deleteServiceInstance method: " + e)
456                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Error occured during deleteServiceInstance from aai")
457                 }
458         }
459
460    public void preInitResourcesOperStatus(DelegateExecution execution){
461         msoLogger.trace("STARTED preInitResourcesOperStatus Process ")
462         try{
463             String serviceId = execution.getVariable("serviceInstanceId")
464             String operationId = execution.getVariable("operationId")
465             String operationType = execution.getVariable("operationType")
466             String resourceTemplateUUIDs = ""
467             String result = "processing"
468             String progress = "0"
469             String reason = ""
470             String operationContent = "Prepare service creation"
471             msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
472             serviceId = UriUtils.encode(serviceId,"UTF-8")
473             execution.setVariable("serviceInstanceId", serviceId)
474             execution.setVariable("operationId", operationId)
475             execution.setVariable("operationType", operationType)
476             // we use resource instance ids for delete flow as resourceTemplateUUIDs
477             /*[
478              {
479                  "resourceInstanceId":"1111",
480                  "resourceType":"vIMS"
481              },
482              {
483                  "resourceInstanceId":"222",
484                  "resourceType":"vEPC"
485              },
486              {
487                  "resourceInstanceId":"3333",
488                  "resourceType":"overlay"
489              },
490              {
491                  "resourceInstanceId":"4444",
492                  "resourceType":"underlay"
493              }
494          ]*/
495             String serviceRelationShip = execution.getVariable("serviceRelationShip")
496
497             def jsonSlurper = new JsonSlurper()
498             def jsonOutput = new JsonOutput()
499             List relationShipList =  jsonSlurper.parseText(serviceRelationShip)
500
501             if (relationShipList != null) {
502                 relationShipList.each {
503                     resourceTemplateUUIDs  = resourceTemplateUUIDs + it.resourceInstanceId + ":"
504                 }
505             }
506             execution.setVariable("URN_mso_adapters_openecomp_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
507
508             String payload =
509                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
510                         xmlns:ns="http://org.onap.so/requestsdb">
511                         <soapenv:Header/>
512                         <soapenv:Body>
513                             <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
514                             <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
515                             <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
516                             <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
517                             <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
518                         </ns:initResourceOperationStatus>
519                     </soapenv:Body>
520                 </soapenv:Envelope>"""
521
522             payload = utils.formatXml(payload)
523             execution.setVariable("CVFMI_initResOperStatusRequest", payload)
524             msoLogger.info("Outgoing initResourceOperationStatus: \n" + payload)
525             msoLogger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
526
527         }catch(Exception e){
528             msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preInitResourcesOperStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
529             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
530         }
531         msoLogger.trace("COMPLETED preInitResourcesOperStatus Process ")
532     }
533
534    /**
535     * prepare delete parameters
536     */
537    public void preResourceDelete(execution, resourceName){
538        // we use resource instance ids for delete flow as resourceTemplateUUIDs
539        /*[
540         {
541             "resourceInstanceId":"1111",
542             "resourceType":"vIMS"
543         },
544         {
545             "resourceInstanceId":"222",
546             "resourceType":"vEPC"
547         },
548         {
549             "resourceInstanceId":"3333",
550             "resourceType":"overlay"
551         },
552         {
553             "resourceInstanceId":"4444",
554             "resourceType":"underlay"
555         }
556     ]*/
557        msoLogger.trace("STARTED preResourceDelete Process ")
558        String serviceRelationShip = execution.getVariable("serviceRelationShip")
559        def jsonSlurper = new JsonSlurper()
560        def jsonOutput = new JsonOutput()
561        List relationShipList =  jsonSlurper.parseText(serviceRelationShip)
562
563        if (relationShipList != null) {
564            relationShipList.each {
565                if(StringUtils.containsIgnoreCase(it.resourceType, resourceName)) {
566                                    String resourceInstanceUUID = it.resourceInstanceId
567                                    String resourceTemplateUUID = it.resourceInstanceId
568                                    execution.setVariable("resourceTemplateId", resourceTemplateUUID)
569                                    execution.setVariable("resourceInstanceId", resourceInstanceUUID)
570                                    execution.setVariable("resourceType", resourceName)
571                                msoLogger.info("Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + "  resourceInstanceId: " + resourceInstanceUUID + " resourceType: " + resourceName)
572                            }
573            }
574        }
575        msoLogger.trace("END preResourceDelete Process ")
576    }
577
578    public void sequenceResource(execution){
579        msoLogger.trace("STARTED sequenceResource Process ")
580        List<String> nsResources = new ArrayList<String>()
581        List<String> wanResources = new ArrayList<String>()
582        List<String> resourceSequence = new  ArrayList<String>()
583
584        String serviceRelationShip = execution.getVariable("serviceRelationShip")
585
586
587        def jsonSlurper = new JsonSlurper()
588        def jsonOutput = new JsonOutput()
589        List relationShipList =  jsonSlurper.parseText(serviceRelationShip)
590
591        if (relationShipList != null) {
592            relationShipList.each {
593                if(StringUtils.containsIgnoreCase(it.resourceType, "overlay") || StringUtils.containsIgnoreCase(it.resourceType, "underlay")){
594                    wanResources.add(it.resourceType)
595                }else{
596                    nsResources.add(it.resourceType)
597                }
598            }
599        }
600        resourceSequence.addAll(wanResources)
601        resourceSequence.addAll(nsResources)
602        String isContainsWanResource = wanResources.isEmpty() ? "false" : "true"
603        execution.setVariable("isContainsWanResource", isContainsWanResource)
604        execution.setVariable("currentResourceIndex", 0)
605        execution.setVariable("resourceSequence", resourceSequence)
606        msoLogger.info("resourceSequence: " + resourceSequence)
607        execution.setVariable("wanResources", wanResources)
608        msoLogger.trace("END sequenceResource Process ")
609    }
610
611    public void getCurrentResource(execution){
612        msoLogger.trace("Start getCurrentResoure Process ")
613        def currentIndex = execution.getVariable("currentResourceIndex")
614        List<String> resourceSequence = execution.getVariable("resourceSequence")
615        List<String> wanResources = execution.getVariable("wanResources")
616        String resourceName =  resourceSequence.get(currentIndex)
617        execution.setVariable("resourceType",resourceName)
618        if(wanResources.contains(resourceName)){
619            execution.setVariable("controllerInfo", "SDN-C")
620        }else{
621            execution.setVariable("controllerInfo", "VF-C")
622        }
623        msoLogger.trace("COMPLETED getCurrentResoure Process ")
624    }
625
626    public void parseNextResource(execution){
627        msoLogger.trace("Start parseNextResource Process ")
628        def currentIndex = execution.getVariable("currentResourceIndex")
629        def nextIndex =  currentIndex + 1
630        execution.setVariable("currentResourceIndex", nextIndex)
631        List<String> resourceSequence = execution.getVariable("resourceSequence")
632        if(nextIndex >= resourceSequence.size()){
633            execution.setVariable("allResourceFinished", "true")
634        }else{
635            execution.setVariable("allResourceFinished", "false")
636        }
637        msoLogger.trace("COMPLETED parseNextResource Process ")
638    }
639
640 }