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