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

Make task-list api not return task_input and task_result #143

Merged
merged 1 commit into from
Nov 6, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ public String name() {
@Override
public void checkCreate(boolean isBatch) {
E.checkArgumentNotNull(this.gremlin,
"The gremlin script can't be null");
"The gremlin parameter can't be null");
E.checkArgumentNotNull(this.language,
"The language parameter can't be null");
E.checkArgument(this.aliases == null || this.aliases.isEmpty(),
"There is no need to pass gremlin aliases");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.baidu.hugegraph.server.RestServer;
import com.baidu.hugegraph.task.HugeTask;
import com.baidu.hugegraph.task.HugeTaskScheduler;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;
import com.codahale.metrics.annotation.Timed;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -82,7 +83,7 @@ public Map<String, List<Object>> list(@Context GraphManager manager,

List<Object> tasks = new ArrayList<>();
while (itor.hasNext()) {
tasks.add(itor.next().asMap());
tasks.add(itor.next().asMap(false));
}
return ImmutableMap.of("tasks", tasks);
}
Expand Down Expand Up @@ -111,15 +112,8 @@ public void delete(@Context GraphManager manager,

HugeGraph g = graph(manager, graph);
HugeTaskScheduler scheduler = g.taskScheduler();

HugeTask<?> task = scheduler.task(IdGenerator.of(id));
if (task.completed()) {
scheduler.deleteTask(IdGenerator.of(id));
} else {
throw new BadRequestException(String.format(
"Can't delete task '%s' with unstable status '%s'",
id, task.status()));
}
HugeTask<?> task = scheduler.deleteTask(IdGenerator.of(id));
E.checkArgument(task != null, "There is no task with id '%s'", id);
}

@PUT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public String list(@Context GraphManager manager,
LOG.debug("Graph [{}] get edges by ids: {}", graph, stringIds);

E.checkArgument(stringIds != null && !stringIds.isEmpty(),
"Ids can't be null or empty");
"The ids parameter can't be null or empty");

Object[] ids = new Id[stringIds.size()];
for (int i = 0; i < ids.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public String list(@Context GraphManager manager,
LOG.debug("Graph [{}] get vertices by ids: {}", graph, stringIds);

E.checkArgument(stringIds != null && !stringIds.isEmpty(),
"Ids can't be null or empty");
"The ids parameter can't be null or empty");

Object[] ids = new Id[stringIds.size()];
for (int i = 0; i < ids.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ public AuthenticatedUser authenticate(final Map<String, String> credentials)
* @return String No permission if return ROLE_NONE else return a role
*/
public String authenticate(final String username, final String password) {
E.checkArgumentNotNull(username, "The username can't be null");
E.checkArgumentNotNull(password, "The password can't be null");
E.checkArgument(username != null,
"The username parameter can't be null");
E.checkArgument(password != null,
"The password parameter can't be null");

String role;
if (password.equals(this.tokens.get(username))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,28 @@ public IndexLabel.Builder indexLabel(String name) {
}

public PropertyKey getPropertyKey(String name) {
E.checkArgumentNotNull(name, "Name can't be null");
E.checkArgumentNotNull(name, "The name parameter can't be null");
PropertyKey propertyKey = this.transaction.getPropertyKey(name);
checkExists(HugeType.PROPERTY_KEY, propertyKey, name);
return propertyKey;
}

public VertexLabel getVertexLabel(String name) {
E.checkArgumentNotNull(name, "Name can't be null");
E.checkArgumentNotNull(name, "The name parameter can't be null");
VertexLabel vertexLabel = this.transaction.getVertexLabel(name);
checkExists(HugeType.VERTEX_LABEL, vertexLabel, name);
return vertexLabel;
}

public EdgeLabel getEdgeLabel(String name) {
E.checkArgumentNotNull(name, "Name can't be null");
E.checkArgumentNotNull(name, "The name parameter can't be null");
EdgeLabel edgeLabel = this.transaction.getEdgeLabel(name);
checkExists(HugeType.EDGE_LABEL, edgeLabel, name);
return edgeLabel;
}

public IndexLabel getIndexLabel(String name) {
E.checkArgumentNotNull(name, "Name can't be null");
E.checkArgumentNotNull(name, "The name parameter can't be null");
IndexLabel indexLabel = this.transaction.getIndexLabel(name);
checkExists(HugeType.INDEX_LABEL, indexLabel, name);
return indexLabel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ protected Object[] asArray() {
}

public Map<String, Object> asMap() {
return this.asMap(true);
}

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

Expand All @@ -372,10 +376,10 @@ public Map<String, Object> asMap() {
if (this.update != null) {
map.put(Hidden.unHide(P.UPDATE), this.update);
}
if (this.input != null) {
if (withDetails && this.input != null) {
map.put(Hidden.unHide(P.INPUT), this.input);
}
if (this.result != null) {
if (withDetails && this.result != null) {
map.put(Hidden.unHide(P.RESULT), this.result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ private <V> Future<?> submitTask(HugeTask<V> task) {

public <V> void cancel(HugeTask<V> task) {
E.checkArgumentNotNull(task, "Task can't be null");
this.tasks.remove(task.id());
task.cancel(true);
if (!task.completed()) {
task.cancel(true);
this.remove(task.id());
}
}

protected void remove(Id id) {
Expand Down Expand Up @@ -212,17 +214,34 @@ public <V> Iterator<HugeTask<V>> findTask(Status status, long limit) {

public <V> HugeTask<V> deleteTask(Id id) {
HugeTask<?> task = this.tasks.get(id);
/*
* Tasks are removed from memory after completed at most time,
* but there is a tiny gap between tasks are completed and
* removed from memory.
* We assume tasks only in memory may be incomplete status,
* in fact, it is also possible to appear on the backend tasks
* when the database status is inconsistent.
*/
if (task != null) {
E.checkState(task.completed(),
"Can't delete task '%s' in status %s",
"Can't delete incomplete task '%s' in status '%s'. " +
"Please try to cancel the task first",
id, task.status());
this.remove(id);
}
return this.submit(() -> {
HugeTask<V> result = null;
Iterator<Vertex> vertices = this.tx().queryVertices(id);
if (vertices.hasNext()) {
this.tx().removeVertex((HugeVertex) vertices.next());
HugeVertex vertex = (HugeVertex) vertices.next();
result = HugeTask.fromVertex(vertex);
E.checkState(result.completed(),
"Can't delete incomplete task '%s' in status '%s'",
id, result.status());
this.tx().removeVertex(vertex);
assert !vertices.hasNext();
}
return result;
});
}

Expand Down