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