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;
83 public void deleteVfModule(BuildingBlockExecution execution) throws Exception {
84 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
85 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
87 execution.setVariable("aaiVfModuleRollback", false);
89 aaiVfModuleResources.deleteVfModule(vfModule, genericVnf);
90 execution.setVariable("aaiVfModuleRollback", true);
91 } catch (Exception ex) {
92 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
96 public void deleteVnf(BuildingBlockExecution execution) throws Exception {
97 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
99 execution.setVariable("aaiVnfRollback", false);
101 aaiVnfResources.deleteVnf(genericVnf);
102 execution.setVariable("aaiVnfRollback", true);
103 } catch (Exception ex) {
104 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
108 public void deleteServiceInstance(BuildingBlockExecution execution) throws Exception {
110 ServiceInstance serviceInstance =
111 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
112 aaiSIResources.deleteServiceInstance(serviceInstance);
113 } catch (Exception ex) {
114 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
119 public void deleteNetwork(BuildingBlockExecution execution) throws Exception {
121 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
122 aaiNetworkResources.deleteNetwork(l3network);
123 execution.setVariable("isRollbackNeeded", true);
124 } catch (Exception ex) {
125 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
129 public void deleteCollection(BuildingBlockExecution execution) throws Exception {
131 ServiceInstance serviceInstance =
132 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
133 aaiNetworkResources.deleteCollection(serviceInstance.getCollection());
134 } catch (Exception ex) {
135 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
139 public void deleteInstanceGroup(BuildingBlockExecution execution) throws Exception {
141 ServiceInstance serviceInstance =
142 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
143 aaiNetworkResources.deleteNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup());
144 } catch (Exception ex) {
145 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
149 public void deleteVolumeGroup(BuildingBlockExecution execution) {
151 VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
152 CloudRegion cloudRegion = execution.getGeneralBuildingBlock().getCloudRegion();
153 aaiVolumeGroupResources.deleteVolumeGroup(volumeGroup, cloudRegion);
154 } catch (Exception ex) {
155 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
159 public void deleteConfiguration(BuildingBlockExecution execution) {
161 Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
162 aaiConfigurationResources.deleteConfiguration(configuration);
163 } catch (Exception ex) {
164 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
168 public void deleteInstanceGroupVnf(BuildingBlockExecution execution) {
170 InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
171 aaiInstanceGroupResources.deleteInstanceGroup(instanceGroup);
172 } catch (Exception ex) {
173 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
177 public void deleteNetworkPolicies(BuildingBlockExecution execution) {
179 String fqdns = execution.getVariable(contrailNetworkPolicyFqdnList);
180 if (fqdns != null && !fqdns.isEmpty()) {
181 String[] fqdnList = fqdns.split(",");
182 int fqdnCount = fqdnList.length;
184 for (int i = 0; i < fqdnCount; i++) {
185 String fqdn = fqdnList[i];
186 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY);
187 uri.queryParam(networkPolicyFqdnParam, fqdn);
188 Optional<NetworkPolicies> oNetPolicies = aaiNetworkResources.getNetworkPolicies(uri);
189 if (oNetPolicies.isPresent()) {
190 NetworkPolicies networkPolicies = oNetPolicies.get();
191 List<NetworkPolicy> networkPolicyList = networkPolicies.getNetworkPolicy();
192 if (networkPolicyList != null && !networkPolicyList.isEmpty()) {
193 NetworkPolicy networkPolicy = networkPolicyList.get(0);
194 String networkPolicyId = networkPolicy.getNetworkPolicyId();
195 logger.debug("Deleting network-policy with network-policy-id {}", networkPolicyId);
196 aaiNetworkResources.deleteNetworkPolicy(networkPolicyId);
202 } catch (Exception ex) {
203 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);