You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2020/12/15 02:12:45 UTC

[incubator-nlpcraft] branch master updated: WIP.

This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/master by this push:
     new b94b2f5  WIP.
b94b2f5 is described below

commit b94b2f5454d3f941207cdac79fb335e6a67fc5ae
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Mon Dec 14 18:12:34 2020 -0800

    WIP.
---
 .../model/tools/embedded/NCEmbeddedProbe.java      | 41 +++++++++++++++++-----
 .../model/tools/test/NCTestAutoModelValidator.java |  5 +--
 .../test/impl/NCTestAutoModelValidatorImpl.scala   | 40 +++++++++++++++++++--
 .../org/apache/nlpcraft/probe/NCProbeBoot.scala    | 41 +++++++++++++++++++---
 4 files changed, 109 insertions(+), 18 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/embedded/NCEmbeddedProbe.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/embedded/NCEmbeddedProbe.java
index 56e81ad..1017bc0 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/embedded/NCEmbeddedProbe.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/embedded/NCEmbeddedProbe.java
@@ -96,6 +96,7 @@ public class NCEmbeddedProbe {
      * @param cfgFile Configuration file path. It should be either a full path or the file name
      *      that can be found in the current working directory or on the classpath as a class loader
      *      resource.
+     * @throws NCException Thrown in case of any errors starting the data probe.
      * @return Whether or not probe started ok.
      */
     public static boolean start(String cfgFile) {
@@ -107,10 +108,32 @@ public class NCEmbeddedProbe {
     }
 
     /**
+     * Start the embedded probe with given configuration file and models overrides. It is equivalent to starting
+     * a probe using <code>-config=cfgFile</code> command line argument.
+     *
+     * @param cfgFile Configuration file path. It should be either a full path or the file name
+     *      that can be found in the current working directory or on the classpath as a class loader
+     *      resource.
+     * @param mdlClasses One or more data model classes to be deployed by the embedded probe. These will
+     *      override {@code nlpcraft.probe.models} configuration property in the provided configuration file.
+     * @throws NCException Thrown in case of any errors starting the data probe.
+     * @return Whether or not probe started ok.
+     */
+    @SafeVarargs
+    public static boolean start(String cfgFile, Class<? extends NCModel>... mdlClasses) {
+        CompletableFuture<Integer> fut = new CompletableFuture<>();
+
+        NCProbeBoot$.MODULE$.start(cfgFile, mdlClasses, fut);
+
+        return waitForFuture(fut);
+    }
+
+    /**
      * Starts the embedded probe with default configuration and specified models to deploy.
-     * 
-     * @param mdlClasses One or more data model classes to be deployed by the embedded probe.
-     * @throws NCException Thrown if given list of models is empty.
+     *
+     * @param mdlClasses One or more data model classes to be deployed by the embedded probe. These will
+     *      override {@code nlpcraft.probe.models} configuration property in the default configuration file.
+     * @throws NCException Thrown in case of any errors starting the data probe.
      * @return  Whether or not probe started ok.
      */
     @SafeVarargs
@@ -127,12 +150,12 @@ public class NCEmbeddedProbe {
     /**
      * Starts the embedded probe with default configuration and specified overrides.
      *
-     * @param probeId Probe ID.
-     * @param tok Probe token.
-     * @param upLink Probe up-link to the server.
-     * @param dnLink Probe down-link from the server.
-     * @param mdlClasses One or more data model classes to be deployed by the embedded probe.
-     * @throws NCException Thrown if given list of models is empty.
+     * @param probeId Probe ID override.
+     * @param tok Probe token override.
+     * @param upLink Probe up-link to the server override.
+     * @param dnLink Probe down-link from the server override.
+     * @param mdlClasses One or more data model classes overrides to be deployed by the embedded probe.
+     * @throws NCException Thrown in case of any errors starting the data probe.
      * @return  Whether or not probe started ok.
      */
     @SafeVarargs
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestAutoModelValidator.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestAutoModelValidator.java
index 977a515..3b0386c 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestAutoModelValidator.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestAutoModelValidator.java
@@ -19,6 +19,7 @@ package org.apache.nlpcraft.model.tools.test;
 
 import org.apache.nlpcraft.model.*;
 import org.apache.nlpcraft.model.tools.test.impl.*;
+
 import java.util.*;
 
 /**
@@ -71,7 +72,7 @@ public class NCTestAutoModelValidator {
      *      output will be printed out to the configured logger.
      */
     public static void main(String[] args) throws Exception {
-        System.exit(NCTestAutoModelValidatorImpl.isValid() ? 0 : 1);
+        System.exit(NCTestAutoModelValidatorImpl.isValid(args) ? 0 : 1);
     }
 
     /**
@@ -86,7 +87,7 @@ public class NCTestAutoModelValidator {
      *      output will be printed out to the configured logger (e.g. log4j), if any.
      */
     public static boolean isValid() throws Exception {
-        return NCTestAutoModelValidatorImpl.isValid();
+        return NCTestAutoModelValidatorImpl.isValid(new String[] {});
     }
 
     /**
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/impl/NCTestAutoModelValidatorImpl.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/impl/NCTestAutoModelValidatorImpl.scala
index 97a1ed3..88c686e 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/impl/NCTestAutoModelValidatorImpl.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/impl/NCTestAutoModelValidatorImpl.scala
@@ -31,26 +31,62 @@ import org.apache.nlpcraft.probe.mgrs.model.NCModelManager
 private [test] object NCTestAutoModelValidatorImpl extends LazyLogging {
     private final val PROP_MODELS = "NLPCRAFT_TEST_MODELS"
 
+    /**
+     *
+     * @param args
+     * @throws Exception Thrown in case of any errors.
+     * @return
+     */
     @throws[Exception]
-    def isValid: Boolean =
+    def isValid(args: Array[String]): Boolean =
         U.sysEnv(PROP_MODELS) match {
             case Some(p) ⇒ isValid(getClasses(p.split(",")))
             case None ⇒ throw new IllegalStateException(s"System property '$PROP_MODELS' is not defined.")
         }
 
+    /**
+     *
+     * @param claxx
+     * @throws Exception Thrown in case of any errors.
+     * @return
+     */
     @throws[Exception]
     def isValidForClass(claxx: Class[_ <: NCModel]): Boolean = isValid(Seq(claxx))
 
+    /**
+     *
+     * @param mdlIds
+     * @throws Exception Thrown in case of any errors.
+     * @return
+     */
     @throws[Exception]
     def isValidForModelIds(mdlIds: String): Boolean = isValid(getClasses(mdlIds.split(",")))
-    
+
+    /**
+     *
+     * @param mdlIds
+     * @throws Exception Thrown in case of any errors.
+     * @return
+     */
     @throws[Exception]
     def isValidForModelIds(mdlIds: java.util.Collection[String]): Boolean =
         isValid(getClasses(mdlIds.toArray().asInstanceOf[Array[String]]))
 
+    /**
+     *
+     * @param mdlIds
+     * @throws Exception Thrown in case of any errors.
+     * @return
+     */
     @throws[Exception]
     def isValidForModelIds(mdlIds: Array[String]): Boolean = isValid(getClasses(mdlIds))
 
+    /**
+     *
+     * @param classes
+     * @throws Exception Thrown in case of any errors.
+     * @return
+     */
     @throws[Exception]
     private def isValid(classes: Seq[Class[_ <: NCModel]]): Boolean = {
         if (NCEmbeddedProbe.start(classes: _*))
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
index 3aab814..85c7d67 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
@@ -315,7 +315,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
     
     /**
       *
-      * @param cfgFile
+      * @param cfgFile Configuration file to use.
       * @param fut
       */
     private [probe] def start(cfgFile: String, fut: CompletableFuture[Integer]): Unit = {
@@ -329,11 +329,14 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
     }
     
     /**
-      *
-      * @param mdlClasses
+      * Starts the embedded probe with given configuration file and provided overrides.
+     *
+      * @param cfgFile Configuration file to use.
+      * @param mdlClasses Overrides for 'nlpcraft.probe.models' configuration property.
       * @param fut
       */
     private [probe] def start(
+        cfgFile: String,
         mdlClasses: Array[java.lang.Class[_ <: NCModel]],
         fut: CompletableFuture[Integer]): Unit = {
         checkStarted()
@@ -341,7 +344,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
         import ConfigValueFactory._
     
         val cfg = initializeConfig(
-            Array.empty,
+            Array(s"-config=$cfgFile"),
             Some(
                 ConfigFactory.empty().withValue(
                     "nlpcraft.probe.models",
@@ -354,7 +357,35 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
             override def run(): Unit = start0(cfg, fut)
         }.start()
     }
-    
+
+    /**
+     * Starts the embedded probe with the default configuration.
+     *
+     * @param mdlClasses Overrides for 'nlpcraft.probe.models' configuration property.
+     * @param fut
+     */
+    private [probe] def start(
+        mdlClasses: Array[java.lang.Class[_ <: NCModel]],
+        fut: CompletableFuture[Integer]): Unit = {
+        checkStarted()
+
+        import ConfigValueFactory._
+
+        val cfg = initializeConfig(
+            Array.empty,
+            Some(
+                ConfigFactory.empty().withValue(
+                    "nlpcraft.probe.models",
+                    fromAnyRef(mdlClasses.map(_.getName).mkString(","))
+                )
+            )
+        )
+
+        new Thread() {
+            override def run(): Unit = start0(cfg, fut)
+        }.start()
+    }
+
     /**
       * 
       * @param probeId Probe ID.