This is an automated email from the ASF dual-hosted git repository.
ming pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/incubator-hugegraph-computer.git
The following commit(s) were added to refs/heads/master by this push:
new a21a1916 refact(core): support auth config for computer task (#265)
a21a1916 is described below
commit a21a19163e232559300c9821ddf9ba31f14392b5
Author: diaohancai <[email protected]>
AuthorDate: Sun Oct 8 08:55:47 2023 +0800
refact(core): support auth config for computer task (#265)
* fix: hugegraph client authentication configuration
* chore: improve description
---------
Co-authored-by: diaohancai <[email protected]>
---
.../hugegraph/computer/core/config/ComputerOptions.java | 16 ++++++++++++++++
.../computer/core/output/hg/task/TaskManager.java | 4 +++-
.../computer/core/input/hg/HugeGraphFetcher.java | 4 +++-
.../computer/core/input/hg/HugeInputSplitFetcher.java | 5 ++++-
.../src/assembly/static/conf/computer.properties | 2 ++
.../hugegraph/computer/suite/unit/UnitTestBase.java | 13 +++++++------
6 files changed, 35 insertions(+), 9 deletions(-)
diff --git
a/computer-api/src/main/java/org/apache/hugegraph/computer/core/config/ComputerOptions.java
b/computer-api/src/main/java/org/apache/hugegraph/computer/core/config/ComputerOptions.java
index 33fba83d..cce7447d 100644
---
a/computer-api/src/main/java/org/apache/hugegraph/computer/core/config/ComputerOptions.java
+++
b/computer-api/src/main/java/org/apache/hugegraph/computer/core/config/ComputerOptions.java
@@ -645,6 +645,22 @@ public class ComputerOptions extends OptionHolder {
"hugegraph"
);
+ public static final ConfigOption<String> HUGEGRAPH_USERNAME =
+ new ConfigOption<>(
+ "hugegraph.username",
+ "The username of graph for authentication.",
+ null,
+ ""
+ );
+
+ public static final ConfigOption<String> HUGEGRAPH_PASSWORD =
+ new ConfigOption<>(
+ "hugegraph.password",
+ "The password of graph for authentication.",
+ null,
+ ""
+ );
+
public static final ConfigOption<String> TRANSPORT_SERVER_HOST =
new ConfigOption<>(
"transport.server_host",
diff --git
a/computer-api/src/main/java/org/apache/hugegraph/computer/core/output/hg/task/TaskManager.java
b/computer-api/src/main/java/org/apache/hugegraph/computer/core/output/hg/task/TaskManager.java
index 241ffdd9..cdeb95ed 100644
---
a/computer-api/src/main/java/org/apache/hugegraph/computer/core/output/hg/task/TaskManager.java
+++
b/computer-api/src/main/java/org/apache/hugegraph/computer/core/output/hg/task/TaskManager.java
@@ -56,7 +56,9 @@ public final class TaskManager {
this.config = config;
String url = config.get(ComputerOptions.HUGEGRAPH_URL);
String graph = config.get(ComputerOptions.HUGEGRAPH_GRAPH_NAME);
- this.client = new HugeClientBuilder(url, graph).build();
+ String username = config.get(ComputerOptions.HUGEGRAPH_USERNAME);
+ String password = config.get(ComputerOptions.HUGEGRAPH_PASSWORD);
+ this.client = new HugeClientBuilder(url, graph).configUser(username,
password).build();
// Try to make all batch threads running and don't wait for producer
this.batchSemaphore = new Semaphore(this.batchSemaphoreNum());
/*
diff --git
a/computer-core/src/main/java/org/apache/hugegraph/computer/core/input/hg/HugeGraphFetcher.java
b/computer-core/src/main/java/org/apache/hugegraph/computer/core/input/hg/HugeGraphFetcher.java
index e39f1481..813fd007 100644
---
a/computer-core/src/main/java/org/apache/hugegraph/computer/core/input/hg/HugeGraphFetcher.java
+++
b/computer-core/src/main/java/org/apache/hugegraph/computer/core/input/hg/HugeGraphFetcher.java
@@ -37,7 +37,9 @@ public class HugeGraphFetcher implements GraphFetcher {
public HugeGraphFetcher(Config config, InputSplitRpcService rpcService) {
String url = config.get(ComputerOptions.HUGEGRAPH_URL);
String graph = config.get(ComputerOptions.HUGEGRAPH_GRAPH_NAME);
- this.client = new HugeClientBuilder(url, graph).build();
+ String username = config.get(ComputerOptions.HUGEGRAPH_USERNAME);
+ String password = config.get(ComputerOptions.HUGEGRAPH_PASSWORD);
+ this.client = new HugeClientBuilder(url, graph).configUser(username,
password).build();
this.vertexFetcher = new HugeVertexFetcher(config, this.client);
this.edgeFetcher = new HugeEdgeFetcher(config, this.client);
this.rpcService = rpcService;
diff --git
a/computer-core/src/main/java/org/apache/hugegraph/computer/core/input/hg/HugeInputSplitFetcher.java
b/computer-core/src/main/java/org/apache/hugegraph/computer/core/input/hg/HugeInputSplitFetcher.java
index 49d99202..cd1654c9 100644
---
a/computer-core/src/main/java/org/apache/hugegraph/computer/core/input/hg/HugeInputSplitFetcher.java
+++
b/computer-core/src/main/java/org/apache/hugegraph/computer/core/input/hg/HugeInputSplitFetcher.java
@@ -38,8 +38,11 @@ public class HugeInputSplitFetcher implements
InputSplitFetcher {
this.config = config;
String url = config.get(ComputerOptions.HUGEGRAPH_URL);
String graph = config.get(ComputerOptions.HUGEGRAPH_GRAPH_NAME);
+ String username = config.get(ComputerOptions.HUGEGRAPH_USERNAME);
+ String password = config.get(ComputerOptions.HUGEGRAPH_PASSWORD);
int timeout = config.get(ComputerOptions.INPUT_SPLIT_FETCH_TIMEOUT);
- this.client = new HugeClientBuilder(url, graph).configTimeout(timeout)
+ this.client = new HugeClientBuilder(url, graph).configUser(username,
password)
+ .configTimeout(timeout)
.build();
}
diff --git a/computer-dist/src/assembly/static/conf/computer.properties
b/computer-dist/src/assembly/static/conf/computer.properties
index a2c780d4..c687b7eb 100644
--- a/computer-dist/src/assembly/static/conf/computer.properties
+++ b/computer-dist/src/assembly/static/conf/computer.properties
@@ -27,6 +27,8 @@ bsp.etcd_endpoints=http://127.0.0.1:2379
hugegraph.url=http://127.0.0.1:8080
hugegraph.name=hugegraph
+hugegraph.username=
+hugegraph.password=
algorithm.params_class=org.apache.hugegraph.computer.algorithm.centrality.pagerank.PageRankParams
diff --git
a/computer-test/src/main/java/org/apache/hugegraph/computer/suite/unit/UnitTestBase.java
b/computer-test/src/main/java/org/apache/hugegraph/computer/suite/unit/UnitTestBase.java
index 421b33b8..efc0703f 100644
---
a/computer-test/src/main/java/org/apache/hugegraph/computer/suite/unit/UnitTestBase.java
+++
b/computer-test/src/main/java/org/apache/hugegraph/computer/suite/unit/UnitTestBase.java
@@ -69,6 +69,8 @@ public class UnitTestBase {
"abcdefghijklmnopqrstuvxyz";
private static String URL;
private static String GRAPH;
+ private static String USERNAME;
+ private static String PASSWORD;
private static HugeClient CLIENT = null;
protected static void clearAll() {
@@ -121,11 +123,10 @@ public class UnitTestBase {
"defaultValue",
"src/main/resources/hdfs_input_test/struct.json");
- URL = ComputerOptions.HUGEGRAPH_URL
- .defaultValue();
-
- GRAPH = ComputerOptions.HUGEGRAPH_GRAPH_NAME
- .defaultValue();
+ URL = ComputerOptions.HUGEGRAPH_URL.defaultValue();
+ GRAPH = ComputerOptions.HUGEGRAPH_GRAPH_NAME.defaultValue();
+ USERNAME = ComputerOptions.HUGEGRAPH_USERNAME.defaultValue();
+ PASSWORD = ComputerOptions.HUGEGRAPH_PASSWORD.defaultValue();
Class.forName(IdType.class.getName());
// Don't forget to register options
@@ -286,7 +287,7 @@ public class UnitTestBase {
protected static synchronized HugeClient client() {
if (CLIENT == null) {
- CLIENT = HugeClient.builder(URL, GRAPH).build();
+ CLIENT = HugeClient.builder(URL, GRAPH).configUser(USERNAME,
PASSWORD).build();
}
return CLIENT;
}