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