2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.sdnc.tasks;
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.ServiceInstance;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
29 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
30 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
31 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
32 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
33 import org.onap.so.client.exception.ExceptionBuilder;
34 import org.onap.so.client.orchestration.SDNCServiceInstanceResources;
35 import org.onap.so.client.orchestration.SDNCVfModuleResources;
36 import org.onap.so.client.orchestration.SDNCVnfResources;
37 import org.onap.so.db.catalog.beans.OrchestrationStatus;
38 import org.onap.so.logger.MsoLogger;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Component;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
43 import org.onap.so.client.orchestration.SDNCNetworkResources;
46 public class SDNCUnassignTasks {
47 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, SDNCUnassignTasks.class);
49 private SDNCServiceInstanceResources sdncSIResources;
51 private SDNCVfModuleResources sdncVfModuleResources;
53 private SDNCVnfResources sdncVnfResources;
55 private ExceptionBuilder exceptionUtil;
57 private ExtractPojosForBB extractPojosForBB;
59 private SDNCNetworkResources sdncNetworkResources;
61 public void unassignServiceInstance(BuildingBlockExecution execution) {
63 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
64 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
66 if (serviceInstance.getOrchestrationStatus() == OrchestrationStatus.INVENTORIED) {
67 return; // If INVENTORIED then SDNC unassign is not necessary
70 RequestContext requestContext = gBBInput.getRequestContext();
71 Customer customer = gBBInput.getCustomer();
72 String sdncUnassignResponse = sdncSIResources.unassignServiceInstance(serviceInstance, customer, requestContext);
73 execution.setVariable("sdncUnassignResponse", sdncUnassignResponse);
74 } catch (Exception ex) {
75 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
79 public void unassignVfModule(BuildingBlockExecution execution) {
81 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
82 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
83 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
85 if (OrchestrationStatus.INVENTORIED == vfModule.getOrchestrationStatus() || OrchestrationStatus.PENDING_CREATE == vfModule.getOrchestrationStatus()) {
86 return; // If INVENTORIED or PENDING_CREATE then SDNC unassign is not necessary
89 execution.setVariable("sdncVfModuleRollback", false);
91 String response = sdncVfModuleResources.unassignVfModule(vfModule, vnf, serviceInstance);
92 execution.setVariable("SDNCResponse", response);
93 execution.setVariable("sdncVfModuleRollback", true);
94 } catch (Exception ex) {
95 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
99 public void unassignVnf(BuildingBlockExecution execution) {
101 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
102 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
103 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
105 if (OrchestrationStatus.INVENTORIED == vnf.getOrchestrationStatus() || OrchestrationStatus.CREATED == vnf.getOrchestrationStatus()) {
106 return; // If INVENTORIED or CREATED then SDNC unassign is not necessary
109 RequestContext requestContext = gBBInput.getRequestContext();
110 Customer customer = gBBInput.getCustomer();
111 CloudRegion cloudRegion = gBBInput.getCloudRegion();
112 execution.setVariable("sdncVnfRollback", false);
113 String response = sdncVnfResources.unassignVnf(vnf, serviceInstance, customer, cloudRegion, requestContext);
114 execution.setVariable("sdncUnassignVnfResponse", response);
115 execution.setVariable("sdncVnfRollback", true);
116 } catch (Exception ex) {
117 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
121 public void unassignNetwork(BuildingBlockExecution execution) throws Exception {
122 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
123 L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
125 if (OrchestrationStatus.INVENTORIED == network.getOrchestrationStatus()) {
126 return; // If INVENTORIED then SDNC unassign is not necessary
129 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
130 Customer customer = gBBInput.getCustomer();
131 RequestContext requestContext = gBBInput.getRequestContext();
132 CloudRegion cloudRegion = gBBInput.getCloudRegion();
133 String cloudRegionSdnc = execution.getVariable("cloudRegionSdnc");
134 cloudRegion.setLcpCloudRegionId(cloudRegionSdnc);
136 String response = sdncNetworkResources.unassignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
137 execution.setVariable("SDNCUnAssignNetworkResponse", response);
138 execution.setVariable("isRollbackNeeded", true);
139 } catch (Exception ex) {
140 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);