Search in sources :

Example 16 with NodesInfoResponse

use of org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse in project elasticsearch by elastic.

the class AckClusterUpdateSettingsIT method testClusterUpdateSettingsNoAcknowledgement.

public void testClusterUpdateSettingsNoAcknowledgement() {
    client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put("number_of_shards", between(cluster().numDataNodes(), DEFAULT_MAX_NUM_SHARDS)).put("number_of_replicas", 0)).get();
    ensureGreen();
    // now that the cluster is stable, remove timeout
    removePublishTimeout();
    NodesInfoResponse nodesInfo = client().admin().cluster().prepareNodesInfo().get();
    String excludedNodeId = null;
    for (NodeInfo nodeInfo : nodesInfo.getNodes()) {
        if (nodeInfo.getNode().isDataNode()) {
            excludedNodeId = nodeInfo.getNode().getId();
            break;
        }
    }
    assertNotNull(excludedNodeId);
    ClusterUpdateSettingsResponse clusterUpdateSettingsResponse = client().admin().cluster().prepareUpdateSettings().setTimeout("0s").setTransientSettings(Settings.builder().put("cluster.routing.allocation.exclude._id", excludedNodeId)).get();
    assertThat(clusterUpdateSettingsResponse.isAcknowledged(), equalTo(false));
    assertThat(clusterUpdateSettingsResponse.getTransientSettings().get("cluster.routing.allocation.exclude._id"), equalTo(excludedNodeId));
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) ClusterUpdateSettingsResponse(org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse)

Example 17 with NodesInfoResponse

use of org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse in project elasticsearch by elastic.

the class AckClusterUpdateSettingsIT method testClusterUpdateSettingsAcknowledgement.

public void testClusterUpdateSettingsAcknowledgement() {
    createIndex("test");
    ensureGreen();
    // now that the cluster is stable, remove timeout
    removePublishTimeout();
    NodesInfoResponse nodesInfo = client().admin().cluster().prepareNodesInfo().get();
    String excludedNodeId = null;
    for (NodeInfo nodeInfo : nodesInfo.getNodes()) {
        if (nodeInfo.getNode().isDataNode()) {
            excludedNodeId = nodeInfo.getNode().getId();
            break;
        }
    }
    assertNotNull(excludedNodeId);
    ClusterUpdateSettingsResponse clusterUpdateSettingsResponse = client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put("cluster.routing.allocation.exclude._id", excludedNodeId)).get();
    assertAcked(clusterUpdateSettingsResponse);
    assertThat(clusterUpdateSettingsResponse.getTransientSettings().get("cluster.routing.allocation.exclude._id"), equalTo(excludedNodeId));
    for (Client client : clients()) {
        ClusterState clusterState = getLocalClusterState(client);
        assertThat(clusterState.metaData().transientSettings().get("cluster.routing.allocation.exclude._id"), equalTo(excludedNodeId));
        for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
            for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
                for (ShardRouting shardRouting : indexShardRoutingTable) {
                    assert clusterState.nodes() != null;
                    if (shardRouting.unassigned() == false && clusterState.nodes().get(shardRouting.currentNodeId()).getId().equals(excludedNodeId)) {
                        //if the shard is still there it must be relocating and all nodes need to know, since the request was acknowledged
                        //reroute happens as part of the update settings and we made sure no throttling comes into the picture via settings
                        assertThat(shardRouting.relocating(), equalTo(true));
                    }
                }
            }
        }
    }
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterState(org.elasticsearch.cluster.ClusterState) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) ClusterUpdateSettingsResponse(org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse) Client(org.elasticsearch.client.Client) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 18 with NodesInfoResponse

use of org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse in project elasticsearch by elastic.

the class SettingsFilteringIT method testNodeInfoIsFiltered.

public void testNodeInfoIsFiltered() {
    NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().clear().setSettings(true).get();
    for (NodeInfo info : nodeInfos.getNodes()) {
        Settings settings = info.getSettings();
        assertNotNull(settings);
        assertNull(settings.get(SettingsFilteringPlugin.SOME_NODE_SETTING.getKey()));
        assertTrue(settings.getAsBoolean(SettingsFilteringPlugin.SOME_OTHER_NODE_SETTING.getKey(), false));
        assertEquals(settings.get("node.name"), info.getNode().getName());
    }
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) Settings(org.elasticsearch.common.settings.Settings)

Example 19 with NodesInfoResponse

