org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest Java Examples

The following examples show how to use org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestPluginsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void doRequest(final RestRequest request, final RestChannel channel, final Client 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()));

    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);
                }
            });
        }
    });
}
 
Example #2
Source File: RestNodesAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void doRequest(final RestRequest request, final RestChannel channel, final Client 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()));

    client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.clear().jvm(true).os(true).process(true);
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {
                @Override
                public void processResponse(final NodesInfoResponse nodesInfoResponse) {
                    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
                    nodesStatsRequest.clear().jvm(true).os(true).fs(true).indices(true).process(true).script(true);
                    client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {
                        @Override
                        public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
                            return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                        }
                    });
                }
            });
        }
    });
}
 
Example #3
Source File: NodesInfoRequestBuilder.java    From elasticshell with Apache License 2.0 5 votes vote down vote up
@Override
protected XContentBuilder toXContent(NodesInfoRequest request, NodesInfoResponse response, XContentBuilder builder) throws IOException {
    response.settingsFilter(new SettingsFilter(ImmutableSettings.settingsBuilder().build()));
    builder.startObject();
    builder.field(Fields.OK, true);
    response.toXContent(builder, ToXContent.EMPTY_PARAMS);
    builder.endObject();
    return builder;
}
 
Example #4
Source File: NodeTestUtils.java    From elasticsearch-analysis-baseform with Apache License 2.0 5 votes vote down vote up
protected void findNodeAddress() {
    NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().transport(true);
    NodesInfoResponse response = client("1").admin().cluster().nodesInfo(nodesInfoRequest).actionGet();
    Object obj = response.iterator().next().getTransport().getAddress()
            .publishAddress();
    if (obj instanceof InetSocketTransportAddress) {
        InetSocketTransportAddress address = (InetSocketTransportAddress) obj;
        host = address.address().getHostName();
        port = address.address().getPort();
    }
}
 
Example #5
Source File: NodeTestUtils.java    From elasticsearch-helper with Apache License 2.0 5 votes vote down vote up
protected void findNodeAddress() {
    NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().transport(true);
    NodesInfoResponse response = client("1").admin().cluster().nodesInfo(nodesInfoRequest).actionGet();
    Object obj = response.iterator().next().getTransport().getAddress()
            .publishAddress();
    if (obj instanceof InetSocketTransportAddress) {
        InetSocketTransportAddress address = (InetSocketTransportAddress) obj;
        host = address.address().getHostName();
        port = address.address().getPort();
    }
}
 
Example #6
Source File: IngestAutodiscoverTest.java    From elasticsearch-helper with Apache License 2.0 5 votes vote down vote up
@Test
public void testAutodiscover() throws IOException {
    startNode("2");
    Settings.Builder settingsBuilder = Settings.builder()
            .put("cluster.name", getClusterName())
            .put("path.home", System.getProperty("path.home"))
            .put("autodiscover", true);
    int i = 0;
    NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().transport(true);
    NodesInfoResponse response = client("1").admin().cluster().nodesInfo(nodesInfoRequest).actionGet();
    for (NodeInfo nodeInfo : response) {
        TransportAddress ta = nodeInfo.getTransport().getAddress().publishAddress();
        if (ta instanceof InetSocketTransportAddress) {
            InetSocketTransportAddress address = (InetSocketTransportAddress) ta;
            settingsBuilder.put("host." + i++, address.address().getHostName() + ":" + address.address().getPort());
        }
    }
    final IngestTransportClient ingest = ClientBuilder.builder()
            .put(settingsBuilder.build())
            .setMetric(new LongAdderIngestMetric())
            .toIngestTransportClient();
    try {
        ingest.newIndex("test");
    } finally {
        ingest.shutdown();
    }
    if (ingest.hasThrowable()) {
        logger.error("error", ingest.getThrowable());
    }
    assertFalse(ingest.hasThrowable());
}
 
Example #7
Source File: AbstractNodeTest.java    From elasticsearch-gatherer with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void createIndex() throws Exception {
    startNode("1");
    // find node address
    NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().transport(true);
    NodesInfoResponse response = client("1").admin().cluster().nodesInfo(nodesInfoRequest).actionGet();
    InetSocketTransportAddress address = (InetSocketTransportAddress)response.iterator().next()
                    .getTransport().getAddress().publishAddress();
    PORT = address.address().getPort();
    addresses.put("1", address);
    logger.info("creating index {}", INDEX);
    client("1").admin().indices().create(new CreateIndexRequest(INDEX)).actionGet();
    logger.info("index {} created", INDEX);
}
 
