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;
29 import org.onap.aai.domain.yang.NetworkPolicies;
30 import org.onap.aai.domain.yang.NetworkPolicy;
31 import org.onap.so.bpmn.common.BuildingBlockExecution;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
40 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
41 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
42 import org.onap.so.client.aai.AAIObjectPlurals;
43 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
44 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
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.AAIVolumeGroupResources;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
55 import org.springframework.beans.factory.annotation.Autowired;
56 import org.springframework.stereotype.Component;
59 public class AAIDeleteTasks {
60 private static final Logger logger = LoggerFactory.getLogger(AAIDeleteTasks.class);
62 private static String CONTRAIL_NETWORK_POLICY_FQDN_LIST = "contrailNetworkPolicyFqdnList";
63 private static String NETWORK_POLICY_FQDN_PARAM = "network-policy-fqdn";
66 private ExceptionBuilder exceptionUtil;
68 private ExtractPojosForBB extractPojosForBB;
70 private AAIServiceInstanceResources aaiSIResources;
72 private AAIVnfResources aaiVnfResources;
74 private AAIVfModuleResources aaiVfModuleResources;
76 private AAINetworkResources aaiNetworkResources;
78 private AAIVolumeGroupResources aaiVolumeGroupResources;
80 private AAIConfigurationResources aaiConfigurationResources;
82 private AAIInstanceGroupResources aaiInstanceGroupResources;
84 public void deleteVfModule(BuildingBlockExecution execution) throws Exception {
85 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
86 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
88 execution.setVariable("aaiVfModuleRollback", false);
90 aaiVfModuleResources.deleteVfModule(vfModule, genericVnf);
91 execution.setVariable("aaiVfModuleRollback", true);
92 } catch (Exception ex) {
93 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
97 public void deleteVnf(BuildingBlockExecution execution) throws Exception {
98 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
100 execution.setVariable("aaiVnfRollback", false);
102 aaiVnfResources.deleteVnf(genericVnf);
103 execution.setVariable("aaiVnfRollback", true);
104 } catch (Exception ex) {
105 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
109 public void deleteServiceInstance(BuildingBlockExecution execution) throws Exception {
111 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
112 aaiSIResources.deleteServiceInstance(serviceInstance);
114 catch(Exception ex) {
115 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
120 public void deleteNetwork(BuildingBlockExecution execution) throws Exception {
122 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
123 aaiNetworkResources.deleteNetwork(l3network);
124 execution.setVariable("isRollbackNeeded", true);
126 catch(Exception ex) {
127 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
131 public void deleteCollection(BuildingBlockExecution execution) throws Exception {
133 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
134 aaiNetworkResources.deleteCollection(serviceInstance.getCollection());
136 catch(Exception ex) {
137 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
141 public void deleteInstanceGroup(BuildingBlockExecution execution) throws Exception {
143 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
144 aaiNetworkResources.deleteNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup());
146 catch(Exception ex) {
147 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
151 public void deleteVolumeGroup(BuildingBlockExecution execution) {
153 VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
154 CloudRegion cloudRegion = execution.getGeneralBuildingBlock().getCloudRegion();
155 aaiVolumeGroupResources.deleteVolumeGroup(volumeGroup, cloudRegion);
156 } catch (Exception ex) {
157 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
160 public void deleteConfiguration(BuildingBlockExecution execution) {
162 Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
163 aaiConfigurationResources.deleteConfiguration(configuration);
164 } catch (Exception ex) {
165 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
169 public void deleteInstanceGroupVnf(BuildingBlockExecution execution) {
171 InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
172 aaiInstanceGroupResources.deleteInstanceGroup(instanceGroup);
173 } catch (Exception ex) {
174 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
178 public void deleteNetworkPolicies(BuildingBlockExecution execution) {
180 String fqdns = execution.getVariable(CONTRAIL_NETWORK_POLICY_FQDN_LIST);
181 if (fqdns != null && !fqdns.isEmpty()) {
182 String fqdnList[] = fqdns.split(",");
183 int fqdnCount = fqdnList.length;
185 for (int i=0; i < fqdnCount; i++) {
186 String fqdn = fqdnList[i];
187 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY);
188 uri.queryParam(NETWORK_POLICY_FQDN_PARAM, fqdn);
189 Optional<NetworkPolicies> oNetPolicies = aaiNetworkResources.getNetworkPolicies(uri);
190 if(oNetPolicies.isPresent()) {
191 NetworkPolicies networkPolicies = oNetPolicies.get();
192 List<NetworkPolicy> networkPolicyList = networkPolicies.getNetworkPolicy();
193 if (networkPolicyList != null && !networkPolicyList.isEmpty()) {
194 NetworkPolicy networkPolicy = networkPolicyList.get(0);
195 String networkPolicyId = networkPolicy.getNetworkPolicyId();
196 logger.debug("Deleting network-policy with network-policy-id {}", networkPolicyId);
197 aaiNetworkResources.deleteNetworkPolicy(networkPolicyId);
203 } catch (Exception ex) {
204 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);