Expose whether a task is cancellable in the _tasks list API
Closes #17369
This commit is contained in:
parent
e76038e076
commit
f599ac5d5a
|
@ -57,10 +57,12 @@ public class TaskInfo implements Writeable<TaskInfo>, ToXContent {
|
||||||
|
|
||||||
private final Task.Status status;
|
private final Task.Status status;
|
||||||
|
|
||||||
|
private final boolean cancellable;
|
||||||
|
|
||||||
private final TaskId parentTaskId;
|
private final TaskId parentTaskId;
|
||||||
|
|
||||||
public TaskInfo(DiscoveryNode node, long id, String type, String action, String description, Task.Status status, long startTime,
|
public TaskInfo(DiscoveryNode node, long id, String type, String action, String description, Task.Status status, long startTime,
|
||||||
long runningTimeNanos, TaskId parentTaskId) {
|
long runningTimeNanos, boolean cancellable, TaskId parentTaskId) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.taskId = new TaskId(node.getId(), id);
|
this.taskId = new TaskId(node.getId(), id);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
@ -69,6 +71,7 @@ public class TaskInfo implements Writeable<TaskInfo>, ToXContent {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
this.runningTimeNanos = runningTimeNanos;
|
this.runningTimeNanos = runningTimeNanos;
|
||||||
|
this.cancellable = cancellable;
|
||||||
this.parentTaskId = parentTaskId;
|
this.parentTaskId = parentTaskId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +88,7 @@ public class TaskInfo implements Writeable<TaskInfo>, ToXContent {
|
||||||
}
|
}
|
||||||
startTime = in.readLong();
|
startTime = in.readLong();
|
||||||
runningTimeNanos = in.readLong();
|
runningTimeNanos = in.readLong();
|
||||||
|
cancellable = in.readBoolean();
|
||||||
parentTaskId = new TaskId(in);
|
parentTaskId = new TaskId(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +138,13 @@ public class TaskInfo implements Writeable<TaskInfo>, ToXContent {
|
||||||
return runningTimeNanos;
|
return runningTimeNanos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the task supports cancellation
|
||||||
|
*/
|
||||||
|
public boolean isCancellable() {
|
||||||
|
return cancellable;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the parent task id
|
* Returns the parent task id
|
||||||
*/
|
*/
|
||||||
|
@ -161,6 +172,7 @@ public class TaskInfo implements Writeable<TaskInfo>, ToXContent {
|
||||||
}
|
}
|
||||||
out.writeLong(startTime);
|
out.writeLong(startTime);
|
||||||
out.writeLong(runningTimeNanos);
|
out.writeLong(runningTimeNanos);
|
||||||
|
out.writeBoolean(cancellable);
|
||||||
parentTaskId.writeTo(out);
|
parentTaskId.writeTo(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,6 +190,7 @@ public class TaskInfo implements Writeable<TaskInfo>, ToXContent {
|
||||||
}
|
}
|
||||||
builder.dateValueField("start_time_in_millis", "start_time", startTime);
|
builder.dateValueField("start_time_in_millis", "start_time", startTime);
|
||||||
builder.timeValueField("running_time_in_nanos", "running_time", runningTimeNanos, TimeUnit.NANOSECONDS);
|
builder.timeValueField("running_time_in_nanos", "running_time", runningTimeNanos, TimeUnit.NANOSECONDS);
|
||||||
|
builder.field("cancellable", cancellable);
|
||||||
if (parentTaskId.isSet()) {
|
if (parentTaskId.isSet()) {
|
||||||
builder.field("parent_task_id", parentTaskId.toString());
|
builder.field("parent_task_id", parentTaskId.toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class Task {
|
||||||
status = getStatus();
|
status = getStatus();
|
||||||
}
|
}
|
||||||
return new TaskInfo(node, getId(), getType(), getAction(), description, status, startTime, System.nanoTime() - startTimeNanos,
|
return new TaskInfo(node, getId(), getType(), getAction(), description, status, startTime, System.nanoTime() - startTimeNanos,
|
||||||
parentTask);
|
this instanceof CancellableTask, parentTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksReque
|
||||||
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse;
|
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse;
|
||||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
|
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
|
||||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
||||||
|
import org.elasticsearch.action.admin.cluster.node.tasks.list.TaskInfo;
|
||||||
import org.elasticsearch.action.support.nodes.BaseNodeRequest;
|
import org.elasticsearch.action.support.nodes.BaseNodeRequest;
|
||||||
import org.elasticsearch.action.support.nodes.BaseNodesRequest;
|
import org.elasticsearch.action.support.nodes.BaseNodesRequest;
|
||||||
import org.elasticsearch.action.support.replication.ClusterStateCreationUtils;
|
import org.elasticsearch.action.support.replication.ClusterStateCreationUtils;
|
||||||
|
@ -267,6 +268,10 @@ public class CancellableTasksTests extends TaskManagerTestCase {
|
||||||
// We should have the information about the cancelled task in the cancel operation response
|
// We should have the information about the cancelled task in the cancel operation response
|
||||||
assertEquals(1, response.getTasks().size());
|
assertEquals(1, response.getTasks().size());
|
||||||
assertEquals(mainTask.getId(), response.getTasks().get(0).getId());
|
assertEquals(mainTask.getId(), response.getTasks().get(0).getId());
|
||||||
|
// Verify that all cancelled tasks reported that they support cancellation
|
||||||
|
for(TaskInfo taskInfo : response.getTasks()) {
|
||||||
|
assertTrue(taskInfo.isCancellable());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure that tasks are no longer running
|
// Make sure that tasks are no longer running
|
||||||
|
|
|
@ -565,6 +565,10 @@ public class TransportTasksActionTests extends TaskManagerTestCase {
|
||||||
ListTasksResponse listResponse = testNodes[randomIntBetween(0, testNodes.length - 1)].transportListTasksAction.execute
|
ListTasksResponse listResponse = testNodes[randomIntBetween(0, testNodes.length - 1)].transportListTasksAction.execute
|
||||||
(listTasksRequest).get();
|
(listTasksRequest).get();
|
||||||
assertEquals(1, listResponse.getPerNodeTasks().size());
|
assertEquals(1, listResponse.getPerNodeTasks().size());
|
||||||
|
// Verify that tasks are marked as non-cancellable
|
||||||
|
for (TaskInfo taskInfo : listResponse.getTasks()) {
|
||||||
|
assertFalse(taskInfo.isCancellable());
|
||||||
|
}
|
||||||
|
|
||||||
// Release all tasks and wait for response
|
// Release all tasks and wait for response
|
||||||
checkLatch.countDown();
|
checkLatch.countDown();
|
||||||
|
|
|
@ -40,6 +40,7 @@ The result will look similar to the following:
|
||||||
"action" : "cluster:monitor/tasks/lists[n]",
|
"action" : "cluster:monitor/tasks/lists[n]",
|
||||||
"start_time_in_millis" : 1458585884904,
|
"start_time_in_millis" : 1458585884904,
|
||||||
"running_time_in_nanos" : 47402,
|
"running_time_in_nanos" : 47402,
|
||||||
|
"cancellable" : false,
|
||||||
"parent_task_id" : "oTUltX4IQMOUUVeiohTt8A:123"
|
"parent_task_id" : "oTUltX4IQMOUUVeiohTt8A:123"
|
||||||
},
|
},
|
||||||
"oTUltX4IQMOUUVeiohTt8A:123" : {
|
"oTUltX4IQMOUUVeiohTt8A:123" : {
|
||||||
|
@ -48,7 +49,8 @@ The result will look similar to the following:
|
||||||
"type" : "transport",
|
"type" : "transport",
|
||||||
"action" : "cluster:monitor/tasks/lists",
|
"action" : "cluster:monitor/tasks/lists",
|
||||||
"start_time_in_millis" : 1458585884904,
|
"start_time_in_millis" : 1458585884904,
|
||||||
"running_time_in_nanos" : 236042
|
"running_time_in_nanos" : 236042,
|
||||||
|
"cancellable" : false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue