Query http listeners. Closes #10.
This commit is contained in:
parent
cfafb52beb
commit
b5f3fc9ae1
|
@ -19,22 +19,45 @@
|
||||||
|
|
||||||
package org.elasticsearch.action.admin.cluster.node.info;
|
package org.elasticsearch.action.admin.cluster.node.info;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.elasticsearch.action.support.nodes.NodeOperationResponse;
|
import org.elasticsearch.action.support.nodes.NodeOperationResponse;
|
||||||
import org.elasticsearch.cluster.node.Node;
|
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.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kimchy (Shay Banon)
|
* @author kimchy (Shay Banon)
|
||||||
*/
|
*/
|
||||||
public class NodeInfo extends NodeOperationResponse {
|
public class NodeInfo extends NodeOperationResponse {
|
||||||
|
|
||||||
protected NodeInfo() {
|
private ImmutableMap<String, String> attributes;
|
||||||
|
|
||||||
|
private Settings settings;
|
||||||
|
|
||||||
|
NodeInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeInfo(Node node) {
|
public NodeInfo(Node node, Map<String, String> attributes, Settings settings) {
|
||||||
|
this(node, ImmutableMap.copyOf(attributes), settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NodeInfo(Node node, ImmutableMap<String, String> attributes, Settings settings) {
|
||||||
super(node);
|
super(node);
|
||||||
|
this.attributes = attributes;
|
||||||
|
this.settings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImmutableMap<String, String> attributes() {
|
||||||
|
return this.attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Settings settings() {
|
||||||
|
return this.settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NodeInfo readNodeInfo(DataInput in) throws ClassNotFoundException, IOException {
|
public static NodeInfo readNodeInfo(DataInput in) throws ClassNotFoundException, IOException {
|
||||||
|
@ -42,4 +65,25 @@ public class NodeInfo extends NodeOperationResponse {
|
||||||
nodeInfo.readFrom(in);
|
nodeInfo.readFrom(in);
|
||||||
return nodeInfo;
|
return nodeInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException {
|
||||||
|
super.readFrom(in);
|
||||||
|
ImmutableMap.Builder<String, String> 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<String, String> entry : attributes.entrySet()) {
|
||||||
|
out.writeUTF(entry.getKey());
|
||||||
|
out.writeUTF(entry.getValue());
|
||||||
|
}
|
||||||
|
ImmutableSettings.writeSettingsToStream(settings, out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.action.admin.cluster.node.info;
|
package org.elasticsearch.action.admin.cluster.node.info;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import org.elasticsearch.ElasticSearchException;
|
import org.elasticsearch.ElasticSearchException;
|
||||||
import org.elasticsearch.action.TransportActions;
|
import org.elasticsearch.action.TransportActions;
|
||||||
|
@ -28,6 +29,7 @@ import org.elasticsearch.cluster.ClusterName;
|
||||||
import org.elasticsearch.cluster.ClusterService;
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
|
import org.elasticsearch.util.MapBuilder;
|
||||||
import org.elasticsearch.util.settings.Settings;
|
import org.elasticsearch.util.settings.Settings;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -39,11 +41,21 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||||
*/
|
*/
|
||||||
public class TransportNodesInfo extends TransportNodesOperationAction<NodesInfoRequest, NodesInfoResponse, TransportNodesInfo.NodeInfoRequest, NodeInfo> {
|
public class TransportNodesInfo extends TransportNodesOperationAction<NodesInfoRequest, NodesInfoResponse, TransportNodesInfo.NodeInfoRequest, NodeInfo> {
|
||||||
|
|
||||||
|
private volatile ImmutableMap<String, String> nodeAttributes = ImmutableMap.of();
|
||||||
|
|
||||||
@Inject public TransportNodesInfo(Settings settings, ClusterName clusterName, ThreadPool threadPool,
|
@Inject public TransportNodesInfo(Settings settings, ClusterName clusterName, ThreadPool threadPool,
|
||||||
ClusterService clusterService, TransportService transportService) {
|
ClusterService clusterService, TransportService transportService) {
|
||||||
super(settings, clusterName, threadPool, clusterService, transportService);
|
super(settings, clusterName, threadPool, clusterService, transportService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void putNodeAttribute(String key, String value) {
|
||||||
|
nodeAttributes = new MapBuilder<String, String>().putAll(nodeAttributes).put(key, value).immutableMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void removeNodeAttribute(String key) {
|
||||||
|
nodeAttributes = new MapBuilder<String, String>().putAll(nodeAttributes).remove(key).immutableMap();
|
||||||
|
}
|
||||||
|
|
||||||
@Override protected String transportAction() {
|
@Override protected String transportAction() {
|
||||||
return TransportActions.Admin.Cluster.Node.INFO;
|
return TransportActions.Admin.Cluster.Node.INFO;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +92,7 @@ public class TransportNodesInfo extends TransportNodesOperationAction<NodesInfoR
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected NodeInfo nodeOperation(NodeInfoRequest nodeInfoRequest) throws ElasticSearchException {
|
@Override protected NodeInfo nodeOperation(NodeInfoRequest nodeInfoRequest) throws ElasticSearchException {
|
||||||
return new NodeInfo(clusterService.state().nodes().localNode());
|
return new NodeInfo(clusterService.state().nodes().localNode(), nodeAttributes, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected boolean accumulateExceptions() {
|
@Override protected boolean accumulateExceptions() {
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.http;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import org.elasticsearch.ElasticSearchException;
|
import org.elasticsearch.ElasticSearchException;
|
||||||
|
import org.elasticsearch.action.admin.cluster.node.info.TransportNodesInfo;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.util.component.AbstractComponent;
|
import org.elasticsearch.util.component.AbstractComponent;
|
||||||
import org.elasticsearch.util.component.Lifecycle;
|
import org.elasticsearch.util.component.Lifecycle;
|
||||||
|
@ -42,15 +43,19 @@ public class HttpServer extends AbstractComponent implements LifecycleComponent<
|
||||||
|
|
||||||
private final ThreadPool threadPool;
|
private final ThreadPool threadPool;
|
||||||
|
|
||||||
|
private final TransportNodesInfo nodesInfo;
|
||||||
|
|
||||||
private final PathTrie<HttpServerHandler> getHandlers;
|
private final PathTrie<HttpServerHandler> getHandlers;
|
||||||
private final PathTrie<HttpServerHandler> postHandlers;
|
private final PathTrie<HttpServerHandler> postHandlers;
|
||||||
private final PathTrie<HttpServerHandler> putHandlers;
|
private final PathTrie<HttpServerHandler> putHandlers;
|
||||||
private final PathTrie<HttpServerHandler> deleteHandlers;
|
private final PathTrie<HttpServerHandler> deleteHandlers;
|
||||||
|
|
||||||
@Inject public HttpServer(Settings settings, HttpServerTransport transport, ThreadPool threadPool) {
|
@Inject public HttpServer(Settings settings, HttpServerTransport transport, ThreadPool threadPool,
|
||||||
|
TransportNodesInfo nodesInfo) {
|
||||||
super(settings);
|
super(settings);
|
||||||
this.transport = transport;
|
this.transport = transport;
|
||||||
this.threadPool = threadPool;
|
this.threadPool = threadPool;
|
||||||
|
this.nodesInfo = nodesInfo;
|
||||||
|
|
||||||
getHandlers = new PathTrie<HttpServerHandler>();
|
getHandlers = new PathTrie<HttpServerHandler>();
|
||||||
postHandlers = new PathTrie<HttpServerHandler>();
|
postHandlers = new PathTrie<HttpServerHandler>();
|
||||||
|
@ -88,6 +93,7 @@ public class HttpServer extends AbstractComponent implements LifecycleComponent<
|
||||||
if (logger.isInfoEnabled()) {
|
if (logger.isInfoEnabled()) {
|
||||||
logger.info("{}", transport.boundAddress());
|
logger.info("{}", transport.boundAddress());
|
||||||
}
|
}
|
||||||
|
nodesInfo.putNodeAttribute("httpAddress", transport.boundAddress().publishAddress().toString());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +101,7 @@ public class HttpServer extends AbstractComponent implements LifecycleComponent<
|
||||||
if (!lifecycle.moveToStopped()) {
|
if (!lifecycle.moveToStopped()) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
nodesInfo.removeNodeAttribute("httpAddress");
|
||||||
transport.stop();
|
transport.stop();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.elasticsearch.util.json.JsonBuilder;
|
||||||
import org.elasticsearch.util.settings.Settings;
|
import org.elasticsearch.util.settings.Settings;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kimchy (Shay Banon)
|
* @author kimchy (Shay Banon)
|
||||||
|
@ -47,6 +48,7 @@ public class HttpNodesInfoAction extends BaseHttpServerHandler {
|
||||||
|
|
||||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||||
String[] nodesIds = HttpActions.splitNodes(request.param("nodeId"));
|
String[] nodesIds = HttpActions.splitNodes(request.param("nodeId"));
|
||||||
|
final boolean includeSettings = HttpActions.paramAsBoolean("settings", false);
|
||||||
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(nodesIds);
|
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(nodesIds);
|
||||||
nodesInfoRequest.listenerThreaded(false);
|
nodesInfoRequest.listenerThreaded(false);
|
||||||
client.admin().cluster().execNodesInfo(nodesInfoRequest, new ActionListener<NodesInfoResponse>() {
|
client.admin().cluster().execNodesInfo(nodesInfoRequest, new ActionListener<NodesInfoResponse>() {
|
||||||
|
@ -55,6 +57,8 @@ public class HttpNodesInfoAction extends BaseHttpServerHandler {
|
||||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder.field("clusterName", result.clusterName().value());
|
builder.field("clusterName", result.clusterName().value());
|
||||||
|
|
||||||
|
builder.startObject("nodes");
|
||||||
for (NodeInfo nodeInfo : result) {
|
for (NodeInfo nodeInfo : result) {
|
||||||
builder.startObject(nodeInfo.node().id());
|
builder.startObject(nodeInfo.node().id());
|
||||||
|
|
||||||
|
@ -62,8 +66,22 @@ public class HttpNodesInfoAction extends BaseHttpServerHandler {
|
||||||
builder.field("transportAddress", nodeInfo.node().address().toString());
|
builder.field("transportAddress", nodeInfo.node().address().toString());
|
||||||
builder.field("dataNode", nodeInfo.node().dataNode());
|
builder.field("dataNode", nodeInfo.node().dataNode());
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> nodeAttribute : nodeInfo.attributes().entrySet()) {
|
||||||
|
builder.field(nodeAttribute.getKey(), nodeAttribute.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includeSettings) {
|
||||||
|
builder.startObject("settings");
|
||||||
|
for (Map.Entry<String, String> entry : nodeInfo.settings().getAsMap().entrySet()) {
|
||||||
|
builder.field(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
builder.endObject();
|
||||||
|
}
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
builder.endObject();
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
channel.sendResponse(new JsonHttpResponse(request, HttpResponse.Status.OK, builder));
|
channel.sendResponse(new JsonHttpResponse(request, HttpResponse.Status.OK, builder));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class HttpClusterStateAction extends BaseHttpServerHandler {
|
||||||
|
|
||||||
builder.startObject("settings");
|
builder.startObject("settings");
|
||||||
for (Map.Entry<String, String> entry : indexMetaData.settings().getAsMap().entrySet()) {
|
for (Map.Entry<String, String> 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();
|
builder.endObject();
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class HttpIndicesStatusAction extends BaseHttpServerHandler {
|
||||||
|
|
||||||
builder.startObject("settings");
|
builder.startObject("settings");
|
||||||
for (Map.Entry<String, String> entry : indexStatus.settings().getAsMap().entrySet()) {
|
for (Map.Entry<String, String> 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();
|
builder.endObject();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue