Skip to content
This repository was archived by the owner on Dec 28, 2025. It is now read-only.

Commit 6a05f0f

Browse files
zhoneyjaveme
andauthored
adapt for dynamically add/remove graph (#138)
Change-Id: I005fba5a131f55820dbd1d702eb5ef812acd132f Co-authored-by: Jermy Li <javaloveme@gmail.com>
1 parent cff2c65 commit 6a05f0f

File tree

15 files changed

+500
-116
lines changed

15 files changed

+500
-116
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-20.04
1818
env:
1919
TRAVIS_DIR: assembly/travis
20-
COMMIT_ID: 2dd2d7c3fd7cb42cd7338d70a73e04b0c5604487
20+
COMMIT_ID: 1d031c5905cbef008dd5fb468576b0e6a9445181
2121
steps:
2222
- name: Install JDK 8
2323
uses: actions/setup-java@v2
@@ -43,7 +43,7 @@ jobs:
4343
4444
- name: Prepare env and service
4545
run: |
46-
$TRAVIS_DIR/install-hugegraph-from-source.sh $COMMIT_ID | grep -v "Downloading\|Downloaded"
46+
$TRAVIS_DIR/install-hugegraph-from-source.sh $COMMIT_ID
4747
4848
- name: Run test
4949
run: |

BCLOUD

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

assembly/travis/conf/gremlin-server.yaml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
scriptEvaluationTimeout: 30000
77

88
channelizer: org.apache.tinkerpop.gremlin.server.channel.WsAndHttpChannelizer
9+
# don't set graph at here, this happens after support for dynamically adding graph
910
graphs: {
10-
hugegraph: conf/hugegraph.properties
1111
}
1212
scriptEngines: {
1313
gremlin-groovy: {
@@ -17,16 +17,30 @@ scriptEngines: {
1717
org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {
1818
classImports: [
1919
java.lang.Math,
20+
com.baidu.hugegraph.backend.id.IdGenerator,
2021
com.baidu.hugegraph.type.define.Directions,
21-
com.baidu.hugegraph.traversal.algorithm.CustomizePathsTraverser,
22+
com.baidu.hugegraph.type.define.NodeRole,
23+
com.baidu.hugegraph.traversal.algorithm.CollectionPathsTraverser,
24+
com.baidu.hugegraph.traversal.algorithm.CountTraverser,
2225
com.baidu.hugegraph.traversal.algorithm.CustomizedCrosspointsTraverser,
26+
com.baidu.hugegraph.traversal.algorithm.CustomizePathsTraverser,
2327
com.baidu.hugegraph.traversal.algorithm.FusiformSimilarityTraverser,
2428
com.baidu.hugegraph.traversal.algorithm.HugeTraverser,
29+
com.baidu.hugegraph.traversal.algorithm.JaccardSimilarTraverser,
30+
com.baidu.hugegraph.traversal.algorithm.KneighborTraverser,
31+
com.baidu.hugegraph.traversal.algorithm.KoutTraverser,
32+
com.baidu.hugegraph.traversal.algorithm.MultiNodeShortestPathTraverser,
2533
com.baidu.hugegraph.traversal.algorithm.NeighborRankTraverser,
2634
com.baidu.hugegraph.traversal.algorithm.PathsTraverser,
2735
com.baidu.hugegraph.traversal.algorithm.PersonalRankTraverser,
36+
com.baidu.hugegraph.traversal.algorithm.SameNeighborTraverser,
2837
com.baidu.hugegraph.traversal.algorithm.ShortestPathTraverser,
38+
com.baidu.hugegraph.traversal.algorithm.SingleSourceShortestPathTraverser,
2939
com.baidu.hugegraph.traversal.algorithm.SubGraphTraverser,
40+
com.baidu.hugegraph.traversal.algorithm.TemplatePathsTraverser,
41+
com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep,
42+
com.baidu.hugegraph.traversal.algorithm.steps.RepeatEdgeStep,
43+
com.baidu.hugegraph.traversal.algorithm.steps.WeightedEdgeStep,
3044
com.baidu.hugegraph.traversal.optimize.Text,
3145
com.baidu.hugegraph.traversal.optimize.TraversalUtil,
3246
com.baidu.hugegraph.util.DateUtil
@@ -40,12 +54,6 @@ scriptEngines: {
4054
}
4155
}
4256
serializers:
43-
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0,
44-
config: {
45-
serializeResultToString: false,
46-
ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry]
47-
}
48-
}
4957
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1,
5058
config: {
5159
serializeResultToString: false,
@@ -72,7 +80,7 @@ serializers:
7280
}
7381
metrics: {
7482
consoleReporter: {enabled: false, interval: 180000},
75-
csvReporter: {enabled: true, interval: 180000, fileName: /tmp/gremlin-server-metrics.csv},
83+
csvReporter: {enabled: false, interval: 180000, fileName: ./metrics/gremlin-server-metrics.csv},
7684
jmxReporter: {enabled: false},
7785
slf4jReporter: {enabled: false, interval: 180000},
7886
gangliaReporter: {enabled: false, interval: 180000, addressingMode: MULTICAST},

assembly/travis/conf/rest-server.properties

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,39 @@ restserver.url=http://127.0.0.1:8080
33
# gremlin server url, need to be consistent with host and port in gremlin-server.yaml
44
#gremlinserver.url=http://127.0.0.1:8182
55

6-
# graphs list with pair NAME:CONF_PATH
7-
graphs=[hugegraph:conf/hugegraph.properties]
6+
graphs=./conf/graphs
87

9-
# authentication
8+
# The maximum thread ratio for batch writing, only take effect if the batch.max_write_threads is 0
9+
batch.max_write_ratio=80
10+
batch.max_write_threads=0
11+
12+
# authentication configs
13+
# choose 'com.baidu.hugegraph.auth.StandardAuthenticator' or 'com.baidu.hugegraph.auth.ConfigAuthenticator'
1014
auth.authenticator=com.baidu.hugegraph.auth.StandardAuthenticator
15+
16+
# for StandardAuthenticator mode
17+
#auth.graph_store=hugegraph
18+
# auth client config
19+
#auth.remote_url=127.0.0.1:8899,127.0.0.1:8898,127.0.0.1:8897
20+
21+
# for ConfigAuthenticator mode
1122
#auth.admin_token=
1223
#auth.user_tokens=[]
24+
25+
# rpc group configs of multi graph servers
26+
# rpc server configs
27+
rpc.server_host=127.0.0.1
28+
rpc.server_port=8090
29+
#rpc.server_timeout=30
30+
31+
# rpc client configs (like enable to keep cache consistency)
32+
rpc.remote_url=127.0.0.1:8090
33+
#rpc.client_connect_timeout=20
34+
#rpc.client_reconnect_period=10
35+
#rpc.client_read_timeout=40
36+
#rpc.client_retries=3
37+
#rpc.client_load_balancer=consistentHash
38+
39+
# lightweight load balancing (beta)
40+
server.id=server-1
41+
server.role=master

assembly/travis/install-hugegraph-from-source.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,34 @@ fi
99

1010
COMMIT_ID=$1
1111
HUGEGRAPH_GIT_URL="https://github.com/hugegraph/hugegraph.git"
12+
GIT_DIR=hugegraph
1213

14+
# download code and compile
1315
git clone --depth 100 ${HUGEGRAPH_GIT_URL}
14-
cd hugegraph
16+
cd "${GIT_DIR}"
1517
git checkout ${COMMIT_ID}
1618
mvn package -DskipTests
17-
mv hugegraph-*.tar.gz ../
19+
20+
TAR=$(echo hugegraph-*.tar.gz)
21+
tar -zxvf "${TAR}" -C ../
1822
cd ../
19-
rm -rf hugegraph
20-
tar -zxvf hugegraph-*.tar.gz
23+
rm -rf "${GIT_DIR}"
2124

25+
HTTP_SERVER_DIR=$(echo hugegraph-*)
2226
HTTPS_SERVER_DIR="hugegraph_https"
23-
mkdir ${HTTPS_SERVER_DIR}
24-
cp -r hugegraph-*/. ${HTTPS_SERVER_DIR}
25-
cd "$(find hugegraph-* | head -1)"
26-
cp ../$TRAVIS_DIR/conf/* conf
27+
28+
cp -r "${HTTP_SERVER_DIR}" "${HTTPS_SERVER_DIR}"
29+
30+
# config auth options just for http server (must keep '/.')
31+
cp -rf "${TRAVIS_DIR}"/conf/. "${HTTP_SERVER_DIR}"/conf/
32+
2733
# start HugeGraphServer with http protocol
34+
cd "${HTTP_SERVER_DIR}"
2835
echo -e "pa" | bin/init-store.sh || exit 1
2936
bin/start-hugegraph.sh || exit 1
3037

31-
cd ../${HTTPS_SERVER_DIR}
38+
# config options for https server
39+
cd ../"${HTTPS_SERVER_DIR}"
3240
REST_SERVER_CONFIG="conf/rest-server.properties"
3341
GREMLIN_SERVER_CONFIG="conf/gremlin-server.yaml"
3442
sed -i "s?http://127.0.0.1:8080?https://127.0.0.1:8443?g" "$REST_SERVER_CONFIG"

assembly/travis/install-hugegraph-from-tar.sh

Lines changed: 0 additions & 69 deletions
This file was deleted.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.baidu.hugegraph</groupId>
77
<artifactId>hugegraph-client</artifactId>
8-
<version>2.0.0</version>
8+
<version>2.0.1</version>
99
<packaging>jar</packaging>
1010

1111
<name>hugegraph-client</name>
@@ -113,7 +113,7 @@
113113
<manifestEntries>
114114
<!-- Must be on one line, otherwise the automatic
115115
upgrade script cannot replace the version number -->
116-
<Implementation-Version>1.9.4.0</Implementation-Version>
116+
<Implementation-Version>2.0.1.0</Implementation-Version>
117117
</manifestEntries>
118118
</archive>
119119
</configuration>

src/main/java/com/baidu/hugegraph/api/graphs/GraphsAPI.java

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
import java.util.List;
2323
import java.util.Map;
2424

25+
import javax.ws.rs.core.HttpHeaders;
26+
import javax.ws.rs.core.MediaType;
27+
import javax.ws.rs.core.MultivaluedHashMap;
28+
import javax.ws.rs.core.MultivaluedMap;
29+
30+
import org.apache.commons.lang3.StringUtils;
31+
2532
import com.baidu.hugegraph.api.API;
2633
import com.baidu.hugegraph.client.RestClient;
2734
import com.baidu.hugegraph.exception.InvalidResponseException;
@@ -33,6 +40,13 @@
3340

3441
public class GraphsAPI extends API {
3542

43+
private static final String DELIMITER = "/";
44+
private static final String MODE = "mode";
45+
private static final String GRAPH_READ_MODE = "graph_read_mode";
46+
private static final String CLEAR = "clear";
47+
48+
private static final String CONFIRM_MESSAGE = "confirm_message";
49+
3650
public GraphsAPI(RestClient client) {
3751
super(client);
3852
this.path(this.type());
@@ -43,6 +57,21 @@ protected String type() {
4357
return HugeType.GRAPHS.string();
4458
}
4559

60+
@SuppressWarnings("unchecked")
61+
public Map<String, String> create(String name, String cloneGraphName,
62+
String configText) {
63+
this.client.checkApiVersion("0.67", "dynamic graph add");
64+
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
65+
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
66+
Map<String, Object> params = null;
67+
if (StringUtils.isNotEmpty(cloneGraphName)) {
68+
params = ImmutableMap.of("clone_graph_name", cloneGraphName);
69+
}
70+
RestResult result = this.client.post(joinPath(this.path(), name),
71+
configText, headers, params);
72+
return result.readObject(Map.class);
73+
}
74+
4675
@SuppressWarnings("unchecked")
4776
public Map<String, String> get(String name) {
4877
RestResult result = this.client.get(this.path(), name);
@@ -54,19 +83,28 @@ public List<String> list() {
5483
return result.readList(this.type(), String.class);
5584
}
5685

86+
public void clear(String graph, String message) {
87+
this.client.delete(joinPath(this.path(), graph, CLEAR),
88+
ImmutableMap.of(CONFIRM_MESSAGE, message));
89+
}
90+
91+
public void drop(String graph, String message) {
92+
this.client.checkApiVersion("0.67", "dynamic graph delete");
93+
this.client.delete(joinPath(this.path(), graph),
94+
ImmutableMap.of(CONFIRM_MESSAGE, message));
95+
}
96+
5797
public void mode(String graph, GraphMode mode) {
58-
String path = String.join("/", this.path(), graph);
5998
// NOTE: Must provide id for PUT. If use "graph/mode", "/" will
6099
// be encoded to "%2F". So use "mode" here although inaccurate.
61-
this.client.put(path, "mode", mode);
100+
this.client.put(joinPath(this.path(), graph, MODE), null, mode);
62101
}
63102

64103
public GraphMode mode(String graph) {
65-
String path = String.join("/", this.path(), graph);
66-
RestResult result = this.client.get(path, "mode");
104+
RestResult result = this.client.get(joinPath(this.path(), graph), MODE);
67105
@SuppressWarnings("unchecked")
68106
Map<String, String> mode = result.readObject(Map.class);
69-
String value = mode.get("mode");
107+
String value = mode.get(MODE);
70108
if (value == null) {
71109
throw new InvalidResponseException(
72110
"Invalid response, expect 'mode' in response");
@@ -81,20 +119,20 @@ public GraphMode mode(String graph) {
81119

82120
public void readMode(String graph, GraphReadMode readMode) {
83121
this.client.checkApiVersion("0.59", "graph read mode");
84-
String path = String.join("/", this.path(), graph);
85122
// NOTE: Must provide id for PUT. If use "graph/graph_read_mode", "/"
86123
// will be encoded to "%2F". So use "graph_read_mode" here although
87124
// inaccurate.
88-
this.client.put(path, "graph_read_mode", readMode);
125+
this.client.put(joinPath(this.path(), graph, GRAPH_READ_MODE),
126+
null, readMode);
89127
}
90128

91129
public GraphReadMode readMode(String graph) {
92130
this.client.checkApiVersion("0.59", "graph read mode");
93-
String path = String.join("/", this.path(), graph);
94-
RestResult result = this.client.get(path, "graph_read_mode");
131+
RestResult result = this.client.get(joinPath(this.path(), graph),
132+
GRAPH_READ_MODE);
95133
@SuppressWarnings("unchecked")
96134
Map<String, String> readMode = result.readObject(Map.class);
97-
String value = readMode.get("graph_read_mode");
135+
String value = readMode.get(GRAPH_READ_MODE);
98136
if (value == null) {
99137
throw new InvalidResponseException(
100138
"Invalid response, expect 'graph_read_mode' in response");
@@ -107,9 +145,11 @@ public GraphReadMode readMode(String graph) {
107145
}
108146
}
109147

110-
public void clear(String graph, String message) {
111-
String path = String.join("/", this.path(), graph, "clear");
112-
this.client.delete(path,
113-
ImmutableMap.of("confirm_message", message));
148+
private static String joinPath(String path, String graph) {
149+
return String.join(DELIMITER, path, graph);
150+
}
151+
152+
private static String joinPath(String path, String graph, String action) {
153+
return String.join(DELIMITER, path, graph, action);
114154
}
115155
}

0 commit comments

Comments
 (0)