2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
24 import javax.xml.parsers.DocumentBuilder
25 import javax.xml.parsers.DocumentBuilderFactory
27 import org.apache.commons.lang3.*
28 import org.camunda.bpm.engine.delegate.BpmnError
29 import org.camunda.bpm.engine.delegate.DelegateExecution
30 import org.onap.aai.domain.yang.GenericVnf
31 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
32 import org.onap.so.bpmn.common.scripts.ExceptionUtil
33 import org.onap.so.bpmn.common.scripts.VidUtils
34 import org.onap.so.bpmn.core.json.JsonUtils
35 import org.onap.so.client.graphinventory.entities.uri.Depth;
36 import org.onap.so.client.aai.AAIResourcesClient
37 import org.onap.so.client.aai.AAIObjectType
38 import org.onap.so.client.aai.entities.AAIResultWrapper
39 import org.onap.so.client.aai.entities.uri.AAIResourceUri
40 import org.onap.so.client.aai.entities.uri.AAIUriFactory
41 import org.w3c.dom.Document
42 import org.w3c.dom.Element
43 import org.w3c.dom.Node
44 import org.w3c.dom.NodeList
45 import org.xml.sax.InputSource
47 import org.onap.so.logger.MessageEnum
48 import org.onap.so.logger.MsoLogger
51 * This class supports the DoDeleteVnf subFlow
52 * with the Deletion of a generic vnf for
56 class DoDeleteVnf extends AbstractServiceTaskProcessor {
57 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteVnf.class);
59 String Prefix="DoDVNF_"
60 ExceptionUtil exceptionUtil = new ExceptionUtil()
61 JsonUtils jsonUtil = new JsonUtils()
62 VidUtils vidUtils = new VidUtils(this)
65 * This method gets and validates the incoming
71 public void preProcessRequest(DelegateExecution execution) {
73 execution.setVariable("prefix",Prefix)
74 msoLogger.trace("STARTED DoDeleteVnf PreProcessRequest Process")
76 execution.setVariable("DoDVNF_SuccessIndicator", false)
77 execution.setVariable("DoDVNF_vnfInUse", false)
82 String vnfId = execution.getVariable("vnfId")
83 execution.setVariable("DoDVNF_vnfId", vnfId)
84 msoLogger.debug("Incoming Vnf(Instance) Id is: " + vnfId)
87 msoLogger.debug("Rethrowing MSOWorkflowException")
90 msoLogger.debug(" Error Occured in DoDeleteVnf PreProcessRequest method!" + e)
91 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf PreProcessRequest")
94 msoLogger.trace("COMPLETED DoDeleteVnf PreProcessRequest Process ")
98 public void getVnf(DelegateExecution execution){
100 execution.setVariable("prefix",Prefix)
101 msoLogger.trace("STARTED DoDeleteVnf getVnf Process ")
104 AAIResourcesClient resourceClient = new AAIResourcesClient()
105 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, execution.getVariable('vnfId'))
107 if(resourceClient.exists(uri)){
108 execution.setVariable("GENGV_FoundIndicator", true)
109 AAIResultWrapper wrapper = resourceClient.get(uri.depth(Depth.ONE))
110 if(wrapper.getRelationships().isPresent()){
111 List<AAIResourceUri> relationships = wrapper.getRelationships().get().getRelatedAAIUris(AAIObjectType.CLOUD_REGION)
112 relationships.addAll(wrapper.getRelationships().get().getRelatedAAIUris(AAIObjectType.L3_NETWORK))
113 if(!relationships.isEmpty()){
114 execution.setVariable("DoDVNF_vnfInUse", true)
116 msoLogger.debug("Relationship NOT related to OpenStack")
120 Optional<GenericVnf> vnf = wrapper.asBean(GenericVnf.class)
121 if(!vnf.get().getVfModules().getVfModule().isEmpty()){
122 execution.setVariable("DoDVNF_vnfInUse", true)
125 execution.setVariable("GENGV_FoundIndicator", false)
128 } catch (Exception ex) {
129 msoLogger.debug("Error Occured in DoDeleteVnf getVnf Process " + ex.getMessage())
130 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf getVnf Process")
133 msoLogger.trace("COMPLETED DoDeleteVnf getVnf Process ")
137 * Deletes the generic vnf from aai
139 public void deleteVnf(DelegateExecution execution) {
140 msoLogger.trace("STARTED deleteVnf")
142 String vnfId = execution.getVariable("DoDVNF_vnfId")
144 AAIResourcesClient resourceClient = new AAIResourcesClient();
145 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
146 resourceClient.delete(uri)
148 msoLogger.trace("COMPLETED deleteVnf")
149 } catch (Exception ex) {
150 msoLogger.debug("Error Occured in DoDeleteVnf deleteVnf Process " + ex.getMessage())
151 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf deleteVnf Process")