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/09/12 20:14:59 UTC

[incubator-nlpcraft] branch NLPCRAFT-41 updated (59e8f71 -> bf46b0e)

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

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


    from 59e8f71  WIP.
     new 4ab4d49  WIP.
     new 5a84b1e  Merge branch 'NLPCRAFT-41' of https://github.com/apache/incubator-nlpcraft into NLPCRAFT-41
     new bf46b0e  WIP.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../nlpcraft/common/config/NCConfigurable.scala    | 40 ++++++++----------
 .../org/apache/nlpcraft/common/util/NCUtils.scala  | 23 ++++++-----
 .../model/tools/embedded/NCEmbeddedProbe.java      | 28 +++++++------
 .../scala/org/apache/nlpcraft/probe/NCProbe.scala  | 13 +++++-
 .../org/apache/nlpcraft/probe/NCProbeBoot.scala    | 40 +++++++-----------
 .../probe/mgrs/conn/NCConnectionManager.scala      | 11 ++---
 .../mgrs/conversation/NCConversationManager.scala  |  2 +-
 .../mgrs/dialogflow/NCDialogFlowManager.scala      |  4 +-
 .../probe/mgrs/nlp/NCProbeEnrichmentManager.scala  | 23 +++++++----
 .../lifecycle/NCServerLifecycleManager.scala       |  9 +----
 .../server/nlp/core/NCNlpServerManager.scala       |  5 ++-
 .../nlpcraft/server/probe/NCProbeManager.scala     | 47 +++++++++++++---------
 .../nlpcraft/server/rest/NCRestManager.scala       | 13 ++++--
 .../org/apache/nlpcraft/server/sql/NCSql.scala     | 11 +++--
 .../nlpcraft/server/user/NCUserManager.scala       | 15 +++++--
 15 files changed, 160 insertions(+), 124 deletions(-)


[incubator-nlpcraft] 01/03: WIP.

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4ab4d4952be6c38c5a19b3f500a62d7df2e9dda9
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sat Sep 12 12:41:10 2020 -0700

    WIP.
---
 .../nlpcraft/common/config/NCConfigurable.scala    | 40 +++++++++-------------
 .../org/apache/nlpcraft/probe/NCProbeBoot.scala    | 17 +++------
 .../mgrs/conversation/NCConversationManager.scala  |  4 +--
 .../mgrs/dialogflow/NCDialogFlowManager.scala      |  4 +--
 .../probe/mgrs/nlp/NCProbeEnrichmentManager.scala  |  5 ++-
 .../lifecycle/NCServerLifecycleManager.scala       |  9 ++---
 .../server/nlp/core/NCNlpServerManager.scala       |  5 ++-
 .../nlpcraft/server/probe/NCProbeManager.scala     | 33 ++++++++++++++----
 .../nlpcraft/server/rest/NCRestManager.scala       | 13 +++++--
 .../org/apache/nlpcraft/server/sql/NCSql.scala     | 11 +++---
 .../nlpcraft/server/user/NCUserManager.scala       | 15 ++++++--
 11 files changed, 91 insertions(+), 65 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/config/NCConfigurable.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/config/NCConfigurable.scala
index 7770202..934d9ae 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/config/NCConfigurable.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/config/NCConfigurable.scala
@@ -20,7 +20,6 @@ package org.apache.nlpcraft.common.config
 import com.typesafe.config.{Config, ConfigFactory}
 import com.typesafe.scalalogging.LazyLogging
 import org.apache.nlpcraft.common.NCE
-import org.slf4j.LoggerFactory
 
 import scala.collection.JavaConverters._
 
