This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-108
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-108 by this push:
new 1b93bb1 WIP.
1b93bb1 is described below
commit 1b93bb13c1c1852f6255581d460c9732c06339d7
Author: Aaron Radzinski <[email protected]>
AuthorDate: Mon Oct 5 01:33:24 2020 -0700
WIP.
---
.../nlpcraft/common/ansi/NCAnsiProgressBar.scala | 4 +--
.../common/nlp/core/NCNlpCoreManager.scala | 2 --
.../org/apache/nlpcraft/common/util/NCUtils.scala | 2 ++
.../nlpcraft/model/tools/cmdline/NCCli.scala | 41 ++++++++++++++++------
.../model/tools/cmdline/NCCliServerBeacon.scala | 5 ++-
.../org/apache/nlpcraft/server/NCServer.scala | 5 +--
.../server/nlp/core/NCNlpServerManager.scala | 2 --
7 files changed, 41 insertions(+), 20 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/ansi/NCAnsiProgressBar.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/ansi/NCAnsiProgressBar.scala
index 3b5f746..a1e0e05 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/ansi/NCAnsiProgressBar.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/ansi/NCAnsiProgressBar.scala
@@ -83,7 +83,7 @@ class NCAnsiProgressBar(
if (useAnsi) {
clean()
- val bar = Math.round((tick.toFloat / totalTicks.toFloat) *
dispSize)
+ val bar = if (tick == 1) 1 else Math.round((tick.toFloat /
totalTicks.toFloat) * dispSize)
out.print(PB_LEFT)
for (i ← 0 until dispSize)
@@ -91,7 +91,7 @@ class NCAnsiProgressBar(
out.print(PB_RIGHT)
out.flush()
}
- else if (tick % (totalTicks / dispSize) == 0) {
+ else if (tick == 1 || tick % (totalTicks / dispSize) == 0) {
out.print(NON_ANSI_CHAR)
out.flush()
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/core/NCNlpCoreManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/core/NCNlpCoreManager.scala
index 2bb5710..446fa0d 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/core/NCNlpCoreManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/core/NCNlpCoreManager.scala
@@ -53,8 +53,6 @@ object NCNlpCoreManager extends NCService {
addTags(span, "nlpEngine" → Config.engine)
- logger.info(s"NLP engine configured: ${Config.engine}")
-
val factory: NCNlpTokenizerFactory =
Config.engine match {
case "stanford" ⇒
U.mkObject("org.apache.nlpcraft.common.nlp.core.stanford.NCStanfordTokenizerFactory")
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 1742da9..df80d9a 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
@@ -75,6 +75,8 @@ object NCUtils extends LazyLogging {
final val NL = System getProperty "line.separator"
+ final val LOG_MARKER = "d[-_-]b"
+
private val idGen = new NCIdGenerator(NCBlowfishHasher.salt(), 8)
private lazy val ANSI_FG_COLORS = Seq(
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
index 7f79bc1..7a717e7 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
@@ -65,12 +65,12 @@ object NCCli extends App {
//noinspection RegExpRedundantEscape\
private final val TAILER_PTRN = Pattern.compile("^.*NC[a-zA-Z0-9]+ started
\\[[\\d]+ms\\]$")
- // Number of server services that need to be started.
+ // Number of server services that need to be started + 1 for log marker.
// Used for progress bar functionality.
// +==================================================================+
// | MAKE SURE TO UPDATE THIS VAR WHEN NUMBER OF SERVICES IS CHANGED. |
// +==================================================================+
- private final val NUM_SRV_SERVICES = 30
+ private final val NUM_SRV_SERVICES = 30/*services*/ + 1/*log marker*/
private final val SRV_BEACON_PATH = ".nlpcraft/server_beacon"
private final val HIST_PATH = ".nlpcraft/.cli_history"
@@ -96,6 +96,7 @@ object NCCli extends App {
private val gson = new GsonBuilder().setPrettyPrinting().create
case class SplitError(index: Int) extends Exception
+ case class NoLocalServer() extends IllegalStateException(s"Cannot detect
locally running REST server.")
case class ReplState(
var isServerOnline: Boolean = false,
@@ -553,7 +554,7 @@ object NCCli extends App {
// Ensure that there isn't another local server running.
loadServerBeacon() match {
- case Some(b) ⇒ throw new IllegalStateException(s"Existing local
server (pid ${c(b.pid)}) detected.")
+ case Some(b) ⇒ throw new IllegalStateException(s"Existing server
(pid ${c(b.pid)}) detected.")
case None ⇒ ()
}
@@ -659,9 +660,10 @@ object NCCli extends App {
Tailer.create(
replState.serverOutput.get,
new TailerListenerAdapter {
- override def handle(line: String): Unit =
- if (TAILER_PTRN.matcher(line).matches())
+ override def handle(line: String): Unit = {
+ if (line.endsWith(U.LOG_MARKER) ||
TAILER_PTRN.matcher(line).matches())
progressBar.ticked()
+ }
},
500.ms
)
@@ -713,7 +715,7 @@ object NCCli extends App {
private def getRestEndpointFromBeacon: String =
loadServerBeacon() match {
case Some(beacon) ⇒ s"http://${beacon.restEndpoint}"
- case None ⇒ throw new IllegalStateException(s"Cannot detect
locally running REST server.")
+ case None ⇒ throw NoLocalServer()
}
/**
@@ -722,7 +724,10 @@ object NCCli extends App {
* @param repl Whether or not executing from REPL.
*/
private def cmdLessServer(cmd: Command, args: Seq[Argument], repl:
Boolean): Unit = {
-
+ loadServerBeacon() match {
+ case Some(beacon) ⇒ System.out.println(s"Log path:
${beacon.logPath}")
+ case None ⇒ throw NoLocalServer()
+ }
}
/**
@@ -815,6 +820,22 @@ object NCCli extends App {
case Some(ph) ⇒
beacon.ph = ph
+ val files = new File(SystemUtils.getUserHome,
".nlpcraft").listFiles(new FilenameFilter {
+ override def accept(dir: File, name: String): Boolean =
+ name.startsWith(s".pid_$ph")
+ })
+
+ if (files.size == 1) {
+ val split = files(0).getName.split("_")
+
+ if (split.size == 2) {
+ val logFile = new File(SystemUtils.getUserHome,
s".nlpcraft/server_log_${split(2)}.txt")
+
+ if (logFile.exists())
+ beacon.logPath = logFile.getAbsolutePath
+ }
+ }
+
Some(beacon)
case None ⇒
// Attempt to clean up stale beacon file.
@@ -871,8 +892,7 @@ object NCCli extends App {
} else
error(s"Failed to stop the local REST server (pid
${c(pid)}).")
- case None ⇒
- error("Cannot detect locally running REST server.")
+ case None ⇒ throw NoLocalServer()
}
}
@@ -1043,7 +1063,6 @@ object NCCli extends App {
tbl += ("Token providers", s"${g(beacon.tokenProviders)}")
tbl += ("NLP engine", s"${g(beacon.nlpEngine)}")
tbl += ("External config URL", s"${g(beacon.extConfigUrl)}")
- tbl += ("Beacon file path", s"${g(beacon.filePath)}")
tbl += ("Started on", s"${g(DateFormat.getDateTimeInstance.format(new
Date(beacon.startMs)))}")
tbl
@@ -1058,7 +1077,7 @@ object NCCli extends App {
private def cmdGetServer(cmd: Command, args: Seq[Argument], repl:
Boolean): Unit = {
loadServerBeacon() match {
case Some(beacon) ⇒ logln(s"Local REST
server:\n${mkServerBeaconTable(beacon).toString}")
- case None ⇒ error(s"Cannot detect local REST server.")
+ case None ⇒ throw NoLocalServer()
}
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliServerBeacon.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliServerBeacon.scala
index 2847318..2f6bd77 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliServerBeacon.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliServerBeacon.scala
@@ -34,6 +34,8 @@ package org.apache.nlpcraft.model.tools.cmdline
* @param nlpEngine
* @param tokenProviders
* @param extConfigUrl
+ * @param beaconPath
+ * @param logPath
* @param ph
*/
case class NCCliServerBeacon(
@@ -52,7 +54,8 @@ case class NCCliServerBeacon(
nlpEngine: String,
tokenProviders: String,
extConfigUrl: String,
- filePath: String,
+ beaconPath: String,
+ @transient var logPath: String = null,
@transient var ph: ProcessHandle = null
)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala
index 5709e5f..abfdd33 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala
@@ -275,7 +275,7 @@ object NCServer extends App with NCIgniteInstance with
LazyLogging with NCOpenCe
tokenProviders = Config.tokProviders,
nlpEngine = Config.nlpEngine,
extConfigUrl = Config.extCfgUrl,
- filePath = path.getAbsolutePath,
+ beaconPath = path.getAbsolutePath,
startMs = currentTime
))
stream.flush()
@@ -300,7 +300,6 @@ object NCServer extends App with NCIgniteInstance with
LazyLogging with NCOpenCe
tbl += (s"${b("Token providers")}", Config.tokProviders)
tbl += (s"${b("NLP engine")}", Config.nlpEngine)
tbl += (s"${b("External config URL")}", Config.extCfgUrl)
- tbl += (s"${b("Beacon file path")}", path.getAbsolutePath)
logger.info(s"Sever configuration:\n$tbl")
}
@@ -335,6 +334,8 @@ object NCServer extends App with NCIgniteInstance with
LazyLogging with NCOpenCe
save()
}
+ logger.info(U.LOG_MARKER)
+
NCIgniteRunner.runWith(
args.find(_.startsWith("-igniteConfig=")) match {
case None ⇒ null // Will use default on the classpath 'ignite.xml'.
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 2552434..fb12deb 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
@@ -117,8 +117,6 @@ object NCNlpServerManager extends NCService {
// These component can be started independently.
U.executeParallel(ners.values.map(ner ⇒ () ⇒ ner.start()).toSeq: _*)
- logger.info(s"Enabled built-in NERs:
${Config.tokenProviders.mkString(", ")}")
-
ackStarted()
}