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

Add multi-node auth information sharing function #1350

Merged
merged 20 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,9 @@ public UserManager userManager() {
}

@Override
public void swichUserManager(UserManager userManager) {
public void switchUserManager(UserManager userManager) {
this.verifyAdminPermission();
this.userManager.swichUserManager(userManager);
this.userManager.switchUserManager(userManager);
}

@Override
Expand Down Expand Up @@ -1352,9 +1352,9 @@ public RolePermission loginUser(String username, String password) {
}
}

private void swichUserManager(UserManager userManager) {
private void switchUserManager(UserManager userManager) {
this.userManager = userManager;
hugegraph.swichUserManager(userManager);
hugegraph.switchUserManager(userManager);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void setup(HugeConfig config) {
String remoteUrl = config.get(ServerOptions.AUTH_REMOTE_URL);
if (StringUtils.isNotEmpty(remoteUrl)) {
RpcClientProvider provider = new RpcClientProvider(config);
this.graph.swichUserManager(provider.userManager());
this.graph.switchUserManager(provider.userManager());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@
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;
import com.baidu.hugegraph.rpc.RpcServerProvider;
import com.baidu.hugegraph.task.TaskManager;
import com.baidu.hugegraph.type.define.NodeRole;
import com.baidu.hugegraph.util.E;
Expand All @@ -66,18 +67,19 @@ public final class GraphManager {

private final Map<String, Graph> graphs;
private final HugeAuthenticator authenticator;
private final RpcServerProvider rpcServerProvider;
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.rpcServerProvider = this.startRpcServer(conf);
this.startRpcServer();
this.serverStarted(conf);
this.addMetrics(conf);
}
Expand Down Expand Up @@ -166,17 +168,17 @@ public void close() {
this.destoryRpcServer();
}

private RpcServerProvider startRpcServer(HugeConfig conf) {
private void startRpcServer() {
RpcProviderConfig config = this.rpcServer.config();
if (this.authenticator != null) {
return new RpcServerProvider(conf, this.authenticator.userManager());
config.addService(UserManager.class,
this.authenticator.userManager());
}
return null;
this.rpcServer.exportAll();
}

private void destoryRpcServer() {
if (this.rpcServerProvider != null) {
this.rpcServerProvider.destroy();
}
this.rpcServer.destroy();
}
javeme marked this conversation as resolved.
Show resolved Hide resolved

private HugeAuthenticator authenticator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ public class RpcProviderConfig {

private final Map<String, ProviderConfig> configs = Maps.newHashMap();

public <T, E extends T> void addProviderConfig(Class<T> clazz,
E serviceImpl) {
public <T, E extends T> void addService(Class<T> clazz, E serviceImpl) {
ProviderConfig<T> providerConfig = new ProviderConfig<T>()
.setInterfaceId(clazz.getName())
.setRef(serviceImpl);
this.configs.put(clazz.getName(), providerConfig);
}

public Map<String, ProviderConfig> providerConfigs() {
public Map<String, ProviderConfig> configs() {
return this.configs;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand All @@ -30,12 +31,15 @@
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 final Map<String, ProviderConfig> providerConfigs;
private static final Logger LOG = Log.logger(SofaRpcServer.class);

private final HugeConfig conf;
private final RpcProviderConfig configs;
private final ServerConfig serverConfig;
private final int rpcServerTimeout;

static {
if (RpcConfigs.getOrDefaultValue(RpcOptions.JVM_SHUTDOWN_HOOK, true)) {
Expand All @@ -48,34 +52,44 @@ public void run() {
}
}

public SofaRpcServer(HugeConfig conf, RpcProviderConfig providerConfig) {
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.providerConfigs = providerConfig.providerConfigs();
this.rpcServerTimeout = conf.get(ServerOptions.RPC_SERVER_TIMEOUT) * 1000;
this.configs = new RpcProviderConfig();
}

public RpcProviderConfig config() {
return this.configs;
}

public void exportAll() {
if (MapUtils.isEmpty(this.providerConfigs)) {
throw new RpcException(
"The server provider config map can't be empty");
LOG.debug("RpcServer starting on port {}", this.port());
Map<String, ProviderConfig> configs = this.configs.configs();
if (MapUtils.isEmpty(configs)) {
LOG.info("RpcServer configs is empty, skip RpcServer starting");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RpcServer config is empty

return;
}
for (ProviderConfig providerConfig : this.providerConfigs.values()) {
int timeout = this.conf.get(ServerOptions.RPC_SERVER_TIMEOUT) * 1000;
for (ProviderConfig providerConfig : configs.values()) {
providerConfig.setServer(this.serverConfig);
providerConfig.setTimeout(this.rpcServerTimeout);
providerConfig.setTimeout(timeout);
providerConfig.export();
}
LOG.info("RpcServer started success on port {}", this.port());
}

public void unExport(String serviceName) {
javeme marked this conversation as resolved.
Show resolved Hide resolved
if (!this.providerConfigs.containsKey(serviceName)) {
throw new RpcException("The service name '%s' doesn't exist, please " +
"change others", serviceName);
Map<String, ProviderConfig> configs = this.configs.configs();
if (!configs.containsKey(serviceName)) {
throw new RpcException("The service name '%s' doesn't exist, " +
"please change others", serviceName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove "please change others"

}
this.providerConfigs.get(serviceName).unExport();
configs.get(serviceName).unExport();
}

public int port() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public interface HugeGraph extends Graph {
public HugeFeatures features();

public UserManager userManager();
public void swichUserManager(UserManager userManager);
public void switchUserManager(UserManager userManager);
public TaskScheduler taskScheduler();
public RaftGroupManager raftGroupManager(String group);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ public UserManager userManager() {
}

@Override
public void swichUserManager(UserManager userManager) {
public void switchUserManager(UserManager userManager) {
this.userManager = userManager;
}

Expand Down