Search in sources :

Example 1 with Task

use of com.baidu.hugegraph.structure.Task in project incubator-hugegraph-toolchain by apache.

the class TaskApiTest method testListByStatus.

@Test
public void testListByStatus() {
    IndexLabel personByCity = schema().getIndexLabel("personByCity");
    IndexLabel personByAge = schema().getIndexLabel("personByAge");
    IndexLabel knowsByDate = schema().getIndexLabel("knowsByDate");
    IndexLabel createdByDate = schema().getIndexLabel("createdByDate");
    Set<Long> taskIds = new HashSet<>();
    taskIds.add(rebuildAPI.rebuild(personByCity));
    taskIds.add(rebuildAPI.rebuild(personByAge));
    taskIds.add(rebuildAPI.rebuild(knowsByDate));
    taskIds.add(rebuildAPI.rebuild(createdByDate));
    taskIds.forEach(BaseApiTest::waitUntilTaskCompleted);
    List<Task> tasks = taskAPI.list("SUCCESS", -1);
    Assert.assertEquals(4, tasks.size());
    Set<Long> listedTaskIds = new HashSet<>();
    for (Task task : tasks) {
        listedTaskIds.add(task.id());
    }
    Assert.assertEquals(taskIds.size(), listedTaskIds.size());
    Assert.assertTrue(taskIds.containsAll(listedTaskIds));
    tasks = taskAPI.list("SUCCESS", 3);
    Assert.assertEquals(3, tasks.size());
    Set<Long> listedTaskIds1 = new HashSet<>();
    for (Task task : tasks) {
        listedTaskIds1.add(task.id());
    }
    Assert.assertEquals(3, listedTaskIds1.size());
    Assert.assertTrue(taskIds.containsAll(listedTaskIds));
}
Also used : Task(com.baidu.hugegraph.structure.Task) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Task

use of com.baidu.hugegraph.structure.Task in project incubator-hugegraph-toolchain by apache.

the class TaskApiTest method testListByIds.

@Test
public void testListByIds() {
    IndexLabel personByCity = schema().getIndexLabel("personByCity");
    IndexLabel personByAge = schema().getIndexLabel("personByAge");
    IndexLabel knowsByDate = schema().getIndexLabel("knowsByDate");
    IndexLabel createdByDate = schema().getIndexLabel("createdByDate");
    List<Long> taskIds = new ArrayList<>();
    taskIds.add(rebuildAPI.rebuild(personByCity));
    taskIds.add(rebuildAPI.rebuild(personByAge));
    taskIds.add(rebuildAPI.rebuild(knowsByDate));
    taskIds.add(rebuildAPI.rebuild(createdByDate));
    taskIds.forEach(BaseApiTest::waitUntilTaskCompleted);
    List<Task> tasks = taskAPI.list(taskIds);
    Assert.assertEquals(4, tasks.size());
    Set<Long> listedTaskIds = new HashSet<>();
    for (Task task : tasks) {
        listedTaskIds.add(task.id());
    }
    Assert.assertEquals(taskIds.size(), listedTaskIds.size());
    Assert.assertTrue(taskIds.containsAll(listedTaskIds));
}
Also used : Task(com.baidu.hugegraph.structure.Task) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Task

use of com.baidu.hugegraph.structure.Task in project incubator-hugegraph-toolchain by apache.

the class TaskApiTest method testTaskAsMap.

@Test
public void testTaskAsMap() {
    IndexLabel personByCity = schema().getIndexLabel("personByCity");
    long taskId = rebuildAPI.rebuild(personByCity);
    Task task = taskAPI.get(taskId);
    Assert.assertNotNull(task);
    Assert.assertEquals(taskId, task.id());
    waitUntilTaskCompleted(taskId);
    task = taskAPI.get(taskId);
    Map<String, Object> taskMap = task.asMap();
    Assert.assertEquals("rebuild_index", taskMap.get(Task.P.TYPE));
    Assert.assertEquals("success", taskMap.get(Task.P.STATUS));
}
Also used : Task(com.baidu.hugegraph.structure.Task) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

Example 4 with Task

