-
Notifications
You must be signed in to change notification settings - Fork 25k
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
high level REST api: cancel task #30745
Changes from all commits
c7e221f
1df3544
332f4dd
9495732
9869569
5654c21
2c709ed
3ed1829
62b161a
314e1ff
58e9539
c51eb3c
9e748ee
a511490
96e3fa2
4260549
f646fa4
31f08ef
0c05fe7
783d00a
4e34cfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,4 +178,5 @@ public void onFailure(Exception e) { | |
assertTrue(latch.await(30L, TimeUnit.SECONDS)); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
[[java-rest-high-cluster-cancel-tasks]] | ||
=== Cancel Tasks API | ||
|
||
The Cancel Tasks API allows cancellation of a currently running task. | ||
|
||
==== Cancel Tasks Request | ||
|
||
A `CancelTasksRequest`: | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[cancel-tasks-request] | ||
-------------------------------------------------- | ||
There are no required parameters. The task cancellation command supports the same | ||
task selection parameters as the list tasks command. | ||
|
||
==== Parameters | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-request-filter] | ||
-------------------------------------------------- | ||
<1> Cancel a task | ||
<2> Cancel only cluster-related tasks | ||
<3> Cancel all tasks running on nodes nodeId1 and nodeId2 | ||
|
||
==== Synchronous Execution | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-execute] | ||
-------------------------------------------------- | ||
|
||
==== Asynchronous Execution | ||
|
||
The asynchronous execution requires `CancelTasksRequest` instance and an | ||
`ActionListener` instance to be passed to the asynchronous method: | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[cancel-tasks-execute-async] | ||
-------------------------------------------------- | ||
<1> The `CancelTasksRequest` to execute and the `ActionListener` to use | ||
when the execution completes | ||
|
||
The asynchronous method does not block and returns immediately. Once it is | ||
completed the `ActionListener` is called back using the `onResponse` method | ||
if the execution successfully completed or using the `onFailure` method if | ||
it failed. | ||
|
||
A typical listener for `CancelTasksResponse` looks like: | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[cancel-tasks-execute-listener] | ||
-------------------------------------------------- | ||
<1> Called when the execution is successfully completed. The response is | ||
provided as an argument | ||
<2> Called in case of a failure. The raised exception is provided as an argument | ||
|
||
==== Cancel Tasks Response | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-response-tasks] | ||
-------------------------------------------------- | ||
<1> List of cancelled tasks | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-response-calc] | ||
-------------------------------------------------- | ||
<1> List of cancelled tasks grouped by a node | ||
<2> List of cancelled tasks grouped by a parent task | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-response-failures] | ||
-------------------------------------------------- | ||
<1> List of node failures | ||
<2> List of task cancellation failures | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,23 +19,48 @@ | |
|
||
package org.elasticsearch.action.admin.cluster.node.tasks.cancel; | ||
|
||
import org.elasticsearch.action.FailedNodeException; | ||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.action.TaskOperationFailure; | ||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.tasks.TaskInfo; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg; | ||
|
||
/** | ||
* Returns the list of tasks that were cancelled | ||
*/ | ||
public class CancelTasksResponse extends ListTasksResponse { | ||
|
||
private static final ConstructingObjectParser<CancelTasksResponse, Void> PARSER = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think you can make something like:
in ListTasksResponse? That way you wouldn't need to copy this stuff. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great idea! will do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nik9000 I went to do this and ran into a problem: because otherwise, unless I'm missing something, couldn't call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd supply a lambda, yeah. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nik9000 nice suggestion, this is implemented now |
||
setupParser("cancel_tasks_response", CancelTasksResponse::new); | ||
|
||
public CancelTasksResponse() { | ||
} | ||
|
||
public CancelTasksResponse(List<TaskInfo> tasks, List<TaskOperationFailure> taskFailures, List<? extends FailedNodeException> | ||
public CancelTasksResponse(List<TaskInfo> tasks, List<TaskOperationFailure> taskFailures, List<? extends ElasticsearchException> | ||
nodeFailures) { | ||
super(tasks, taskFailures, nodeFailures); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return super.toXContent(builder, params); | ||
} | ||
|
||
public static CancelTasksResponse fromXContent(XContentParser parser) { | ||
return PARSER.apply(parser, null); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Strings.toString(this, true, true); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove empty line?