javeme commented on code in PR #508:
URL:
https://github.com/apache/incubator-hugegraph-toolchain/pull/508#discussion_r1320086105
##########
hugegraph-client/src/main/java/org/apache/hugegraph/api/graph/EdgeAPI.java:
##########
@@ -68,29 +68,30 @@ 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,
+// MultivaluedHashMap<String, Object> headers = new
MultivaluedHashMap<>();
+// headers.putSingle("Content-Encoding", BATCH_ENCODING);
+ Headers headers = new Headers.Builder().add("Content-Encoding",
BATCH_ENCODING).build();
Review Comment:
define a const?
##########
hugegraph-client/src/main/java/org/apache/hugegraph/api/graph/EdgeAPI.java:
##########
@@ -46,16 +45,17 @@ protected String type() {
}
public Edge create(Edge edge) {
- RestResult result = this.client.post(this.path(), edge);
+ OkhttpRestResult result = this.client.post(this.path(), edge);
return result.readObject(Edge.class);
}
public List<String> create(List<Edge> edges, boolean checkVertex) {
- MultivaluedHashMap<String, Object> headers = new
MultivaluedHashMap<>();
- headers.putSingle("Content-Encoding", BATCH_ENCODING);
+// MultivaluedHashMap<String, Object> headers = new
MultivaluedHashMap<>();
+// headers.putSingle("Content-Encoding", BATCH_ENCODING);
Review Comment:
ditto
##########
hugegraph-client/src/main/java/org/apache/hugegraph/api/auth/UserAPI.java:
##########
@@ -40,32 +40,33 @@ protected String type() {
}
public User create(User user) {
- RestResult result = this.client.post(this.path(), user);
+ OkhttpRestResult result = this.client.post(this.path(), user);
return result.readObject(User.class);
}
public User get(Object id) {
- RestResult result = this.client.get(this.path(), formatEntityId(id));
+ OkhttpRestResult result = this.client.get(this.path(),
formatEntityId(id));
return result.readObject(User.class);
}
public UserRole getUserRole(Object id) {
- String idEncoded = RestClient.encode(formatEntityId(id));
+// String idEncoded = RestClient.encode(formatEntityId(id));
Review Comment:
can we remove the unused code
##########
hugegraph-client/src/main/java/org/apache/hugegraph/rest/OkhttpRestResult.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.rest;
+
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.Module;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.SneakyThrows;
+import okhttp3.Headers;
+import okhttp3.Response;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class OkhttpRestResult {
Review Comment:
don't need to Okhttp prefix
##########
hugegraph-client/src/main/java/org/apache/hugegraph/rest/OkhttpRestClient.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.rest;
+
+import okhttp3.Headers;
+
+import java.util.Map;
+
+public interface OkhttpRestClient {
Review Comment:
don't need to Okhttp prefix, we expect to keep the same interface name
##########
hugegraph-client/src/main/java/org/apache/hugegraph/api/graph/EdgeAPI.java:
##########
@@ -68,29 +68,30 @@ 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,
+// MultivaluedHashMap<String, Object> headers = new
MultivaluedHashMap<>();
+// headers.putSingle("Content-Encoding", BATCH_ENCODING);
Review Comment:
ditto
##########
hugegraph-client/src/main/java/org/apache/hugegraph/rest/OkhttpAbstractRestClient.java:
##########
@@ -0,0 +1,449 @@
+/*
+ * 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.rest;
+
+import com.google.common.collect.ImmutableMap;
+import lombok.SneakyThrows;
+import okhttp3.*;
+import okio.BufferedSink;
+import okio.GzipSink;
+import okio.Okio;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hugegraph.util.JsonUtil;
+
+import javax.net.ssl.*;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.security.KeyStore;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+public abstract class OkhttpAbstractRestClient implements OkhttpRestClient {
+
+ private OkHttpClient client;
+
+ private String baseUrl;
+
+ public OkhttpAbstractRestClient(String url, int timeout) {
+ this(url, OkhttpConfig.builder()
+ .timeout(timeout)
+ .build());
+ }
+
+ public OkhttpAbstractRestClient(String url, String user, String password,
+ Integer timeout) {
+ this(url, OkhttpConfig.builder()
+ .user(user).password(password)
+ .timeout(timeout)
+ .build());
+ }
+
+ public OkhttpAbstractRestClient(String url, int timeout,
+ int maxTotal, int maxPerRoute) {
+ this(url, null, null, timeout, maxTotal, maxPerRoute);
+ }
+
+ public OkhttpAbstractRestClient(String url, int timeout, int idleTime,
+ int maxTotal, int maxPerRoute) {
+ this(url, OkhttpConfig.builder()
+ .idleTime(idleTime)
+ .timeout(timeout)
+ .maxTotal(maxTotal)
+ .maxPerRoute(maxPerRoute)
+ .build());
+ }
+
+ public OkhttpAbstractRestClient(String url, String user, String password,
+ int timeout, int maxTotal, int
maxPerRoute) {
+ this(url, OkhttpConfig.builder()
+ .user(user).password(password)
+ .timeout(timeout)
+ .maxTotal(maxTotal)
+ .maxPerRoute(maxPerRoute)
+ .build());
+ }
+
+ public OkhttpAbstractRestClient(String url, String user, String password,
+ int timeout, int maxTotal, int maxPerRoute,
+ String trustStoreFile,
+ String trustStorePassword) {
+ this(url, OkhttpConfig.builder()
+ .user(user).password(password)
+ .timeout(timeout)
+ .maxTotal(maxTotal)
+ .maxPerRoute(maxPerRoute)
+ .trustStoreFile(trustStoreFile)
+ .trustStorePassword(trustStorePassword)
+ .build());
+ }
+
+ public OkhttpAbstractRestClient(String url, String token, Integer timeout)
{
+ this(url, OkhttpConfig.builder()
+ .token(token)
+ .timeout(timeout)
+ .build());
+ }
+
+ public OkhttpAbstractRestClient(String url, String token, Integer timeout,
+ Integer maxTotal, Integer maxPerRoute) {
+ this(url,OkhttpConfig.builder()
+ .token(token)
+ .timeout(timeout)
+ .maxTotal(maxTotal)
+ .maxPerRoute(maxPerRoute)
+ .build());
+ }
+
+ public OkhttpAbstractRestClient(String url, String token, Integer timeout,
+ Integer maxTotal, Integer maxPerRoute,
+ String trustStoreFile,
+ String trustStorePassword) {
+ this(url,OkhttpConfig.builder()
+ .token(token)
+ .timeout(timeout)
+ .maxTotal(maxTotal)
+ .maxPerRoute(maxPerRoute)
+ .trustStoreFile(trustStoreFile)
+ .trustStorePassword(trustStorePassword)
+ .build());
+ }
+
+ public OkhttpAbstractRestClient(String url, OkhttpConfig okhttpConfig) {
+ this.baseUrl = url;
+ this.client = getOkhttpClient(okhttpConfig);
+ }
+
+ private OkHttpClient getOkhttpClient(OkhttpConfig okhttpConfig) {
+ OkHttpClient.Builder builder = new OkHttpClient.Builder();
+
+ if(okhttpConfig.getTimeout()!=null) {
+ builder.connectTimeout(okhttpConfig.getTimeout(),
TimeUnit.MILLISECONDS)
+ .readTimeout(okhttpConfig.getTimeout(),
TimeUnit.MILLISECONDS);
+ }
+
+ if(okhttpConfig.getIdleTime()!=null) {
+ ConnectionPool connectionPool = new ConnectionPool(5,
okhttpConfig.getIdleTime(), TimeUnit.MILLISECONDS);
+ builder.connectionPool(connectionPool);
+ }
+
+
+ //auth
Review Comment:
can we add more details for comments
##########
pom.xml:
##########
@@ -151,17 +151,35 @@
<!-- submodules will not inherit the dependencies unless they address it
-->
<dependencyManagement>
<dependencies>
- <dependency>
- <groupId>org.glassfish.jersey</groupId>
- <artifactId>jersey-bom</artifactId>
- <version>${jersey.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
+<!-- <dependency>-->
+<!-- <groupId>org.glassfish.jersey</groupId>-->
+<!-- <artifactId>jersey-bom</artifactId>-->
+<!-- <version>${jersey.version}</version>-->
+<!-- <type>pom</type>-->
+<!-- <scope>import</scope>-->
+<!-- </dependency>-->
Review Comment:
we can remove all the unused code
##########
hugegraph-client/src/main/java/org/apache/hugegraph/api/graph/VertexAPI.java:
##########
@@ -68,19 +66,21 @@ 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,
+// MultivaluedHashMap<String, Object> headers = new
MultivaluedHashMap<>();
+// headers.putSingle("Content-Encoding", BATCH_ENCODING);
+ Headers headers = new Headers.Builder().add("Content-Encoding",
BATCH_ENCODING).build();
+ OkhttpRestResult 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);
+// MultivaluedHashMap<String, Object> headers = new
MultivaluedHashMap<>();
+// headers.putSingle("Content-Encoding", BATCH_ENCODING);
Review Comment:
ditto
##########
hugegraph-client/src/test/java/org/apache/hugegraph/unit/RestResultTest.java:
##########
@@ -55,7 +56,7 @@
public class RestResultTest extends BaseUnitTest {
- private jakarta.ws.rs.core.Response mockResponse;
+ private okhttp3.Response mockResponse;
Review Comment:
ok, I mean we can try to import okhttp3.Response
##########
hugegraph-client/src/main/java/org/apache/hugegraph/rest/OkhttpConfig.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.rest;
+
+import lombok.Builder;
+import lombok.Getter;
+import lombok.Setter;
+
+@Builder
+@Getter
+@Setter
+public class OkhttpConfig {
Review Comment:
expect a blank line after the class define
##########
hugegraph-client/src/main/java/org/apache/hugegraph/driver/HugeClient.java:
##########
@@ -60,7 +60,8 @@ public HugeClient(HugeClientBuilder builder) {
builder.maxConnsPerRoute(),
builder.trustStoreFile(),
builder.trustStorePassword());
- } catch (ProcessingException e) {
+ } catch (Exception e) {
+ log.error("", e);
Review Comment:
please improve the log message
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]