use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class ConfigUtil method writeToFile.
public static String writeToFile(String dir, String graphName, HugeConfig config) {
E.checkArgument(FileUtils.getFile(dir).exists(), "The directory '%s' must exist", dir);
String fileName = Paths.get(dir, graphName + CONF_SUFFIX).toString();
try {
config.save(new File(fileName));
LOG.info("Write HugeConfig to file: '{}'", fileName);
} catch (ConfigurationException e) {
throw new HugeException("Failed to write HugeConfig to file '%s'", e, fileName);
}
return fileName;
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class ConfigUtil method checkGremlinConfig.
public static void checkGremlinConfig(String conf) {
Parameters params = new Parameters();
try {
FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder(YAMLConfiguration.class).configure(params.fileBased().setFileName(conf));
YAMLConfiguration config = (YAMLConfiguration) builder.getConfiguration();
List<HierarchicalConfiguration<ImmutableNode>> nodes = config.childConfigurationsAt(NODE_GRAPHS);
if (nodes == null || nodes.isEmpty()) {
return;
}
E.checkArgument(nodes.size() == 1, "Not allowed to specify multiple '%s' " + "nodes in config file '%s'", NODE_GRAPHS, conf);
ImmutableNode root = null;
NodeHandler<ImmutableNode> nodeHandler = null;
for (HierarchicalConfiguration<ImmutableNode> node : nodes) {
NodeModel<ImmutableNode> nodeModel = node.getNodeModel();
E.checkArgument(nodeModel != null && (nodeHandler = nodeModel.getNodeHandler()) != null && (root = nodeHandler.getRootNode()) != null, "Node '%s' must contain root", node);
}
} catch (ConfigurationException e) {
throw new HugeException("Failed to load yaml config file '%s'", conf);
}
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class HugeScriptTraversal method applyStrategies.
@Override
public void applyStrategies() throws IllegalStateException {
ScriptEngine engine = SingleGremlinScriptEngineManager.get(this.language);
Bindings bindings = engine.createBindings();
bindings.putAll(this.bindings);
@SuppressWarnings("rawtypes") TraversalStrategy[] strategies = this.getStrategies().toList().toArray(new TraversalStrategy[0]);
GraphTraversalSource g = this.graph.traversal();
if (strategies.length > 0) {
g = g.withStrategies(strategies);
}
bindings.put("g", g);
bindings.put("graph", this.graph);
for (Map.Entry<String, String> entry : this.aliases.entrySet()) {
Object value = bindings.get(entry.getValue());
if (value == null) {
throw new IllegalArgumentException(String.format("Invalid aliase '%s':'%s'", entry.getKey(), entry.getValue()));
}
bindings.put(entry.getKey(), value);
}
try {
Object result = engine.eval(this.script, bindings);
if (result instanceof Admin) {
@SuppressWarnings({ "unchecked", "resource" }) Admin<S, E> traversal = (Admin<S, E>) result;
traversal.getSideEffects().mergeInto(this.sideEffects);
traversal.getSteps().forEach(this::addStep);
this.strategies = traversal.getStrategies();
} else {
this.result = result;
}
super.applyStrategies();
} catch (ScriptException e) {
throw new HugeException(e.getMessage(), e);
}
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class SingleWayMultiPathsRecords method linkPath.
protected final Path linkPath(int layerIndex, int target) {
List<Id> ids = CollectionFactory.newList(CollectionType.EC);
IntMap layer = this.layer(layerIndex);
if (!layer.containsKey(target)) {
throw new HugeException("Failed to get path for %s", this.id(target));
}
// Collect self node
ids.add(this.id(target));
// Concat parents
for (int i = layerIndex; i > 0; i--) {
layer = this.layer(i);
// Uptrack parents
target = layer.get(target);
ids.add(this.id(target));
}
Collections.reverse(ids);
return new Path(ids);
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class HugeGremlinServer method start.
public static GremlinServer start(String conf, String graphsDir, EventHub hub) throws Exception {
// Start GremlinServer with inject traversal source
LOG.info(GremlinServer.getHeader());
final Settings settings;
try {
settings = Settings.read(conf);
} catch (Exception e) {
LOG.error("Can't found the configuration file at '{}' or " + "being parsed properly. [{}]", conf, e.getMessage());
throw e;
}
// Scan graph confs and inject into gremlin server context
E.checkState(settings.graphs != null, "The GremlinServer's settings.graphs is null");
settings.graphs.putAll(ConfigUtil.scanGraphsDir(graphsDir));
LOG.info("Configuring Gremlin Server from {}", conf);
ContextGremlinServer server = new ContextGremlinServer(settings, hub);
// Inject customized traversal source
server.injectTraversalSource();
server.start().exceptionally(t -> {
LOG.error("Gremlin Server was unable to start and will " + "shutdown now: {}", t.getMessage());
server.stop().join();
throw new HugeException("Failed to start Gremlin Server");
}).join();
return server;
}
Aggregations