Search in sources :

Example 1 with PendingClusterTasksResponse

use of org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse in project elasticsearch by elastic.

the class RestPendingClusterTasksAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    PendingClusterTasksRequest pendingClusterTasksRequest = new PendingClusterTasksRequest();
    pendingClusterTasksRequest.masterNodeTimeout(request.paramAsTime("master_timeout", pendingClusterTasksRequest.masterNodeTimeout()));
    pendingClusterTasksRequest.local(request.paramAsBoolean("local", pendingClusterTasksRequest.local()));
    return channel -> client.admin().cluster().pendingClusterTasks(pendingClusterTasksRequest, new RestResponseListener<PendingClusterTasksResponse>(channel) {

        @Override
        public RestResponse buildResponse(PendingClusterTasksResponse pendingClusterTasks) throws Exception {
            Table tab = buildTable(request, pendingClusterTasks);
            return RestTable.buildResponse(tab, channel);
        }
    });
}
Also used : PendingClusterTasksRequest(org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest) Settings(org.elasticsearch.common.settings.Settings) GET(org.elasticsearch.rest.RestRequest.Method.GET) PendingClusterTasksResponse(org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse) RestResponse(org.elasticsearch.rest.RestResponse) PendingClusterTask(org.elasticsearch.cluster.service.PendingClusterTask) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) Table(org.elasticsearch.common.Table) PendingClusterTasksResponse(org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse) RestResponse(org.elasticsearch.rest.RestResponse) PendingClusterTasksRequest(org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest)

Example 2 with PendingClusterTasksResponse

use of org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse in project elasticsearch by elastic.

the class ClusterServiceIT method testPendingUpdateTask.

