Package org.elasticsearch.cluster

Examples of org.elasticsearch.cluster.ClusterState$Custom


                .build();

        startNode("node1", settings);
        startNode("node2", settings);

        ClusterState state = client("node1").admin().cluster().prepareState().execute().actionGet().state();
        assertThat(state.nodes().size(), equalTo(2));

        state = client("node2").admin().cluster().prepareState().execute().actionGet().state();
        assertThat(state.nodes().size(), equalTo(2));
    }
View Full Code Here


        logger.info("--> start first node");
        startNode("node1", settings);

        logger.info("--> should be blocked, no master...");
        ClusterState state = client("node1").admin().cluster().prepareState().setLocal(true).execute().actionGet().state();
        assertThat(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK), equalTo(true));

        logger.info("--> start second node, cluster should be formed");
        startNode("node2", settings);

        Thread.sleep(3000);

        state = client("node1").admin().cluster().prepareState().setLocal(true).execute().actionGet().state();
        assertThat(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK), equalTo(false));
        state = client("node2").admin().cluster().prepareState().setLocal(true).execute().actionGet().state();
        assertThat(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK), equalTo(false));

        state = client("node1").admin().cluster().prepareState().execute().actionGet().state();
        assertThat(state.nodes().size(), equalTo(2));
        assertThat(state.metaData().indices().containsKey("test"), equalTo(false));

        client("node1").admin().indices().prepareCreate("test").execute().actionGet();
        logger.info("--> indexing some data");
        for (int i = 0; i < 100; i++) {
            client("node1").prepareIndex("test", "type1", Integer.toString(i)).setSource("field", "value").execute().actionGet();
        }
        // flush for simpler debugging
        client("node1").admin().indices().prepareFlush().execute().actionGet();

        client("node1").admin().indices().prepareRefresh().execute().actionGet();
        logger.info("--> verify we the data back");
        for (int i = 0; i < 10; i++) {
            assertThat(client("node1").prepareCount().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(100l));
        }

        String masterNodeName = state.nodes().masterNode().name();
        String nonMasterNodeName = masterNodeName.equals("node1") ? "node2" : "node1";
        logger.info("--> closing master node {}", masterNodeName);
        closeNode(masterNodeName);

        Thread.sleep(200);

        state = client(nonMasterNodeName).admin().cluster().prepareState().setLocal(true).execute().actionGet().state();
        assertThat(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK), equalTo(true));

        logger.info("--> starting the previous master node again...");
        startNode(masterNodeName, settings);

        Thread.sleep(3000);

        state = client("node1").admin().cluster().prepareState().setLocal(true).execute().actionGet().state();
        assertThat(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK), equalTo(false));
        state = client("node2").admin().cluster().prepareState().setLocal(true).execute().actionGet().state();
        assertThat(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK), equalTo(false));

        state = client("node1").admin().cluster().prepareState().execute().actionGet().state();
        assertThat(state.nodes().size(), equalTo(2));
        assertThat(state.metaData().indices().containsKey("test"), equalTo(true));

        logger.info("Running Cluster Health");
        ClusterHealthResponse clusterHealth = client("node1").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));

        logger.info("--> verify we the data back");
        for (int i = 0; i < 10; i++) {
            assertThat(client("node1").prepareCount().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(100l));
        }

        masterNodeName = state.nodes().masterNode().name();
        nonMasterNodeName = masterNodeName.equals("node1") ? "node2" : "node1";
        logger.info("--> closing non master node {}", nonMasterNodeName);
        closeNode(nonMasterNodeName);

        Thread.sleep(200);

        state = client(masterNodeName).admin().cluster().prepareState().setLocal(true).execute().actionGet().state();
        assertThat(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK), equalTo(true));

        logger.info("--> starting the previous master node again...");
        startNode(nonMasterNodeName, settings);

        Thread.sleep(3000);

        state = client("node1").admin().cluster().prepareState().setLocal(true).execute().actionGet().state();
        assertThat(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK), equalTo(false));
        state = client("node2").admin().cluster().prepareState().setLocal(true).execute().actionGet().state();
        assertThat(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK), equalTo(false));

        state = client("node1").admin().cluster().prepareState().execute().actionGet().state();
        assertThat(state.nodes().size(), equalTo(2));
        assertThat(state.metaData().indices().containsKey("test"), equalTo(true));

        logger.info("Running Cluster Health");
        clusterHealth = client("node1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
View Full Code Here

        logger.info("--> start first 2 nodes");
        startNode("node1", settings);
        startNode("node2", settings);

        Thread.sleep(500);
        ClusterState state = client("node1").admin().cluster().prepareState().setLocal(true).execute().actionGet().state();
        assertThat(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK), equalTo(true));
        state = client("node2").admin().cluster().prepareState().setLocal(true).execute().actionGet().state();
        assertThat(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK), equalTo(true));

        logger.info("--> start two more nodes");
        startNode("node3", settings);
        startNode("node4", settings);

        Thread.sleep(1000);

        state = client("node1").admin().cluster().prepareState().execute().actionGet().state();
        assertThat(state.nodes().size(), equalTo(4));
        String masterNode = state.nodes().masterNode().name();
        LinkedList<String> nonMasterNodes = new LinkedList<String>();
        for (DiscoveryNode node : state.nodes()) {
            if (!node.name().equals(masterNode)) {
                nonMasterNodes.add(node.name());
            }
        }

        logger.info("--> indexing some data");
        for (int i = 0; i < 100; i++) {
            client("node1").prepareIndex("test", "type1", Integer.toString(i)).setSource("field", "value").execute().actionGet();
        }
        // flush for simpler debugging
        client("node1").admin().indices().prepareFlush().execute().actionGet();

        client("node1").admin().indices().prepareRefresh().execute().actionGet();
        logger.info("--> verify we the data back");
        for (int i = 0; i < 10; i++) {
            assertThat(client("node1").prepareCount().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(100l));
        }

        Set<String> nodesToShutdown = Sets.newHashSet();
        nodesToShutdown.add(nonMasterNodes.removeLast());
        nodesToShutdown.add(nonMasterNodes.removeLast());
        logger.info("--> shutting down two master nodes {}", nodesToShutdown);
        for (String nodeToShutdown : nodesToShutdown) {
            closeNode(nodeToShutdown);
        }

        Thread.sleep(3000);

        String lastNonMasterNodeUp = nonMasterNodes.removeLast();
        logger.info("--> verify that there is no master anymore on remaining nodes");
        state = client(masterNode).admin().cluster().prepareState().setLocal(true).execute().actionGet().state();
        assertThat(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK), equalTo(true));
        state = client(lastNonMasterNodeUp).admin().cluster().prepareState().setLocal(true).execute().actionGet().state();
        assertThat(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK), equalTo(true));

        logger.info("--> start back the nodes {}", nodesToShutdown);
        for (String nodeToShutdown : nodesToShutdown) {
            startNode(nodeToShutdown, settings);
        }

        Thread.sleep(1000);

        logger.info("Running Cluster Health");
        ClusterHealthResponse clusterHealth = client("node1").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));

        state = client("node1").admin().cluster().prepareState().execute().actionGet().state();
        assertThat(state.nodes().size(), equalTo(4));

        logger.info("--> verify we the data back");
        for (int i = 0; i < 10; i++) {
            assertThat(client("node1").prepareCount().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(100l));
        }
