use of com.baidu.hugegraph.task.TaskScheduler in project incubator-hugegraph by apache.
the class TaskAPI method get.
@GET
@Timed
@Path("{id}")
@Produces(APPLICATION_JSON_WITH_CHARSET)
public Map<String, Object> get(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") long id) {
LOG.debug("Graph [{}] get task: {}", graph, id);
TaskScheduler scheduler = graph(manager, graph).taskScheduler();
return scheduler.task(IdGenerator.of(id)).asMap();
}
use of com.baidu.hugegraph.task.TaskScheduler in project incubator-hugegraph by apache.
the class StandardHugeGraph method taskScheduler.
@Override
public TaskScheduler taskScheduler() {
TaskScheduler scheduler = this.taskManager.getScheduler(this.params);
E.checkState(scheduler != null, "Can't find task scheduler for graph '%s'", this);
return scheduler;
}
use of com.baidu.hugegraph.task.TaskScheduler in project incubator-hugegraph by apache.
the class EphemeralJobBuilder method schedule.
public HugeTask<V> schedule() {
E.checkArgumentNotNull(this.name, "Job name can't be null");
E.checkArgumentNotNull(this.job, "Job can't be null");
HugeTask<V> task = new HugeTask<>(this.genTaskId(), null, this.job);
task.type(this.job.type());
task.name(this.name);
if (this.input != null) {
task.input(this.input);
}
TaskScheduler scheduler = this.graph.taskScheduler();
scheduler.schedule(task);
return task;
}
use of com.baidu.hugegraph.task.TaskScheduler in project incubator-hugegraph by apache.
the class TaskCoreTest method testGremlinJobAndCancel.
@Test
public void testGremlinJobAndCancel() throws TimeoutException {
HugeGraph graph = graph();
TaskScheduler scheduler = graph.taskScheduler();
HugeTask<Object> task = runGremlinJob("Thread.sleep(1000 * 10);");
sleepAWhile();
task = scheduler.task(task.id());
scheduler.cancel(task);
task = scheduler.task(task.id());
Assert.assertEquals(TaskStatus.CANCELLING, task.status());
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.CANCELLED, task.status());
Assert.assertEquals("test-gremlin-job", task.name());
Assert.assertTrue(task.result(), task.result() == null || task.result().endsWith("InterruptedException"));
// Cancel success task
HugeTask<Object> task2 = runGremlinJob("1+2");
task2 = scheduler.waitUntilTaskCompleted(task2.id(), 10);
Assert.assertEquals(TaskStatus.SUCCESS, task2.status());
scheduler.cancel(task2);
task2 = scheduler.task(task2.id());
Assert.assertEquals(TaskStatus.SUCCESS, task2.status());
Assert.assertEquals("3", task2.result());
// Cancel failure task with big results (job size exceeded limit)
String bigList = "def l=[]; for (i in 1..800001) l.add(i); l;";
HugeTask<Object> task3 = runGremlinJob(bigList);
task3 = scheduler.waitUntilTaskCompleted(task3.id(), 12);
Assert.assertEquals(TaskStatus.FAILED, task3.status());
scheduler.cancel(task3);
task3 = scheduler.task(task3.id());
Assert.assertEquals(TaskStatus.FAILED, task3.status());
Assert.assertContains("LimitExceedException: Job results size 800001 " + "has exceeded the max limit 800000", task3.result());
// Cancel failure task with big results (task exceeded limit 16M)
String bigResults = "def random = new Random(); def rs=[];" + "for (i in 0..4) {" + " def len = 1024 * 1024;" + " def item = new StringBuilder(len);" + " for (j in 0..len) { " + " item.append(\"node:\"); " + " item.append((char) random.nextInt(256)); " + " item.append(\",\"); " + " };" + " rs.add(item);" + "};" + "rs;";
HugeTask<Object> task4 = runGremlinJob(bigResults);
task4 = scheduler.waitUntilTaskCompleted(task4.id(), 10);
Assert.assertEquals(TaskStatus.FAILED, task4.status());
scheduler.cancel(task4);
task4 = scheduler.task(task4.id());
Assert.assertEquals(TaskStatus.FAILED, task4.status());
Assert.assertContains("LimitExceedException: Task result size", task4.result());
Assert.assertContains("exceeded limit 16777216 bytes", task4.result());
}
use of com.baidu.hugegraph.task.TaskScheduler in project incubator-hugegraph by apache.
the class TaskCoreTest method testTask.
@Test
public void testTask() throws TimeoutException {
HugeGraph graph = graph();
TaskScheduler scheduler = graph.taskScheduler();
TaskCallable<Object> callable = new SleepCallable<>();
Id id = IdGenerator.of(88888);
HugeTask<?> task = new HugeTask<>(id, null, callable);
task.type("test");
task.name("test-task");
scheduler.schedule(task);
Assert.assertEquals(id, task.id());
Assert.assertFalse(task.completed());
Assert.assertThrows(IllegalArgumentException.class, () -> {
scheduler.delete(id);
}, e -> {
Assert.assertContains("Can't delete incomplete task '88888'", e.getMessage());
});
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(id, task.id());
Assert.assertEquals("test-task", task.name());
Assert.assertEquals(TaskStatus.SUCCESS, task.status());
Assert.assertEquals("test-task", scheduler.task(id).name());
Assert.assertEquals("test-task", scheduler.tasks(Arrays.asList(id)).next().name());
Iterator<HugeTask<Object>> iter = scheduler.tasks(ImmutableList.of(id));
Assert.assertTrue(iter.hasNext());
Assert.assertEquals("test-task", iter.next().name());
Assert.assertFalse(iter.hasNext());
iter = scheduler.tasks(TaskStatus.SUCCESS, 10, null);
Assert.assertTrue(iter.hasNext());
Assert.assertEquals("test-task", iter.next().name());
Assert.assertFalse(iter.hasNext());
iter = scheduler.tasks(null, 10, null);
Assert.assertTrue(iter.hasNext());
Assert.assertEquals("test-task", iter.next().name());
Assert.assertFalse(iter.hasNext());
scheduler.delete(id);
iter = scheduler.tasks(null, 10, null);
Assert.assertFalse(iter.hasNext());
Assert.assertThrows(NotFoundException.class, () -> {
scheduler.task(id);
});
}
Aggregations