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

Fix: config(rest-server.properties) error but HugeGraphServer still up #131

Merged
merged 1 commit into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -19,16 +19,12 @@

package com.baidu.hugegraph.dist;

import java.util.ServiceLoader;

import org.apache.tinkerpop.gremlin.server.GremlinServer;
import org.slf4j.Logger;

import com.baidu.hugegraph.HugeException;
import com.baidu.hugegraph.HugeGraph;
import com.baidu.hugegraph.plugin.HugeGraphPlugin;
import com.baidu.hugegraph.util.Log;
import com.baidu.hugegraph.util.VersionUtil;
import com.baidu.hugegraph.version.CoreVersion;

public class HugeGraphServer {

Expand All @@ -41,52 +37,32 @@ public class HugeGraphServer {
}

public static void main(String[] args) throws Exception {

if (args.length != 2) {
String msg = "HugeGraphServer can only accept two config files";
LOG.error(msg);
throw new HugeException(msg);
}

HugeRestServer.register();

Copy link
Contributor

Choose a reason for hiding this comment

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

add HugeRestServer.register() and HugeGremlinServer.register() to do:

RegisterUtil.registerBackends();
RegisterUtil.registerPlugins();

just call HugeRestServer.register() here

GremlinServer gremlinServer = null;
try {
RegisterUtil.registerBackends();
// Scan the jars in plugins directory and load them
registerPlugins();
// Start GremlinServer
HugeGremlinServer.start(args[0]);
// Start HugeRestServer
HugeRestServer.start(args[1]);
gremlinServer = HugeGremlinServer.start(args[0]);
} catch (Exception e) {
LOG.error("HugeGraphServer error:", e);
LOG.error("HugeGremlinServer start error: ", e);
HugeGraph.shutdown(30L);
throw e;
}
}

private static void registerPlugins() {
ServiceLoader<HugeGraphPlugin> plugins = ServiceLoader.load(
HugeGraphPlugin.class);
for (HugeGraphPlugin plugin : plugins) {
LOG.info("Loading plugin {}({})",
plugin.name(), plugin.getClass().getCanonicalName());
String minVersion = plugin.supportsMinVersion();
String maxVersion = plugin.supportsMaxVersion();

if (!VersionUtil.match(CoreVersion.VERSION, minVersion,
maxVersion)) {
LOG.warn("Skip loading plugin '{}' due to the version range " +
"'[{}, {})' that it's supported doesn't cover " +
"current core version '{}'", plugin.name(),
minVersion, maxVersion, CoreVersion.VERSION.get());
continue;
}
try {
plugin.register();
LOG.info("Loaded plugin '{}'", plugin.name());
} catch (Exception e) {
throw new HugeException("Failed to load plugin '%s'",
plugin.name(), e);
}
try {
// Start HugeRestServer
HugeRestServer.start(args[1]);
} catch (Exception e) {
LOG.error("HugeRestServer start error: ", e);
gremlinServer.stop();
Copy link
Contributor

Choose a reason for hiding this comment

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

put it in front of HugeGraph.shutdown()

HugeGraph.shutdown(30L);
throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,43 +34,44 @@ public class HugeGremlinServer {
private static final String G_PREFIX = "__g_";

public static void main(String[] args) throws Exception {

if (args.length != 1) {
String msg = "HugeGremlinServer can only accept one config files";
LOG.error(msg);
throw new HugeException(msg);
}

register();

try {
RegisterUtil.registerBackends();
start(args[0]);
} catch (Exception e) {
LOG.error("HugeGremlinServer error:", e);
throw e;
}
LOG.info("HugeGremlinServer started");
}

Runtime.getRuntime().addShutdownHook(new Thread(() -> {
LOG.info("HugeGremlinServer stopped");
}));
public static void register() {
RegisterUtil.registerBackends();
RegisterUtil.registerPlugins();
}

public static void start(String conf) throws Exception {
public static GremlinServer start(String conf) throws Exception {
// Start GremlinServer with inject traversal source
startWithInjectTraversal(conf);
return startWithInjectTraversal(conf);
}

private static void startWithInjectTraversal(String conf)
throws Exception {
private static ContextGremlinServer startWithInjectTraversal(String conf)
Copy link
Contributor

Choose a reason for hiding this comment

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

align "throws..."

throws Exception {
LOG.info(GremlinServer.getHeader());
final Settings settings;

try {
settings = Settings.read(conf);
} catch (Exception ex) {
} catch (Exception e) {
LOG.error("Can't found the configuration file at {} or " +
"being parsed properly. [{}]", conf, ex.getMessage());
return;
"being parsed properly. [{}]", conf, e.getMessage());
throw e;
}

LOG.info("Configuring Gremlin Server from {}", conf);
Expand All @@ -85,5 +86,7 @@ private static void startWithInjectTraversal(String conf)
server.stop().join();
throw new HugeException("Failed to start Gremlin Server");
}).join();

return server;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static void main(String[] args) throws Exception {
}

try {
RegisterUtil.registerBackends();
// Start HugeRestServer
start(args[0]);
} catch (Exception e) {
Expand All @@ -47,10 +46,15 @@ public static void main(String[] args) throws Exception {
LOG.info("HugeRestServer stopped");
}

public static void start(String conf) throws Exception {
public static void register() {
RegisterUtil.registerBackends();
RegisterUtil.registerPlugins();
}

public static RestServer start(String conf) throws Exception {
RegisterUtil.registerServer();

// Start RestServer
RestServer.start(conf);
return RestServer.start(conf);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,28 @@

import java.io.InputStream;
import java.util.List;
import java.util.ServiceLoader;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.slf4j.Logger;

import com.baidu.hugegraph.HugeException;
import com.baidu.hugegraph.backend.serializer.SerializerFactory;
import com.baidu.hugegraph.backend.store.BackendProviderFactory;
import com.baidu.hugegraph.config.CoreOptions;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.config.OptionSpace;
import com.baidu.hugegraph.plugin.HugeGraphPlugin;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;
import com.baidu.hugegraph.util.VersionUtil;
import com.baidu.hugegraph.version.CoreVersion;

public class RegisterUtil {

private static final Logger LOG = Log.logger(RegisterUtil.class);

static {
OptionSpace.register("core", CoreOptions.instance());
OptionSpace.register("dist", DistOptions.instance());
Expand Down Expand Up @@ -160,4 +168,34 @@ public static void registerPalo() {
public static void registerServer() {
OptionSpace.register("server", "com.baidu.hugegraph.config.ServerOptions");
}

/**
* Scan the jars in plugins directory and load them
*/
public static void registerPlugins() {
ServiceLoader<HugeGraphPlugin> plugins = ServiceLoader.load(
HugeGraphPlugin.class);
for (HugeGraphPlugin plugin : plugins) {
LOG.info("Loading plugin {}({})",
plugin.name(), plugin.getClass().getCanonicalName());
String minVersion = plugin.supportsMinVersion();
String maxVersion = plugin.supportsMaxVersion();

if (!VersionUtil.match(CoreVersion.VERSION, minVersion,
maxVersion)) {
LOG.warn("Skip loading plugin '{}' due to the version range " +
"'[{}, {})' that it's supported doesn't cover " +
"current core version '{}'", plugin.name(),
minVersion, maxVersion, CoreVersion.VERSION.get());
continue;
}
try {
plugin.register();
LOG.info("Loaded plugin '{}'", plugin.name());
} catch (Exception e) {
throw new HugeException("Failed to load plugin '%s'",
plugin.name(), e);
}
}
}
}