You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2020/03/29 10:07:04 UTC

[incubator-nlpcraft] branch NLPCRAFT-28 updated: WIP.

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

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


The following commit(s) were added to refs/heads/NLPCRAFT-28 by this push:
     new 1d5a58b  WIP.
1d5a58b is described below

commit 1d5a58b5c0921f94d1f97e77fa8d639490f230e7
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Sun Mar 29 13:06:56 2020 +0300

    WIP.
---
 pom.xml                                            | 56 ++++++++++++-
 .../nlpcraft/server/rest/NCBasicRestApi.scala      | 93 +++++++++++++---------
 2 files changed, 112 insertions(+), 37 deletions(-)

diff --git a/pom.xml b/pom.xml
index 04d80cf..7f21291 100644
--- a/pom.xml
+++ b/pom.xml
@@ -119,6 +119,7 @@
         <maven.source.plugin.ver>3.0.1</maven.source.plugin.ver>
         <maven.gpg.plugin.ver>1.6</maven.gpg.plugin.ver>
         <maven.nexus.staging.plugin>1.6.7</maven.nexus.staging.plugin>
+        <maven.bazaarvoice.plugin>0.9</maven.bazaarvoice.plugin>
         <org.antlr4.ver>4.8</org.antlr4.ver>
         <akka.http.2.11.ver>10.1.9</akka.http.2.11.ver>
         <akka.stream.2.11.ver>2.5.23</akka.stream.2.11.ver>
@@ -499,13 +500,66 @@
             </plugin>
 
             <plugin>
+                <groupId>com.bazaarvoice.maven.plugins</groupId>
+                <artifactId>process-exec-maven-plugin</artifactId>
+                <version>${maven.bazaarvoice.plugin}</version>
+                <executions>
+                    <execution>
+                        <id>pre-integration-test</id>
+                        <phase>pre-integration-test</phase>
+                        <goals>
+                            <goal>start</goal>
+                        </goals>
+                        <configuration>
+                            <name>server</name>
+                            <healthcheckUrl>http://localhost:8081/api/v1/health</healthcheckUrl>
+                            <waitAfterLaunch>180</waitAfterLaunch>
+                            <arguments>
+                                <argument>java</argument>
+                                <argument>-Xmx4G</argument>
+                                <argument>-Xms4G</argument>
+                                <argument>-jar</argument>
+                                <argument>${project.build.directory}/${project.artifactId}-${project.version}-all-deps.jar</argument>
+                                <argument>-server</argument>
+                            </arguments>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>stop-all</id>
+                        <phase>post-integration-test</phase>
+                        <goals>
+                            <goal>stop-all</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <version>${maven.surefire.plugin.ver}</version>
                 <configuration>
-                    <skipTests>true</skipTests>
+                    <!-- Skips all tests on phase `test`. -->
+                    <skip>true</skip>
                 </configuration>
+                <executions>
+                    <!-- All tests are defined as integration. -->
+                    <execution>
+                        <id>integration-tests</id>
+                        <phase>integration-test</phase>
+                        <goals>
+                            <goal>test</goal>
+                        </goals>
+                        <configuration>
+                            <skip>false</skip>
+                            <includes>
+                                <include>**/*.*</include>
+                            </includes>
+                        </configuration>
+                    </execution>
+                </executions>
             </plugin>
+
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-enforcer-plugin</artifactId>
diff --git a/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala b/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
index 4071932..472b9d1 100644
--- a/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
+++ b/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
@@ -354,6 +354,20 @@ class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace w
     }
 
     /**
+     *
+     * @return
+     */
+    protected def health$(): Route = {
+        case class Res(status: String)
+
+        implicit val resFmt: RootJsonFormat[Res] = jsonFormat1(Res)
+
+        complete {
+            Res(API_OK)
+        }
+    }
+
+    /**
       *
       * @return
       */
@@ -1696,42 +1710,49 @@ class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace w
                 entity = "Unable to serve response within time limit, please enhance your calm."
             )
 
