Skip to content

Commit

Permalink
tiny improve
Browse files Browse the repository at this point in the history
  • Loading branch information
imbajin committed Mar 18, 2024
1 parent 07483a4 commit 9687c31
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The HugeClient class is the main entry point for interacting with a HugeGraph server.
* It provides methods for managing graphs, schemas, jobs, tasks, and other resources.
* It also implements the Closeable interface, so it can be used in a try-with-resources statement.
*/
public class HugeClient implements Closeable {

private static final Logger LOG = LoggerFactory.getLogger(RestClient.class);
Expand All @@ -51,6 +56,11 @@ public class HugeClient implements Closeable {
private AuthManager auth;
private MetricsManager metrics;

/**
* Constructs a new HugeClient using the provided builder.
*
* @param builder the HugeClientBuilder to use for configuration
*/
public HugeClient(HugeClientBuilder builder) {
this.borrowedClient = false;
RestClientConfig config;
Expand All @@ -76,6 +86,7 @@ public HugeClient(HugeClientBuilder builder) {
try {
this.initManagers(this.client, builder.graph());
} catch (Throwable e) {
// TODO: catch some exception(like IO/Network related) rather than throw Throwable
this.client.close();
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@

package org.apache.hugegraph.exception;

/**
* Used to wrap other unexpected exceptions like Client/ServerException, and convert them into this.
* This is typically done to handle exceptions uniformly in the hubble UI.
*/
public class GenericException extends ParameterizedException {

public GenericException(ServerException e) {
super(e.getMessage(), e.getCause());
}


public GenericException(Exception e) {
super(e.getMessage(), e.getCause());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import org.apache.hugegraph.common.Constant;
import org.apache.hugegraph.common.Response;
import org.apache.hugegraph.exception.ExternalException;
import org.apache.hugegraph.exception.GenericException;
import org.apache.hugegraph.exception.IllegalGremlinException;
import org.apache.hugegraph.exception.InternalException;
import org.apache.hugegraph.exception.ParameterizedException;
import org.apache.hugegraph.exception.GenericException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
Expand Down Expand Up @@ -69,10 +69,11 @@ public Response exceptionHandler(ExternalException e) {
public Response exceptionHandler(GenericException e) {
log.error("GenericException:", e);
return Response.builder()
.status(Constant.STATUS_BAD_REQUEST)
.message("Connection to the graph server failed. Please refer to the Hubble log for details.")
.cause(null)
.build();
.status(Constant.STATUS_BAD_REQUEST)
.message("Faied to the graph server failed. Please refer to the " +
"Hubble log for details.")
.cause(null)
.build();
}

@ExceptionHandler(ParameterizedException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@
import java.util.Set;

import org.apache.hugegraph.common.Constant;
import org.apache.hugegraph.driver.HugeClient;
import org.apache.hugegraph.entity.GraphConnection;
import org.apache.hugegraph.exception.ExternalException;
import org.apache.hugegraph.exception.GenericException;
import org.springframework.web.util.UriComponentsBuilder;

import org.apache.hugegraph.driver.HugeClient;
import org.apache.hugegraph.exception.ServerException;
import org.apache.hugegraph.rest.ClientException;
import org.apache.hugegraph.structure.gremlin.Result;
import org.apache.hugegraph.structure.gremlin.ResultSet;
import org.springframework.web.util.UriComponentsBuilder;

import com.google.common.collect.ImmutableSet;

Expand All @@ -54,8 +53,8 @@ public static HugeClient tryConnect(GraphConnection connection) {
String trustStoreFile = connection.getTrustStoreFile();
String trustStorePassword = connection.getTrustStorePassword();

String url = UriComponentsBuilder.newInstance().scheme(protocol).host(host).port(port)
.toUriString();
String url = UriComponentsBuilder.newInstance()
.scheme(protocol).host(host).port(port).toUriString();
if (username == null) {
username = "";
password = "";
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,14 @@
<goal>clean</goal>
</goals>
</execution>
<!-- auto delete .flattened-pom.xml after "install" step -->
<execution>
<!-- auto delete .flattened-pom.xml after "install" step, will influence deploy step now-->
<!--execution>
<id>remove-flattened-pom</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</execution-->
</executions>
</plugin>
</plugins>
Expand Down

0 comments on commit 9687c31

Please sign in to comment.