cb265b6e4189f5529c98540c3ae52a276d539d4d
[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.GenericVnf;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
31 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
32 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
33 import org.onap.so.client.exception.ExceptionBuilder;
34 import org.onap.so.client.orchestration.AAINetworkResources;
35 import org.onap.so.client.orchestration.AAIServiceInstanceResources;
36 import org.onap.so.client.orchestration.AAIVfModuleResources;
37 import org.onap.so.client.orchestration.AAIVnfResources;
38 import org.onap.so.client.orchestration.AAIVolumeGroupResources;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Component;
41
42 @Component
43 public class AAIDeleteTasks {
44         
45         @Autowired
46         private ExceptionBuilder exceptionUtil;
47         @Autowired
48         private ExtractPojosForBB extractPojosForBB;
49         @Autowired
50         private AAIServiceInstanceResources aaiSIResources;
51         @Autowired
52         private AAIVnfResources aaiVnfResources;
53         @Autowired
54         private AAIVfModuleResources aaiVfModuleResources;
55         @Autowired
56         private AAINetworkResources aaiNetworkResources;
57         @Autowired
58         private AAIVolumeGroupResources aaiVolumeGroupResources;
59         
60         public void deleteVfModule(BuildingBlockExecution execution) throws Exception {         
61                 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
62                 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
63                 
64                 execution.setVariable("aaiVfModuleRollback", false);
65                 try {
66                         aaiVfModuleResources.deleteVfModule(vfModule, genericVnf);
67                         execution.setVariable("aaiVfModuleRollback", true);
68                 } catch (Exception ex) {                        
69                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
70                 }       
71         }
72
73         public void deleteVnf(BuildingBlockExecution execution) throws Exception {              
74                 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
75                 
76                 execution.setVariable("aaiVnfRollback", false);
77                 try {
78                         aaiVnfResources.deleteVnf(genericVnf);
79                         execution.setVariable("aaiVnfRollback", true);
80                 } catch (Exception ex) {                        
81                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
82                 }       
83         }
84         
85         public void deleteServiceInstance(BuildingBlockExecution execution) throws Exception {
86                 try {
87                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); 
88                         aaiSIResources.deleteServiceInstance(serviceInstance);
89                 }
90                 catch(Exception ex) {
91                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
92                 }
93                 
94         }
95         
96         public void deleteNetwork(BuildingBlockExecution execution) throws Exception {
97                 try {
98                         L3Network l3network =  extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID)); 
99                         aaiNetworkResources.deleteNetwork(l3network);
100                         execution.setVariable("isRollbackNeeded", true);
101                 }
102                 catch(Exception ex) {
103                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
104                 }
105         }
106         
107         public void deleteCollection(BuildingBlockExecution execution) throws Exception {
108                 try {
109                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); 
110                         aaiNetworkResources.deleteCollection(serviceInstance.getCollection());
111                 }
112                 catch(Exception ex) {
113                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
114                 }
115         }
116         
117         public void deleteInstanceGroup(BuildingBlockExecution execution) throws Exception {
118                 try {
119                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); 
120                         aaiNetworkResources.deleteNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup());
121                 }
122                 catch(Exception ex) {
123                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
124                 }
125         }
126         
127         public void deleteVolumeGroup(BuildingBlockExecution execution) {
128                 try {
129                         VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
130                         CloudRegion cloudRegion = execution.getGeneralBuildingBlock().getCloudRegion();
131                         aaiVolumeGroupResources.deleteVolumeGroup(volumeGroup, cloudRegion);
132                 } catch (Exception ex) {
133                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
134                 }
135         }
136 }