Example #8
Source File: ElasticSearchService.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected NodesStatsResponse getNodesStats() {
    final NodesInfoResponse nodesInfoResponse = client.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet();
    final String[] nodes = new String[nodesInfoResponse.getNodes().length];

    int i = 0;

    for (NodeInfo nodeInfo : nodesInfoResponse.getNodes()) {
        nodes[i++] = nodeInfo.getNode().getName();
    }

    return client.admin().cluster().nodesStats(new NodesStatsRequest(nodes)).actionGet();
}
 
Example #9
Source File: ClusterRerouteManager.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
private void createNodeNameVsNodeIdMap(
        BiMap<String, String> nodeNameVsNodeId) {
    nodeNameVsNodeId.clear();
    NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
    nodesInfoRequest.all();
    NodesInfoResponse nodesInfoResponse = connection.getClient()
            .admin()
            .cluster()
            .nodesInfo(nodesInfoRequest)
            .actionGet();
    nodesInfoResponse.getNodes()
            .forEach(nodeInfo -> nodeNameVsNodeId.put(nodeInfo.getNode()
                                                              .getName(), nodeInfo.getNode()
                                                              .getId()));
}
 
Example #10
Source File: AbstractNodeTestHelper.java    From elasticsearch-csv with Apache License 2.0 5 votes vote down vote up
protected void findNodeAddress() {
    NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().transport(true);
    NodesInfoResponse response = client("1").admin().cluster().nodesInfo(nodesInfoRequest).actionGet();
    Object obj = response.iterator().next().getTransport().getAddress()
            .publishAddress();
    if (obj instanceof InetSocketTransportAddress) {
        InetSocketTransportAddress address = (InetSocketTransportAddress) obj;
        host = address.address().getHostName();
        port = address.address().getPort();
    }
}
 
Example #11
Source File: NodeTestUtils.java    From elasticsearch-xml with Apache License 2.0 5 votes vote down vote up
protected void findNodeAddress() {
    NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().transport(true);
    NodesInfoResponse response = client("1").admin().cluster().nodesInfo(nodesInfoRequest).actionGet();
    Object obj = response.iterator().next().getTransport().getAddress()
            .publishAddress();
    if (obj instanceof InetSocketTransportAddress) {
        InetSocketTransportAddress address = (InetSocketTransportAddress) obj;
        host = address.address().getHostName();
        port = address.address().getPort();
    }
}
 
Example #12
Source File: ElasticSearchService.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected NodesStatsResponse getNodesStats() {
    final NodesInfoResponse nodesInfoResponse = client.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet();
    final String[] nodes = new String[nodesInfoResponse.getNodes().length];

    int i = 0;

    for (NodeInfo nodeInfo : nodesInfoResponse.getNodes()) {
        nodes[i++] = nodeInfo.getNode().getName();
    }

    return client.admin().cluster().nodesStats(new NodesStatsRequest(nodes)).actionGet();
}
 
Example #13
Source File: RestThreadPoolAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void doRequest(final RestRequest request, final RestChannel channel, final Client 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()));

    client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.clear().process(true).threadPool(true);
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {
                @Override
                public void processResponse(final NodesInfoResponse nodesInfoResponse) {
                    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
                    nodesStatsRequest.clear().threadPool(true);
                    client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {
                        @Override
                        public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
                            return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                        }
                    });
                }
            });
        }
    });
}
 