View Full Code Here

        for (int i = 0; i < 10; i++) {
            CountResponse countResponse = client1.prepareCount().setQuery(matchAllQuery()).execute().actionGet();
            assertThat(countResponse.count(), equalTo(10l));
        }

        ClusterState clusterState = client1.admin().cluster().prepareState().execute().actionGet().state();
        assertThat(clusterState.metaData().index("test").mappings().containsKey("type1"), equalTo(true));

        client1.admin().indices().prepareDeleteMapping().setType("type1").execute().actionGet();
        Thread.sleep(500); // for now, we don't have ack logic, so just wait

        for (int i = 0; i < 10; i++) {
            CountResponse countResponse = client1.prepareCount().setQuery(matchAllQuery()).execute().actionGet();
            assertThat(countResponse.count(), equalTo(0l));
        }

        clusterState = client1.admin().cluster().prepareState().execute().actionGet().state();
        assertThat(clusterState.metaData().index("test").mappings().containsKey("type1"), equalTo(false));
    }
View Full Code Here

        FilterBuilder filter = termFilter("user", "kimchy");
        client1.admin().indices().prepareAliases().addAlias("test", "alias1", filter).execute().actionGet();

        // For now just making sure that filter was stored with the alias
        logger.info("--> making sure that filter was stored with alias [alias1] and filter [user:kimchy]");
        ClusterState clusterState = client1.admin().cluster().prepareState().execute().actionGet().state();
        IndexMetaData indexMd = clusterState.metaData().index("test");
        assertThat(indexMd.aliases().get("alias1").filter().string(), equalTo("{\"term\":{\"user\":\"kimchy\"}}"));

    }
