2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 
   6  * ================================================================================
 
   7  * Modifications Copyright (c) 2019 Samsung
 
   8  * ================================================================================
 
   9  * Licensed under the Apache License, Version 2.0 (the "License");
 
  10  * you may not use this file except in compliance with the License.
 
  11  * You may obtain a copy of the License at
 
  13  *      http://www.apache.org/licenses/LICENSE-2.0
 
  15  * Unless required by applicable law or agreed to in writing, software
 
  16  * distributed under the License is distributed on an "AS IS" BASIS,
 
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  18  * See the License for the specific language governing permissions and
 
  19  * limitations under the License.
 
  20  * ============LICENSE_END=========================================================
 
  23 package org.onap.so.bpmn.infrastructure.scripts
 
  26 import javax.xml.parsers.DocumentBuilder
 
  27 import javax.xml.parsers.DocumentBuilderFactory
 
  29 import org.apache.commons.lang3.*
 
  30 import org.camunda.bpm.engine.delegate.BpmnError
 
  31 import org.camunda.bpm.engine.delegate.DelegateExecution
 
  32 import org.onap.aai.domain.yang.GenericVnf
 
  33 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 
  34 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 
  35 import org.onap.so.bpmn.common.scripts.VidUtils
 
  36 import org.onap.so.bpmn.core.json.JsonUtils
 
  37 import org.onap.aaiclient.client.graphinventory.entities.uri.Depth;
 
  38 import org.onap.aaiclient.client.aai.AAIResourcesClient
 
  39 import org.onap.aaiclient.client.aai.AAIObjectType
 
  40 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
 
  41 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
 
  42 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
 
  43 import org.w3c.dom.Document
 
  44 import org.w3c.dom.Element
 
  45 import org.w3c.dom.Node
 
  46 import org.w3c.dom.NodeList
 
  47 import org.xml.sax.InputSource
 
  49 import org.slf4j.Logger
 
  50 import org.slf4j.LoggerFactory
 
  53  * This class supports the DoDeleteVnf subFlow
 
  54  * with the Deletion of a generic vnf for
 
  58 class DoDeleteVnf extends AbstractServiceTaskProcessor {
 
  59     private static final Logger logger = LoggerFactory.getLogger( DoDeleteVnf.class);
 
  61         String Prefix="DoDVNF_"
 
  62         ExceptionUtil exceptionUtil = new ExceptionUtil()
 
  63         JsonUtils jsonUtil = new JsonUtils()
 
  64         VidUtils vidUtils = new VidUtils(this)
 
  67          * This method gets and validates the incoming
 
  73         public void preProcessRequest(DelegateExecution execution) {
 
  75                 execution.setVariable("prefix",Prefix)
 
  76                 logger.trace("STARTED DoDeleteVnf PreProcessRequest Process")
 
  78                 execution.setVariable("DoDVNF_SuccessIndicator", false)
 
  79                 execution.setVariable("DoDVNF_vnfInUse", false)
 
  84                         String vnfId = execution.getVariable("vnfId")
 
  85                         execution.setVariable("DoDVNF_vnfId", vnfId)
 
  86                         logger.debug("Incoming Vnf(Instance) Id is: " + vnfId)
 
  89                         logger.debug("Rethrowing MSOWorkflowException")
 
  92                         logger.debug(" Error Occured in DoDeleteVnf PreProcessRequest method!" + e)
 
  93                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf PreProcessRequest")
 
  96                 logger.trace("COMPLETED DoDeleteVnf PreProcessRequest Process ")
 
 100         public void getVnf(DelegateExecution execution){
 
 102                 execution.setVariable("prefix",Prefix)
 
 103                 logger.trace("STARTED DoDeleteVnf getVnf Process ")
 
 106                         AAIResourcesClient resourceClient = new AAIResourcesClient()
 
 107                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, execution.getVariable('vnfId'))
 
 109                         if(resourceClient.exists(uri)){
 
 110                                 execution.setVariable("GENGV_FoundIndicator", true)
 
 111                                 AAIResultWrapper wrapper = resourceClient.get(uri.depth(Depth.ONE))
 
 112                                 if(wrapper.getRelationships().isPresent()){
 
 113                                         List<AAIResourceUri> relationships = wrapper.getRelationships().get().getRelatedAAIUris(AAIObjectType.CLOUD_REGION)
 
 114                                         relationships.addAll(wrapper.getRelationships().get().getRelatedAAIUris(AAIObjectType.L3_NETWORK))
 
 115                                         if(!relationships.isEmpty()){
 
 116                                                 execution.setVariable("DoDVNF_vnfInUse", true)
 
 118                                                 logger.debug("Relationship NOT related to OpenStack")
 
 122                                 Optional<GenericVnf> vnf = wrapper.asBean(GenericVnf.class)
 
 123                                 if (vnf.get() != null) {
 
 124                                         if (vnf.get().getVfModules() != null) {
 
 125                                                 if((vnf.get().getVfModules().getVfModule() != null) && !vnf.get().getVfModules().getVfModule().isEmpty()){                      
 
 126                                                         execution.setVariable("DoDVNF_vnfInUse", true)
 
 131                                 execution.setVariable("GENGV_FoundIndicator", false)
 
 134                 } catch (Exception ex) {
 
 135                         logger.debug("Error Occured in DoDeleteVnf getVnf Process " + ex.getMessage())
 
 136                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf getVnf Process")
 
 139                 logger.trace("COMPLETED DoDeleteVnf getVnf Process ")
 
 143          * Deletes the generic vnf from aai
 
 145         public void deleteVnf(DelegateExecution execution) {
 
 146                 logger.trace("STARTED deleteVnf")
 
 148                         String vnfId = execution.getVariable("DoDVNF_vnfId")
 
 150                         AAIResourcesClient resourceClient = new AAIResourcesClient();
 
 151                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
 
 152                         resourceClient.delete(uri)
 
 154                         logger.trace("COMPLETED deleteVnf")
 
 155                 } catch (Exception ex) {
 
 156                         logger.debug("Error Occured in DoDeleteVnf deleteVnf Process " + ex.getMessage())
 
 157                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf deleteVnf Process")