Search in sources :

Example 6 with ListTasksResponse

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

the class RetryTests method taskStatus.

/**
     * Fetch the status for a task of type "action". Fails if there aren't exactly one of that type of task running.
     */
private BulkByScrollTask.Status taskStatus(String action) {
    ListTasksResponse response = client().admin().cluster().prepareListTasks().setActions(action).setDetailed(true).get();
    assertThat(response.getTasks(), hasSize(1));
    return (BulkByScrollTask.Status) response.getTasks().get(0).getStatus();
}
Also used : ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse)

Example 7 with ListTasksResponse

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

the class CancellableTasksTests method testTaskCancellationOnCoordinatingNodeLeavingTheCluster.

public void testTaskCancellationOnCoordinatingNodeLeavingTheCluster() throws Exception {
    setupTestNodes(Settings.EMPTY);
    connectNodes(testNodes);
    CountDownLatch responseLatch = new CountDownLatch(1);
    boolean simulateBanBeforeLeaving = randomBoolean();
    final AtomicReference<NodesResponse> responseReference = new AtomicReference<>();
    final AtomicReference<Throwable> throwableReference = new AtomicReference<>();
    int blockedNodesCount = randomIntBetween(0, nodesCount - 1);
    // We shouldn't block on the first node since it's leaving the cluster anyway so it doesn't matter
    List<TestNode> blockOnNodes = randomSubsetOf(blockedNodesCount, Arrays.copyOfRange(testNodes, 1, nodesCount));
    Task mainTask = startCancellableTestNodesAction(true, blockOnNodes, new CancellableNodesRequest("Test Request"), 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();
        }
    });
    String mainNode = testNodes[0].getNodeId();
    // Make sure that tasks are running
    ListTasksResponse listTasksResponse = testNodes[randomIntBetween(0, testNodes.length - 1)].transportListTasksAction.execute(new ListTasksRequest().setParentTaskId(new TaskId(mainNode, mainTask.getId()))).get();
    assertThat(listTasksResponse.getTasks().size(), greaterThanOrEqualTo(blockOnNodes.size()));
    // Simulate the coordinating node leaving the cluster
    DiscoveryNode[] discoveryNodes = new DiscoveryNode[testNodes.length - 1];
    for (int i = 1; i < testNodes.length; i++) {
        discoveryNodes[i - 1] = testNodes[i].discoveryNode();
    }
    DiscoveryNode master = discoveryNodes[0];
    for (int i = 1; i < testNodes.length; i++) {
        // Notify only nodes that should remain in the cluster
        setState(testNodes[i].clusterService, ClusterStateCreationUtils.state(testNodes[i].discoveryNode(), master, discoveryNodes));
    }
    if (simulateBanBeforeLeaving) {
        logger.info("--> Simulate issuing cancel request on the node that is about to leave the cluster");
        // Simulate issuing cancel request on the node that is about to leave the cluster
        CancelTasksRequest request = new CancelTasksRequest();
        request.setReason("Testing Cancellation");
        request.setTaskId(new TaskId(testNodes[0].getNodeId(), mainTask.getId()));
        // And send the cancellation request to a random node
        CancelTasksResponse response = testNodes[0].transportCancelTasksAction.execute(request).get();
        logger.info("--> Done simulating issuing cancel request on the node that is about to leave the cluster");
        // This node still thinks that's part of the cluster, so cancelling should look successful
        if (response.getTasks().size() == 0) {
            logger.error("!!!!");
        }
        assertThat(response.getTasks().size(), lessThanOrEqualTo(1));
        assertThat(response.getTaskFailures().size(), lessThanOrEqualTo(1));
        assertThat(response.getTaskFailures().size() + response.getTasks().size(), lessThanOrEqualTo(1));
    }
    for (int i = 1; i < testNodes.length; i++) {
        assertEquals("No bans on the node " + i, 0, testNodes[i].transportService.getTaskManager().getBanCount());
    }
    // Close the first node
    testNodes[0].close();
    assertBusy(() -> {
        // Make sure that tasks are no longer running
        try {
            ListTasksResponse listTasksResponse1 = testNodes[randomIntBetween(1, testNodes.length - 1)].transportListTasksAction.execute(new ListTasksRequest().setTaskId(new TaskId(mainNode, mainTask.getId()))).get();
            assertEquals(0, listTasksResponse1.getTasks().size());
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        } catch (ExecutionException ex2) {
            fail("shouldn't be here");
        }
    });
    // Wait for clean up
    responseLatch.await();
}
Also used : CancellableTask(org.elasticsearch.tasks.CancellableTask) Task(org.elasticsearch.tasks.Task) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) 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) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse) ExecutionException(java.util.concurrent.ExecutionException) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TaskCancelledException(org.elasticsearch.tasks.TaskCancelledException) ListTasksRequest(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest)

Example 8 with ListTasksResponse

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

the class TasksIT method testListTasksWaitForTimeout.

public void testListTasksWaitForTimeout() throws Exception {
    waitForTimeoutTestCase(id -> {
        ListTasksResponse response = client().admin().cluster().prepareListTasks().setActions(TestTaskPlugin.TestTaskAction.NAME).setWaitForCompletion(true).setTimeout(timeValueMillis(100)).get();
        assertThat(response.getNodeFailures(), not(empty()));
        return response.getNodeFailures();
    });
}
Also used : ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse)

