Replaced all tabs with spaces in java and pom.xml
[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  * 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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.sdnc.tasks;
24
25 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
26 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
27 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation;
28 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
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.Customer;
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.entities.GeneralBuildingBlock;
37 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
38 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
39 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
40 import org.onap.so.client.exception.ExceptionBuilder;
41 import org.onap.so.client.orchestration.SDNCNetworkResources;
42 import org.onap.so.client.orchestration.SDNCServiceInstanceResources;
43 import org.onap.so.client.orchestration.SDNCVfModuleResources;
44 import org.onap.so.client.orchestration.SDNCVnfResources;
45 import org.onap.so.client.sdnc.beans.SDNCRequest;
46 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49 import org.springframework.beans.factory.annotation.Autowired;
50 import org.springframework.stereotype.Component;
51
52 @Component
53 public class SDNCDeactivateTasks {
54     private static final Logger logger = LoggerFactory.getLogger(SDNCDeactivateTasks.class);
55     @Autowired
56     private SDNCNetworkResources sdncNetworkResources;
57     @Autowired
58     private SDNCVfModuleResources sdncVfModuleResources;
59     @Autowired
60     private SDNCServiceInstanceResources sdncSIResources;
61     @Autowired
62     private SDNCVnfResources sdncVnfResources;
63     @Autowired
64     private ExceptionBuilder exceptionUtil;
65     @Autowired
66     private ExtractPojosForBB extractPojosForBB;
67
68     public void deactivateVfModule(BuildingBlockExecution execution) {
69         try {
70             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
71             RequestContext requestContext = gBBInput.getRequestContext();
72             ServiceInstance serviceInstance =
73                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
74             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
75             VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
76             Customer customer = gBBInput.getCustomer();
77             CloudRegion cloudRegion = gBBInput.getCloudRegion();
78             GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.deactivateVfModule(vfModule, vnf,
79                     serviceInstance, customer, cloudRegion, requestContext);
80             SDNCRequest sdncRequest = new SDNCRequest();
81             sdncRequest.setSDNCPayload(req);
82             sdncRequest.setTopology(SDNCTopology.VFMODULE);
83             execution.setVariable("SDNCRequest", sdncRequest);
84         } catch (Exception ex) {
85             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
86         }
87     }
88
89     /**
90      * BPMN access method to perform Service Topology Deactivate action on SDNC for Vnf
91      * 
92      * @param execution
93      * @throws Exception
94      */
95     public void deactivateVnf(BuildingBlockExecution execution) throws Exception {
96         try {
97             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
98             RequestContext requestContext = gBBInput.getRequestContext();
99             ServiceInstance serviceInstance = null;
100             GenericVnf vnf = null;
101             serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
102             vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
103             CloudRegion cloudRegion = gBBInput.getCloudRegion();
104             Customer customer = gBBInput.getCustomer();
105             GenericResourceApiVnfOperationInformation req =
106                     sdncVnfResources.deactivateVnf(vnf, serviceInstance, customer, cloudRegion, requestContext);
107             SDNCRequest sdncRequest = new SDNCRequest();
108             sdncRequest.setSDNCPayload(req);
109             sdncRequest.setTopology(SDNCTopology.VNF);
110             execution.setVariable("SDNCRequest", sdncRequest);
111         } catch (Exception ex) {
112             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
113         }
114     }
115
116     /*
117      * BPMN access method to perform Service Topology Deactivate action on SDNC for Service Instance
118      * 
119      * @param execution
120      * 
121      * @throws Exception
122      */
123     public void deactivateServiceInstance(BuildingBlockExecution execution) throws Exception {
124         try {
125             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
126             RequestContext requestContext = gBBInput.getRequestContext();
127             ServiceInstance serviceInstance =
128                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
129             Customer customer = gBBInput.getCustomer();
130             GenericResourceApiServiceOperationInformation req =
131                     sdncSIResources.deactivateServiceInstance(serviceInstance, customer, requestContext);
132             SDNCRequest sdncRequest = new SDNCRequest();
133             sdncRequest.setSDNCPayload(req);
134             sdncRequest.setTopology(SDNCTopology.SERVICE);
135             execution.setVariable("SDNCRequest", sdncRequest);
136         } catch (Exception ex) {
137             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
138         }
139     }
140
141     /**
142      * BPMN access method to invoke deactivate on a L3Network object
143      * 
144      * @param execution
145      */
146     public void deactivateNetwork(BuildingBlockExecution execution) {
147         try {
148             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
149             L3Network l3Network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
150             ServiceInstance serviceInstance =
151                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
152             Customer customer = gBBInput.getCustomer();
153             RequestContext requestContext = gBBInput.getRequestContext();
154             CloudRegion cloudRegion = gBBInput.getCloudRegion();
155             GenericResourceApiNetworkOperationInformation req = sdncNetworkResources.deactivateNetwork(l3Network,
156                     serviceInstance, customer, requestContext, cloudRegion);
157             SDNCRequest sdncRequest = new SDNCRequest();
158             sdncRequest.setSDNCPayload(req);
159             sdncRequest.setTopology(SDNCTopology.NETWORK);
160             execution.setVariable("SDNCRequest", sdncRequest);
161         } catch (Exception ex) {
162             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
163         }
164     }
165 }