use of org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse in project elasticsearch-jdbc by jprante.

the class NodeTestUtils method findNodeAddresses.

protected void findNodeAddresses() {
    NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().transport(true);
    NodesInfoResponse response = client("1").admin().cluster().nodesInfo(nodesInfoRequest).actionGet();
    Iterator<NodeInfo> it = response.iterator();
    hosts = new LinkedList<>();
    hosts = new LinkedList<>();
    while (it.hasNext()) {
        NodeInfo nodeInfo = it.next();
        TransportInfo transportInfo = nodeInfo.getTransport();
        TransportAddress address = transportInfo.getAddress().publishAddress();
        if (address instanceof InetSocketTransportAddress) {
            InetSocketTransportAddress inetSocketTransportAddress = (InetSocketTransportAddress) address;
            hosts.add(inetSocketTransportAddress.address().getHostName() + ":" + inetSocketTransportAddress.address().getPort());
        }
    }
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) TransportInfo(org.elasticsearch.transport.TransportInfo) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

Example 20 with NodesInfoResponse

use of org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse in project MSEC by Tencent.

the class ESHelper method waitForClusterReady.

public void waitForClusterReady(final TransportClient client, ArrayList<String> ips, final ClusterHealthStatus status) throws IOException {
    Logger logger = Logger.getLogger(ESHelper.class);
    int timeout = 60;
    int node_num = 0;
    long begin = System.currentTimeMillis() / 1000L;
    long end = begin;
    Set<String> done_ips = new HashSet<>();
    try {
        logger.info("waiting for cluster state: " + status.name());
        ClusterHealthResponse healthResponse = null;
        while (true) {
            try {
                healthResponse = client.admin().cluster().prepareHealth().setWaitForStatus(status).setTimeout(TimeValue.timeValueSeconds(5)).execute().actionGet();
            } catch (NoNodeAvailableException | MasterNotDiscoveredException ex) {
                end = System.currentTimeMillis() / 1000L;
                if (end - begin >= timeout)
                    throw new IOException("Server start timeout");
                logger.info("server still starting/discovering, retry...");
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                }
                continue;
            }
            if (healthResponse != null && healthResponse.isTimedOut()) {
                end = System.currentTimeMillis() / 1000L;
                if (//timeout
                end - begin >= timeout)
                    throw new IOException("cluster not ready, current state is " + healthResponse.getStatus().name());
                continue;
            } else {
                logger.info("cluster state ok");
                int new_node_num = healthResponse.getNumberOfNodes();
                if (new_node_num > node_num) {
                    node_num = new_node_num;
                    NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().all().get();
                    for (NodeInfo node : nodeInfos.getNodes()) {
                        if (!done_ips.contains(node.getHostname()) && ips.contains(node.getHostname())) {
                            updateStatus(node.getHostname(), "Done.");
                            done_ips.add(node.getHostname());
                        }
                    }
                    if (done_ips.size() == ips.size())
                        break;
                    end = System.currentTimeMillis() / 1000L;
                    if (//timeout
                    end - begin >= timeout)
                        break;
                }
            }
        }
    } catch (final ElasticsearchTimeoutException e) {
        throw new IOException("ES API timeout");
    }
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) IOException(java.io.IOException) Logger(org.apache.log4j.Logger) NoNodeAvailableException(org.elasticsearch.client.transport.NoNodeAvailableException) MasterNotDiscoveredException(org.elasticsearch.discovery.MasterNotDiscoveredException) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo)

Aggregations

NodesInfoResponse (org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)20 NodeInfo (org.elasticsearch.action.admin.cluster.node.info.NodeInfo)13 NodesInfoRequest (org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)7 Settings (org.elasticsearch.common.settings.Settings)6 TransportAddress (org.elasticsearch.common.transport.TransportAddress)5 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)4 ClusterStateRequest (org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)4 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)4 NodeClient (org.elasticsearch.client.node.NodeClient)4 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)4 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)4 Table (org.elasticsearch.common.Table)4 RestController (org.elasticsearch.rest.RestController)4 RestRequest (org.elasticsearch.rest.RestRequest)4 GET (org.elasticsearch.rest.RestRequest.Method.GET)4 RestResponse (org.elasticsearch.rest.RestResponse)4 RestActionListener (org.elasticsearch.rest.action.RestActionListener)4 RestResponseListener (org.elasticsearch.rest.action.RestResponseListener)4 Map (java.util.Map)3 HashMap (java.util.HashMap)2