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

The following examples show how to use org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse. 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: CustomRealmIT.java    From shield-custom-realm-example with Apache License 2.0 6 votes vote down vote up
public void testTransportClient() throws Exception {
    NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get();
    List<NodeInfo>  nodes = nodeInfos.getNodes();
    assertTrue(nodes.size() > 0);
    TransportAddress publishAddress = randomFrom(nodes).getTransport().address().publishAddress();
    String clusterName = nodeInfos.getClusterName().value();

    Settings settings = Settings.builder()
            .put("cluster.name", clusterName)
            .put(ThreadContext.PREFIX + "." + CustomRealm.USER_HEADER, randomFrom(KNOWN_USERS))
            .put(ThreadContext.PREFIX + "." + CustomRealm.PW_HEADER, PASSWORD)
            .build();
    try (TransportClient client = new PreBuiltXPackTransportClient(settings)) {
        client.addTransportAddress(publishAddress);
        ClusterHealthResponse response = client.admin().cluster().prepareHealth().execute().actionGet();
        assertThat(response.isTimedOut(), is(false));
    }
}
 
Example #2
Source File: SirenJoinPluginTest.java    From siren-join with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testPluginLoaded() {
  NodesInfoResponse nodesInfoResponse = client().admin().cluster().prepareNodesInfo().clear().setPlugins(true).get();
  assertTrue(nodesInfoResponse.getNodes().length != 0);
  assertThat(nodesInfoResponse.getNodes()[0].getPlugins().getPluginInfos(), notNullValue());
  assertThat(nodesInfoResponse.getNodes()[0].getPlugins().getPluginInfos().size(), not(0));

  boolean pluginFound = false;

  for (PluginInfo pluginInfo : nodesInfoResponse.getNodes()[0].getPlugins().getPluginInfos()) {
    if (pluginInfo.getName().equals("SirenJoinPlugin")) {
      pluginFound = true;
      break;
    }
  }

  assertThat(pluginFound, is(true));
}
 
Example #3
Source File: Elasticsearch5SearchIndex.java    From vertexium with Apache License 2.0 6 votes vote down vote up
private boolean checkPluginInstalled(Client client) {
    if (config.isForceDisableVertexiumPlugin()) {
        LOGGER.info("Forcing the vertexium plugin off. Running without the server side Vertexium plugin will disable some features.");
        return false;
    }

    NodesInfoResponse nodesInfoResponse = client.admin().cluster().prepareNodesInfo().setPlugins(true).get();
    for (NodeInfo nodeInfo : nodesInfoResponse.getNodes()) {
        for (PluginInfo pluginInfo : nodeInfo.getPlugins().getPluginInfos()) {
            if ("vertexium".equals(pluginInfo.getName())) {
                return true;
            }
        }
    }
    if (config.isErrorOnMissingVertexiumPlugin()) {
        throw new VertexiumException("Vertexium plugin cannot be found");
    }
    LOGGER.warn("Running without the server side Vertexium plugin will disable some features.");
    return false;
}
 