Example #14
Source File: SSLTest.java    From deprecated-security-ssl with Apache License 2.0 5 votes vote down vote up
@Test
public void testTransportClientSSL() throws Exception {

    final Settings settings = Settings.builder().put("opendistro_security.ssl.transport.enabled", true)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_KEYSTORE_ALIAS, "node-0")
            .put("opendistro_security.ssl.transport.keystore_filepath", getAbsoluteFilePathFromClassPath("node-0-keystore.jks"))
            .put("opendistro_security.ssl.transport.truststore_filepath", getAbsoluteFilePathFromClassPath("truststore.jks"))
            .put("opendistro_security.ssl.transport.enforce_hostname_verification", false)
            .put("opendistro_security.ssl.transport.resolve_hostname", false).build();

    startES(settings);
    
    log.debug("Elasticsearch started");

    final Settings tcSettings = Settings.builder().put("cluster.name", clustername).put(settings).build();

    try (TransportClient tc = new TransportClientImpl(tcSettings, asCollection(OpenDistroSecuritySSLPlugin.class))) {
        
        log.debug("TransportClient built, connect now to {}:{}", nodeHost, nodePort);
        
        tc.addTransportAddress(new TransportAddress(new InetSocketAddress(nodeHost, nodePort)));
        Assert.assertEquals(3, tc.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());            
        log.debug("TransportClient connected");           
        Assert.assertEquals("test", tc.index(new IndexRequest("test","test").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"a\":5}", XContentType.JSON)).actionGet().getIndex());            
        log.debug("Index created");           
        Assert.assertEquals(1L, tc.search(new SearchRequest("test")).actionGet().getHits().getTotalHits());
        log.debug("Search done");
        Assert.assertEquals(3, tc.admin().cluster().health(new ClusterHealthRequest("test")).actionGet().getNumberOfNodes());
        log.debug("ClusterHealth done");            
        Assert.assertEquals(3, tc.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());           
        log.debug("NodesInfoRequest asserted");
    }
}
 
Example #15
Source File: RestNodeAttrsAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void doRequest(final RestRequest request, final RestChannel channel, final Client 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()));

    client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.clear().jvm(false).os(false).process(true);
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {
                @Override
                public void processResponse(final NodesInfoResponse nodesInfoResponse) {
                    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
                    nodesStatsRequest.clear().jvm(false).os(false).fs(false).indices(false).process(false);
                    client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {
                        @Override
                        public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
                            return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                        }
                    });
                }
            });
        }
    });
}
 
Example #16
Source File: OpenSSLTest.java    From deprecated-security-ssl with Apache License 2.0 5 votes vote down vote up
@Test
public void testNodeClientSSLwithOpenSslTLSv13() throws Exception {

    Assume.assumeTrue(OpenSsl.isAvailable() && OpenSsl.version() > 0x10101009L);

    final Settings settings = Settings.builder().put("opendistro_security.ssl.transport.enabled", true)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_KEYSTORE_ALIAS, "node-0")
            .put("opendistro_security.ssl.transport.keystore_filepath", getAbsoluteFilePathFromClassPath("node-0-keystore.jks"))
            .put("opendistro_security.ssl.transport.truststore_filepath", getAbsoluteFilePathFromClassPath("truststore.jks"))
            .put("opendistro_security.ssl.transport.enforce_hostname_verification", false)
            .put("opendistro_security.ssl.transport.resolve_hostname", false)
            .putList(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_ENABLED_PROTOCOLS, "TLSv1.3")
            .putList(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_ENABLED_CIPHERS, "TLS_CHACHA20_POLY1305_SHA256")
            .build();

    startES(settings);

    final Settings tcSettings = Settings.builder().put("cluster.name", clustername).put("path.home", ".")
            .put("node.name", "client_node_" + new Random().nextInt())
            .put(settings)// -----
            .build();

    try (Node node = new PluginAwareNode(tcSettings, Netty4Plugin.class, OpenDistroSecuritySSLPlugin.class).start()) {
        ClusterHealthResponse res = node.client().admin().cluster().health(new ClusterHealthRequest().waitForNodes("4").timeout(TimeValue.timeValueSeconds(5))).actionGet();
        Assert.assertFalse(res.isTimedOut());
        Assert.assertEquals(4, res.getNumberOfNodes());
        Assert.assertEquals(4, node.client().admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());
    }

    Assert.assertFalse(executeSimpleRequest("_nodes/stats?pretty").contains("\"tx_size_in_bytes\" : 0"));
    Assert.assertFalse(executeSimpleRequest("_nodes/stats?pretty").contains("\"rx_count\" : 0"));
    Assert.assertFalse(executeSimpleRequest("_nodes/stats?pretty").contains("\"rx_size_in_bytes\" : 0"));
    Assert.assertFalse(executeSimpleRequest("_nodes/stats?pretty").contains("\"tx_count\" : 0"));
}
 
