Merge "change all sdnc calls"
[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  * 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.onap.so.logger.MsoLogger;
46 import org.springframework.beans.factory.annotation.Autowired;
47 import org.springframework.stereotype.Component;
48
49 @Component
50 public class SDNCUnassignTasks {
51         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, SDNCUnassignTasks.class);
52         @Autowired
53         private SDNCServiceInstanceResources sdncSIResources;
54         @Autowired
55         private SDNCVfModuleResources sdncVfModuleResources;
56         @Autowired
57         private SDNCVnfResources sdncVnfResources;
58         @Autowired
59         private ExceptionBuilder exceptionUtil;
60         @Autowired
61         private ExtractPojosForBB extractPojosForBB;
62         @Autowired
63         private SDNCNetworkResources sdncNetworkResources;
64
65         public void unassignServiceInstance(BuildingBlockExecution execution) {
66                 try {
67                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
68                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); 
69                         RequestContext requestContext = gBBInput.getRequestContext();
70                         Customer customer = gBBInput.getCustomer();
71                         GenericResourceApiServiceOperationInformation req = sdncSIResources.unassignServiceInstance(serviceInstance, customer, requestContext);
72                         SDNCRequest sdncRequest = new SDNCRequest();
73                         sdncRequest.setSDNCPayload(req);
74                         sdncRequest.setTopology(SDNCTopology.SERVICE);
75                         execution.setVariable("SDNCRequest", sdncRequest);
76                 } catch (Exception ex) {
77                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
78                 }
79         }
80         
81         public void unassignVfModule(BuildingBlockExecution execution) {                
82                 try {
83                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); 
84                         GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); 
85                         VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
86                         GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.unassignVfModule(vfModule, vnf, serviceInstance);            
87                         SDNCRequest sdncRequest = new SDNCRequest();
88                         sdncRequest.setSDNCPayload(req);
89                         sdncRequest.setTopology(SDNCTopology.VFMODULE);
90                         execution.setVariable("SDNCRequest", sdncRequest);              } catch (Exception ex) {                        
91                     exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
92                 }
93         }
94         
95         public void unassignVnf(BuildingBlockExecution execution)  {
96                 try {
97                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
98                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
99                         GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
100                         RequestContext requestContext = gBBInput.getRequestContext();
101                         Customer customer = gBBInput.getCustomer();
102                         CloudRegion cloudRegion = gBBInput.getCloudRegion();
103                         GenericResourceApiVnfOperationInformation req = sdncVnfResources.unassignVnf(vnf, serviceInstance, customer, cloudRegion, requestContext);
104                         SDNCRequest sdncRequest = new SDNCRequest();
105                         sdncRequest.setSDNCPayload(req);
106                         sdncRequest.setTopology(SDNCTopology.VNF);
107                         execution.setVariable("SDNCRequest", sdncRequest);
108                 } catch (Exception ex) {
109                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
110                 }
111         }
112
113         public void unassignNetwork(BuildingBlockExecution execution) throws Exception {
114                 try {
115                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
116                         L3Network network =  extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
117                         ServiceInstance serviceInstance =  extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
118                         Customer customer = gBBInput.getCustomer();
119                         RequestContext requestContext = gBBInput.getRequestContext();           
120                         CloudRegion cloudRegion = gBBInput.getCloudRegion();
121                         String cloudRegionSdnc = execution.getVariable("cloudRegionSdnc");
122                         cloudRegion.setLcpCloudRegionId(cloudRegionSdnc);
123                         GenericResourceApiNetworkOperationInformation req = sdncNetworkResources.unassignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
124                         SDNCRequest sdncRequest = new SDNCRequest();
125                         sdncRequest.setSDNCPayload(req);
126                         sdncRequest.setTopology(SDNCTopology.NETWORK);
127                         execution.setVariable("SDNCRequest", sdncRequest);
128                 } catch (Exception ex) {
129                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
130                 }
131         }
132 }