-        corsHandler (post {
-            withRequestTimeoutResponse(_ ⇒ timeoutResp) {
-                path(API / "signin") { withLatency(M_SIGNIN_LATENCY_MS, signin$) } ~
-                path(API / "signout") { withLatency(M_SIGNOUT_LATENCY_MS, signout$) } ~ {
-                path(API / "cancel") { withLatency(M_CANCEL_LATENCY_MS, cancel$) } ~
-                path(API / "check") { withLatency(M_CHECK_LATENCY_MS, check$) } ~
-                path(API / "clear"/ "conversation") { withLatency(M_CLEAR_CONV_LATENCY_MS, clear$Conversation) } ~
-                path(API / "clear"/ "dialog") { withLatency(M_CLEAR_DIALOG_LATENCY_MS, clear$Dialog) } ~
-                path(API / "company"/ "add") { withLatency(M_COMPANY_ADD_LATENCY_MS, company$Add) } ~
-                path(API / "company"/ "get") { withLatency(M_COMPANY_GET_LATENCY_MS, company$Get) } ~
-                path(API / "company" / "update") { withLatency(M_COMPANY_UPDATE_LATENCY_MS, company$Update) } ~
-                path(API / "company" / "token" / "reset") { withLatency(M_COMPANY_TOKEN_LATENCY_MS, company$Token$Reset) } ~
-                path(API / "company" / "delete") { withLatency(M_COMPANY_DELETE_LATENCY_MS, company$Delete) } ~
-                path(API / "user" / "get") { withLatency(M_USER_GET_LATENCY_MS, user$Get) } ~
-                path(API / "user" / "add") { withLatency(M_USER_ADD_LATENCY_MS, user$Add) } ~
-                path(API / "user" / "update") { withLatency(M_USER_UPDATE_LATENCY_MS, user$Update) } ~
-                path(API / "user" / "delete") { withLatency(M_USER_DELETE_LATENCY_MS, user$Delete) } ~
-                path(API / "user" / "admin") { withLatency(M_USER_ADMIN_LATENCY_MS, user$Admin) } ~
-                path(API / "user" / "passwd" / "reset") { withLatency(M_USER_PASSWD_RESET_LATENCY_MS, user$Password$Reset) } ~
-                path(API / "user" / "all") { withLatency(M_USER_ALL_LATENCY_MS, user$All) } ~
-                path(API / "feedback"/ "add") { withLatency(M_FEEDBACK_ADD_LATENCY_MS, feedback$Add) } ~
-                path(API / "feedback"/ "all") { withLatency(M_FEEDBACK_GET_LATENCY_MS, feedback$All) } ~
-                path(API / "feedback" / "delete") { withLatency(M_FEEDBACK_DELETE_LATENCY_MS, feedback$Delete) } ~
-                path(API / "probe" / "all") { withLatency(M_PROBE_ALL_LATENCY_MS, probe$All) } ~
-                path(API / "ask") { withLatency(M_ASK_LATENCY_MS, ask$) } ~
-                (path(API / "ask" / "sync") &
-                    entity(as[JsValue]) &
-                    optionalHeaderValueByName("User-Agent") &
-                    extractClientIP
-                ) {
-                    (req, userAgentOpt, rmtAddr) ⇒
-                        onSuccess(withLatency(M_ASK_SYNC_LATENCY_MS, ask$Sync(req, userAgentOpt, rmtAddr))) {
-                            js ⇒ complete(HttpResponse(entity = HttpEntity(ContentTypes.`application/json`, js)))
-                        }
-                }}
+        corsHandler (
+            get {
+                withRequestTimeoutResponse(_ ⇒ timeoutResp) {
+                    path(API / "health") { health$() }
+                }
+            } ~
+            post {
+                withRequestTimeoutResponse(_ ⇒ timeoutResp) {
+                    path(API / "signin") { withLatency(M_SIGNIN_LATENCY_MS, signin$) } ~
+                    path(API / "signout") { withLatency(M_SIGNOUT_LATENCY_MS, signout$) } ~ {
+                    path(API / "cancel") { withLatency(M_CANCEL_LATENCY_MS, cancel$) } ~
+                    path(API / "check") { withLatency(M_CHECK_LATENCY_MS, check$) } ~
+                    path(API / "clear"/ "conversation") { withLatency(M_CLEAR_CONV_LATENCY_MS, clear$Conversation) } ~
+                    path(API / "clear"/ "dialog") { withLatency(M_CLEAR_DIALOG_LATENCY_MS, clear$Dialog) } ~
+                    path(API / "company"/ "add") { withLatency(M_COMPANY_ADD_LATENCY_MS, company$Add) } ~
+                    path(API / "company"/ "get") { withLatency(M_COMPANY_GET_LATENCY_MS, company$Get) } ~
+                    path(API / "company" / "update") { withLatency(M_COMPANY_UPDATE_LATENCY_MS, company$Update) } ~
+                    path(API / "company" / "token" / "reset") { withLatency(M_COMPANY_TOKEN_LATENCY_MS, company$Token$Reset) } ~
+                    path(API / "company" / "delete") { withLatency(M_COMPANY_DELETE_LATENCY_MS, company$Delete) } ~
+                    path(API / "user" / "get") { withLatency(M_USER_GET_LATENCY_MS, user$Get) } ~
+                    path(API / "user" / "add") { withLatency(M_USER_ADD_LATENCY_MS, user$Add) } ~
+                    path(API / "user" / "update") { withLatency(M_USER_UPDATE_LATENCY_MS, user$Update) } ~
+                    path(API / "user" / "delete") { withLatency(M_USER_DELETE_LATENCY_MS, user$Delete) } ~
+                    path(API / "user" / "admin") { withLatency(M_USER_ADMIN_LATENCY_MS, user$Admin) } ~
+                    path(API / "user" / "passwd" / "reset") { withLatency(M_USER_PASSWD_RESET_LATENCY_MS, user$Password$Reset) } ~
+                    path(API / "user" / "all") { withLatency(M_USER_ALL_LATENCY_MS, user$All) } ~
+                    path(API / "feedback"/ "add") { withLatency(M_FEEDBACK_ADD_LATENCY_MS, feedback$Add) } ~
+                    path(API / "feedback"/ "all") { withLatency(M_FEEDBACK_GET_LATENCY_MS, feedback$All) } ~
+                    path(API / "feedback" / "delete") { withLatency(M_FEEDBACK_DELETE_LATENCY_MS, feedback$Delete) } ~
+                    path(API / "probe" / "all") { withLatency(M_PROBE_ALL_LATENCY_MS, probe$All) } ~
+                    path(API / "ask") { withLatency(M_ASK_LATENCY_MS, ask$) } ~
+                    (path(API / "ask" / "sync") &
+                        entity(as[JsValue]) &
+                        optionalHeaderValueByName("User-Agent") &
+                        extractClientIP
+                    ) {
+                        (req, userAgentOpt, rmtAddr) ⇒
+                            onSuccess(withLatency(M_ASK_SYNC_LATENCY_MS, ask$Sync(req, userAgentOpt, rmtAddr))) {
+                                js ⇒ complete(HttpResponse(entity = HttpEntity(ContentTypes.`application/json`, js)))
+                            }
+                    }}
+                }
             }
-        })
+        )
     }
 }