Package org.elasticsearch.cluster

Examples of org.elasticsearch.cluster.ClusterService


        // start one server
        logger.info("Starting sever1");
        startNode("server1", settings);

        ClusterService clusterService1 = ((InternalNode) node("server1")).injector().getInstance(ClusterService.class);

        logger.info("Creating index [test]");
        CreateIndexResponse createIndexResponse = client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
        assertThat(createIndexResponse.acknowledged(), equalTo(true));

        logger.info("Running Cluster Health");
        ClusterHealthResponse clusterHealth = client("server1").admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));

        // sleep till the cluster state gets published, since we check the master
        Thread.sleep(200);


        ClusterState clusterState1 = clusterService1.state();
        RoutingNode routingNodeEntry1 = clusterState1.readOnlyRoutingNodes().nodesToShards().get(clusterState1.nodes().localNodeId());
        assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), equalTo(11));

        clusterState1 = client("server1").admin().cluster().state(clusterStateRequest()).actionGet().state();
        routingNodeEntry1 = clusterState1.readOnlyRoutingNodes().nodesToShards().get(clusterState1.nodes().localNodeId());
        assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), equalTo(11));

        logger.info("Starting server2");
        // start another server
        startNode("server2", settings);
        ClusterService clusterService2 = ((InternalNode) node("server2")).injector().getInstance(ClusterService.class);

        logger.info("Running Cluster Health");
        clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("2")).actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));

        // sleep till the cluster state gets published, since we check the master
        Thread.sleep(200);

        clusterState1 = clusterService1.state();
        routingNodeEntry1 = clusterState1.readOnlyRoutingNodes().nodesToShards().get(clusterState1.nodes().localNodeId());
        assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), equalTo(11));

        ClusterState clusterState2 = clusterService2.state();
        RoutingNode routingNodeEntry2 = clusterState2.readOnlyRoutingNodes().nodesToShards().get(clusterState2.nodes().localNodeId());
        assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED), equalTo(11));

        logger.info("Starting server3");
        // start another server
        startNode("server3", settings);
        Thread.sleep(200);

        ClusterService clusterService3 = ((InternalNode) node("server3")).injector().getInstance(ClusterService.class);

        logger.info("Running Cluster Health");
        clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("3").waitForRelocatingShards(0)).actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
        assertThat(clusterHealth.relocatingShards(), equalTo(0));
        assertThat(clusterHealth.activeShards(), equalTo(22));
        assertThat(clusterHealth.activePrimaryShards(), equalTo(11));

        // sleep till the cluster state gets published, since we check the master
        Thread.sleep(200);

        clusterState1 = clusterService1.state();
        routingNodeEntry1 = clusterState1.readOnlyRoutingNodes().nodesToShards().get(clusterState1.nodes().localNodeId());
        assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), anyOf(equalTo(7), equalTo(8)));

        clusterState2 = clusterService2.state();
        routingNodeEntry2 = clusterState2.readOnlyRoutingNodes().nodesToShards().get(clusterState2.nodes().localNodeId());
        assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED), anyOf(equalTo(7), equalTo(8)));

        ClusterState clusterState3 = clusterService3.state();
        RoutingNode routingNodeEntry3 = clusterState3.readOnlyRoutingNodes().nodesToShards().get(clusterState3.nodes().localNodeId());
        assertThat(routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(7));

        assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED) + routingNodeEntry2.numberOfShardsWithState(STARTED) + routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(22));

        logger.info("Closing server1");
        // kill the first server
        closeNode("server1");
        // verify health
        logger.info("Running Cluster Health");
        clusterHealth = client("server2").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForRelocatingShards(0).waitForNodes("2")).actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
        assertThat(clusterHealth.relocatingShards(), equalTo(0));
        assertThat(clusterHealth.activeShards(), equalTo(22));
        assertThat(clusterHealth.activePrimaryShards(), equalTo(11));

        // sleep till the cluster state gets published, since we check the master
        Thread.sleep(200);

        clusterState2 = clusterService2.state();
        routingNodeEntry2 = clusterState2.readOnlyRoutingNodes().nodesToShards().get(clusterState2.nodes().localNodeId());
        assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED), equalTo(11));

        clusterState3 = clusterService3.state();
        routingNodeEntry3 = clusterState3.readOnlyRoutingNodes().nodesToShards().get(clusterState3.nodes().localNodeId());
        assertThat(routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(11));

        assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED) + routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(22));

        logger.info("Deleting index [test]");
        // last, lets delete the index
        DeleteIndexResponse deleteIndexResponse = client("server2").admin().indices().prepareDelete("test").execute().actionGet();
        assertThat(deleteIndexResponse.acknowledged(), equalTo(true));

        Thread.sleep(500); // wait till the cluster state gets published

        clusterState2 = clusterService2.state();
        routingNodeEntry2 = clusterState2.readOnlyRoutingNodes().nodesToShards().get(clusterState2.nodes().localNodeId());
        assertThat(routingNodeEntry2, nullValue());

        clusterState3 = clusterService3.state();
        routingNodeEntry3 = clusterState3.readOnlyRoutingNodes().nodesToShards().get(clusterState3.nodes().localNodeId());
        assertThat(routingNodeEntry3, nullValue());
    }
