a96e2702cd00b4d5e549184869fde039a5f16c9c
[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 = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
62                         VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
63                         
64                         DeleteVolumeGroupRequest deleteVolumeGroupRequest = vnfAdapterVolumeGroupResources.deleteVolumeGroupRequest(gBBInput.getRequestContext(), gBBInput.getCloudRegion(), serviceInstance, volumeGroup);
65                         execution.setVariable(VNFREST_REQUEST, deleteVolumeGroupRequest.toXmlString());
66                         execution.setVariable("deleteVolumeGroupRequest", "true");
67                 } catch (Exception ex) {
68                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
69                 }
70         }
71
72         public void deleteVfModule(BuildingBlockExecution execution) {
73                 try {
74                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
75                         
76                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
77                         VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
78                         GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
79                         
80                         DeleteVfModuleRequest deleteVfModuleRequest = vnfAdapterVfModuleResources.deleteVfModuleRequest( gBBInput.getRequestContext(), gBBInput.getCloudRegion(), serviceInstance, genericVnf, vfModule);
81                         execution.setVariable(VNFREST_REQUEST, deleteVfModuleRequest.toXmlString());
82                         execution.setVariable("deleteVfModuleRequest", "true");
83                 } catch (Exception ex) {
84                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
85                 }
86         }
87 }