Search in sources :

Example 11 with NodesInfoResponse

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

the class RestPluginsAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) throws Exception {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.clear().plugins(true);
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestResponseListener<NodesInfoResponse>(channel) {

                @Override
                public RestResponse buildResponse(final NodesInfoResponse nodesInfoResponse) throws Exception {
                    return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse), channel);
                }
            });
        }
    });
}
Also used : PluginInfo(org.elasticsearch.plugins.PluginInfo) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) NodeClient(org.elasticsearch.client.node.NodeClient) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) RestActionListener(org.elasticsearch.rest.action.RestActionListener) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)

Example 12 with NodesInfoResponse

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

the class Netty4TransportMultiPortIntegrationIT method testThatInfosAreExposed.

@Network
public void testThatInfosAreExposed() throws Exception {
    NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().clear().setTransport(true).get();
    for (NodeInfo nodeInfo : response.getNodes()) {
        assertThat(nodeInfo.getTransport().getProfileAddresses().keySet(), hasSize(1));
        assertThat(nodeInfo.getTransport().getProfileAddresses(), hasKey("client1"));
        BoundTransportAddress boundTransportAddress = nodeInfo.getTransport().getProfileAddresses().get("client1");
        for (TransportAddress transportAddress : boundTransportAddress.boundAddresses()) {
            assertThat(transportAddress, instanceOf(TransportAddress.class));
        }
        // bound addresses
        for (TransportAddress transportAddress : boundTransportAddress.boundAddresses()) {
            assertThat(transportAddress, instanceOf(TransportAddress.class));
            assertThat(transportAddress.address().getPort(), is(allOf(greaterThanOrEqualTo(randomPort), lessThanOrEqualTo(randomPort + 10))));
        }
        // publish address
        assertThat(boundTransportAddress.publishAddress(), instanceOf(TransportAddress.class));
        TransportAddress publishAddress = boundTransportAddress.publishAddress();
        assertThat(NetworkAddress.format(publishAddress.address().getAddress()), is("127.0.0.7"));
        assertThat(publishAddress.address().getPort(), is(4321));
    }
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) Network(org.elasticsearch.test.junit.annotations.Network)

Example 13 with NodesInfoResponse

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

the class Netty4TransportPublishAddressIT method testDifferentPorts.

public void testDifferentPorts() throws Exception {
    if (!NetworkUtils.SUPPORTS_V6) {
        return;
    }
    logger.info("--> starting a node on ipv4 only");
    Settings ipv4Settings = Settings.builder().put("network.host", "127.0.0.1").build();
    // should bind 127.0.0.1:XYZ
    String ipv4OnlyNode = internalCluster().startNode(ipv4Settings);
    logger.info("--> starting a node on ipv4 and ipv6");
    Settings bothSettings = Settings.builder().put("network.host", "_local_").build();
    // should bind [::1]:XYZ and 127.0.0.1:XYZ+1
    internalCluster().startNode(bothSettings);
    logger.info("--> waiting for the cluster to declare itself stable");
    // fails if port of publish address does not match corresponding bound address
    ensureStableCluster(2);
    logger.info("--> checking if boundAddress matching publishAddress has same port");
    NodesInfoResponse nodesInfoResponse = client().admin().cluster().prepareNodesInfo().get();
    for (NodeInfo nodeInfo : nodesInfoResponse.getNodes()) {
        BoundTransportAddress boundTransportAddress = nodeInfo.getTransport().getAddress();
        if (nodeInfo.getNode().getName().equals(ipv4OnlyNode)) {
            assertThat(boundTransportAddress.boundAddresses().length, equalTo(1));
            assertThat(boundTransportAddress.boundAddresses()[0].getPort(), equalTo(boundTransportAddress.publishAddress().getPort()));
        } else {
            assertThat(boundTransportAddress.boundAddresses().length, greaterThan(1));
            for (TransportAddress boundAddress : boundTransportAddress.boundAddresses()) {
                assertThat(boundAddress, instanceOf(TransportAddress.class));
                TransportAddress inetBoundAddress = (TransportAddress) boundAddress;
                if (inetBoundAddress.address().getAddress() instanceof Inet4Address) {
                    // IPv4 address is preferred publish address for _local_
                    assertThat(inetBoundAddress.getPort(), equalTo(boundTransportAddress.publishAddress().getPort()));
                }
            }
        }
    }
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) Inet4Address(java.net.Inet4Address) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) Settings(org.elasticsearch.common.settings.Settings)

