2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Modifications Copyright (C) 2018 IBM.
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.ccsdk.sli.core.sli.provider;
26 import java.util.Properties;
28 import org.onap.ccsdk.sli.core.dblib.DbLibService;
29 import org.onap.ccsdk.sli.core.sli.ConfigurationException;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicDblibStore;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
36 import org.onap.ccsdk.sli.core.sli.provider.base.AbstractSvcLogicNodeExecutor;
37 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicPropertiesProvider;
38 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceImplBase;
39 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
40 import org.osgi.framework.BundleContext;
41 import org.osgi.framework.ServiceReference;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
46 public class SvcLogicServiceImpl extends SvcLogicServiceImplBase implements SvcLogicService {
48 private static final Logger LOG = LoggerFactory.getLogger(SvcLogicServiceImpl.class);
49 protected BundleContext bctx = null;
51 public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider) throws SvcLogicException {
53 this.resolver = SvcLogicClassResolver.getInstance();
54 properties = resourceProvider.getProperties();
55 this.store = getStore();
58 public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider, DbLibService dbSvc)
59 throws SvcLogicException {
61 this.resolver = SvcLogicClassResolver.getInstance();
62 properties = resourceProvider.getProperties();
63 this.store = new SvcLogicDblibStore(dbSvc);
66 public void registerExecutor(ServiceReference sr) {
67 String nodeName = (String) sr.getProperty("nodeType");
68 if (nodeName != null) {
69 AbstractSvcLogicNodeExecutor executor;
71 executor = (AbstractSvcLogicNodeExecutor) bctx.getService(sr);
72 } catch (Exception e) {
73 LOG.error("Cannot get service executor for {}", nodeName, e);
76 registerExecutor(nodeName, executor);
80 public void unregisterExecutor(ServiceReference sr) {
81 String nodeName = (String) sr.getProperty("nodeType");
83 if (nodeName != null) {
84 unregisterExecutor(nodeName);
89 public Properties execute(String module, String rpc, String version, String mode, Properties props)
90 throws SvcLogicException {
91 return (execute(module, rpc, version, mode, props, null));
95 public Properties execute(String module, String rpc, String version, String mode, Properties props,
96 DOMDataBroker domDataBroker) throws SvcLogicException {
97 LOG.info("Fetching service logic from data store");
98 SvcLogicGraph graph = store.fetch(module, rpc, version, mode);
101 Properties retProps = new Properties();
102 retProps.setProperty("error-code", "401");
103 retProps.setProperty("error-message",
104 "No service logic found for [" + module + "," + rpc + "," + version + "," + mode + "]");
108 SvcLogicContext ctx = new SvcLogicContext(props);
109 ctx.setAttribute(CURRENT_GRAPH, graph.toString());
110 ctx.setAttribute("X-ECOMP-RequestID", MDC.get("X-ECOMP-RequestID"));
111 ctx.setDomDataBroker(domDataBroker);
113 return (ctx.toProperties());
117 public SvcLogicStore getStore() throws SvcLogicException {
118 // Create and initialize SvcLogicStore object - used to access
119 // saved service logic.
125 store = SvcLogicStoreFactory.getSvcLogicStore(properties);
126 } catch (Exception e) {
127 throw new ConfigurationException("Could not get service logic store", e);
132 store.init(properties);
133 } catch (SvcLogicException e) {
134 throw new ConfigurationException("Could not get service logic store", e);