SliProviderBaseUpdates 59/97859/7
authorSmokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Fri, 1 Nov 2019 14:38:49 +0000 (14:38 +0000)
committerKevin Smokowski <kevin.smokowski@att.com>
Fri, 1 Nov 2019 17:14:39 +0000 (17:14 +0000)
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

artifacts/pom.xml
sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/HashMapResolver.java [new file with mode: 0644]
sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/InMemorySvcLogicStore.java [new file with mode: 0644]
sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceImplBase.java
sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutorTest.java
sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/HashMapResolverTest.java [new file with mode: 0644]
sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/InMemorySvcLogicStoreTest.java [new file with mode: 0644]
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java

index 1f0781b..32d1ef7 100755 (executable)
                                <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>
 
diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/HashMapResolver.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/HashMapResolver.java
new file mode 100644 (file)
index 0000000..d333127
--- /dev/null
@@ -0,0 +1,52 @@
+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
diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/InMemorySvcLogicStore.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/InMemorySvcLogicStore.java
new file mode 100644 (file)
index 0000000..ddf464f
--- /dev/null
@@ -0,0 +1,66 @@
+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
+    }
+
+}
index 361ca70..80d992f 100644 (file)
@@ -26,14 +26,13 @@ package org.onap.ccsdk.sli.core.sli.provider.base;
 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;
@@ -72,8 +71,9 @@ public class SvcLogicServiceImplBase implements SvcLogicServiceBase {
     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() {
@@ -140,25 +140,25 @@ public class SvcLogicServiceImplBase implements SvcLogicServiceBase {
     }
 
     @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 {
index 474136d..9a92938 100644 (file)
@@ -21,9 +21,7 @@
 
 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;
@@ -31,10 +29,6 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
 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 {
@@ -63,7 +57,8 @@ 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());
     }
 
 }
diff --git a/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/HashMapResolverTest.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/HashMapResolverTest.java
new file mode 100644 (file)
index 0000000..5a21406
--- /dev/null
@@ -0,0 +1,51 @@
+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
diff --git a/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/InMemorySvcLogicStoreTest.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/InMemorySvcLogicStoreTest.java
new file mode 100644 (file)
index 0000000..5f8757a
--- /dev/null
@@ -0,0 +1,35 @@
+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
index 49d0a38..92c2aa4 100755 (executable)
@@ -26,20 +26,16 @@ package org.onap.ccsdk.sli.core.sli.provider;
 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 {
 
@@ -47,41 +43,18 @@ public class SvcLogicServiceImpl extends SvcLogicServiceImplBase implements SvcL
 
     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