Example 14 with NodesInfoResponse

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

the class SimpleNodesInfoIT method testNodesInfosTotalIndexingBuffer.

public void testNodesInfosTotalIndexingBuffer() throws Exception {
    List<String> nodesIds = internalCluster().startNodes(2);
    final String node_1 = nodesIds.get(0);
    final String node_2 = nodesIds.get(1);
    ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("2").get();
    logger.info("--> done cluster_health, status {}", clusterHealth.getStatus());
    String server1NodeId = internalCluster().getInstance(ClusterService.class, node_1).state().nodes().getLocalNodeId();
    String server2NodeId = internalCluster().getInstance(ClusterService.class, node_2).state().nodes().getLocalNodeId();
    logger.info("--> started nodes: {} and {}", server1NodeId, server2NodeId);
    NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().execute().actionGet();
    assertThat(response.getNodes().size(), is(2));
    assertThat(response.getNodesMap().get(server1NodeId), notNullValue());
    assertNotNull(response.getNodesMap().get(server1NodeId).getTotalIndexingBuffer());
    assertThat(response.getNodesMap().get(server1NodeId).getTotalIndexingBuffer().getBytes(), greaterThan(0L));
    assertThat(response.getNodesMap().get(server2NodeId), notNullValue());
    assertNotNull(response.getNodesMap().get(server2NodeId).getTotalIndexingBuffer());
    assertThat(response.getNodesMap().get(server2NodeId).getTotalIndexingBuffer().getBytes(), greaterThan(0L));
    // again, using only the indices flag
    response = client().admin().cluster().prepareNodesInfo().clear().setIndices(true).execute().actionGet();
    assertThat(response.getNodes().size(), is(2));
    assertThat(response.getNodesMap().get(server1NodeId), notNullValue());
    assertNotNull(response.getNodesMap().get(server1NodeId).getTotalIndexingBuffer());
    assertThat(response.getNodesMap().get(server1NodeId).getTotalIndexingBuffer().getBytes(), greaterThan(0L));
    assertThat(response.getNodesMap().get(server2NodeId), notNullValue());
    assertNotNull(response.getNodesMap().get(server2NodeId).getTotalIndexingBuffer());
    assertThat(response.getNodesMap().get(server2NodeId).getTotalIndexingBuffer().getBytes(), greaterThan(0L));
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterService(org.elasticsearch.cluster.service.ClusterService) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)

Example 15 with NodesInfoResponse

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

the class ESIntegTestCase method createRestClient.

protected static RestClient createRestClient(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback, String protocol) {
    final NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get();
    final List<NodeInfo> nodes = nodeInfos.getNodes();
    assertFalse(nodeInfos.hasFailures());
    List<HttpHost> hosts = new ArrayList<>();
    for (NodeInfo node : nodes) {
        if (node.getHttp() != null) {
            TransportAddress publishAddress = node.getHttp().address().publishAddress();
            InetSocketAddress address = publishAddress.address();
            hosts.add(new HttpHost(NetworkAddress.format(address.getAddress()), address.getPort(), protocol));
        }
    }
    RestClientBuilder builder = RestClient.builder(hosts.toArray(new HttpHost[hosts.size()]));
    if (httpClientConfigCallback != null) {
        builder.setHttpClientConfigCallback(httpClientConfigCallback);
    }
    return builder.build();
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) HttpHost(org.apache.http.HttpHost) TransportAddress(org.elasticsearch.common.transport.TransportAddress) InetSocketAddress(java.net.InetSocketAddress) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) RestClientBuilder(org.elasticsearch.client.RestClientBuilder)

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