Search in sources :

Example 11 with TaskScheduler

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();
}
Also used : TaskScheduler(com.baidu.hugegraph.task.TaskScheduler) Path(jakarta.ws.rs.Path) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 12 with TaskScheduler

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;
}
Also used : TaskScheduler(com.baidu.hugegraph.task.TaskScheduler)

Example 13 with TaskScheduler

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;
}
Also used : HugeTask(com.baidu.hugegraph.task.HugeTask) TaskScheduler(com.baidu.hugegraph.task.TaskScheduler)

Example 14 with TaskScheduler

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());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) TaskScheduler(com.baidu.hugegraph.task.TaskScheduler) Test(org.junit.Test)

Example 15 with TaskScheduler

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);
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeTask(com.baidu.hugegraph.task.HugeTask) Id(com.baidu.hugegraph.backend.id.Id) TaskScheduler(com.baidu.hugegraph.task.TaskScheduler) Test(org.junit.Test)

Aggregations

TaskScheduler (com.baidu.hugegraph.task.TaskScheduler)21 HugeGraph (com.baidu.hugegraph.HugeGraph)10 Test (org.junit.Test)10 HugeTask (com.baidu.hugegraph.task.HugeTask)8 Id (com.baidu.hugegraph.backend.id.Id)7 Timed (com.codahale.metrics.annotation.Timed)4 Path (jakarta.ws.rs.Path)3 Produces (jakarta.ws.rs.Produces)3 HugeException (com.baidu.hugegraph.HugeException)2 GremlinJob (com.baidu.hugegraph.job.GremlinJob)2 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)2 TaskCallable (com.baidu.hugegraph.task.TaskCallable)2 GET (jakarta.ws.rs.GET)2 TimeoutException (java.util.concurrent.TimeoutException)2 Status (com.baidu.hugegraph.api.filter.StatusFilter.Status)1 GremlinRequest (com.baidu.hugegraph.api.job.GremlinAPI.GremlinRequest)1 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)1 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)1 TaskStatus (com.baidu.hugegraph.task.TaskStatus)1 BadRequestException (jakarta.ws.rs.BadRequestException)1