Example #4
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 #5
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 #6
Source File: AbstractUnitTest.java    From elasticsearch-shield-kerberos-realm with Apache License 2.0 5 votes vote down vote up
public final void startES(final Settings settings) throws Exception {
    FileUtils.copyFileToDirectory(getAbsoluteFilePathFromClassPath("roles.yml").toFile(), new File("testtmp/config/shield"));

    final Set<Integer> ports = new HashSet<>();
    do {
        ports.add(NetworkUtil.getServerPort());
    } while (ports.size() < 7);

    final Iterator<Integer> portIt = ports.iterator();

    elasticsearchHttpPort1 = portIt.next();
    elasticsearchHttpPort2 = portIt.next();
    elasticsearchHttpPort3 = portIt.next();

    //elasticsearchNodePort1 = portIt.next();
    //elasticsearchNodePort2 = portIt.next();
    //elasticsearchNodePort3 = portIt.next();

    esNode1 = new PluginEnabledNode(getDefaultSettingsBuilder(1, 0, elasticsearchHttpPort1, false, true).put(
            settings == null ? Settings.Builder.EMPTY_SETTINGS : settings).build(), Lists.newArrayList(ShieldPlugin.class, LicensePlugin.class, KerberosRealmPlugin.class)).start();
    client = esNode1.client();
    
    esNode2 = new PluginEnabledNode(getDefaultSettingsBuilder(2, 0, elasticsearchHttpPort2, true, true).put(
            settings == null ? Settings.Builder.EMPTY_SETTINGS : settings).build(), Lists.newArrayList(ShieldPlugin.class, LicensePlugin.class, KerberosRealmPlugin.class)).start();
    
    esNode3 = new PluginEnabledNode(getDefaultSettingsBuilder(3, 0, elasticsearchHttpPort3, true, false).put(
            settings == null ? Settings.Builder.EMPTY_SETTINGS : settings).build(), Lists.newArrayList(ShieldPlugin.class, LicensePlugin.class, KerberosRealmPlugin.class)).start();
    
    waitForGreenClusterState();
    final NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get();
    final NodeInfo[] nodes = nodeInfos.getNodes();
    Assert.assertEquals(nodes + "", 3, nodes.length);
}
 
Example #7
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 #8
Source File: XmlPluginTest.java    From elasticsearch-xml with Apache License 2.0 5 votes vote down vote up
public static InetSocketTransportAddress findHttpAddress(Client client) {
    NodesInfoRequestBuilder nodesInfoRequestBuilder = new NodesInfoRequestBuilder(client, NodesInfoAction.INSTANCE);
    nodesInfoRequestBuilder.setHttp(true).setTransport(false);
    NodesInfoResponse response = nodesInfoRequestBuilder.execute().actionGet();
    Object obj = response.iterator().next().getHttp().getAddress().publishAddress();
    if (obj instanceof InetSocketTransportAddress) {
        return (InetSocketTransportAddress) obj;
    }
    return null;
}
 
Example #9
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 #10
Source File: VietnameseAnalysisIntegrationTest.java    From elasticsearch-analysis-vietnamese with Apache License 2.0 5 votes vote down vote up
public void testPluginIsLoaded() throws Exception {
    NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().setPlugins(true).get();
    for (NodeInfo nodeInfo : response.getNodes()) {
        boolean pluginFound = false;
        for (PluginInfo pluginInfo : nodeInfo.getPlugins().getPluginInfos()) {
            if (pluginInfo.getName().equals(AnalysisVietnamesePlugin.class.getName())) {
                pluginFound = true;
                break;
            }
        }
        assertThat(pluginFound, is(true));
    }
}
 
Example #11
Source File: SimpleTests.java    From elasticsearch-topk-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void assertPluginLoaded() {
    NodesInfoResponse nodesInfoResponse = client.admin().cluster().prepareNodesInfo().clear().setPlugins(true).get();
    logger.info("{}", nodesInfoResponse);
    assertEquals(nodesInfoResponse.getNodes().length, 2);
    assertNotNull(nodesInfoResponse.getNodes()[0].getPlugins().getInfos());
    assertEquals(nodesInfoResponse.getNodes()[0].getPlugins().getInfos().size(), 1);
    assertEquals(nodesInfoResponse.getNodes()[0].getPlugins().getInfos().get(0).getName(), "topk-aggregation");
    assertEquals(nodesInfoResponse.getNodes()[0].getPlugins().getInfos().get(0).isSite(), false);
}
 
