Containerization feature of SO
[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.so.bpmn.common.BuildingBlockExecution;
24 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
30 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
31 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
32 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
33 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
34 import org.onap.so.client.exception.ExceptionBuilder;
35 import org.onap.so.client.orchestration.SDNCNetworkResources;
36 import org.onap.so.client.orchestration.SDNCServiceInstanceResources;
37 import org.onap.so.client.orchestration.SDNCVfModuleResources;
38 import org.onap.so.client.orchestration.SDNCVnfResources;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Component;
41
42 @Component
43 public class SDNCChangeAssignTasks {
44         @Autowired
45         private SDNCNetworkResources sdncNetworkResources;
46         @Autowired
47         private SDNCServiceInstanceResources sdncServiceInstanceResources;
48         @Autowired
49         private SDNCVnfResources sdncVnfResources;
50         @Autowired
51         private ExtractPojosForBB extractPojosForBB;
52         @Autowired
53         private ExceptionBuilder exceptionUtil;
54         @Autowired
55         private SDNCVfModuleResources sdncVfModuleResources;
56         
57         public void changeModelServiceInstance(BuildingBlockExecution execution) {
58                 try {
59                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
60                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
61                         
62                         String response = sdncServiceInstanceResources.changeModelServiceInstance(serviceInstance, gBBInput.getCustomer(), gBBInput.getRequestContext());
63                         execution.setVariable("SDNCChangeAssignTasks.changeModelServiceInstance.response", response);
64                 } catch(Exception ex) {
65                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
66                 }
67         }
68         
69         public void changeModelVnf(BuildingBlockExecution execution) {
70                 try {
71                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
72                         GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
73                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
74                         
75                         String response = sdncVnfResources.changeModelVnf(genericVnf, serviceInstance, gBBInput.getCustomer(), gBBInput.getCloudRegion(), gBBInput.getRequestContext());
76                         execution.setVariable("SDNCChangeModelVnfResponse", response);
77                 } catch(Exception ex) {
78                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
79                 }
80         }
81         
82         public void changeAssignNetwork(BuildingBlockExecution execution) {
83                 try {
84                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
85                         L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
86                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
87                         
88                         String sdncResponse = sdncNetworkResources.changeAssignNetwork(network, serviceInstance, gBBInput.getCustomer(), gBBInput.getRequestContext(), gBBInput.getCloudRegion());
89                         execution.setVariable("SDNCChangeAssignNetworkResponse", sdncResponse);
90                 } catch(Exception ex) {
91                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
92                 }
93         }
94         
95         public void changeAssignModelVfModule(BuildingBlockExecution execution) throws Exception {
96                 try {
97                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
98                         RequestContext requestContext = gBBInput.getRequestContext();
99                         CloudRegion cloudRegion = gBBInput.getCloudRegion();
100                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
101                         GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
102                         VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
103                         Customer customer = gBBInput.getCustomer();
104                         String response = sdncVfModuleResources.changeAssignVfModule(vfModule, vnf, serviceInstance, customer, cloudRegion, requestContext);
105                         execution.setVariable("SDNCChangeAssignVfModuleResponse", response);
106                 } catch (Exception ex) {
107                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
108                 }
109         }
110 }