diff --git a/hugegraph-api/pom.xml b/hugegraph-api/pom.xml
index b963c6bfca..b687b64ac2 100644
--- a/hugegraph-api/pom.xml
+++ b/hugegraph-api/pom.xml
@@ -87,6 +87,52 @@
grizzly-http-servlet
2.4.4
+
+
+
+ com.lmax
+ disruptor
+ 3.3.7
+
+
+ com.alipay.sofa
+ sofa-rpc-all
+ 5.7.6
+
+
+ io.netty
+ netty-all
+
+
+ org.jboss.resteasy
+ resteasy-client
+
+
+ com.alipay.sofa
+ bolt
+
+
+ org.apache.httpcomponents
+ httpcore
+
+
+ org.apache.httpcomponents
+ httpmime
+
+
+ com.alipay.sofa.common
+ sofa-common-tools
+
+
+ org.jboss.logging
+ jboss-logging
+
+
+ com.alipay.sofa
+ hessian
+
+
+
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java
index f58cc35f44..d06ebceb18 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java
@@ -100,8 +100,8 @@ public final class HugeGraphAuthProxy implements HugeGraph {
private static final Logger LOG = Log.logger(HugeGraphAuthProxy.class);
private final HugeGraph hugegraph;
- private final TaskScheduler taskScheduler;
- private final UserManager userManager;
+ private final TaskSchedulerProxy taskScheduler;
+ private final UserManagerProxy userManager;
public HugeGraphAuthProxy(HugeGraph hugegraph) {
LOG.info("Wrap graph '{}' with HugeGraphAuthProxy", hugegraph.name());
@@ -652,6 +652,12 @@ public UserManager userManager() {
return this.userManager;
}
+ @Override
+ public void switchUserManager(UserManager userManager) {
+ this.verifyAdminPermission();
+ this.userManager.switchUserManager(userManager);
+ }
+
@Override
public RaftGroupManager raftGroupManager(String group) {
this.verifyAdminPermission();
@@ -1044,7 +1050,7 @@ private boolean hasTaskPermission(HugeTask> task) {
class UserManagerProxy implements UserManager {
- private final UserManager userManager;
+ private UserManager userManager;
public UserManagerProxy(UserManager origin) {
this.userManager = origin;
@@ -1345,6 +1351,11 @@ public RolePermission loginUser(String username, String password) {
setContext(context);
}
}
+
+ private void switchUserManager(UserManager userManager) {
+ this.userManager = userManager;
+ hugegraph.switchUserManager(userManager);
+ }
}
class VariablesProxy implements Variables {
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java
index 0e0d215c05..08c8a98ed6 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java
@@ -24,11 +24,13 @@
import java.util.Scanner;
import org.apache.commons.lang.NotImplementedException;
+import org.apache.commons.lang.StringUtils;
import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
import com.baidu.hugegraph.HugeGraph;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.config.ServerOptions;
+import com.baidu.hugegraph.rpc.RpcClientProvider;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.StringEncoding;
@@ -78,6 +80,12 @@ public void setup(HugeConfig config) {
E.checkArgument(graphPath != null,
"Invalid graph name '%s'", graphName);
this.graph = (HugeGraph) GraphFactory.open(graphPath);
+
+ String remoteUrl = config.get(ServerOptions.AUTH_REMOTE_URL);
+ if (StringUtils.isNotEmpty(remoteUrl)) {
+ RpcClientProvider provider = new RpcClientProvider(config);
+ this.graph.switchUserManager(provider.userManager());
+ }
}
/**
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java
index f5a5e3c289..dcce7c7493 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java
@@ -222,6 +222,115 @@ public static synchronized ServerOptions instance() {
"hugegraph:9fd95c9c-711b-415b-b85f-d4df46ba5c31"
);
+ public static final ConfigOption AUTH_REMOTE_URL =
+ new ConfigOption<>(
+ "auth.remote_url",
+ "If the address is empty, it provide auth service, " +
+ "otherwise it is auth client and also provide auth service " +
+ "through rpc forwarding. The remote url can be set to " +
+ "multiple addresses, which are linked by ','.",
+ null,
+ ""
+ );
+
+ public static final ConfigOption RPC_SERVER_PORT =
+ new ConfigOption<>(
+ "rpc.server_port",
+ "The port bound by rpc server to provide services.",
+ rangeInt(1, Integer.MAX_VALUE),
+ 8099
+ );
+
+ public static final ConfigOption RPC_SERVER_HOST =
+ new ConfigOption<>(
+ "rpc.server_host",
+ "The hosts/ips bound by rpc server to provide " +
+ "services.",
+ disallowEmpty(),
+ "127.0.0.1"
+ );
+
+ public static final ConfigOption RPC_SERVER_TIMEOUT =
+ new ConfigOption<>(
+ "rpc.server_timeout",
+ "The timeout(in seconds) of rpc server execution.",
+ rangeInt(1, Integer.MAX_VALUE),
+ 30
+ );
+
+ public static final ConfigOption RPC_CLIENT_CONNECT_TIMEOUT =
+ new ConfigOption<>(
+ "rpc.client_connect_timeout",
+ "The timeout(in seconds) of rpc client connect to rpc " +
+ "server.",
+ rangeInt(1, Integer.MAX_VALUE),
+ 20
+ );
+
+ public static final ConfigOption RPC_CLIENT_RECONNECT_PERIOD =
+ new ConfigOption<>(
+ "rpc.client_reconnect_period",
+ "The period(in seconds) of rpc client reconnect to rpc " +
+ "server.",
+ rangeInt(1, Integer.MAX_VALUE),
+ 10
+ );
+
+ public static final ConfigOption RPC_CLIENT_READ_TIMEOUT =
+ new ConfigOption<>(
+ "rpc.client_read_timeout",
+ "The timeout(in seconds) of rpc client read from rpc " +
+ "server.",
+ rangeInt(1, Integer.MAX_VALUE),
+ 40
+ );
+
+ public static final ConfigOption RPC_CLIENT_RETRIES =
+ new ConfigOption<>(
+ "rpc.client_retries",
+ "Failed retry number of rpc client calls to rpc server.",
+ rangeInt(0, Integer.MAX_VALUE),
+ 3
+ );
+
+ public static final ConfigOption RPC_CLIENT_LOAD_BALANCER =
+ new ConfigOption<>(
+ "rpc.client_load_balancer",
+ "The rpc client uses a load-balancing algorithm to " +
+ "access multiple rpc servers in one cluster. Default " +
+ "value is 'consistentHash', means forwording by request " +
+ "parameters.",
+ allowValues("random", "localPref", "roundRobin",
+ "consistentHash", "weightRoundRobin"),
+ "consistentHash"
+ );
+
+ public static final ConfigOption RPC_PROTOCOL =
+ new ConfigOption<>(
+ "rpc.protocol",
+ "Rpc communication protocol, client and server need to " +
+ "be specified the same value.",
+ allowValues("bolt", "rest", "dubbo", "h2c", "http"),
+ "bolt"
+ );
+
+ public static final ConfigOption RPC_CONFIG_ORDER =
+ new ConfigOption<>(
+ "rpc.config_order",
+ "Sofa rpc configuration file loading order, the larger " +
+ "the more later loading.",
+ rangeInt(1, Integer.MAX_VALUE),
+ 999
+ );
+
+ public static final ConfigOption RPC_LOGGER_IMPL =
+ new ConfigOption<>(
+ "rpc.logger_impl",
+ "Sofa rpc log implementation class.",
+ disallowEmpty(),
+ "com.alipay.sofa.rpc.log.SLF4JLoggerImpl"
+ );
+
public static final ConfigOption SSL_KEYSTORE_FILE =
new ConfigOption<>(
"ssl.keystore_file",
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java
index 82269a28b0..727f6ea034 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java
@@ -51,6 +51,8 @@
import com.baidu.hugegraph.license.LicenseVerifier;
import com.baidu.hugegraph.metrics.MetricsUtil;
import com.baidu.hugegraph.metrics.ServerReporter;
+import com.baidu.hugegraph.rpc.RpcProviderConfig;
+import com.baidu.hugegraph.rpc.SofaRpcServer;
import com.baidu.hugegraph.serializer.JsonSerializer;
import com.baidu.hugegraph.serializer.Serializer;
import com.baidu.hugegraph.server.RestServer;
@@ -65,16 +67,19 @@ public final class GraphManager {
private final Map graphs;
private final HugeAuthenticator authenticator;
+ private final SofaRpcServer rpcServer;
public GraphManager(HugeConfig conf) {
this.graphs = new ConcurrentHashMap<>();
this.authenticator = HugeAuthenticator.loadAuthenticator(conf);
+ this.rpcServer = new SofaRpcServer(conf);
this.loadGraphs(conf.getMap(ServerOptions.GRAPHS));
// this.installLicense(conf, "");
// Raft will load snapshot firstly then launch election and replay log
this.waitGraphsStarted();
this.checkBackendVersionOrExit();
+ this.startRpcServer();
this.serverStarted(conf);
this.addMetrics(conf);
}
@@ -159,6 +164,23 @@ public UserManager userManager() {
return this.authenticator().userManager();
}
+ public void close() {
+ this.destoryRpcServer();
+ }
+
+ private void startRpcServer() {
+ RpcProviderConfig config = this.rpcServer.config();
+ if (this.authenticator != null) {
+ config.addService(UserManager.class,
+ this.authenticator.userManager());
+ }
+ this.rpcServer.exportAll();
+ }
+
+ private void destoryRpcServer() {
+ this.rpcServer.destroy();
+ }
+
private HugeAuthenticator authenticator() {
E.checkState(this.authenticator != null, "Unconfigured authenticator");
return this.authenticator;
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcClientProvider.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcClientProvider.java
new file mode 100644
index 0000000000..d028ce8104
--- /dev/null
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcClientProvider.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * 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 com.baidu.hugegraph.rpc;
+
+import com.alipay.sofa.rpc.config.ConsumerConfig;
+import com.baidu.hugegraph.auth.UserManager;
+import com.baidu.hugegraph.config.HugeConfig;
+
+public class RpcClientProvider {
+
+ public final RpcConsumerConfig rpcConsumerConfig;
+
+ public RpcClientProvider(HugeConfig conf) {
+ RpcCommonConfig.initRpcConfigs(conf);
+ this.rpcConsumerConfig = new RpcConsumerConfig();
+ this.rpcConsumerConfig.addConsumerConfig(UserManager.class, conf);
+ }
+
+ public UserManager userManager() {
+ return (UserManager) this.serviceProxy(UserManager.class.getName());
+ }
+
+ public Object serviceProxy(String serviceName) {
+ ConsumerConfig config = this.rpcConsumerConfig.consumerConfig(serviceName);
+ return config.refer();
+ }
+}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcCommonConfig.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcCommonConfig.java
new file mode 100644
index 0000000000..d3ad769d10
--- /dev/null
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcCommonConfig.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * 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 com.baidu.hugegraph.rpc;
+
+import java.util.Map;
+
+import com.alipay.sofa.rpc.common.RpcConfigs;
+import com.baidu.hugegraph.config.HugeConfig;
+import com.baidu.hugegraph.config.ServerOptions;
+
+public class RpcCommonConfig {
+
+ public static void initRpcConfigs(HugeConfig conf) {
+ RpcConfigs.putValue("rpc.config.order",
+ conf.get(ServerOptions.RPC_CONFIG_ORDER));
+ RpcConfigs.putValue("logger.impl",
+ conf.get(ServerOptions.RPC_LOGGER_IMPL));
+ }
+
+ public static void initRpcConfigs(String key, Object value) {
+ RpcConfigs.putValue(key, value);
+ }
+
+ public static void initRpcConfigs(Map conf) {
+ for(Map.Entry entry : conf.entrySet()) {
+ RpcConfigs.putValue(entry.getKey(), entry.getValue());
+ }
+ }
+}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcConsumerConfig.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcConsumerConfig.java
new file mode 100644
index 0000000000..ec92cc259b
--- /dev/null
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcConsumerConfig.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * 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 com.baidu.hugegraph.rpc;
+
+import java.util.Map;
+
+import com.alipay.sofa.rpc.config.ConsumerConfig;
+import com.baidu.hugegraph.config.HugeConfig;
+import com.baidu.hugegraph.config.ServerOptions;
+import com.google.common.collect.Maps;
+
+public class RpcConsumerConfig {
+
+ private final Map configs = Maps.newHashMap();
+
+ public void addConsumerConfig(Class clazz, HugeConfig conf) {
+ String protocol = conf.get(ServerOptions.RPC_PROTOCOL);
+ String directUrl = conf.get(ServerOptions.AUTH_REMOTE_URL);
+ int timeout = conf.get(ServerOptions.RPC_CLIENT_READ_TIMEOUT) * 1000;
+ int connectTimeout = conf.get(ServerOptions
+ .RPC_CLIENT_CONNECT_TIMEOUT) * 1000;
+ int reconnectPeriod = conf.get(ServerOptions
+ .RPC_CLIENT_RECONNECT_PERIOD) * 1000;
+ int retries = conf.get(ServerOptions.RPC_CLIENT_RETRIES);
+ String loadBalancer = conf.get(ServerOptions.RPC_CLIENT_LOAD_BALANCER);
+ ConsumerConfig consumerConfig = new ConsumerConfig()
+ .setInterfaceId(clazz.getName())
+ .setProtocol(protocol)
+ .setDirectUrl(directUrl)
+ .setTimeout(timeout)
+ .setConnectTimeout(connectTimeout)
+ .setReconnectPeriod(reconnectPeriod)
+ .setRetries(retries)
+ .setLoadBalancer(loadBalancer);
+ this.configs.put(clazz.getName(), consumerConfig);
+ }
+
+ public ConsumerConfig consumerConfig(String serverName) {
+ if (!this.configs.containsKey(serverName)) {
+ throw new RpcException("Invalid server name '%s'", serverName);
+ }
+ return this.configs.get(serverName);
+ }
+}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcException.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcException.java
new file mode 100644
index 0000000000..4b03f6943a
--- /dev/null
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcException.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * 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 com.baidu.hugegraph.rpc;
+
+import com.baidu.hugegraph.HugeException;
+
+public class RpcException extends HugeException {
+
+ private static final long serialVersionUID = -6067652498161184537L;
+
+ public RpcException(String message) {
+ super(message);
+ }
+
+ public RpcException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public RpcException(String message, Object... args) {
+ super(message, args);
+ }
+
+ public RpcException(String message, Throwable cause, Object... args) {
+ super(message, cause, args);
+ }
+}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcProviderConfig.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcProviderConfig.java
new file mode 100644
index 0000000000..096d339ca4
--- /dev/null
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcProviderConfig.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * 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 com.baidu.hugegraph.rpc;
+
+import java.util.Map;
+
+import com.alipay.sofa.rpc.config.ProviderConfig;
+import com.google.common.collect.Maps;
+
+public class RpcProviderConfig {
+
+ private final Map configs = Maps.newHashMap();
+
+ public void addService(Class clazz, E serviceImpl) {
+ ProviderConfig providerConfig = new ProviderConfig()
+ .setInterfaceId(clazz.getName())
+ .setRef(serviceImpl);
+ this.configs.put(clazz.getName(), providerConfig);
+ }
+
+ public Map configs() {
+ return this.configs;
+ }
+}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/SofaRpcServer.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/SofaRpcServer.java
new file mode 100644
index 0000000000..a92401b518
--- /dev/null
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/SofaRpcServer.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * 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 com.baidu.hugegraph.rpc;
+
+import java.util.Map;
+
+import org.apache.commons.collections.MapUtils;
+import org.slf4j.Logger;
+
+import com.alipay.sofa.rpc.common.RpcConfigs;
+import com.alipay.sofa.rpc.common.RpcOptions;
+import com.alipay.sofa.rpc.config.ProviderConfig;
+import com.alipay.sofa.rpc.config.ServerConfig;
+import com.alipay.sofa.rpc.context.RpcRuntimeContext;
+import com.baidu.hugegraph.config.HugeConfig;
+import com.baidu.hugegraph.config.ServerOptions;
+import com.baidu.hugegraph.util.Log;
+
+public class SofaRpcServer {
+
+ private static final Logger LOG = Log.logger(SofaRpcServer.class);
+
+ private final HugeConfig conf;
+ private final RpcProviderConfig configs;
+ private final ServerConfig serverConfig;
+
+ static {
+ if (RpcConfigs.getOrDefaultValue(RpcOptions.JVM_SHUTDOWN_HOOK, true)) {
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+ RpcRuntimeContext.destroy();
+ }, "SOFA-RPC-ShutdownHook"));
+ }
+ }
+
+ public SofaRpcServer(HugeConfig conf) {
+ RpcCommonConfig.initRpcConfigs(conf);
+ this.conf = conf;
+ this.serverConfig = new ServerConfig()
+ .setProtocol(conf.get(ServerOptions.RPC_PROTOCOL))
+ .setPort(conf.get(ServerOptions.RPC_SERVER_PORT))
+ .setHost(conf.get(ServerOptions.RPC_SERVER_HOST))
+ .setDaemon(false);
+ this.configs = new RpcProviderConfig();
+ }
+
+ public RpcProviderConfig config() {
+ return this.configs;
+ }
+
+ public void exportAll() {
+ LOG.debug("RpcServer starting on port {}", this.port());
+ Map configs = this.configs.configs();
+ if (MapUtils.isEmpty(configs)) {
+ LOG.info("RpcServer config is empty, skip starting RpcServer");
+ return;
+ }
+ int timeout = this.conf.get(ServerOptions.RPC_SERVER_TIMEOUT) * 1000;
+ for (ProviderConfig providerConfig : configs.values()) {
+ providerConfig.setServer(this.serverConfig);
+ providerConfig.setTimeout(timeout);
+ providerConfig.export();
+ }
+ LOG.info("RpcServer started success on port {}", this.port());
+ }
+
+ public void unExport(String serviceName) {
+ Map configs = this.configs.configs();
+ if (!configs.containsKey(serviceName)) {
+ throw new RpcException("The service name '%s' doesn't exist",
+ serviceName);
+ }
+ configs.get(serviceName).unExport();
+ }
+
+ public int port() {
+ return this.serverConfig.getPort();
+ }
+
+ public void destroy() {
+ LOG.info("RpcServer stop on port {}", this.port());
+ this.serverConfig.destroy();
+ }
+}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/server/ApplicationConfig.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/server/ApplicationConfig.java
index f8cf2fb2ca..b5134c8007 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/server/ApplicationConfig.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/server/ApplicationConfig.java
@@ -102,10 +102,16 @@ public GraphManagerFactory(HugeConfig conf) {
register(new ApplicationEventListener() {
private final ApplicationEvent.Type EVENT_INITED =
ApplicationEvent.Type.INITIALIZATION_FINISHED;
+ private final ApplicationEvent.Type EVENT_DESTROY =
+ ApplicationEvent.Type.DESTROY_FINISHED;
@Override
public void onEvent(ApplicationEvent event) {
if (event.getType() == this.EVENT_INITED) {
manager = new GraphManager(conf);
+ } else if (event.getType() == this.EVENT_DESTROY) {
+ if (manager != null) {
+ manager.close();
+ }
}
}
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/HugeGraph.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/HugeGraph.java
index e3d8f44be2..82ea83a729 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/HugeGraph.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/HugeGraph.java
@@ -155,6 +155,7 @@ public interface HugeGraph extends Graph {
public HugeFeatures features();
public UserManager userManager();
+ public void switchUserManager(UserManager userManager);
public TaskScheduler taskScheduler();
public RaftGroupManager raftGroupManager(String group);
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java
index dbb4ac055b..38a8d57eb7 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java
@@ -140,7 +140,7 @@ public class StandardHugeGraph implements HugeGraph {
private final RateLimiter writeRateLimiter;
private final RateLimiter readRateLimiter;
private final TaskManager taskManager;
- private final UserManager userManager;
+ private UserManager userManager;
private final HugeFeatures features;
@@ -883,6 +883,11 @@ public UserManager userManager() {
return this.userManager;
}
+ @Override
+ public void switchUserManager(UserManager userManager) {
+ this.userManager = userManager;
+ }
+
@Override
public RaftGroupManager raftGroupManager(String group) {
if (!(this.storeProvider instanceof RaftBackendStoreProvider)) {
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/HugeUser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/HugeUser.java
index d47385deed..78d376fd49 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/HugeUser.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/HugeUser.java
@@ -29,7 +29,6 @@
import org.apache.tinkerpop.gremlin.structure.Vertex;
import com.baidu.hugegraph.HugeGraphParams;
-import com.baidu.hugegraph.auth.ResourceType;
import com.baidu.hugegraph.auth.SchemaDefine.Entity;
import com.baidu.hugegraph.backend.id.Id;
import com.baidu.hugegraph.schema.VertexLabel;
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/SchemaDefine.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/SchemaDefine.java
index e38da0c29d..57bf0e4fd0 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/SchemaDefine.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/SchemaDefine.java
@@ -19,6 +19,7 @@
package com.baidu.hugegraph.auth;
+import java.io.Serializable;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
@@ -32,7 +33,6 @@
import com.baidu.hugegraph.HugeGraphParams;
import com.baidu.hugegraph.auth.HugeTarget.P;
-import com.baidu.hugegraph.auth.ResourceType;
import com.baidu.hugegraph.backend.id.Id;
import com.baidu.hugegraph.schema.IndexLabel;
import com.baidu.hugegraph.schema.PropertyKey;
@@ -116,7 +116,7 @@ protected static String unhideField(String label, String key) {
return Hidden.unHide(label) + "_" + key;
}
- public static abstract class UserElement {
+ public static abstract class UserElement implements Serializable {
protected static final String CREATE = "create";
protected static final String UPDATE = "update";
diff --git a/hugegraph-dist/src/assembly/static/conf/rest-server.properties b/hugegraph-dist/src/assembly/static/conf/rest-server.properties
index 71e7daa4da..4287e13566 100644
--- a/hugegraph-dist/src/assembly/static/conf/rest-server.properties
+++ b/hugegraph-dist/src/assembly/static/conf/rest-server.properties
@@ -10,6 +10,17 @@ graphs=[hugegraph:conf/hugegraph.properties]
#auth.authenticator=
#auth.admin_token=
#auth.user_tokens=[]
+#auth.remote_url=127.0.0.1:8899,127.0.0.1:8898,127.0.0.1:8897
server.id=server-1
server.role=master
+
+rpc.server_host=127.0.0.1
+rpc.server_port=8893
+rpc.server_timeout=30
+rpc.client_connect_timeout=20
+rpc.client_reconnect_period=10
+rpc.client_read_timeout=40
+rpc.client_retries=3
+rpc.client_load_balancer=consistentHash
+rpc.protocol=bolt