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