From 7d82b39d7007df02bdd050ed1d46111d29fa6ade Mon Sep 17 00:00:00 2001 From: Kevin Smokowski Date: Fri, 23 Feb 2018 18:09:55 +0000 Subject: Favor interfaces Favor using interfaces over concrete implementations Change-Id: Ie7541eeefa69671cc7ed39fba37fdd2e24380770 Issue-ID: CCSDK-189 Signed-off-by: Kevin Smokowski Favor interfaces Favor using interfaces over concrete implementations Change-Id: Ie3b71833c0f31f67288430c25ca31ca07c0449e0 Issue-ID: CCSDK-189 Signed-off-by: Kevin Smokowski --- .../org/onap/ccsdk/sli/core/sli/ExprGrammar.g4 | 2 +- .../onap/ccsdk/sli/core/sli/SvcLogicLoader.java | 212 +++++++++-------- .../sli/core/sli/provider/BlockNodeExecutor.java | 2 +- .../sli/core/sli/provider/BreakNodeExecutor.java | 2 +- .../sli/core/sli/provider/CallNodeExecutor.java | 2 +- .../core/sli/provider/ConfigureNodeExecutor.java | 2 +- .../sli/core/sli/provider/DeleteNodeExecutor.java | 2 +- .../sli/core/sli/provider/ExecuteNodeExecutor.java | 2 +- .../sli/core/sli/provider/ExistsNodeExecutor.java | 2 +- .../sli/core/sli/provider/ForNodeExecutor.java | 2 +- .../core/sli/provider/GetResourceNodeExecutor.java | 2 +- .../core/sli/provider/IsAvailableNodeExecutor.java | 2 +- .../ccsdk/sli/core/sli/provider/MdsalHelper.java | 254 ++++++++++----------- .../sli/core/sli/provider/NotifyNodeExecutor.java | 2 +- .../sli/core/sli/provider/RecordNodeExecutor.java | 2 +- .../sli/core/sli/provider/ReleaseNodeExecutor.java | 2 +- .../sli/core/sli/provider/ReserveNodeExecutor.java | 2 +- .../sli/core/sli/provider/ReturnNodeExecutor.java | 2 +- .../sli/core/sli/provider/SaveNodeExecutor.java | 2 +- .../sli/core/sli/provider/SetNodeExecutor.java | 18 +- .../core/sli/provider/SvcLogicNodeExecutor.java | 2 +- .../sli/provider/SvcLogicPropertiesProvider.java | 164 +------------ .../provider/SvcLogicPropertiesProviderImpl.java | 188 +++++++++++++++ .../sli/core/sli/provider/SvcLogicService.java | 11 +- .../sli/core/sli/provider/SvcLogicServiceImpl.java | 109 ++++----- .../sli/core/sli/provider/SwitchNodeExecutor.java | 2 +- .../sli/core/sli/provider/UpdateNodeExecutor.java | 2 +- .../sli/core/sli/provider/WhileNodeExecutor.java | 2 +- .../org/opendaylight/blueprint/sli-blueprint.xml | 2 +- .../core/sli/provider/ExecuteNodeExecutorTest.java | 2 +- .../sli/provider/ITCaseSvcLogicGraphExecutor.java | 4 +- 31 files changed, 508 insertions(+), 498 deletions(-) create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProviderImpl.java mode change 100755 => 100644 sli/provider/src/main/resources/org/opendaylight/blueprint/sli-blueprint.xml diff --git a/sli/common/src/main/antlr4/org/onap/ccsdk/sli/core/sli/ExprGrammar.g4 b/sli/common/src/main/antlr4/org/onap/ccsdk/sli/core/sli/ExprGrammar.g4 index 1b026bb1..42563168 100755 --- a/sli/common/src/main/antlr4/org/onap/ccsdk/sli/core/sli/ExprGrammar.g4 +++ b/sli/common/src/main/antlr4/org/onap/ccsdk/sli/core/sli/ExprGrammar.g4 @@ -16,7 +16,7 @@ MULTOP : '/' | '*'; NUMBER : ('0'..'9')+; -STRING : '\'' ~[\']* '\''; +STRING : '\'' ~[']* '\''; IDENTIFIER : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'-')*; diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicLoader.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicLoader.java index bc8c1bdf..95f73f96 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicLoader.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicLoader.java @@ -32,137 +32,133 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SvcLogicLoader { - private static final Logger LOGGER = LoggerFactory.getLogger(SvcLogicLoader.class); - SvcLogicStore store; - String directoryRoot; - String propFile; - - public SvcLogicLoader(String directoryRoot, String propFile) { - store = SvcLogicParser.getStore(propFile); - this.directoryRoot = directoryRoot; - this.propFile = propFile; - } - - public void loadAndActivate() throws IOException { - SvcLogicCrawler slc = new SvcLogicCrawler(); - Files.walkFileTree(Paths.get(this.directoryRoot), slc); - - loadGraphs(slc.getGraphPaths(), directoryRoot); - - List activationEntries = processActivationFiles(slc.getActivationPaths()); - activateGraphs(activationEntries); - } - - private List processActivationFiles(List activationPaths) { - List activationEntries = new ArrayList(); - for (Path activationFile : activationPaths) { - activationEntries.addAll(getActivationEntries(activationFile)); + private static final Logger LOGGER = LoggerFactory.getLogger(SvcLogicLoader.class); + protected SvcLogicStore store; + protected String directoryRoot; + + public SvcLogicLoader(String directoryRoot, SvcLogicStore store) { + this.store = store; + this.directoryRoot = directoryRoot; } - return activationEntries; - } + public SvcLogicLoader(String directoryRoot, String propFile) { + this.store = SvcLogicParser.getStore(propFile); + this.directoryRoot = directoryRoot; + } - private void activateGraphs(List activationEntries) { - for (ActivationEntry entry : activationEntries) { - try { - if (store.hasGraph(entry.module, entry.rpc, entry.version, entry.mode)) { - store.activate(entry.module, entry.rpc, entry.version, entry.mode); - } else { - LOGGER.error("hasGraph returned false for " + entry.toString()); - } - } catch (SvcLogicException e) { - LOGGER.error("Failed to call hasGraph for " + entry.toString(), e); - } + public void loadAndActivate() throws IOException { + SvcLogicCrawler slc = new SvcLogicCrawler(); + Files.walkFileTree(Paths.get(directoryRoot), slc); + loadGraphs(slc.getGraphPaths(), directoryRoot); + List activationEntries = processActivationFiles(slc.getActivationPaths()); + activateGraphs(activationEntries); } - } - - protected List getActivationEntries(Path activationFilePath) { - List activationEntries = new ArrayList<>(); - int lineNumber = 1; - try (BufferedReader br = Files.newBufferedReader(activationFilePath, StandardCharsets.US_ASCII)) { - String fileRead = br.readLine(); - while (fileRead != null) { - String[] fields = fileRead.split("\\s"); - if (fields.length == 4) { - activationEntries.add(parseActivationEntry(fields)); - } else { - LOGGER.error("Activation entry [" + fileRead + "] is declared at line number " + lineNumber + " in the file " + activationFilePath + " and is invalid."); + + private List processActivationFiles(List activationPaths) { + List activationEntries = new ArrayList(); + for (Path activationFile : activationPaths) { + activationEntries.addAll(getActivationEntries(activationFile)); } - fileRead = br.readLine(); - lineNumber++; - } - return activationEntries; - } catch (IOException ioe) { - LOGGER.error("Couldn't read the activation file at " + activationFilePath, ioe); - return null; - } - } - - protected void loadGraphs(List graphPaths, String directoryRoot) { - for (Path graphPath : graphPaths) { - try { - saveGraph(graphPath.toString()); - } catch (Exception e) { - LOGGER.error("Couldn't load graph at " + graphPath, e); - } + return activationEntries; } - } - private void saveGraph(String xmlFile) throws SvcLogicException { - File f = new File(xmlFile); - if (!f.canRead()) { - throw new ConfigurationException("Cannot read xml file (" + xmlFile + ")"); + private void activateGraphs(List activationEntries) { + for (ActivationEntry entry : activationEntries) { + try { + if (store.hasGraph(entry.module, entry.rpc, entry.version, entry.mode)) { + store.activate(entry.module, entry.rpc, entry.version, entry.mode); + } else { + LOGGER.error("hasGraph returned false for " + entry.toString()); + } + } catch (SvcLogicException e) { + LOGGER.error("Failed to call hasGraph for " + entry.toString(), e); + } + } } - SvcLogicParser parser = new SvcLogicParser(); - LinkedList graphs = null; - - try { - graphs = parser.parse(xmlFile); - } catch (Exception e) { - throw new SvcLogicException(e.getMessage(), e); + protected List getActivationEntries(Path activationFilePath) { + List activationEntries = new ArrayList<>(); + int lineNumber = 1; + try (BufferedReader br = Files.newBufferedReader(activationFilePath, StandardCharsets.US_ASCII)) { + String fileRead = br.readLine(); + while (fileRead != null) { + String[] fields = fileRead.split("\\s"); + if (fields.length == 4) { + activationEntries.add(parseActivationEntry(fields)); + } else { + LOGGER.error("Activation entry [" + fileRead + "] is declared at line number " + lineNumber + + " in the file " + activationFilePath + " and is invalid."); + } + fileRead = br.readLine(); + lineNumber++; + } + return activationEntries; + } catch (IOException ioe) { + LOGGER.error("Couldn't read the activation file at " + activationFilePath, ioe); + return null; + } } - if (graphs == null) { - throw new SvcLogicException("Could not parse " + xmlFile); + protected void loadGraphs(List graphPaths, String directoryRoot) { + for (Path graphPath : graphPaths) { + try { + saveGraph(graphPath.toString()); + } catch (Exception e) { + LOGGER.error("Couldn't load graph at " + graphPath, e); + } + } } - for (Iterator iter = graphs.iterator(); iter.hasNext();) { - - SvcLogicGraph graph = iter.next(); + private void saveGraph(String xmlFile) throws SvcLogicException { + File f = new File(xmlFile); + if (!f.canRead()) { + throw new ConfigurationException("Cannot read xml file (" + xmlFile + ")"); + } - try { - LOGGER.info("Saving " + graph.toString() + " to database"); - store.store(graph); - } catch (Exception e) { - throw new SvcLogicException(e.getMessage(), e); - } + SvcLogicParser parser = new SvcLogicParser(); + LinkedList graphs = null; - } - } + try { + graphs = parser.parse(xmlFile); + } catch (Exception e) { + throw new SvcLogicException(e.getMessage(), e); + } - protected ActivationEntry parseActivationEntry(String[] fileInput) { - return new ActivationEntry(fileInput[0], fileInput[1], fileInput[2], fileInput[3]); - } + if (graphs == null) { + throw new SvcLogicException("Could not parse " + xmlFile); + } - protected String getValue(String raw, String attributeName) { - raw = raw.substring(attributeName.length() + 1); - if (raw.contains(">")) { - raw = raw.substring(0, raw.lastIndexOf('>')); - } - if (raw.endsWith("'")) { - raw = raw.substring(0, raw.lastIndexOf('\'')); + for (Iterator iter = graphs.iterator(); iter.hasNext();) { + SvcLogicGraph graph = iter.next(); + try { + LOGGER.info("Saving " + graph.toString() + " to database"); + store.store(graph); + } catch (Exception e) { + throw new SvcLogicException(e.getMessage(), e); + } + } } - if (raw.endsWith("\"")) { - raw = raw.substring(0, raw.lastIndexOf('"')); + + protected ActivationEntry parseActivationEntry(String[] fileInput) { + return new ActivationEntry(fileInput[0], fileInput[1], fileInput[2], fileInput[3]); } - return raw; - } + protected String getValue(String raw, String attributeName) { + raw = raw.substring(attributeName.length() + 1); + if (raw.contains(">")) { + raw = raw.substring(0, raw.lastIndexOf('>')); + } + if (raw.endsWith("'")) { + raw = raw.substring(0, raw.lastIndexOf('\'')); + } + if (raw.endsWith("\"")) { + raw = raw.substring(0, raw.lastIndexOf('"')); + } + return raw; + } } diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BlockNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BlockNodeExecutor.java index 64428409..e5ae021f 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BlockNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BlockNodeExecutor.java @@ -34,7 +34,7 @@ public class BlockNodeExecutor extends SvcLogicNodeExecutor { .getLogger(BlockNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { SvcLogicExpression atomicExpr = node.getAttribute("atomic"); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BreakNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BreakNodeExecutor.java index 3bbb3a15..fc6f0a50 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BreakNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BreakNodeExecutor.java @@ -33,7 +33,7 @@ public class BreakNodeExecutor extends SvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(BreakNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String message = "BreakNodeExecutor encountered break with nodeId " + node.getNodeId(); LOG.debug(message); throw new BreakNodeException(message); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/CallNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/CallNodeExecutor.java index 24774af2..6036c38a 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/CallNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/CallNodeExecutor.java @@ -36,7 +36,7 @@ public class CallNodeExecutor extends SvcLogicNodeExecutor { .getLogger(CallNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String outValue = "not-found"; diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ConfigureNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ConfigureNodeExecutor.java index aaadaae3..337b7064 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ConfigureNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ConfigureNodeExecutor.java @@ -38,7 +38,7 @@ public class ConfigureNodeExecutor extends SvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory .getLogger(ConfigureNodeExecutor.class); - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String adaptorName = SvcLogicExpressionResolver.evaluate( diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/DeleteNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/DeleteNodeExecutor.java index a7c3c8e6..571dd37c 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/DeleteNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/DeleteNodeExecutor.java @@ -33,7 +33,7 @@ public class DeleteNodeExecutor extends SvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(DeleteNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutor.java index 2da0241a..ed75c335 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutor.java @@ -41,7 +41,7 @@ public class ExecuteNodeExecutor extends SvcLogicNodeExecutor { .getLogger(ExecuteNodeExecutor.class); private static final String pluginErrorMessage = "Could not execute plugin. SvcLogic status will be set to failure."; - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String pluginName = SvcLogicExpressionResolver.evaluate( diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExistsNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExistsNodeExecutor.java index 69b1132b..80aec075 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExistsNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExistsNodeExecutor.java @@ -33,7 +33,7 @@ public class ExistsNodeExecutor extends SvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(ExistsNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ForNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ForNodeExecutor.java index e9011c80..6c6b4ca2 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ForNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ForNodeExecutor.java @@ -35,7 +35,7 @@ public class ForNodeExecutor extends SvcLogicNodeExecutor { .getLogger(ForNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { SvcLogicExpression atomicExpr = node.getAttribute("atomic"); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/GetResourceNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/GetResourceNodeExecutor.java index 64cf5bc9..468a6fff 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/GetResourceNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/GetResourceNodeExecutor.java @@ -33,7 +33,7 @@ public class GetResourceNodeExecutor extends SvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(GetResourceNodeExecutor.class); - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/IsAvailableNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/IsAvailableNodeExecutor.java index d2a4bfad..72d99e4f 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/IsAvailableNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/IsAvailableNodeExecutor.java @@ -33,7 +33,7 @@ public class IsAvailableNodeExecutor extends SvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(IsAvailableNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); 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 39a87a91..bea21387 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 @@ -23,7 +23,7 @@ package org.onap.ccsdk.sli.core.sli.provider; import java.io.File; import java.io.FileInputStream; -import java.io.IOException; +import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.lang.reflect.Constructor; @@ -34,14 +34,14 @@ import java.lang.reflect.Type; import java.util.LinkedList; import java.util.List; import java.util.Properties; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddressBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefixBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber; import org.opendaylight.yangtools.yang.binding.Identifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -287,52 +287,52 @@ public class MdsalHelper { LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); } - } else if (isPortNumber(returnType)) { - // Save its value - try { - String propName = propNamePfx + "." + fieldName; - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - PortNumber retValue = (PortNumber) m.invoke(fromObj); - if (!isAccessible) { - m.setAccessible(isAccessible); - } - - if (retValue != null) { - propVal = "" + retValue.getValue(); - LOG.debug("Setting property " + propName + " to " + propVal); - props.setProperty(propName, propVal); - - } - } catch (Exception e) { - LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() - + "." + m.getName() + "() to Properties entry", e); - } - } else if (isDscp(returnType)) { - // Save its value - try { - String propName = propNamePfx + "." + fieldName; - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - Dscp retValue = (Dscp) m.invoke(fromObj); - if (!isAccessible) { - m.setAccessible(isAccessible); - } - - if (retValue != null) { - propVal = "" + retValue.getValue(); - LOG.debug("Setting property " + propName + " to " + propVal); - props.setProperty(propName, propVal); - - } - } catch (Exception e) { - LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() - + "." + m.getName() + "() to Properties entry", e); - } + } else if (isPortNumber(returnType)) { + // Save its value + try { + String propName = propNamePfx + "." + fieldName; + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + PortNumber retValue = (PortNumber) m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + + if (retValue != null) { + propVal = "" + retValue.getValue(); + LOG.debug("Setting property " + propName + " to " + propVal); + props.setProperty(propName, propVal); + + } + } catch (Exception e) { + LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() + + "." + m.getName() + "() to Properties entry", e); + } + } else if (isDscp(returnType)) { + // Save its value + try { + String propName = propNamePfx + "." + fieldName; + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + Dscp retValue = (Dscp) m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + + if (retValue != null) { + propVal = "" + retValue.getValue(); + LOG.debug("Setting property " + propName + " to " + propVal); + props.setProperty(propName, propVal); + + } + } catch (Exception e) { + LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() + + "." + m.getName() + "() to Properties entry", e); + } } else { try { boolean isAccessible = m.isAccessible(); @@ -621,9 +621,9 @@ public class MdsalHelper { String paramValue = props.getProperty(propName); if (paramValue == null) { LOG.trace(propName + " is unset"); - } else if ("".equals(paramValue)) { - LOG.trace(propName + " was set to the empty string, setting it to null"); - paramValue = null; + } else if ("".equals(paramValue)) { + LOG.trace(propName + " was set to the empty string, setting it to null"); + paramValue = null; } else { LOG.trace(propName + " = " + paramValue); } @@ -720,28 +720,28 @@ public class MdsalHelper { + "(" + paramValue + ")", e); } } - } else if ("PortNumber".equals(simpleName)) { - if ((paramValue != null) && (paramValue.length() > 0)) { - try { - PortNumber portNumber = PortNumber.getDefaultInstance(paramValue); - m.invoke(toObj, portNumber); - foundValue = true; - } catch (Exception e) { - LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName() - + "(" + paramValue + ")", e); - } - } - } else if ("Dscp".equals(simpleName)) { - if ((paramValue != null) && (paramValue.length() > 0)) { - try { - Dscp dscp = Dscp.getDefaultInstance(paramValue); - m.invoke(toObj, dscp); - foundValue = true; - } catch (Exception e) { - LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName() - + "(" + paramValue + ")", e); - } - } + } else if ("PortNumber".equals(simpleName)) { + if ((paramValue != null) && (paramValue.length() > 0)) { + try { + PortNumber portNumber = PortNumber.getDefaultInstance(paramValue); + m.invoke(toObj, portNumber); + foundValue = true; + } catch (Exception e) { + LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName() + + "(" + paramValue + ")", e); + } + } + } else if ("Dscp".equals(simpleName)) { + if ((paramValue != null) && (paramValue.length() > 0)) { + try { + Dscp dscp = Dscp.getDefaultInstance(paramValue); + m.invoke(toObj, dscp); + foundValue = true; + } catch (Exception e) { + LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName() + + "(" + paramValue + ")", e); + } + } } else { // setter expects a yang-generated class. Need // to @@ -1095,8 +1095,8 @@ public class MdsalHelper { String simpleName = returnClass.getSimpleName(); if ("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName) - || "IpAddress".equals(simpleName) || "IpPrefix".equals(simpleName) - || "PortNumber".equals(simpleName) || "Dscp".equals(simpleName)) { + || "IpAddress".equals(simpleName) || "IpPrefix".equals(simpleName) + || "PortNumber".equals(simpleName) || "Dscp".equals(simpleName)) { LOG.trace(m.getName() + " is an " + simpleName); pstr.print("\n\n * " + propName); } else { @@ -1155,9 +1155,9 @@ public class MdsalHelper { if (c == null) { return (false); } - if (!isIetfInet(c)) { - return (false); - } + if (!isIetfInet(c)) { + return (false); + } String simpleName = c.getSimpleName(); return ("IpPrefix".equals(simpleName)); } @@ -1167,9 +1167,9 @@ public class MdsalHelper { if (c == null) { return (false); } - if (!isIetfInet(c)) { - return (false); - } + if (!isIetfInet(c)) { + return (false); + } String simpleName = c.getSimpleName(); return ("Ipv4Address".equals(simpleName)); } @@ -1179,9 +1179,9 @@ public class MdsalHelper { if (c == null) { return (false); } - if (!isIetfInet(c)) { - return (false); - } + if (!isIetfInet(c)) { + return (false); + } String simpleName = c.getSimpleName(); return ("Ipv6Address".equals(simpleName)); } @@ -1191,52 +1191,52 @@ public class MdsalHelper { if (c == null) { return (false); } - if (!isIetfInet(c)) { - return (false); - } + if (!isIetfInet(c)) { + return (false); + } String simpleName = c.getSimpleName(); return ("IpAddress".equals(simpleName)); } - public static boolean isPortNumber(Class c) { - - if (c == null) { - return (false); - } - if (!isIetfInet(c)) { - return (false); - } - - String simpleName = c.getSimpleName(); - return ("PortNumber".equals(simpleName)); - } - - public static boolean isDscp(Class c) { - - if (c == null) { - return (false); - } - if (!isIetfInet(c)) { - return (false); - } - String simpleName = c.getSimpleName(); - return ("Dscp".equals(simpleName)); - } - - public static boolean isIetfInet(Class c) { - - Package p = c.getPackage(); - if (p != null) { - String pkgName = p.getName(); - - if ((pkgName != null) && (pkgName.indexOf("yang.ietf.inet.types") > -1)) { - return (true); - } - } - - return (false); - } - + public static boolean isPortNumber(Class c) { + + if (c == null) { + return (false); + } + if (!isIetfInet(c)) { + return (false); + } + + String simpleName = c.getSimpleName(); + return ("PortNumber".equals(simpleName)); + } + + public static boolean isDscp(Class c) { + + if (c == null) { + return (false); + } + if (!isIetfInet(c)) { + return (false); + } + String simpleName = c.getSimpleName(); + return ("Dscp".equals(simpleName)); + } + + public static boolean isIetfInet(Class c) { + + Package p = c.getPackage(); + if (p != null) { + String pkgName = p.getName(); + + if ((pkgName != null) && (pkgName.indexOf("yang.ietf.inet.types") > -1)) { + return (true); + } + } + + return (false); + } + public static String toLowerHyphen(String inStr) { if (inStr == null) { return (null); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/NotifyNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/NotifyNodeExecutor.java index cfeab797..44d1ec8f 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/NotifyNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/NotifyNodeExecutor.java @@ -33,7 +33,7 @@ public class NotifyNodeExecutor extends SvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(NotifyNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/RecordNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/RecordNodeExecutor.java index 42e21535..e3941446 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/RecordNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/RecordNodeExecutor.java @@ -38,7 +38,7 @@ public class RecordNodeExecutor extends SvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(RecordNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReleaseNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReleaseNodeExecutor.java index c1ea9641..b0453fad 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReleaseNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReleaseNodeExecutor.java @@ -33,7 +33,7 @@ public class ReleaseNodeExecutor extends SvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(ReleaseNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReserveNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReserveNodeExecutor.java index 646650c6..00355cd0 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReserveNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReserveNodeExecutor.java @@ -34,7 +34,7 @@ public class ReserveNodeExecutor extends SvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(ReserveNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReturnNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReturnNodeExecutor.java index 7f924180..e05692d5 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReturnNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReturnNodeExecutor.java @@ -38,7 +38,7 @@ public class ReturnNodeExecutor extends SvcLogicNodeExecutor { .getLogger(ReturnNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String status = SvcLogicExpressionResolver.evaluate( diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SaveNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SaveNodeExecutor.java index d2b8b0a5..1b5219be 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SaveNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SaveNodeExecutor.java @@ -38,7 +38,7 @@ public class SaveNodeExecutor extends SvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(SaveNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java index d0c052a1..dc7fad0a 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java @@ -41,7 +41,7 @@ public class SetNodeExecutor extends SvcLogicNodeExecutor { .getLogger(SetNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String ifunsetStr = SvcLogicExpressionResolver.evaluate( @@ -60,16 +60,16 @@ public class SetNodeExecutor extends SvcLogicNodeExecutor { // Resolve LHS of assignment (could contain index variables) try { - //Backticks symbolize the variable should be handled as an expression instead of as a variable - if (curName.trim().startsWith("`")) { - int lastParen = curName.lastIndexOf("`"); - String evalExpr = curName.trim().substring(1, lastParen); - SvcLogicExpression lhsExpr = SvcLogicExpressionFactory.parse(evalExpr); - lhsVarName = SvcLogicExpressionResolver.evaluate(lhsExpr, node, ctx); - } else { + //Backticks symbolize the variable should be handled as an expression instead of as a variable + if (curName.trim().startsWith("`")) { + int lastParen = curName.lastIndexOf("`"); + String evalExpr = curName.trim().substring(1, lastParen); + SvcLogicExpression lhsExpr = SvcLogicExpressionFactory.parse(evalExpr); + lhsVarName = SvcLogicExpressionResolver.evaluate(lhsExpr, node, ctx); + } else { SvcLogicExpression lhsExpr = SvcLogicExpressionFactory.parse(curName); lhsVarName = SvcLogicExpressionResolver.resolveVariableName(lhsExpr, node, ctx); - } + } } catch (Exception e) { LOG.warn("Caught exception trying to resolve variable name ("+curName+")", e); } diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicNodeExecutor.java index 0cfcfb91..593c972a 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicNodeExecutor.java @@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory; public abstract class SvcLogicNodeExecutor { - public abstract SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException; + public abstract SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException; private static final Logger LOG = LoggerFactory.getLogger(SvcLogicNodeExecutor.class); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProvider.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProvider.java index 6e859721..9debd6bc 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProvider.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProvider.java @@ -20,169 +20,9 @@ package org.onap.ccsdk.sli.core.sli.provider; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Optional; import java.util.Properties; -import java.util.Vector; -import org.onap.ccsdk.sli.core.dblib.DblibConfigurationException; -import org.onap.ccsdk.sli.core.sli.ConfigurationException; -import org.onap.ccsdk.sli.core.utils.JREFileResolver; -import org.onap.ccsdk.sli.core.utils.KarafRootFileResolver; -import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver; -import org.onap.ccsdk.sli.core.utils.common.CoreDefaultFileResolver; -import org.onap.ccsdk.sli.core.utils.common.SdncConfigEnvVarFileResolver; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +public interface SvcLogicPropertiesProvider { -/** - * Responsible for determining the properties file to use and instantiating the - * DBResourceManager Service. The priority for properties file - * resolution is as follows: - * - *
    - *
  1. A directory identified by the system environment variable - * SDNC_CONFIG_DIR
  2. - *
  3. The default directory DEFAULT_DBLIB_PROP_DIR
  4. - *
  5. A directory identified by the JRE argument - * dblib.properties
  6. - *
  7. A dblib.properties file located in the karaf root - * directory
  8. - *
- */ -public class SvcLogicPropertiesProvider { - - private static final Logger LOG = LoggerFactory.getLogger(SvcLogicPropertiesProvider.class); - - /** - * The name of the properties file for database configuration - */ - private static final String SVCLOGIC_PROP_FILE_NAME = "svclogic.properties"; - - /** - * A prioritized list of strategies for resolving dblib properties files. - */ - private Vector sliPropertiesFileResolvers = new Vector<>(); - - /** - * The configuration properties for the db connection. - */ - private Properties properties; - - /** - * Set up the prioritized list of strategies for resolving dblib properties - * files. - */ - public SvcLogicPropertiesProvider() { - sliPropertiesFileResolvers - .add(new SdncConfigEnvVarFileResolver("Using property file (1) from environment variable")); - sliPropertiesFileResolvers.add(new CoreDefaultFileResolver("Using property file (2) from default directory")); - - sliPropertiesFileResolvers.add( - new JREFileResolver("Using property file (3) from JRE argument", SvcLogicPropertiesProvider.class)); - sliPropertiesFileResolvers.add(new KarafRootFileResolver("Using property file (4) from karaf root", this)); - - // determines properties file as according to the priority described in the - // class header comment - final File propertiesFile = determinePropertiesFile(this); - if (propertiesFile != null) { - try (FileInputStream fileInputStream = new FileInputStream(propertiesFile)) { - properties = new Properties(); - properties.load(fileInputStream); - } catch (final IOException e) { - LOG.error("Failed to load properties for file: {}", propertiesFile.toString(), - new ConfigurationException("Failed to load properties for file: " + propertiesFile.toString(), - e)); - } - } else { - // Try to read properties as resource - - InputStream propStr = getClass().getResourceAsStream("/" + SVCLOGIC_PROP_FILE_NAME); - if (propStr != null) { - properties = new Properties(); - try { - properties.load(propStr); - propStr.close(); - } catch (IOException e) { - properties = null; - } - } - - } - - if (properties == null) { - reportFailure("Missing configuration properties resource(3)", new ConfigurationException( - "Missing configuration properties resource(3): " + SVCLOGIC_PROP_FILE_NAME)); - } - } - - /** - * Extract svclogic config properties. - * - * @return the svclogic config properties - */ - public Properties getProperties() { - return properties; - } - - /** - * Reports the method chosen for properties resolution to the - * Logger. - * - * @param message - * Some user friendly message - * @param fileOptional - * The file location of the chosen properties file - * @return the file location of the chosen properties file - */ - private static File reportSuccess(final String message, final Optional fileOptional) { - if (fileOptional.isPresent()) { - final File file = fileOptional.get(); - LOG.info("{} {}", message, file.getPath()); - return file; - } - return null; - } - - /** - * Reports fatal errors. This is the case in which no properties file could be - * found. - * - * @param message - * An appropriate fatal error message - * @param configurationException - * An exception describing what went wrong during resolution - */ - private static void reportFailure(final String message, final ConfigurationException configurationException) { - - LOG.error("{}", message, configurationException); - } - - /** - * Determines the dblib properties file to use based on the following priority: - *
    - *
  1. A directory identified by the system environment variable - * SDNC_CONFIG_DIR
  2. - *
  3. The default directory DEFAULT_DBLIB_PROP_DIR
  4. - *
  5. A directory identified by the JRE argument - * dblib.properties
  6. - *
  7. A dblib.properties file located in the karaf root - * directory
  8. - *
- */ - File determinePropertiesFile(final SvcLogicPropertiesProvider resourceProvider) { - - for (final PropertiesFileResolver sliPropertiesFileResolver : sliPropertiesFileResolvers) { - final Optional fileOptional = sliPropertiesFileResolver.resolveFile(SVCLOGIC_PROP_FILE_NAME); - if (fileOptional.isPresent()) { - return reportSuccess(sliPropertiesFileResolver.getSuccessfulResolutionMessage(), fileOptional); - } - } - - return null; - } + public Properties getProperties();; } diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProviderImpl.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProviderImpl.java new file mode 100644 index 00000000..a9992a09 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProviderImpl.java @@ -0,0 +1,188 @@ +/*- + * ============LICENSE_START======================================================= + * onap + * ================================================================================ + * Copyright (C) 2016 - 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Optional; +import java.util.Properties; +import java.util.Vector; + +import org.onap.ccsdk.sli.core.dblib.DblibConfigurationException; +import org.onap.ccsdk.sli.core.sli.ConfigurationException; +import org.onap.ccsdk.sli.core.utils.JREFileResolver; +import org.onap.ccsdk.sli.core.utils.KarafRootFileResolver; +import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver; +import org.onap.ccsdk.sli.core.utils.common.CoreDefaultFileResolver; +import org.onap.ccsdk.sli.core.utils.common.SdncConfigEnvVarFileResolver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Responsible for determining the properties file to use and instantiating the + * DBResourceManager Service. The priority for properties file + * resolution is as follows: + * + *
    + *
  1. A directory identified by the system environment variable + * SDNC_CONFIG_DIR
  2. + *
  3. The default directory DEFAULT_DBLIB_PROP_DIR
  4. + *
  5. A directory identified by the JRE argument + * dblib.properties
  6. + *
  7. A dblib.properties file located in the karaf root + * directory
  8. + *
+ */ +public class SvcLogicPropertiesProviderImpl implements SvcLogicPropertiesProvider { + + private static final Logger LOG = LoggerFactory.getLogger(SvcLogicPropertiesProviderImpl.class); + + /** + * The name of the properties file for database configuration + */ + private static final String SVCLOGIC_PROP_FILE_NAME = "svclogic.properties"; + + /** + * A prioritized list of strategies for resolving dblib properties files. + */ + private Vector sliPropertiesFileResolvers = new Vector<>(); + + /** + * The configuration properties for the db connection. + */ + private Properties properties; + + /** + * Set up the prioritized list of strategies for resolving dblib properties + * files. + */ + public SvcLogicPropertiesProviderImpl() { + sliPropertiesFileResolvers + .add(new SdncConfigEnvVarFileResolver("Using property file (1) from environment variable")); + sliPropertiesFileResolvers.add(new CoreDefaultFileResolver("Using property file (2) from default directory")); + + sliPropertiesFileResolvers.add( + new JREFileResolver("Using property file (3) from JRE argument", SvcLogicPropertiesProviderImpl.class)); + sliPropertiesFileResolvers.add(new KarafRootFileResolver("Using property file (4) from karaf root", this)); + + // determines properties file as according to the priority described in the + // class header comment + final File propertiesFile = determinePropertiesFile(this); + if (propertiesFile != null) { + try (FileInputStream fileInputStream = new FileInputStream(propertiesFile)) { + properties = new Properties(); + properties.load(fileInputStream); + } catch (final IOException e) { + LOG.error("Failed to load properties for file: {}", propertiesFile.toString(), + new ConfigurationException("Failed to load properties for file: " + propertiesFile.toString(), + e)); + } + } else { + // Try to read properties as resource + + InputStream propStr = getClass().getResourceAsStream("/" + SVCLOGIC_PROP_FILE_NAME); + if (propStr != null) { + properties = new Properties(); + try { + properties.load(propStr); + propStr.close(); + } catch (IOException e) { + properties = null; + } + } + + } + + if (properties == null) { + reportFailure("Missing configuration properties resource(3)", new ConfigurationException( + "Missing configuration properties resource(3): " + SVCLOGIC_PROP_FILE_NAME)); + } + } + + /** + * Extract svclogic config properties. + * + * @return the svclogic config properties + */ + public Properties getProperties() { + return properties; + } + + /** + * Reports the method chosen for properties resolution to the + * Logger. + * + * @param message + * Some user friendly message + * @param fileOptional + * The file location of the chosen properties file + * @return the file location of the chosen properties file + */ + private static File reportSuccess(final String message, final Optional fileOptional) { + if (fileOptional.isPresent()) { + final File file = fileOptional.get(); + LOG.info("{} {}", message, file.getPath()); + return file; + } + return null; + } + + /** + * Reports fatal errors. This is the case in which no properties file could be + * found. + * + * @param message + * An appropriate fatal error message + * @param configurationException + * An exception describing what went wrong during resolution + */ + private static void reportFailure(final String message, final ConfigurationException configurationException) { + + LOG.error("{}", message, configurationException); + } + + /** + * Determines the dblib properties file to use based on the following priority: + *
    + *
  1. A directory identified by the system environment variable + * SDNC_CONFIG_DIR
  2. + *
  3. The default directory DEFAULT_DBLIB_PROP_DIR
  4. + *
  5. A directory identified by the JRE argument + * dblib.properties
  6. + *
  7. A dblib.properties file located in the karaf root + * directory
  8. + *
+ */ + File determinePropertiesFile(final SvcLogicPropertiesProviderImpl resourceProvider) { + + for (final PropertiesFileResolver sliPropertiesFileResolver : sliPropertiesFileResolvers) { + final Optional fileOptional = sliPropertiesFileResolver.resolveFile(SVCLOGIC_PROP_FILE_NAME); + if (fileOptional.isPresent()) { + return reportSuccess(sliPropertiesFileResolver.getSuccessfulResolutionMessage(), fileOptional); + } + } + + return null; + } +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java index 19d985dd..3f24adff 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java @@ -22,8 +22,11 @@ package org.onap.ccsdk.sli.core.sli.provider; import java.util.Properties; - +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.opendaylight.controller.md.sal.dom.api.DOMDataBroker; public interface SvcLogicService { @@ -73,4 +76,10 @@ public interface SvcLogicService { */ Properties execute(String module, String rpc, String version, String mode, Properties parms, DOMDataBroker domDataBroker) throws SvcLogicException; + SvcLogicStore getStore() throws SvcLogicException; + + SvcLogicContext execute(SvcLogicGraph calledGraph, SvcLogicContext ctx) throws SvcLogicException; + + SvcLogicNode executeNode(SvcLogicNode nextNode, SvcLogicContext ctx) throws SvcLogicException; + } 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 53875b35..3bd896c5 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 @@ -23,7 +23,6 @@ package org.onap.ccsdk.sli.core.sli.provider; import java.util.HashMap; 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.MetricLogger; @@ -47,35 +46,24 @@ import org.slf4j.LoggerFactory; import org.slf4j.MDC; public class SvcLogicServiceImpl implements SvcLogicService { - - private static final Logger LOG = LoggerFactory - .getLogger(SvcLogicServiceImpl.class); - - private HashMap nodeExecutors = null; - - private BundleContext bctx = null; - - private Properties properties; - - private SvcLogicStore store; - - public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider) throws SvcLogicException{ - - properties = resourceProvider.getProperties(); - - getStore(); + private static final Logger LOG = LoggerFactory.getLogger(SvcLogicServiceImpl.class); + protected HashMap nodeExecutors = null; + protected BundleContext bctx = null; + protected Properties properties; + protected SvcLogicStore store; + + public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider) throws SvcLogicException { + properties = resourceProvider.getProperties(); + getStore(); } - public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider, DbLibService dbSvc) throws SvcLogicException{ - - properties = resourceProvider.getProperties(); - store = new SvcLogicDblibStore(dbSvc); -} - - - - private void registerExecutors() { + public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider, DbLibService dbSvc) + throws SvcLogicException { + properties = resourceProvider.getProperties(); + store = new SvcLogicDblibStore(dbSvc); + } + protected void registerExecutors() { LOG.info("Entered register executors"); if (bctx == null) { bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); @@ -91,25 +79,23 @@ public class SvcLogicServiceImpl implements SvcLogicService { tracker.open(); ServiceListener listener = new ServiceListener() { - public void serviceChanged(ServiceEvent ev) { ServiceReference sr = ev.getServiceReference(); switch (ev.getType()) { - case ServiceEvent.REGISTERED: { - registerExecutor(sr); - } - break; - case ServiceEvent.UNREGISTERING: { - unregisterExecutor(sr); - } - break; + case ServiceEvent.REGISTERED: { + registerExecutor(sr); + } + break; + case ServiceEvent.UNREGISTERING: { + unregisterExecutor(sr); + } + break; } } }; LOG.info("Adding service listener"); - String filter = "(objectclass=" + SvcLogicNodeExecutor.class.getName() - + ")"; + String filter = "(objectclass=" + SvcLogicNodeExecutor.class.getName() + ")"; try { bctx.addServiceListener(listener, filter); ServiceReference[] srl = bctx.getServiceReferences(SvcLogicNodeExecutor.class.getName(), null); @@ -123,7 +109,6 @@ public class SvcLogicServiceImpl implements SvcLogicService { } public void registerExecutor(ServiceReference sr) { - String nodeName = (String) sr.getProperty("nodeType"); if (nodeName != null) { @@ -139,8 +124,7 @@ public class SvcLogicServiceImpl implements SvcLogicService { } } - public void registerExecutor(String nodeName, SvcLogicNodeExecutor executor) - { + public void registerExecutor(String nodeName, SvcLogicNodeExecutor executor) { if (nodeExecutors == null) { nodeExecutors = new HashMap<>(); } @@ -152,7 +136,7 @@ public class SvcLogicServiceImpl implements SvcLogicService { String nodeName = (String) sr.getProperty("nodeType"); if (nodeName != null) { - unregisterExecutor(nodeName); + unregisterExecutor(nodeName); } } @@ -162,13 +146,12 @@ public class SvcLogicServiceImpl implements SvcLogicService { } public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx) throws SvcLogicException { - if (nodeExecutors == null) { registerExecutors(); } // Set service name in MDC to reference current working directed graph - MDC.put(MetricLogger.SERVICE_NAME, graph.getModule()+":"+graph.getRpc()+"/v"+graph.getVersion()); + MDC.put(MetricLogger.SERVICE_NAME, graph.getModule() + ":" + graph.getRpc() + "/v" + graph.getVersion()); MDC.put("currentGraph", graph.toString()); @@ -176,7 +159,7 @@ public class SvcLogicServiceImpl implements SvcLogicService { LOG.info("About to execute graph {}", graph.toString()); while (curNode != null) { - MDC.put("nodeId", curNode.getNodeId()+" ("+curNode.getNodeType()+")"); + MDC.put("nodeId", curNode.getNodeId() + " (" + curNode.getNodeType() + ")"); LOG.info("About to execute node # {} ({})", curNode.getNodeId(), curNode.getNodeType()); SvcLogicNode nextNode = executeNode(curNode, ctx); @@ -200,8 +183,8 @@ public class SvcLogicServiceImpl implements SvcLogicService { 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()) { @@ -227,36 +210,31 @@ public class SvcLogicServiceImpl implements SvcLogicService { } return (nextNode); } - } @Override - public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException - { + public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException { return (store.hasGraph(module, rpc, version, mode)); } @Override public Properties execute(String module, String rpc, String version, String mode, Properties props) throws SvcLogicException { - return(execute(module, rpc, version, mode, props, null)); + return (execute(module, rpc, version, mode, props, null)); } - @Override - public Properties execute(String module, String rpc, String version, String mode, - Properties props, DOMDataBroker domDataBroker) throws SvcLogicException { - - + public Properties execute(String module, String rpc, String version, String mode, Properties props, + DOMDataBroker domDataBroker) throws SvcLogicException { LOG.info("Fetching service logic from data store"); SvcLogicGraph graph = store.fetch(module, rpc, version, mode); - if (graph == null) - { + 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); + retProps.setProperty("error-message", + "No service logic found for [" + module + "," + rpc + "," + version + "," + mode + "]"); + return (retProps); } SvcLogicContext ctx = new SvcLogicContext(props); @@ -266,16 +244,15 @@ public class SvcLogicServiceImpl implements SvcLogicService { execute(graph, ctx); - return(ctx.toProperties()); + return (ctx.toProperties()); } - public SvcLogicStore getStore() throws SvcLogicException { + public SvcLogicStore getStore() throws SvcLogicException { // Create and initialize SvcLogicStore object - used to access // saved service logic. - - if (store != null) { - return store; - } + if (store != null) { + return store; + } try { store = SvcLogicStoreFactory.getSvcLogicStore(properties); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SwitchNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SwitchNodeExecutor.java index fa3bbcf4..592fb288 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SwitchNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SwitchNodeExecutor.java @@ -34,7 +34,7 @@ public class SwitchNodeExecutor extends SvcLogicNodeExecutor { @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/UpdateNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/UpdateNodeExecutor.java index 148745f6..a783df41 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/UpdateNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/UpdateNodeExecutor.java @@ -38,7 +38,7 @@ public class UpdateNodeExecutor extends SvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(UpdateNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/WhileNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/WhileNodeExecutor.java index 69ac6138..b717aa98 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/WhileNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/WhileNodeExecutor.java @@ -34,7 +34,7 @@ public class WhileNodeExecutor extends SvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(WhileNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { + public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String testResult = evaluateNodeTest(node, ctx); SvcLogicExpression silentFailureExpr = node.getAttribute("do"); diff --git a/sli/provider/src/main/resources/org/opendaylight/blueprint/sli-blueprint.xml b/sli/provider/src/main/resources/org/opendaylight/blueprint/sli-blueprint.xml old mode 100755 new mode 100644 index 82905742..bb14477e --- a/sli/provider/src/main/resources/org/opendaylight/blueprint/sli-blueprint.xml +++ b/sli/provider/src/main/resources/org/opendaylight/blueprint/sli-blueprint.xml @@ -3,7 +3,7 @@ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0" odl:use-default-for-reference-types="true"> - + diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java index eccbfc9e..33ce6f69 100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java @@ -53,7 +53,7 @@ public class ExecuteNodeExecutorTest extends TestCase { MockExecuteNodeExecutor execute = new MockExecuteNodeExecutor(); SvcLogicNode node = new SvcLogicNode(0, "", "", new SvcLogicGraph()); node.setAttribute("method", "selectLunch"); - SvcLogicPropertiesProvider resourceProvider = new SvcLogicPropertiesProvider(); + SvcLogicPropertiesProvider resourceProvider = new SvcLogicPropertiesProviderImpl(); execute.execute(new SvcLogicServiceImpl(resourceProvider), new SvcLogicNode(0, "", "", new SvcLogicGraph()), new SvcLogicContext()); } 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 18f044b3..5e627cdb 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 @@ -102,7 +102,7 @@ public class ITCaseSvcLogicGraphExecutor { SvcLogicParser parser = new SvcLogicParser(); // Loop through executor tests - SvcLogicPropertiesProvider resourceProvider = new SvcLogicPropertiesProvider(); + SvcLogicPropertiesProvider resourceProvider = new SvcLogicPropertiesProviderImpl(); SvcLogicServiceImpl svc = new SvcLogicServiceImpl(resourceProvider); for (String nodeType : BUILTIN_NODES.keySet()) { @@ -156,7 +156,7 @@ public class ITCaseSvcLogicGraphExecutor { SvcLogicParser parser = new SvcLogicParser(); // Loop through executor tests - SvcLogicPropertiesProvider resourceProvider = new SvcLogicPropertiesProvider(); + SvcLogicPropertiesProvider resourceProvider = new SvcLogicPropertiesProviderImpl(); SvcLogicServiceImpl svc = new SvcLogicServiceImpl(resourceProvider); -- cgit 1.2.3-korg