Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): support graphspace #633

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b346b81
add GraphSpace related structres and APIs
Thespica Oct 15, 2024
62e04ca
add enums for HugeType
Thespica Oct 16, 2024
1c0b6fa
fix gs for client, remove unused manager
Thespica Oct 21, 2024
2d86424
adapt more gs-related field and constructor, and recoded them
Thespica Oct 23, 2024
137d87f
adapt gs for api/schema/*
Thespica Oct 23, 2024
198a089
adapt gs for some apis and tests
Thespica Oct 23, 2024
8dd679e
modify ci to enable gs-filter
Thespica Oct 23, 2024
b388817
update copyright
Thespica Oct 23, 2024
dd19092
enable server gs-filter
Thespica Oct 23, 2024
8b207b2
ci run all tests
Thespica Oct 24, 2024
abe45ce
refine ci test
Thespica Oct 24, 2024
cf171ce
refine ci server script
Thespica Oct 24, 2024
5ecbae6
refine ci rest conf
Thespica Oct 24, 2024
7bd6bc3
basic support gs filter
Thespica Nov 9, 2024
54211b8
remove redundante null parameter
Thespica Nov 9, 2024
ae8e62e
RestClient record core version
Thespica Nov 11, 2024
1e749b6
get supportGs by core version
Thespica Nov 11, 2024
229548e
close gs filter option
Thespica Nov 11, 2024
0dac10c
fix test to let client created by clone
Thespica Nov 11, 2024
140df68
fix params order when building client
Thespica Nov 13, 2024
f385e15
stop ci if test failed
Thespica Nov 13, 2024
269be6a
add default overload of graph space for client builder
Thespica Nov 14, 2024
fadf4e4
try update server's commit of loader-ci and sportk-connector-ci
Thespica Nov 15, 2024
6e1d76b
align default graph space name to DEFAULT(UPPER CASE)
Thespica Nov 15, 2024
9a205ff
restore format of rest-server.properties
Thespica Nov 15, 2024
71b5b32
restore ci server commit id
Thespica Nov 15, 2024
1bb75cd
align parameter name of test
Thespica Nov 15, 2024
75ad6ce
remove zh-ch documentation
Thespica Nov 15, 2024
2b8925b
add todo about be compatitable to server do not support gs
Thespica Nov 17, 2024
4b8a166
Merge branch 'master' into client-support-gs
imbajin Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/client-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ jobs:

- name: Prepare env and service
run: |
# TODO(@Thespica): test both servers of supporting gs and not supporting gs
# when the server supports gs
$TRAVIS_DIR/install-hugegraph-from-source.sh $COMMIT_ID

- name: Install Java ${{ matrix.JAVA_VERSION }} for client
Expand Down
24 changes: 14 additions & 10 deletions hugegraph-client/src/main/java/org/apache/hugegraph/api/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ public API(RestClient client) {
this.path = null;
}

protected static void checkOffset(long value) {
E.checkArgument(value >= 0, "Offset must be >= 0, but got: %s", value);
}

protected static void checkLimit(long value, String name) {
E.checkArgument(value > 0 || value == NO_LIMIT,
"%s must be > 0 or == %s, but got: %s",
name, NO_LIMIT, value);
}

protected static String joinPath(String... paths) {
return String.join(PATH_SPLITOR, paths);
}

public String path() {
E.checkState(this.path != null, "Path can't be null");
return this.path;
Expand All @@ -51,14 +65,4 @@ protected void path(String pathTemplate, Object... args) {
}

protected abstract String type();

protected static void checkOffset(long value) {
E.checkArgument(value >= 0, "Offset must be >= 0, but got: %s", value);
}

protected static void checkLimit(long value, String name) {
E.checkArgument(value > 0 || value == NO_LIMIT,
"%s must be > 0 or == %s, but got: %s",
name, NO_LIMIT, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

public class EdgeAPI extends GraphAPI {

public EdgeAPI(RestClient client, String graph) {
super(client, graph);
public EdgeAPI(RestClient client, String graphSpace, String graph) {
super(client, graphSpace, graph);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,16 @@

public abstract class GraphAPI extends API {

private static final String PATH = "graphs/%s/graph/%s";
private static final String PATH = "graphspaces/%s/graphs/%s/graph/%s";

private final String batchPath;

public GraphAPI(RestClient client, String graph) {
public GraphAPI(RestClient client, String graphSpace, String graph) {
super(client);
this.path(PATH, graph, this.type());
this.path(PATH, graphSpace, graph, this.type());
this.batchPath = String.join("/", this.path(), "batch");
}

public String batchPath() {
return this.batchPath;
}

public static String formatVertexId(Object id) {
return formatVertexId(id, false);
}
Expand Down Expand Up @@ -68,4 +64,8 @@ public static String formatProperties(Map<String, Object> properties) {
}
return JsonUtil.toJson(properties);
}

public String batchPath() {
return this.batchPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

public class VertexAPI extends GraphAPI {

public VertexAPI(RestClient client, String graph) {
super(client, graph);
public VertexAPI(RestClient client, String graphSpace, String graph) {
super(client, graphSpace, graph);
}

@Override
Expand Down Expand Up @@ -83,21 +83,21 @@ public int update(BatchOlapPropertyRequest request) {
}

public Vertex append(Vertex vertex) {
String id = formatVertexId(vertex.id());
String id = GraphAPI.formatVertexId(vertex.id());
Map<String, Object> params = ImmutableMap.of("action", "append");
RestResult result = this.client.put(this.path(), id, vertex, params);
return result.readObject(Vertex.class);
}

public Vertex eliminate(Vertex vertex) {
String id = formatVertexId(vertex.id());
String id = GraphAPI.formatVertexId(vertex.id());
Map<String, Object> params = ImmutableMap.of("action", "eliminate");
RestResult result = this.client.put(this.path(), id, vertex, params);
return result.readObject(Vertex.class);
}

public Vertex get(Object id) {
String vertexId = formatVertexId(id);
String vertexId = GraphAPI.formatVertexId(id);
RestResult result = this.client.get(this.path(), vertexId);
return result.readObject(Vertex.class);
}
Expand All @@ -115,7 +115,7 @@ public Vertices list(String label, Map<String, Object> properties,
boolean keepP, int offset, String page, int limit) {
checkOffset(offset);
checkLimit(limit, "Limit");
String props = formatProperties(properties);
String props = GraphAPI.formatProperties(properties);
Map<String, Object> params = new LinkedHashMap<>();
params.put("label", label);
params.put("properties", props);
Expand All @@ -128,7 +128,7 @@ public Vertices list(String label, Map<String, Object> properties,
}

public void delete(Object id) {
String vertexId = formatVertexId(id);
String vertexId = GraphAPI.formatVertexId(id);
this.client.delete(this.path(), vertexId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,19 @@ public class GraphsAPI extends API {
private static final String GRAPH_READ_MODE = "graph_read_mode";
private static final String CLEAR = "clear";
private static final String CONFIRM_MESSAGE = "confirm_message";
private static final String PATH = "graphspaces/%s/graphs";

public GraphsAPI(RestClient client) {
public GraphsAPI(RestClient client, String graphSpace) {
super(client);
this.path(this.type());
this.path(String.format(PATH, graphSpace));
}

private static String joinPath(String path, String graph) {
return String.join(DELIMITER, path, graph);
}

private static String joinPath(String path, String graph, String action) {
return String.join(DELIMITER, path, graph, action);
}

@Override
Expand Down Expand Up @@ -130,12 +139,4 @@ public GraphReadMode readMode(String graph) {
throw new InvalidResponseException("Invalid GraphReadMode value '%s'", value);
}
}

private static String joinPath(String path, String graph) {
return String.join(DELIMITER, path, graph);
}

private static String joinPath(String path, String graph, String action) {
return String.join(DELIMITER, path, graph, action);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,23 @@
import org.apache.hugegraph.api.API;
import org.apache.hugegraph.client.RestClient;
import org.apache.hugegraph.rest.RestResult;
import org.apache.hugegraph.structure.constant.HugeType;
import org.apache.hugegraph.structure.gremlin.Response;

public class CypherAPI extends API {

private static final String PATH = "graphs/%s/cypher";
private static final String PATH = "graphspaces/%s/graphs/%s/cypher";

public CypherAPI(RestClient client, String graph) {
public CypherAPI(RestClient client) {
super(client);
this.path(PATH, graph);
}

@Override
protected String type() {
return HugeType.CYPHER.string();
return PATH;
}

public Response post(String cypher) {
public Response post(String graphSpace, String graph, String cypher) {
this.path(type(), graphSpace, graph);
RestResult result = this.client.post(this.path(), cypher);
return result.readObject(Response.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ public Response post(GremlinRequest request) {
RestResult result = this.client.post(this.path(), request);
return result.readObject(Response.class);
}

public boolean isSupportGs() {
return client.isSupportGs();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.api.job;

import java.util.Map;

import org.apache.hugegraph.api.task.TaskAPI;
import org.apache.hugegraph.client.RestClient;
import org.apache.hugegraph.rest.RestResult;

public class CypherJobAPI extends JobAPI {

private static final String JOB_TYPE = "cypher";

public CypherJobAPI(RestClient client, String graphSpace, String graph) {
super(client, graphSpace, graph);
}

@Override
protected String jobType() {
return JOB_TYPE;
}

public long execute(String cypher) {
RestResult result = this.client.post(this.path(), cypher);
@SuppressWarnings("unchecked")
Map<String, Object> task = result.readObject(Map.class);
return TaskAPI.parseTaskId(task);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class GremlinJobAPI extends JobAPI {

private static final String JOB_TYPE = "gremlin";

public GremlinJobAPI(RestClient client, String graph) {
super(client, graph);
public GremlinJobAPI(RestClient client, String graphSpace, String graph) {
super(client, graphSpace, graph);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
public abstract class JobAPI extends API {

// For example: graphs/hugegraph/jobs/gremlin
private static final String PATH = "graphs/%s/%s/%s";
private static final String PATH = "graphspaces/%s/graphs/%s/%s/%s";

public JobAPI(RestClient client, String graph) {
public JobAPI(RestClient client, String graphSpace, String graph) {
super(client);
this.path(String.format(PATH, graph, this.type(), this.jobType()));
this.path(String.format(PATH, graphSpace, graph, this.type(), this.jobType()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class RebuildAPI extends JobAPI {

private static final String JOB_TYPE = "rebuild";

public RebuildAPI(RestClient client, String graph) {
super(client, graph);
public RebuildAPI(RestClient client, String graphSpace, String graph) {
super(client, graphSpace, graph);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

public class EdgeLabelAPI extends SchemaElementAPI {

public EdgeLabelAPI(RestClient client, String graph) {
super(client, graph);
public EdgeLabelAPI(RestClient client, String graphSpace, String graph) {
super(client, graphSpace, graph);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

public class IndexLabelAPI extends SchemaElementAPI {

public IndexLabelAPI(RestClient client, String graph) {
super(client, graph);
public IndexLabelAPI(RestClient client, String graphSpace, String graph) {
super(client, graphSpace, graph);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

public class PropertyKeyAPI extends SchemaElementAPI {

public PropertyKeyAPI(RestClient client, String graph) {
super(client, graph);
public PropertyKeyAPI(RestClient client, String graphSpace, String graph) {
super(client, graphSpace, graph);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

public class SchemaAPI extends API {

private static final String PATH = "graphs/%s/%s";
private static final String PATH = "graphspaces/%s/graphs/%s/%s";

public SchemaAPI(RestClient client, String graph) {
public SchemaAPI(RestClient client, String graphSpace, String graph) {
super(client);
this.path(PATH, graph, this.type());
this.path(PATH, graphSpace, graph, this.type());
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

public abstract class SchemaElementAPI extends API {

private static final String PATH = "graphs/%s/schema/%s";
private static final String PATH = "graphspaces/%s/graphs/%s/schema/%s";

public SchemaElementAPI(RestClient client, String graph) {
public SchemaElementAPI(RestClient client, String graphSpace, String graph) {
super(client);
this.path(PATH, graph, this.type());
this.path(PATH, graphSpace, graph, this.type());
}

protected abstract Object checkCreateOrUpdate(SchemaElement schemaElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

public class VertexLabelAPI extends SchemaElementAPI {

public VertexLabelAPI(RestClient client, String graph) {
super(client, graph);
public VertexLabelAPI(RestClient client, String graphSpace, String graph) {
super(client, graphSpace, graph);
}

@Override
Expand Down
Loading
Loading