Removed MsoLogger class
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoDeleteVnf.groovy
index 699e9bf..2530347 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -27,12 +29,15 @@ import javax.xml.parsers.DocumentBuilderFactory
 import org.apache.commons.lang3.*
 import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.aai.domain.yang.GenericVnf
 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 import org.onap.so.bpmn.common.scripts.VidUtils
 import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.client.graphinventory.entities.uri.Depth;
 import org.onap.so.client.aai.AAIResourcesClient
 import org.onap.so.client.aai.AAIObjectType
+import org.onap.so.client.aai.entities.AAIResultWrapper
 import org.onap.so.client.aai.entities.uri.AAIResourceUri
 import org.onap.so.client.aai.entities.uri.AAIUriFactory
 import org.w3c.dom.Document
@@ -41,8 +46,8 @@ import org.w3c.dom.Node
 import org.w3c.dom.NodeList
 import org.xml.sax.InputSource
 
-import org.onap.so.logger.MessageEnum
-import org.onap.so.logger.MsoLogger
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
 
 /**
  * This class supports the DoDeleteVnf subFlow
@@ -51,7 +56,7 @@ import org.onap.so.logger.MsoLogger
  *
  */
 class DoDeleteVnf extends AbstractServiceTaskProcessor {
-       private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteVnf.class);
+    private static final Logger logger = LoggerFactory.getLogger( DoDeleteVnf.class);
 
        String Prefix="DoDVNF_"
        ExceptionUtil exceptionUtil = new ExceptionUtil()
