You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by zh...@apache.org on 2022/11/22 13:00:59 UTC

[incubator-hugegraph-toolchain] 01/01: Fix Hubble graph connect error

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

zhaocong pushed a commit to branch fix_hubble
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-toolchain.git

commit 2bd2370e5bb8ccbf3669e98745445aba232e7c2b
Author: coderzc <zh...@apache.org>
AuthorDate: Tue Nov 22 21:00:27 2022 +0800

    Fix Hubble graph connect error
---
 hugegraph-hubble/hubble-be/pom.xml                 |  9 +++
 .../hugegraph/handler/CustomInterceptor.java       |  2 +-
 .../apache/hugegraph/handler/ExceptionAdvisor.java |  5 ++
 .../apache/hugegraph/unit/GraphConnectionTest.java | 56 +++++++++++++++
 .../src/test/resources/application.properties      |  2 +-
 .../src/test/resources/database/schema.sql         | 81 +++++++++++++++++++++-
 hugegraph-hubble/pom.xml                           |  8 +++
 7 files changed, 160 insertions(+), 3 deletions(-)

diff --git a/hugegraph-hubble/hubble-be/pom.xml b/hugegraph-hubble/hubble-be/pom.xml
index 28a8821a..8f292127 100644
--- a/hugegraph-hubble/hubble-be/pom.xml
+++ b/hugegraph-hubble/hubble-be/pom.xml
@@ -63,6 +63,11 @@
             <groupId>com.github.ben-manes.caffeine</groupId>
             <artifactId>caffeine</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.hugegraph</groupId>
+            <artifactId>hugegraph-common</artifactId>
+            <version>${version}</version>
+        </dependency>
 
         <dependency>
             <groupId>org.apache.hugegraph</groupId>
@@ -97,6 +102,10 @@
                     <groupId>com.oracle</groupId>
                     <artifactId>ojdbc8</artifactId>
                 </exclusion>
+                <exclusion>
+                    <groupId>org.apache.hugegraph</groupId>
+                    <artifactId>hugegraph-common</artifactId>
+                </exclusion>
             </exclusions>
         </dependency>
 
diff --git a/hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/handler/CustomInterceptor.java b/hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/handler/CustomInterceptor.java
index 5c2c6b7a..98fbbd79 100644
--- a/hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/handler/CustomInterceptor.java
+++ b/hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/handler/CustomInterceptor.java
@@ -34,7 +34,7 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
 import lombok.extern.log4j.Log4j2;
 
 @Log4j2
