2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.sdnc.tasks;
23 import org.onap.so.bpmn.common.BuildingBlockExecution;
24 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
27 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
28 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
29 import org.onap.so.client.exception.BBObjectNotFoundException;
30 import org.onap.so.client.exception.BadResponseException;
31 import org.onap.so.client.exception.ExceptionBuilder;
32 import org.onap.so.client.orchestration.SDNCVnfResources;
33 import org.onap.so.client.orchestration.SDNCVfModuleResources;
34 import org.onap.so.logger.MsoLogger;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Component;
39 public class SDNCQueryTasks {
40 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, SDNCQueryTasks.class);
42 private SDNCVnfResources sdncVnfResources;
44 private SDNCVfModuleResources sdncVfModuleResources;
46 private ExceptionBuilder exceptionUtil;
48 private ExtractPojosForBB extractPojosForBB;
50 public void queryVnf(BuildingBlockExecution execution) throws Exception {
51 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
52 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
54 String selfLink = "restconf/config/GENERIC-RESOURCE-API:services/service/"
55 + serviceInstance.getServiceInstanceId() + "/service-data/vnfs/vnf/"
56 + genericVnf.getVnfId() + "/vnf-data/vnf-topology/";
58 if(genericVnf.getSelflink() == null) {
59 genericVnf.setSelflink(selfLink);
61 String response = sdncVnfResources.queryVnf(genericVnf);
62 execution.setVariable("SDNCQueryResponse_" + genericVnf.getVnfId(), response);
63 } catch (Exception ex) {
64 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
69 public void queryVfModule(BuildingBlockExecution execution) throws Exception {
70 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
71 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
72 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
73 String selfLink = "restconf/config/GENERIC-RESOURCE-API:services/service/"
74 + serviceInstance.getServiceInstanceId() + "/service-data/vnfs/vnf/"
75 + genericVnf.getVnfId() + "/vnf-data/vf-modules/vf-module/"
76 + vfModule.getVfModuleId() + "/vf-module-data/vf-module-topology/";
78 if(vfModule.getSelflink() == null || (vfModule.getSelflink() != null && vfModule.getSelflink().isEmpty())) {
79 vfModule.setSelflink(selfLink);
81 if(vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) {
82 String response = sdncVfModuleResources.queryVfModule(vfModule);
83 execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), response);
86 throw new Exception("Vf Module " + vfModule.getVfModuleId() + " exists in gBuildingBlock but does not have a selflink value");
88 } catch (Exception ex) {
89 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
93 public void queryVfModuleForVolumeGroup(BuildingBlockExecution execution) {
95 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
96 if(vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) {
97 String response = sdncVfModuleResources.queryVfModule(vfModule);
98 execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), response);
101 throw new Exception("Vf Module " + vfModule.getVfModuleId() + " exists in gBuildingBlock but does not have a selflink value");
103 } catch(BBObjectNotFoundException bbException) {
104 // If there is not a vf module in the general building block, we will not call SDNC and proceed as normal without throwing an error
105 // If we see a bb object not found exception for something that is not a vf module id, then we should throw the error as normal
106 if(!ResourceKey.VF_MODULE_ID.equals(bbException.getResourceKey())) {
107 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, bbException);
109 } catch(Exception ex) {
110 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);