Containerization feature of SO
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / sdnc / tasks / SDNCDeactivateTasks.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.sdnc.tasks;
22
23 import org.onap.so.bpmn.common.BuildingBlockExecution;
24 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
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.entities.GeneralBuildingBlock;
31 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
32 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
33 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
34 import org.onap.so.client.exception.ExceptionBuilder;
35 import org.onap.so.client.orchestration.SDNCNetworkResources;
36 import org.onap.so.client.orchestration.SDNCServiceInstanceResources;
37 import org.onap.so.client.orchestration.SDNCVfModuleResources;
38 import org.onap.so.client.orchestration.SDNCVnfResources;
39 import org.onap.so.logger.MsoLogger;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.stereotype.Component;
42
43 @Component
44 public class SDNCDeactivateTasks {
45         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,
46                         SDNCDeactivateTasks.class);
47         @Autowired
48         private SDNCNetworkResources sdncNetworkResources;
49         @Autowired
50         private SDNCVfModuleResources sdncVfModuleResources;
51         @Autowired
52         private SDNCServiceInstanceResources sdncSIResources;
53         @Autowired
54         private SDNCVnfResources sdncVnfResources;
55         @Autowired
56         private ExceptionBuilder exceptionUtil;
57         @Autowired
58         private ExtractPojosForBB extractPojosForBB;
59
60         public void deactivateVfModule(BuildingBlockExecution execution) {
61                 try {
62                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
63                         RequestContext requestContext = gBBInput.getRequestContext();
64
65                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID,
66                                         execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
67                         GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID,
68                                         execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
69                         VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID,
70                                         execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
71
72                         Customer customer = gBBInput.getCustomer();
73                         CloudRegion cloudRegion = gBBInput.getCloudRegion();
74                         execution.setVariable("sdncDeactivateVfModuleRollback", false);
75
76                         String response = sdncVfModuleResources.deactivateVfModule(vfModule, vnf, serviceInstance, customer,
77                                         cloudRegion, requestContext);
78                         execution.setVariable("SDNCDeactivateVfModuleResponse", response);
79                         execution.setVariable("sdncDeactivateVfModuleRollback", true);
80                 } catch (Exception ex) {
81                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
82                 }
83         }
84
85         /**
86          * BPMN access method to perform Service Topology Deactivate action on SDNC for Vnf
87          * @param execution
88          * @throws Exception
89          */
90         public void deactivateVnf(BuildingBlockExecution execution) throws Exception {
91                 try {
92                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
93                         RequestContext requestContext = gBBInput.getRequestContext();
94                         ServiceInstance serviceInstance = null;
95                         GenericVnf vnf = null;
96                                         
97                         serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID,
98                                         execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
99                         vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID,
100                                         execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
101                         CloudRegion cloudRegion = gBBInput.getCloudRegion();
102                         Customer customer = gBBInput.getCustomer();
103                         String response = sdncVnfResources.deactivateVnf(vnf, serviceInstance, customer, cloudRegion, requestContext);
104                         execution.setVariable("SDNCDeactivateVnfResponse", response);
105                 } catch (Exception ex) {
106                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
107                 }
108         }
109
110         /*      
111          * BPMN access method to perform Service Topology Deactivate action on SDNC for Service Instance
112          * @param execution
113          * @throws Exception
114          */
115         public void deactivateServiceInstance(BuildingBlockExecution execution) throws Exception {
116                 try {
117                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
118                         RequestContext requestContext = gBBInput.getRequestContext();
119                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID,
120                                         execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
121                         Customer customer = gBBInput.getCustomer();
122                         execution.setVariable("sdncServiceInstanceRollback", false);
123                         String response = sdncSIResources.deactivateServiceInstance(serviceInstance, customer, requestContext);
124                         execution.setVariable("deactivateServiceInstanceSDNCResponse", response);
125                         execution.setVariable("sdncServiceInstanceRollback", true);
126                 } catch (Exception ex) {
127                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
128                 }
129         }
130
131         /**
132          * BPMN access method to invoke deactivate on a L3Network object
133          * 
134          * @param execution
135          */
136         public void deactivateNetwork(BuildingBlockExecution execution) {
137                 execution.setVariable("SDNCDeactivateTasks.deactivateNetwork.rollback", false);
138                 try {
139                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
140                         L3Network l3Network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
141                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
142                         Customer customer = gBBInput.getCustomer();
143                         RequestContext requestContext = gBBInput.getRequestContext();
144                         CloudRegion cloudRegion = gBBInput.getCloudRegion();
145
146                         String response = sdncNetworkResources.deactivateNetwork(l3Network, serviceInstance, customer,
147                                         requestContext, cloudRegion);
148                         execution.setVariable("SDNCDeactivateTasks.deactivateNetwork.response", response);
149                         execution.setVariable("SDNCDeactivateTasks.deactivateNetwork.rollback", true);
150                 } catch (Exception ex) {
151                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
152                 }
153         }
154 }