You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by ji...@apache.org on 2023/03/01 12:41:33 UTC

[incubator-hugegraph-toolchain] 01/01: chore: clean store file in all modules

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

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

commit 7bbfc032846e256cba7be51a46be798f90f00d7e
Author: imbajin <ji...@apache.org>
AuthorDate: Wed Mar 1 20:41:25 2023 +0800

    chore: clean store file in all modules
    
    TODO: we need use a better way to download it when building binary package
---
 README.md                                          |   2 +-
 .../java/org/apache/hugegraph/util/CommonUtil.java |  15 ++++++++++++++
 .../hugegraph/functional/HugeClientHttpsTest.java  |  23 ++++++++++++++-------
 .../java/org/apache/hugegraph/testutil/Utils.java  |   5 +----
 .../src/test/resources/hugegraph.truststore        | Bin 679 -> 0 bytes
 .../hugegraph/service/SettingSSLService.java       |   5 ++---
 .../assembly/static/conf/hugegraph.truststore      | Bin 679 -> 0 bytes
 .../assembly/travis/conf/hugegraph.truststore      | Bin 679 -> 0 bytes
 .../hugegraph/loader/constant/Constants.java       |   2 +-
 .../hugegraph/loader/util/HugeClientHolder.java    |   4 +---
 .../loader/test/functional/FileLoadTest.java       |  13 ++++++++----
 .../hugegraph/loader/test/functional/LoadTest.java |   5 +++--
 hugegraph-tools/assembly/conf/hugegraph.truststore | Bin 679 -> 0 bytes
 .../java/org/apache/hugegraph/base/ToolClient.java |  17 +++++++--------
 14 files changed, 57 insertions(+), 34 deletions(-)

