Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / sdnc / tasks / SDNCQueryTasks.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.sdnc.tasks;
24
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.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.orchestration.SDNCVnfResources;
34 import org.onap.so.client.orchestration.SDNCVfModuleResources;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.stereotype.Component;
39
40 @Component
41 public class SDNCQueryTasks {
42     private static final Logger logger = LoggerFactory.getLogger(SDNCQueryTasks.class);
43     @Autowired
44     private SDNCVnfResources sdncVnfResources;
45     @Autowired
46     private SDNCVfModuleResources sdncVfModuleResources;
47     @Autowired
48     private ExceptionBuilder exceptionUtil;
49     @Autowired
50     private ExtractPojosForBB extractPojosForBB;
51
52     public void queryVnf(BuildingBlockExecution execution) throws Exception {
53         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
54         GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
55
56         String selfLink =
57                 "restconf/config/GENERIC-RESOURCE-API:services/service/" + serviceInstance.getServiceInstanceId()
58                         + "/service-data/vnfs/vnf/" + genericVnf.getVnfId() + "/vnf-data/vnf-topology/";
59         try {
60             if (genericVnf.getSelflink() == null) {
61                 genericVnf.setSelflink(selfLink);
62             }
63             String response = sdncVnfResources.queryVnf(genericVnf);
64             execution.setVariable("SDNCQueryResponse_" + genericVnf.getVnfId(), response);
65         } catch (Exception ex) {
66             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
67         }
68     }
69
70
71     public void queryVfModule(BuildingBlockExecution execution) throws Exception {
72         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
73         GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
74         VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
75         String selfLink = "restconf/config/GENERIC-RESOURCE-API:services/service/"
76                 + serviceInstance.getServiceInstanceId() + "/service-data/vnfs/vnf/" + genericVnf.getVnfId()
77                 + "/vnf-data/vf-modules/vf-module/" + vfModule.getVfModuleId() + "/vf-module-data/vf-module-topology/";
78         try {
79             if (vfModule.getSelflink() == null
80                     || (vfModule.getSelflink() != null && vfModule.getSelflink().isEmpty())) {
81                 vfModule.setSelflink(selfLink);
82             }
83             if (vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) {
84                 String response = sdncVfModuleResources.queryVfModule(vfModule);
85                 execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), response);
86             } else {
87                 throw new Exception("Vf Module " + vfModule.getVfModuleId()
88                         + " exists in gBuildingBlock but does not have a selflink value");
89             }
90         } catch (Exception ex) {
91             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
92         }
93     }
94
95     public void queryVfModuleForVolumeGroup(BuildingBlockExecution execution) {
96         try {
97             VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
98             if (vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) {
99                 String response = sdncVfModuleResources.queryVfModule(vfModule);
100                 execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), response);
101             } else {
102                 throw new Exception("Vf Module " + vfModule.getVfModuleId()
103                         + " exists in gBuildingBlock but does not have a selflink value");
104             }
105         } catch (BBObjectNotFoundException bbException) {
106             // If there is not a vf module in the general building block, we will not call SDNC and proceed as normal
107             // without throwing an error
108             // If we see a bb object not found exception for something that is not a vf module id, then we should throw
109             // the error as normal
110             if (!ResourceKey.VF_MODULE_ID.equals(bbException.getResourceKey())) {
111                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, bbException);
112             }
113         } catch (Exception ex) {
114             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
115         }
116     }
117 }