Search in sources :

Example 21 with HugeException

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

the class RegisterUtil method registerBackends.

public static void registerBackends() {
    String confFile = "/backend.properties";
    URL input = RegisterUtil.class.getResource(confFile);
    E.checkState(input != null, "Can't read file '%s' as stream", confFile);
    PropertiesConfiguration props = null;
    try {
        props = new Configurations().properties(input);
    } catch (ConfigurationException e) {
        throw new HugeException("Can't load config file: %s", e, confFile);
    }
    HugeConfig config = new HugeConfig(props);
    List<String> backends = config.get(DistOptions.BACKENDS);
    for (String backend : backends) {
        registerBackend(backend);
    }
}
Also used : ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) Configurations(org.apache.commons.configuration2.builder.fluent.Configurations) HugeConfig(com.baidu.hugegraph.config.HugeConfig) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) HugeException(com.baidu.hugegraph.HugeException) URL(java.net.URL)

Example 22 with HugeException

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

the class ExampleUtil method waitAllTaskDone.

public static void waitAllTaskDone(HugeGraph graph) {
    TaskScheduler scheduler = graph.taskScheduler();
    Iterator<HugeTask<Object>> tasks = scheduler.tasks(null, -1L, null);
    while (tasks.hasNext()) {
        try {
            scheduler.waitUntilTaskCompleted(tasks.next().id(), 20L);
        } catch (TimeoutException e) {
            throw new HugeException("Failed to wait task done", e);
        }
    }
}
Also used : HugeTask(com.baidu.hugegraph.task.HugeTask) TaskScheduler(com.baidu.hugegraph.task.TaskScheduler) HugeException(com.baidu.hugegraph.HugeException) TimeoutException(java.util.concurrent.TimeoutException)

Example 23 with HugeException

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

the class Reflection method registerFieldsToFilter.

public static void registerFieldsToFilter(Class<?> containingClass, String... fieldNames) {
    if (REGISTER_FILEDS_TO_FILTER_METHOD == null) {
        throw new NotSupportException("Reflection.registerFieldsToFilter()");
    }
    try {
        REGISTER_FILEDS_TO_FILTER_METHOD.setAccessible(true);
        REGISTER_FILEDS_TO_FILTER_METHOD.invoke(REFLECTION_CLAZZ, containingClass, fieldNames);
    } catch (IllegalAccessException | InvocationTargetException e) {
        throw new HugeException("Failed to register class '%s' fields to filter: %s", containingClass, Arrays.toString(fieldNames));
    }
}
Also used : NotSupportException(com.baidu.hugegraph.exception.NotSupportException) HugeException(com.baidu.hugegraph.HugeException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 24 with HugeException

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

the class SecurityManagerTest method runGremlinJob.

private static String runGremlinJob(String gremlin) {
    JobBuilder<Object> builder = JobBuilder.of(graph);
    Map<String, Object> input = new HashMap<>();
    input.put("gremlin", gremlin);
    input.put("bindings", ImmutableMap.of());
    input.put("language", "gremlin-groovy");
    input.put("aliases", ImmutableMap.of());
    builder.name("test-gremlin-job").input(JsonUtil.toJson(input)).job(new GremlinJob());
    HugeTask<?> task = builder.schedule();
    try {
        task = graph.taskScheduler().waitUntilTaskCompleted(task.id(), 10);
    } catch (TimeoutException e) {
        throw new HugeException("Wait for task timeout: %s", e, task);
    }
    return task.result();
}
Also used : GremlinJob(com.baidu.hugegraph.job.GremlinJob) HashMap(java.util.HashMap) HugeException(com.baidu.hugegraph.HugeException) TimeoutException(java.util.concurrent.TimeoutException)

Example 25 with HugeException

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

the class GraphTransaction method removeEdges.

public void removeEdges(EdgeLabel edgeLabel) {
    if (this.hasUpdate()) {
        throw new HugeException("There are still changes to commit");
    }
    boolean autoCommit = this.autoCommit();
    this.autoCommit(false);
    // Commit data already in tx firstly
    this.commit();
    try {
        if (this.store().features().supportsDeleteEdgeByLabel()) {
            // TODO: Need to change to writeQuery!
            this.doRemove(this.serializer.writeId(HugeType.EDGE_OUT, edgeLabel.id()));
            this.doRemove(this.serializer.writeId(HugeType.EDGE_IN, edgeLabel.id()));
        } else {
            this.traverseEdgesByLabel(edgeLabel, edge -> {
                this.removeEdge((HugeEdge) edge);
                this.commitIfGtSize(COMMIT_BATCH);
            }, true);
        }
        this.commit();
    } catch (Exception e) {
        LOG.error("Failed to remove edges", e);
        throw new HugeException("Failed to remove edges", e);
    } finally {
        this.autoCommit(autoCommit);
    }
}
Also used : HugeException(com.baidu.hugegraph.HugeException) BackendException(com.baidu.hugegraph.backend.BackendException) LimitExceedException(com.baidu.hugegraph.exception.LimitExceedException) ForbiddenException(jakarta.ws.rs.ForbiddenException) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) 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