-
Notifications
You must be signed in to change notification settings - Fork 525
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
||
|
@@ -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(); | ||
|
||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put it in front of HugeGraph.shutdown() |
||
HugeGraph.shutdown(30L); | ||
throw e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
@@ -85,5 +86,7 @@ private static void startWithInjectTraversal(String conf) | |
server.stop().join(); | ||
throw new HugeException("Failed to start Gremlin Server"); | ||
}).join(); | ||
|
||
return server; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
HugeRestServer.register()
andHugeGremlinServer.register()
to do:just call
HugeRestServer.register()
here