@@ -68,7 +73,7 @@ class DoDeleteVnf extends AbstractServiceTaskProcessor {
        public void preProcessRequest(DelegateExecution execution) {
 
                execution.setVariable("prefix",Prefix)
-               msoLogger.trace("STARTED DoDeleteVnf PreProcessRequest Process")
+               logger.trace("STARTED DoDeleteVnf PreProcessRequest Process")
 
                execution.setVariable("DoDVNF_SuccessIndicator", false)
                execution.setVariable("DoDVNF_vnfInUse", false)
@@ -78,72 +83,67 @@ class DoDeleteVnf extends AbstractServiceTaskProcessor {
 
                        String vnfId = execution.getVariable("vnfId")
                        execution.setVariable("DoDVNF_vnfId", vnfId)
-                       msoLogger.debug("Incoming Vnf(Instance) Id is: " + vnfId)
+                       logger.debug("Incoming Vnf(Instance) Id is: " + vnfId)
 
-                       // Setting for sub flow calls
-                       execution.setVariable("DoDVNF_type", "generic-vnf")
                }catch(BpmnError b){
-                       msoLogger.debug("Rethrowing MSOWorkflowException")
+                       logger.debug("Rethrowing MSOWorkflowException")
                        throw b
                }catch(Exception e){
-                       msoLogger.debug(" Error Occured in DoDeleteVnf PreProcessRequest method!" + e)
+                       logger.debug(" Error Occured in DoDeleteVnf PreProcessRequest method!" + e)
                        exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf PreProcessRequest")
 
                }
-               msoLogger.trace("COMPLETED DoDeleteVnf PreProcessRequest Process ")
+               logger.trace("COMPLETED DoDeleteVnf PreProcessRequest Process ")
        }
 
 
-       public void processGetVnfResponse(DelegateExecution execution){
+       public void getVnf(DelegateExecution execution){
 
                execution.setVariable("prefix",Prefix)
-               msoLogger.trace("STARTED DoDeleteVnf processGetVnfResponse Process ")
+               logger.trace("STARTED DoDeleteVnf getVnf Process ")
                try {
-                       String vnf = execution.getVariable("DoDVNF_genericVnf")
-                       String resourceVersion = utils.getNodeText(vnf, "resource-version")
-                       execution.setVariable("DoDVNF_resourceVersion", resourceVersion)
-
-                       if(utils.nodeExists(vnf, "relationship")){
-                               InputSource source = new InputSource(new StringReader(vnf));
-                               DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
-                               DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
-                               Document vnfXml = docBuilder.parse(source)
-
-                               NodeList nodeList = vnfXml.getElementsByTagName("relationship")
-                               for (int x = 0; x < nodeList.getLength(); x++) {
-                                       Node node = nodeList.item(x)
-                                       if (node.getNodeType() == Node.ELEMENT_NODE) {
-                                               Element eElement = (Element) node
-                                               def e = eElement.getElementsByTagName("related-to").item(0).getTextContent()
-                                               if(e.equals("volume-group") || e.equals("l3-network")){
-                                                       msoLogger.debug("Generic Vnf still has relationship to OpenStack.")
-                                                       execution.setVariable("DoDVNF_vnfInUse", true)
-                                               }else{
-                                                       msoLogger.debug("Relationship NOT related to OpenStack")
-                                               }
+
+                       AAIResourcesClient resourceClient = new AAIResourcesClient()
+                       AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, execution.getVariable('vnfId'))
+
+                       if(resourceClient.exists(uri)){
+                               execution.setVariable("GENGV_FoundIndicator", true)
+                               AAIResultWrapper wrapper = resourceClient.get(uri.depth(Depth.ONE))
+                               if(wrapper.getRelationships().isPresent()){
+                                       List<AAIResourceUri> relationships = wrapper.getRelationships().get().getRelatedAAIUris(AAIObjectType.CLOUD_REGION)
+                                       relationships.addAll(wrapper.getRelationships().get().getRelatedAAIUris(AAIObjectType.L3_NETWORK))
+                                       if(!relationships.isEmpty()){
+                                               execution.setVariable("DoDVNF_vnfInUse", true)
+                                       }else{
+                                               logger.debug("Relationship NOT related to OpenStack")
                                        }
                                }
-                       }
 
-                       if(utils.nodeExists(vnf, "vf-module")){
-                               execution.setVariable("DoDVNF_vnfInUse", true)
-                               msoLogger.debug("Generic Vnf still has vf-modules.")
+                               Optional<GenericVnf> vnf = wrapper.asBean(GenericVnf.class)
+                               if (vnf.get() != null) {
+                                       if (vnf.get().getVfModules() != null) {
+                                               if((vnf.get().getVfModules().getVfModule() != null) && !vnf.get().getVfModules().getVfModule().isEmpty()){                      
+                                                       execution.setVariable("DoDVNF_vnfInUse", true)
+                                               }
+                                       }                       
+                               }
+                       }else{
+                               execution.setVariable("GENGV_FoundIndicator", false)
                        }
 
-
                } catch (Exception ex) {
-                       msoLogger.debug("Error Occured in DoDeleteVnf processGetVnfResponse Process " + ex.getMessage())
-                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf processGetVnfResponse Process")
+                       logger.debug("Error Occured in DoDeleteVnf getVnf Process " + ex.getMessage())
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf getVnf Process")
 
                }
-               msoLogger.trace("COMPLETED DoDeleteVnf processGetVnfResponse Process ")
+               logger.trace("COMPLETED DoDeleteVnf getVnf Process ")
        }
 
        /**
         * Deletes the generic vnf from aai
         */
        public void deleteVnf(DelegateExecution execution) {
-               msoLogger.trace("STARTED deleteVnf")
+               logger.trace("STARTED deleteVnf")
                try {
                        String vnfId = execution.getVariable("DoDVNF_vnfId")
 
@@ -151,9 +151,9 @@ class DoDeleteVnf extends AbstractServiceTaskProcessor {
                        AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
                        resourceClient.delete(uri)
 
-                       msoLogger.trace("COMPLETED deleteVnf")
+                       logger.trace("COMPLETED deleteVnf")
                } catch (Exception ex) {
-                       msoLogger.debug("Error Occured in DoDeleteVnf deleteVnf Process " + ex.getMessage())
+                       logger.debug("Error Occured in DoDeleteVnf deleteVnf Process " + ex.getMessage())
                        exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf deleteVnf Process")
                }
        }