Example #17
Source File: SSLTest.java    From deprecated-security-ssl with Apache License 2.0 5 votes vote down vote up
@Test
public void testNodeClientSSLwithJavaTLSv13() throws Exception {
    
    //Java TLS 1.3 is available since Java 11
    Assume.assumeTrue(!allowOpenSSL && PlatformDependent.javaVersion() >= 11);

    final Settings settings = Settings.builder().put("opendistro_security.ssl.transport.enabled", true)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_KEYSTORE_ALIAS, "node-0")
            .put("opendistro_security.ssl.transport.keystore_filepath", getAbsoluteFilePathFromClassPath("node-0-keystore.jks"))
            .put("opendistro_security.ssl.transport.truststore_filepath", getAbsoluteFilePathFromClassPath("truststore.jks"))
            .put("opendistro_security.ssl.transport.enforce_hostname_verification", false)
            .put("opendistro_security.ssl.transport.resolve_hostname", false)
            .putList(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_ENABLED_PROTOCOLS, "TLSv1.3")
            .putList(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_ENABLED_CIPHERS, "TLS_AES_128_GCM_SHA256")
            .build();

    startES(settings);      

    final Settings tcSettings = Settings.builder().put("cluster.name", clustername).put("path.home", ".")
            .put("node.name", "client_node_" + new Random().nextInt())
            .put(settings)// -----
            .build();

    try (Node node = new PluginAwareNode(tcSettings, Netty4Plugin.class, OpenDistroSecuritySSLPlugin.class).start()) {
        ClusterHealthResponse res = node.client().admin().cluster().health(new ClusterHealthRequest().waitForNodes("4").timeout(TimeValue.timeValueSeconds(5))).actionGet();
        Assert.assertFalse(res.isTimedOut());
        Assert.assertEquals(4, res.getNumberOfNodes());
        Assert.assertEquals(4, node.client().admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());
    }

    Assert.assertFalse(executeSimpleRequest("_nodes/stats?pretty").contains("\"tx_size_in_bytes\" : 0"));
    Assert.assertFalse(executeSimpleRequest("_nodes/stats?pretty").contains("\"rx_count\" : 0"));
    Assert.assertFalse(executeSimpleRequest("_nodes/stats?pretty").contains("\"rx_size_in_bytes\" : 0"));
    Assert.assertFalse(executeSimpleRequest("_nodes/stats?pretty").contains("\"tx_count\" : 0"));
}
 
Example #18
Source File: SSLTest.java    From deprecated-security-ssl with Apache License 2.0 5 votes vote down vote up
@Test
public void testTransportClientSSLFail() throws Exception {
    thrown.expect(NoNodeAvailableException.class);

    final Settings settings = Settings.builder().put("opendistro_security.ssl.transport.enabled", true)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_KEYSTORE_ALIAS, "node-0")
            .put("opendistro_security.ssl.transport.keystore_filepath", getAbsoluteFilePathFromClassPath("node-0-keystore.jks"))
            .put("opendistro_security.ssl.transport.truststore_filepath", getAbsoluteFilePathFromClassPath("truststore.jks"))
            .put("opendistro_security.ssl.transport.enforce_hostname_verification", false)
            .put("opendistro_security.ssl.transport.resolve_hostname", false).build();

    startES(settings);

    final Settings tcSettings = Settings.builder().put("cluster.name", clustername)
            .put("path.home", getAbsoluteFilePathFromClassPath("node-0-keystore.jks").getParent())
            .put("opendistro_security.ssl.transport.keystore_filepath", getAbsoluteFilePathFromClassPath("node-0-keystore.jks"))
            .put("opendistro_security.ssl.transport.truststore_filepath", getAbsoluteFilePathFromClassPath("truststore_fail.jks"))
            .put("opendistro_security.ssl.transport.enforce_hostname_verification", false)
            .put("opendistro_security.ssl.transport.resolve_hostname", false).build();

    try (TransportClient tc = new TransportClientImpl(tcSettings, asCollection(OpenDistroSecuritySSLPlugin.class))) {
        tc.addTransportAddress(new TransportAddress(new InetSocketAddress(nodeHost, nodePort)));
        Assert.assertEquals(3, tc.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());
    }
}
 
