4ffb39770763dc4b3cf62cab2ddfe9de323086a2
[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     public static final String SDNC_REQUEST = "SDNCRequest";
51     @Autowired
52     private SDNCNetworkResources sdncNetworkResources;
53     @Autowired
54     private SDNCServiceInstanceResources sdncServiceInstanceResources;
55     @Autowired
56     private SDNCVnfResources sdncVnfResources;
57     @Autowired
58     private ExtractPojosForBB extractPojosForBB;
59     @Autowired
60     private ExceptionBuilder exceptionUtil;
61     @Autowired
62     private SDNCVfModuleResources sdncVfModuleResources;
63
64     public void changeModelServiceInstance(BuildingBlockExecution execution) {
65         try {
66             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
67             ServiceInstance serviceInstance =
68                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
69             GenericResourceApiServiceOperationInformation req = sdncServiceInstanceResources
70                     .changeModelServiceInstance(serviceInstance, gBBInput.getCustomer(), gBBInput.getRequestContext());
71             SDNCRequest sdncRequest = new SDNCRequest();
72             sdncRequest.setSDNCPayload(req);
73             sdncRequest.setTopology(SDNCTopology.SERVICE);
74             execution.setVariable(SDNC_REQUEST, sdncRequest);
75         } catch (Exception ex) {
76             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
77         }
78     }
79
80     public void changeModelVnf(BuildingBlockExecution execution) {
81         try {
82             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
83             GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
84             ServiceInstance serviceInstance =
85                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
86             GenericResourceApiVnfOperationInformation req = sdncVnfResources.changeModelVnf(genericVnf, serviceInstance,
87                     gBBInput.getCustomer(), gBBInput.getCloudRegion(), gBBInput.getRequestContext());
88             SDNCRequest sdncRequest = new SDNCRequest();
89             sdncRequest.setSDNCPayload(req);
90             sdncRequest.setTopology(SDNCTopology.VNF);
91             execution.setVariable(SDNC_REQUEST, sdncRequest);
92         } catch (Exception ex) {
93             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
94         }
95     }
96
97     public void changeAssignNetwork(BuildingBlockExecution execution) {
98         try {
99             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
100             L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
101             ServiceInstance serviceInstance =
102                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
103             GenericResourceApiNetworkOperationInformation req = sdncNetworkResources.changeAssignNetwork(network,
104                     serviceInstance, gBBInput.getCustomer(), gBBInput.getRequestContext(), gBBInput.getCloudRegion());
105             SDNCRequest sdncRequest = new SDNCRequest();
106             sdncRequest.setSDNCPayload(req);
107             sdncRequest.setTopology(SDNCTopology.NETWORK);
108             execution.setVariable(SDNC_REQUEST, sdncRequest);
109         } catch (Exception ex) {
110             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
111         }
112     }
113
114     public void changeAssignModelVfModule(BuildingBlockExecution execution) throws Exception {
115         try {
116             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
117             RequestContext requestContext = gBBInput.getRequestContext();
118             CloudRegion cloudRegion = gBBInput.getCloudRegion();
119             ServiceInstance serviceInstance =
120                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
121             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
122             VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
123             Customer customer = gBBInput.getCustomer();
124             GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.changeAssignVfModule(vfModule,
125                     vnf, serviceInstance, customer, cloudRegion, requestContext);
126             SDNCRequest sdncRequest = new SDNCRequest();
127             sdncRequest.setSDNCPayload(req);
128             sdncRequest.setTopology(SDNCTopology.VFMODULE);
129             execution.setVariable(SDNC_REQUEST, sdncRequest);
130         } catch (Exception ex) {
131             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
132         }
133     }
134 }