Containerization feature of SO
[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  * 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.adapter.vnf.tasks;
22
23 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
24 import org.onap.so.bpmn.common.BuildingBlockExecution;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
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.tasks.ExtractPojosForBB;
32 import org.onap.so.client.exception.ExceptionBuilder;
33 import org.onap.so.client.orchestration.VnfAdapterVfModuleResources;
34 import org.onap.so.client.orchestration.VnfAdapterVolumeGroupResources;
35 import org.onap.so.logger.MsoLogger;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Component;
38
39 @Component
40 public class VnfAdapterDeleteTasks {
41         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, VnfAdapterDeleteTasks.class);
42         private static final String VNFREST_REQUEST = "VNFREST_Request";
43         
44         @Autowired
45         private ExtractPojosForBB extractPojosForBB;
46         @Autowired
47         private VnfAdapterVolumeGroupResources vnfAdapterVolumeGroupResources;
48         @Autowired
49         private VnfAdapterVfModuleResources vnfAdapterVfModuleResources;
50         @Autowired
51         private ExceptionBuilder exceptionUtil;
52         
53         public void deleteVolumeGroup(BuildingBlockExecution execution) {
54                 try {
55                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
56                         
57                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
58                         VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
59                         
60                         vnfAdapterVolumeGroupResources.deleteVolumeGroup(gBBInput.getRequestContext(), gBBInput.getCloudRegion(), serviceInstance, volumeGroup);
61                 } catch (Exception ex) {
62                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
63                 }
64         }
65
66         public void deleteVfModule(BuildingBlockExecution execution) {
67                 try {
68                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
69                         
70                         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
71                         VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
72                         GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
73                         
74                         DeleteVfModuleRequest deleteVfModuleRequest = vnfAdapterVfModuleResources.deleteVfModuleRequest( gBBInput.getRequestContext(), gBBInput.getCloudRegion(), serviceInstance, genericVnf, vfModule);
75                         execution.setVariable(VNFREST_REQUEST, deleteVfModuleRequest.toXmlString());
76                         execution.setVariable("deleteVfModuleRequest", "true");
77                 } catch (Exception ex) {
78                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
79                 }
80         }
81 }