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);
}
}
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);
}
}
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);
}
}
}
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();
}
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);
}
}
Aggregations