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