Search in sources :

Example 6 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class PropertyKeyBuilder method create.

@Override
public PropertyKey create() {
    // Create index label async
    SchemaElement.TaskWithSchema propertyKeyWithTask = this.createWithTask();
    Id task = propertyKeyWithTask.task();
    if (task == IdGenerator.ZERO) {
        /*
             * Task id will be IdGenerator.ZERO if creating property key
             * already exists or creating property key is oltp
             */
        return propertyKeyWithTask.propertyKey();
    }
    // Wait task completed (change to sync mode)
    HugeGraph graph = this.graph();
    long timeout = graph.option(CoreOptions.TASK_WAIT_TIMEOUT);
    try {
        graph.taskScheduler().waitUntilTaskCompleted(task, timeout);
    } catch (TimeoutException e) {
        throw new HugeException("Failed to wait property key create task completed", e);
    }
    // Return property key without task-info
    return propertyKeyWithTask.propertyKey();
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) SchemaElement(com.baidu.hugegraph.schema.SchemaElement) Id(com.baidu.hugegraph.backend.id.Id) HugeException(com.baidu.hugegraph.HugeException) TimeoutException(java.util.concurrent.TimeoutException)

Example 7 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class VertexLabelRemoveJob method removeVertexLabel.

private static void removeVertexLabel(HugeGraphParams graph, Id id) {
    GraphTransaction graphTx = graph.graphTransaction();
    SchemaTransaction schemaTx = graph.schemaTransaction();
    VertexLabel vertexLabel = schemaTx.getVertexLabel(id);
    // If the vertex label does not exist, return directly
    if (vertexLabel == null) {
        return;
    }
    if (vertexLabel.status().deleting()) {
        LOG.info("The vertex label '{}' has been in {} status, " + "please check if it's expected to delete it again", vertexLabel, vertexLabel.status());
    }
    // Check no edge label use the vertex label
    List<EdgeLabel> edgeLabels = schemaTx.getEdgeLabels();
    for (EdgeLabel edgeLabel : edgeLabels) {
        if (edgeLabel.linkWithLabel(id)) {
            throw new HugeException("Not allowed to remove vertex label '%s' " + "because the edge label '%s' still link with it", vertexLabel.name(), edgeLabel.name());
        }
    }
    /*
         * Copy index label ids because removeIndexLabel will mutate
         * vertexLabel.indexLabels()
         */
    Set<Id> indexLabelIds = ImmutableSet.copyOf(vertexLabel.indexLabels());
    LockUtil.Locks locks = new LockUtil.Locks(graph.name());
    try {
        locks.lockWrites(LockUtil.VERTEX_LABEL_DELETE, id);
        schemaTx.updateSchemaStatus(vertexLabel, SchemaStatus.DELETING);
        try {
            for (Id ilId : indexLabelIds) {
                IndexLabelRemoveJob.removeIndexLabel(graph, ilId);
            }
            // TODO: use event to replace direct call
            // Deleting a vertex will automatically deletes the held edge
            graphTx.removeVertices(vertexLabel);
            /*
                 * Should commit changes to backend store before release
                 * delete lock
                 */
            graph.graph().tx().commit();
            // Remove vertex label
            removeSchema(schemaTx, vertexLabel);
        } catch (Throwable e) {
            schemaTx.updateSchemaStatus(vertexLabel, SchemaStatus.UNDELETED);
            throw e;
        }
    } finally {
        locks.unlock();
    }
}
Also used : LockUtil(com.baidu.hugegraph.util.LockUtil) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) Id(com.baidu.hugegraph.backend.id.Id) HugeException(com.baidu.hugegraph.HugeException) SchemaTransaction(com.baidu.hugegraph.backend.tx.SchemaTransaction)

Example 8 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class SchemaLabel method getLabelId.

public static Id getLabelId(HugeGraph graph, HugeType type, Object label) {
    E.checkNotNull(graph, "graph");
    E.checkNotNull(type, "type");
    E.checkNotNull(label, "label");
    if (label instanceof Number) {
        return IdGenerator.of(((Number) label).longValue());
    } else if (label instanceof String) {
        if (type.isVertex()) {
            return graph.vertexLabel((String) label).id();
        } else if (type.isEdge()) {
            return graph.edgeLabel((String) label).id();
        } else {
            throw new HugeException("Not support query from '%s' with label '%s'", type, label);
        }
    } else {
        throw new HugeException("The label type must be number or string, but got '%s'", label.getClass());
    }
}
Also used : HugeException(com.baidu.hugegraph.HugeException)

Example 9 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class ContextGremlinServer method removeGraph.

private void removeGraph(String name) {
    GraphManager manager = this.getServerGremlinExecutor().getGraphManager();
    GremlinExecutor executor = this.getServerGremlinExecutor().getGremlinExecutor();
    try {
        manager.removeGraph(name);
        manager.removeTraversalSource(G_PREFIX + name);
        Whitebox.invoke(executor, "globalBindings", new Class<?>[] { Object.class }, "remove", name);
    } catch (Exception e) {
        throw new HugeException("Failed to remove graph '%s' from " + "gremlin server context", e, name);
    }
}
Also used : GraphManager(org.apache.tinkerpop.gremlin.server.GraphManager) GremlinExecutor(org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor) HugeException(com.baidu.hugegraph.HugeException) HugeException(com.baidu.hugegraph.HugeException)

Example 10 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class HugeAuthenticator method loadAuthenticator.

public static HugeAuthenticator loadAuthenticator(HugeConfig conf) {
    String authClass = conf.get(ServerOptions.AUTHENTICATOR);
    if (authClass.isEmpty()) {
        return null;
    }
    HugeAuthenticator authenticator;
    ClassLoader cl = conf.getClass().getClassLoader();
    try {
        authenticator = (HugeAuthenticator) cl.loadClass(authClass).newInstance();
    } catch (Exception e) {
        throw new HugeException("Failed to load authenticator: '%s'", authClass, e);
    }
    authenticator.setup(conf);
    return authenticator;
}
Also used : HugeException(com.baidu.hugegraph.HugeException) HugeException(com.baidu.hugegraph.HugeException) AuthenticationException(org.apache.tinkerpop.gremlin.server.auth.AuthenticationException)

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