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.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.AAINetworkResources;
47 import org.onap.so.client.orchestration.AAIServiceInstanceResources;
48 import org.onap.so.client.orchestration.AAIVfModuleResources;
49 import org.onap.so.client.orchestration.AAIVnfResources;
50 import org.onap.so.client.orchestration.AAIVolumeGroupResources;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53 import org.springframework.beans.factory.annotation.Autowired;
54 import org.springframework.stereotype.Component;
57 public class AAIDeleteTasks {
58 private static final Logger logger = LoggerFactory.getLogger(AAIDeleteTasks.class);
60 private static String CONTRAIL_NETWORK_POLICY_FQDN_LIST = "contrailNetworkPolicyFqdnList";
61 private static String NETWORK_POLICY_FQDN_PARAM = "network-policy-fqdn";
64 private ExceptionBuilder exceptionUtil;
66 private ExtractPojosForBB extractPojosForBB;
68 private AAIServiceInstanceResources aaiSIResources;
70 private AAIVnfResources aaiVnfResources;
72 private AAIVfModuleResources aaiVfModuleResources;
74 private AAINetworkResources aaiNetworkResources;
76 private AAIVolumeGroupResources aaiVolumeGroupResources;
78 private AAIConfigurationResources aaiConfigurationResources;
80 public void deleteVfModule(BuildingBlockExecution execution) throws Exception {
81 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
82 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
84 execution.setVariable("aaiVfModuleRollback", false);
86 aaiVfModuleResources.deleteVfModule(vfModule, genericVnf);
87 execution.setVariable("aaiVfModuleRollback", true);
88 } catch (Exception ex) {
89 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
93 public void deleteVnf(BuildingBlockExecution execution) throws Exception {
94 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
96 execution.setVariable("aaiVnfRollback", false);
98 aaiVnfResources.deleteVnf(genericVnf);
99 execution.setVariable("aaiVnfRollback", true);
100 } catch (Exception ex) {
101 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
105 public void deleteServiceInstance(BuildingBlockExecution execution) throws Exception {
107 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
108 aaiSIResources.deleteServiceInstance(serviceInstance);
110 catch(Exception ex) {
111 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
116 public void deleteNetwork(BuildingBlockExecution execution) throws Exception {
118 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
119 aaiNetworkResources.deleteNetwork(l3network);
120 execution.setVariable("isRollbackNeeded", true);
122 catch(Exception ex) {
123 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
127 public void deleteCollection(BuildingBlockExecution execution) throws Exception {
129 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
130 aaiNetworkResources.deleteCollection(serviceInstance.getCollection());
132 catch(Exception ex) {
133 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
137 public void deleteInstanceGroup(BuildingBlockExecution execution) throws Exception {
139 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
140 aaiNetworkResources.deleteNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup());
142 catch(Exception ex) {
143 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
147 public void deleteVolumeGroup(BuildingBlockExecution execution) {
149 VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
150 CloudRegion cloudRegion = execution.getGeneralBuildingBlock().getCloudRegion();
151 aaiVolumeGroupResources.deleteVolumeGroup(volumeGroup, cloudRegion);
152 } catch (Exception ex) {
153 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
156 public void deleteConfiguration(BuildingBlockExecution execution) {
158 Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID, execution.getLookupMap().get(ResourceKey.CONFIGURATION_ID));
159 aaiConfigurationResources.deleteConfiguration(configuration);
160 } catch (Exception ex) {
161 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
165 public void deleteNetworkPolicies(BuildingBlockExecution execution) {
167 String fqdns = execution.getVariable(CONTRAIL_NETWORK_POLICY_FQDN_LIST);
168 if (fqdns != null && !fqdns.isEmpty()) {
169 String fqdnList[] = fqdns.split(",");
170 int fqdnCount = fqdnList.length;
172 for (int i=0; i < fqdnCount; i++) {
173 String fqdn = fqdnList[i];
174 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY);
175 uri.queryParam(NETWORK_POLICY_FQDN_PARAM, fqdn);
176 Optional<NetworkPolicies> oNetPolicies = aaiNetworkResources.getNetworkPolicies(uri);
177 if(oNetPolicies.isPresent()) {
178 NetworkPolicies networkPolicies = oNetPolicies.get();
179 List<NetworkPolicy> networkPolicyList = networkPolicies.getNetworkPolicy();
180 if (networkPolicyList != null && !networkPolicyList.isEmpty()) {
181 NetworkPolicy networkPolicy = networkPolicyList.get(0);
182 String networkPolicyId = networkPolicy.getNetworkPolicyId();
183 logger.debug("Deleting network-policy with network-policy-id {}", networkPolicyId);
184 aaiNetworkResources.deleteNetworkPolicy(networkPolicyId);
190 } catch (Exception ex) {
191 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);