3fc25196e121a9d149a94d065f3e5e775da57d40
[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 java.net.URI;
26 import javax.ws.rs.core.UriBuilder;
27 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
28 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
29 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation;
30 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
31 import org.onap.so.bpmn.common.BuildingBlockExecution;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
38 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
39 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
40 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
41 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
42 import org.onap.so.client.exception.ExceptionBuilder;
43 import org.onap.so.client.orchestration.SDNCNetworkResources;
44 import org.onap.so.client.orchestration.SDNCServiceInstanceResources;
45 import org.onap.so.client.orchestration.SDNCVfModuleResources;
46 import org.onap.so.client.orchestration.SDNCVnfResources;
47 import org.onap.so.client.sdnc.beans.SDNCRequest;
48 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51 import org.springframework.beans.factory.annotation.Autowired;
52 import org.springframework.core.env.Environment;
53 import org.springframework.stereotype.Component;
54
55 @Component
56 public class SDNCDeactivateTasks {
57
58     public static final String SDNC_REQUEST = "SDNCRequest";
59     @Autowired
60     private SDNCNetworkResources sdncNetworkResources;
61     @Autowired
62     private SDNCVfModuleResources sdncVfModuleResources;
63     @Autowired
64     private SDNCServiceInstanceResources sdncSIResources;
65     @Autowired
66     private SDNCVnfResources sdncVnfResources;
67     @Autowired
68     private ExceptionBuilder exceptionUtil;
69     @Autowired
70     private ExtractPojosForBB extractPojosForBB;
71     @Autowired
72     private Environment env;
73
74     public void deactivateVfModule(BuildingBlockExecution execution) {
75         try {
76             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
77             RequestContext requestContext = gBBInput.getRequestContext();
78             ServiceInstance serviceInstance =
79                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
80             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
81             VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
82             Customer customer = gBBInput.getCustomer();
83             CloudRegion cloudRegion = gBBInput.getCloudRegion();
84             SDNCRequest sdncRequest = new SDNCRequest();
85             UriBuilder builder = UriBuilder.fromPath(env.getRequiredProperty("mso.workflow.message.endpoint"))
86                     .path(sdncRequest.getCorrelationName()).path(sdncRequest.getCorrelationValue());
87             URI uri = builder.build();
88             GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.deactivateVfModule(vfModule, vnf,
89                     serviceInstance, customer, cloudRegion, requestContext, uri);
90             sdncRequest.setSDNCPayload(req);
91             sdncRequest.setTopology(SDNCTopology.VFMODULE);
92             execution.setVariable(SDNC_REQUEST, sdncRequest);
93         } catch (Exception ex) {
94             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
95         }
96     }
97
98     /**
99      * BPMN access method to perform Service Topology Deactivate action on SDNC for Vnf
100      * 
101      * @param execution
102      * @throws Exception
103      */
104     public void deactivateVnf(BuildingBlockExecution execution) throws Exception {
105         try {
106             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
107             RequestContext requestContext = gBBInput.getRequestContext();
108             ServiceInstance serviceInstance = null;
109             GenericVnf vnf = null;
110             serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
111             vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
112             CloudRegion cloudRegion = gBBInput.getCloudRegion();
113             Customer customer = gBBInput.getCustomer();
114             GenericResourceApiVnfOperationInformation req =
115                     sdncVnfResources.deactivateVnf(vnf, serviceInstance, customer, cloudRegion, requestContext);
116             SDNCRequest sdncRequest = new SDNCRequest();
117             sdncRequest.setSDNCPayload(req);
118             sdncRequest.setTopology(SDNCTopology.VNF);
119             execution.setVariable(SDNC_REQUEST, sdncRequest);
120         } catch (Exception ex) {
121             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
122         }
123     }
124
125     /*
126      * BPMN access method to perform Service Topology Deactivate action on SDNC for Service Instance
127      * 
128      * @param execution
129      * 
130      * @throws Exception
131      */
132     public void deactivateServiceInstance(BuildingBlockExecution execution) throws Exception {
133         try {
134             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
135             RequestContext requestContext = gBBInput.getRequestContext();
136             ServiceInstance serviceInstance =
137                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
138             Customer customer = gBBInput.getCustomer();
139             GenericResourceApiServiceOperationInformation req =
140                     sdncSIResources.deactivateServiceInstance(serviceInstance, customer, requestContext);
141             SDNCRequest sdncRequest = new SDNCRequest();
142             sdncRequest.setSDNCPayload(req);
143             sdncRequest.setTopology(SDNCTopology.SERVICE);
144             execution.setVariable(SDNC_REQUEST, sdncRequest);
145         } catch (Exception ex) {
146             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
147         }
148     }
149
150     /**
151      * BPMN access method to invoke deactivate on a L3Network object
152      * 
153      * @param execution
154      */
155     public void deactivateNetwork(BuildingBlockExecution execution) {
156         try {
157             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
158             L3Network l3Network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
159             ServiceInstance serviceInstance =
160                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
161             Customer customer = gBBInput.getCustomer();
162             RequestContext requestContext = gBBInput.getRequestContext();
163             CloudRegion cloudRegion = gBBInput.getCloudRegion();
164             GenericResourceApiNetworkOperationInformation req = sdncNetworkResources.deactivateNetwork(l3Network,
165                     serviceInstance, customer, requestContext, cloudRegion);
166             SDNCRequest sdncRequest = new SDNCRequest();
167             sdncRequest.setSDNCPayload(req);
168             sdncRequest.setTopology(SDNCTopology.NETWORK);
169             execution.setVariable(SDNC_REQUEST, sdncRequest);
170         } catch (Exception ex) {
171             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
172         }
173     }
174 }