2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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.ccsdk.sli.plugins.restconfdiscovery;
23 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
24 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
25 import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
26 import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
27 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
28 import org.osgi.framework.Bundle;
29 import org.osgi.framework.BundleContext;
30 import org.osgi.framework.FrameworkUtil;
31 import org.osgi.framework.ServiceReference;
34 * Holder to store callback directed graph info.
36 class SvcLogicGraphInfo {
37 private String module;
40 private String version;
43 * Creates an instance of SvcLogicGraphInfo.
45 * @param module module name of callback DG
46 * @param rpc rpc name of callback DG
47 * @param mode mode of callback DG
48 * @param version version of callback DG
50 public SvcLogicGraphInfo(String module, String rpc, String mode, String version) {
54 this.version = version;
57 public SvcLogicGraphInfo() {}
60 * Returns module name of callback DG.
62 * @return module name of callback DG
64 public String module() {
69 * Sets module of callback DG.
71 * @param module module name of the DG
73 public void module(String module) {
78 * Returns rpc of callback DG.
80 * @return rpc of callback DG
87 * Sets rpc of callback DG.
89 * @param rpc rpc attribute of the DG
91 public void rpc(String rpc) {
96 * Returns mode of callback DG.
98 * @return mode of callback DG
100 public String mode() {
107 * @param mode mode of the DG
109 public void mode(String mode) {
114 * Returns version of callback DG.
116 * @return version of callback DG
118 public String version() {
123 * Sets version of DG.
125 * @param version version of the DG
127 public void version(String version) {
128 this.version = version;
132 * Executes call back DG.
134 * @param ctx service logic context
135 * @throws SvcLogicException service logic error
137 public void executeGraph(SvcLogicContext ctx) throws SvcLogicException {
138 SvcLogicService service = findSvcLogicService();
139 if (service == null) {
140 throw new SvcLogicException("\"Could not get SvcLogicService reference\"");
143 SvcLogicStore store = service.getStore();
145 SvcLogicGraph subGraph = store.fetch(module, rpc, mode, version);
146 if (subGraph != null) {
147 ctx.setAttribute("subGraph", subGraph.toString());
148 service.execute(subGraph, ctx);
150 throw new SvcLogicException("Failed to call child [" + module +
151 "," + rpc + "," + version +
152 "," + mode + "] because" +
153 " the" + " graph could" +
157 throw new SvcLogicException("\"Could not get SvcLogicStore reference\"");
161 private static SvcLogicService findSvcLogicService() throws SvcLogicException {
162 Bundle bundle = FrameworkUtil.getBundle(SvcLogicService.class);
163 if (bundle == null) {
164 throw new SvcLogicException("Cannot find bundle reference for "
165 + SvcLogicService.NAME);
168 BundleContext bctx = bundle.getBundleContext();
169 ServiceReference<SvcLogicService> sref = bctx.getServiceReference(
170 SvcLogicService.class);
172 return bctx.getService(sref);
174 throw new SvcLogicException("Cannot find service reference for "
175 + SvcLogicService.NAME);