Favor interfaces
authorKevin Smokowski <ks6305@att.com>
Fri, 23 Feb 2018 18:09:55 +0000 (18:09 +0000)
committerTimoney, Dan (dt5972) <dt5972@att.com>
Fri, 2 Mar 2018 20:19:35 +0000 (15:19 -0500)
Favor using interfaces over concrete implementations

Change-Id: Ie7541eeefa69671cc7ed39fba37fdd2e24380770
Issue-ID: CCSDK-189
Signed-off-by: Kevin Smokowski <ks6305@att.com>
Favor interfaces

Favor using interfaces over concrete implementations

Change-Id: Ie3b71833c0f31f67288430c25ca31ca07c0449e0
Issue-ID: CCSDK-189
Signed-off-by: Kevin Smokowski <ks6305@att.com>
31 files changed:
sli/common/src/main/antlr4/org/onap/ccsdk/sli/core/sli/ExprGrammar.g4
sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicLoader.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BlockNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BreakNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/CallNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ConfigureNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/DeleteNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExistsNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ForNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/GetResourceNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/IsAvailableNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/NotifyNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/RecordNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReleaseNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReserveNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReturnNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SaveNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProvider.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProviderImpl.java [new file with mode: 0644]
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SwitchNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/UpdateNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/WhileNodeExecutor.java
sli/provider/src/main/resources/org/opendaylight/blueprint/sli-blueprint.xml [changed mode: 0755->0644]
sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java
sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java

index 1b026bb..4256316 100755 (executable)
@@ -16,7 +16,7 @@ MULTOP : '/' | '*';
 
 NUMBER : ('0'..'9')+;
 
-STRING : '\'' ~[\']* '\'';
+STRING : '\'' ~[']* '\'';
 
 IDENTIFIER : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'-')*;
 
index bc8c1bd..95f73f9 100644 (file)
@@ -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<ActivationEntry> activationEntries = processActivationFiles(slc.getActivationPaths());
-    activateGraphs(activationEntries);
-  }
-
-  private List<ActivationEntry> processActivationFiles(List<Path> activationPaths) {
-    List<ActivationEntry> activationEntries = new ArrayList<ActivationEntry>();
-    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<ActivationEntry> 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<ActivationEntry> activationEntries = processActivationFiles(slc.getActivationPaths());
+        activateGraphs(activationEntries);
     }
