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