From 22f99e848f657a040b12b3b70948e683d5c6701c Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 6 Dec 2012 15:22:44 +0100 Subject: [PATCH] Expose es version in node info api. Closes #2466 --- .../admin/cluster/node/info/NodeInfo.java | 21 ++++++++++++++++++- .../cluster/node/info/NodesInfoResponse.java | 4 ++++ .../node/service/NodeService.java | 8 +++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java index b2e81f26950..8861eeec3a9 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java @@ -49,6 +49,8 @@ public class NodeInfo extends NodeOperationResponse { @Nullable private String hostname; + private String version; + @Nullable private Settings settings; @@ -76,11 +78,12 @@ public class NodeInfo extends NodeOperationResponse { NodeInfo() { } - public NodeInfo(@Nullable String hostname, DiscoveryNode node, @Nullable ImmutableMap serviceAttributes, @Nullable Settings settings, + public NodeInfo(@Nullable String hostname, String version, DiscoveryNode node, @Nullable ImmutableMap serviceAttributes, @Nullable Settings settings, @Nullable OsInfo os, @Nullable ProcessInfo process, @Nullable JvmInfo jvm, @Nullable ThreadPoolInfo threadPool, @Nullable NetworkInfo network, @Nullable TransportInfo transport, @Nullable HttpInfo http) { super(node); this.hostname = hostname; + this.version = version; this.serviceAttributes = serviceAttributes; this.settings = settings; this.os = os; @@ -108,6 +111,20 @@ public class NodeInfo extends NodeOperationResponse { return hostname(); } + /** + * The current ES version + */ + public String version() { + return version; + } + + /** + * The current ES version + */ + public String getVersion() { + return version(); + } + /** * The service attributes of the node. */ @@ -246,6 +263,7 @@ public class NodeInfo extends NodeOperationResponse { if (in.readBoolean()) { hostname = in.readUTF(); } + version = in.readOptionalString(); if (in.readBoolean()) { ImmutableMap.Builder builder = ImmutableMap.builder(); int size = in.readVInt(); @@ -289,6 +307,7 @@ public class NodeInfo extends NodeOperationResponse { out.writeBoolean(true); out.writeUTF(hostname); } + out.writeOptionalString(version); if (serviceAttributes() == null) { out.writeBoolean(false); } else { diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoResponse.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoResponse.java index 86d3d42a5e5..b51b67fc3da 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoResponse.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoResponse.java @@ -83,6 +83,10 @@ public class NodesInfoResponse extends NodesOperationResponse implemen builder.field("hostname", nodeInfo.hostname(), XContentBuilder.FieldCaseConversion.NONE); } + if (nodeInfo.version() != null) { + builder.field("version", nodeInfo.version()); + } + if (nodeInfo.serviceAttributes() != null) { for (Map.Entry nodeAttribute : nodeInfo.serviceAttributes().entrySet()) { builder.field(nodeAttribute.getKey(), nodeAttribute.getValue()); diff --git a/src/main/java/org/elasticsearch/node/service/NodeService.java b/src/main/java/org/elasticsearch/node/service/NodeService.java index f119cf2b936..348abe481f8 100644 --- a/src/main/java/org/elasticsearch/node/service/NodeService.java +++ b/src/main/java/org/elasticsearch/node/service/NodeService.java @@ -20,6 +20,7 @@ package org.elasticsearch.node.service; import com.google.common.collect.ImmutableMap; +import org.elasticsearch.Version; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.cluster.ClusterService; @@ -60,6 +61,8 @@ public class NodeService extends AbstractComponent { @Nullable private String hostname; + private final String version; + @Inject public NodeService(Settings settings, ThreadPool threadPool, MonitorService monitorService, Discovery discovery, ClusterService clusterService, TransportService transportService, IndicesService indicesService) { super(settings); @@ -73,6 +76,7 @@ public class NodeService extends AbstractComponent { if (address != null) { this.hostname = address.getHostName(); } + this.version = Version.CURRENT.toString(); } public void setHttpServer(@Nullable HttpServer httpServer) { @@ -105,7 +109,7 @@ public class NodeService extends AbstractComponent { } public NodeInfo info() { - return new NodeInfo(hostname, clusterService.state().nodes().localNode(), serviceAttributes, + return new NodeInfo(hostname, version, clusterService.state().nodes().localNode(), serviceAttributes, settings, monitorService.osService().info(), monitorService.processService().info(), @@ -118,7 +122,7 @@ public class NodeService extends AbstractComponent { } public NodeInfo info(boolean settings, boolean os, boolean process, boolean jvm, boolean threadPool, boolean network, boolean transport, boolean http) { - return new NodeInfo(hostname, clusterService.state().nodes().localNode(), serviceAttributes, + return new NodeInfo(hostname, version, clusterService.state().nodes().localNode(), serviceAttributes, settings ? this.settings : null, os ? monitorService.osService().info() : null, process ? monitorService.processService().info() : null,