use of com.baidu.hugegraph.structure.Task in project incubator-hugegraph-toolchain by apache.

the class TaskApiTest method testListByStatusAndPage.

@Test
public void testListByStatusAndPage() {
    IndexLabel personByCity = schema().getIndexLabel("personByCity");
    IndexLabel personByAge = schema().getIndexLabel("personByAge");
    IndexLabel knowsByDate = schema().getIndexLabel("knowsByDate");
    IndexLabel createdByDate = schema().getIndexLabel("createdByDate");
    Set<Long> taskIds = new HashSet<>();
    taskIds.add(rebuildAPI.rebuild(personByCity));
    taskIds.add(rebuildAPI.rebuild(personByAge));
    taskIds.add(rebuildAPI.rebuild(knowsByDate));
    taskIds.add(rebuildAPI.rebuild(createdByDate));
    taskIds.forEach(BaseApiTest::waitUntilTaskCompleted);
    TasksWithPage tasksWithPage = taskAPI.list("SUCCESS", "", 2);
    List<Task> tasks = tasksWithPage.tasks();
    Assert.assertEquals(2, tasks.size());
    Set<Long> listedTaskIds = new HashSet<>();
    for (Task task : tasks) {
        listedTaskIds.add(task.id());
    }
    tasksWithPage = taskAPI.list("SUCCESS", tasksWithPage.page(), 2);
    List<Task> tasks1 = tasksWithPage.tasks();
    Assert.assertEquals(2, tasks1.size());
    Assert.assertNull(tasksWithPage.page());
    for (Task task : tasks1) {
        listedTaskIds.add(task.id());
    }
    Assert.assertEquals(taskIds.size(), listedTaskIds.size());
    Assert.assertTrue(taskIds.containsAll(listedTaskIds));
}
Also used : Task(com.baidu.hugegraph.structure.Task) TasksWithPage(com.baidu.hugegraph.api.task.TasksWithPage) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with Task

use of com.baidu.hugegraph.structure.Task in project incubator-hugegraph-toolchain by apache.

the class AsyncTaskService method list.

public IPage<Task> list(int connId, int pageNo, int pageSize, String content, String type, String status) {
    HugeClient client = this.getClient(connId);
    if (status.isEmpty()) {
        status = null;
    }
    List<Task> tasks = client.task().list(status);
    List<Task> result = new ArrayList<>();
    for (Task task : tasks) {
        if (!type.isEmpty() && !type.equals(task.type())) {
            continue;
        }
        if (!content.isEmpty()) {
            String taskId = String.valueOf(task.id());
            if (!content.equals(taskId) && !task.name().contains(content)) {
                continue;
            }
        }
        result.add(task);
    }
    result.sort(Comparator.comparing(Task::createTime).reversed());
    return PageUtil.page(result, pageNo, pageSize);
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) Task(com.baidu.hugegraph.structure.Task) ArrayList(java.util.ArrayList)

Aggregations

Task (com.baidu.hugegraph.structure.Task)18 Test (org.junit.Test)12 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)7 HashSet (java.util.HashSet)4 HugeClient (com.baidu.hugegraph.driver.HugeClient)3 ArrayList (java.util.ArrayList)3 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)2 ExecuteHistory (com.baidu.hugegraph.entity.query.ExecuteHistory)2 InternalException (com.baidu.hugegraph.exception.InternalException)2 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)2 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)2 GremlinRequest (com.baidu.hugegraph.api.gremlin.GremlinRequest)1 TaskAPI (com.baidu.hugegraph.api.task.TaskAPI)1 TasksWithPage (com.baidu.hugegraph.api.task.TasksWithPage)1 ExternalException (com.baidu.hugegraph.exception.ExternalException)1 AuthBackupRestoreManager (com.baidu.hugegraph.manager.AuthBackupRestoreManager)1 BackupManager (com.baidu.hugegraph.manager.BackupManager)1 DumpGraphManager (com.baidu.hugegraph.manager.DumpGraphManager)1 GraphsManager (com.baidu.hugegraph.manager.GraphsManager)1 GremlinManager (com.baidu.hugegraph.manager.GremlinManager)1