-@Component
+//@Component
 public class CustomInterceptor extends HandlerInterceptorAdapter {
 
     @Autowired
diff --git a/hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/handler/ExceptionAdvisor.java b/hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/handler/ExceptionAdvisor.java
index 0b2a9bd7..be961e5a 100644
--- a/hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/handler/ExceptionAdvisor.java
+++ b/hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/handler/ExceptionAdvisor.java
@@ -44,6 +44,7 @@ public class ExceptionAdvisor {
     @ExceptionHandler(InternalException.class)
     @ResponseStatus(HttpStatus.OK)
     public Response exceptionHandler(InternalException e) {
+        log.error("InternalException:", e);
         String message = this.handleMessage(e.getMessage(), e.args());
         return Response.builder()
                        .status(Constant.STATUS_INTERNAL_ERROR)
@@ -55,6 +56,7 @@ public class ExceptionAdvisor {
     @ExceptionHandler(ExternalException.class)
     @ResponseStatus(HttpStatus.OK)
     public Response exceptionHandler(ExternalException e) {
+        log.error("ExternalException:", e);
         String message = this.handleMessage(e.getMessage(), e.args());
         return Response.builder()
                        .status(e.status())
@@ -66,6 +68,7 @@ public class ExceptionAdvisor {
     @ExceptionHandler(ParameterizedException.class)
     @ResponseStatus(HttpStatus.OK)
     public Response exceptionHandler(ParameterizedException e) {
+        log.error("ParameterizedException", e);
         String message = this.handleMessage(e.getMessage(), e.args());
         return Response.builder()
                        .status(Constant.STATUS_BAD_REQUEST)
@@ -77,6 +80,7 @@ public class ExceptionAdvisor {
     @ExceptionHandler(Exception.class)
     @ResponseStatus(HttpStatus.OK)
     public Response exceptionHandler(Exception e) {
+        log.error("Exception:", e);
         String message = this.handleMessage(e.getMessage(), null);
         return Response.builder()
                        .status(Constant.STATUS_BAD_REQUEST)
@@ -88,6 +92,7 @@ public class ExceptionAdvisor {
     @ExceptionHandler(IllegalGremlinException.class)
     @ResponseStatus(HttpStatus.OK)
     public Response exceptionHandler(IllegalGremlinException e) {
+        log.error("IllegalGremlinException:", e);
         String message = this.handleMessage(e.getMessage(), e.args());
         return Response.builder()
                        .status(Constant.STATUS_ILLEGAL_GREMLIN)
diff --git a/hugegraph-hubble/hubble-be/src/test/java/org/apache/hugegraph/unit/GraphConnectionTest.java b/hugegraph-hubble/hubble-be/src/test/java/org/apache/hugegraph/unit/GraphConnectionTest.java
new file mode 100644
index 00000000..aa219609
--- /dev/null
+++ b/hugegraph-hubble/hubble-be/src/test/java/org/apache/hugegraph/unit/GraphConnectionTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hugegraph.unit;
+
+import org.apache.hugegraph.HugeGraphHubble;
+import org.apache.hugegraph.common.Constant;
+import org.apache.hugegraph.common.Response;
+import org.apache.hugegraph.entity.GraphConnection;
+import org.apache.hugegraph.testutil.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@TestPropertySource("classpath:application.properties")
+@SpringBootTest(classes = HugeGraphHubble.class, webEnvironment =
+        SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class GraphConnectionTest {
+
+    private static final String HOST = "127.0.0.1";
+    private static final int PORT = 8080;
+
+    @Autowired
+    private TestRestTemplate testRestTemplate;
+
+    @Test
+    public void testGraphConnect() {
+        GraphConnection entry =
+                GraphConnection.builder().host(HOST).port(PORT).name("test").graph(
+                        "hugegraph").build();
+        Response response = testRestTemplate.postForObject(
+                Constant.API_VERSION + "graph-connections",
+                entry, Response.class);
+        Assert.assertEquals(response.getMessage(), 200, response.getStatus());
+    }
+}
diff --git a/hugegraph-hubble/hubble-be/src/test/resources/application.properties b/hugegraph-hubble/hubble-be/src/test/resources/application.properties
index 6efb9e8b..a651d07a 100644
--- a/hugegraph-hubble/hubble-be/src/test/resources/application.properties
+++ b/hugegraph-hubble/hubble-be/src/test/resources/application.properties
@@ -2,7 +2,7 @@ server.servlet.context-path=/api/v1.1
 server.port=8088
 
 spring.datasource.driver-class-name=org.h2.Driver
-spring.datasource.url=jdbc:h2:mem:db
+spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_ON_EXIT=FALSE
 spring.datasource.username=sa
 spring.datasource.password=
 spring.datasource.schema=classpath:database/schema.sql
diff --git a/hugegraph-hubble/hubble-be/src/test/resources/database/schema.sql b/hugegraph-hubble/hubble-be/src/test/resources/database/schema.sql
index cec66668..cc03c3e7 100644
--- a/hugegraph-hubble/hubble-be/src/test/resources/database/schema.sql
+++ b/hugegraph-hubble/hubble-be/src/test/resources/database/schema.sql
@@ -12,8 +12,11 @@ CREATE TABLE IF NOT EXISTS `graph_connection` (
     `graph` VARCHAR(48) NOT NULL,
     `host` VARCHAR(48) NOT NULL DEFAULT 'localhost',
     `port` INT NOT NULL DEFAULT '8080',
+    `timeout` INT NOT NULL,
     `username` VARCHAR(48),
     `password` VARCHAR(48),
+    `enabled` BOOLEAN NOT NULL DEFAULT true,
+    `disable_reason` VARCHAR(65535) NOT NULL DEFAULT '',
     `create_time` DATETIME(6) NOT NULL,
     PRIMARY KEY (`id`),
     UNIQUE (`name`),
@@ -22,19 +25,95 @@ CREATE TABLE IF NOT EXISTS `graph_connection` (
 
 CREATE TABLE IF NOT EXISTS `execute_history` (
     `id` INT NOT NULL AUTO_INCREMENT,
+    `conn_id` INT NOT NULL,
+    `async_id` LONG NOT NULL DEFAULT 0,
     `execute_type` TINYINT NOT NULL,
     `content` VARCHAR(65535) NOT NULL,
     `execute_status` TINYINT NOT NULL,
+    `async_status` TINYINT NOT NULL DEFAULT 0,
     `duration` LONG NOT NULL,
     `create_time` DATETIME(6) NOT NULL,
     PRIMARY KEY (`id`)
 );
+CREATE INDEX IF NOT EXISTS `execute_history_conn_id` ON `execute_history`(`conn_id`);
 
 CREATE TABLE IF NOT EXISTS `gremlin_collection` (
     `id` INT NOT NULL AUTO_INCREMENT,
+    `conn_id` INT NOT NULL,
     `name` VARCHAR(48) NOT NULL,
     `content` VARCHAR(65535) NOT NULL,
     `create_time` DATETIME(6) NOT NULL,
     PRIMARY KEY (`id`),
-    UNIQUE (`name`)
+    UNIQUE (`conn_id`, `name`)
 );
+CREATE INDEX IF NOT EXISTS `gremlin_collection_conn_id` ON `gremlin_collection`(`conn_id`);
+
+CREATE TABLE IF NOT EXISTS `file_mapping` (
+    `id` INT NOT NULL AUTO_INCREMENT,
+    `conn_id` INT NOT NULL,
+    `job_id` INT NOT NULL DEFAULT 0,
+    `name` VARCHAR(128) NOT NULL,
+    `path` VARCHAR(256) NOT NULL,
+    `total_lines` LONG NOT NULL,
+    `total_size` LONG NOT NULL,
+    `file_status` TINYINT NOT NULL DEFAULT 0,
+    `file_setting` VARCHAR(65535) NOT NULL,
+    `vertex_mappings` VARCHAR(65535) NOT NULL,
+    `edge_mappings` VARCHAR(65535) NOT NULL,
+    `load_parameter` VARCHAR(65535) NOT NULL,
+    `create_time` DATETIME(6) NOT NULL,
+    `update_time` DATETIME(6) NOT NULL,
+    PRIMARY KEY (`id`),
+    UNIQUE (`conn_id`, `job_id`, `name`)
+);
+CREATE INDEX IF NOT EXISTS `file_mapping_conn_id` ON `file_mapping`(`conn_id`);
+
+CREATE TABLE IF NOT EXISTS `load_task` (
+    `id` INT NOT NULL AUTO_INCREMENT,
+    `conn_id` INT NOT NULL,
+    `job_id` INT NOT NULL DEFAULT 0,
+    `file_id` INT NOT NULL,
+    `file_name` VARCHAR(128) NOT NULL,
+    `options` VARCHAR(65535) NOT NULL,
+    `vertices` VARCHAR(512) NOT NULL,
+    `edges` VARCHAR(512) NOT NULL,
+    `file_total_lines` LONG NOT NULL,
+    `load_status` TINYINT NOT NULL,
+    `file_read_lines` LONG NOT NULL,
+    `last_duration` LONG NOT NULL,
+    `curr_duration` LONG NOT NULL,
+    `create_time` DATETIME(6) NOT NULL,
+    PRIMARY KEY (`id`)
+);
+
+CREATE TABLE IF NOT EXISTS `job_manager` (
+    `id` INT NOT NULL AUTO_INCREMENT,
+    `conn_id` INT NOT NULL DEFAULT 0,
+    `job_name` VARCHAR(100) NOT NULL DEFAULT '',
+    `job_remarks` VARCHAR(200) NOT NULL DEFAULT '',
+    `job_size` LONG NOT NULL DEFAULT 0,
+    `job_status` TINYINT NOT NULL DEFAULT 0,
+    `job_duration` LONG NOT NULL DEFAULT 0,
+    `update_time` DATETIME(6) NOT NULL,
+    `create_time` DATETIME(6) NOT NULL,
+    PRIMARY KEY (`id`),
+    UNIQUE (`job_name`, `conn_id`)
+);
+
+CREATE TABLE IF NOT EXISTS `async_task` (
+    `id` INT NOT NULL AUTO_INCREMENT,
+    `conn_id` INT NOT NULL DEFAULT 0,
+    `task_id` INT NOT NULL DEFAULT 0,
+    `task_name` VARCHAR(100) NOT NULL DEFAULT '',
+    `task_reason` VARCHAR(200) NOT NULL DEFAULT '',
+    `task_type` TINYINT NOT NULL DEFAULT 0,
+    `algorithm_name` VARCHAR(48) NOT NULL DEFAULT '',
+    `task_content` VARCHAR(65535) NOT NULL DEFAULT '',
+    `task_status` TINYINT NOT NULL DEFAULT 0,
+    `task_duration` LONG NOT NULL DEFAULT 0,
+    `create_time`  DATETIME(6)  NOT NULL,
+    PRIMARY KEY (`id`)
+);
+
+CREATE INDEX IF NOT EXISTS `load_task_conn_id` ON `load_task`(`conn_id`);
+CREATE INDEX IF NOT EXISTS `load_task_file_id` ON `load_task`(`file_id`);
diff --git a/hugegraph-hubble/pom.xml b/hugegraph-hubble/pom.xml
index b17ddcc4..d8cba158 100644
--- a/hugegraph-hubble/pom.xml
+++ b/hugegraph-hubble/pom.xml
@@ -41,10 +41,18 @@
 
     <properties>
         <springboot.version>2.1.8.RELEASE</springboot.version>
+        <jersey.version>3.0.3</jersey.version>
     </properties>
 
     <dependencyManagement>
         <dependencies>
+            <dependency>
+                <groupId>org.glassfish.jersey</groupId>
+                <artifactId>jersey-bom</artifactId>
+                <version>${jersey.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
             <dependency>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-dependencies</artifactId>