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.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
44 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
45 import org.w3c.dom.Document
46 import org.w3c.dom.Element
47 import org.w3c.dom.Node
48 import org.w3c.dom.NodeList
49 import org.xml.sax.InputSource
51 import org.slf4j.Logger
52 import org.slf4j.LoggerFactory
55 * This class supports the DoDeleteVnf subFlow
56 * with the Deletion of a generic vnf for
60 class DoDeleteVnf extends AbstractServiceTaskProcessor {
61 private static final Logger logger = LoggerFactory.getLogger( DoDeleteVnf.class);
63 String Prefix="DoDVNF_"
64 ExceptionUtil exceptionUtil = new ExceptionUtil()
65 JsonUtils jsonUtil = new JsonUtils()
66 VidUtils vidUtils = new VidUtils(this)
69 * This method gets and validates the incoming
75 public void preProcessRequest(DelegateExecution execution) {
77 execution.setVariable("prefix",Prefix)
78 logger.trace("STARTED DoDeleteVnf PreProcessRequest Process")
80 execution.setVariable("DoDVNF_SuccessIndicator", false)
81 execution.setVariable("DoDVNF_vnfInUse", false)
86 String vnfId = execution.getVariable("vnfId")
87 execution.setVariable("DoDVNF_vnfId", vnfId)
88 logger.debug("Incoming Vnf(Instance) Id is: " + vnfId)
91 logger.debug("Rethrowing MSOWorkflowException")
94 logger.debug(" Error Occured in DoDeleteVnf PreProcessRequest method!" + e)
95 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf PreProcessRequest")
98 logger.trace("COMPLETED DoDeleteVnf PreProcessRequest Process ")
102 public void getVnf(DelegateExecution execution){
104 execution.setVariable("prefix",Prefix)
105 logger.trace("STARTED DoDeleteVnf getVnf Process ")
108 AAIResourcesClient resourceClient = new AAIResourcesClient()
109 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(execution.getVariable('vnfId')))
111 if(resourceClient.exists(uri)){
112 execution.setVariable("GENGV_FoundIndicator", true)
113 AAIResultWrapper wrapper = resourceClient.get(uri.depth(Depth.ONE))
114 if(wrapper.getRelationships().isPresent()){
115 List<AAIResourceUri> relationships = wrapper.getRelationships().get().getRelatedUris(Types.CLOUD_REGION)
116 relationships.addAll(wrapper.getRelationships().get().getRelatedUris(Types.L3_NETWORK))
117 if(!relationships.isEmpty()){
118 execution.setVariable("DoDVNF_vnfInUse", true)
120 logger.debug("Relationship NOT related to OpenStack")
124 Optional<GenericVnf> vnf = wrapper.asBean(GenericVnf.class)
125 if (vnf.get() != null) {
126 if (vnf.get().getVfModules() != null) {
127 if((vnf.get().getVfModules().getVfModule() != null) && !vnf.get().getVfModules().getVfModule().isEmpty()){
128 execution.setVariable("DoDVNF_vnfInUse", true)
133 execution.setVariable("GENGV_FoundIndicator", false)
136 } catch (Exception ex) {
137 logger.debug("Error Occured in DoDeleteVnf getVnf Process " + ex.getMessage())
138 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf getVnf Process")
141 logger.trace("COMPLETED DoDeleteVnf getVnf Process ")
145 * Deletes the generic vnf from aai
147 public void deleteVnf(DelegateExecution execution) {
148 logger.trace("STARTED deleteVnf")
150 String vnfId = execution.getVariable("DoDVNF_vnfId")
152 AAIResourcesClient resourceClient = new AAIResourcesClient();
153 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId))
154 resourceClient.delete(uri)
156 logger.trace("COMPLETED deleteVnf")
157 } catch (Exception ex) {
158 logger.debug("Error Occured in DoDeleteVnf deleteVnf Process " + ex.getMessage())
159 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf deleteVnf Process")