@@ -39,7 +38,7 @@ trait NCConfigurable {
       */
     private def checkMandatory(name: String): Unit =
         if (!hocon.hasPath(name))
-            abortWith(s"Mandatory configuration property '$name' not found.")
+            throw new NCE(s"Mandatory configuration property not found: $name")
     
     /**
       * Gets mandatory configuration property.
@@ -125,15 +124,19 @@ trait NCConfigurable {
         val i = ep.indexOf(':')
     
         if (i <= 0)
-            abortWith(s"Invalid 'host:port' endpoint format: $ep")
+            throw new NCE(s"Invalid 'host:port' endpoint configuration property format [" +
+                s"name=$name, " +
+                s"endpoint=$ep" +
+            s"]")
             
         try
             ep.substring(0, i) → ep.substring(i + 1).toInt
         catch {
             case _: NumberFormatException ⇒
-                abortWith(s"Invalid 'host:port' endpoint port: $ep")
-                
-                throw new AssertionError()
+                throw new NCE(s"Invalid 'host:port' endpoint configuration property port [" +
+                    s"name=$name, " +
+                    s"endpoint=$ep" +
+                s"]")
         }
     }
     
@@ -180,9 +183,10 @@ trait NCConfigurable {
             f(v)
         catch {
             case _: Exception ⇒
-                abortWith(s"Configuration property '$name' cannot be extracted from value '$v'")
-    
-                throw new AssertionError()
+                throw new NCE(s"Configuration property cannot be extracted [" +
+                    s"name=$name, " +
+                    s"value='$v'" +
+                s"]")
         }
     }
     
@@ -198,9 +202,9 @@ trait NCConfigurable {
             hocon.getAnyRef(name).asInstanceOf[java.util.Map[K, V]].asScala.toMap
         catch {
             case e: ClassCastException ⇒
-                abortWith(s"Configuration property '$name' has unexpected type.", e.getMessage)
-    
-                throw new AssertionError()
+                throw new NCE(s"Configuration property has unexpected type (expecting 'java.util.Map') [" +
+                    s"name=$name" +
+                s"]", e)
         }
     }
     
@@ -247,18 +251,6 @@ trait NCConfigurable {
     def getStringListOpt(name: String): Option[Seq[String]] =
         if (!hocon.hasPath(name)) None else Some(hocon.getStringList(name).asScala)
 
-    /**
-      *
-      * @param errMsgs Optional error messages.
-      */
-    def abortWith(errMsgs: String*): Unit = {
-        val logger = LoggerFactory.getLogger(getClass)
-
-        errMsgs.foreach(s ⇒ logger.error(s))
-
-        // Abort immediately.
-        System.exit(1)
-    }
 }
 
 object NCConfigurable extends LazyLogging {
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 000caed..63ed84f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
@@ -171,17 +171,10 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
         
         catching(classOf[Throwable]) either startManagers(cfg) match {
             case Left(e) ⇒ // Exception.
-                e match {
-                    case x: NCException ⇒
-                        logger.error(s"Failed to start probe.", x)
+                logger.error("Failed to start probe.", e)
 
-                        stopManagers()
+                stop0()
 
-                        logger.info("Managers stopped.")
-
-                    case x: Throwable ⇒ logger.error("Failed to start probe due to unexpected error.", x)
-                }
-                
                 fut.complete(null)
             
             case _ ⇒ // Managers started OK.
@@ -206,7 +199,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
                     }
         }
     
-        logger.info("Embedded probe thread stopped OK.")
+        logger.trace("Probe thread stopped OK.")
     }
     
     /**
@@ -227,7 +220,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
             probeThread.join()
         }
         
-        logger.info("Embedded probe shutdown OK.")
+        logger.info("Probe shutdown OK.")
     }
     
     /**
@@ -235,7 +228,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
       */
     private def checkStarted(): Unit = 
         if (started)
