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