View Full Code Here


        // start one server
        logger.info("Starting server1");
        startNode("server1", settings);

        ClusterService clusterService1 = ((InternalNode) node("server1")).injector().getInstance(ClusterService.class);

        logger.info("Creating index [test]");
        CreateIndexResponse createIndexResponse = client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
        assertThat(createIndexResponse.acknowledged(), equalTo(true));

        logger.info("Running Cluster Health");
        ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
        assertThat(clusterHealth.relocatingShards(), equalTo(0));
        assertThat(clusterHealth.activeShards(), equalTo(11));
        assertThat(clusterHealth.activePrimaryShards(), equalTo(11));

        ClusterState clusterState1 = clusterService1.state();
        RoutingNode routingNodeEntry1 = clusterState1.readOnlyRoutingNodes().nodesToShards().get(clusterState1.nodes().localNodeId());
        assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), equalTo(11));

        // start another server
        logger.info("Starting server2");
        startNode("server2", settings);
        Thread.sleep(200);

        logger.info("Running Cluster Health");
        clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForRelocatingShards(0).waitForNodes("2")).actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
        assertThat(clusterHealth.relocatingShards(), equalTo(0));
        assertThat(clusterHealth.activeShards(), equalTo(11));
        assertThat(clusterHealth.activePrimaryShards(), equalTo(11));

        // sleep till the cluster state gets published, since we check the master
        Thread.sleep(200);

        ClusterService clusterService2 = ((InternalNode) node("server2")).injector().getInstance(ClusterService.class);

        clusterState1 = clusterService1.state();
        routingNodeEntry1 = clusterState1.readOnlyRoutingNodes().nodesToShards().get(clusterState1.nodes().localNodeId());
        assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), anyOf(equalTo(6), equalTo(5)));

        ClusterState clusterState2 = clusterService2.state();
        RoutingNode routingNodeEntry2 = clusterState2.readOnlyRoutingNodes().nodesToShards().get(clusterState2.nodes().localNodeId());
        assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED), anyOf(equalTo(5), equalTo(6)));

        // start another server
        logger.info("Starting server3");
        startNode("server3");
        Thread.sleep(200);

        ClusterService clusterService3 = ((InternalNode) node("server3")).injector().getInstance(ClusterService.class);

        logger.info("Running Cluster Health");
        clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForRelocatingShards(0).waitForNodes("3")).actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
        assertThat(clusterHealth.relocatingShards(), equalTo(0));
        assertThat(clusterHealth.activeShards(), equalTo(11));
        assertThat(clusterHealth.activePrimaryShards(), equalTo(11));

        // sleep till the cluster state gets published, since we check the master
        Thread.sleep(200);

        clusterState1 = clusterService1.state();
        routingNodeEntry1 = clusterState1.readOnlyRoutingNodes().nodesToShards().get(clusterState1.nodes().localNodeId());
        assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), anyOf(equalTo(5), equalTo(4), equalTo(3)));

        clusterState2 = clusterService2.state();
        routingNodeEntry2 = clusterState2.readOnlyRoutingNodes().nodesToShards().get(clusterState2.nodes().localNodeId());
        assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED), anyOf(equalTo(5), equalTo(4), equalTo(3)));

        ClusterState clusterState3 = clusterService3.state();
        RoutingNode routingNodeEntry3 = clusterState3.readOnlyRoutingNodes().nodesToShards().get(clusterState3.nodes().localNodeId());
        assertThat(routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(3));

        assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED) + routingNodeEntry2.numberOfShardsWithState(STARTED) + routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(11));

        logger.info("Closing server1");
        // kill the first server
        closeNode("server1");

        logger.info("Running Cluster Health");
        clusterHealth = client("server3").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("2").waitForRelocatingShards(0)).actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
        assertThat(clusterHealth.relocatingShards(), equalTo(0));
        assertThat(clusterHealth.activeShards(), equalTo(11));
        assertThat(clusterHealth.activePrimaryShards(), equalTo(11));

        // sleep till the cluster state gets published, since we check the master
        Thread.sleep(200);

        clusterState2 = clusterService2.state();
        routingNodeEntry2 = clusterState2.readOnlyRoutingNodes().nodesToShards().get(clusterState2.nodes().localNodeId());
        assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED), anyOf(equalTo(5), equalTo(6)));

        clusterState3 = clusterService3.state();
        routingNodeEntry3 = clusterState3.readOnlyRoutingNodes().nodesToShards().get(clusterState3.nodes().localNodeId());
        assertThat(routingNodeEntry3.numberOfShardsWithState(STARTED), anyOf(equalTo(5), equalTo(6)));

        assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED) + routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(11));

        logger.info("Deleting index [test]");
        // last, lets delete the index
        DeleteIndexResponse deleteIndexResponse = client("server2").admin().indices().delete(deleteIndexRequest("test")).actionGet();
        assertThat(deleteIndexResponse.acknowledged(), equalTo(true));

        Thread.sleep(500); // wait till the cluster state gets published

        clusterState2 = clusterService2.state();
        routingNodeEntry2 = clusterState2.readOnlyRoutingNodes().nodesToShards().get(clusterState2.nodes().localNodeId());
        assertThat(routingNodeEntry2, nullValue());

        clusterState3 = clusterService3.state();
        routingNodeEntry3 = clusterState3.readOnlyRoutingNodes().nodesToShards().get(clusterState3.nodes().localNodeId());
        assertThat(routingNodeEntry3, nullValue());
    }