-  }
-
-  protected List<ActivationEntry> getActivationEntries(Path activationFilePath) {
-    List<ActivationEntry> 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<ActivationEntry> processActivationFiles(List<Path> activationPaths) {
+        List<ActivationEntry> activationEntries = new ArrayList<ActivationEntry>();
+        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<Path> 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<ActivationEntry> 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<SvcLogicGraph> graphs = null;
-
-    try {
-      graphs = parser.parse(xmlFile);
-    } catch (Exception e) {
-      throw new SvcLogicException(e.getMessage(), e);
+    protected List<ActivationEntry> getActivationEntries(Path activationFilePath) {
+        List<ActivationEntry> 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<Path> 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<SvcLogicGraph> 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<SvcLogicGraph> 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<SvcLogicGraph> 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;
+    }
 
 }
index 6442840..e5ae021 100644 (file)
@@ -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");
index 3bbb3a1..fc6f0a5 100644 (file)
@@ -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);
index 24774af..6036c38 100644 (file)
@@ -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";
index aaadaae..337b706 100644 (file)
@@ -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(
index a7c3c8e..571dd37 100644 (file)
@@ -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);
index 2da0241..ed75c33 100644 (file)
@@ -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(
index 69b1132..80aec07 100644 (file)
@@ -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);
index e9011c8..6c6b4ca 100644 (file)
@@ -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");
index 64cf5bc..468a6ff 100644 (file)
@@ -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);
index d2a4bfa..72d99e4 100644 (file)
@@ -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);
index 39a87a9..bea2138 100644 (file)
@@ -23,7 +23,7 @@ package org.onap.ccsdk.sli.core.sli.provider;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.IOException;\r
+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;\r
+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;\r
+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)) {\r
-                            // Save its value\r
-                            try {\r
-                                String propName = propNamePfx + "." + fieldName;\r
-                                boolean isAccessible = m.isAccessible();\r
-                                if (!isAccessible) {\r
-                                    m.setAccessible(true);\r
-                                }\r
-                                PortNumber retValue = (PortNumber) m.invoke(fromObj);\r
-                                if (!isAccessible) {\r
-                                    m.setAccessible(isAccessible);\r
-                                }\r
-\r
-                                if (retValue != null) {\r
-                                    propVal = "" + retValue.getValue();\r
-                                    LOG.debug("Setting property " + propName + " to " + propVal);\r
-                                    props.setProperty(propName, propVal);\r
-\r
-                                }\r
-                            } catch (Exception e) {\r
-                                LOG.error("Caught exception trying to convert value returned by " + fromClass.getName()\r
-                                        + "." + m.getName() + "() to Properties entry", e);\r
-                            }\r
-                        } else if (isDscp(returnType)) {\r
-                            // Save its value\r
-                            try {\r
-                                String propName = propNamePfx + "." + fieldName;\r
-                                boolean isAccessible = m.isAccessible();\r
-                                if (!isAccessible) {\r
-                                    m.setAccessible(true);\r
-                                }\r
-                                Dscp retValue = (Dscp) m.invoke(fromObj);\r
-                                if (!isAccessible) {\r
-                                    m.setAccessible(isAccessible);\r
-                                }\r
-\r
-                                if (retValue != null) {\r
-                                    propVal = "" + retValue.getValue();\r
-                                    LOG.debug("Setting property " + propName + " to " + propVal);\r
-                                    props.setProperty(propName, propVal);\r
-\r
-                                }\r
-                            } catch (Exception e) {\r
-                                LOG.error("Caught exception trying to convert value returned by " + fromClass.getName()\r
-                                        + "." + m.getName() + "() to Properties entry", e);\r
-                            }\r
+                        } 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)) {\r
-                        LOG.trace(propName + " was set to the empty string, setting it to null");\r
-                        paramValue = null;\r
+                    } 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)) {\r
-                                if ((paramValue != null) && (paramValue.length() > 0)) {\r
-                                    try {\r
-                                        PortNumber portNumber = PortNumber.getDefaultInstance(paramValue);\r
-                                        m.invoke(toObj, portNumber);\r
-                                        foundValue = true;\r
-                                    } catch (Exception e) {\r
-                                        LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName()\r
-                                                + "(" + paramValue + ")", e);\r
-                                    }\r
-                                }\r
-                            } else if ("Dscp".equals(simpleName)) {\r
-                                if ((paramValue != null) && (paramValue.length() > 0)) {\r
-                                    try {\r
-                                        Dscp dscp = Dscp.getDefaultInstance(paramValue);\r
-                                        m.invoke(toObj, dscp);\r
-                                        foundValue = true;\r
-                                    } catch (Exception e) {\r
-                                        LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName()\r
-                                                + "(" + paramValue + ")", e);\r
-                                    }\r
-                                }\r
+                            } 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)\r
-                                    || "PortNumber".equals(simpleName) || "Dscp".equals(simpleName)) {\r
+                                    || "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)) {\r
-            return (false);\r
-        }\r
+        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)) {\r
-            return (false);\r
-        }\r
+        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)) {\r
-            return (false);\r
-        }\r
+        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)) {\r
-            return (false);\r
-        }\r
+        if (!isIetfInet(c)) {
+            return (false);
+        }
         String simpleName = c.getSimpleName();
         return ("IpAddress".equals(simpleName));
     }
 
-    public static boolean isPortNumber(Class c) {\r
-\r
-        if (c == null) {\r
-            return (false);\r
-        }\r
-        if (!isIetfInet(c)) {\r
-            return (false);\r
-        }\r
-\r
-        String simpleName = c.getSimpleName();\r
-        return ("PortNumber".equals(simpleName));\r
-    }\r
-\r
-    public static boolean isDscp(Class c) {\r
-\r
-        if (c == null) {\r
-            return (false);\r
-        }\r
-        if (!isIetfInet(c)) {\r
-            return (false);\r
-        }\r
-        String simpleName = c.getSimpleName();\r
-        return ("Dscp".equals(simpleName));\r
-    }\r
-\r
-    public static boolean isIetfInet(Class c) {\r
-\r
-        Package p = c.getPackage();\r
-        if (p != null) {\r
-            String pkgName = p.getName();\r
-\r
-            if ((pkgName != null) && (pkgName.indexOf("yang.ietf.inet.types") > -1)) {\r
-                return (true);\r
-            }\r
-        }\r
-\r
-        return (false);\r
-    }\r
-\r
+    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);
index cfeab79..44d1ec8 100644 (file)
@@ -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);
index 42e2153..e394144 100644 (file)
@@ -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);
index c1ea964..b0453fa 100644 (file)
@@ -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);
index 646650c..00355cd 100644 (file)
@@ -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);
index 7f92418..e05692d 100644 (file)
@@ -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(
index d2b8b0a..1b5219b 100644 (file)
@@ -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);
index d0c052a..dc7fad0 100644 (file)
@@ -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\r
-                if (curName.trim().startsWith("`")) {\r
-                    int lastParen = curName.lastIndexOf("`");\r
-                    String evalExpr = curName.trim().substring(1, lastParen);\r
-                    SvcLogicExpression lhsExpr = SvcLogicExpressionFactory.parse(evalExpr);\r
-                    lhsVarName = SvcLogicExpressionResolver.evaluate(lhsExpr, node, ctx);\r
-                } else {\r
+                //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);
-                }\r
+                }
                        } catch (Exception e) {
                                LOG.warn("Caught exception trying to resolve variable name ("+curName+")", e);
                        }