diff --git a/README.md b/README.md
index d6558eae..b1ac7dca 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
 [![Build Status](https://github.com/apache/hugegraph-toolchain/actions/workflows/hubble-ci.yml/badge.svg)](https://github.com/apache/hugegraph-toolchain/actions/workflows/hubble-ci.yml)
 [![Build Status](https://github.com/apache/hugegraph-toolchain/actions/workflows/tools-ci.yml/badge.svg)](https://github.com/apache/hugegraph-toolchain/actions/workflows/tools-ci.yml)
 [![codecov](https://codecov.io/gh/apache/hugegraph-toolchain/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/hugegraph-toolchain)
-[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.hugegraph/hugegraph-loader/badge.svg)](https://mvnrepository.com/artifact/org.apache.hugegraph/hugegraph-loader)
+[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.hugegraph/hugegraph-client/badge.svg)](https://mvnrepository.com/artifact/org.apache.hugegraph/hugegraph-client)
 
 `hugegraph-toolchain` is the integration project of a series of utilities for [HugeGraph](https://github.com/apache/hugegraph), it includes 4 main modules.
 
diff --git a/hugegraph-client/src/main/java/org/apache/hugegraph/util/CommonUtil.java b/hugegraph-client/src/main/java/org/apache/hugegraph/util/CommonUtil.java
index b67d89aa..aa728e3c 100644
--- a/hugegraph-client/src/main/java/org/apache/hugegraph/util/CommonUtil.java
+++ b/hugegraph-client/src/main/java/org/apache/hugegraph/util/CommonUtil.java
@@ -17,8 +17,13 @@
 
 package org.apache.hugegraph.util;
 
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
 import java.util.Map;
 
+import org.apache.commons.io.FileUtils;
+
 public final class CommonUtil {
 
     public static void checkMapClass(Object object, Class<?> kClass,
@@ -41,4 +46,14 @@ public final class CommonUtil {
                          "but got '%s'(%s)", vClass, value, value.getClass());
         }
     }
+
+    public static void downloadFileByUrl(String url, String destPath) {
+        int connectTimeout = 5000;
+        int readTimeout = 5000;
+        try {
+            FileUtils.copyURLToFile(new URL(url), new File(destPath), connectTimeout, readTimeout);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
 }
diff --git a/hugegraph-client/src/test/java/org/apache/hugegraph/functional/HugeClientHttpsTest.java b/hugegraph-client/src/test/java/org/apache/hugegraph/functional/HugeClientHttpsTest.java
index c8c73333..22feaa56 100644
--- a/hugegraph-client/src/test/java/org/apache/hugegraph/functional/HugeClientHttpsTest.java
+++ b/hugegraph-client/src/test/java/org/apache/hugegraph/functional/HugeClientHttpsTest.java
@@ -25,7 +25,9 @@ import org.apache.hugegraph.driver.SchemaManager;
 import org.apache.hugegraph.structure.constant.T;
 import org.apache.hugegraph.structure.graph.Vertex;
 import org.apache.hugegraph.testutil.Assert;
+import org.apache.hugegraph.util.CommonUtil;
 import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableMap;
@@ -40,11 +42,18 @@ public class HugeClientHttpsTest {
     private static final int MAX_CONNS_PER_ROUTE = 10;
     private static final int MAX_CONNS = 10;
     private static final int IDLE_TIME = 30;
-    private static final String TRUST_STORE_FILE = "src/test/resources/hugegraph.truststore";
+    private static final String TRUST_STORE_PATH = "src/test/resources/hugegraph.truststore";
     private static final String TRUST_STORE_PASSWORD = "hugegraph";
 
     private static HugeClient client;
 
+    @Before
+    public void init() {
+        String url = "https://github.com/apache/incubator-hugegraph-doc/" +
+                     "raw/binary/dist/toolchain/hugegraph.truststore";
+        CommonUtil.downloadFileByUrl(url, TRUST_STORE_PATH);
+    }
+
     @After
     public void teardown() throws Exception {
         Assert.assertNotNull("Client is not opened", client);
@@ -55,7 +64,7 @@ public class HugeClientHttpsTest {
     public void testHttpsClientBuilderWithConnection() {
         client = HugeClient.builder(BASE_URL, GRAPH)
                            .configUser(USERNAME, PASSWORD)
-                           .configSSL(TRUST_STORE_FILE, TRUST_STORE_PASSWORD)
+                           .configSSL(TRUST_STORE_PATH, TRUST_STORE_PASSWORD)
                            .build();
         Assert.assertTrue(client.graphs().listGraph().contains("hugegraph"));
         this.addVertexAndCheckPropertyValue();
@@ -66,7 +75,7 @@ public class HugeClientHttpsTest {
         client = HugeClient.builder(BASE_URL, GRAPH)
                            .configTimeout(TIMEOUT)
                            .configPool(MAX_CONNS, MAX_CONNS_PER_ROUTE)
-                           .configSSL(TRUST_STORE_FILE, TRUST_STORE_PASSWORD)
+                           .configSSL(TRUST_STORE_PATH, TRUST_STORE_PASSWORD)
                            .build();
         Assert.assertTrue(client.graphs().listGraph().contains("hugegraph"));
         this.addVertexAndCheckPropertyValue();
@@ -77,7 +86,7 @@ public class HugeClientHttpsTest {
         client = HugeClient.builder(BASE_URL, GRAPH)
                            .configUser(USERNAME, PASSWORD)
                            .configPool(MAX_CONNS, MAX_CONNS_PER_ROUTE)
-                           .configSSL(TRUST_STORE_FILE, TRUST_STORE_PASSWORD)
+                           .configSSL(TRUST_STORE_PATH, TRUST_STORE_PASSWORD)
                            .build();
         Assert.assertTrue(client.graphs().listGraph().contains("hugegraph"));
         this.addVertexAndCheckPropertyValue();
@@ -88,7 +97,7 @@ public class HugeClientHttpsTest {
         client = HugeClient.builder(BASE_URL, GRAPH)
                            .configUser(USERNAME, PASSWORD)
                            .configTimeout(TIMEOUT)
-                           .configSSL(TRUST_STORE_FILE, TRUST_STORE_PASSWORD)
+                           .configSSL(TRUST_STORE_PATH, TRUST_STORE_PASSWORD)
                            .build();
         Assert.assertTrue(client.graphs().listGraph().contains("hugegraph"));
         this.addVertexAndCheckPropertyValue();
@@ -100,7 +109,7 @@ public class HugeClientHttpsTest {
                            .configUser(USERNAME, PASSWORD)
                            .configTimeout(TIMEOUT)
                            .configPool(MAX_CONNS, MAX_CONNS_PER_ROUTE)
-                           .configSSL(TRUST_STORE_FILE, TRUST_STORE_PASSWORD)
+                           .configSSL(TRUST_STORE_PATH, TRUST_STORE_PASSWORD)
                            .configIdleTime(IDLE_TIME)
                            .build();
         Assert.assertTrue(client.graphs().listGraph().contains("hugegraph"));
@@ -113,7 +122,7 @@ public class HugeClientHttpsTest {
                            .configUser(USERNAME, PASSWORD)
                            .configTimeout(TIMEOUT)
                            .configPool(0, 0)
-                           .configSSL(TRUST_STORE_FILE, TRUST_STORE_PASSWORD)
+                           .configSSL(TRUST_STORE_PATH, TRUST_STORE_PASSWORD)
                            .build();
         Assert.assertTrue(client.graphs().listGraph().contains("hugegraph"));
         this.addVertexAndCheckPropertyValue();
diff --git a/hugegraph-client/src/test/java/org/apache/hugegraph/testutil/Utils.java b/hugegraph-client/src/test/java/org/apache/hugegraph/testutil/Utils.java
index 490a2826..1e4dd63f 100644
--- a/hugegraph-client/src/test/java/org/apache/hugegraph/testutil/Utils.java
+++ b/hugegraph-client/src/test/java/org/apache/hugegraph/testutil/Utils.java
@@ -135,10 +135,7 @@ public final class Utils {
         if (left.dataType() != right.dataType()) {
             return false;
         }
-        if (left.cardinality() != right.cardinality()) {
-            return false;
-        }
-        return true;
+        return left.cardinality() == right.cardinality();
     }
 
     public static boolean equalVertexLabel(VertexLabel left,
diff --git a/hugegraph-client/src/test/resources/hugegraph.truststore b/hugegraph-client/src/test/resources/hugegraph.truststore
deleted file mode 100644
index 5b0828dc..00000000
Binary files a/hugegraph-client/src/test/resources/hugegraph.truststore and /dev/null differ
diff --git a/hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/service/SettingSSLService.java b/hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/service/SettingSSLService.java
index 25eef7c6..74dc1f85 100644
--- a/hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/service/SettingSSLService.java
+++ b/hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/service/SettingSSLService.java
@@ -18,11 +18,10 @@
 
 package org.apache.hugegraph.service;
 
-import org.springframework.stereotype.Service;
-
 import org.apache.hugegraph.config.HugeConfig;
 import org.apache.hugegraph.entity.GraphConnection;
 import org.apache.hugegraph.options.HubbleOptions;
+import org.springframework.stereotype.Service;
 
 import lombok.extern.log4j.Log4j2;
 
@@ -32,7 +31,7 @@ public class SettingSSLService {
 
     public void configSSL(HugeConfig config, GraphConnection connection) {
         String protocol = config.get(HubbleOptions.SERVER_PROTOCOL);
-        if (protocol != null && protocol.equals("https")) {
+        if ("https".equals(protocol)) {
             connection.setProtocol(protocol);
             String trustStoreFile = config.get(
                                     HubbleOptions.CLIENT_TRUSTSTORE_FILE);
diff --git a/hugegraph-loader/assembly/static/conf/hugegraph.truststore b/hugegraph-loader/assembly/static/conf/hugegraph.truststore
deleted file mode 100644
index 5b0828dc..00000000
Binary files a/hugegraph-loader/assembly/static/conf/hugegraph.truststore and /dev/null differ
diff --git a/hugegraph-loader/assembly/travis/conf/hugegraph.truststore b/hugegraph-loader/assembly/travis/conf/hugegraph.truststore
deleted file mode 100644
index 5b0828dc..00000000
Binary files a/hugegraph-loader/assembly/travis/conf/hugegraph.truststore and /dev/null differ
diff --git a/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/constant/Constants.java b/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/constant/Constants.java
index d2abeab9..563cd401 100644
--- a/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/constant/Constants.java
+++ b/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/constant/Constants.java
@@ -31,7 +31,7 @@ public final class Constants {
     public static final String HTTPS_PREFIX = "https://";
     public static final String JSON_SUFFIX = ".json";
     public static final String GROOVY_SCHEMA = "schema";
-    public static final String TRUST_STORE_FILE = "conf/hugegraph.truststore";
+    public static final String TRUST_STORE_PATH = "conf/hugegraph.truststore";
 
     public static final String FIELD_VERSION = "version";
     public static final String V1_STRUCT_VERSION = "1.0";
diff --git a/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/util/HugeClientHolder.java b/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/util/HugeClientHolder.java
index 31d21ddb..124b3bd9 100644
--- a/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/util/HugeClientHolder.java
+++ b/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/util/HugeClientHolder.java
@@ -20,7 +20,6 @@ package org.apache.hugegraph.loader.util;
 import java.nio.file.Paths;
 
 import org.apache.commons.lang3.StringUtils;
-
 import org.apache.hugegraph.driver.HugeClient;
 import org.apache.hugegraph.driver.HugeClientBuilder;
 import org.apache.hugegraph.exception.ServerException;
@@ -61,8 +60,7 @@ public final class HugeClientHolder {
                                     "The system property 'loader.home.path' " +
                                     "can't be null or empty when enable " +
                                     "https protocol");
-                    trustFile = Paths.get(homePath, Constants.TRUST_STORE_FILE)
-                                     .toString();
+                    trustFile = Paths.get(homePath, Constants.TRUST_STORE_PATH).toString();
                 } else {
                     trustFile = options.trustStoreFile;
                 }
diff --git a/hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/FileLoadTest.java b/hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/FileLoadTest.java
index 8a4eac1e..ad54a118 100644
--- a/hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/FileLoadTest.java
+++ b/hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/FileLoadTest.java
@@ -54,6 +54,7 @@ import org.apache.hugegraph.structure.graph.Vertex;
 import org.apache.hugegraph.structure.schema.PropertyKey;
 import org.apache.hugegraph.testutil.Assert;
 import org.apache.hugegraph.testutil.Whitebox;
+import org.apache.hugegraph.util.CommonUtil;
 import org.apache.hugegraph.util.LongEncoding;
 import org.junit.After;
 import org.junit.Before;
@@ -3043,6 +3044,8 @@ public class FileLoadTest extends LoadTest {
         ioUtil.write("vertex_person.csv",
                      "tiny,1,1,1",
                      "mary,2,2,2");
+
+        CommonUtil.downloadFileByUrl(FILE_URL, TRUST_STORE_PATH);
         String[] args = new String[]{
                 "-f", structPath("value_mapping/struct.json"),
                 "-s", configPath("value_mapping/schema.groovy"),
@@ -3050,7 +3053,7 @@ public class FileLoadTest extends LoadTest {
                 "-h", SERVER,
                 "-p", String.valueOf(HTTPS_PORT),
                 "--protocol", HTTPS_PROTOCOL,
-                "--trust-store-file", TRUST_STORE_FILE,
+                "--trust-store-file", TRUST_STORE_PATH,
                 "--trust-store-password", "hugegraph",
                 "--batch-insert-threads", "2",
                 "--test-mode", "true"
@@ -3060,7 +3063,7 @@ public class FileLoadTest extends LoadTest {
         HugeClient httpsClient = null;
         try {
             httpsClient = HugeClient.builder(HTTPS_URL, GRAPH)
-                                    .configSSL(TRUST_STORE_FILE, "hugegraph")
+                                    .configSSL(TRUST_STORE_PATH, "hugegraph")
                                     .build();
             List<Vertex> vertices = httpsClient.graph().listVertices();
             Assert.assertEquals(2, vertices.size());
@@ -3074,6 +3077,8 @@ public class FileLoadTest extends LoadTest {
         ioUtil.write("vertex_person.csv",
                      "marko,1,1,1",
                      "vadas,2,2,2");
+
+        CommonUtil.downloadFileByUrl(FILE_URL, TRUST_STORE_PATH);
         String[] args = new String[]{
                 "-f", structPath("value_mapping/struct.json"),
                 "-s", configPath("value_mapping/schema.groovy"),
@@ -3081,7 +3086,7 @@ public class FileLoadTest extends LoadTest {
                 "-h", SERVER,
                 "-p", String.valueOf(HTTPS_PORT),
                 "--protocol", HTTPS_PROTOCOL,
-                "--trust-store-file", TRUST_STORE_FILE,
+                "--trust-store-file", TRUST_STORE_PATH,
                 "--trust-store-password", "hugegraph",
                 "--batch-insert-threads", "2",
                 "--test-mode", "true"
@@ -3093,7 +3098,7 @@ public class FileLoadTest extends LoadTest {
         options.port = HTTPS_PORT;
         options.graph = GRAPH;
         options.protocol = HTTPS_PROTOCOL;
-        options.trustStoreFile = TRUST_STORE_FILE;
+        options.trustStoreFile = TRUST_STORE_PATH;
         options.trustStoreToken = "hugegraph";
 
         HugeClient httpsClient = null;
diff --git a/hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/LoadTest.java b/hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/LoadTest.java
index 1f597f79..0b14b2b1 100644
--- a/hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/LoadTest.java
+++ b/hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/LoadTest.java
@@ -29,7 +29,6 @@ import org.apache.hugegraph.driver.HugeClient;
 import org.apache.hugegraph.structure.constant.T;
 import org.apache.hugegraph.structure.graph.Edge;
 import org.apache.hugegraph.structure.graph.Vertex;
-
 import org.apache.hugegraph.testutil.Assert;
 
 public class LoadTest {
@@ -43,7 +42,9 @@ public class LoadTest {
     protected static final String URL = String.format("http://%s:%s", SERVER, PORT);
     protected static final String HTTPS_URL = String.format("https://%s:%s", SERVER, HTTPS_PORT);
     protected static final String HTTPS_PROTOCOL = "https";
-    protected static final String TRUST_STORE_FILE = "assembly/travis/conf/hugegraph.truststore";
+    protected static final String TRUST_STORE_PATH = "assembly/travis/conf/hugegraph.truststore";
+    protected static final String FILE_URL = "https://github.com/apache/incubator-hugegraph-doc/" +
+                                             "raw/binary/dist/toolchain/hugegraph.truststore";
     protected static final HugeClient CLIENT = HugeClient.builder(URL, GRAPH).build();
 
     public static String configPath(String fileName) {
diff --git a/hugegraph-tools/assembly/conf/hugegraph.truststore b/hugegraph-tools/assembly/conf/hugegraph.truststore
deleted file mode 100644
index 5b0828dc..00000000
Binary files a/hugegraph-tools/assembly/conf/hugegraph.truststore and /dev/null differ
diff --git a/hugegraph-tools/src/main/java/org/apache/hugegraph/base/ToolClient.java b/hugegraph-tools/src/main/java/org/apache/hugegraph/base/ToolClient.java
index a24a940f..86cea21f 100644
--- a/hugegraph-tools/src/main/java/org/apache/hugegraph/base/ToolClient.java
+++ b/hugegraph-tools/src/main/java/org/apache/hugegraph/base/ToolClient.java
@@ -34,12 +34,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 
 public class ToolClient {
 
-    private static final String DEFAULT_TRUST_STORE_FILE =
-                                "conf/hugegraph.truststore";
+    private static final String DEFAULT_TRUST_STORE_FILE = "conf/hugegraph.truststore";
     private static final String DEFAULT_TRUST_STORE_PASSWORD = "hugegraph";
 
-    private HugeClient client;
-    private ObjectMapper mapper;
+    private final HugeClient client;
+    private final ObjectMapper mapper;
 
     public ToolClient(ConnectionInfo info) {
         if (info.username == null) {
@@ -125,13 +124,13 @@ public class ToolClient {
 
     public static class ConnectionInfo {
 
-        private String url;
-        private String graph;
+        private final String url;
+        private final String graph;
         private String username;
         private String password;
-        private Integer timeout;
-        private String trustStoreFile;
-        private String trustStorePassword;
+        private final Integer timeout;
+        private final String trustStoreFile;
+        private final String trustStorePassword;
 
         public ConnectionInfo(String url, String graph,
                               String username, String password,