-            throw new NCException(s"Embedded probe has already been started (only one probe per JVM is allowed).")
+            throw new NCException(s"Probe has already been started (only one probe per JVM is allowed).")
     
     /**
       *
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conversation/NCConversationManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conversation/NCConversationManager.scala
index d0ee41b..72f8402 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conversation/NCConversationManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conversation/NCConversationManager.scala
@@ -35,13 +35,13 @@ object NCConversationManager extends NCService {
     case class Value(conv: NCConversation, var tstamp: Long = 0)
 
     private object Config extends NCConfigurable {
-        private final val name = "nlpcraft.probe.convGcTimeoutMs"
+        private final val name = "nlpcraft.probe.convGcTimeoutMs1"
 
         def timeoutMs: Long = getInt(name)
 
         def check(): Unit =
             if (timeoutMs <= 0)
-                abortWith(s"Configuration property '$name' must be >= 0.")
+                throw new NCE(s"Configuration property must be >= 0 [name=$name]")
     }
 
     Config.check()
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/dialogflow/NCDialogFlowManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/dialogflow/NCDialogFlowManager.scala
index fa29fc2..eced14b 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/dialogflow/NCDialogFlowManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/dialogflow/NCDialogFlowManager.scala
@@ -41,7 +41,7 @@ object NCDialogFlowManager extends NCService {
 
         def check(): Unit =
             if (timeoutMs <= 0)
-                abortWith(s"Configuration property '$name' must be >= 0.")
+                throw new NCE(s"Configuration property must be >= 0 [name=$name]")
     }
 
     Config.check()
@@ -84,7 +84,7 @@ object NCDialogFlowManager extends NCService {
                 )
             }
 
-            logger.trace(s"Added to dialog flow [intId=$intId, userId=$usrId, mdlId=$mdlId]")
+            logger.trace(s"Added to dialog flow [mdlId=$mdlId, intId=$intId, userId=$usrId]")
         }
     }
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
index 21c7145..36d7d8d 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
@@ -76,7 +76,10 @@ object NCProbeEnrichmentManager extends NCService with NCOpenCensusModelStats {
 
         def check(): Unit =
             if (resultMaxSize <= 0)
-                abortWith(s"Value of '$pre.resultMaxSizeBytes' must be positive")
+                throw new NCE(s"Configuration property value must be > 0 [" +
+                    s"name=$pre.resultMaxSizeBytes, " +
+                    s"value=$resultMaxSize" +
+                s"]")
     }
 
     Config.check()
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/lifecycle/NCServerLifecycleManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/lifecycle/NCServerLifecycleManager.scala
index 3f3b3f1..49f1c0a 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/lifecycle/NCServerLifecycleManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/lifecycle/NCServerLifecycleManager.scala
@@ -37,14 +37,9 @@ object NCServerLifecycleManager extends NCService {
           */
         def loadAndCheck(): Unit = {
             if (classes.distinct.size != classes.size)
-                abortWith(s"Configuration property '$prop' cannot have duplicates.")
+                throw new NCE(s"Configuration property cannot have duplicates [name=$prop]")
             
-            try
-                objects = classes.map(U.mkObject(_).asInstanceOf[NCServerLifecycle])
-            catch {
-                case e: NCE ⇒ abortWith(e.getMessage, e.getCause.getMessage)
-                case e: Throwable ⇒ abortWith(e.getMessage)
-            }
+            objects = classes.map(U.mkObject(_).asInstanceOf[NCServerLifecycle])
         }
     }
     
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/NCNlpServerManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/NCNlpServerManager.scala
index 589e64c..d656342 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/NCNlpServerManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/core/NCNlpServerManager.scala
@@ -46,7 +46,10 @@ object NCNlpServerManager extends NCService {
             val unsupported = tokenProviders.filter(t ⇒ !TOKEN_PROVIDERS.contains(t))
 
             if (unsupported.nonEmpty)
-                abortWith(s"Configuration '$prop' contains unsupported providers: ${unsupported.mkString(",")}")
+                throw new NCE(s"Configuration property contains unsupported token providers [" +
+                    s"name=$prop, " +
+                    s"unsupported=${unsupported.mkString(", ")}" +
+                s"]")
         }
     }
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
index fe4dadc..e17ac84 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
@@ -76,18 +76,39 @@ object NCProbeManager extends NCService {
             val (_, dnPort) =  getDnHostPort
             val (_, upPort) =  getUpHostPort
 
+            val msg1 = "Configuration property must be >= 0 and <= 65535"
+            val msg2 = "Configuration property must be > 0"
+
             if (!(dnPort >= 0 && dnPort <= 65535))
-                abortWith(s"Configuration property '$pre.links.upLink' must be >= 0 and <= 65535: $dnPort")
+                throw new NCE(s"$msg1 [" +
+                    s"name=$pre.links.upLink, " +
+                    s"value=$dnPort" +
+                s"]")
             if (!(upPort >= 0 && upPort <= 65535))
-                abortWith(s"Configuration property '$pre.links.downLink' must be >= 0 and <= 65535: $upPort")
+                throw new NCE(s"$msg1 [" +
+                    s"name=$pre.links.downLink, " +
+                    s"value=$upPort" +
+                s"]")
             if (reconnectTimeoutMs <= 0)
-                abortWith(s"Configuration property '$pre.reconnectTimeoutMs' must be > 0: $reconnectTimeoutMs")
+                throw new NCE(s"$msg2 [" +
+                    s"name=$pre.reconnectTimeoutMs, " +
+                    s"value=$reconnectTimeoutMs" +
+                s"]")
             if (poolSize <= 0)
-                abortWith(s"Configuration property '$pre.poolSize' must be > 0: $poolSize")
+                throw new NCE(s"$msg2 [" +
+                    s"name=$pre.poolSize, " +
+                    s"value=$poolSize" +
+                s"]")
             if (soTimeoutMs <= 0)
-                abortWith(s"Configuration property '$pre.soTimeoutMs' must be > 0: $soTimeoutMs")
+                throw new NCE(s"$msg2 [" +
+                    s"name=$pre.soTimeoutMs, " +
+                    s"value=$soTimeoutMs" +
+                s"]")
             if (pingTimeoutMs <= 0)
-                abortWith(s"Configuration property '$pre.pingTimeoutMs' timeout must be > 0: $pingTimeoutMs")
+                throw new NCE(s"$msg2 [" +
+                    s"name=$pre.pingTimeoutMs, " +
+                    s"value=$pingTimeoutMs" +
+                s"]")
         }
     }
     
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestManager.scala
index 640fd6f..08e8432 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestManager.scala
@@ -50,11 +50,18 @@ object NCRestManager extends NCService {
           */
         def check(): Unit = {
             if (!(port > 0 && port < 65535))
-                abortWith(s"Configuration property port '$pre.port' must be > 0 and < 65535: $port")
+                throw new NCE(s"Configuration property must be > 0 and < 65535 [" +
+                    s"name=$pre.port, " +
+                    s"value=$port" +
+                s"]")
             if (host == null)
-                abortWith(s"Configuration property port '$pre.host' must be specified.")
+                throw new NCE(s"Configuration property must be specified [" +
+                    s"name=$pre.host" +
+                s"]")
             if (apiImpl == null)
-                abortWith(s"Configuration property port '$pre.apiImpl' must be specified (use 'org.apache.nlpcraft.server.rest.NCBasicRestApi' as default).")
+                throw new NCE(s"Configuration property must be specified (use 'org.apache.nlpcraft.server.rest.NCBasicRestApi' as default) [" +
+                    s"name=$pre.apiImpl" +
+                s"]")
         }
     }
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sql/NCSql.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sql/NCSql.scala
index 9b4444b..a829002 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sql/NCSql.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sql/NCSql.scala
@@ -74,13 +74,16 @@ object NCSql extends LazyLogging {
           */
         def check(): Unit = {
             if (minPoolSize > maxPoolSize)
-                abortWith(s"Configuration property '$pre.c3p0.pool.minSize' ($minPoolSize) must be <= '$pre.c3p0.pool.maxSize' ($maxPoolSize).")
+                throw new NCE(s"Configuration property '$pre.c3p0.pool.minSize' ($minPoolSize) must be <= '$pre.c3p0.pool.maxSize' ($maxPoolSize).")
             if (minPoolSize > initPoolSize)
-                abortWith(s"Configuration property '$pre.c3p0.pool.minSize' ($minPoolSize) must be <= '$pre.c3p0.pool.initSize' ($initPoolSize).")
+                throw new NCE(s"Configuration property '$pre.c3p0.pool.minSize' ($minPoolSize) must be <= '$pre.c3p0.pool.initSize' ($initPoolSize).")
             if (initPoolSize > maxPoolSize)
-                abortWith(s"Configuration property '$pre.c3p0.pool.initSize' ($initPoolSize) must be <= '$pre.c3p0.pool.maxSize' ($maxPoolSize).")
+                throw new NCE(s"Configuration property '$pre.c3p0.pool.initSize' ($initPoolSize) must be <= '$pre.c3p0.pool.maxSize' ($maxPoolSize).")
             if (acqInc <= 0)
-                abortWith(s"Configuration property '$pre.c3p0.pool.acquireIncrement' must be > 0: $acqInc")
+                throw new NCE(s"Configuration property must be > 0 [" +
+                    s"name=$pre.c3p0.pool.acquireIncrement, " +
+                    s"value=$acqInc" +
+                s"]")
         }
     }
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/user/NCUserManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/user/NCUserManager.scala
index 1f9da3a..758efe8 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/user/NCUserManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/user/NCUserManager.scala
@@ -75,11 +75,20 @@ object NCUserManager extends NCService with NCIgniteInstance {
           */
         def check(): Unit = {
             if (pwdPoolBlowup <= 1)
-                abortWith(s"Configuration parameter '$pre.pwdPoolBlowup' must be > 1")
+                throw new NCE(s"Configuration parameter must be > 1 [" +
+                    s"name=$pre.pwdPoolBlowup, " +
+                    s"value=$pwdPoolBlowup" +
+                s"]")
             if (timeoutScannerFreqMins <= 0)
-                abortWith(s"Configuration parameter '$pre.timeoutScannerFreqMins' must be > 0")
+                throw new NCE(s"Configuration parameter must be > 0 [" +
+                    s"name=$pre.timeoutScannerFreqMins, " +
+                    s"value=$timeoutScannerFreqMins" +
+                s"]")
             if (accessTokenExpireTimeoutMins <= 0)
-                abortWith(s"Configuration parameter '$pre.accessTokenExpireTimeoutMins' must be > 0")
+                throw new NCE(s"Configuration parameter must be > 0 [" +
+                    s"name=$pre.accessTokenExpireTimeoutMins, " +
+                    s"value=$accessTokenExpireTimeoutMins" +
+                s"]")
         }
     }
 


