Refine search
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject("nodes"); for (NodeInfo nodeInfo : getNodes()) { builder.startObject(nodeInfo.getNode().getId()); builder.field("name", nodeInfo.getNode().getName()); builder.field("transport_address", nodeInfo.getNode().getAddress().toString()); builder.field("host", nodeInfo.getNode().getHostName()); builder.field("ip", nodeInfo.getNode().getHostAddress()); builder.field("version", nodeInfo.getVersion()); builder.field("build_flavor", nodeInfo.getBuild().flavor().displayName()); builder.field("build_type", nodeInfo.getBuild().type().displayName()); builder.field("build_hash", nodeInfo.getBuild().shortHash()); if (nodeInfo.getTotalIndexingBuffer() != null) { builder.humanReadableField("total_indexing_buffer", "total_indexing_buffer_in_bytes", nodeInfo.getTotalIndexingBuffer()); for (DiscoveryNode.Role role : nodeInfo.getNode().getRoles()) { builder.value(role.getRoleName()); if (!nodeInfo.getNode().getAttributes().isEmpty()) { builder.startObject("attributes"); for (Map.Entry<String, String> entry : nodeInfo.getNode().getAttributes().entrySet()) { builder.field(entry.getKey(), entry.getValue()); if (nodeInfo.getSettings() != null) { builder.startObject("settings"); Settings settings = nodeInfo.getSettings(); settings.toXContent(builder, params);
private static void issueWarnings(Client tc) { NodesInfoResponse nir = tc.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet(); Version maxVersion = nir.getNodes().stream().max((n1,n2) -> n1.getVersion().compareTo(n2.getVersion())).get().getVersion(); Version minVersion = nir.getNodes().stream().min((n1,n2) -> n1.getVersion().compareTo(n2.getVersion())).get().getVersion(); if(!maxVersion.equals(minVersion)) { System.out.println("WARNING: Your cluster consists of different node versions. It is not recommended to run sgadmin against a mixed cluster. This may fail."); System.out.println(" Minimum node version is "+minVersion.toString()); System.out.println(" Maximum node version is "+maxVersion.toString()); } else { System.out.println("Elasticsearch Version: "+minVersion.toString()); } if(nir.getNodes().size() > 0) { List<PluginInfo> pluginInfos = nir.getNodes().get(0).getPlugins().getPluginInfos(); String sgVersion = pluginInfos.stream().filter(p->p.getClassname().equals("com.floragunn.searchguard.SearchGuardPlugin")).map(p->p.getVersion()).findFirst().orElse("<unknown>"); System.out.println("Search Guard Version: "+sgVersion); } } }
final List<NodeInfo> dataNodes = nodes.stream().filter(n->n.getNode().getRoles().contains(Role.DATA) && !n.getNode().getRoles().contains(Role.MASTER)).collect(Collectors.toList()); final List<NodeInfo> clientNodes = nodes.stream().filter(n->!n.getNode().getRoles().contains(Role.MASTER) && !n.getNode().getRoles().contains(Role.DATA)).collect(Collectors.toList()); if (nodeInfo.getHttp() != null && nodeInfo.getHttp().address() != null) { final TransportAddress his = nodeInfo.getHttp().address() .publishAddress(); clusterInfo.httpPort = his.getPort(); final TransportAddress is = nodeInfo.getTransport().getAddress() .publishAddress(); clusterInfo.nodePort = is.getPort(); final TransportAddress is = nodeInfo.getTransport().getAddress() .publishAddress(); clusterInfo.nodePort = is.getPort(); clusterInfo.nodeHost = is.getAddress(); if (nodeInfo.getHttp() != null && nodeInfo.getHttp().address() != null) { final TransportAddress his = nodeInfo.getHttp().address() .publishAddress(); clusterInfo.httpPort = his.getPort(); final TransportAddress is = nodeInfo.getTransport().getAddress() .publishAddress(); clusterInfo.nodePort = is.getPort(); clusterInfo.nodeHost = is.getAddress(); if (nodeInfo.getHttp() != null && nodeInfo.getHttp().address() != null) { final TransportAddress his = nodeInfo.getHttp().address()
@Override public void onResponse(NodesInfoResponse nodeInfos) { try { Map<DiscoveryNode, IngestInfo> ingestInfos = new HashMap<>(); for (NodeInfo nodeInfo : nodeInfos.getNodes()) { ingestInfos.put(nodeInfo.getNode(), nodeInfo.getIngest()); } ingestService.putPipeline(ingestInfos, request, listener); } catch (Exception e) { onFailure(e); } }
NodeInfo info = nodesInfo.getNodesMap().get(node.getId()); NodeStats stats = nodesStats.getNodesMap().get(node.getId()); JvmInfo jvmInfo = info == null ? null : info.getJvm(); JvmStats jvmStats = stats == null ? null : stats.getJvm(); FsInfo fsInfo = stats == null ? null : stats.getFs(); OsStats osStats = stats == null ? null : stats.getOs(); ProcessStats processStats = stats == null ? null : stats.getProcess(); NodeIndicesStats indicesStats = stats == null ? null : stats.getIndices(); table.addCell(fullId ? node.getId() : Strings.substring(node.getId(), 0, 4)); table.addCell(info == null ? null : info.getProcess().getId()); table.addCell(node.getHostAddress()); table.addCell(node.getAddress().address().getPort()); final HttpInfo httpInfo = info == null ? null : info.getHttp(); if (httpInfo != null) { TransportAddress transportAddress = httpInfo.getAddress().publishAddress(); table.addCell(node.getVersion().toString()); table.addCell(info == null ? null : info.getBuild().flavor().displayName()); table.addCell(info == null ? null : info.getBuild().type().displayName()); table.addCell(info == null ? null : info.getBuild().shortHash()); table.addCell(jvmInfo == null ? null : jvmInfo.version());
for (final ThreadPoolStats.Stats threadPoolStats : nodeStats.getThreadPool()) { candidates.add(threadPoolStats.getName()); final NodeInfo info = nodesInfo.getNodesMap().get(node.getId()); final NodeStats stats = nodesStats.getNodesMap().get(node.getId()); poolThreadInfo = new HashMap<>(); ThreadPoolStats threadPoolStats = stats.getThreadPool(); for (ThreadPoolStats.Stats threadPoolStat : threadPoolStats) { poolThreadStats.put(threadPoolStat.getName(), threadPoolStat); for (ThreadPool.Info threadPoolInfo : info.getThreadPool()) { poolThreadInfo.put(threadPoolInfo.getName(), threadPoolInfo); table.addCell(node.getName()); table.addCell(node.getId()); table.addCell(node.getEphemeralId()); table.addCell(info == null ? null : info.getProcess().getId()); table.addCell(node.getHostName()); table.addCell(node.getHostAddress());
private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo) { 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.getId()); for (Map.Entry<String, String> attrEntry : node.getAttributes().entrySet()) { table.startRow(); table.addCell(node.getName()); table.addCell(fullId ? node.getId() : Strings.substring(node.getId(), 0, 4)); table.addCell(info == null ? null : info.getProcess().getId()); table.addCell(node.getHostName()); table.addCell(node.getHostAddress()); table.addCell(node.getAddress().address().getPort()); table.addCell(attrEntry.getKey()); table.addCell(attrEntry.getValue()); table.endRow(); } } return table; } }
NodeInfo info = nodesInfo.getNodesMap().get(node.id()); NodeStats stats = nodesStats.getNodesMap().get(node.id()); JvmInfo jvmInfo = info == null ? null : info.getJvm(); JvmStats jvmStats = stats == null ? null : stats.getJvm(); FsInfo fsInfo = stats == null ? null : stats.getFs(); OsStats osStats = stats == null ? null : stats.getOs(); ProcessStats processStats = stats == null ? null : stats.getProcess(); NodeIndicesStats indicesStats = stats == null ? null : stats.getIndices(); 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()); table.addCell(node.getVersion().number()); table.addCell(info == null ? null : info.getBuild().hashShort()); table.addCell(jvmInfo == null ? null : jvmInfo.version()); table.addCell(fsInfo == null ? null : fsInfo.getTotal().getAvailable());
builder.startObject(nodeInfo.getNode().id(), XContentBuilder.FieldCaseConversion.NONE); builder.field("name", nodeInfo.getNode().name(), XContentBuilder.FieldCaseConversion.NONE); builder.field("transport_address", nodeInfo.getNode().address().toString()); builder.field("host", nodeInfo.getNode().getHostName(), XContentBuilder.FieldCaseConversion.NONE); builder.field("ip", nodeInfo.getNode().getHostAddress(), XContentBuilder.FieldCaseConversion.NONE); builder.field("version", nodeInfo.getVersion()); builder.field("build", nodeInfo.getBuild().hashShort()); if (nodeInfo.getServiceAttributes() != null) { for (Map.Entry<String, String> nodeAttribute : nodeInfo.getServiceAttributes().entrySet()) { builder.field(nodeAttribute.getKey(), nodeAttribute.getValue(), XContentBuilder.FieldCaseConversion.NONE); if (!nodeInfo.getNode().attributes().isEmpty()) { builder.startObject("attributes"); for (Map.Entry<String, String> attr : nodeInfo.getNode().attributes().entrySet()) { builder.field(attr.getKey(), attr.getValue(), XContentBuilder.FieldCaseConversion.NONE); if (nodeInfo.getSettings() != null) { builder.startObject("settings"); Settings settings = nodeInfo.getSettings(); settings.toXContent(builder, params); builder.endObject(); if (nodeInfo.getOs() != null) { nodeInfo.getOs().toXContent(builder, params); if (nodeInfo.getProcess() != null) {
private Map<String, String> getNodesInfos(NodesInfoResponse nodesInfoResponse) { Map<String, String> nodeInfoMap = new HashMap<>(); for (NodeInfo nodeInfo : nodesInfoResponse.getNodes()) { try (XContentBuilder builder = XContentFactory.jsonBuilder()) { builder.humanReadable(true).prettyPrint(); builder.startObject(); nodeInfo.getSettings().toXContent(builder, ToXContent.EMPTY_PARAMS); nodeInfo.getOs().toXContent(builder, ToXContent.EMPTY_PARAMS); nodeInfo.getProcess().toXContent(builder, ToXContent.EMPTY_PARAMS); nodeInfo.getJvm().toXContent(builder, ToXContent.EMPTY_PARAMS); nodeInfo.getThreadPool().toXContent(builder, ToXContent.EMPTY_PARAMS); nodeInfo.getTransport().toXContent(builder, ToXContent.EMPTY_PARAMS); nodeInfo.getPlugins().toXContent(builder, ToXContent.EMPTY_PARAMS); nodeInfo.getIngest().toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); nodeInfoMap.put(nodeInfo.getNode().getName(), builder.string()); } catch (IOException e) { Exceptions.handle(e); } } return nodeInfoMap; }
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.getId()); for (PluginInfo pluginInfo : info.getPlugins().getPluginInfos()) { table.startRow(); table.addCell(node.getId()); table.addCell(node.getName()); table.addCell(pluginInfo.getName()); table.addCell(pluginInfo.getVersion()); table.addCell(pluginInfo.getDescription()); table.endRow(); } } return table; } }
private boolean checkPluginInstalled(Client client) { NodesInfoResponse nodesInfoResponse = client.admin().cluster().prepareNodesInfo().setPlugins(true).get(); for (NodeInfo nodeInfo : nodesInfoResponse.getNodes()) { for (PluginInfo pluginInfo : nodeInfo.getPlugins().getInfos()) { if ("Vertexium".equals(pluginInfo.getName())) { return true; } } } LOGGER.warn("Running without the server side Vertexium plugin will be deprecated in the future."); return false; }
ClusterStatsNodes(List<ClusterStatsNodeResponse> nodeResponses) { this.versions = new HashSet<>(); this.fs = new FsInfo.Path(); this.plugins = new HashSet<>(); Set<InetAddress> seenAddresses = new HashSet<>(nodeResponses.size()); List<NodeInfo> nodeInfos = new ArrayList<>(nodeResponses.size()); List<NodeStats> nodeStats = new ArrayList<>(nodeResponses.size()); for (ClusterStatsNodeResponse nodeResponse : nodeResponses) { nodeInfos.add(nodeResponse.nodeInfo()); nodeStats.add(nodeResponse.nodeStats()); this.versions.add(nodeResponse.nodeInfo().getVersion()); this.plugins.addAll(nodeResponse.nodeInfo().getPlugins().getPluginInfos()); // now do the stats that should be deduped by hardware (implemented by ip deduping) TransportAddress publishAddress = nodeResponse.nodeInfo().getTransport().address().publishAddress(); final InetAddress inetAddress = publishAddress.address().getAddress(); if (!seenAddresses.add(inetAddress)) { continue; } if (nodeResponse.nodeStats().getFs() != null) { this.fs.add(nodeResponse.nodeStats().getFs().getTotal()); } } this.counts = new Counts(nodeInfos); this.os = new OsStats(nodeInfos, nodeStats); this.process = new ProcessStats(nodeStats); this.jvm = new JvmStats(nodeInfos, nodeStats); this.networkTypes = new NetworkTypes(nodeInfos); }
NodeInfo info = nodesInfo.getNodesMap().get(node.id()); NodeStats stats = nodesStats.getNodesMap().get(node.id()); table.startRow(); 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()); poolThreadInfo = new HashMap<>(14); ThreadPoolStats threadPoolStats = stats.getThreadPool(); for (ThreadPoolStats.Stats threadPoolStat : threadPoolStats) { poolThreadStats.put(threadPoolStat.getName(), threadPoolStat); for (ThreadPool.Info threadPoolInfo : info.getThreadPool()) { poolThreadInfo.put(threadPoolInfo.getName(), threadPoolInfo);
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; } }
/** * Returns information about a cluster. * @return a map of key value pairs containing cluster information */ public static Map<String, String> getSearchClusterInfo() { Map<String, String> md = new HashMap<String, String>(); NodesInfoResponse res = getClient().admin().cluster().nodesInfo(new NodesInfoRequest().all()).actionGet(); md.put("cluser.name", res.getClusterName().toString()); for (NodeInfo nodeInfo : res) { md.put("node.name", nodeInfo.getNode().getName()); md.put("node.address", nodeInfo.getNode().getAddress().toString()); md.put("node.data", Boolean.toString(nodeInfo.getNode().isDataNode())); md.put("node.client", Boolean.toString(nodeInfo.getNode().isClientNode())); md.put("node.version", nodeInfo.getNode().getVersion().toString()); } return md; }
client.addTransportAddresses(transportAddresses); NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get(); httpAddresses = new InetSocketAddress[nodeInfos.getNodes().size()]; this.clusterName = nodeInfos.getClusterName().value(); int dataNodes = 0; int masterAndDataNodes = 0; for (int i = 0; i < nodeInfos.getNodes().size(); i++) { NodeInfo nodeInfo = nodeInfos.getNodes().get(i); httpAddresses[i] = nodeInfo.getHttp().address().publishAddress().address(); if (DiscoveryNode.isDataNode(nodeInfo.getSettings())) { dataNodes++; masterAndDataNodes++; } else if (DiscoveryNode.isMasterNode(nodeInfo.getSettings())) { masterAndDataNodes++;
/** * 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]; }
@Override public void handleResponse(NodesInfoResponse response) { Collection<TransportAddress> httpAddresses = new HashSet<>(); for (NodeInfo info : response.getNodes()) { if (connectedNodes.contains(info.getNode()) && info.getHttp() != null) { httpAddresses.add(info.getHttp().getAddress().publishAddress()); } } if (httpAddresses.size() < maxNumRemoteConnections) { // just in case non of the connected nodes have http enabled we get other http enabled nodes instead. for (NodeInfo info : response.getNodes()) { if (nodePredicate.test(info.getNode()) && info.getHttp() != null) { httpAddresses.add(info.getHttp().getAddress().publishAddress()); } if (httpAddresses.size() == maxNumRemoteConnections) { break; // once we have enough return... } } } RemoteConnectionInfo remoteConnectionInfo = new RemoteConnectionInfo(clusterAlias, seedNodes.stream().map(n -> n.getAddress()).collect(Collectors.toList()), new ArrayList<>(httpAddresses), maxNumRemoteConnections, connectedNodes.size(), RemoteClusterService.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settings)); listener.onResponse(remoteConnectionInfo); }
for(NodeInfo ni: nir.getNodes()) { Settings nodeSettings = ni.getSettings();