use of com.baidu.hugegraph.task.TaskScheduler in project incubator-hugegraph by apache.
the class TestGraph method clearSchema.
@Watched
protected void clearSchema() {
// Clear schema and graph data will be cleared at same time
SchemaManager schema = this.graph.schema();
schema.getIndexLabels().stream().forEach(elem -> {
schema.indexLabel(elem.name()).remove();
});
schema.getEdgeLabels().stream().forEach(elem -> {
schema.edgeLabel(elem.name()).remove();
});
schema.getVertexLabels().stream().forEach(elem -> {
schema.vertexLabel(elem.name()).remove();
});
schema.getPropertyKeys().stream().forEach(elem -> {
schema.propertyKey(elem.name()).remove();
});
TaskScheduler scheduler = this.graph.taskScheduler();
scheduler.tasks(null, -1, null).forEachRemaining(elem -> {
scheduler.delete(elem.id());
});
}
use of com.baidu.hugegraph.task.TaskScheduler in project incubator-hugegraph by apache.
the class TaskCoreTest method testEphemeralJob.
@Test
public void testEphemeralJob() throws TimeoutException {
HugeGraph graph = graph();
TaskScheduler scheduler = graph.taskScheduler();
EphemeralJobBuilder<Object> builder = EphemeralJobBuilder.of(graph);
builder.name("test-job-ephemeral").job(new EphemeralJob<Object>() {
@Override
public String type() {
return "test";
}
@Override
public Object execute() throws Exception {
sleepAWhile();
return ImmutableMap.of("k1", 13579, "k2", "24680");
}
});
HugeTask<Object> task = builder.schedule();
Assert.assertEquals("test-job-ephemeral", task.name());
Assert.assertEquals("test", task.type());
Assert.assertFalse(task.completed());
HugeTask<?> task2 = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.SUCCESS, task.status());
Assert.assertEquals("{\"k1\":13579,\"k2\":\"24680\"}", task.result());
Assert.assertEquals(TaskStatus.SUCCESS, task2.status());
Assert.assertEquals("{\"k1\":13579,\"k2\":\"24680\"}", task2.result());
Assert.assertThrows(NotFoundException.class, () -> {
scheduler.waitUntilTaskCompleted(task.id(), 10);
});
Assert.assertThrows(NotFoundException.class, () -> {
scheduler.task(task.id());
});
}
use of com.baidu.hugegraph.task.TaskScheduler in project incubator-hugegraph by apache.
the class TaskCoreTest method testGremlinJob.
@Test
public void testGremlinJob() throws TimeoutException {
HugeGraph graph = graph();
TaskScheduler scheduler = graph.taskScheduler();
GremlinRequest request = new GremlinRequest();
request.gremlin("sleep(100); 3 + 5");
JobBuilder<Object> builder = JobBuilder.of(graph);
builder.name("test-job-gremlin").input(request.toJson()).job(new GremlinJob());
HugeTask<Object> task = builder.schedule();
Assert.assertEquals("test-job-gremlin", task.name());
Assert.assertEquals("gremlin", task.type());
Assert.assertFalse(task.completed());
Assert.assertNull(task.result());
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals("test-job-gremlin", task.name());
Assert.assertEquals("gremlin", task.type());
Assert.assertEquals(TaskStatus.SUCCESS, task.status());
Assert.assertEquals("8", task.result());
task = scheduler.task(task.id());
Assert.assertEquals("test-job-gremlin", task.name());
Assert.assertEquals("gremlin", task.type());
Assert.assertEquals(TaskStatus.SUCCESS, task.status());
Assert.assertEquals("8", task.result());
}
use of com.baidu.hugegraph.task.TaskScheduler in project incubator-hugegraph by apache.
the class TaskCoreTest method testGremlinJobWithSerializedResults.
@Test
public void testGremlinJobWithSerializedResults() throws TimeoutException {
HugeGraph graph = graph();
TaskScheduler scheduler = graph.taskScheduler();
String script = "schema=graph.schema();" + "schema.propertyKey('name').asText().ifNotExist().create();" + "schema.vertexLabel('char').useCustomizeNumberId()" + " .properties('name').ifNotExist().create();" + "schema.edgeLabel('next').sourceLabel('char').targetLabel('char')" + " .properties('name').ifNotExist().create();" + "g.addV('char').property(id,1).property('name','A').as('a')" + " .addV('char').property(id,2).property('name','B').as('b')" + " .addV('char').property(id,3).property('name','C').as('c')" + " .addV('char').property(id,4).property('name','D').as('d')" + " .addV('char').property(id,5).property('name','E').as('e')" + " .addV('char').property(id,6).property('name','F').as('f')" + " .addE('next').from('a').to('b').property('name','ab')" + " .addE('next').from('b').to('c').property('name','bc')" + " .addE('next').from('b').to('d').property('name','bd')" + " .addE('next').from('c').to('d').property('name','cd')" + " .addE('next').from('c').to('e').property('name','ce')" + " .addE('next').from('d').to('e').property('name','de')" + " .addE('next').from('e').to('f').property('name','ef')" + " .addE('next').from('f').to('d').property('name','fd')" + " .iterate();" + "g.tx().commit(); g.E().count();";
HugeTask<Object> task = runGremlinJob(script);
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals("test-gremlin-job", task.name());
Assert.assertEquals("gremlin", task.type());
Assert.assertEquals(TaskStatus.SUCCESS, task.status());
Assert.assertEquals("[8]", task.result());
Id edgeLabelId = graph.schema().getEdgeLabel("next").id();
script = "g.V(1).outE().inV().path()";
task = runGremlinJob(script);
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.SUCCESS, task.status());
String expected = String.format("[{\"labels\":[[],[],[]],\"objects\":[" + "{\"id\":1,\"label\":\"char\",\"type\":\"vertex\"," + "\"properties\":{\"name\":\"A\"}}," + "{\"id\":\"L1>%s>>L2\",\"label\":\"next\",\"type\":\"edge\",\"outV\":1," + "\"outVLabel\":\"char\",\"inV\":2,\"" + "inVLabel\":\"char\",\"properties\":{\"name\":\"ab\"}}," + "{\"id\":2,\"label\":\"char\",\"type\":\"vertex\"," + "\"properties\":{\"name\":\"B\"}}" + "]}]", edgeLabelId);
Assert.assertEquals(expected, task.result());
script = "g.V(1).out().out().path()";
task = runGremlinJob(script);
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.SUCCESS, task.status());
expected = "[{\"labels\":[[],[],[]],\"objects\":[" + "{\"id\":1,\"label\":\"char\",\"type\":\"vertex\"," + "\"properties\":{\"name\":\"A\"}}," + "{\"id\":2,\"label\":\"char\",\"type\":\"vertex\"," + "\"properties\":{\"name\":\"B\"}}," + "{\"id\":3,\"label\":\"char\",\"type\":\"vertex\"," + "\"properties\":{\"name\":\"C\"}}]}," + "{\"labels\":[[],[],[]],\"objects\":[" + "{\"id\":1,\"label\":\"char\",\"type\":\"vertex\"," + "\"properties\":{\"name\":\"A\"}}," + "{\"id\":2,\"label\":\"char\",\"type\":\"vertex\"," + "\"properties\":{\"name\":\"B\"}}," + "{\"id\":4,\"label\":\"char\",\"type\":\"vertex\"," + "\"properties\":{\"name\":\"D\"}}]}]";
Assert.assertEquals(expected, task.result());
script = "g.V(1).outE().inV().tree()";
task = runGremlinJob(script);
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.SUCCESS, task.status());
expected = String.format("[[{\"key\":{\"id\":1,\"label\":\"char\",\"type\":\"vertex\"," + "\"properties\":{\"name\":\"A\"}}," + "\"value\":[" + "{\"key\":{\"id\":\"L1>%s>>L2\",\"label\":\"next\",\"type\":\"edge\",\"outV\":1," + "\"outVLabel\":\"char\",\"inV\":2,\"inVLabel\":\"char\"," + "\"properties\":{\"name\":\"ab\"}}," + "\"value\":[{\"key\":{\"id\":2,\"label\":\"char\",\"type\":\"vertex\"," + "\"properties\":{\"name\":\"B\"}},\"value\":[]}]}]}]]", edgeLabelId);
Assert.assertEquals(expected, task.result());
script = "g.V(1).out().out().tree()";
task = runGremlinJob(script);
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.SUCCESS, task.status());
expected = "[[{\"key\":{\"id\":1,\"label\":\"char\",\"type\":\"vertex\"," + "\"properties\":{\"name\":\"A\"}}," + "\"value\":[{\"key\":{\"id\":2,\"label\":\"char\",\"type\":\"vertex\"," + "\"properties\":{\"name\":\"B\"}}," + "\"value\":[" + "{\"key\":{\"id\":3,\"label\":\"char\",\"type\":\"vertex\",\"properties\":" + "{\"name\":\"C\"}},\"value\":[]}," + "{\"key\":{\"id\":4,\"label\":\"char\",\"type\":\"vertex\",\"properties\":" + "{\"name\":\"D\"}},\"value\":[]}]}]}]]";
Assert.assertEquals(expected, task.result());
}
use of com.baidu.hugegraph.task.TaskScheduler in project incubator-hugegraph by apache.
the class TaskAPI method delete.
@DELETE
@Timed
@Path("{id}")
public void delete(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") long id) {
LOG.debug("Graph [{}] delete task: {}", graph, id);
TaskScheduler scheduler = graph(manager, graph).taskScheduler();
HugeTask<?> task = scheduler.delete(IdGenerator.of(id));
E.checkArgument(task != null, "There is no task with id '%s'", id);
}
Aggregations