Search in sources :

Example 16 with HugeException

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;
}
Also used : ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) File(java.io.File) HugeException(com.baidu.hugegraph.HugeException)

Example 17 with HugeException

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);
    }
}
Also used : Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) FileBasedConfigurationBuilder(org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder) ImmutableNode(org.apache.commons.configuration2.tree.ImmutableNode) FileBasedConfiguration(org.apache.commons.configuration2.FileBasedConfiguration) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) HugeException(com.baidu.hugegraph.HugeException) YAMLConfiguration(org.apache.commons.configuration2.YAMLConfiguration) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException)

Example 18 with HugeException

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);
    }
}
Also used : TraversalStrategy(org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy) Bindings(javax.script.Bindings) HugeException(com.baidu.hugegraph.HugeException) ScriptEngine(javax.script.ScriptEngine) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) ScriptException(javax.script.ScriptException) Map(java.util.Map)

Example 19 with HugeException

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);
}
Also used : Path(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path) IntMap(com.baidu.hugegraph.util.collection.IntMap) Id(com.baidu.hugegraph.backend.id.Id) HugeException(com.baidu.hugegraph.HugeException)

Example 20 with HugeException

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;
}
Also used : HugeException(com.baidu.hugegraph.HugeException) ContextGremlinServer(com.baidu.hugegraph.auth.ContextGremlinServer) Log(com.baidu.hugegraph.util.Log) Logger(org.slf4j.Logger) ConfigUtil(com.baidu.hugegraph.util.ConfigUtil) GremlinServer(org.apache.tinkerpop.gremlin.server.GremlinServer) Settings(org.apache.tinkerpop.gremlin.server.Settings) EventHub(com.baidu.hugegraph.event.EventHub) E(com.baidu.hugegraph.util.E) ContextGremlinServer(com.baidu.hugegraph.auth.ContextGremlinServer) HugeException(com.baidu.hugegraph.HugeException) Settings(org.apache.tinkerpop.gremlin.server.Settings) HugeException(com.baidu.hugegraph.HugeException)

Aggregations

HugeException (com.baidu.hugegraph.HugeException)59 Id (com.baidu.hugegraph.backend.id.Id)11 TimeoutException (java.util.concurrent.TimeoutException)6 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)5 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)5 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)4 File (java.io.File)4 Map (java.util.Map)4 HugeGraph (com.baidu.hugegraph.HugeGraph)3 Condition (com.baidu.hugegraph.backend.query.Condition)3 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)3 ConfigException (com.baidu.hugegraph.config.ConfigException)3 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)3 SchemaElement (com.baidu.hugegraph.schema.SchemaElement)3 StringReader (java.io.StringReader)3 PeerId (com.alipay.sofa.jraft.entity.PeerId)2 BackendException (com.baidu.hugegraph.backend.BackendException)2 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)2 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)2 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)2