Skip to content

Commit

Permalink
feat: update common version and remove jersey code (#538)
Browse files Browse the repository at this point in the history
* Update client-ci.yml

add on workflow_dispatch

* replace jersey with okhttp

* fix test error

* fix the problem that mockito can't mock final class

* fix error

* Update BaseClientTest.java

* https support && add licence header

* fix licence check error

* fix error

* fix licence check error

* fix error

* rename rest class && remove jersey dependency

* add workflow_dispatch

* add workflow_dispatch

* hubble error fix

* update okhttp version of hubble

* refactor class name

* add workflow_dispatch

* fix licence dependency check error

* feat: merge request

* chore(ci): add stage profile settings

* update common version and fix code

* fix

* fix

* update version

* fix spark-connector-ci

* fix spark-connector-ci

* fix spark-connector-ci

* update client version

* update client version

* fix license-checker

* code optimize

* remove useless dependency

* remove useless code

* fix licence check

* fix import & update api version

* remove redundant common import in hubble

* remove redundant lombok version

* remove useless code

* add comment

* rename id

* add encode test case

* add encode test case and fix code issue

* fix test error

* fix test error

* fix code issue

* fix code issue

* fix code issue

* update hg server commitId

* debug ci error

* revert commit ID & let it pass 100

* Update client-ci.yml

* tiny fix

---------

Co-authored-by: tianzy <tianzy@home.com>
Co-authored-by: imbajin <jin@apache.org>
  • Loading branch information
3 people authored Dec 5, 2023
1 parent b066b80 commit cb68bea
Show file tree
Hide file tree
Showing 30 changed files with 410 additions and 432 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/client-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "hugegraph-client-ci"

on:
workflow_dispatch:
push:
branches:
- master
Expand All @@ -23,11 +24,12 @@ jobs:
env:
USE_STAGE: 'true' # Whether to include the stage repository.
TRAVIS_DIR: hugegraph-client/assembly/travis
# TODO: replace it with the (latest - n) commit id (n >= 15)
COMMIT_ID: be6ee386b9939dc6bd6fcbdf2274b8acc3a0a314
strategy:
fail-fast: false
matrix:
JAVA_VERSION: ['8']
JAVA_VERSION: [ '8' ]
steps:
- name: Install JDK 8
uses: actions/setup-java@v3
Expand Down Expand Up @@ -71,4 +73,5 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: target/jacoco.xml
3 changes: 3 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
name: "CodeQL"

on:
workflow_dispatch:
push:
branches: [ master, release-* ]
pull_request:
# The branches below must be a subset of the branches above
# branches: [ master ] # enable in all PR
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/hubble-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "hugegraph-hubble-ci"

on:
workflow_dispatch:
push:
branches:
- master
Expand All @@ -22,7 +23,7 @@ on:

env:
TRAVIS_DIR: hugegraph-hubble/hubble-dist/assembly/travis
# TODO: need update it later (eed6103359fe40d2f1476fb8c56d9388c3111a99)
# TODO: replace it with the (latest - n) commit id (n >= 15)
COMMIT_ID: be6ee386b9939dc6bd6fcbdf2274b8acc3a0a314

jobs:
Expand Down Expand Up @@ -113,6 +114,7 @@ jobs:
hubble-dist/assembly/travis/run-api-test.sh
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.0.0
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: target/site/jacoco/*.xml
5 changes: 4 additions & 1 deletion .github/workflows/loader-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "hugegraph-loader-ci"

on:
workflow_dispatch:
push:
branches:
- master
Expand All @@ -25,6 +26,7 @@ jobs:
USE_STAGE: 'true' # Whether to include the stage repository.
TRAVIS_DIR: hugegraph-loader/assembly/travis
STATIC_DIR: hugegraph-loader/assembly/static
# TODO: replace it with the (latest - n) commit id (n >= 15)
COMMIT_ID: be6ee386b9939dc6bd6fcbdf2274b8acc3a0a314
DB_USER: root
DB_PASS: root
Expand Down Expand Up @@ -74,6 +76,7 @@ jobs:
mvn test -P kafka
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.0.0
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: target/jacoco.xml
4 changes: 3 additions & 1 deletion .github/workflows/tools-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: "hugegraph-tools-ci"
on:
workflow_dispatch:
push:
branches:
- master
Expand Down Expand Up @@ -56,6 +57,7 @@ jobs:
run: |
mvn test -Dtest=FuncTestSuite -pl hugegraph-tools -ntp
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.0.0
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: target/jacoco.xml
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ header: # `header` section is configurations for source codes license header.
- 'assembly/**'
- '.github/**/*'
- '**/target/*'
- 'hugegraph-client/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker'
# - 'hugegraph-hubble/hubble-fe/**'
comment: on-failure # on what condition license-eye will comment on the pull request, `on-failure`, `always`, `never`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ echo "gremlinserver.url=http://127.0.0.1:8282" >> ${REST_SERVER_CONFIG}

# start HugeGraphServer with https protocol
bin/init-store.sh
bin/start-hugegraph.sh
bin/start-hugegraph.sh || (cat logs/hugegraph-server.log && exit 1)
cd ../
19 changes: 9 additions & 10 deletions hugegraph-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
License for the specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand All @@ -30,15 +30,12 @@
<packaging>jar</packaging>

<name>${project.artifactId}</name>
<url>https://github.com/apache/incubator-hugegraph-toolchain/tree/master/hugegraph-client</url>
<url>https://github.com/apache/hugegraph-toolchain/tree/master/hugegraph-client</url>
<description>
hugegraph-client is a Java-written client of HugeGraph, providing
operations of graph, schema, gremlin, variables and traversals etc.
</description>

<properties>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.hugegraph</groupId>
Expand All @@ -48,15 +45,17 @@
<groupId>org.lz4</groupId>
<artifactId>lz4-java</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<optional>true</optional>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public User get(Object id) {
}

public UserRole getUserRole(Object id) {
String idEncoded = RestClient.encode(formatEntityId(id));
String path = String.join("/", this.path(), idEncoded, "role");
String formattedId = formatEntityId(id);
String path = String.join("/", this.path(), formattedId, "role");
RestResult result = this.client.get(path);
return result.readObject(UserRole.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.apache.hugegraph.client.RestClient;
import org.apache.hugegraph.exception.NotAllCreatedException;
import org.apache.hugegraph.rest.RestHeaders;
import org.apache.hugegraph.rest.RestResult;
import org.apache.hugegraph.structure.constant.Direction;
import org.apache.hugegraph.structure.constant.HugeType;
Expand All @@ -32,8 +33,6 @@

import com.google.common.collect.ImmutableMap;

import jakarta.ws.rs.core.MultivaluedHashMap;

public class EdgeAPI extends GraphAPI {

public EdgeAPI(RestClient client, String graph) {
Expand All @@ -51,12 +50,9 @@ public Edge create(Edge edge) {
}

public List<String> create(List<Edge> edges, boolean checkVertex) {
MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>();
headers.putSingle("Content-Encoding", BATCH_ENCODING);
Map<String, Object> params = ImmutableMap.of("check_vertex",
checkVertex);
RestResult result = this.client.post(this.batchPath(), edges,
headers, params);
RestHeaders headers = new RestHeaders().add(RestHeaders.CONTENT_ENCODING, BATCH_ENCODING);
Map<String, Object> params = ImmutableMap.of("check_vertex", checkVertex);
RestResult result = this.client.post(this.batchPath(), edges, headers, params);
List<String> ids = result.readList(String.class);
if (edges.size() != ids.size()) {
throw new NotAllCreatedException("Not all edges are successfully created, " +
Expand All @@ -68,10 +64,8 @@ public List<String> create(List<Edge> edges, boolean checkVertex) {

public List<Edge> update(BatchEdgeRequest request) {
this.client.checkApiVersion("0.45", "batch property update");
MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>();
headers.putSingle("Content-Encoding", BATCH_ENCODING);
RestResult result = this.client.put(this.batchPath(), null,
request, headers);
RestHeaders headers = new RestHeaders().add(RestHeaders.CONTENT_ENCODING, BATCH_ENCODING);
RestResult result = this.client.put(this.batchPath(), null, request, headers);
return result.readList(this.type(), Edge.class);
}

Expand All @@ -98,11 +92,9 @@ public Edges list(int limit) {
return this.list(null, null, null, null, 0, null, limit);
}

public Edges list(Object vertexId, Direction direction,
String label, Map<String, Object> properties,
int offset, String page, int limit) {
return this.list(vertexId, direction, label, properties, false,
offset, page, limit);
public Edges list(Object vertexId, Direction direction, String label,
Map<String, Object> properties, int offset, String page, int limit) {
return this.list(vertexId, direction, label, properties, false, offset, page, limit);
}

public Edges list(Object vertexId, Direction direction, String label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
import java.util.Map;
import java.util.UUID;

import org.glassfish.jersey.uri.UriComponent;
import org.glassfish.jersey.uri.UriComponent.Type;

import org.apache.hugegraph.api.API;
import org.apache.hugegraph.client.RestClient;
import org.apache.hugegraph.util.E;
Expand Down Expand Up @@ -61,25 +58,14 @@ public static String formatVertexId(Object id, boolean allowNull) {
id = id.toString();
}
E.checkArgument(id instanceof String || id instanceof Number,
"The vertex id must be either String or " +
"Number, but got '%s'", id);
"The vertex id must be either String or Number, but got '%s'", id);
return (uuid ? "U" : "") + JsonUtil.toJson(id);
}

public static String formatProperties(Map<String, Object> properties) {
if (properties == null) {
return null;
}
String json = JsonUtil.toJson(properties);
/*
* Don't use UrlEncoder.encode, it encoded the space as `+`,
* which will invalidate the jersey's automatic decoding
* because it considers the space to be encoded as `%2F`
*/
return encode(json);
}

public static String encode(String raw) {
return UriComponent.encode(raw, Type.QUERY_PARAM_SPACE_ENCODED);
return JsonUtil.toJson(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.apache.hugegraph.client.RestClient;
import org.apache.hugegraph.exception.InvalidResponseException;
import org.apache.hugegraph.exception.NotAllCreatedException;
import org.apache.hugegraph.rest.RestHeaders;
import org.apache.hugegraph.rest.RestResult;
import org.apache.hugegraph.structure.constant.HugeType;
import org.apache.hugegraph.structure.graph.BatchOlapPropertyRequest;
import org.apache.hugegraph.structure.graph.BatchVertexRequest;
Expand All @@ -32,10 +34,6 @@

import com.google.common.collect.ImmutableMap;

import jakarta.ws.rs.core.MultivaluedHashMap;

import org.apache.hugegraph.rest.RestResult;

public class VertexAPI extends GraphAPI {

public VertexAPI(RestClient client, String graph) {
Expand All @@ -53,10 +51,8 @@ public Vertex create(Vertex vertex) {
}

public List<Object> create(List<Vertex> vertices) {
MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>();
headers.putSingle("Content-Encoding", BATCH_ENCODING);
RestResult result = this.client.post(this.batchPath(), vertices,
headers);
RestHeaders headers = new RestHeaders().add(RestHeaders.CONTENT_ENCODING, BATCH_ENCODING);
RestResult result = this.client.post(this.batchPath(), vertices, headers);
List<Object> ids = result.readList(Object.class);
if (vertices.size() != ids.size()) {
throw new NotAllCreatedException("Not all vertices are successfully created, " +
Expand All @@ -68,17 +64,14 @@ public List<Object> create(List<Vertex> vertices) {

public List<Vertex> update(BatchVertexRequest request) {
this.client.checkApiVersion("0.45", "batch property update");
MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>();
headers.putSingle("Content-Encoding", BATCH_ENCODING);
RestResult result = this.client.put(this.batchPath(), null,
request, headers);
RestHeaders headers = new RestHeaders().add(RestHeaders.CONTENT_ENCODING, BATCH_ENCODING);
RestResult result = this.client.put(this.batchPath(), null, request, headers);
return result.readList(this.type(), Vertex.class);
}

public int update(BatchOlapPropertyRequest request) {
this.client.checkApiVersion("0.59", "olap property batch update");
MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>();
headers.putSingle("Content-Encoding", BATCH_ENCODING);
RestHeaders headers = new RestHeaders().add(RestHeaders.CONTENT_ENCODING, BATCH_ENCODING);
String path = String.join("/", this.path(), "olap/batch");
RestResult result = this.client.put(path, null, request, headers);
Object size = result.readObject(Map.class).get("size");
Expand Down
Loading

0 comments on commit cb68bea

Please sign in to comment.