Containerization feature of SO
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / sdnc / tasks / SDNCAssignTasks.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.bbobjects.VolumeGroup;
31 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
32 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
33 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
34 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
35 import org.onap.so.client.exception.BBObjectNotFoundException;
36 import org.onap.so.client.exception.ExceptionBuilder;
37 import org.onap.so.client.orchestration.SDNCNetworkResources;
38 import org.onap.so.client.orchestration.SDNCServiceInstanceResources;
39 import org.onap.so.client.orchestration.SDNCVfModuleResources;
40 import org.onap.so.client.orchestration.SDNCVnfResources;
41 import org.onap.so.logger.MsoLogger;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.stereotype.Component;
44
45 @Component
46 public class SDNCAssignTasks {
47         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, SDNCAssignTasks.class);
48         @Autowired
49         private SDNCServiceInstanceResources sdncSIResources;
50         @Autowired
51         private SDNCVnfResources sdncVnfResources;
52         @Autowired
53         private SDNCVfModuleResources sdncVfModuleResources;
54         @Autowired
55         private ExceptionBuilder exceptionUtil;
56         @Autowired
57         private ExtractPojosForBB extractPojosForBB;
58         @Autowired
59         private SDNCNetworkResources sdncNetworkResources;
60
61         public void assignServiceInstance(BuildingBlockExecution execution) {
62                 try {
63                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
64                         RequestContext requestContext = gBBInput.getRequestContext();
65                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
66                         Customer customer = gBBInput.getCustomer();
67                         String response = sdncSIResources.assignServiceInstance(serviceInstance, customer, requestContext);
68                         execution.setVariable("SDNCResponse", response);
69                 } catch (Exception ex) {
70                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
71                 }
72         }
73
74         public void assignVnf(BuildingBlockExecution execution) {
75                 try {
76                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
77                         RequestContext requestContext = gBBInput.getRequestContext();
78                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
79                         GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
80                         Customer customer = gBBInput.getCustomer();
81                         CloudRegion cloudRegion = gBBInput.getCloudRegion();
82                         String response = sdncVnfResources.assignVnf(vnf, serviceInstance, customer, cloudRegion, requestContext, vnf.isCallHoming());
83                         execution.setVariable("SDNCResponse", response);
84                 } catch (Exception ex) {
85                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
86                 }
87         }
88         
89         public void assignVfModule(BuildingBlockExecution execution) {
90                 try {
91                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
92                         RequestContext requestContext = gBBInput.getRequestContext();
93                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
94                         GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
95                         VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
96                         VolumeGroup volumeGroup = null;
97                         try{
98                                 volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
99                         } catch (BBObjectNotFoundException e){
100                                 msoLogger.info("No volume group was found.");
101                         }
102                         Customer customer = gBBInput.getCustomer();
103                         CloudRegion cloudRegion = gBBInput.getCloudRegion();
104                 
105                         String response = sdncVfModuleResources.assignVfModule(vfModule, volumeGroup, vnf, serviceInstance, customer, cloudRegion, requestContext);             
106                         execution.setVariable("SDNCAssignResponse_"+ vfModule.getVfModuleId(), response);
107                 } catch (Exception ex) {                        
108                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
109                 }
110         }
111         
112         /**
113          * BPMN access method to perform Assign action on SDNC for L3Network
114          * @param execution
115          * @throws Exception
116          */
117         public void assignNetwork(BuildingBlockExecution execution) {
118                 try {
119                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
120                         
121                         L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
122                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
123         
124                         Customer customer = gBBInput.getCustomer();
125                         RequestContext requestContext = gBBInput.getRequestContext();
126                         CloudRegion cloudRegion = gBBInput.getCloudRegion();
127                 
128                         sdncNetworkResources.assignNetwork(l3network, serviceInstance, customer, requestContext, cloudRegion);
129                 } catch (Exception ex) {
130                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
131                 }
132         }
133 }