Example #12
Source File: KerberosRealmEmbeddedTests.java    From elasticsearch-shield-kerberos-realm with Apache License 2.0 5 votes vote down vote up
@Test
public void testTransportClientMultiRound() throws Exception {

    //Mock mode, no kerberos involved

    embeddedKrbServer.getSimpleKdcServer().stop();

    final Settings esServerSettings = Settings.builder().put(PREFIX + SettingConstants.ACCEPTOR_KEYTAB_PATH, "mock")
            .put(PREFIX + SettingConstants.ACCEPTOR_PRINCIPAL, "mock").put(PREFIX + "mock_mode", true)
            .putArray(PREFIX + SettingConstants.ROLES+".cc_kerberos_realm_role", "spock/[email protected]","mock_principal")
            .build();

    this.startES(esServerSettings);

    final NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get();
    final NodeInfo[] nodes = nodeInfos.getNodes();
    assertTrue(nodes.length > 2);

    final Settings settings = Settings.builder().put("cluster.name", clustername)
            .putArray("plugin.types", ShieldPlugin.class.getName()).build();

    try (TransportClient client = TransportClient.builder().settings(settings).build()) {
        client.addTransportAddress(nodes[0].getTransport().address().publishAddress());
        try (KerberizedClient kc = new MockingKerberizedClient(client)) {

            ClusterHealthResponse response = kc.admin().cluster().prepareHealth().execute().actionGet();
            assertThat(response.isTimedOut(), is(false));

            response = kc.admin().cluster().prepareHealth().execute().actionGet();
            assertThat(response.isTimedOut(), is(false));

            response = kc.admin().cluster().prepareHealth().execute().actionGet();
            assertThat(response.isTimedOut(), is(false));
            assertThat(response.status(), is(RestStatus.OK));
            assertThat(response.getStatus(), is(ClusterHealthStatus.GREEN));
        }
    }
}
 
Example #13
Source File: EmbeddedElasticsearchNode.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Returns current address to connect to with HTTP client.
 * @return hostname/port for HTTP connection
 */
public TransportAddress httpAddress() {
  Preconditions.checkState(isStarted, "node is not started");

  NodesInfoResponse response =  client().admin().cluster().prepareNodesInfo()
      .execute().actionGet();
  if (response.getNodes().size() != 1) {
    throw new IllegalStateException("Expected single node but got "
        + response.getNodes().size());
  }
  NodeInfo node = response.getNodes().get(0);
  return node.getHttp().address().boundAddresses()[0];
}
 
Example #14
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 #15
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 #16
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 #17
Source File: DecompoundQueryTests.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 5 votes vote down vote up
public void testPluginIsLoaded() {
    NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().setPlugins(true).get();
    for (NodeInfo nodeInfo : response.getNodes()) {
        boolean pluginFound = false;
        for (PluginInfo pluginInfo : nodeInfo.getPlugins().getPluginInfos()) {
            if (pluginInfo.getName().equals(BundlePlugin.class.getName())) {
                pluginFound = true;
                break;
            }
        }
        assertThat(pluginFound, is(true));
    }
}
 
Example #18
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 #19
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 #20
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 #21
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 #22
Source File: RestNodeAttrsAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) {
    boolean fullId = req.paramAsBoolean("full_id", false);

    DiscoveryNodes nodes = state.getState().nodes();
    Table table = getTableWithHeader(req);

    for (DiscoveryNode node : nodes) {
        NodeInfo info = nodesInfo.getNodesMap().get(node.id());
        ImmutableMap<String, String> attrs = node.getAttributes();
        for(String att : attrs.keySet()) {
            table.startRow();
            table.addCell(node.name());
            table.addCell(fullId ? node.id() : Strings.substring(node.getId(), 0, 4));
            table.addCell(info == null ? null : info.getProcess().getId());
            table.addCell(node.getHostName());
            table.addCell(node.getHostAddress());
            if (node.address() instanceof InetSocketTransportAddress) {
                table.addCell(((InetSocketTransportAddress) node.address()).address().getPort());
            } else {
                table.addCell("-");
            }
            table.addCell(att);
            table.addCell(attrs.containsKey(att) ? attrs.get(att) : null);
            table.endRow();
        }
    }

    return table;
}
 
Example #23
Source File: EmbeddedElasticsearchNode.java    From Quicksql with MIT License 5 votes vote down vote up
/**
 * Returns current address to connect to with HTTP client.
 *
 * @return hostname/port for HTTP connection
 */
public TransportAddress httpAddress() {
    Preconditions.checkState(isStarted, "node is not started");

    NodesInfoResponse response = client().admin().cluster().prepareNodesInfo()
        .execute().actionGet();
    if (response.getNodes().size() != 1) {
        throw new IllegalStateException("Expected single node but got "
            + response.getNodes().size());
    }
    NodeInfo node = response.getNodes().get(0);
    return node.getHttp().address().boundAddresses()[0];
}
 
