Skip to content

Commit 6ee9a38

Browse files
committed
WIP.
1 parent b94b2f5 commit 6ee9a38

File tree

5 files changed

+38
-146
lines changed

5 files changed

+38
-146
lines changed

nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModelApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class TimeModelApp {
3232
*/
3333
public static void main(String[] args) throws Exception {
3434
// Start the data probe "in place" with 'TimeModel' model.
35-
if (NCEmbeddedProbe.start(TimeModel.class))
35+
if (NCEmbeddedProbe.start(null, TimeModel.class.getName()))
3636
Thread.currentThread().join();
3737
}
3838
}

nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/embedded/NCEmbeddedProbe.java

Lines changed: 15 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.nlpcraft.model.tools.embedded;
1919

2020
import org.apache.nlpcraft.common.*;
21-
import org.apache.nlpcraft.model.*;
2221
import org.apache.nlpcraft.model.tools.test.*;
2322
import org.apache.nlpcraft.probe.*;
2423
import org.apache.nlpcraft.probe.mgrs.nlp.*;
@@ -81,68 +80,22 @@ private static boolean waitForFuture(CompletableFuture<Integer> fut) {
8180
}
8281

8382
/**
83+
* Start the embedded probe with optional configuration file and models overrides.
8484
*
85-
* @param classes
86-
*/
87-
private static void checkModelClasses(Class<? extends NCModel>[] classes) {
88-
if (classes.length == 0)
89-
throw new NCException("At least one model class must be provided when starting embedded probe.");
90-
}
91-
92-
/**
93-
* Start the embedded probe with given configuration file. It is equivalent to starting a probe using
94-
* <code>-config=cfgFile</code> command line argument.
95-
*
96-
* @param cfgFile Configuration file path. It should be either a full path or the file name
85+
* @param cfgFile Optional configuration file path. It should be either a full path or the file name
9786
* that can be found in the current working directory or on the classpath as a class loader
98-
* resource.
87+
* resource. If provided - it is equivalent to starting a probe using <code>-config=cfgFile</code>
88+
* command line argument. If {@code null} - the probe will start with the default configuration.
89+
* @param mdlClasses Optional data model classes to be deployed by the embedded probe. If provided -
90+
* these will override {@code nlpcraft.probe.models} configuration property. If {@code null} - the models
91+
* defined in the configuration (default or provided via {@code cfgFile} parameter) will be used.
9992
* @throws NCException Thrown in case of any errors starting the data probe.
10093
* @return Whether or not probe started ok.
10194
*/
102-
public static boolean start(String cfgFile) {
95+
public static boolean start(String cfgFile, String... mdlClasses) {
10396
CompletableFuture<Integer> fut = new CompletableFuture<>();
10497

105-
NCProbeBoot$.MODULE$.start(cfgFile, fut);
106-
107-
return waitForFuture(fut);
108-
}
109-
110-
/**
111-
* Start the embedded probe with given configuration file and models overrides. It is equivalent to starting
112-
* a probe using <code>-config=cfgFile</code> command line argument.
113-
*
114-
* @param cfgFile Configuration file path. It should be either a full path or the file name
115-
* that can be found in the current working directory or on the classpath as a class loader
116-
* resource.
117-
* @param mdlClasses One or more data model classes to be deployed by the embedded probe. These will
118-
* override {@code nlpcraft.probe.models} configuration property in the provided configuration file.
119-
* @throws NCException Thrown in case of any errors starting the data probe.
120-
* @return Whether or not probe started ok.
121-
*/
122-
@SafeVarargs
123-
public static boolean start(String cfgFile, Class<? extends NCModel>... mdlClasses) {
124-
CompletableFuture<Integer> fut = new CompletableFuture<>();
125-
126-
NCProbeBoot$.MODULE$.start(cfgFile, mdlClasses, fut);
127-
128-
return waitForFuture(fut);
129-
}
130-
131-
/**
132-
* Starts the embedded probe with default configuration and specified models to deploy.
133-
*
134-
* @param mdlClasses One or more data model classes to be deployed by the embedded probe. These will
135-
* override {@code nlpcraft.probe.models} configuration property in the default configuration file.
136-
* @throws NCException Thrown in case of any errors starting the data probe.
137-
* @return Whether or not probe started ok.
138-
*/
139-
@SafeVarargs
140-
public static boolean start(Class<? extends NCModel>... mdlClasses) {
141-
checkModelClasses(mdlClasses);
142-
143-
CompletableFuture<Integer> fut = new CompletableFuture<>();
144-
145-
NCProbeBoot$.MODULE$.start(mdlClasses, fut);
98+
NCProbeBoot$.MODULE$.startEmbedded(cfgFile, mdlClasses, fut);
14699

147100
return waitForFuture(fut);
148101
}
@@ -154,22 +107,23 @@ public static boolean start(Class<? extends NCModel>... mdlClasses) {
154107
* @param tok Probe token override.
155108
* @param upLink Probe up-link to the server override.
156109
* @param dnLink Probe down-link from the server override.
157-
* @param mdlClasses One or more data model classes overrides to be deployed by the embedded probe.
110+
* @param mdlClasses One or more data model classes overrides to be deployed by the embedded probe. At least
111+
* model must be provided.
158112
* @throws NCException Thrown in case of any errors starting the data probe.
159113
* @return Whether or not probe started ok.
160114
*/
161-
@SafeVarargs
162115
public static boolean start(
163116
String probeId,
164117
String tok,
165118
String upLink,
166119
String dnLink,
167-
Class<? extends NCModel>... mdlClasses) {
168-
checkModelClasses(mdlClasses);
120+
String... mdlClasses) {
121+
if (mdlClasses.length == 0)
122+
throw new NCException("At least one model class must be provided when starting embedded probe.");
169123

170124
CompletableFuture<Integer> fut = new CompletableFuture<>();
171125

172-
NCProbeBoot$.MODULE$.start(probeId, tok, upLink, dnLink, mdlClasses, fut);
126+
NCProbeBoot$.MODULE$.startEmbedded(probeId, tok, upLink, dnLink, mdlClasses, fut);
173127

174128
return waitForFuture(fut);
175129
}

nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestAutoModelValidator.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,6 @@ public static boolean isValid(String... mdlIds) throws Exception {
118118
return NCTestAutoModelValidatorImpl.isValidForModelIds(mdlIds);
119119
}
120120

121-
/**
122-
* Performs validation based on {@link NCIntentSample} annotations for given models.
123-
*
124-
* @param mdlIds Comma separate list of one or more model IDs to validate.
125-
* @return <code>True</code> if no validation errors found, <code>false</code> otherwise. Note that
126-
* standard validation output will be printed out to the configured logger.
127-
* @throws Exception Thrown in case of any unexpected errors during validation. Note that standard validation
128-
* output will be printed out to the configured logger.
129-
*
130-
* @see NCModelView#getId()
131-
*/
132-
public static boolean isValid(String mdlIds) throws Exception {
133-
return NCTestAutoModelValidatorImpl.isValidForModelIds(mdlIds);
134-
}
135-
136121
/**
137122
* Performs validation based on {@link NCIntentSample} annotations for given models.
138123
*

nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbe.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object NCProbe extends App {
3535

3636
while (!fut.isDone)
3737
ignoring(classOf[Exception]) {
38-
fut.get();
38+
fut.get()
3939
}
4040

4141
System.exit(fut.get)

nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala

Lines changed: 21 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import org.apache.nlpcraft.common.opencensus.NCOpenCensusTrace
3333
import org.apache.nlpcraft.common.extcfg.NCExternalConfigManager
3434
import org.apache.nlpcraft.common.version.NCVersion
3535
import org.apache.nlpcraft.common.{NCE, NCException, NCService, U}
36-
import org.apache.nlpcraft.model.NCModel
3736
import org.apache.nlpcraft.probe.mgrs.cmd.NCCommandManager
3837
import org.apache.nlpcraft.probe.mgrs.conn.NCConnectionManager
3938
import org.apache.nlpcraft.probe.mgrs.conversation.NCConversationManager
@@ -312,45 +311,34 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
312311
private def checkStarted(): Unit =
313312
if (started)
314313
throw new NCException(s"Probe has already been started (only one probe per JVM is allowed).")
315-
316-
/**
317-
*
318-
* @param cfgFile Configuration file to use.
319-
* @param fut
320-
*/
321-
private [probe] def start(cfgFile: String, fut: CompletableFuture[Integer]): Unit = {
322-
checkStarted()
323-
324-
val cfg = initializeConfig(Array(s"-config=$cfgFile"), None)
325-
326-
new Thread() {
327-
override def run(): Unit = start0(cfg, fut)
328-
}.start()
329-
}
330-
314+
331315
/**
332-
* Starts the embedded probe with given configuration file and provided overrides.
316+
* Starts the embedded probe with optional configuration file and provided overrides.
333317
*
334-
* @param cfgFile Configuration file to use.
335-
* @param mdlClasses Overrides for 'nlpcraft.probe.models' configuration property.
318+
* @param cfgFile Optional configuration file to use. If `null` - the default configuration will be used.
319+
* @param mdlClasses Optional overrides for 'nlpcraft.probe.models' configuration property. If `null` -
320+
* the models configured in the configuration (default or provided) will be used.
336321
* @param fut
337322
*/
338-
private [probe] def start(
323+
private [probe] def startEmbedded(
339324
cfgFile: String,
340-
mdlClasses: Array[java.lang.Class[_ <: NCModel]],
325+
mdlClasses: Array[String],
341326
fut: CompletableFuture[Integer]): Unit = {
342327
checkStarted()
343328

344329
import ConfigValueFactory._
345-
330+
346331
val cfg = initializeConfig(
347-
Array(s"-config=$cfgFile"),
348-
Some(
349-
ConfigFactory.empty().withValue(
350-
"nlpcraft.probe.models",
351-
fromAnyRef(mdlClasses.map(_.getName).mkString(","))
332+
if (cfgFile == null) Array.empty else Array(s"-config=$cfgFile"),
333+
if (mdlClasses == null)
334+
None
335+
else
336+
Some(
337+
ConfigFactory.empty().withValue(
338+
"nlpcraft.probe.models",
339+
fromAnyRef(mdlClasses.mkString(","))
340+
)
352341
)
353-
)
354342
)
355343

356344
new Thread() {
@@ -359,48 +347,21 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
359347
}
360348

361349
/**
362-
* Starts the embedded probe with the default configuration.
350+
* Starts the embedded probe with specified configuration values.
363351
*
364-
* @param mdlClasses Overrides for 'nlpcraft.probe.models' configuration property.
365-
* @param fut
366-
*/
367-
private [probe] def start(
368-
mdlClasses: Array[java.lang.Class[_ <: NCModel]],
369-
fut: CompletableFuture[Integer]): Unit = {
370-
checkStarted()
371-
372-
import ConfigValueFactory._
373-
374-
val cfg = initializeConfig(
375-
Array.empty,
376-
Some(
377-
ConfigFactory.empty().withValue(
378-
"nlpcraft.probe.models",
379-
fromAnyRef(mdlClasses.map(_.getName).mkString(","))
380-
)
381-
)
382-
)
383-
384-
new Thread() {
385-
override def run(): Unit = start0(cfg, fut)
386-
}.start()
387-
}
388-
389-
/**
390-
*
391352
* @param probeId Probe ID.
392353
* @param tok
393354
* @param upLinkStr
394355
* @param dnLinkStr
395356
* @param mdlClasses
396357
* @param fut
397358
*/
398-
private [probe] def start(
359+
private [probe] def startEmbedded(
399360
probeId: String,
400361
tok: String,
401362
upLinkStr: String,
402363
dnLinkStr: String,
403-
mdlClasses: Array[java.lang.Class[_ <: NCModel]],
364+
mdlClasses: Array[String],
404365
fut: CompletableFuture[Integer]): Unit = {
405366
checkStarted()
406367

@@ -412,7 +373,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
412373
val upLink: (String, Integer) = getHostPort(upLinkStr)
413374
val dnLink: (String, Integer) = getHostPort(dnLinkStr)
414375
val jarsFolder: Option[String] = getStringOpt(s"$prefix.jarsFolder")
415-
val models: String = mdlClasses.map(_.getName).mkString(",")
376+
val models: String = mdlClasses.mkString(",")
416377
val lifecycle: Seq[String] = getStringList(s"$prefix.lifecycle")
417378
}
418379

@@ -443,14 +404,6 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
443404
stop0()
444405
}
445406

446-
/**
447-
*
448-
* @param args
449-
* @param fut
450-
*/
451-
private [probe] def start(args: Array[String], fut: CompletableFuture[Integer]): Unit =
452-
start0(initializeConfig(args, None), fut)
453-
454407
/**
455408
* Prints ASCII-logo.
456409
*/

0 commit comments

Comments
 (0)