use of org.opensearch.client.tasks.CancelTasksResponse in project OpenSearch by opensearch-project.
the class TasksIT method testCancelTasks.
public void testCancelTasks() throws IOException {
ListTasksRequest listRequest = new ListTasksRequest();
ListTasksResponse listResponse = execute(listRequest, highLevelClient().tasks()::list, highLevelClient().tasks()::listAsync);
// in this case, probably no task will actually be cancelled.
// this is ok, that case is covered in TasksIT.testTasksCancellation
org.opensearch.tasks.TaskInfo firstTask = listResponse.getTasks().get(0);
String node = listResponse.getPerNodeTasks().keySet().iterator().next();
CancelTasksRequest cancelTasksRequest = new CancelTasksRequest.Builder().withTaskId(new TaskId(node, firstTask.getId())).build();
CancelTasksResponse response = execute(cancelTasksRequest, highLevelClient().tasks()::cancel, highLevelClient().tasks()::cancelAsync);
// Since the task may or may not have been cancelled, assert that we received a response only
// The actual testing of task cancellation is covered by TasksIT.testTasksCancellation
assertThat(response, notNullValue());
}
use of org.opensearch.client.tasks.CancelTasksResponse in project OpenSearch by opensearch-project.
the class TasksClientDocumentationIT method testCancelTasks.
@SuppressWarnings("unused")
public void testCancelTasks() throws IOException {
RestHighLevelClient client = highLevelClient();
{
// tag::cancel-tasks-request
CancelTasksRequest request = new org.opensearch.client.tasks.CancelTasksRequest.Builder().withNodesFiltered(Arrays.asList("nodeId1", "nodeId2")).withActionsFiltered(Collections.singletonList("cluster:*")).build();
// end::cancel-tasks-request
// tag::cancel-tasks-request-filter
CancelTasksRequest byTaskIdRequest = // <1>
new org.opensearch.client.tasks.CancelTasksRequest.Builder().withTaskId(// <2>
new org.opensearch.client.tasks.TaskId("myNode", 44L)).withWaitForCompletion(// <3>
true).build();
// end::cancel-tasks-request-filter
}
CancelTasksRequest request = new org.opensearch.client.tasks.CancelTasksRequest.Builder().build();
// tag::cancel-tasks-execute
CancelTasksResponse response = client.tasks().cancel(request, RequestOptions.DEFAULT);
// end::cancel-tasks-execute
assertThat(response, notNullValue());
// tag::cancel-tasks-response-tasks
// <1>
List<org.opensearch.client.tasks.TaskInfo> tasks = response.getTasks();
// end::cancel-tasks-response-tasks
// tag::cancel-tasks-response-calc
// <1>
Map<String, List<org.opensearch.client.tasks.TaskInfo>> perNodeTasks = response.getPerNodeTasks();
// <2>
List<org.opensearch.client.tasks.TaskGroup> groups = response.getTaskGroups();
// end::cancel-tasks-response-calc
// tag::cancel-tasks-response-failures
// <1>
List<org.opensearch.client.tasks.OpenSearchException> nodeFailures = response.getNodeFailures();
// <2>
List<org.opensearch.client.tasks.TaskOperationFailure> taskFailures = response.getTaskFailures();
// end::cancel-tasks-response-failures
assertThat(response.getNodeFailures(), equalTo(emptyList()));
assertThat(response.getTaskFailures(), equalTo(emptyList()));
}
Aggregations