Nodes Info API: Allow to specify which info to get back, simpler URI paths, closes #1596.
This commit is contained in:
parent
d149cbb06e
commit
f1f2fb2ba7
|
@ -42,31 +42,39 @@ import java.util.Map;
|
|||
*/
|
||||
public class NodeInfo extends NodeOperationResponse {
|
||||
|
||||
@Nullable
|
||||
private ImmutableMap<String, String> serviceAttributes;
|
||||
|
||||
@Nullable
|
||||
private String hostname;
|
||||
|
||||
@Nullable
|
||||
private Settings settings;
|
||||
|
||||
@Nullable
|
||||
private OsInfo os;
|
||||
|
||||
@Nullable
|
||||
private ProcessInfo process;
|
||||
|
||||
@Nullable
|
||||
private JvmInfo jvm;
|
||||
|
||||
@Nullable
|
||||
private NetworkInfo network;
|
||||
|
||||
@Nullable
|
||||
private TransportInfo transport;
|
||||
|
||||
@Nullable
|
||||
private HttpInfo http;
|
||||
|
||||
NodeInfo() {
|
||||
}
|
||||
|
||||
public NodeInfo(@Nullable String hostname, DiscoveryNode node, ImmutableMap<String, String> serviceAttributes, Settings settings,
|
||||
OsInfo os, ProcessInfo process, JvmInfo jvm, NetworkInfo network,
|
||||
TransportInfo transport, @Nullable HttpInfo http) {
|
||||
public NodeInfo(@Nullable String hostname, DiscoveryNode node, @Nullable ImmutableMap<String, String> serviceAttributes, @Nullable Settings settings,
|
||||
@Nullable OsInfo os, @Nullable ProcessInfo process, @Nullable JvmInfo jvm, @Nullable NetworkInfo network,
|
||||
@Nullable TransportInfo transport, @Nullable HttpInfo http) {
|
||||
super(node);
|
||||
this.hostname = hostname;
|
||||
this.serviceAttributes = serviceAttributes;
|
||||
|
@ -98,6 +106,7 @@ public class NodeInfo extends NodeOperationResponse {
|
|||
/**
|
||||
* The service attributes of the node.
|
||||
*/
|
||||
@Nullable
|
||||
public ImmutableMap<String, String> serviceAttributes() {
|
||||
return this.serviceAttributes;
|
||||
}
|
||||
|
@ -105,6 +114,7 @@ public class NodeInfo extends NodeOperationResponse {
|
|||
/**
|
||||
* The attributes of the node.
|
||||
*/
|
||||
@Nullable
|
||||
public ImmutableMap<String, String> getServiceAttributes() {
|
||||
return serviceAttributes();
|
||||
}
|
||||
|
@ -112,6 +122,7 @@ public class NodeInfo extends NodeOperationResponse {
|
|||
/**
|
||||
* The settings of the node.
|
||||
*/
|
||||
@Nullable
|
||||
public Settings settings() {
|
||||
return this.settings;
|
||||
}
|
||||
|
@ -119,6 +130,7 @@ public class NodeInfo extends NodeOperationResponse {
|
|||
/**
|
||||
* The settings of the node.
|
||||
*/
|
||||
@Nullable
|
||||
public Settings getSettings() {
|
||||
return settings();
|
||||
}
|
||||
|
@ -126,6 +138,7 @@ public class NodeInfo extends NodeOperationResponse {
|
|||
/**
|
||||
* Operating System level information.
|
||||
*/
|
||||
@Nullable
|
||||
public OsInfo os() {
|
||||
return this.os;
|
||||
}
|
||||
|
@ -133,6 +146,7 @@ public class NodeInfo extends NodeOperationResponse {
|
|||
/**
|
||||
* Operating System level information.
|
||||
*/
|
||||
@Nullable
|
||||
public OsInfo getOs() {
|
||||
return os();
|
||||
}
|
||||
|
@ -140,6 +154,7 @@ public class NodeInfo extends NodeOperationResponse {
|
|||
/**
|
||||
* Process level information.
|
||||
*/
|
||||
@Nullable
|
||||
public ProcessInfo process() {
|
||||
return process;
|
||||
}
|
||||
|
@ -147,6 +162,7 @@ public class NodeInfo extends NodeOperationResponse {
|
|||
/**
|
||||
* Process level information.
|
||||
*/
|
||||
@Nullable
|
||||
public ProcessInfo getProcess() {
|
||||
return process();
|
||||
}
|
||||
|
@ -154,6 +170,7 @@ public class NodeInfo extends NodeOperationResponse {
|
|||
/**
|
||||
* JVM level information.
|
||||
*/
|
||||
@Nullable
|
||||
public JvmInfo jvm() {
|
||||
return jvm;
|
||||
}
|
||||
|
@ -161,6 +178,7 @@ public class NodeInfo extends NodeOperationResponse {
|
|||
/**
|
||||
* JVM level information.
|
||||
*/
|
||||
@Nullable
|
||||
public JvmInfo getJvm() {
|
||||
return jvm();
|
||||
}
|
||||
|
@ -168,6 +186,7 @@ public class NodeInfo extends NodeOperationResponse {
|
|||
/**
|
||||
* Network level information.
|
||||
*/
|
||||
@Nullable
|
||||
public NetworkInfo network() {
|
||||
return network;
|
||||
}
|
||||
|
@ -175,22 +194,27 @@ public class NodeInfo extends NodeOperationResponse {
|
|||
/**
|
||||
* Network level information.
|
||||
*/
|
||||
@Nullable
|
||||
public NetworkInfo getNetwork() {
|
||||
return network();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TransportInfo transport() {
|
||||
return transport;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TransportInfo getTransport() {
|
||||
return transport();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public HttpInfo http() {
|
||||
return http;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public HttpInfo getHttp() {
|
||||
return http();
|
||||
}
|
||||
|
@ -207,13 +231,17 @@ public class NodeInfo extends NodeOperationResponse {
|
|||
if (in.readBoolean()) {
|
||||
hostname = in.readUTF();
|
||||
}
|
||||
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
|
||||
int size = in.readVInt();
|
||||
for (int i = 0; i < size; i++) {
|
||||
builder.put(in.readUTF(), in.readUTF());
|
||||
if (in.readBoolean()) {
|
||||
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
|
||||
int size = in.readVInt();
|
||||
for (int i = 0; i < size; i++) {
|
||||
builder.put(in.readUTF(), in.readUTF());
|
||||
}
|
||||
serviceAttributes = builder.build();
|
||||
}
|
||||
if (in.readBoolean()) {
|
||||
settings = ImmutableSettings.readSettingsFromStream(in);
|
||||
}
|
||||
serviceAttributes = builder.build();
|
||||
settings = ImmutableSettings.readSettingsFromStream(in);
|
||||
if (in.readBoolean()) {
|
||||
os = OsInfo.readOsInfo(in);
|
||||
}
|
||||
|
@ -243,12 +271,22 @@ public class NodeInfo extends NodeOperationResponse {
|
|||
out.writeBoolean(true);
|
||||
out.writeUTF(hostname);
|
||||
}
|
||||
out.writeVInt(serviceAttributes.size());
|
||||
for (Map.Entry<String, String> entry : serviceAttributes.entrySet()) {
|
||||
out.writeUTF(entry.getKey());
|
||||
out.writeUTF(entry.getValue());
|
||||
if (serviceAttributes() == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
out.writeVInt(serviceAttributes.size());
|
||||
for (Map.Entry<String, String> entry : serviceAttributes.entrySet()) {
|
||||
out.writeUTF(entry.getKey());
|
||||
out.writeUTF(entry.getValue());
|
||||
}
|
||||
}
|
||||
if (settings == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
ImmutableSettings.writeSettingsToStream(settings, out);
|
||||
}
|
||||
ImmutableSettings.writeSettingsToStream(settings, out);
|
||||
if (os == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
|
|
|
@ -20,14 +20,24 @@
|
|||
package org.elasticsearch.action.admin.cluster.node.info;
|
||||
|
||||
import org.elasticsearch.action.support.nodes.NodesOperationRequest;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A request to get node (cluster) level information.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class NodesInfoRequest extends NodesOperationRequest {
|
||||
|
||||
private boolean settings = false;
|
||||
private boolean os = false;
|
||||
private boolean process = false;
|
||||
private boolean jvm = false;
|
||||
private boolean network = false;
|
||||
private boolean transport = false;
|
||||
private boolean http = false;
|
||||
|
||||
public NodesInfoRequest() {
|
||||
}
|
||||
|
||||
|
@ -38,4 +48,147 @@ public class NodesInfoRequest extends NodesOperationRequest {
|
|||
public NodesInfoRequest(String... nodesIds) {
|
||||
super(nodesIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all info flags.
|
||||
*/
|
||||
public NodesInfoRequest clear() {
|
||||
settings = false;
|
||||
os = false;
|
||||
process = false;
|
||||
jvm = false;
|
||||
network = false;
|
||||
transport = false;
|
||||
http = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node settings be returned.
|
||||
*/
|
||||
public boolean settings() {
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node settings be returned.
|
||||
*/
|
||||
public NodesInfoRequest settings(boolean settings) {
|
||||
this.settings = settings;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node OS be returned.
|
||||
*/
|
||||
public boolean os() {
|
||||
return this.os;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node OS be returned.
|
||||
*/
|
||||
public NodesInfoRequest os(boolean os) {
|
||||
this.os = os;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node Process be returned.
|
||||
*/
|
||||
public boolean process() {
|
||||
return this.process;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node Process be returned.
|
||||
*/
|
||||
public NodesInfoRequest process(boolean process) {
|
||||
this.process = process;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node JVM be returned.
|
||||
*/
|
||||
public boolean jvm() {
|
||||
return this.jvm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node JVM be returned.
|
||||
*/
|
||||
public NodesInfoRequest jvm(boolean jvm) {
|
||||
this.jvm = jvm;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node Network be returned.
|
||||
*/
|
||||
public boolean network() {
|
||||
return this.network;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node Network be returned.
|
||||
*/
|
||||
public NodesInfoRequest network(boolean network) {
|
||||
this.network = network;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node Transport be returned.
|
||||
*/
|
||||
public boolean transport() {
|
||||
return this.transport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node Transport be returned.
|
||||
*/
|
||||
public NodesInfoRequest transport(boolean transport) {
|
||||
this.transport = transport;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node HTTP be returned.
|
||||
*/
|
||||
public boolean http() {
|
||||
return this.http;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node HTTP be returned.
|
||||
*/
|
||||
public NodesInfoRequest http(boolean http) {
|
||||
this.http = http;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
settings = in.readBoolean();
|
||||
os = in.readBoolean();
|
||||
process = in.readBoolean();
|
||||
jvm = in.readBoolean();
|
||||
network = in.readBoolean();
|
||||
transport = in.readBoolean();
|
||||
http = in.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeBoolean(settings);
|
||||
out.writeBoolean(os);
|
||||
out.writeBoolean(process);
|
||||
out.writeBoolean(jvm);
|
||||
out.writeBoolean(network);
|
||||
out.writeBoolean(transport);
|
||||
out.writeBoolean(http);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,13 +23,20 @@ import org.elasticsearch.action.support.nodes.NodesOperationResponse;
|
|||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.SettingsFilter;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class NodesInfoResponse extends NodesOperationResponse<NodeInfo> {
|
||||
public class NodesInfoResponse extends NodesOperationResponse<NodeInfo> implements ToXContent {
|
||||
|
||||
private SettingsFilter settingsFilter;
|
||||
|
||||
public NodesInfoResponse() {
|
||||
}
|
||||
|
@ -55,4 +62,71 @@ public class NodesInfoResponse extends NodesOperationResponse<NodeInfo> {
|
|||
node.writeTo(out);
|
||||
}
|
||||
}
|
||||
|
||||
public NodesInfoResponse settingsFilter(SettingsFilter settingsFilter) {
|
||||
this.settingsFilter = settingsFilter;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.field("cluster_name", clusterName().value());
|
||||
|
||||
builder.startObject("nodes");
|
||||
for (NodeInfo nodeInfo : this) {
|
||||
builder.startObject(nodeInfo.node().id(), XContentBuilder.FieldCaseConversion.NONE);
|
||||
|
||||
builder.field("name", nodeInfo.node().name(), XContentBuilder.FieldCaseConversion.NONE);
|
||||
builder.field("transport_address", nodeInfo.node().address().toString());
|
||||
|
||||
if (nodeInfo.hostname() != null) {
|
||||
builder.field("hostname", nodeInfo.hostname(), XContentBuilder.FieldCaseConversion.NONE);
|
||||
}
|
||||
|
||||
if (nodeInfo.serviceAttributes() != null) {
|
||||
for (Map.Entry<String, String> nodeAttribute : nodeInfo.serviceAttributes().entrySet()) {
|
||||
builder.field(nodeAttribute.getKey(), nodeAttribute.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
builder.startObject("attributes");
|
||||
for (Map.Entry<String, String> attr : nodeInfo.node().attributes().entrySet()) {
|
||||
builder.field(attr.getKey(), attr.getValue());
|
||||
}
|
||||
builder.endObject();
|
||||
|
||||
|
||||
if (nodeInfo.settings() != null) {
|
||||
builder.startObject("settings");
|
||||
Settings settings = settingsFilter.filterSettings(nodeInfo.settings());
|
||||
for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) {
|
||||
builder.field(entry.getKey(), entry.getValue());
|
||||
}
|
||||
builder.endObject();
|
||||
}
|
||||
|
||||
if (nodeInfo.os() != null) {
|
||||
nodeInfo.os().toXContent(builder, params);
|
||||
}
|
||||
if (nodeInfo.process() != null) {
|
||||
nodeInfo.process().toXContent(builder, params);
|
||||
}
|
||||
if (nodeInfo.jvm() != null) {
|
||||
nodeInfo.jvm().toXContent(builder, params);
|
||||
}
|
||||
if (nodeInfo.network() != null) {
|
||||
nodeInfo.network().toXContent(builder, params);
|
||||
}
|
||||
if (nodeInfo.transport() != null) {
|
||||
nodeInfo.transport().toXContent(builder, params);
|
||||
}
|
||||
if (nodeInfo.http() != null) {
|
||||
nodeInfo.http().toXContent(builder, params);
|
||||
}
|
||||
|
||||
builder.endObject();
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,11 +26,14 @@ import org.elasticsearch.action.support.nodes.TransportNodesOperationAction;
|
|||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.node.service.NodeService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
@ -84,7 +87,7 @@ public class TransportNodesInfoAction extends TransportNodesOperationAction<Node
|
|||
|
||||
@Override
|
||||
protected NodeInfoRequest newNodeRequest(String nodeId, NodesInfoRequest request) {
|
||||
return new NodeInfoRequest(nodeId);
|
||||
return new NodeInfoRequest(nodeId, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,8 +96,9 @@ public class TransportNodesInfoAction extends TransportNodesOperationAction<Node
|
|||
}
|
||||
|
||||
@Override
|
||||
protected NodeInfo nodeOperation(NodeInfoRequest nodeInfoRequest) throws ElasticSearchException {
|
||||
return nodeService.info();
|
||||
protected NodeInfo nodeOperation(NodeInfoRequest nodeRequest) throws ElasticSearchException {
|
||||
NodesInfoRequest request = nodeRequest.request;
|
||||
return nodeService.info(request.settings(), request.os(), request.process(), request.jvm(), request.network(), request.transport(), request.http());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -102,13 +106,29 @@ public class TransportNodesInfoAction extends TransportNodesOperationAction<Node
|
|||
return false;
|
||||
}
|
||||
|
||||
protected static class NodeInfoRequest extends NodeOperationRequest {
|
||||
static class NodeInfoRequest extends NodeOperationRequest {
|
||||
|
||||
private NodeInfoRequest() {
|
||||
NodesInfoRequest request;
|
||||
|
||||
NodeInfoRequest() {
|
||||
}
|
||||
|
||||
private NodeInfoRequest(String nodeId) {
|
||||
NodeInfoRequest(String nodeId, NodesInfoRequest request) {
|
||||
super(nodeId);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
request = new NodesInfoRequest();
|
||||
request.readFrom(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
request.writeTo(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,71 @@ public class NodesInfoRequestBuilder extends BaseClusterRequestBuilder<NodesInfo
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all info flags.
|
||||
*/
|
||||
public NodesInfoRequestBuilder clear() {
|
||||
request.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node settings be returned.
|
||||
*/
|
||||
public NodesInfoRequestBuilder setSettings(boolean settings) {
|
||||
request.settings(settings);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node OS info be returned.
|
||||
*/
|
||||
public NodesInfoRequestBuilder setOs(boolean os) {
|
||||
request.os(os);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node OS process be returned.
|
||||
*/
|
||||
public NodesInfoRequestBuilder setProcess(boolean process) {
|
||||
request.process(process);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node JVM info be returned.
|
||||
*/
|
||||
public NodesInfoRequestBuilder setJvm(boolean jvm) {
|
||||
request.jvm(jvm);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node Network info be returned.
|
||||
*/
|
||||
public NodesInfoRequestBuilder setNetwork(boolean network) {
|
||||
request.network(network);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node Transport info be returned.
|
||||
*/
|
||||
public NodesInfoRequestBuilder setTransport(boolean transport) {
|
||||
request.transport(transport);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the node HTTP info be returned.
|
||||
*/
|
||||
public NodesInfoRequestBuilder setHttp(boolean http) {
|
||||
request.http(http);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doExecute(ActionListener<NodesInfoResponse> listener) {
|
||||
client.nodesInfo(request, listener);
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.node.service;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
|
||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||
|
@ -37,6 +35,8 @@ import org.elasticsearch.indices.IndicesService;
|
|||
import org.elasticsearch.monitor.MonitorService;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class NodeService extends AbstractComponent {
|
||||
|
@ -107,6 +107,18 @@ public class NodeService extends AbstractComponent {
|
|||
transportService.info(), httpServer == null ? null : httpServer.info());
|
||||
}
|
||||
|
||||
public NodeInfo info(boolean settings, boolean os, boolean process, boolean jvm, boolean network, boolean transport, boolean http) {
|
||||
return new NodeInfo(hostname, clusterService.state().nodes().localNode(), serviceAttributes,
|
||||
settings ? this.settings : null,
|
||||
os ? monitorService.osService().info() : null,
|
||||
process ? monitorService.processService().info() : null,
|
||||
jvm ? monitorService.jvmService().info() : null,
|
||||
network ? monitorService.networkService().info() : null,
|
||||
transport ? transportService.info() : null,
|
||||
http ? (httpServer == null ? null : httpServer.info()) : null
|
||||
);
|
||||
}
|
||||
|
||||
public NodeStats stats() {
|
||||
// for indices stats we want to include previous allocated shards stats as well (it will
|
||||
// only be applied to the sensible ones to use, like refresh/merge/flush/indexing stats)
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.rest.action.admin.cluster.node.info;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
|
||||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
@ -33,7 +32,6 @@ import org.elasticsearch.rest.action.support.RestActions;
|
|||
import org.elasticsearch.rest.action.support.RestXContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -48,6 +46,29 @@ public class RestNodesInfoAction extends BaseRestHandler {
|
|||
super(settings, client);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_cluster/nodes", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_cluster/nodes/{nodeId}", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/{nodeId}", this);
|
||||
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/settings", new RestSettingsHandler());
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/{nodeId}/settings", new RestSettingsHandler());
|
||||
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/os", new RestOsHandler());
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/{nodeId}/os", new RestOsHandler());
|
||||
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/process", new RestProcessHandler());
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/{nodeId}/process", new RestProcessHandler());
|
||||
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/jvm", new RestJvmHandler());
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/{nodeId}/jvm", new RestJvmHandler());
|
||||
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/network", new RestNetworkHandler());
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/{nodeId}/network", new RestNetworkHandler());
|
||||
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/transport", new RestTransportHandler());
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/{nodeId}/transport", new RestTransportHandler());
|
||||
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/http", new RestHttpHandler());
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_nodes/{nodeId}/http", new RestHttpHandler());
|
||||
|
||||
this.settingsFilter = settingsFilter;
|
||||
}
|
||||
|
@ -55,71 +76,34 @@ public class RestNodesInfoAction extends BaseRestHandler {
|
|||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
String[] nodesIds = RestActions.splitNodes(request.param("nodeId"));
|
||||
final boolean includeSettings = request.paramAsBoolean("settings", false);
|
||||
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(nodesIds);
|
||||
final NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(nodesIds);
|
||||
|
||||
boolean clear = request.paramAsBoolean("clear", false);
|
||||
if (clear) {
|
||||
nodesInfoRequest.clear();
|
||||
}
|
||||
nodesInfoRequest.settings(request.paramAsBoolean("settings", nodesInfoRequest.settings()));
|
||||
nodesInfoRequest.os(request.paramAsBoolean("os", nodesInfoRequest.os()));
|
||||
nodesInfoRequest.process(request.paramAsBoolean("process", nodesInfoRequest.process()));
|
||||
nodesInfoRequest.jvm(request.paramAsBoolean("jvm", nodesInfoRequest.jvm()));
|
||||
nodesInfoRequest.network(request.paramAsBoolean("network", nodesInfoRequest.network()));
|
||||
nodesInfoRequest.transport(request.paramAsBoolean("transport", nodesInfoRequest.transport()));
|
||||
nodesInfoRequest.http(request.paramAsBoolean("http", nodesInfoRequest.http()));
|
||||
|
||||
executeNodeRequest(request, channel, nodesInfoRequest);
|
||||
}
|
||||
|
||||
void executeNodeRequest(final RestRequest request, final RestChannel channel, NodesInfoRequest nodesInfoRequest) {
|
||||
nodesInfoRequest.listenerThreaded(false);
|
||||
client.admin().cluster().nodesInfo(nodesInfoRequest, new ActionListener<NodesInfoResponse>() {
|
||||
@Override
|
||||
public void onResponse(NodesInfoResponse result) {
|
||||
public void onResponse(NodesInfoResponse response) {
|
||||
try {
|
||||
response.settingsFilter(settingsFilter);
|
||||
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
|
||||
builder.startObject();
|
||||
builder.field("cluster_name", result.clusterName().value());
|
||||
|
||||
builder.startObject("nodes");
|
||||
for (NodeInfo nodeInfo : result) {
|
||||
builder.startObject(nodeInfo.node().id(), XContentBuilder.FieldCaseConversion.NONE);
|
||||
|
||||
builder.field("name", nodeInfo.node().name(), XContentBuilder.FieldCaseConversion.NONE);
|
||||
builder.field("transport_address", nodeInfo.node().address().toString());
|
||||
|
||||
if (nodeInfo.hostname() != null) {
|
||||
builder.field("hostname", nodeInfo.hostname(), XContentBuilder.FieldCaseConversion.NONE);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> nodeAttribute : nodeInfo.serviceAttributes().entrySet()) {
|
||||
builder.field(nodeAttribute.getKey(), nodeAttribute.getValue());
|
||||
}
|
||||
|
||||
builder.startObject("attributes");
|
||||
for (Map.Entry<String, String> attr : nodeInfo.node().attributes().entrySet()) {
|
||||
builder.field(attr.getKey(), attr.getValue());
|
||||
}
|
||||
builder.endObject();
|
||||
|
||||
|
||||
if (includeSettings) {
|
||||
builder.startObject("settings");
|
||||
Settings settings = settingsFilter.filterSettings(nodeInfo.settings());
|
||||
for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) {
|
||||
builder.field(entry.getKey(), entry.getValue());
|
||||
}
|
||||
builder.endObject();
|
||||
}
|
||||
|
||||
if (nodeInfo.os() != null) {
|
||||
nodeInfo.os().toXContent(builder, request);
|
||||
}
|
||||
if (nodeInfo.process() != null) {
|
||||
nodeInfo.process().toXContent(builder, request);
|
||||
}
|
||||
if (nodeInfo.jvm() != null) {
|
||||
nodeInfo.jvm().toXContent(builder, request);
|
||||
}
|
||||
if (nodeInfo.network() != null) {
|
||||
nodeInfo.network().toXContent(builder, request);
|
||||
}
|
||||
if (nodeInfo.transport() != null) {
|
||||
nodeInfo.transport().toXContent(builder, request);
|
||||
}
|
||||
if (nodeInfo.http() != null) {
|
||||
nodeInfo.http().toXContent(builder, request);
|
||||
}
|
||||
|
||||
builder.endObject();
|
||||
}
|
||||
builder.endObject();
|
||||
|
||||
builder.field("ok", true);
|
||||
response.toXContent(builder, request);
|
||||
builder.endObject();
|
||||
channel.sendResponse(new XContentRestResponse(request, RestStatus.OK, builder));
|
||||
} catch (Exception e) {
|
||||
|
@ -137,4 +121,67 @@ public class RestNodesInfoAction extends BaseRestHandler {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
class RestSettingsHandler implements RestHandler {
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(RestActions.splitNodes(request.param("nodeId")));
|
||||
nodesInfoRequest.clear().settings(true);
|
||||
executeNodeRequest(request, channel, nodesInfoRequest);
|
||||
}
|
||||
}
|
||||
|
||||
class RestOsHandler implements RestHandler {
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(RestActions.splitNodes(request.param("nodeId")));
|
||||
nodesInfoRequest.clear().os(true);
|
||||
executeNodeRequest(request, channel, nodesInfoRequest);
|
||||
}
|
||||
}
|
||||
|
||||
class RestProcessHandler implements RestHandler {
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(RestActions.splitNodes(request.param("nodeId")));
|
||||
nodesInfoRequest.clear().process(true);
|
||||
executeNodeRequest(request, channel, nodesInfoRequest);
|
||||
}
|
||||
}
|
||||
|
||||
class RestJvmHandler implements RestHandler {
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(RestActions.splitNodes(request.param("nodeId")));
|
||||
nodesInfoRequest.clear().jvm(true);
|
||||
executeNodeRequest(request, channel, nodesInfoRequest);
|
||||
}
|
||||
}
|
||||
|
||||
class RestNetworkHandler implements RestHandler {
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(RestActions.splitNodes(request.param("nodeId")));
|
||||
nodesInfoRequest.clear().network(true);
|
||||
executeNodeRequest(request, channel, nodesInfoRequest);
|
||||
}
|
||||
}
|
||||
|
||||
class RestTransportHandler implements RestHandler {
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(RestActions.splitNodes(request.param("nodeId")));
|
||||
nodesInfoRequest.clear().transport(true);
|
||||
executeNodeRequest(request, channel, nodesInfoRequest);
|
||||
}
|
||||
}
|
||||
|
||||
class RestHttpHandler implements RestHandler {
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(RestActions.splitNodes(request.param("nodeId")));
|
||||
nodesInfoRequest.clear().http(true);
|
||||
executeNodeRequest(request, channel, nodesInfoRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue