e587830c74b8e084afa235742ffb7c359ddd2e62
[so.git] /
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
55     public static final String SDNC_REQUEST = "SDNCRequest";
56     @Autowired
57     private SDNCNetworkResources sdncNetworkResources;
58     @Autowired
59     private SDNCVfModuleResources sdncVfModuleResources;
60     @Autowired
61     private SDNCServiceInstanceResources sdncSIResources;
62     @Autowired
63     private SDNCVnfResources sdncVnfResources;
64     @Autowired
65     private ExceptionBuilder exceptionUtil;
66     @Autowired
67     private ExtractPojosForBB extractPojosForBB;
68
69     public void deactivateVfModule(BuildingBlockExecution execution) {
70         try {
71             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
72             RequestContext requestContext = gBBInput.getRequestContext();
73             ServiceInstance serviceInstance =
74                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
75             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
76             VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
77             Customer customer = gBBInput.getCustomer();
78             CloudRegion cloudRegion = gBBInput.getCloudRegion();
79             GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.deactivateVfModule(vfModule, vnf,
80                     serviceInstance, customer, cloudRegion, requestContext);
81             SDNCRequest sdncRequest = new SDNCRequest();
82             sdncRequest.setSDNCPayload(req);
83             sdncRequest.setTopology(SDNCTopology.VFMODULE);
84             execution.setVariable(SDNC_REQUEST, sdncRequest);
85         } catch (Exception ex) {
86             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
87         }
88     }
89
90     /**
91      * BPMN access method to perform Service Topology Deactivate action on SDNC for Vnf
92      * 
93      * @param execution
94      * @throws Exception
95      */
96     public void deactivateVnf(BuildingBlockExecution execution) throws Exception {
97         try {
98             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
99             RequestContext requestContext = gBBInput.getRequestContext();
100             ServiceInstance serviceInstance = null;
101             GenericVnf vnf = null;
102             serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
103             vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
104             CloudRegion cloudRegion = gBBInput.getCloudRegion();
105             Customer customer = gBBInput.getCustomer();
106             GenericResourceApiVnfOperationInformation req =
107                     sdncVnfResources.deactivateVnf(vnf, serviceInstance, customer, cloudRegion, requestContext);
108             SDNCRequest sdncRequest = new SDNCRequest();
109             sdncRequest.setSDNCPayload(req);
110             sdncRequest.setTopology(SDNCTopology.VNF);
111             execution.setVariable(SDNC_REQUEST, sdncRequest);
112         } catch (Exception ex) {
113             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
114         }
115     }
116
117     /*
118      * BPMN access method to perform Service Topology Deactivate action on SDNC for Service Instance
119      * 
120      * @param execution
121      * 
122      * @throws Exception
123      */
124     public void deactivateServiceInstance(BuildingBlockExecution execution) throws Exception {
125         try {
126             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
127             RequestContext requestContext = gBBInput.getRequestContext();
128             ServiceInstance serviceInstance =
129                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
130             Customer customer = gBBInput.getCustomer();
131             GenericResourceApiServiceOperationInformation req =
132                     sdncSIResources.deactivateServiceInstance(serviceInstance, customer, requestContext);
133             SDNCRequest sdncRequest = new SDNCRequest();
134             sdncRequest.setSDNCPayload(req);
135             sdncRequest.setTopology(SDNCTopology.SERVICE);
136             execution.setVariable(SDNC_REQUEST, sdncRequest);
137         } catch (Exception ex) {
138             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
139         }
140     }
141
142     /**
143      * BPMN access method to invoke deactivate on a L3Network object
144      * 
145      * @param execution
146      */
147     public void deactivateNetwork(BuildingBlockExecution execution) {
148         try {
149             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
150             L3Network l3Network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
151             ServiceInstance serviceInstance =
152                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
153             Customer customer = gBBInput.getCustomer();
154             RequestContext requestContext = gBBInput.getRequestContext();
155             CloudRegion cloudRegion = gBBInput.getCloudRegion();
156             GenericResourceApiNetworkOperationInformation req = sdncNetworkResources.deactivateNetwork(l3Network,
157                     serviceInstance, customer, requestContext, cloudRegion);
158             SDNCRequest sdncRequest = new SDNCRequest();
159             sdncRequest.setSDNCPayload(req);
160             sdncRequest.setTopology(SDNCTopology.NETWORK);
161             execution.setVariable(SDNC_REQUEST, sdncRequest);
162         } catch (Exception ex) {
163             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
164         }
165     }
166 }