diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java index 084c05f6e30..c3db80ef3cb 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java @@ -19,22 +19,45 @@ package org.elasticsearch.action.admin.cluster.node.info; +import com.google.common.collect.ImmutableMap; import org.elasticsearch.action.support.nodes.NodeOperationResponse; import org.elasticsearch.cluster.node.Node; +import org.elasticsearch.util.settings.ImmutableSettings; +import org.elasticsearch.util.settings.Settings; import java.io.DataInput; +import java.io.DataOutput; import java.io.IOException; +import java.util.Map; /** * @author kimchy (Shay Banon) */ public class NodeInfo extends NodeOperationResponse { - protected NodeInfo() { + private ImmutableMap attributes; + + private Settings settings; + + NodeInfo() { } - public NodeInfo(Node node) { + public NodeInfo(Node node, Map attributes, Settings settings) { + this(node, ImmutableMap.copyOf(attributes), settings); + } + + public NodeInfo(Node node, ImmutableMap attributes, Settings settings) { super(node); + this.attributes = attributes; + this.settings = settings; + } + + public ImmutableMap attributes() { + return this.attributes; + } + + public Settings settings() { + return this.settings; } public static NodeInfo readNodeInfo(DataInput in) throws ClassNotFoundException, IOException { @@ -42,4 +65,25 @@ public class NodeInfo extends NodeOperationResponse { nodeInfo.readFrom(in); return nodeInfo; } + + @Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException { + super.readFrom(in); + ImmutableMap.Builder builder = ImmutableMap.builder(); + int size = in.readInt(); + for (int i = 0; i < size; i++) { + builder.put(in.readUTF(), in.readUTF()); + } + attributes = builder.build(); + settings = ImmutableSettings.readSettingsFromStream(in); + } + + @Override public void writeTo(DataOutput out) throws IOException { + super.writeTo(out); + out.writeInt(attributes.size()); + for (Map.Entry entry : attributes.entrySet()) { + out.writeUTF(entry.getKey()); + out.writeUTF(entry.getValue()); + } + ImmutableSettings.writeSettingsToStream(settings, out); + } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfo.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfo.java index 6e2f99a79d5..3417716b4e3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfo.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfo.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.admin.cluster.node.info; +import com.google.common.collect.ImmutableMap; import com.google.inject.Inject; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.TransportActions; @@ -28,6 +29,7 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; +import org.elasticsearch.util.MapBuilder; import org.elasticsearch.util.settings.Settings; import java.util.ArrayList; @@ -39,11 +41,21 @@ import java.util.concurrent.atomic.AtomicReferenceArray; */ public class TransportNodesInfo extends TransportNodesOperationAction { + private volatile ImmutableMap nodeAttributes = ImmutableMap.of(); + @Inject public TransportNodesInfo(Settings settings, ClusterName clusterName, ThreadPool threadPool, ClusterService clusterService, TransportService transportService) { super(settings, clusterName, threadPool, clusterService, transportService); } + public synchronized void putNodeAttribute(String key, String value) { + nodeAttributes = new MapBuilder().putAll(nodeAttributes).put(key, value).immutableMap(); + } + + public synchronized void removeNodeAttribute(String key) { + nodeAttributes = new MapBuilder().putAll(nodeAttributes).remove(key).immutableMap(); + } + @Override protected String transportAction() { return TransportActions.Admin.Cluster.Node.INFO; } @@ -80,7 +92,7 @@ public class TransportNodesInfo extends TransportNodesOperationAction getHandlers; private final PathTrie postHandlers; private final PathTrie putHandlers; private final PathTrie deleteHandlers; - @Inject public HttpServer(Settings settings, HttpServerTransport transport, ThreadPool threadPool) { + @Inject public HttpServer(Settings settings, HttpServerTransport transport, ThreadPool threadPool, + TransportNodesInfo nodesInfo) { super(settings); this.transport = transport; this.threadPool = threadPool; + this.nodesInfo = nodesInfo; getHandlers = new PathTrie(); postHandlers = new PathTrie(); @@ -88,6 +93,7 @@ public class HttpServer extends AbstractComponent implements LifecycleComponent< if (logger.isInfoEnabled()) { logger.info("{}", transport.boundAddress()); } + nodesInfo.putNodeAttribute("httpAddress", transport.boundAddress().publishAddress().toString()); return this; } @@ -95,6 +101,7 @@ public class HttpServer extends AbstractComponent implements LifecycleComponent< if (!lifecycle.moveToStopped()) { return this; } + nodesInfo.removeNodeAttribute("httpAddress"); transport.stop(); return this; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/http/action/admin/cluster/node/info/HttpNodesInfoAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/http/action/admin/cluster/node/info/HttpNodesInfoAction.java index 12ef2985cdb..fd5b84c3955 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/http/action/admin/cluster/node/info/HttpNodesInfoAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/http/action/admin/cluster/node/info/HttpNodesInfoAction.java @@ -32,6 +32,7 @@ import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; import java.io.IOException; +import java.util.Map; /** * @author kimchy (Shay Banon) @@ -47,6 +48,7 @@ public class HttpNodesInfoAction extends BaseHttpServerHandler { @Override public void handleRequest(final HttpRequest request, final HttpChannel channel) { String[] nodesIds = HttpActions.splitNodes(request.param("nodeId")); + final boolean includeSettings = HttpActions.paramAsBoolean("settings", false); NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(nodesIds); nodesInfoRequest.listenerThreaded(false); client.admin().cluster().execNodesInfo(nodesInfoRequest, new ActionListener() { @@ -55,6 +57,8 @@ public class HttpNodesInfoAction extends BaseHttpServerHandler { JsonBuilder builder = HttpJsonBuilder.cached(request); builder.startObject(); builder.field("clusterName", result.clusterName().value()); + + builder.startObject("nodes"); for (NodeInfo nodeInfo : result) { builder.startObject(nodeInfo.node().id()); @@ -62,8 +66,22 @@ public class HttpNodesInfoAction extends BaseHttpServerHandler { builder.field("transportAddress", nodeInfo.node().address().toString()); builder.field("dataNode", nodeInfo.node().dataNode()); + for (Map.Entry nodeAttribute : nodeInfo.attributes().entrySet()) { + builder.field(nodeAttribute.getKey(), nodeAttribute.getValue()); + } + + if (includeSettings) { + builder.startObject("settings"); + for (Map.Entry entry : nodeInfo.settings().getAsMap().entrySet()) { + builder.field(entry.getKey(), entry.getValue()); + } + builder.endObject(); + } + builder.endObject(); } + builder.endObject(); + builder.endObject(); channel.sendResponse(new JsonHttpResponse(request, HttpResponse.Status.OK, builder)); } catch (Exception e) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/http/action/admin/cluster/state/HttpClusterStateAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/http/action/admin/cluster/state/HttpClusterStateAction.java index badcd811e87..ee91538d311 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/http/action/admin/cluster/state/HttpClusterStateAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/http/action/admin/cluster/state/HttpClusterStateAction.java @@ -66,7 +66,7 @@ public class HttpClusterStateAction extends BaseHttpServerHandler { builder.startObject("settings"); for (Map.Entry entry : indexMetaData.settings().getAsMap().entrySet()) { - builder.startObject("setting").field("name", entry.getKey()).field("value", entry.getValue()).endObject(); + builder.field(entry.getKey(), entry.getValue()); } builder.endObject(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/http/action/admin/indices/status/HttpIndicesStatusAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/http/action/admin/indices/status/HttpIndicesStatusAction.java index 7e306dcc517..bab8859b93c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/http/action/admin/indices/status/HttpIndicesStatusAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/http/action/admin/indices/status/HttpIndicesStatusAction.java @@ -75,7 +75,7 @@ public class HttpIndicesStatusAction extends BaseHttpServerHandler { builder.startObject("settings"); for (Map.Entry entry : indexStatus.settings().getAsMap().entrySet()) { - builder.startObject("setting").field("name", entry.getKey()).field("value", entry.getValue()).endObject(); + builder.field(entry.getKey(), entry.getValue()); } builder.endObject();