Search in sources :

Example 6 with ListTasksRequest

use of org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest in project elasticsearch by elastic.

the class RestListTasksAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final ListTasksRequest listTasksRequest = generateListTasksRequest(request);
    final String groupBy = request.param("group_by", "nodes");
    return channel -> client.admin().cluster().listTasks(listTasksRequest, listTasksResponseListener(nodesInCluster, groupBy, channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) TaskId(org.elasticsearch.tasks.TaskId) Supplier(java.util.function.Supplier) Strings(org.elasticsearch.common.Strings) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) ListTasksRequest(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest) RestChannel(org.elasticsearch.rest.RestChannel) Settings(org.elasticsearch.common.settings.Settings) TimeValue(org.elasticsearch.common.unit.TimeValue) RestStatus(org.elasticsearch.rest.RestStatus) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) ActionListener(org.elasticsearch.action.ActionListener) ListTasksRequest(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest)

Example 7 with ListTasksRequest

use of org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest in project elasticsearch by elastic.

the class RestListTasksAction method generateListTasksRequest.

public static ListTasksRequest generateListTasksRequest(RestRequest request) {
    boolean detailed = request.paramAsBoolean("detailed", false);
    String[] nodes = Strings.splitStringByCommaToArray(request.param("nodes"));
    String[] actions = Strings.splitStringByCommaToArray(request.param("actions"));
    TaskId parentTaskId = new TaskId(request.param("parent_task_id"));
    boolean waitForCompletion = request.paramAsBoolean("wait_for_completion", false);
    TimeValue timeout = request.paramAsTime("timeout", null);
    ListTasksRequest listTasksRequest = new ListTasksRequest();
    listTasksRequest.setNodes(nodes);
    listTasksRequest.setDetailed(detailed);
    listTasksRequest.setActions(actions);
    listTasksRequest.setParentTaskId(parentTaskId);
    listTasksRequest.setWaitForCompletion(waitForCompletion);
    listTasksRequest.setTimeout(timeout);
    return listTasksRequest;
}
Also used : TaskId(org.elasticsearch.tasks.TaskId) ListTasksRequest(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 8 with ListTasksRequest

use of org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest in project elasticsearch by elastic.

the class TransportTasksActionTests method testFindChildTasks.

public void testFindChildTasks() throws Exception {
    setupTestNodes(Settings.EMPTY);
    connectNodes(testNodes);
    CountDownLatch checkLatch = new CountDownLatch(1);
    ActionFuture<NodesResponse> future = startBlockingTestNodesAction(checkLatch);
    TestNode testNode = testNodes[randomIntBetween(0, testNodes.length - 1)];
    // Get the parent task
    ListTasksRequest listTasksRequest = new ListTasksRequest();
    listTasksRequest.setActions("testAction");
    ListTasksResponse response = testNode.transportListTasksAction.execute(listTasksRequest).get();
    assertEquals(1, response.getTasks().size());
    String parentNode = response.getTasks().get(0).getTaskId().getNodeId();
    long parentTaskId = response.getTasks().get(0).getId();
    // Find tasks with common parent
    listTasksRequest = new ListTasksRequest();
    listTasksRequest.setParentTaskId(new TaskId(parentNode, parentTaskId));
    response = testNode.transportListTasksAction.execute(listTasksRequest).get();
    assertEquals(testNodes.length, response.getTasks().size());
    for (TaskInfo task : response.getTasks()) {
        assertEquals("testAction[n]", task.getAction());
        assertEquals(parentNode, task.getParentTaskId().getNodeId());
        assertEquals(parentTaskId, task.getParentTaskId().getId());
    }
    // Release all tasks and wait for response
    checkLatch.countDown();
    NodesResponse responses = future.get();
    assertEquals(0, responses.failureCount());
}
Also used : TaskInfo(org.elasticsearch.tasks.TaskInfo) TaskId(org.elasticsearch.tasks.TaskId) ListTasksRequest(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse)

Example 9 with ListTasksRequest

use of org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest in project elasticsearch by elastic.

the class TransportTasksActionTests method testTaskManagementOptOut.

public void testTaskManagementOptOut() throws Exception {
    setupTestNodes(Settings.EMPTY);
    connectNodes(testNodes);
    CountDownLatch checkLatch = new CountDownLatch(1);
    // Starting actions that disable task manager
    ActionFuture<NodesResponse> future = startBlockingTestNodesAction(checkLatch, new NodesRequest("Test Request", false));
    TestNode testNode = testNodes[randomIntBetween(0, testNodes.length - 1)];
    // Get the parent task
    ListTasksRequest listTasksRequest = new ListTasksRequest();
    listTasksRequest.setActions("testAction*");
    ListTasksResponse response = testNode.transportListTasksAction.execute(listTasksRequest).get();
    assertEquals(0, response.getTasks().size());
    // Release all tasks and wait for response
    checkLatch.countDown();
    NodesResponse responses = future.get();
    assertEquals(0, responses.failureCount());
}
Also used : BaseNodesRequest(org.elasticsearch.action.support.nodes.BaseNodesRequest) ListTasksRequest(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest) CountDownLatch(java.util.concurrent.CountDownLatch) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse)