Example #19
Source File: SSLTest.java    From deprecated-security-ssl with Apache License 2.0 5 votes vote down vote up
@Test
public void testNodeClientSSL() throws Exception {

    final Settings settings = Settings.builder().put("opendistro_security.ssl.transport.enabled", true)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_KEYSTORE_ALIAS, "node-0")
            .put("opendistro_security.ssl.transport.keystore_filepath", getAbsoluteFilePathFromClassPath("node-0-keystore.jks"))
            .put("opendistro_security.ssl.transport.truststore_filepath", getAbsoluteFilePathFromClassPath("truststore.jks"))
            .put("opendistro_security.ssl.transport.enforce_hostname_verification", false)
            .put("opendistro_security.ssl.transport.resolve_hostname", false)
            .build();

    startES(settings);      

    final Settings tcSettings = Settings.builder().put("cluster.name", clustername).put("path.home", ".")
            .put("node.name", "client_node_" + new Random().nextInt())
            .put(settings)// -----
            .build();

    try (Node node = new PluginAwareNode(tcSettings, Netty4Plugin.class, OpenDistroSecuritySSLPlugin.class).start()) {
        ClusterHealthResponse res = node.client().admin().cluster().health(new ClusterHealthRequest().waitForNodes("4").timeout(TimeValue.timeValueSeconds(5))).actionGet();
        Assert.assertFalse(res.isTimedOut());
        Assert.assertEquals(4, res.getNumberOfNodes());
        Assert.assertEquals(4, node.client().admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());
    }

    Assert.assertFalse(executeSimpleRequest("_nodes/stats?pretty").contains("\"tx_size_in_bytes\" : 0"));
    Assert.assertFalse(executeSimpleRequest("_nodes/stats?pretty").contains("\"rx_count\" : 0"));
    Assert.assertFalse(executeSimpleRequest("_nodes/stats?pretty").contains("\"rx_size_in_bytes\" : 0"));
    Assert.assertFalse(executeSimpleRequest("_nodes/stats?pretty").contains("\"tx_count\" : 0"));
}
 
Example #20
Source File: RestNodesInfoAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    String[] nodeIds;
    Set<String> metrics;

    // special case like /_nodes/os (in this case os are metrics and not the nodeId)
    // still, /_nodes/_local (or any other node id) should work and be treated as usual
    // this means one must differentiate between allowed metrics and arbitrary node ids in the same place
    if (request.hasParam("nodeId") && !request.hasParam("metrics")) {
        Set<String> metricsOrNodeIds = Strings.splitStringByCommaToSet(request.param("nodeId", "_all"));
        boolean isMetricsOnly = ALLOWED_METRICS.containsAll(metricsOrNodeIds);
        if (isMetricsOnly) {
            nodeIds = new String[]{"_all"};
            metrics = metricsOrNodeIds;
        } else {
            nodeIds = metricsOrNodeIds.toArray(new String[]{});
            metrics = Sets.newHashSet("_all");
        }
    } else {
        nodeIds = Strings.splitStringByCommaToArray(request.param("nodeId", "_all"));
        metrics = Strings.splitStringByCommaToSet(request.param("metrics", "_all"));
    }

    final NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(nodeIds);
    nodesInfoRequest.timeout(request.param("timeout"));
    // shortcut, dont do checks if only all is specified
    if (metrics.size() == 1 && metrics.contains("_all")) {
        nodesInfoRequest.all();
    } else {
        nodesInfoRequest.clear();
        nodesInfoRequest.settings(metrics.contains("settings"));
        nodesInfoRequest.os(metrics.contains("os"));
        nodesInfoRequest.process(metrics.contains("process"));
        nodesInfoRequest.jvm(metrics.contains("jvm"));
        nodesInfoRequest.threadPool(metrics.contains("thread_pool"));
        nodesInfoRequest.transport(metrics.contains("transport"));
        nodesInfoRequest.http(metrics.contains("http"));
        nodesInfoRequest.plugins(metrics.contains("plugins"));
    }

    settingsFilter.addFilterSettingParams(request);

    client.admin().cluster().nodesInfo(nodesInfoRequest, new RestBuilderListener<NodesInfoResponse>(channel) {

        @Override
        public RestResponse buildResponse(NodesInfoResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            response.toXContent(builder, request);
            builder.endObject();
            return new BytesRestResponse(RestStatus.OK, builder);
        }
    });
}
 
Example #21
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void nodesInfo(final NodesInfoRequest request, final ActionListener<NodesInfoResponse> listener) {
    execute(NodesInfoAction.INSTANCE, request, listener);
}
 
Example #22
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<NodesInfoResponse> nodesInfo(final NodesInfoRequest request) {
    return execute(NodesInfoAction.INSTANCE, request);
}
 
