Search in sources :

Example 31 with HugeException

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

the class ContextGremlinServer method injectTraversalSource.

public void injectTraversalSource() {
    GraphManager manager = this.getServerGremlinExecutor().getGraphManager();
    for (String graph : manager.getGraphNames()) {
        GraphTraversalSource g = manager.getGraph(graph).traversal();
        String gName = G_PREFIX + graph;
        if (manager.getTraversalSource(gName) != null) {
            throw new HugeException("Found existing name '%s' in global bindings, " + "it may lead to gremlin query error.", gName);
        }
        // Add a traversal source for all graphs with customed rule.
        manager.putTraversalSource(gName, g);
    }
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) GraphManager(org.apache.tinkerpop.gremlin.server.GraphManager) HugeException(com.baidu.hugegraph.HugeException)

Example 32 with HugeException

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

the class JsonSerializer method writeList.

@Override
public String writeList(String label, Collection<?> list) {
    try (ByteArrayOutputStream out = new ByteArrayOutputStream(LBUF_SIZE)) {
        out.write(String.format("{\"%s\": ", label).getBytes(API.CHARSET));
        out.write(JsonUtil.toJson(list).getBytes(API.CHARSET));
        out.write("}".getBytes(API.CHARSET));
        return out.toString(API.CHARSET);
    } catch (Exception e) {
        throw new HugeException("Failed to serialize %s", e, label);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) HugeException(com.baidu.hugegraph.HugeException) HugeException(com.baidu.hugegraph.HugeException)

Example 33 with HugeException

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

the class JsonSerializer method writeIterator.

private String writeIterator(String label, Iterator<?> iter, boolean paging) {
    // Early throw if needed
    iter.hasNext();
    // Serialize Iterator
    try (ByteArrayOutputStream out = new ByteArrayOutputStream(LBUF_SIZE)) {
        out.write("{".getBytes(API.CHARSET));
        out.write(String.format("\"%s\":[", label).getBytes(API.CHARSET));
        // Write data
        boolean first = true;
        while (iter.hasNext()) {
            if (!first) {
                out.write(",".getBytes(API.CHARSET));
            } else {
                first = false;
            }
            out.write(JsonUtil.toJson(iter.next()).getBytes(API.CHARSET));
        }
        out.write("]".getBytes(API.CHARSET));
        // Write page
        if (paging) {
            String page;
            if (iter instanceof GraphTraversal<?, ?>) {
                page = TraversalUtil.page((GraphTraversal<?, ?>) iter);
            } else if (iter instanceof Metadatable) {
                page = PageInfo.pageInfo(iter);
            } else {
                throw new HugeException("Invalid paging iterator: %s", iter.getClass());
            }
            if (page != null) {
                page = String.format(",\"page\": \"%s\"", page);
            } else {
                page = ",\"page\": null";
            }
            out.write(page.getBytes(API.CHARSET));
        }
        out.write("}".getBytes(API.CHARSET));
        return out.toString(API.CHARSET);
    } catch (HugeException e) {
        throw e;
    } catch (Exception e) {
        throw new HugeException("Failed to serialize %s", e, label);
    } finally {
        try {
            CloseableIterator.closeIterator(iter);
        } catch (Exception e) {
            throw new HugeException("Failed to close for %s", e, label);
        }
    }
}
Also used : Metadatable(com.baidu.hugegraph.iterator.Metadatable) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HugeException(com.baidu.hugegraph.HugeException) HugeException(com.baidu.hugegraph.HugeException)

Example 34 with HugeException

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

the class JsonSerializer method writeTaskWithSchema.

@Override
public String writeTaskWithSchema(SchemaElement.TaskWithSchema taskWithSchema) {
    StringBuilder builder = new StringBuilder();
    long id = taskWithSchema.task() == null ? 0L : taskWithSchema.task().asLong();
    SchemaElement schemaElement = taskWithSchema.schemaElement();
    String type;
    String schema;
    if (schemaElement instanceof PropertyKey) {
        type = "property_key";
        schema = this.writePropertyKey((PropertyKey) schemaElement);
    } else if (schemaElement instanceof IndexLabel) {
        type = "index_label";
        schema = this.writeIndexlabel((IndexLabel) schemaElement);
    } else {
        throw new HugeException("Invalid schema element '%s' in " + "TaskWithSchema, only support " + "[PropertyKey, IndexLabel]", schemaElement);
    }
    return builder.append("{\"").append(type).append("\": ").append(schema).append(", \"task_id\": ").append(id).append("}").toString();
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaElement(com.baidu.hugegraph.schema.SchemaElement) HugeException(com.baidu.hugegraph.HugeException) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 35 with HugeException

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

the class LicenseVerifier method verify.

public void verify() {
    try {
        LicenseParams params = this.manager.licenseManager().verifyLicense();
        LOG.info("The license verification passed, " + "the term of validity is from {} to {}", params.notBefore(), params.notAfter());
    } catch (Exception e) {
        LOG.error("Failed to verify license", e);
        throw new HugeException("Failed to verify license", e);
    }
}
Also used : HugeException(com.baidu.hugegraph.HugeException) HugeException(com.baidu.hugegraph.HugeException) IOException(java.io.IOException)

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