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.aaiclient.client.aai.entities.uri.AAIPluralResourceUri;
31 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
32 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
33 import org.onap.so.bpmn.common.BuildingBlockExecution;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
43 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
44 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
45 import org.onap.so.client.exception.ExceptionBuilder;
46 import org.onap.so.client.orchestration.AAIConfigurationResources;
47 import org.onap.so.client.orchestration.AAIInstanceGroupResources;
48 import org.onap.so.client.orchestration.AAINetworkResources;
49 import org.onap.so.client.orchestration.AAIServiceInstanceResources;
50 import org.onap.so.client.orchestration.AAIVfModuleResources;
51 import org.onap.so.client.orchestration.AAIVnfResources;
52 import org.onap.so.client.orchestration.AAIPnfResources;
53 import org.onap.so.client.orchestration.AAIVolumeGroupResources;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
56 import org.springframework.beans.factory.annotation.Autowired;
57 import org.springframework.stereotype.Component;
60 public class AAIDeleteTasks {
61 private static final Logger logger = LoggerFactory.getLogger(AAIDeleteTasks.class);
63 private static String contrailNetworkPolicyFqdnList = "contrailNetworkPolicyFqdnList";
64 private static String networkPolicyFqdnParam = "network-policy-fqdn";
67 private ExceptionBuilder exceptionUtil;
69 private ExtractPojosForBB extractPojosForBB;
71 private AAIServiceInstanceResources aaiSIResources;
73 private AAIVnfResources aaiVnfResources;
75 private AAIPnfResources aaiPnfResources;
77 private AAIVfModuleResources aaiVfModuleResources;
79 private AAINetworkResources aaiNetworkResources;
81 private AAIVolumeGroupResources aaiVolumeGroupResources;
83 private AAIConfigurationResources aaiConfigurationResources;
85 private AAIInstanceGroupResources aaiInstanceGroupResources;
88 * BPMN access method to delete the VfModule from A&AI.
90 * It will extract the genericVnf & VfModule from the BBObject.
92 * Before deleting it set the aaiVfModuleRollback as false & then it will delete the VfModule.
97 public void deleteVfModule(BuildingBlockExecution execution) throws Exception {
98 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
99 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
101 execution.setVariable("aaiVfModuleRollback", false);
103 aaiVfModuleResources.deleteVfModule(vfModule, genericVnf);
104 execution.setVariable("aaiVfModuleRollback", true);
105 } catch (Exception ex) {
106 logger.error("Exception occurred in AAIDeleteTasks deleteVfModule process", ex);
107 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
112 * BPMN access method to delete the Vnf from A&AI.
114 * It will extract the genericVnf from the BBObject.
116 * Before deleting it set the aaiVnfRollback as false & then it will delete the Vnf.
121 public void deleteVnf(BuildingBlockExecution execution) throws Exception {
122 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
124 execution.setVariable("aaiVnfRollback", false);
126 aaiVnfResources.deleteVnf(genericVnf);
127 execution.setVariable("aaiVnfRollback", true);
128 } catch (Exception ex) {
129 logger.error("Exception occurred in AAIDeleteTasks deleteVnf process", ex);
130 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
136 public void deletePnf(BuildingBlockExecution execution) throws Exception {
137 Pnf pnf = extractPojosForBB.extractByKey(execution, ResourceKey.PNF);
138 execution.setVariable("aaiPnfRollback", false);
140 aaiPnfResources.deletePnf(pnf);
141 execution.setVariable("aaiPnfRollback", true);
142 } catch (Exception ex) {
143 logger.error("Exception occurred in AAIDeleteTasks deletePnf process", ex);
144 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
149 * BPMN access method to delete the ServiceInstance from A&AI.
151 * It will extract the serviceInstance from the BBObject.
156 public void deleteServiceInstance(BuildingBlockExecution execution) throws Exception {
158 ServiceInstance serviceInstance =
159 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
160 aaiSIResources.deleteServiceInstance(serviceInstance);
161 } catch (Exception ex) {
162 logger.error("Exception occurred in AAIDeleteTasks deleteServiceInstance process", ex);
163 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
169 * BPMN access method to delete the l3network from A&AI.
171 * It will extract the l3network from the BBObject.
173 * After deleting the l3network it set the isRollbackNeeded as true.
178 public void deleteNetwork(BuildingBlockExecution execution) throws Exception {
180 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
181 aaiNetworkResources.deleteNetwork(l3network);
182 execution.setVariable("isRollbackNeeded", true);
183 } catch (Exception ex) {
184 logger.error("Exception occurred in AAIDeleteTasks deleteNetwork process", ex);
185 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
190 * BPMN access method to delete the Collection from A&AI.
192 * It will extract the serviceInstance from the BBObject.
194 * Then it will get the collection from serviceinstance.
199 public void deleteCollection(BuildingBlockExecution execution) throws Exception {
201 ServiceInstance serviceInstance =
202 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
203 aaiNetworkResources.deleteCollection(serviceInstance.getCollection());
204 } catch (Exception ex) {
205 logger.error("Exception occurred in AAIDeleteTasks deleteCollection process", ex);
206 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
211 * BPMN access method to delete the InstanceGroup from A&AI.
213 * It will extract the serviceInstance from the BBObject.
215 * Then it will get the Instance group from serviceInstance.
220 public void deleteInstanceGroup(BuildingBlockExecution execution) throws Exception {
222 ServiceInstance serviceInstance =
223 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
224 aaiNetworkResources.deleteNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup());
225 } catch (Exception ex) {
226 logger.error("Exception occurred in AAIDeleteTasks deleteInstanceGroup process", ex);
227 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
232 * BPMN access method to delete the VolumeGroup from A&AI.
234 * It will extract the volumeGroup from the BBObject and cloudRegion from execution object .
236 * Then it will delete from A&AI.
241 public void deleteVolumeGroup(BuildingBlockExecution execution) {
243 VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
244 CloudRegion cloudRegion = execution.getGeneralBuildingBlock().getCloudRegion();
245 aaiVolumeGroupResources.deleteVolumeGroup(volumeGroup, cloudRegion);
246 } catch (Exception ex) {
247 logger.error("Exception occurred in AAIDeleteTasks deleteVolumeGroup process", ex);
248 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
253 * BPMN access method to delete the Configuration from A&AI.
255 * It will extract the configuration from the BBObject.
257 * Then it will delete from A&AI.
261 public void deleteConfiguration(BuildingBlockExecution execution) {
263 Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
264 aaiConfigurationResources.deleteConfiguration(configuration);
265 } catch (Exception ex) {
266 logger.error("Exception occurred in AAIDeleteTasks deleteConfiguration process", ex);
267 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
272 * BPMN access method to delete the InstanceGroupVnf from A&AI.
274 * It will extract the instanceGroup from the BBObject.
276 * Then it will delete from A&AI.
280 public void deleteInstanceGroupVnf(BuildingBlockExecution execution) {
282 InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
283 aaiInstanceGroupResources.deleteInstanceGroup(instanceGroup);
284 } catch (Exception ex) {
285 logger.error("Exception occurred in AAIDeleteTasks deleteInstanceGroupVnf process", ex);
286 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
291 public void deleteNetworkPolicies(BuildingBlockExecution execution) {
293 String fqdns = execution.getVariable(contrailNetworkPolicyFqdnList);
294 if (fqdns != null && !fqdns.isEmpty()) {
295 String[] fqdnList = fqdns.split(",");
296 int fqdnCount = fqdnList.length;
298 for (int i = 0; i < fqdnCount; i++) {
299 String fqdn = fqdnList[i];
300 AAIPluralResourceUri uri =
301 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicies());
302 uri.queryParam(networkPolicyFqdnParam, fqdn);
303 Optional<NetworkPolicies> oNetPolicies = aaiNetworkResources.getNetworkPolicies(uri);
304 if (oNetPolicies.isPresent()) {
305 NetworkPolicies networkPolicies = oNetPolicies.get();
306 List<NetworkPolicy> networkPolicyList = networkPolicies.getNetworkPolicy();
307 if (networkPolicyList != null && !networkPolicyList.isEmpty()) {
308 NetworkPolicy networkPolicy = networkPolicyList.get(0);
309 String networkPolicyId = networkPolicy.getNetworkPolicyId();
310 logger.debug("Deleting network-policy with network-policy-id {}", networkPolicyId);
311 aaiNetworkResources.deleteNetworkPolicy(networkPolicyId);
317 } catch (Exception ex) {
318 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);