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.aai.tasks;
26 import java.util.List;
27 import java.util.Optional;
28 import org.onap.aai.domain.yang.NetworkPolicies;
29 import org.onap.aai.domain.yang.NetworkPolicy;
30 import org.onap.so.bpmn.common.BuildingBlockExecution;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
39 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
40 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
41 import org.onap.so.client.aai.AAIObjectPlurals;
42 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
43 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
44 import org.onap.so.client.exception.ExceptionBuilder;
45 import org.onap.so.client.orchestration.AAIConfigurationResources;
46 import org.onap.so.client.orchestration.AAIInstanceGroupResources;
47 import org.onap.so.client.orchestration.AAINetworkResources;
48 import org.onap.so.client.orchestration.AAIServiceInstanceResources;
49 import org.onap.so.client.orchestration.AAIVfModuleResources;
50 import org.onap.so.client.orchestration.AAIVnfResources;
51 import org.onap.so.client.orchestration.AAIVolumeGroupResources;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54 import org.springframework.beans.factory.annotation.Autowired;
55 import org.springframework.stereotype.Component;
58 public class AAIDeleteTasks {
59 private static final Logger logger = LoggerFactory.getLogger(AAIDeleteTasks.class);
61 private static String contrailNetworkPolicyFqdnList = "contrailNetworkPolicyFqdnList";
62 private static String networkPolicyFqdnParam = "network-policy-fqdn";
65 private ExceptionBuilder exceptionUtil;
67 private ExtractPojosForBB extractPojosForBB;
69 private AAIServiceInstanceResources aaiSIResources;
71 private AAIVnfResources aaiVnfResources;
73 private AAIVfModuleResources aaiVfModuleResources;
75 private AAINetworkResources aaiNetworkResources;
77 private AAIVolumeGroupResources aaiVolumeGroupResources;
79 private AAIConfigurationResources aaiConfigurationResources;
81 private AAIInstanceGroupResources aaiInstanceGroupResources;
84 * BPMN access method to delete the VfModule from A&AI.
86 * It will extract the genericVnf & VfModule from the BBObject.
88 * Before deleting it set the aaiVfModuleRollback as false & then it will delete the VfModule.
93 public void deleteVfModule(BuildingBlockExecution execution) throws Exception {
94 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
95 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
97 execution.setVariable("aaiVfModuleRollback", false);
99 aaiVfModuleResources.deleteVfModule(vfModule, genericVnf);
100 execution.setVariable("aaiVfModuleRollback", true);
101 } catch (Exception ex) {
102 logger.error("Exception occurred in AAIDeleteTasks deleteVfModule process", ex);
103 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
108 * BPMN access method to delete the Vnf from A&AI.
110 * It will extract the genericVnf from the BBObject.
112 * Before deleting it set the aaiVnfRollback as false & then it will delete the Vnf.
117 public void deleteVnf(BuildingBlockExecution execution) throws Exception {
118 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
120 execution.setVariable("aaiVnfRollback", false);
122 aaiVnfResources.deleteVnf(genericVnf);
123 execution.setVariable("aaiVnfRollback", true);
124 } catch (Exception ex) {
125 logger.error("Exception occurred in AAIDeleteTasks deleteVnf process", ex);
126 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
131 * BPMN access method to delete the ServiceInstance from A&AI.
133 * It will extract the serviceInstance from the BBObject.
138 public void deleteServiceInstance(BuildingBlockExecution execution) throws Exception {
140 ServiceInstance serviceInstance =
141 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
142 aaiSIResources.deleteServiceInstance(serviceInstance);
143 } catch (Exception ex) {
144 logger.error("Exception occurred in AAIDeleteTasks deleteServiceInstance process", ex);
145 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
151 * BPMN access method to delete the l3network from A&AI.
153 * It will extract the l3network from the BBObject.
155 * After deleting the l3network it set the isRollbackNeeded as true.
160 public void deleteNetwork(BuildingBlockExecution execution) throws Exception {
162 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
163 aaiNetworkResources.deleteNetwork(l3network);
164 execution.setVariable("isRollbackNeeded", true);
165 } catch (Exception ex) {
166 logger.error("Exception occurred in AAIDeleteTasks deleteNetwork process", ex);
167 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
172 * BPMN access method to delete the Collection from A&AI.
174 * It will extract the serviceInstance from the BBObject.
176 * Then it will get the collection from serviceinstance.
181 public void deleteCollection(BuildingBlockExecution execution) throws Exception {
183 ServiceInstance serviceInstance =
184 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
185 aaiNetworkResources.deleteCollection(serviceInstance.getCollection());
186 } catch (Exception ex) {
187 logger.error("Exception occurred in AAIDeleteTasks deleteCollection process", ex);
188 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
193 * BPMN access method to delete the InstanceGroup from A&AI.
195 * It will extract the serviceInstance from the BBObject.
197 * Then it will get the Instance group from serviceInstance.
202 public void deleteInstanceGroup(BuildingBlockExecution execution) throws Exception {
204 ServiceInstance serviceInstance =
205 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
206 aaiNetworkResources.deleteNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup());
207 } catch (Exception ex) {
208 logger.error("Exception occurred in AAIDeleteTasks deleteInstanceGroup process", ex);
209 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
214 * BPMN access method to delete the VolumeGroup from A&AI.
216 * It will extract the volumeGroup from the BBObject and cloudRegion from execution object .
218 * Then it will delete from A&AI.
223 public void deleteVolumeGroup(BuildingBlockExecution execution) {
225 VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
226 CloudRegion cloudRegion = execution.getGeneralBuildingBlock().getCloudRegion();
227 aaiVolumeGroupResources.deleteVolumeGroup(volumeGroup, cloudRegion);
228 } catch (Exception ex) {
229 logger.error("Exception occurred in AAIDeleteTasks deleteVolumeGroup process", ex);
230 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
235 * BPMN access method to delete the Configuration from A&AI.
237 * It will extract the configuration from the BBObject.
239 * Then it will delete from A&AI.
243 public void deleteConfiguration(BuildingBlockExecution execution) {
245 Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
246 aaiConfigurationResources.deleteConfiguration(configuration);
247 } catch (Exception ex) {
248 logger.error("Exception occurred in AAIDeleteTasks deleteConfiguration process", ex);
249 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
254 * BPMN access method to delete the InstanceGroupVnf from A&AI.
256 * It will extract the instanceGroup from the BBObject.
258 * Then it will delete from A&AI.
262 public void deleteInstanceGroupVnf(BuildingBlockExecution execution) {
264 InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
265 aaiInstanceGroupResources.deleteInstanceGroup(instanceGroup);
266 } catch (Exception ex) {
267 logger.error("Exception occurred in AAIDeleteTasks deleteInstanceGroupVnf process", ex);
268 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
273 public void deleteNetworkPolicies(BuildingBlockExecution execution) {
275 String fqdns = execution.getVariable(contrailNetworkPolicyFqdnList);
276 if (fqdns != null && !fqdns.isEmpty()) {
277 String[] fqdnList = fqdns.split(",");
278 int fqdnCount = fqdnList.length;
280 for (int i = 0; i < fqdnCount; i++) {
281 String fqdn = fqdnList[i];
282 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY);
283 uri.queryParam(networkPolicyFqdnParam, fqdn);
284 Optional<NetworkPolicies> oNetPolicies = aaiNetworkResources.getNetworkPolicies(uri);
285 if (oNetPolicies.isPresent()) {
286 NetworkPolicies networkPolicies = oNetPolicies.get();
287 List<NetworkPolicy> networkPolicyList = networkPolicies.getNetworkPolicy();
288 if (networkPolicyList != null && !networkPolicyList.isEmpty()) {
289 NetworkPolicy networkPolicy = networkPolicyList.get(0);
290 String networkPolicyId = networkPolicy.getNetworkPolicyId();
291 logger.debug("Deleting network-policy with network-policy-id {}", networkPolicyId);
292 aaiNetworkResources.deleteNetworkPolicy(networkPolicyId);
298 } catch (Exception ex) {
299 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);