SvcLogicServiceImplBase constructor should have SvcLogicResolver as a parameter,Added HashMapResolver to map svclogic instances without osgi,Added InMemorySvcLogicStore useful for simple demos or junit test
Issue-ID: CCSDK-1891
Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Change-Id: I3c3cdd33177ef10133db2672ddd4b308becefc90
<artifactId>utils-installer</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>sli-recording</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</dependencyManagement>
--- /dev/null
+package org.onap.ccsdk.sli.core.sli.provider.base;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource;\r
+\r
+public class HashMapResolver implements SvcLogicResolver {\r
+ Map<String, SvcLogicResource> svcLogicResourceMap = new HashMap<String, SvcLogicResource>();\r
+ Map<String, SvcLogicJavaPlugin> svcLogicJavaPluginMap = new HashMap<String, SvcLogicJavaPlugin>();\r
+ Map<String, SvcLogicAdaptor> adaptorMap = new HashMap<String, SvcLogicAdaptor>();\r
+ Map<String, SvcLogicRecorder> recorderMap = new HashMap<String, SvcLogicRecorder>();\r
+\r
+ @Override\r
+ public SvcLogicResource getSvcLogicResource(String resourceName) {\r
+ return svcLogicResourceMap.get(resourceName);\r
+ }\r
+\r
+ @Override\r
+ public SvcLogicRecorder getSvcLogicRecorder(String recorderName) {\r
+ return recorderMap.get(recorderName);\r
+ }\r
+\r
+ @Override\r
+ public SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName) {\r
+ return svcLogicJavaPluginMap.get(pluginName);\r
+ }\r
+\r
+ @Override\r
+ public SvcLogicAdaptor getSvcLogicAdaptor(String adaptorName) {\r
+ return adaptorMap.get(adaptorName);\r
+ }\r
+\r
+ public void addSvcLogicAdaptor(String adaptorName, SvcLogicAdaptor adaptor) {\r
+ adaptorMap.put(adaptorName, adaptor);\r
+ }\r
+\r
+ public void addSvcLogicRecorder(String recorderName, SvcLogicRecorder recorder) {\r
+ recorderMap.put(recorderName, recorder);\r
+ }\r
+\r
+ public void addSvcLogicSvcLogicJavaPlugin(String pluginName, SvcLogicJavaPlugin plugin) {\r
+ svcLogicJavaPluginMap.put(pluginName, plugin);\r
+ }\r
+\r
+ public void addSvcLogicResource(String resourceName, SvcLogicResource resource) {\r
+ svcLogicResourceMap.put(resourceName, resource);\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.onap.ccsdk.sli.core.sli.provider.base;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
+import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class InMemorySvcLogicStore implements SvcLogicStore {
+ private static final Logger logger = LoggerFactory.getLogger(InMemorySvcLogicStore.class);
+ public Map<String, SvcLogicGraph> graphStore;
+
+ public InMemorySvcLogicStore() {
+ graphStore = new HashMap<String, SvcLogicGraph>();
+ }
+
+ @Override
+ public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
+ String storeId = new String(module + ":" + rpc);
+ return graphStore.containsKey(storeId);
+ }
+
+ @Override
+ public SvcLogicGraph fetch(String module, String rpc, String version, String mode) throws SvcLogicException {
+ String storeId = new String(module + ":" + rpc);
+ return graphStore.get(storeId);
+ }
+
+ @Override
+ public void store(SvcLogicGraph graph) throws SvcLogicException {
+ if (graph != null) {
+ String storeId = new String(graph.getModule() + ":" + graph.getRpc());
+ graphStore.put(storeId, graph);
+ logger.info(graph.toString() + " stored in InMemorySvcLogicStore.");
+ }
+ }
+
+ @Override
+ public void init(Properties props) throws SvcLogicException {
+ // noop
+ }
+
+ @Override
+ public void delete(String module, String rpc, String version, String mode) throws SvcLogicException {
+ String storeId = new String(module + ":" + rpc);
+ if (graphStore.containsKey(storeId)) {
+ graphStore.remove(storeId);
+ }
+ }
+
+ @Override
+ public void activate(SvcLogicGraph graph) throws SvcLogicException {
+ // noop
+ }
+
+ @Override
+ public void activate(String module, String rpc, String version, String mode) throws SvcLogicException {
+ // noop
+ }
+
+}
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
-
import org.onap.ccsdk.sli.core.sli.ExitNodeException;
-import org.onap.ccsdk.sli.core.sli.MetricLogger;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
protected SvcLogicStore store;
protected static final String CURRENT_GRAPH="currentGraph";
- public SvcLogicServiceImplBase(SvcLogicStore store) {
+ public SvcLogicServiceImplBase(SvcLogicStore store, SvcLogicResolver resolver) {
this.store = store;
+ this.resolver = resolver;
}
protected void registerExecutors() {
}
@Override
- public Properties execute(String module, String rpc, String version, String mode, Properties props)
- throws SvcLogicException {
- LOG.info("Fetching service logic from data store");
- SvcLogicGraph graph = store.fetch(module, rpc, version, mode);
-
- if (graph == null) {
- Properties retProps = new Properties();
- retProps.setProperty("error-code", "401");
- retProps.setProperty("error-message",
- "No service logic found for [" + module + "," + rpc + "," + version + "," + mode + "]");
- return (retProps);
- }
+ public Properties execute(String module, String rpc, String version, String mode, Properties props)
+ throws SvcLogicException {
+ SvcLogicGraph graph = store.fetch(module, rpc, version, mode);
+
+ if (graph == null) {
+ Properties retProps = new Properties();
+ retProps.setProperty("error-code", "401");
+ retProps.setProperty("error-message",
+ "No service logic found for [" + module + "," + rpc + "," + version + "," + mode + "]");
+ return (retProps);
+ }
- SvcLogicContext ctx = new SvcLogicContext(props);
- ctx.setAttribute(CURRENT_GRAPH, graph.toString());
- ctx.setAttribute("X-ECOMP-RequestID", MDC.get("X-ECOMP-RequestID"));
- execute(graph, ctx);
- return (ctx.toProperties());
- }
+ SvcLogicContext ctx = new SvcLogicContext(props);
+ ctx.setAttribute(CURRENT_GRAPH, graph.toString());
+ // To support legacy code we should not stop populating X-ECOMP-RequestID
+ ctx.setAttribute("X-ECOMP-RequestID", MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
+ execute(graph, ctx);
+ return (ctx.toProperties());
+ }
@Override
public SvcLogicStore getStore() throws SvcLogicException {
package org.onap.ccsdk.sli.core.sli.provider.base;
-import java.util.Map.Entry;
import java.util.Properties;
-
import org.onap.ccsdk.sli.core.sli.DuplicateValueException;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
-import org.onap.ccsdk.sli.core.sli.provider.base.ExecuteNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicPropertiesProvider;
-import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceImplBase;
-
import junit.framework.TestCase;
public class ExecuteNodeExecutorTest extends TestCase {
};
- execute.execute(new SvcLogicServiceImplBase(null), new SvcLogicNode(0, "", "", new SvcLogicGraph()), new SvcLogicContext());
+ execute.execute(new SvcLogicServiceImplBase(null, null), new SvcLogicNode(0, "", "", new SvcLogicGraph()),
+ new SvcLogicContext());
}
}
--- /dev/null
+package org.onap.ccsdk.sli.core.sli.provider.base;\r
+\r
+import static org.junit.Assert.assertNotNull;\r
+import org.junit.Rule;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+import org.mockito.junit.MockitoJUnit;\r
+import org.mockito.junit.MockitoRule;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource;\r
+\r
+public class HashMapResolverTest {\r
+ @Mock\r
+ SvcLogicResource myResource;\r
+\r
+ @Mock\r
+ SvcLogicRecorder myRecorder;\r
+\r
+ @Mock\r
+ SvcLogicJavaPlugin myJavaPlugin;\r
+\r
+ @Mock\r
+ SvcLogicAdaptor myAdaptor;\r
+\r
+ @Rule\r
+ public MockitoRule mockitoRule = MockitoJUnit.rule();\r
+\r
+ @Test\r
+ public void simpleTest() throws Exception {\r
+\r
+ HashMapResolver resolver = new HashMapResolver();\r
+ String resourceKey = "simple.resource";\r
+ String recorderKey = "simple.record";\r
+ String pluginKey = "simple.plugin";\r
+ String adaptorKey = "simple.adaptor";\r
+\r
+ resolver.addSvcLogicAdaptor(adaptorKey, myAdaptor);\r
+ resolver.addSvcLogicRecorder(recorderKey, myRecorder);\r
+ resolver.addSvcLogicResource(resourceKey, myResource);\r
+ resolver.addSvcLogicSvcLogicJavaPlugin(pluginKey, myJavaPlugin);\r
+\r
+ assertNotNull(resolver.getSvcLogicAdaptor(adaptorKey));\r
+ assertNotNull(resolver.getSvcLogicJavaPlugin(pluginKey));\r
+ assertNotNull(resolver.getSvcLogicRecorder(recorderKey));\r
+ assertNotNull(resolver.getSvcLogicResource(resourceKey));\r
+\r
+\r
+ }\r
+}\r
--- /dev/null
+package org.onap.ccsdk.sli.core.sli.provider.base;\r
+\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.assertNull;\r
+import static org.junit.Assert.assertTrue;\r
+import java.util.Properties;\r
+import org.junit.Test;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;\r
+\r
+public class InMemorySvcLogicStoreTest {\r
+ @Test\r
+ public void simpleTest() throws Exception {\r
+ InMemorySvcLogicStore store = new InMemorySvcLogicStore();\r
+ store.init(new Properties());\r
+ SvcLogicGraph graph = new SvcLogicGraph();\r
+ String module = "TEST";\r
+ String rpc = "NOTIFICATION";\r
+ String mode = "sync";\r
+ String version = "1";\r
+\r
+ graph.setModule(module);\r
+ graph.setRpc(rpc);\r
+ graph.setMode(mode);\r
+ graph.setVersion(version);\r
+\r
+ store.store(graph);\r
+ assertTrue(store.hasGraph(module, rpc, version, mode));\r
+ assertNotNull(store.fetch(module, rpc, version, mode));\r
+ store.activate(graph);\r
+ store.activate(module, rpc, version, mode);\r
+\r
+ store.delete(module, rpc, version, mode);\r
+ assertNull(store.fetch(module, rpc, version, mode));\r
+ }\r
+}\r
import java.util.Properties;
import org.onap.ccsdk.sli.core.dblib.DbLibService;
import org.onap.ccsdk.sli.core.sli.ConfigurationException;
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicDblibStore;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicPropertiesProvider;
import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicResolver;
import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceImplBase;
-import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
public class SvcLogicServiceImpl extends SvcLogicServiceImplBase implements SvcLogicService {
public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider, SvcLogicResolver resolver)
throws SvcLogicException {
- super(null);
- this.resolver = resolver;
+ super(null, resolver);
properties = resourceProvider.getProperties();
this.store = getStore();
}
public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider, DbLibService dbSvc,
SvcLogicResolver resolver) throws SvcLogicException {
- super(null);
- this.resolver = resolver;
+ super(null, resolver);
properties = resourceProvider.getProperties();
this.store = new SvcLogicDblibStore(dbSvc);
}
- @Override
- public Properties execute(String module, String rpc, String version, String mode, Properties props)
- throws SvcLogicException {
- SvcLogicGraph graph = store.fetch(module, rpc, version, mode);
-
- if (graph == null) {
- Properties retProps = new Properties();
- retProps.setProperty("error-code", "401");
- retProps.setProperty("error-message",
- "No service logic found for [" + module + "," + rpc + "," + version + "," + mode + "]");
- return (retProps);
- }
-
- SvcLogicContext ctx = new SvcLogicContext(props);
- ctx.setAttribute(CURRENT_GRAPH, graph.toString());
- // To support legacy code we should not stop populating X-ECOMP-RequestID
- ctx.setAttribute("X-ECOMP-RequestID", MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
- execute(graph, ctx);
- return (ctx.toProperties());
- }
-
@Override
@Deprecated
// DomDataBroker is not being used, this should be removed eventually