2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.aai.tasks;
24 import java.util.List;
25 import java.util.Optional;
27 import org.onap.aai.domain.yang.NetworkPolicies;
28 import org.onap.aai.domain.yang.NetworkPolicy;
29 import org.onap.so.bpmn.common.BuildingBlockExecution;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
37 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
38 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
39 import org.onap.so.client.aai.AAIObjectPlurals;
40 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
41 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
42 import org.onap.so.client.exception.ExceptionBuilder;
43 import org.onap.so.client.orchestration.AAIConfigurationResources;
44 import org.onap.so.client.orchestration.AAINetworkResources;
45 import org.onap.so.client.orchestration.AAIServiceInstanceResources;
46 import org.onap.so.client.orchestration.AAIVfModuleResources;
47 import org.onap.so.client.orchestration.AAIVnfResources;
48 import org.onap.so.client.orchestration.AAIVolumeGroupResources;
49 import org.onap.so.logger.MsoLogger;
50 import org.springframework.beans.factory.annotation.Autowired;
51 import org.springframework.stereotype.Component;
54 public class AAIDeleteTasks {
55 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AAIDeleteTasks.class);
57 private static String CONTRAIL_NETWORK_POLICY_FQDN_LIST = "contrailNetworkPolicyFqdnList";
58 private static String NETWORK_POLICY_FQDN_PARAM = "network-policy-fqdn";
61 private ExceptionBuilder exceptionUtil;
63 private ExtractPojosForBB extractPojosForBB;
65 private AAIServiceInstanceResources aaiSIResources;
67 private AAIVnfResources aaiVnfResources;
69 private AAIVfModuleResources aaiVfModuleResources;
71 private AAINetworkResources aaiNetworkResources;
73 private AAIVolumeGroupResources aaiVolumeGroupResources;
75 private AAIConfigurationResources aaiConfigurationResources;
77 public void deleteVfModule(BuildingBlockExecution execution) throws Exception {
78 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
79 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
81 execution.setVariable("aaiVfModuleRollback", false);
83 aaiVfModuleResources.deleteVfModule(vfModule, genericVnf);
84 execution.setVariable("aaiVfModuleRollback", true);
85 } catch (Exception ex) {
86 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
90 public void deleteVnf(BuildingBlockExecution execution) throws Exception {
91 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
93 execution.setVariable("aaiVnfRollback", false);
95 aaiVnfResources.deleteVnf(genericVnf);
96 execution.setVariable("aaiVnfRollback", true);
97 } catch (Exception ex) {
98 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
102 public void deleteServiceInstance(BuildingBlockExecution execution) throws Exception {
104 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
105 aaiSIResources.deleteServiceInstance(serviceInstance);
107 catch(Exception ex) {
108 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
113 public void deleteNetwork(BuildingBlockExecution execution) throws Exception {
115 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
116 aaiNetworkResources.deleteNetwork(l3network);
117 execution.setVariable("isRollbackNeeded", true);
119 catch(Exception ex) {
120 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
124 public void deleteCollection(BuildingBlockExecution execution) throws Exception {
126 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
127 aaiNetworkResources.deleteCollection(serviceInstance.getCollection());
129 catch(Exception ex) {
130 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
134 public void deleteInstanceGroup(BuildingBlockExecution execution) throws Exception {
136 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
137 aaiNetworkResources.deleteNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup());
139 catch(Exception ex) {
140 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
144 public void deleteVolumeGroup(BuildingBlockExecution execution) {
146 VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
147 CloudRegion cloudRegion = execution.getGeneralBuildingBlock().getCloudRegion();
148 aaiVolumeGroupResources.deleteVolumeGroup(volumeGroup, cloudRegion);
149 } catch (Exception ex) {
150 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
153 public void deleteConfiguration(BuildingBlockExecution execution) {
155 Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID, execution.getLookupMap().get(ResourceKey.CONFIGURATION_ID));
156 aaiConfigurationResources.deleteConfiguration(configuration);
157 } catch (Exception ex) {
158 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
162 public void deleteNetworkPolicies(BuildingBlockExecution execution) {
164 String fqdns = execution.getVariable(CONTRAIL_NETWORK_POLICY_FQDN_LIST);
165 if (fqdns != null && !fqdns.isEmpty()) {
166 String fqdnList[] = fqdns.split(",");
167 int fqdnCount = fqdnList.length;
169 for (int i=0; i < fqdnCount; i++) {
170 String fqdn = fqdnList[i];
171 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY);
172 uri.queryParam(NETWORK_POLICY_FQDN_PARAM, fqdn);
173 Optional<NetworkPolicies> oNetPolicies = aaiNetworkResources.getNetworkPolicies(uri);
174 if(oNetPolicies.isPresent()) {
175 NetworkPolicies networkPolicies = oNetPolicies.get();
176 List<NetworkPolicy> networkPolicyList = networkPolicies.getNetworkPolicy();
177 if (networkPolicyList != null && !networkPolicyList.isEmpty()) {
178 NetworkPolicy networkPolicy = networkPolicyList.get(0);
179 String networkPolicyId = networkPolicy.getNetworkPolicyId();
180 msoLogger.debug("Deleting network-policy with network-policy-id " + networkPolicyId);
181 aaiNetworkResources.deleteNetworkPolicy(networkPolicyId);
187 } catch (Exception ex) {
188 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);