Example #24
Source File: AnalysisOpenKoreanTextPluginTest.java    From elasticsearch-analysis-openkoreantext with Apache License 2.0 5 votes vote down vote up
public void testPluginIsLoaded() {
    NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().setPlugins(true).get();
    for (NodeInfo node : response.getNodes()) {
        boolean founded = false;
        for (PluginInfo pluginInfo : node.getPlugins().getPluginInfos()) {
            if (pluginInfo.getName().equals(AnalysisOpenKoreanTextPlugin.class.getName())) {
                founded = true;
            }
        }
        Assert.assertTrue(founded);
    }
}
 
Example #25
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 #26
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 #27
Source File: RestPluginsAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo) {
    DiscoveryNodes nodes = state.getState().nodes();
    Table table = getTableWithHeader(req);

    for (DiscoveryNode node : nodes) {
        NodeInfo info = nodesInfo.getNodesMap().get(node.id());

        for (PluginInfo pluginInfo : info.getPlugins().getPluginInfos()) {
            table.startRow();
            table.addCell(node.id());
            table.addCell(node.name());
            table.addCell(pluginInfo.getName());
            table.addCell(pluginInfo.getVersion());
            String type;
            if (pluginInfo.isSite()) {
                if (pluginInfo.isJvm()) {
                    type = "j/s";
                } else {
                    type = "s";
                }
            } else {
                if (pluginInfo.isJvm()) {
                    type = "j";
                } else {
                    type = "";
                }
            }
            table.addCell(type);
            table.addCell(pluginInfo.getUrl());
            table.addCell(pluginInfo.getDescription());
            table.endRow();
        }
    }

    return table;
}
 
Example #28
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 #29
Source File: CustomRealmIT.java    From shield-custom-realm-example with Apache License 2.0 5 votes vote down vote up
public void testTransportClientWrongAuthentication() throws Exception {
    NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get();
    List<NodeInfo> nodes = nodeInfos.getNodes();
    assertTrue(nodes.size() > 0);
    TransportAddress publishAddress = randomFrom(nodes).getTransport().address().publishAddress();
    String clusterName = nodeInfos.getClusterName().value();

    Settings settings;
    if (randomBoolean()) {
        settings = Settings.builder()
                .put("cluster.name", clusterName)
                .put(ThreadContext.PREFIX + "." + CustomRealm.USER_HEADER, randomFrom(KNOWN_USERS) + randomAlphaOfLength(1))
                .put(ThreadContext.PREFIX + "." + CustomRealm.PW_HEADER, PASSWORD)
                .build();
    } else {
        settings = Settings.builder()
                .put("cluster.name", clusterName)
                .put(ThreadContext.PREFIX + "." + CustomRealm.USER_HEADER, randomFrom(KNOWN_USERS))
                .put(ThreadContext.PREFIX + "." + CustomRealm.PW_HEADER, randomAlphaOfLengthBetween(16, 32))
                .build();
    }

    try (TransportClient client = new PreBuiltXPackTransportClient(settings)) {
        client.addTransportAddress(publishAddress);
        client.admin().cluster().prepareHealth().execute().actionGet();
        fail("authentication failure should have resulted in a NoNodesAvailableException");
    } catch (NoNodeAvailableException e) {
        // expected
    }
}
 
Example #30
Source File: EmbeddedElasticsearchNode.java    From Quicksql with MIT License 5 votes vote down vote up
/**
 * Returns current address to connect to with HTTP client.
 * @return hostname/port for HTTP connection
 */
public TransportAddress httpAddress() {
  Preconditions.checkState(isStarted, "node is not started");

  NodesInfoResponse response =  client().admin().cluster().prepareNodesInfo()
      .execute().actionGet();
  if (response.getNodes().size() != 1) {
    throw new IllegalStateException("Expected single node but got "
        + response.getNodes().size());
  }
  NodeInfo node = response.getNodes().get(0);
  return node.getHttp().address().boundAddresses()[0];
}