Example #23
Source File: SSLTest.java    From deprecated-security-ssl with Apache License 2.0 4 votes vote down vote up
@Test
public void testCustomPrincipalExtractor() throws Exception {
    
    enableHTTPClientSSL = true;
    trustHTTPServerCertificate = true;
    sendHTTPClientCertificate = true;
    
    final Settings settings = Settings.builder().put("opendistro_security.ssl.transport.enabled", true)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_KEYSTORE_ALIAS, "node-0")
            .put("opendistro_security.ssl.transport.keystore_filepath", getAbsoluteFilePathFromClassPath("node-0-keystore.jks"))
            .put("opendistro_security.ssl.transport.truststore_filepath", getAbsoluteFilePathFromClassPath("truststore.jks"))
            .put("opendistro_security.ssl.transport.enforce_hostname_verification", false)
            .put("opendistro_security.ssl.transport.resolve_hostname", false)
            .put("opendistro_security.ssl.transport.principal_extractor_class", "com.amazon.opendistroforelasticsearch.security.ssl.TestPrincipalExtractor")
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_KEYSTORE_ALIAS, "node-0")
            .put("opendistro_security.ssl.http.enabled", true)
            .put("opendistro_security.ssl.http.keystore_filepath", getAbsoluteFilePathFromClassPath("node-0-keystore.jks"))
            .put("opendistro_security.ssl.http.truststore_filepath", getAbsoluteFilePathFromClassPath("truststore.jks")).build();

    startES(settings);
    
    log.debug("Elasticsearch started");

    final Settings tcSettings = Settings.builder().put("cluster.name", clustername).put("path.home", ".").put(settings).build();

    try (TransportClient tc = new TransportClientImpl(tcSettings, asCollection(OpenDistroSecuritySSLPlugin.class))) {
        
        log.debug("TransportClient built, connect now to {}:{}", nodeHost, nodePort);
        
        tc.addTransportAddress(new TransportAddress(new InetSocketAddress(nodeHost, nodePort)));
        Assert.assertEquals(3, tc.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());            
        log.debug("TransportClient connected");
        TestPrincipalExtractor.reset();
        Assert.assertEquals("test", tc.index(new IndexRequest("test","test").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"a\":5}", XContentType.JSON)).actionGet().getIndex());            
        log.debug("Index created");           
        Assert.assertEquals(1L, tc.search(new SearchRequest("test")).actionGet().getHits().getTotalHits());
        log.debug("Search done");
        Assert.assertEquals(3, tc.admin().cluster().health(new ClusterHealthRequest("test")).actionGet().getNumberOfNodes());
        log.debug("ClusterHealth done");            
        Assert.assertEquals(3, tc.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());           
        log.debug("NodesInfoRequest asserted");
    }
    
    executeSimpleRequest("_opendistro/_security/sslinfo?pretty");
    
    //we need to test this in Security itself because in the SSL only plugin the info is not longer propagated
    //Assert.assertTrue(TestPrincipalExtractor.getTransportCount() > 0);
    Assert.assertTrue(TestPrincipalExtractor.getHttpCount() > 0);
}
 
Example #24
Source File: NodesInfoRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
public NodesInfoRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
    super(client, new NodesInfoRequest(), jsonToString, stringToJson);
}
 
Example #25
Source File: NodesInfoRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected ActionFuture<NodesInfoResponse> doExecute(NodesInfoRequest request) {
    return client.admin().cluster().nodesInfo(request);
}
 
Example #26
Source File: Requests.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a nodes info request against one or more nodes. Pass <tt>null</tt> or an empty array for all nodes.
 *
 * @param nodesIds The nodes ids to get the status for
 * @return The nodes info request
 * @see org.elasticsearch.client.ClusterAdminClient#nodesStats(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest)
 */
public static NodesInfoRequest nodesInfoRequest(String... nodesIds) {
    return new NodesInfoRequest(nodesIds);
}
 
Example #27
Source File: Requests.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a nodes info request against all the nodes.
 *
 * @return The nodes info request
 * @see org.elasticsearch.client.ClusterAdminClient#nodesInfo(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)
 */
public static NodesInfoRequest nodesInfoRequest() {
    return new NodesInfoRequest();
}
 
Example #28
Source File: ClusterAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Nodes info of the cluster.
 *
 * @param request  The nodes info request
 * @param listener A listener to be notified with a result
 * @see org.elasticsearch.client.Requests#nodesInfoRequest(String...)
 */
void nodesInfo(NodesInfoRequest request, ActionListener<NodesInfoResponse> listener);
 
Example #29
Source File: ClusterAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Nodes info of the cluster.
 *
 * @param request The nodes info request
 * @return The result future
 * @see org.elasticsearch.client.Requests#nodesInfoRequest(String...)
 */
ActionFuture<NodesInfoResponse> nodesInfo(NodesInfoRequest request);