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 / SDNCChangeAssignTasks.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.sdnc.tasks;
22
23 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
24 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
25 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation;
26 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
27 import org.onap.so.bpmn.common.BuildingBlockExecution;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
34 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
35 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
36 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
37 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
38 import org.onap.so.client.exception.ExceptionBuilder;
39 import org.onap.so.client.orchestration.SDNCNetworkResources;
40 import org.onap.so.client.orchestration.SDNCServiceInstanceResources;
41 import org.onap.so.client.orchestration.SDNCVfModuleResources;
42 import org.onap.so.client.orchestration.SDNCVnfResources;
43 import org.onap.so.client.sdnc.beans.SDNCRequest;
44 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
45 import org.springframework.beans.factory.annotation.Autowired;
46 import org.springframework.stereotype.Component;
47
48 @Component
49 public class SDNCChangeAssignTasks {
50     @Autowired
51     private SDNCNetworkResources sdncNetworkResources;
52     @Autowired
53     private SDNCServiceInstanceResources sdncServiceInstanceResources;
54     @Autowired
55     private SDNCVnfResources sdncVnfResources;
56     @Autowired
57     private ExtractPojosForBB extractPojosForBB;
58     @Autowired
59     private ExceptionBuilder exceptionUtil;
60     @Autowired
61     private SDNCVfModuleResources sdncVfModuleResources;
62
63     public void changeModelServiceInstance(BuildingBlockExecution execution) {
64         try {
65             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
66             ServiceInstance serviceInstance =
67                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
68             GenericResourceApiServiceOperationInformation req = sdncServiceInstanceResources
69                     .changeModelServiceInstance(serviceInstance, gBBInput.getCustomer(), gBBInput.getRequestContext());
70             SDNCRequest sdncRequest = new SDNCRequest();
71             sdncRequest.setSDNCPayload(req);
72             sdncRequest.setTopology(SDNCTopology.SERVICE);
73             execution.setVariable("SDNCRequest", sdncRequest);
74         } catch (Exception ex) {
75             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
76         }
77     }
78
79     public void changeModelVnf(BuildingBlockExecution execution) {
80         try {
81             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
82             GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
83             ServiceInstance serviceInstance =
84                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
85             GenericResourceApiVnfOperationInformation req = sdncVnfResources.changeModelVnf(genericVnf, serviceInstance,
86                     gBBInput.getCustomer(), gBBInput.getCloudRegion(), gBBInput.getRequestContext());
87             SDNCRequest sdncRequest = new SDNCRequest();
88             sdncRequest.setSDNCPayload(req);
89             sdncRequest.setTopology(SDNCTopology.VNF);
90             execution.setVariable("SDNCRequest", sdncRequest);
91         } catch (Exception ex) {
92             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
93         }
94     }
95
96     public void changeAssignNetwork(BuildingBlockExecution execution) {
97         try {
98             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
99             L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
100             ServiceInstance serviceInstance =
101                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
102             GenericResourceApiNetworkOperationInformation req = sdncNetworkResources.changeAssignNetwork(network,
103                     serviceInstance, gBBInput.getCustomer(), gBBInput.getRequestContext(), gBBInput.getCloudRegion());
104             SDNCRequest sdncRequest = new SDNCRequest();
105             sdncRequest.setSDNCPayload(req);
106             sdncRequest.setTopology(SDNCTopology.NETWORK);
107             execution.setVariable("SDNCRequest", sdncRequest);
108         } catch (Exception ex) {
109             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
110         }
111     }
112
113     public void changeAssignModelVfModule(BuildingBlockExecution execution) throws Exception {
114         try {
115             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
116             RequestContext requestContext = gBBInput.getRequestContext();
117             CloudRegion cloudRegion = gBBInput.getCloudRegion();
118             ServiceInstance serviceInstance =
119                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
120             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
121             VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
122             Customer customer = gBBInput.getCustomer();
123             GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.changeAssignVfModule(vfModule,
124                     vnf, serviceInstance, customer, cloudRegion, requestContext);
125             SDNCRequest sdncRequest = new SDNCRequest();
126             sdncRequest.setSDNCPayload(req);
127             sdncRequest.setTopology(SDNCTopology.VFMODULE);
128             execution.setVariable("SDNCRequest", sdncRequest);
129         } catch (Exception ex) {
130             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
131         }
132     }
133 }