2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.bpmn.infrastructure.sdnc.tasks;
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;
53 public class SDNCUnassignTasks {
54 private static final Logger logger = LoggerFactory.getLogger(SDNCUnassignTasks.class);
56 private SDNCServiceInstanceResources sdncSIResources;
58 private SDNCVfModuleResources sdncVfModuleResources;
60 private SDNCVnfResources sdncVnfResources;
62 private ExceptionBuilder exceptionUtil;
64 private ExtractPojosForBB extractPojosForBB;
66 private SDNCNetworkResources sdncNetworkResources;
68 public void unassignServiceInstance(BuildingBlockExecution execution) {
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);
84 public void unassignVfModule(BuildingBlockExecution execution) {
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);
98 public void unassignVnf(BuildingBlockExecution execution) {
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);
116 public void unassignNetwork(BuildingBlockExecution execution) throws Exception {
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);