Merge "ValetStatus.jsvs: Fixed sonar issue"
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / aai / tasks / AAIDeleteTasks.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.aai.tasks;
22
23
24 import org.onap.so.bpmn.common.BuildingBlockExecution;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
32 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
33 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
34 import org.onap.so.client.exception.ExceptionBuilder;
35 import org.onap.so.client.orchestration.AAIConfigurationResources;
36 import org.onap.so.client.orchestration.AAINetworkResources;
37 import org.onap.so.client.orchestration.AAIServiceInstanceResources;
38 import org.onap.so.client.orchestration.AAIVfModuleResources;
39 import org.onap.so.client.orchestration.AAIVnfResources;
40 import org.onap.so.client.orchestration.AAIVolumeGroupResources;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.stereotype.Component;
43
44 @Component
45 public class AAIDeleteTasks {
46         
47         @Autowired
48         private ExceptionBuilder exceptionUtil;
49         @Autowired
50         private ExtractPojosForBB extractPojosForBB;
51         @Autowired
52         private AAIServiceInstanceResources aaiSIResources;
53         @Autowired
54         private AAIVnfResources aaiVnfResources;
55         @Autowired
56         private AAIVfModuleResources aaiVfModuleResources;
57         @Autowired
58         private AAINetworkResources aaiNetworkResources;
59         @Autowired
60         private AAIVolumeGroupResources aaiVolumeGroupResources;
61         @Autowired
62         private AAIConfigurationResources aaiConfigurationResources;
63         
64         public void deleteVfModule(BuildingBlockExecution execution) throws Exception {         
65                 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
66                 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
67                 
68                 execution.setVariable("aaiVfModuleRollback", false);
69                 try {
70                         aaiVfModuleResources.deleteVfModule(vfModule, genericVnf);
71                         execution.setVariable("aaiVfModuleRollback", true);
72                 } catch (Exception ex) {                        
73                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
74                 }       
75         }
76
77         public void deleteVnf(BuildingBlockExecution execution) throws Exception {              
78                 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
79                 
80                 execution.setVariable("aaiVnfRollback", false);
81                 try {
82                         aaiVnfResources.deleteVnf(genericVnf);
83                         execution.setVariable("aaiVnfRollback", true);
84                 } catch (Exception ex) {                        
85                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
86                 }       
87         }
88         
89         public void deleteServiceInstance(BuildingBlockExecution execution) throws Exception {
90                 try {
91                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); 
92                         aaiSIResources.deleteServiceInstance(serviceInstance);
93                 }
94                 catch(Exception ex) {
95                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
96                 }
97                 
98         }
99         
100         public void deleteNetwork(BuildingBlockExecution execution) throws Exception {
101                 try {
102                         L3Network l3network =  extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID)); 
103                         aaiNetworkResources.deleteNetwork(l3network);
104                         execution.setVariable("isRollbackNeeded", true);
105                 }
106                 catch(Exception ex) {
107                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
108                 }
109         }
110         
111         public void deleteCollection(BuildingBlockExecution execution) throws Exception {
112                 try {
113                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); 
114                         aaiNetworkResources.deleteCollection(serviceInstance.getCollection());
115                 }
116                 catch(Exception ex) {
117                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
118                 }
119         }
120         
121         public void deleteInstanceGroup(BuildingBlockExecution execution) throws Exception {
122                 try {
123                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); 
124                         aaiNetworkResources.deleteNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup());
125                 }
126                 catch(Exception ex) {
127                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
128                 }
129         }
130         
131         public void deleteVolumeGroup(BuildingBlockExecution execution) {
132                 try {
133                         VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
134                         CloudRegion cloudRegion = execution.getGeneralBuildingBlock().getCloudRegion();
135                         aaiVolumeGroupResources.deleteVolumeGroup(volumeGroup, cloudRegion);
136                 } catch (Exception ex) {
137                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
138                 }
139         }
140         public void deleteConfiguration(BuildingBlockExecution execution) {
141                 try {
142                         Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID, execution.getLookupMap().get(ResourceKey.CONFIGURATION_ID));
143                         aaiConfigurationResources.deleteConfiguration(configuration);
144                 } catch (Exception ex) {
145                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
146                 }
147         }
148 }