59e46e16672854376600c26a4cfc824ea690300d
[so.git] /
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 = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
67                         GenericResourceApiServiceOperationInformation req = sdncServiceInstanceResources.changeModelServiceInstance(serviceInstance, gBBInput.getCustomer(), gBBInput.getRequestContext());
68                         SDNCRequest sdncRequest = new SDNCRequest();
69                         sdncRequest.setSDNCPayload(req);
70                         sdncRequest.setTopology(SDNCTopology.SERVICE);
71                         execution.setVariable("SDNCRequest", sdncRequest);
72                 } catch(Exception ex) {
73                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
74                 }
75         }
76         
77         public void changeModelVnf(BuildingBlockExecution execution) {
78                 try {
79                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
80                         GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
81                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
82                         GenericResourceApiVnfOperationInformation req = sdncVnfResources.changeModelVnf(genericVnf, serviceInstance, gBBInput.getCustomer(), gBBInput.getCloudRegion(), gBBInput.getRequestContext());
83                         SDNCRequest sdncRequest = new SDNCRequest();
84                         sdncRequest.setSDNCPayload(req);
85                         sdncRequest.setTopology(SDNCTopology.VNF);
86                         execution.setVariable("SDNCRequest", sdncRequest);
87                 } catch(Exception ex) {
88                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
89                 }
90         }
91         
92         public void changeAssignNetwork(BuildingBlockExecution execution) {
93                 try {
94                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
95                         L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
96                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
97                         GenericResourceApiNetworkOperationInformation req = sdncNetworkResources.changeAssignNetwork(network, serviceInstance, gBBInput.getCustomer(), gBBInput.getRequestContext(), gBBInput.getCloudRegion());
98                         SDNCRequest sdncRequest = new SDNCRequest();
99                         sdncRequest.setSDNCPayload(req);
100                         sdncRequest.setTopology(SDNCTopology.NETWORK);
101                         execution.setVariable("SDNCRequest", sdncRequest);
102                 } catch(Exception ex) {
103                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
104                 }
105         }
106         
107         public void changeAssignModelVfModule(BuildingBlockExecution execution) throws Exception {
108                 try {
109                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
110                         RequestContext requestContext = gBBInput.getRequestContext();
111                         CloudRegion cloudRegion = gBBInput.getCloudRegion();
112                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
113                         GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
114                         VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
115                         Customer customer = gBBInput.getCustomer();
116                         GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.changeAssignVfModule(vfModule, vnf, serviceInstance, customer, cloudRegion, requestContext);
117                         SDNCRequest sdncRequest = new SDNCRequest();
118                         sdncRequest.setSDNCPayload(req);
119                         sdncRequest.setTopology(SDNCTopology.VFMODULE);
120                         execution.setVariable("SDNCRequest", sdncRequest);
121                 } catch (Exception ex) {
122                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
123                 }
124         }
125 }