index 0cfcfb9..593c972 100644 (file)
@@ -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);
 
index 6e85972..9debd6b 100644 (file)
 
 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
- * <code>DBResourceManager</code> Service. The priority for properties file
- * resolution is as follows:
- *
- * <ol>
- * <li>A directory identified by the system environment variable
- * <code>SDNC_CONFIG_DIR</code></li>
- * <li>The default directory <code>DEFAULT_DBLIB_PROP_DIR</code></li>
- * <li>A directory identified by the JRE argument
- * <code>dblib.properties</code></li>
- * <li>A <code>dblib.properties</code> file located in the karaf root
- * directory</li>
- * </ol>
- */
-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<PropertiesFileResolver> 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
-        * <code>Logger</code>.
-        *
-        * @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<File> 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:
-        * <ol>
-        * <li>A directory identified by the system environment variable
-        * <code>SDNC_CONFIG_DIR</code></li>
-        * <li>The default directory <code>DEFAULT_DBLIB_PROP_DIR</code></li>
-        * <li>A directory identified by the JRE argument
-        * <code>dblib.properties</code></li>
-        * <li>A <code>dblib.properties</code> file located in the karaf root
-        * directory</li>
-        * </ol>
-        */
-       File determinePropertiesFile(final SvcLogicPropertiesProvider resourceProvider) {
-
-               for (final PropertiesFileResolver sliPropertiesFileResolver : sliPropertiesFileResolvers) {
-                       final Optional<File> 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 (file)
index 0000000..a9992a0
--- /dev/null
@@ -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
+ * <code>DBResourceManager</code> Service. The priority for properties file
+ * resolution is as follows:
+ *
+ * <ol>
+ * <li>A directory identified by the system environment variable
+ * <code>SDNC_CONFIG_DIR</code></li>
+ * <li>The default directory <code>DEFAULT_DBLIB_PROP_DIR</code></li>
+ * <li>A directory identified by the JRE argument
+ * <code>dblib.properties</code></li>
+ * <li>A <code>dblib.properties</code> file located in the karaf root
+ * directory</li>
+ * </ol>
+ */
+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<PropertiesFileResolver> 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
+        * <code>Logger</code>.
+        *
+        * @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<File> 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:
+        * <ol>
+        * <li>A directory identified by the system environment variable
+        * <code>SDNC_CONFIG_DIR</code></li>
+        * <li>The default directory <code>DEFAULT_DBLIB_PROP_DIR</code></li>
+        * <li>A directory identified by the JRE argument
+        * <code>dblib.properties</code></li>
+        * <li>A <code>dblib.properties</code> file located in the karaf root
+        * directory</li>
+        * </ol>
+        */
+       File determinePropertiesFile(final SvcLogicPropertiesProviderImpl resourceProvider) {
+
+               for (final PropertiesFileResolver sliPropertiesFileResolver : sliPropertiesFileResolvers) {
+                       final Optional<File> fileOptional = sliPropertiesFileResolver.resolveFile(SVCLOGIC_PROP_FILE_NAME);
+                       if (fileOptional.isPresent()) {
+                               return reportSuccess(sliPropertiesFileResolver.getSuccessfulResolutionMessage(), fileOptional);
+                       }
+               }
+
+               return null;
+       }
+}
index 19d985d..3f24adf 100644 (file)
 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;
+
 }
index 53875b3..3bd896c 100644 (file)
@@ -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<String, SvcLogicNodeExecutor> 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<String, SvcLogicNodeExecutor> 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);
index fa3bbcf..592fb28 100644 (file)
@@ -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 {
 
 
index 148745f..a783df4 100644 (file)
@@ -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);
index 69ac613..b717aa9 100644 (file)
@@ -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");
old mode 100755 (executable)
new mode 100644 (file)
index 8290574..bb14477
@@ -3,7 +3,7 @@
            xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
            odl:use-default-for-reference-types="true">
 
-    <bean id="propProvider" class="org.onap.ccsdk.sli.core.sli.provider.SvcLogicPropertiesProvider" />
+    <bean id="propProvider" class="org.onap.ccsdk.sli.core.sli.provider.SvcLogicPropertiesProviderImpl" />
     <reference id="dblibService" interface="org.onap.ccsdk.sli.core.dblib.DbLibService" />
 
     <bean id="svcLogicService" class="org.onap.ccsdk.sli.core.sli.provider.SvcLogicServiceImpl">
index eccbfc9..33ce6f6 100644 (file)
@@ -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());
     }
 
index 18f044b..5e627cd 100644 (file)
@@ -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);