[SO] Release so 1.13.0 image
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / namingservice / tasks / NamingServiceDeleteTasks.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) 2020 Nokia
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.namingservice.tasks;
24
25
26 import org.onap.so.bpmn.common.BuildingBlockExecution;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
29 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
30 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
31 import org.onap.so.client.exception.BBObjectNotFoundException;
32 import org.onap.so.client.exception.ExceptionBuilder;
33 import org.onap.so.client.namingservice.NamingRequestObject;
34 import org.onap.so.client.orchestration.NamingServiceResources;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Component;
37
38 @Component
39 public class NamingServiceDeleteTasks {
40
41     @Autowired
42     private ExceptionBuilder exceptionUtil;
43     @Autowired
44     private ExtractPojosForBB extractPojosForBB;
45
46     @Autowired
47     private NamingServiceResources namingServiceResources;
48
49     public void deleteInstanceGroupName(BuildingBlockExecution execution) throws BBObjectNotFoundException {
50         InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
51
52         try {
53             namingServiceResources.deleteInstanceGroupName(instanceGroup);
54         } catch (Exception ex) {
55             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
56         }
57     }
58
59     public void deleteServiceInstanceName(BuildingBlockExecution execution) throws BBObjectNotFoundException {
60         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
61         NamingRequestObject namingRequestObject = new NamingRequestObject();
62         namingRequestObject.setExternalKeyValue(serviceInstance.getServiceInstanceId());
63         try {
64             namingServiceResources.deleteServiceInstanceName(namingRequestObject);
65         } catch (Exception ex) {
66             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
67         }
68     }
69
70 }