@TestLogging("_root:debug,org.elasticsearch.action.admin.cluster.tasks:trace")
public void testPendingUpdateTask() throws Exception {
    String node_0 = internalCluster().startNode();
    internalCluster().startCoordinatingOnlyNode(Settings.EMPTY);
    final ClusterService clusterService = internalCluster().getInstance(ClusterService.class, node_0);
    final CountDownLatch block1 = new CountDownLatch(1);
    final CountDownLatch invoked1 = new CountDownLatch(1);
    clusterService.submitStateUpdateTask("1", new ClusterStateUpdateTask() {

        @Override
        public ClusterState execute(ClusterState currentState) {
            invoked1.countDown();
            try {
                block1.await();
            } catch (InterruptedException e) {
                fail();
            }
            return currentState;
        }

        @Override
        public void onFailure(String source, Exception e) {
            invoked1.countDown();
            fail();
        }
    });
    invoked1.await();
    final CountDownLatch invoked2 = new CountDownLatch(9);
    for (int i = 2; i <= 10; i++) {
        clusterService.submitStateUpdateTask(Integer.toString(i), new ClusterStateUpdateTask() {

            @Override
            public ClusterState execute(ClusterState currentState) {
                return currentState;
            }

            @Override
            public void onFailure(String source, Exception e) {
                fail();
            }

            @Override
            public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
                invoked2.countDown();
            }
        });
    }
    // there might be other tasks in this node, make sure to only take the ones we add into account in this test
    // The tasks can be re-ordered, so we need to check out-of-order
    Set<String> controlSources = new HashSet<>(Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"));
    List<PendingClusterTask> pendingClusterTasks = clusterService.pendingTasks();
    assertThat(pendingClusterTasks.size(), greaterThanOrEqualTo(10));
    assertThat(pendingClusterTasks.get(0).getSource().string(), equalTo("1"));
    assertThat(pendingClusterTasks.get(0).isExecuting(), equalTo(true));
    for (PendingClusterTask task : pendingClusterTasks) {
        controlSources.remove(task.getSource().string());
    }
    assertTrue(controlSources.isEmpty());
    controlSources = new HashSet<>(Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"));
    PendingClusterTasksResponse response = internalCluster().coordOnlyNodeClient().admin().cluster().preparePendingClusterTasks().get();
    assertThat(response.pendingTasks().size(), greaterThanOrEqualTo(10));
    assertThat(response.pendingTasks().get(0).getSource().string(), equalTo("1"));
    assertThat(response.pendingTasks().get(0).isExecuting(), equalTo(true));
    for (PendingClusterTask task : response) {
        controlSources.remove(task.getSource().string());
    }
    assertTrue(controlSources.isEmpty());
    block1.countDown();
    invoked2.await();
    // whenever we test for no tasks, we need to awaitBusy since this is a live node
    assertTrue(awaitBusy(() -> clusterService.pendingTasks().isEmpty()));
    waitNoPendingTasksOnAll();
    final CountDownLatch block2 = new CountDownLatch(1);
    final CountDownLatch invoked3 = new CountDownLatch(1);
    clusterService.submitStateUpdateTask("1", new ClusterStateUpdateTask() {

        @Override
        public ClusterState execute(ClusterState currentState) {
            invoked3.countDown();
            try {
                block2.await();
            } catch (InterruptedException e) {
                fail();
            }
            return currentState;
        }

        @Override
        public void onFailure(String source, Exception e) {
            invoked3.countDown();
            fail();
        }
    });
    invoked3.await();
    for (int i = 2; i <= 5; i++) {
        clusterService.submitStateUpdateTask(Integer.toString(i), new ClusterStateUpdateTask() {

            @Override
            public ClusterState execute(ClusterState currentState) {
                return currentState;
            }

            @Override
            public void onFailure(String source, Exception e) {
                fail();
            }
        });
    }
    Thread.sleep(100);
    pendingClusterTasks = clusterService.pendingTasks();
    assertThat(pendingClusterTasks.size(), greaterThanOrEqualTo(5));
    controlSources = new HashSet<>(Arrays.asList("1", "2", "3", "4", "5"));
    for (PendingClusterTask task : pendingClusterTasks) {
        controlSources.remove(task.getSource().string());
    }
    assertTrue(controlSources.isEmpty());
    response = internalCluster().coordOnlyNodeClient().admin().cluster().preparePendingClusterTasks().get();
    assertThat(response.pendingTasks().size(), greaterThanOrEqualTo(5));
    controlSources = new HashSet<>(Arrays.asList("1", "2", "3", "4", "5"));
    for (PendingClusterTask task : response) {
        if (controlSources.remove(task.getSource().string())) {
            assertThat(task.getTimeInQueueInMillis(), greaterThan(0L));
        }
    }
    assertTrue(controlSources.isEmpty());
    block2.countDown();
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) AckedClusterStateUpdateTask(org.elasticsearch.cluster.AckedClusterStateUpdateTask) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) CountDownLatch(java.util.concurrent.CountDownLatch) PendingClusterTasksResponse(org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse) HashSet(java.util.HashSet) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging)

Example 3 with PendingClusterTasksResponse

use of org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse in project graylog2-server by Graylog2.

the class ElasticsearchProbe method elasticsearchStats.

