Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapt to schedule async task in cluster #89

Merged
merged 3 commits into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 12 additions & 35 deletions src/main/java/com/baidu/hugegraph/structure/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@

package com.baidu.hugegraph.structure;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.baidu.hugegraph.util.E;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableSet;

Expand Down Expand Up @@ -68,6 +65,9 @@ public class Task {
@JsonProperty(P.DEPENDENCIES)
private Set<Long> dependencies;

@JsonProperty(P.SERVER)
private String server;

public long id() {
return this.id;
}
Expand Down Expand Up @@ -120,6 +120,10 @@ public Set<Long> dependencies() {
return this.dependencies;
}

public String server() {
return this.server;
}

public boolean completed() {
return ImmutableSet.of("success", "failed", "cancelled")
.contains(this.status);
Expand All @@ -129,40 +133,12 @@ public boolean cancelled() {
return "cancelled".equals(this.status);
}

public boolean success() {
return "success".equals(this.status);
public boolean cancelling() {
return "cancelling".equals(this.status);
}

public Map<String, Object> asMap() {
E.checkState(this.name != null, "Task name can't be null");

Map<String, Object> map = new HashMap<>();

map.put(P.ID, this.id);
map.put(P.TYPE, this.type);
map.put(P.NAME, this.name);
map.put(P.CALLABLE, this.callable);
map.put(P.STATUS, this.status);
map.put(P.PROGRESS, this.progress);
map.put(P.CREATE, this.create);
map.put(P.RETRIES, this.retries);
if (this.description != null) {
map.put(P.DESCRIPTION, this.description);
}
if (this.update != 0) {
map.put(P.UPDATE, this.update);
}
if (this.input != null) {
map.put(P.INPUT, this.input);
}
if (this.result != null) {
map.put(P.RESULT, this.result);
}
if (this.dependencies != null) {
map.put(P.DEPENDENCIES, this.dependencies);
}

return map;
public boolean success() {
return "success".equals(this.status);
}

@Override
Expand All @@ -185,5 +161,6 @@ public static final class P {
public static final String INPUT = "task_input";
public static final String RESULT = "task_result";
public static final String DEPENDENCIES = "task_dependencies";
public static final String SERVER = "task_server";
}
}
9 changes: 9 additions & 0 deletions src/test/java/com/baidu/hugegraph/api/TaskApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ public void testCancel() {
}
// Cancel async task
Task task = taskAPI.cancel(taskId);
Assert.assertTrue(task.cancelling());

try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
// ignored
}

task = taskAPI.get(taskId);
Assert.assertTrue(task.cancelled());

resultSet = gremlin().execute(request);
Expand Down
12 changes: 9 additions & 3 deletions src/test/java/com/baidu/hugegraph/functional/EdgeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,15 @@ public void testIterateEdgesByVertexId() {

Map<String, Object> properties = ImmutableMap.of("date",
"P.gt(\"2012-1-1\")");
edges = graph().iterateEdges(markoId, Direction.OUT, "knows",
properties, 1);
Assert.assertEquals(2, Iterators.size(edges));
Assert.assertThrows(ServerException.class, () -> {
Iterator<Edge> iter = graph().iterateEdges(markoId, Direction.OUT,
"knows", properties,
1);
Iterators.size(iter);
}, e -> {
Assert.assertEquals("Can't query by paging and filtering",
e.getMessage());
});
}

private static void assertContains(List<Edge> edges, Object source,
Expand Down