View Full Code Here

                .add(indexRoutingTable("test").initializeEmpty(metaData.index("test")))
                .build();

        DiscoveryNodes nodes = DiscoveryNodes.newNodesBuilder().put(newNode("node1")).put(newNode("node2")).put(newNode("node3")).localNodeId("node1").masterNodeId("node2").build();

        ClusterState clusterState = newClusterStateBuilder().nodes(nodes).metaData(metaData).routingTable(routingTable).build();

        ShardsAllocation strategy = new ShardsAllocation();
        clusterState = newClusterStateBuilder().state(clusterState).routingTable(strategy.reroute(clusterState).routingTable()).build();

        ClusterState serializedClusterState = ClusterState.Builder.fromBytes(ClusterState.Builder.toBytes(clusterState), newNode("node1"));

        assertThat(serializedClusterState.routingTable().prettyPrint(), equalTo(clusterState.routingTable().prettyPrint()));
    }
View Full Code Here

                .add(indexRoutingTable("test").initializeEmpty(metaData.index("test")))
                .build();

        DiscoveryNodes nodes = DiscoveryNodes.newNodesBuilder().put(newNode("node1")).put(newNode("node2")).put(newNode("node3")).build();

        ClusterState clusterState = newClusterStateBuilder().nodes(nodes).metaData(metaData).routingTable(routingTable).build();

        ShardsAllocation strategy = new ShardsAllocation();
        RoutingTable source = strategy.reroute(clusterState).routingTable();

        BytesStreamOutput outStream = new BytesStreamOutput();
View Full Code Here

            return new PublishClusterStateRequest();
        }

        @Override public void messageReceived(PublishClusterStateRequest request, TransportChannel channel) throws Exception {
            StreamInput in = CachedStreamInput.cachedHandlesLzf(new BytesStreamInput(request.clusterStateInBytes));
            ClusterState clusterState = ClusterState.Builder.readFrom(in, nodesProvider.nodes().localNode());
            listener.onNewClusterState(clusterState);
            channel.sendResponse(VoidStreamable.INSTANCE);
        }
View Full Code Here

        @Override public JoinRequest newInstance() {
            return new JoinRequest();
        }

        @Override public void messageReceived(JoinRequest request, TransportChannel channel) throws Exception {
            ClusterState clusterState = listener.onJoin(request.node);
            if (request.withClusterState) {
                channel.sendResponse(new JoinResponse(clusterState));
            } else {
                channel.sendResponse(VoidStreamable.INSTANCE);
            }
View Full Code Here

                    logger.warn("failed to connect to master [{}], retrying...", e, masterNode);
                    retry = true;
                    continue;
                }
                // send join request
                ClusterState clusterState;
                try {
                    clusterState = membership.sendJoinRequestBlocking(masterNode, localNode, pingTimeout);
                } catch (Exception e) {
                    if (e instanceof ElasticSearchException) {
                        logger.info("failed to send join request to master [{}], reason [{}]", masterNode, ((ElasticSearchException) e).getDetailedMessage());
                    } else {
                        logger.info("failed to send join request to master [{}], reason [{}]", masterNode, e.getMessage());
                    }
                    if (logger.isTraceEnabled()) {
                        logger.trace("detailed failed reason", e);
                    }
                    // failed to send the join request, retry
                    retry = true;
                    continue;
                }
                masterFD.start(masterNode, "initial_join");

                // we update the metadata once we managed to join, so we pre-create indices and so on (no shards allocation)
                final MetaData metaData = clusterState.metaData();
                // sync also the version with the version the master currently has, so the next update will be applied
                final long version = clusterState.version();
                clusterService.submitStateUpdateTask("zen-disco-join (detected master)", new ProcessedClusterStateUpdateTask() {
                    @Override public ClusterState execute(ClusterState currentState) {
                        ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(currentState.blocks()).removeGlobalBlock(NO_MASTER_BLOCK).build();
                        // make sure we have the local node id set, we might need it as a result of the new metadata
                        DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.newNodesBuilder().putAll(currentState.nodes()).put(localNode).localNodeId(localNode.id());
View Full Code Here

TOP

Related Classes of org.elasticsearch.cluster.ClusterState$Custom

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.