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 / SDNCActivateTasks.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.GenericResourceApiVfModuleOperationInformation;
27 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
28 import org.onap.so.bpmn.common.BuildingBlockExecution;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
35 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
36 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
37 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
38 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
39 import org.onap.so.client.exception.BBObjectNotFoundException;
40 import org.onap.so.client.exception.ExceptionBuilder;
41 import org.onap.so.client.orchestration.SDNCNetworkResources;
42 import org.onap.so.client.orchestration.SDNCVfModuleResources;
43 import org.onap.so.client.orchestration.SDNCVnfResources;
44 import org.onap.so.client.sdnc.beans.SDNCRequest;
45 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
48 import org.springframework.beans.factory.annotation.Autowired;
49 import org.springframework.stereotype.Component;
50
51 @Component
52 public class SDNCActivateTasks {
53     private static final Logger logger = LoggerFactory.getLogger(SDNCActivateTasks.class);
54     @Autowired
55     private SDNCVnfResources sdncVnfResources;
56     @Autowired
57     private ExceptionBuilder exceptionUtil;
58     @Autowired
59     private ExtractPojosForBB extractPojosForBB;
60     @Autowired
61     private SDNCNetworkResources sdncNetworkResources;
62     @Autowired
63     private SDNCVfModuleResources sdncVfModuleResources;
64
65
66     public void activateVnf(BuildingBlockExecution execution) {
67         try {
68             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
69             RequestContext requestContext = gBBInput.getRequestContext();
70             ServiceInstance serviceInstance =
71                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
72             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
73             CloudRegion cloudRegion = gBBInput.getCloudRegion();
74             Customer customer = gBBInput.getCustomer();
75             GenericResourceApiVnfOperationInformation req =
76                     sdncVnfResources.activateVnf(vnf, serviceInstance, customer, cloudRegion, requestContext);
77             SDNCRequest sdncRequest = new SDNCRequest();
78             sdncRequest.setSDNCPayload(req);
79             sdncRequest.setTopology(SDNCTopology.VNF);
80             execution.setVariable("SDNCRequest", sdncRequest);
81         } catch (Exception ex) {
82             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
83         }
84     }
85
86     /**
87      * BPMN access method to perform Assign action on SDNC for L3Network
88      * 
89      * @param execution
90      * @throws BBObjectNotFoundException
91      */
92     public void activateNetwork(BuildingBlockExecution execution) throws BBObjectNotFoundException {
93         try {
94             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
95             L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
96             ServiceInstance serviceInstance =
97                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
98             Customer customer = gBBInput.getCustomer();
99             RequestContext requestContext = gBBInput.getRequestContext();
100             CloudRegion cloudRegion = gBBInput.getCloudRegion();
101             GenericResourceApiNetworkOperationInformation req = sdncNetworkResources.activateNetwork(l3network,
102                     serviceInstance, customer, requestContext, cloudRegion);
103             SDNCRequest sdncRequest = new SDNCRequest();
104             sdncRequest.setSDNCPayload(req);
105             sdncRequest.setTopology(SDNCTopology.NETWORK);
106             execution.setVariable("SDNCRequest", sdncRequest);
107         } catch (Exception ex) {
108             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
109         }
110     }
111
112     public void activateVfModule(BuildingBlockExecution execution) {
113         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
114         RequestContext requestContext = gBBInput.getRequestContext();
115         ServiceInstance serviceInstance = null;
116         GenericVnf vnf = null;
117         VfModule vfModule = null;
118         try {
119             serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
120             vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
121             vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
122             Customer customer = gBBInput.getCustomer();
123             CloudRegion cloudRegion = gBBInput.getCloudRegion();
124             GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.activateVfModule(vfModule, vnf,
125                     serviceInstance, customer, cloudRegion, requestContext);
126             SDNCRequest sdncRequest = new SDNCRequest();
127             sdncRequest.setSDNCPayload(req);
128             sdncRequest.setTopology(SDNCTopology.VFMODULE);
129             execution.setVariable("SDNCRequest", sdncRequest);
130         } catch (Exception ex) {
131             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
132         }
133     }
134 }