[incubator-nlpcraft] 03/03: WIP.

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit bf46b0e158a00c185834cb07614228f2c4d6aaef
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sat Sep 12 13:14:44 2020 -0700

    WIP.
---
 .../org/apache/nlpcraft/common/util/NCUtils.scala  | 23 +++++++++---------
 .../model/tools/embedded/NCEmbeddedProbe.java      | 28 ++++++++++++----------
 .../scala/org/apache/nlpcraft/probe/NCProbe.scala  | 13 +++++++++-
 .../org/apache/nlpcraft/probe/NCProbeBoot.scala    | 23 ++++++++----------
 .../probe/mgrs/conn/NCConnectionManager.scala      | 11 +++++----
 .../mgrs/conversation/NCConversationManager.scala  |  2 +-
 .../probe/mgrs/nlp/NCProbeEnrichmentManager.scala  | 18 +++++++++-----
 .../nlpcraft/server/probe/NCProbeManager.scala     | 14 ++---------
 8 files changed, 71 insertions(+), 61 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
index 508b491..bd4e102 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
@@ -1155,18 +1155,19 @@ object NCUtils extends LazyLogging {
       *
       * @param ess Executor services.
       */
-    def shutdownPools(ess: ExecutorService*): Unit = {
-        val seq = ess.filter(_ != null)
+    def shutdownPools(ess: ExecutorService*): Unit =
+        if (ess != null) {
+            val seq = ess.filter(_ != null)
 
-        seq.foreach(_.shutdown())
-        seq.foreach(es ⇒
-            try
-                es.awaitTermination(Long.MaxValue, TimeUnit.MILLISECONDS)
-            catch {
-                case _: InterruptedException ⇒ () // Safely ignore.
-            }
-        )
-    }
+            seq.foreach(_.shutdown())
+            seq.foreach(es ⇒
+                try
+                    es.awaitTermination(Long.MaxValue, TimeUnit.MILLISECONDS)
+                catch {
+                    case _: InterruptedException ⇒ () // Safely ignore.
+                }
+            )
+        }
 
     /**
       * Gets full path for given file name in user's home folder.
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 47c2428..9b206ea 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
@@ -70,13 +70,14 @@ import java.util.function.*;
  * </ul>
  */
 public class NCEmbeddedProbe {
-    private static void waitForFuture(CompletableFuture<?> fut) {
-        while (!fut.isDone()) {
+    private static int waitForFuture(CompletableFuture<Integer> fut) {
+        while (!fut.isDone())
             try {
                 fut.get();
             }
             catch (InterruptedException | ExecutionException ignored) {}
-        }
+
+        return -1;
     }
 
     /**
@@ -87,13 +88,14 @@ public class NCEmbeddedProbe {
      *      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 Exit code from the probe.
      */
-    public static void start(String cfgFile) {
-        CompletableFuture<Void> fut = new CompletableFuture<>();
+    public static int start(String cfgFile) {
+        CompletableFuture<Integer> fut = new CompletableFuture<>();
 
         NCProbeBoot$.MODULE$.start(cfgFile, fut);
 
-        waitForFuture(fut);
+        return waitForFuture(fut);
     }
 
     /**
@@ -110,16 +112,17 @@ public class NCEmbeddedProbe {
      * 
      * @param mdlClasses One or more data model classes to be deployed by the embedded probe.
      * @throws NCException Thrown in case of any errors starting the data probe.
+     * @return Exit code from the probe.
      */
     @SafeVarargs
-    public static void start(Class<? extends NCModel>... mdlClasses) {
+    public static int start(Class<? extends NCModel>... mdlClasses) {
         checkModelClasses(mdlClasses);
 
-        CompletableFuture<Void> fut = new CompletableFuture<>();
+        CompletableFuture<Integer> fut = new CompletableFuture<>();
 
         NCProbeBoot$.MODULE$.start(mdlClasses, fut);
 
-        waitForFuture(fut);
+        return waitForFuture(fut);
     }
 
     /**
@@ -131,9 +134,10 @@ public class NCEmbeddedProbe {
      * @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 in case of any errors starting the data probe.
+     * @return Exit code from the probe.
      */
     @SafeVarargs
-    public static void start(
+    public static int start(
         String probeId,
         String tok,
         String upLink,
@@ -141,11 +145,11 @@ public class NCEmbeddedProbe {
         Class<? extends NCModel>... mdlClasses) {
         checkModelClasses(mdlClasses);
 
-        CompletableFuture<Void> fut = new CompletableFuture<>();
+        CompletableFuture<Integer> fut = new CompletableFuture<>();
 
         NCProbeBoot$.MODULE$.start(probeId, tok, upLink, dnLink, mdlClasses, fut);
 
-        waitForFuture(fut);
+        return waitForFuture(fut);
     }
 
     /**
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbe.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbe.scala
index 21bbb5d..b790055 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbe.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbe.scala
@@ -19,9 +19,20 @@ package org.apache.nlpcraft.probe
 
 import java.util.concurrent.CompletableFuture
 
+import scala.util.control.Exception.ignoring
+
 /**
   * Data probe main app.
   */
 object NCProbe extends App {
-    NCProbeBoot.start(args, new CompletableFuture[Void])
+    val fut = new CompletableFuture[Integer]
+
+    NCProbeBoot.start(args, fut)
+
+    while (!fut.isDone)
+        ignoring(classOf[Exception]) {
+            fut.get();
+        }
+
+    System.exit(fut.get)
 }
\ No newline at end of file
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 63ed84f..9bff0d3 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
@@ -163,7 +163,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
       * @param cfg Probe configuration.
       * @param fut
       */
-    private def start0(cfg: ProbeConfig, fut: CompletableFuture[Void]): Unit = {
+    private def start0(cfg: ProbeConfig, fut: CompletableFuture[Integer]): Unit = {
         probeThread = Thread.currentThread()
         
         asciiLogo()
@@ -175,7 +175,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
 
                 stop0()
 
-                fut.complete(null)
+                fut.complete(1)
             
             case _ ⇒ // Managers started OK.
                 shutdownHook = new Thread() {
@@ -188,7 +188,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
 
                 started = true
                 
-                fut.complete(null)
+                fut.complete(0)
                 
                 // Wait indefinitely.
                 while (started)
@@ -214,12 +214,9 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
         }
         
         started = false
-        
-        if (probeThread != null) {
-            probeThread.interrupt()
-            probeThread.join()
-        }
-        
+
+        U.stopThread(probeThread)
+
         logger.info("Probe shutdown OK.")
     }
     
@@ -235,7 +232,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
       * @param cfgFile
       * @param fut
       */
-    private [probe] def start(cfgFile: String, fut: CompletableFuture[Void]): Unit = {
+    private [probe] def start(cfgFile: String, fut: CompletableFuture[Integer]): Unit = {
         checkStarted()
         
         val cfg = initializeConfig(Array(s"-config=$cfgFile"), None)
@@ -252,7 +249,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
       */
     private [probe] def start(
         mdlClasses: Array[java.lang.Class[_ <: NCModel]],
-        fut: CompletableFuture[Void]): Unit = {
+        fut: CompletableFuture[Integer]): Unit = {
         checkStarted()
     
         import ConfigValueFactory._
@@ -285,7 +282,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
         upLinkStr: String,
         dnLinkStr: String,
         mdlClasses: Array[java.lang.Class[_ <: NCModel]],
-        fut: CompletableFuture[Void]): Unit = {
+        fut: CompletableFuture[Integer]): Unit = {
         checkStarted()
     
         object Cfg extends NCConfigurable {
@@ -328,7 +325,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
       * @param args
       * @param fut
       */
-    private [probe] def start(args: Array[String], fut: CompletableFuture[Void]): Unit =
+    private [probe] def start(args: Array[String], fut: CompletableFuture[Integer]): Unit =
         start0(initializeConfig(args, None), fut)
     
     /**
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala
index bacfe76..b2f69dc 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala
@@ -341,7 +341,8 @@ object NCConnectionManager extends NCService {
                         if (cause != null)
                             logger.error(msg, cause)
                         else
-                            logger.info(msg)
+                            logger.error(msg)
+
                         caller.interrupt() // Interrupt current calling thread.
                 
                         exitLatch.countDown()
@@ -355,7 +356,7 @@ object NCConnectionManager extends NCService {
                             catch {
                                 case _: InterruptedIOException | _: InterruptedException ⇒ ()
                                 case _: EOFException ⇒ exit(t, s"Uplink REST server connection closed.")
-                                case e: Exception ⇒ exit(t, s"Uplink connection failed: ${e.getMessage}", e)
+                                case e: Exception ⇒ exit(t, s"Uplink connection failed: ${e.getMessage}")
                             }
                     }
                     
@@ -390,7 +391,7 @@ object NCConnectionManager extends NCService {
                             catch {
                                 case _: InterruptedIOException | _: InterruptedException ⇒ ()
                                 case _: EOFException ⇒ exit(t, s"Downlink REST server connection closed.")
-                                case e: Exception ⇒ exit(t, s"Downlink connection failed: ${e.getMessage}", e)
+                                case e: Exception ⇒ exit(t, s"Downlink connection failed: ${e.getMessage}")
                             }
                     }
             
@@ -411,12 +412,12 @@ object NCConnectionManager extends NCService {
                     closeAll()
                     
                     if (!isStopping) {
-                        logger.info(s"REST server connection closed (retrying in ${RETRY_TIMEOUT / 1000}s).")
+                        logger.warn(s"REST server connection closed (retrying in ${RETRY_TIMEOUT / 1000}s).")
                     
                         timeout()
                     }
                     else
-                        logger.info(s"REST server connection closed.")
+                        logger.warn(s"REST server connection closed.")
                 }
                 catch {
                     case e: HandshakeError ⇒
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conversation/NCConversationManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conversation/NCConversationManager.scala
index 72f8402..3479d5f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conversation/NCConversationManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conversation/NCConversationManager.scala
@@ -35,7 +35,7 @@ object NCConversationManager extends NCService {
     case class Value(conv: NCConversation, var tstamp: Long = 0)
 
     private object Config extends NCConfigurable {
-        private final val name = "nlpcraft.probe.convGcTimeoutMs1"
+        private final val name = "nlpcraft.probe.convGcTimeoutMs"
 
         def timeoutMs: Long = getInt(name)
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
index 806e922..0b52845 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
@@ -414,10 +414,11 @@ object NCProbeEnrichmentManager extends NCService with NCOpenCensusModelStats {
 
                             diffRedundant.foreach { case (del, similar) ⇒
                                 if (DEEP_DEBUG)
-                                    logger.trace(
-                                        s"Redundant note removed, because similar exists " +
-                                        s"[note=$del, similar=$similar, type=$typ]"
-                                    )
+                                    logger.trace(s"Redundant note removed, because similar exists [" +
+                                        s"note=$del, " +
+                                        s"similar=$similar, " +
+                                        s"type=$typ" +
+                                    s"]")
 
                                 nlpSen.removeNote(del)
                             }
@@ -444,10 +445,15 @@ object NCProbeEnrichmentManager extends NCService with NCOpenCensusModelStats {
                     if (continue) {
                         val changed = res.filter(!_._2).keys.map(_.getClass.getSimpleName).mkString(", ")
 
-                        logger.trace(s"Enrichment iteration finished - more needed [step=$step, changed=$changed]")
+                        logger.trace(s"Enrichment iteration finished - more needed [" +
+                            s"step=$step, " +
+                            s"changed=$changed" +
+                        s"]")
                     }
                     else
-                        logger.trace(s"Enrichment finished [step=$step]")
+                        logger.trace(s"Enrichment finished [" +
+                            s"step=$step" +
+                        s"]")
             }
 
             nlpSen.clone().collapse().
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
index e17ac84..5caede3 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
@@ -466,12 +466,12 @@ object NCProbeManager extends NCService {
                         case _: SocketTimeoutException | _: InterruptedException | _: InterruptedIOException ⇒ ()
                     
                         case _: EOFException ⇒
-                            logger.info(s"Probe closed downlink connection: $probeKey")
+                            logger.error(s"Probe closed downlink connection: $probeKey")
                         
                             t.interrupt()
                     
                         case e: Throwable ⇒
-                            logger.info(s"Error reading probe downlink socket (${e.getMessage}): $probeKey", e)
+                            logger.error(s"Error reading probe downlink socket (${e.getMessage}): $probeKey")
 
                             t.interrupt()
                     }
@@ -704,16 +704,6 @@ object NCProbeManager extends NCService {
         else {
             val typ = probeMsg.getType
 
-            def processPromise[T](promises: ConcurrentHashMap[String, Promise[T]], typ: java.lang.reflect.Type): Unit = {
-                val promise = promises.remove(probeMsg.data[String]("reqGuid"))
-
-                if (promise != null) {
-                    val r: T = GSON.fromJson(probeMsg.data[String]("resp"), typ)
-
-                    promise.success(r)
-                }
-            }
-
             typ match {
                 case "P2S_PING" ⇒ ()
 


[incubator-nlpcraft] 02/03: Merge branch 'NLPCRAFT-41' of https://github.com/apache/incubator-nlpcraft into NLPCRAFT-41

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5a84b1e95108d6fe47057766b5706bc0408bfdcd
Merge: 4ab4d49 59e8f71
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sat Sep 12 12:41:12 2020 -0700

    Merge branch 'NLPCRAFT-41' of https://github.com/apache/incubator-nlpcraft into NLPCRAFT-41

 .../apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)