Example 9 with ListTasksResponse

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

the class TransportTasksActionTests method testTasksDescriptions.

public void testTasksDescriptions() throws Exception {
    long minimalStartTime = System.currentTimeMillis();
    setupTestNodes(Settings.EMPTY);
    connectNodes(testNodes);
    CountDownLatch checkLatch = new CountDownLatch(1);
    ActionFuture<NodesResponse> future = startBlockingTestNodesAction(checkLatch);
    long maximumStartTimeNanos = System.nanoTime();
    // Check task counts using transport with filtering
    TestNode testNode = testNodes[randomIntBetween(0, testNodes.length - 1)];
    ListTasksRequest listTasksRequest = new ListTasksRequest();
    // only pick node actions
    listTasksRequest.setActions("testAction[n]");
    ListTasksResponse response = testNode.transportListTasksAction.execute(listTasksRequest).get();
    assertEquals(testNodes.length, response.getPerNodeTasks().size());
    for (Map.Entry<String, List<TaskInfo>> entry : response.getPerNodeTasks().entrySet()) {
        assertEquals(1, entry.getValue().size());
        assertNull(entry.getValue().get(0).getDescription());
    }
    // Check task counts using transport with detailed description
    long minimalDurationNanos = System.nanoTime() - maximumStartTimeNanos;
    // same request only with detailed description
    listTasksRequest.setDetailed(true);
    response = testNode.transportListTasksAction.execute(listTasksRequest).get();
    assertEquals(testNodes.length, response.getPerNodeTasks().size());
    for (Map.Entry<String, List<TaskInfo>> entry : response.getPerNodeTasks().entrySet()) {
        assertEquals(1, entry.getValue().size());
        assertEquals("CancellableNodeRequest[Test Request, true]", entry.getValue().get(0).getDescription());
        assertThat(entry.getValue().get(0).getStartTime(), greaterThanOrEqualTo(minimalStartTime));
        assertThat(entry.getValue().get(0).getRunningTimeNanos(), greaterThanOrEqualTo(minimalDurationNanos));
    }
    // Release all tasks and wait for response
    checkLatch.countDown();
    NodesResponse responses = future.get();
    assertEquals(0, responses.failureCount());
}
Also used : ListTasksRequest(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest) List(java.util.List) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse) Map(java.util.Map)

Example 10 with ListTasksResponse

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

the class TransportTasksActionTests method testTasksToXContentGrouping.

@SuppressWarnings("unchecked")
public void testTasksToXContentGrouping() throws Exception {
    setupTestNodes(Settings.EMPTY);
    connectNodes(testNodes);
    // Get the parent task
    ListTasksRequest listTasksRequest = new ListTasksRequest();
    listTasksRequest.setActions(ListTasksAction.NAME + "*");
    ListTasksResponse response = testNodes[0].transportListTasksAction.execute(listTasksRequest).get();
    assertEquals(testNodes.length + 1, response.getTasks().size());
    Map<String, Object> byNodes = serialize(response, true);
    byNodes = (Map<String, Object>) byNodes.get("nodes");
    // One element on the top level
    assertEquals(testNodes.length, byNodes.size());
    Map<String, Object> firstNode = (Map<String, Object>) byNodes.get(testNodes[0].getNodeId());
    firstNode = (Map<String, Object>) firstNode.get("tasks");
    // two tasks for the first node
    assertEquals(2, firstNode.size());
    for (int i = 1; i < testNodes.length; i++) {
        Map<String, Object> otherNode = (Map<String, Object>) byNodes.get(testNodes[i].getNodeId());
        otherNode = (Map<String, Object>) otherNode.get("tasks");
        // one tasks for the all other nodes
        assertEquals(1, otherNode.size());
    }
    // Group by parents
    Map<String, Object> byParent = serialize(response, false);
    byParent = (Map<String, Object>) byParent.get("tasks");
    // One element on the top level
    // Only one top level task
    assertEquals(1, byParent.size());
    Map<String, Object> topTask = (Map<String, Object>) byParent.values().iterator().next();
    List<Object> children = (List<Object>) topTask.get("children");
    // two tasks for the first node
    assertEquals(testNodes.length, children.size());
    for (int i = 0; i < testNodes.length; i++) {
        Map<String, Object> child = (Map<String, Object>) children.get(i);
        assertNull(child.get("children"));
    }
}
Also used : ListTasksRequest(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest) List(java.util.List) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse) Map(java.util.Map)

Aggregations

ListTasksResponse (org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse)25 TaskInfo (org.elasticsearch.tasks.TaskInfo)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 ListTasksRequest (org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest)9 TaskId (org.elasticsearch.tasks.TaskId)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 ExecutionException (java.util.concurrent.ExecutionException)6 Task (org.elasticsearch.tasks.Task)6 List (java.util.List)5 CancelTasksResponse (org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse)5 Map (java.util.Map)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 FailedNodeException (org.elasticsearch.action.FailedNodeException)4 CancelTasksRequest (org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest)4 BulkByScrollTask (org.elasticsearch.action.bulk.byscroll.BulkByScrollTask)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 TaskGroup (org.elasticsearch.action.admin.cluster.node.tasks.list.TaskGroup)3 BulkByScrollResponse (org.elasticsearch.action.bulk.byscroll.BulkByScrollResponse)3 CancellableTask (org.elasticsearch.tasks.CancellableTask)3