Example 10 with ListTasksRequest

use of org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest in project elasticsearch by elastic.

the class CancellableTasksTests method testChildTasksCancellation.

public void testChildTasksCancellation() throws Exception {
    setupTestNodes(Settings.EMPTY);
    connectNodes(testNodes);
    CountDownLatch responseLatch = new CountDownLatch(1);
    final AtomicReference<NodesResponse> responseReference = new AtomicReference<>();
    final AtomicReference<Throwable> throwableReference = new AtomicReference<>();
    Task mainTask = startCancellableTestNodesAction(true, nodesCount, new ActionListener<NodesResponse>() {

        @Override
        public void onResponse(NodesResponse listTasksResponse) {
            responseReference.set(listTasksResponse);
            responseLatch.countDown();
        }

        @Override
        public void onFailure(Exception e) {
            throwableReference.set(e);
            responseLatch.countDown();
        }
    });
    // Cancel all child tasks without cancelling the main task, which should quit on its own
    CancelTasksRequest request = new CancelTasksRequest();
    request.setReason("Testing Cancellation");
    request.setParentTaskId(new TaskId(testNodes[0].getNodeId(), mainTask.getId()));
    // And send the cancellation request to a random node
    CancelTasksResponse response = testNodes[randomIntBetween(1, testNodes.length - 1)].transportCancelTasksAction.execute(request).get();
    // Awaiting for the main task to finish
    responseLatch.await();
    // Should have cancelled tasks on all nodes
    assertThat(response.getTasks().size(), equalTo(testNodes.length));
    assertBusy(() -> {
        try {
            // Make sure that main task is no longer running
            ListTasksResponse listTasksResponse = testNodes[randomIntBetween(0, testNodes.length - 1)].transportListTasksAction.execute(new ListTasksRequest().setTaskId(new TaskId(testNodes[0].getNodeId(), mainTask.getId()))).get();
            assertEquals(0, listTasksResponse.getTasks().size());
        } catch (ExecutionException | InterruptedException ex) {
            throw new RuntimeException(ex);
        }
    });
}
Also used : CancellableTask(org.elasticsearch.tasks.CancellableTask) Task(org.elasticsearch.tasks.Task) TaskId(org.elasticsearch.tasks.TaskId) CancelTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse) CancelTasksRequest(org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TaskCancelledException(org.elasticsearch.tasks.TaskCancelledException) ListTasksRequest(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ListTasksRequest (org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest)11 ListTasksResponse (org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 TaskId (org.elasticsearch.tasks.TaskId)7 IOException (java.io.IOException)6 ExecutionException (java.util.concurrent.ExecutionException)5 Task (org.elasticsearch.tasks.Task)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 CancelTasksRequest (org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest)4 CancelTasksResponse (org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 CancellableTask (org.elasticsearch.tasks.CancellableTask)3 TaskCancelledException (org.elasticsearch.tasks.TaskCancelledException)3 TaskInfo (org.elasticsearch.tasks.TaskInfo)3 FailedNodeException (org.elasticsearch.action.FailedNodeException)2 TimeValue (org.elasticsearch.common.unit.TimeValue)2 Supplier (java.util.function.Supplier)1