2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.bpmn.infrastructure.sdnc.tasks;
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;
41 public class SDNCQueryTasks {
42 private static final Logger logger = LoggerFactory.getLogger(SDNCQueryTasks.class);
44 private SDNCVnfResources sdncVnfResources;
46 private SDNCVfModuleResources sdncVfModuleResources;
48 private ExceptionBuilder exceptionUtil;
50 private ExtractPojosForBB extractPojosForBB;
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);
57 "restconf/config/GENERIC-RESOURCE-API:services/service/" + serviceInstance.getServiceInstanceId()
58 + "/service-data/vnfs/vnf/" + genericVnf.getVnfId() + "/vnf-data/vnf-topology/";
60 if (genericVnf.getSelflink() == null) {
61 genericVnf.setSelflink(selfLink);
63 String response = sdncVnfResources.queryVnf(genericVnf);
64 execution.setVariable("SDNCQueryResponse_" + genericVnf.getVnfId(), response);
65 } catch (Exception ex) {
66 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
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/";
79 if (vfModule.getSelflink() == null
80 || (vfModule.getSelflink() != null && vfModule.getSelflink().isEmpty())) {
81 vfModule.setSelflink(selfLink);
83 if (vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) {
84 String response = sdncVfModuleResources.queryVfModule(vfModule);
85 execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), response);
87 throw new Exception("Vf Module " + vfModule.getVfModuleId()
88 + " exists in gBuildingBlock but does not have a selflink value");
90 } catch (Exception ex) {
91 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
95 public void queryVfModuleForVolumeGroup(BuildingBlockExecution execution) {
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);
102 throw new Exception("Vf Module " + vfModule.getVfModuleId()
103 + " exists in gBuildingBlock but does not have a selflink value");
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);
113 } catch (Exception ex) {
114 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);