Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / adapter / vnf / tasks / VnfAdapterDeleteTasks.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.adapter.vnf.tasks;
24
25 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
26 import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest;
27 import org.onap.so.bpmn.common.BuildingBlockExecution;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
32 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
33 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
34 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
35 import org.onap.so.client.exception.ExceptionBuilder;
36 import org.onap.so.client.orchestration.VnfAdapterVfModuleResources;
37 import org.onap.so.client.orchestration.VnfAdapterVolumeGroupResources;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.stereotype.Component;
42
43 @Component
44 public class VnfAdapterDeleteTasks {
45     private static final Logger logger = LoggerFactory.getLogger(VnfAdapterDeleteTasks.class);
46     private static final String VNFREST_REQUEST = "VNFREST_Request";
47
48     @Autowired
49     private ExtractPojosForBB extractPojosForBB;
50     @Autowired
51     private VnfAdapterVolumeGroupResources vnfAdapterVolumeGroupResources;
52     @Autowired
53     private VnfAdapterVfModuleResources vnfAdapterVfModuleResources;
54     @Autowired
55     private ExceptionBuilder exceptionUtil;
56
57     public void deleteVolumeGroup(BuildingBlockExecution execution) {
58         try {
59             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
60
61             ServiceInstance serviceInstance =
62                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
63             VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
64
65             DeleteVolumeGroupRequest deleteVolumeGroupRequest = vnfAdapterVolumeGroupResources.deleteVolumeGroupRequest(
66                     gBBInput.getRequestContext(), gBBInput.getCloudRegion(), serviceInstance, volumeGroup);
67             execution.setVariable(VNFREST_REQUEST, deleteVolumeGroupRequest.toXmlString());
68             execution.setVariable("deleteVolumeGroupRequest", "true");
69         } catch (Exception ex) {
70             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
71         }
72     }
73
74     public void deleteVfModule(BuildingBlockExecution execution) {
75         try {
76             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
77
78             ServiceInstance serviceInstance =
79                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
80             VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
81             GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
82
83             DeleteVfModuleRequest deleteVfModuleRequest = vnfAdapterVfModuleResources.deleteVfModuleRequest(
84                     gBBInput.getRequestContext(), gBBInput.getCloudRegion(), serviceInstance, genericVnf, vfModule);
85             execution.setVariable(VNFREST_REQUEST, deleteVfModuleRequest.toXmlString());
86             execution.setVariable("deleteVfModuleRequest", "true");
87         } catch (Exception ex) {
88             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
89         }
90     }
91 }