public ElasticsearchStats elasticsearchStats() {
    final ClusterAdminClient adminClient = client.admin().cluster();
    final ClusterStatsResponse clusterStatsResponse = adminClient.clusterStats(new ClusterStatsRequest()).actionGet();
    final String clusterName = clusterStatsResponse.getClusterNameAsString();
    final ClusterStatsNodes clusterNodesStats = clusterStatsResponse.getNodesStats();
    final NodesStats nodesStats = NodesStats.create(clusterNodesStats.getCounts().getTotal(), clusterNodesStats.getCounts().getMasterOnly(), clusterNodesStats.getCounts().getDataOnly(), clusterNodesStats.getCounts().getMasterData(), clusterNodesStats.getCounts().getClient());
    final IndicesStats indicesStats = IndicesStats.create(clusterStatsResponse.getIndicesStats().getIndexCount(), clusterStatsResponse.getIndicesStats().getStore().sizeInBytes(), clusterStatsResponse.getIndicesStats().getFieldData().getMemorySizeInBytes());
    final PendingClusterTasksResponse pendingClusterTasksResponse = adminClient.pendingClusterTasks(new PendingClusterTasksRequest()).actionGet();
    final int pendingTasksSize = pendingClusterTasksResponse.pendingTasks().size();
    final List<Long> pendingTasksTimeInQueue = Lists.newArrayListWithCapacity(pendingTasksSize);
    for (PendingClusterTask pendingClusterTask : pendingClusterTasksResponse) {
        pendingTasksTimeInQueue.add(pendingClusterTask.getTimeInQueueInMillis());
    }
    final ClusterHealthResponse clusterHealthResponse = adminClient.health(new ClusterHealthRequest(indexSetRegistry.getIndexWildcards())).actionGet();
    final ClusterHealth clusterHealth = ClusterHealth.create(clusterHealthResponse.getNumberOfNodes(), clusterHealthResponse.getNumberOfDataNodes(), clusterHealthResponse.getActiveShards(), clusterHealthResponse.getRelocatingShards(), clusterHealthResponse.getActivePrimaryShards(), clusterHealthResponse.getInitializingShards(), clusterHealthResponse.getUnassignedShards(), clusterHealthResponse.isTimedOut(), pendingTasksSize, pendingTasksTimeInQueue);
    return ElasticsearchStats.create(clusterName, clusterHealthResponse.getStatus(), clusterHealth, nodesStats, indicesStats);
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) ClusterStatsNodes(org.elasticsearch.action.admin.cluster.stats.ClusterStatsNodes) PendingClusterTask(org.elasticsearch.cluster.service.PendingClusterTask) PendingClusterTasksResponse(org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse) ClusterStatsRequest(org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest) PendingClusterTasksRequest(org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest) ClusterStatsResponse(org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse)

Example 4 with PendingClusterTasksResponse

use of org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse in project elasticsearch by elastic.

the class ESIntegTestCase method waitNoPendingTasksOnAll.

/**
     * Waits until all nodes have no pending tasks.
     */
public void waitNoPendingTasksOnAll() throws Exception {
    assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).get());
    assertBusy(() -> {
        for (Client client : clients()) {
            ClusterHealthResponse clusterHealth = client.admin().cluster().prepareHealth().setLocal(true).get();
            assertThat("client " + client + " still has in flight fetch", clusterHealth.getNumberOfInFlightFetch(), equalTo(0));
            PendingClusterTasksResponse pendingTasks = client.admin().cluster().preparePendingClusterTasks().setLocal(true).get();
            assertThat("client " + client + " still has pending tasks " + pendingTasks, pendingTasks, Matchers.emptyIterable());
            clusterHealth = client.admin().cluster().prepareHealth().setLocal(true).get();
            assertThat("client " + client + " still has in flight fetch", clusterHealth.getNumberOfInFlightFetch(), equalTo(0));
        }
    });
    assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).get());
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) PendingClusterTasksResponse(org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse) AdminClient(org.elasticsearch.client.AdminClient) RandomizingClient(org.elasticsearch.test.client.RandomizingClient) Client(org.elasticsearch.client.Client) RestClient(org.elasticsearch.client.RestClient)

Aggregations

PendingClusterTasksResponse (org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse)4 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)2 PendingClusterTasksRequest (org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest)2 PendingClusterTask (org.elasticsearch.cluster.service.PendingClusterTask)2 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ClusterHealthRequest (org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)1 ClusterStatsNodes (org.elasticsearch.action.admin.cluster.stats.ClusterStatsNodes)1 ClusterStatsRequest (org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest)1 ClusterStatsResponse (org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse)1 AdminClient (org.elasticsearch.client.AdminClient)1 Client (org.elasticsearch.client.Client)1 ClusterAdminClient (org.elasticsearch.client.ClusterAdminClient)1 RestClient (org.elasticsearch.client.RestClient)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 AckedClusterStateUpdateTask (org.elasticsearch.cluster.AckedClusterStateUpdateTask)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 ClusterStateUpdateTask (org.elasticsearch.cluster.ClusterStateUpdateTask)1 Table (org.elasticsearch.common.Table)1 Settings (org.elasticsearch.common.settings.Settings)1