View Full Code Here

    public void testQueryShardRequestHandling() throws Exception {
        // this test just verifies that the request handler is hooked up correctly.
        // once the queryShardAction is used somewhere this test can be deleted.

        TransportQueryShardAction queryShardAction = cluster().getInstance(TransportQueryShardAction.class);
        ClusterService clusterService = cluster().getInstance(ClusterService.class);

        final SettableFuture<Boolean> response = SettableFuture.create();

        DiscoveryNode[] discoveryNodes = clusterService.state().nodes().nodes().values().toArray(DiscoveryNode.class);
        queryShardAction.execute(
                discoveryNodes[1].id(),
                new QueryShardRequest("foo",
                        1,
                        ImmutableList.<Symbol>of(),
View Full Code Here

     */
    static class TestModule extends AbstractModule {

        @Override
        protected void configure() {
            ClusterService clusterService = mock(ClusterService.class);
            ClusterState state = mock(ClusterState.class);
            MetaData metaData = mock(MetaData.class);
            when(metaData.settings()).thenReturn(ImmutableSettings.EMPTY);
            when(metaData.persistentSettings()).thenReturn(ImmutableSettings.EMPTY);
            when(metaData.transientSettings()).thenReturn(ImmutableSettings.EMPTY);
            when(state.metaData()).thenReturn(metaData);
            when(clusterService.state()).thenReturn(state);
            bind(ClusterService.class).toInstance(clusterService);
            bind(Settings.class).toInstance(ImmutableSettings.EMPTY);
            OsService osService = mock(OsService.class);
            OsStats osStats = mock(OsStats.class);
            when(osService.stats()).thenReturn(osStats);
View Full Code Here

        assertThat(md.hasAutoGeneratedPrimaryKey(), is(true));
    }

    private DocIndexMetaData getDocIndexMetaDataFromStatement(String stmt) throws IOException {
        Statement statement = SqlParser.createStatement(stmt);
        ClusterService clusterService = mock(ClusterService.class);
        CreateTableStatementAnalyzer analyzer = new CreateTableStatementAnalyzer(
            new ReferenceInfos(
                ImmutableMap.<String, SchemaInfo>of("doc",
                    new DocSchemaInfo(clusterService,
                        mock(TransportPutIndexTemplateAction.class)))),
View Full Code Here

@CrateIntegrationTest.ClusterScope(scope = CrateIntegrationTest.Scope.GLOBAL)
public class DistributedMergeTaskTest extends SQLTransportIntegrationTest {

    @Test
    public void testDistributedMergeTask() throws Exception {
        ClusterService clusterService = cluster().getInstance(ClusterService.class);
        Functions functions = cluster().getInstance(Functions.class);
        AggregationFunction countAggregation =
                (AggregationFunction)functions.get(new FunctionIdent(CountAggregation.NAME, ImmutableList.<DataType>of()));

        TransportMergeNodeAction transportMergeNodeAction = cluster().getInstance(TransportMergeNodeAction.class);

        Set<String> nodes = new HashSet<>();
        for (DiscoveryNode discoveryNode : clusterService.state().nodes()) {
            nodes.add(discoveryNode.getId());
        }

        // select count(*), user ... group by user
        MergeNode mergeNode = new MergeNode("merge1", 2);
View Full Code Here

        }
    }

    @Test
    public void testThatAddAfterFailureBlocksDueToRetry() throws Exception {
        ClusterService clusterService = mock(ClusterService.class);
        OperationRouting operationRouting = mock(OperationRouting.class);

        mockShard(operationRouting, 1);
        mockShard(operationRouting, 2);
        mockShard(operationRouting, 3);
        when(clusterService.operationRouting()).thenReturn(operationRouting);
        final TransportShardBulkAction transportShardBulkAction = mock(TransportShardBulkAction.class);

        final BulkShardProcessor bulkShardProcessor = new BulkShardProcessor(
                clusterService,
                ImmutableSettings.EMPTY,
View Full Code Here

            discoveryService = mock(DiscoveryService.class);
            DiscoveryNode discoveryNode = mock(DiscoveryNode.class);
            when(discoveryNode.id()).thenReturn(TEST_NODE_ID);
            when(discoveryService.localNode()).thenReturn(discoveryNode);

            ClusterService clusterService = mock(ClusterService.class);
            when(clusterService.localNode()).thenReturn(discoveryNode);
            bind(ClusterService.class).toInstance(clusterService);

            IndicesService indicesService = mock(IndicesService.class);
            bind(IndicesService.class).toInstance(indicesService);
            bind(Settings.class).toInstance(ImmutableSettings.EMPTY);
View Full Code Here

public class MapSideDataCollectOperationTest {


    @Test
    public void testFileUriCollect() throws Exception {
        ClusterService clusterService = mock(ClusterService.class);
        DiscoveryNode discoveryNode = mock(DiscoveryNode.class);
        when(discoveryNode.id()).thenReturn("dummyNodeId");
        when(clusterService.localNode()).thenReturn(discoveryNode);
        DiscoveryService discoveryService = mock(DiscoveryService.class);
        when(discoveryService.localNode()).thenReturn(discoveryNode);
        IndicesService indicesService = mock(IndicesService.class);
        Functions functions = new Functions(
                ImmutableMap.<FunctionIdent, FunctionImplementation>of(),
View Full Code Here

    class TestModule extends MetaDataModule {

        @Override
        protected void configure() {
            ClusterService clusterService = mock(ClusterService.class);
            ClusterState clusterState = mock(ClusterState.class);
            DiscoveryNodes nodes = mock(DiscoveryNodes.class);
            DiscoveryNode node = mock(DiscoveryNode.class);
            when(clusterService.state()).thenReturn(clusterState);
            when(clusterState.nodes()).thenReturn(nodes);
            ImmutableOpenMap<String, DiscoveryNode> dataNodes =
                    ImmutableOpenMap.<String, DiscoveryNode>builder().fPut("foo", node).build();
            when(nodes.dataNodes()).thenReturn(dataNodes);
            FulltextAnalyzerResolver fulltextAnalyzerResolver = mock(FulltextAnalyzerResolver.class);
View Full Code Here

TOP

Related Classes of org.elasticsearch.cluster.ClusterService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.