diff options
9 files changed, 376 insertions, 359 deletions
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java index e7a94e64c..61fb000fb 100755 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java @@ -71,29 +71,29 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb protected final AtomicBoolean dsSelector = new AtomicBoolean(); // Queue<CachedDataSource> dsQueue = new ConcurrentLinkedQueue<CachedDataSource>(); - Queue<CachedDataSource> dsQueue = new PriorityQueue<CachedDataSource>(4, new Comparator<CachedDataSource>() { - @Override - public int compare(CachedDataSource left, CachedDataSource right) { - try { - if(left == null){ - return 1; - } - if(right == null){ - return -1; - } + Queue<CachedDataSource> dsQueue = new PriorityQueue<>(4, new Comparator<CachedDataSource>() { + @Override + public int compare(CachedDataSource left, CachedDataSource right) { + try { + if (left == null) { + return 1; + } + if (right == null) { + return -1; + } - if(!left.isSlave()) { - return -1; - } - if (!right.isSlave()) { - return 1; - } - } catch (Throwable e) { - LOGGER.warn("", e); + if (!left.isSlave()) { + return -1; + } + if (!right.isSlave()) { + return 1; } - return 0; + } catch (Throwable e) { + LOGGER.warn("", e); } - }); + return 0; + } +}); protected final Set<CachedDataSource> broken = Collections.synchronizedSet(new HashSet<CachedDataSource>()); protected final Object monitor = new Object(); protected final Properties configProps; @@ -313,7 +313,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb public void testForceRecovery() { - CachedDataSource active = (CachedDataSource) this.dsQueue.peek(); + CachedDataSource active = this.dsQueue.peek(); handleGetConnectionException(active, new Exception("test")); } @@ -461,7 +461,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb LOGGER.error("Generated alarm: DBResourceManager.getData - No active DB connection pools are available."); throw new DBLibException("No active DB connection pools are available in RequestDataNoRecovery call."); } - CachedDataSource active = (CachedDataSource) this.dsQueue.peek(); + CachedDataSource active = this.dsQueue.peek(); long time = System.currentTimeMillis(); try { if(!active.isFabric()) { @@ -533,7 +533,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb boolean initialRequest = true; boolean retryAllowed = true; - CachedDataSource active = (CachedDataSource) this.dsQueue.peek(); + CachedDataSource active = this.dsQueue.peek(); long time = System.currentTimeMillis(); while(initialRequest) { initialRequest = false; @@ -724,7 +724,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb public void cleanUp() { for(Iterator<CachedDataSource> it=dsQueue.iterator();it.hasNext();){ - CachedDataSource cds = (CachedDataSource)it.next(); + CachedDataSource cds = it.next(); it.remove(); cds.cleanUp(); } @@ -748,28 +748,28 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb @Override public PrintWriter getLogWriter() throws SQLException { - return ((CachedDataSource)this.dsQueue.peek()).getLogWriter(); + return this.dsQueue.peek().getLogWriter(); } @Override public int getLoginTimeout() throws SQLException { - return ((CachedDataSource)this.dsQueue.peek()).getLoginTimeout(); + return this.dsQueue.peek().getLoginTimeout(); } @Override public void setLogWriter(PrintWriter out) throws SQLException { - ((CachedDataSource)this.dsQueue.peek()).setLogWriter(out); + this.dsQueue.peek().setLogWriter(out); } @Override public void setLoginTimeout(int seconds) throws SQLException { - ((CachedDataSource)this.dsQueue.peek()).setLoginTimeout(seconds); + this.dsQueue.peek().setLoginTimeout(seconds); } public void displayState(){ if(LOGGER.isDebugEnabled()){ LOGGER.debug("POOLS : Active = "+dsQueue.size() + ";\t Broken = "+broken.size()); - CachedDataSource current = (CachedDataSource)dsQueue.peek(); + CachedDataSource current = dsQueue.peek(); if(current != null) { LOGGER.debug("POOL : Active name = \'"+current.getDbConnectionName()+ "\'"); } @@ -800,7 +800,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb .append("Name:").append("</th>"); for (int i = 0; i < list.size(); i++) { buffer.append("<th id=\"header").append(2 + i).append("\">"); - buffer.append(((CachedDataSource) list.get(i)).getDbConnectionName()).append("</th>"); + buffer.append(list.get(i).getDbConnectionName()).append("</th>"); } buffer.append("</tr>"); @@ -820,7 +820,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb } else { for (int i = 0; i < list.size(); i++) { - buffer.append("Name: ").append(((CachedDataSource) list.get(i)).getDbConnectionName()); + buffer.append("Name: ").append(list.get(i).getDbConnectionName()); buffer.append("\tState: "); if (broken.contains(list.get(i))) { buffer.append("in recovery"); diff --git a/dblib/provider/src/main/resources/org/opendaylight/blueprint/dblib-blueprint.xml b/dblib/provider/src/main/resources/org/opendaylight/blueprint/dblib-blueprint.xml index ee3e0f033..f1d5166db 100644..100755 --- a/dblib/provider/src/main/resources/org/opendaylight/blueprint/dblib-blueprint.xml +++ b/dblib/provider/src/main/resources/org/opendaylight/blueprint/dblib-blueprint.xml @@ -8,6 +8,11 @@ <bean id="dbResourceManager" class="org.onap.ccsdk.sli.core.dblib.DBResourceManager"> <argument ref="provider" /> </bean> - <service ref="dbResourceManager" interface="org.onap.ccsdk.sli.core.dblib.DbLibService" /> + <service ref="dbResourceManager"> + <interfaces> + <value>javax.sql.DataSource</value> + <value>org.onap.ccsdk.sli.core.dblib.DbLibService</value> + </interfaces> + </service> </blueprint>
\ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 000000000..833e1aa96 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,8 @@ +.. This work is licensed under a Creative Commons Attribution 4.0 International License. + +TODO Add files to toctree and delete this header +------------------------------------------------ +.. toctree:: + :maxdepth: 1 + + diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java index 7af4c1c5d..0912ee9fb 100644 --- a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java @@ -28,6 +28,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; @@ -103,117 +104,81 @@ public class ITCaseSvcLogicParser { store.registerNodeType("save"); store.registerNodeType("update"); store.registerNodeType("break"); - } - - @Before - public void setUp() throws Exception { - LOG.info("before"); - } - - @After - public void tearDown() throws Exception { - LOG.info("after"); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - LOG.info("after class"); - } - - /** - * Test method for {@link org.onap.ccsdk.sli.core.sli.SvcLogicParser#parse(java.lang.String)}. - */ - @Test - public void testParseValidXml() { - - try - { - InputStream testStr = getClass().getResourceAsStream("/parser-good.tests"); - BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); - String testCaseFile = null; - while ((testCaseFile = testsReader.readLine()) != null) { - - testCaseFile = testCaseFile.trim(); - - if (testCaseFile.length() > 0) - { - if (!testCaseFile.startsWith("/")) - { - testCaseFile = "/"+testCaseFile; - } - URL testCaseUrl = getClass().getResource(testCaseFile); - if (testCaseUrl == null) - { - fail("Could not resolve test case file "+testCaseFile); - } - - try { - SvcLogicParser.validate(testCaseUrl.getPath(), store); - } catch (Exception e) { - fail("Validation failure ["+e.getMessage()+"]"); - } - } - } - } - catch (SvcLogicParserException e) - { - fail("Parser error : "+e.getMessage()); - } - catch (Exception e) - { - LOG.error("", e); - fail("Caught exception processing test cases"); - } - } - - @Test - public void testParseInvalidXml() { - - try - { - InputStream testStr = getClass().getResourceAsStream("/parser-bad.tests"); - BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); - String testCaseFile = null; - while ((testCaseFile = testsReader.readLine()) != null) { - - testCaseFile = testCaseFile.trim(); - - if (testCaseFile.length() > 0) - { - if (!testCaseFile.startsWith("/")) - { - testCaseFile = "/"+testCaseFile; - } - URL testCaseUrl = getClass().getResource(testCaseFile); - if (testCaseUrl == null) - { - fail("Could not resolve test case file "+testCaseFile); - } - - boolean valid = true; - try { - SvcLogicParser.load(testCaseUrl.getPath(), store); - } catch (Exception e) { - System.out.println(e.getMessage()); - valid = false; - } - - if (valid) { - fail("Expected compiler error on "+testCaseFile+", but got success"); - } - } - } - } - catch (SvcLogicParserException e) - { - fail("Parser error : "+e.getMessage()); - } - catch (Exception e) - { - LOG.error("", e); - fail("Caught exception processing test cases"); - } - - } - + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + LOG.info("after class"); + } + + @Before + public void setUp() throws Exception { + LOG.info("before"); + } + + @After + public void tearDown() throws Exception { + LOG.info("after"); + } + + /** + * Test method for {@link org.onap.ccsdk.sli.core.sli.SvcLogicParser#parse(java.lang.String)}. + */ + @Test + public void testParseValidXml() { + + try { + InputStream testStr = getClass().getResourceAsStream("/parser-good.tests"); + BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); + String testCaseFile = null; + while ((testCaseFile = testsReader.readLine()) != null) { + + testCaseFile = testCaseFile.trim(); + + if (testCaseFile.length() > 0) { + if (!testCaseFile.startsWith("/")) { + testCaseFile = "/" + testCaseFile; + } + URL testCaseUrl = getClass().getResource(testCaseFile); + if (testCaseUrl == null) { + fail("Could not resolve test case file " + testCaseFile); + } + + try { + SvcLogicParser.validate(testCaseUrl.getPath(), store); + } catch (Exception e) { + fail("Validation failure [" + e.getMessage() + "]"); + } + } + } + } catch (SvcLogicParserException e) { + fail("Parser error : " + e.getMessage()); + } catch (Exception e) { + LOG.error("", e); + fail("Caught exception processing test cases"); + } + } + + @Test(expected = SvcLogicException.class) + public void testParseInvalidXml() throws SvcLogicException, IOException { + + InputStream testStr = getClass().getResourceAsStream("/parser-bad.tests"); + BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); + String testCaseFile; + while ((testCaseFile = testsReader.readLine()) != null) { + + testCaseFile = testCaseFile.trim(); + + if (testCaseFile.length() > 0) { + if (!testCaseFile.startsWith("/")) { + testCaseFile = "/" + testCaseFile; + } + URL testCaseUrl = getClass().getResource(testCaseFile); + if (testCaseUrl == null) { + fail("Could not resolve test case file " + testCaseFile); + } + SvcLogicParser.load(testCaseUrl.getPath(), store); + } + } + } } diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java index 3eeb398f4..52c25b6b3 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java @@ -765,7 +765,7 @@ public class MdsalHelper { } catch (Exception gme) { LOG.info("Unable to find static method getDefaultInstance for " - + "class {}", paramClass.getSimpleName(), e); + + "class {}", paramClass.getSimpleName(), gme); } } diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java index 4bb460d78..5f4d3653e 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java @@ -59,12 +59,11 @@ public class SvcLogicServiceImpl implements SvcLogicService { } if (nodeExecutors == null) { - nodeExecutors = new HashMap<String, SvcLogicNodeExecutor>(); + nodeExecutors = new HashMap<>(); } LOG.info("Opening service tracker"); - ServiceTracker tracker = new ServiceTracker(bctx, - SvcLogicNodeExecutor.class.getName(), null); + ServiceTracker tracker = new ServiceTracker(bctx, SvcLogicNodeExecutor.class.getName(), null); tracker.open(); @@ -90,14 +89,12 @@ public class SvcLogicServiceImpl implements SvcLogicService { + ")"; try { bctx.addServiceListener(listener, filter); - ServiceReference[] srl = bctx.getServiceReferences( - SvcLogicNodeExecutor.class.getName(), null); + ServiceReference[] srl = bctx.getServiceReferences(SvcLogicNodeExecutor.class.getName(), null); for (int i = 0; srl != null && i < srl.length; i++) { - listener.serviceChanged(new ServiceEvent( - ServiceEvent.REGISTERED, srl[i])); + listener.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, srl[i])); } } catch (InvalidSyntaxException e) { - e.printStackTrace(); + LOG.info("Invalid syntax", e); } LOG.info("Done registerExecutors"); } @@ -107,26 +104,24 @@ public class SvcLogicServiceImpl implements SvcLogicService { String nodeName = (String) sr.getProperty("nodeType"); if (nodeName != null) { - SvcLogicNodeExecutor executor = null; + SvcLogicNodeExecutor executor; try { executor = (SvcLogicNodeExecutor) bctx.getService(sr); } catch (Exception e) { - LOG.error("Cannot get service executor for " + nodeName); + LOG.error("Cannot get service executor for {}", nodeName, e); return; } - registerExecutor(nodeName, executor); - } } public void registerExecutor(String nodeName, SvcLogicNodeExecutor executor) { if (nodeExecutors == null) { - nodeExecutors = new HashMap<String, SvcLogicNodeExecutor>(); + nodeExecutors = new HashMap<>(); } - LOG.info("SLI - registering executor for node type "+nodeName); + LOG.info("SLI - registering executor for node type {}", nodeName); nodeExecutors.put(nodeName, executor); } @@ -134,25 +129,16 @@ public class SvcLogicServiceImpl implements SvcLogicService { String nodeName = (String) sr.getProperty("nodeType"); if (nodeName != null) { - unregisterExecutor(nodeName); - } - } - public void unregisterExecutor(String nodeName) - { - - LOG.info("SLI - unregistering executor for node type "+nodeName); + public void unregisterExecutor(String nodeName) { + LOG.info("SLI - unregistering executor for node type {}", nodeName); nodeExecutors.remove(nodeName); } - - - - public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx) - throws SvcLogicException { + public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx) throws SvcLogicException { if (nodeExecutors == null) { registerExecutors(); @@ -164,13 +150,11 @@ public class SvcLogicServiceImpl implements SvcLogicService { MDC.put("currentGraph", graph.toString()); SvcLogicNode curNode = graph.getRootNode(); - LOG.info("About to execute graph " + graph.toString()); - - + LOG.info("About to execute graph {}", graph.toString()); while (curNode != null) { MDC.put("nodeId", curNode.getNodeId()+" ("+curNode.getNodeType()+")"); - LOG.info("About to execute node # "+curNode.getNodeId()+" ("+curNode.getNodeType()+")"); + LOG.info("About to execute node # {} ({})", curNode.getNodeId(), curNode.getNodeType()); SvcLogicNode nextNode = executeNode(curNode, ctx); curNode = nextNode; @@ -181,25 +165,24 @@ public class SvcLogicServiceImpl implements SvcLogicService { return (ctx); } - - public SvcLogicNode executeNode(SvcLogicNode node, SvcLogicContext ctx) - throws SvcLogicException { + public SvcLogicNode executeNode(SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { if (node == null) { return (null); } if (LOG.isDebugEnabled()) { - LOG.debug("Executing node " + node.getNodeId()); + LOG.debug("Executing node {}", node.getNodeId()); } SvcLogicNodeExecutor executor = nodeExecutors.get(node.getNodeType()); if (executor != null) { - LOG.debug("Executing node executor for node type "+node.getNodeType()+" - "+executor.getClass().getName()); + LOG.debug("Executing node executor for node type {} - {}", + node.getNodeType(), executor.getClass().getName()); return (executor.execute(this, node, ctx)); } else { if (LOG.isDebugEnabled()) { - LOG.debug(node.getNodeType() + " node not implemented"); + LOG.debug("{} node not implemented", node.getNodeType()); } SvcLogicNode nextNode = node.getOutcomeValue("failure"); if (nextNode != null) { @@ -243,23 +226,18 @@ public class SvcLogicServiceImpl implements SvcLogicService { public Properties execute(String module, String rpc, String version, String mode, Properties props, DOMDataBroker domDataBroker) throws SvcLogicException { - // See if there is a service logic defined - // SvcLogicStore store = SvcLogicActivator.getStore(); 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); - } SvcLogicContext ctx = new SvcLogicContext(props); @@ -271,8 +249,4 @@ public class SvcLogicServiceImpl implements SvcLogicService { return(ctx.toProperties()); } - - - - } diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java index cdf837afe..0a0e28c4f 100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java @@ -21,6 +21,11 @@ package org.onap.ccsdk.sli.core.sli.provider; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import ch.vorburger.mariadb4j.DB; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; @@ -30,7 +35,11 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.Properties; - +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicGraph; import org.onap.ccsdk.sli.core.sli.SvcLogicParser; @@ -39,170 +48,220 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import ch.vorburger.mariadb4j.DB; -import ch.vorburger.mariadb4j.DBConfigurationBuilder; -import junit.framework.TestCase; - -public class ITCaseSvcLogicGraphExecutor extends TestCase { - private static final Logger LOG = LoggerFactory - .getLogger(SvcLogicGraph.class); - - private static final Map<String, SvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, SvcLogicNodeExecutor>() { - { - put("block", new BlockNodeExecutor()); - put("call", new CallNodeExecutor()); - put("configure", new ConfigureNodeExecutor()); - put("delete", new DeleteNodeExecutor()); - put("execute", new ExecuteNodeExecutor()); - put("exists", new ExistsNodeExecutor()); - put("for", new ForNodeExecutor()); - put("get-resource", new GetResourceNodeExecutor()); - put("is-available", new IsAvailableNodeExecutor()); - put("notify", new NotifyNodeExecutor()); - put("record", new RecordNodeExecutor()); - put("release", new ReleaseNodeExecutor()); - put("reserve", new ReserveNodeExecutor()); - put("return", new ReturnNodeExecutor()); - put("save", new SaveNodeExecutor()); - put("set", new SetNodeExecutor()); - put("switch", new SwitchNodeExecutor()); - put("update", new UpdateNodeExecutor()); - - } - }; - - public void testExecute() { - - try { - InputStream testStr = getClass().getResourceAsStream("/executor.tests"); - BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); - - InputStream propStr = getClass().getResourceAsStream("/svclogic.properties"); - - Properties svcprops = new Properties(); - svcprops.load(propStr); - - // Start MariaDB4j database - DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder(); - config.setPort(0); // 0 => autom. detect free port - DB db = DB.newEmbeddedDB(config.build()); - db.start(); - - - - // Override jdbc URL and database name - svcprops.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); - svcprops.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); - - - - SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(svcprops); - - assertNotNull(store); - - store.registerNodeType("switch"); - store.registerNodeType("block"); - store.registerNodeType("get-resource"); - store.registerNodeType("reserve"); - store.registerNodeType("is-available"); - store.registerNodeType("exists"); - store.registerNodeType("configure"); - store.registerNodeType("return"); - store.registerNodeType("record"); - store.registerNodeType("allocate"); - store.registerNodeType("release"); - store.registerNodeType("for"); - store.registerNodeType("set"); - SvcLogicParser parser = new SvcLogicParser(store); - - // Loop through executor tests - - SvcLogicServiceImpl svc = new SvcLogicServiceImpl(); - - for (String nodeType : BUILTIN_NODES.keySet()) { - - LOG.info("SLI - registering node executor for node type "+nodeType); - - svc.registerExecutor(nodeType, BUILTIN_NODES.get(nodeType)); - - } - String testCaseLine = null; - while ((testCaseLine = testsReader.readLine()) != null) { - - String[] testCaseFields = testCaseLine.split(":"); - String testCaseFile = testCaseFields[0]; - String testCaseMethod = testCaseFields[1]; - String testCaseParameters = null; - - if (testCaseFields.length > 2) { - testCaseParameters = testCaseFields[2]; - } - - SvcLogicContext ctx = new SvcLogicContext(); - if (testCaseParameters != null) { - String[] testCaseParameterSettings = testCaseParameters.split(","); - - for (int i = 0 ; i < testCaseParameterSettings.length ; i++) { - String[] nameValue = testCaseParameterSettings[i].split("="); - if (nameValue != null) { - String name = nameValue[0]; - String value = ""; - if (nameValue.length > 1) { - value = nameValue[1]; - } - - ctx.setAttribute(name, value); - } - } - } - - testCaseFile = testCaseFile.trim(); - - if (testCaseFile.length() > 0) { - if (!testCaseFile.startsWith("/")) { - testCaseFile = "/"+testCaseFile; - } - URL testCaseUrl = getClass().getResource(testCaseFile); - if (testCaseUrl == null) { - fail("Could not resolve test case file "+testCaseFile); - } - - LinkedList<SvcLogicGraph> graphs = parser.parse(testCaseUrl.getPath()); - - - assertNotNull(graphs); - - for (SvcLogicGraph graph: graphs) { - if (graph.getRpc().equals(testCaseMethod)) { - Properties props = ctx.toProperties(); - LOG.info("SvcLogicContext before executing "+testCaseMethod+":"); - for (Enumeration e1 = props.propertyNames(); e1.hasMoreElements() ; ) { - String propName = (String) e1.nextElement(); - LOG.info(propName+" = "+props.getProperty(propName)); - } - - svc.execute(graph, ctx); - - props = ctx.toProperties(); - LOG.info("SvcLogicContext after executing "+testCaseMethod+":"); - for (Enumeration e2 = props.propertyNames(); e2.hasMoreElements() ; ) { - String propName = (String) e2.nextElement(); - LOG.info(propName+" = "+props.getProperty(propName)); - } - } - } - - } - - - } - - - } catch (Exception e) { - LOG.error("Caught exception executing directed graphs", e); - fail("Exception executing graphs"); - } - } - - +public class ITCaseSvcLogicGraphExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(SvcLogicGraph.class); + private static final Map<String, SvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, SvcLogicNodeExecutor>() { + { + put("block", new BlockNodeExecutor()); + put("call", new CallNodeExecutor()); + put("configure", new ConfigureNodeExecutor()); + put("delete", new DeleteNodeExecutor()); + put("execute", new ExecuteNodeExecutor()); + put("exists", new ExistsNodeExecutor()); + put("for", new ForNodeExecutor()); + put("get-resource", new GetResourceNodeExecutor()); + put("is-available", new IsAvailableNodeExecutor()); + put("notify", new NotifyNodeExecutor()); + put("record", new RecordNodeExecutor()); + put("release", new ReleaseNodeExecutor()); + put("reserve", new ReserveNodeExecutor()); + put("return", new ReturnNodeExecutor()); + put("save", new SaveNodeExecutor()); + put("set", new SetNodeExecutor()); + put("switch", new SwitchNodeExecutor()); + put("update", new UpdateNodeExecutor()); + + } + }; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + + LOG.info("before class"); + + InputStream propStr = ITCaseSvcLogicGraphExecutor.class.getResourceAsStream("/svclogic.properties"); + + Properties svcprops = new Properties(); + svcprops.load(propStr); + + // Start MariaDB4j database + DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder(); + config.setPort(0); // 0 => autom. detect free port + DB db = DB.newEmbeddedDB(config.build()); + db.start(); + + // Override jdbc URL and database name + svcprops.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); + svcprops.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); + + SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(svcprops); + + assertNotNull(store); + + store.registerNodeType("switch"); + store.registerNodeType("block"); + store.registerNodeType("get-resource"); + store.registerNodeType("reserve"); + store.registerNodeType("is-available"); + store.registerNodeType("exists"); + store.registerNodeType("configure"); + store.registerNodeType("return"); + store.registerNodeType("record"); + store.registerNodeType("allocate"); + store.registerNodeType("release"); + store.registerNodeType("for"); + store.registerNodeType("set"); + SvcLogicParser parser = new SvcLogicParser(store); + + // Loop through executor tests + + SvcLogicServiceImpl svc = new SvcLogicServiceImpl(); + + for (String nodeType : BUILTIN_NODES.keySet()) { + LOG.info("SLI - registering node executor for node type " + nodeType); + svc.registerExecutor(nodeType, BUILTIN_NODES.get(nodeType)); + } + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + LOG.info("after class"); + } + + @Before + public void setUp() throws Exception { + LOG.info("before"); + } + + @After + public void tearDown() throws Exception { + LOG.info("after"); + } + + @Test + public void testExecute() { + + try { + InputStream testStr = getClass().getResourceAsStream("/executor.tests"); + BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); + + InputStream propStr = getClass().getResourceAsStream("/svclogic.properties"); + + Properties svcprops = new Properties(); + svcprops.load(propStr); + + // Start MariaDB4j database + DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder(); + config.setPort(0); // 0 => autom. detect free port + DB db = DB.newEmbeddedDB(config.build()); + db.start(); + + // Override jdbc URL and database name + svcprops.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); + svcprops.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); + + SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(svcprops); + + assertNotNull(store); + + store.registerNodeType("switch"); + store.registerNodeType("block"); + store.registerNodeType("get-resource"); + store.registerNodeType("reserve"); + store.registerNodeType("is-available"); + store.registerNodeType("exists"); + store.registerNodeType("configure"); + store.registerNodeType("return"); + store.registerNodeType("record"); + store.registerNodeType("allocate"); + store.registerNodeType("release"); + store.registerNodeType("for"); + store.registerNodeType("set"); + SvcLogicParser parser = new SvcLogicParser(store); + + // Loop through executor tests + + SvcLogicServiceImpl svc = new SvcLogicServiceImpl(); + + for (String nodeType : BUILTIN_NODES.keySet()) { + + LOG.info("SLI - registering node executor for node type {}", nodeType); + + svc.registerExecutor(nodeType, BUILTIN_NODES.get(nodeType)); + + } + String testCaseLine = null; + while ((testCaseLine = testsReader.readLine()) != null) { + + String[] testCaseFields = testCaseLine.split(":"); + String testCaseFile = testCaseFields[0]; + String testCaseMethod = testCaseFields[1]; + String testCaseParameters = null; + + if (testCaseFields.length > 2) { + testCaseParameters = testCaseFields[2]; + } + + SvcLogicContext ctx = new SvcLogicContext(); + if (testCaseParameters != null) { + String[] testCaseParameterSettings = testCaseParameters.split(","); + + for (int i = 0; i < testCaseParameterSettings.length; i++) { + String[] nameValue = testCaseParameterSettings[i].split("="); + if (nameValue != null) { + String name = nameValue[0]; + String value = ""; + if (nameValue.length > 1) { + value = nameValue[1]; + } + + ctx.setAttribute(name, value); + } + } + } + + testCaseFile = testCaseFile.trim(); + + if (testCaseFile.length() > 0) { + if (!testCaseFile.startsWith("/")) { + testCaseFile = "/" + testCaseFile; + } + URL testCaseUrl = getClass().getResource(testCaseFile); + if (testCaseUrl == null) { + fail("Could not resolve test case file " + testCaseFile); + } + + LinkedList<SvcLogicGraph> graphs = parser.parse(testCaseUrl.getPath()); + + assertNotNull(graphs); + + for (SvcLogicGraph graph : graphs) { + if (graph.getRpc().equals(testCaseMethod)) { + Properties props = ctx.toProperties(); + LOG.info("SvcLogicContext before executing {}:", testCaseMethod); + for (Enumeration e1 = props.propertyNames(); e1.hasMoreElements(); ) { + String propName = (String) e1.nextElement(); + LOG.info(propName + " = " + props.getProperty(propName)); + } + + svc.execute(graph, ctx); + + props = ctx.toProperties(); + LOG.info("SvcLogicContext after executing {}:", testCaseMethod); + for (Enumeration e2 = props.propertyNames(); e2.hasMoreElements(); ) { + String propName = (String) e2.nextElement(); + LOG.info(propName + " = " + props.getProperty(propName)); + } + } + } + + } + } + + } catch (Exception e) { + LOG.error("Caught exception executing directed graphs", e); + fail("Exception executing graphs"); + } + } } diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java index 6048c66d6..0c43f6850 100644 --- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java +++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java @@ -100,7 +100,7 @@ public class SliStringUtils implements SvcLogicJavaPlugin { } } - private static String quotedOrNULL( String str ) { + public static String quotedOrNULL( String str ) { return (str == null) ? "NULL" : '"' + str + '"'; } diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java index 72b3264e9..96c6ae4ac 100644 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java +++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java @@ -91,6 +91,12 @@ public class SliStringUtilsTest { } @Test + public final void testQuotedOrNull() throws SvcLogicException { + //param.put("nullString",null); + assertEquals("NULL",SliStringUtils.quotedOrNULL(null)); + } + + @Test public void equalsIgnoreCaseTrue() throws SvcLogicException { String sourceString = "HeLlOwORLD"; String targetSTring = "HELLOWORLD"; |