diff --git a/.gitignore b/.gitignore index 3fb62088a9f..82b873847b4 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ target/ ## netbeans ignores nb-configuration.xml nbactions.xml + +/dependency-reduced-pom.xml diff --git a/src/main/java/org/elasticsearch/rest/action/RestActionModule.java b/src/main/java/org/elasticsearch/rest/action/RestActionModule.java index 91d05c898b5..5e9cfe6b1ee 100644 --- a/src/main/java/org/elasticsearch/rest/action/RestActionModule.java +++ b/src/main/java/org/elasticsearch/rest/action/RestActionModule.java @@ -67,6 +67,7 @@ import org.elasticsearch.rest.action.admin.indices.warmer.delete.RestDeleteWarme import org.elasticsearch.rest.action.admin.indices.warmer.get.RestGetWarmerAction; import org.elasticsearch.rest.action.admin.indices.warmer.put.RestPutWarmerAction; import org.elasticsearch.rest.action.bulk.RestBulkAction; +import org.elasticsearch.rest.action.cat.RestIndicesAction; import org.elasticsearch.rest.action.cat.RestMasterAction; import org.elasticsearch.rest.action.cat.RestNodesAction; import org.elasticsearch.rest.action.cat.RestShardsAction; @@ -187,5 +188,6 @@ public class RestActionModule extends AbstractModule { bind(RestShardsAction.class).asEagerSingleton(); bind(RestMasterAction.class).asEagerSingleton(); bind(RestNodesAction.class).asEagerSingleton(); + bind(RestIndicesAction.class).asEagerSingleton(); } } diff --git a/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java b/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java new file mode 100644 index 00000000000..04fa8ebc56f --- /dev/null +++ b/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java @@ -0,0 +1,151 @@ +/* + * Licensed to ElasticSearch and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. ElasticSearch licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.rest.action.cat; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; +import org.elasticsearch.action.admin.cluster.health.ClusterIndexHealth; +import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; +import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; +import org.elasticsearch.action.admin.indices.stats.CommonStats; +import org.elasticsearch.action.admin.indices.stats.IndexStats; +import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest; +import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; +import org.elasticsearch.client.Client; +import org.elasticsearch.client.Requests; +import org.elasticsearch.common.Table; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.rest.*; +import org.elasticsearch.rest.action.support.RestTable; + +import java.io.IOException; +import java.util.Locale; +import java.util.Map; + +import static org.elasticsearch.rest.RestRequest.Method.GET; +import static org.elasticsearch.rest.action.support.RestActions.splitIndices; + +public class RestIndicesAction extends BaseRestHandler { + + @Inject + public RestIndicesAction(Settings settings, Client client, RestController controller) { + super(settings, client); + controller.registerHandler(GET, "/_cat/indices", this); + controller.registerHandler(GET, "/_cat/indices/{index}", this); + } + + @Override + public void handleRequest(final RestRequest request, final RestChannel channel) { + final String[] indices = splitIndices(request.param("index")); + final ClusterStateRequest clusterStateRequest = new ClusterStateRequest(); + clusterStateRequest.filterMetaData(true).filteredIndices(indices); + clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local())); + clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout())); + + client.admin().cluster().state(clusterStateRequest, new ActionListener() { + @Override + public void onResponse(final ClusterStateResponse clusterStateResponse) { + ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(indices); + clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local())); + clusterHealthRequest.indices(indices); + client.admin().cluster().health(clusterHealthRequest, new ActionListener() { + @Override + public void onResponse(final ClusterHealthResponse clusterHealthResponse) { + IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest(); + indicesStatsRequest.clear().store(true).docs(true); + client.admin().indices().stats(indicesStatsRequest, new ActionListener() { + @Override + public void onResponse(IndicesStatsResponse indicesStatsResponse) { + try { + channel.sendResponse(RestTable.buildResponse(buildTable(clusterStateResponse, clusterHealthResponse, indicesStatsResponse), request, channel)); + } catch (Throwable e) { + onFailure(e); + } + } + + @Override + public void onFailure(Throwable e) { + try { + channel.sendResponse(new XContentThrowableRestResponse(request, e)); + } catch (IOException e1) { + logger.error("Failed to send failure response", e1); + } + } + }); + + } + + @Override + public void onFailure(Throwable e) { + try { + channel.sendResponse(new XContentThrowableRestResponse(request, e)); + } catch (IOException e1) { + logger.error("Failed to send failure response", e1); + } + } + }); + } + + @Override + public void onFailure(Throwable e) { + try { + channel.sendResponse(new XContentThrowableRestResponse(request, e)); + } catch (IOException e1) { + logger.error("Failed to send failure response", e1); + } + } + }); + } + + private Table buildTable(ClusterStateResponse state, ClusterHealthResponse health, IndicesStatsResponse stats) { + Table table = new Table(); + table.startHeaders(); + table.addCell("health"); + table.addCell("index"); + table.addCell("pri", "text-align:right;"); + table.addCell("rep", "text-align:right;"); + table.addCell("docs", "text-align:right;"); + table.addCell("docs/del", "text-align:right;"); + table.addCell("size/pri", "text-align:right;"); + table.addCell("size/total", "text-align:right;"); + table.endHeaders(); + + for (Map.Entry entry : state.getState().routingTable().indicesRouting().entrySet()) { + String index = (String) entry.getKey(); + ClusterIndexHealth indexHealth = health.getIndices().get(index); + IndexStats indexStats = stats.getIndices().get(index); + + table.startRow(); + table.addCell(indexHealth == null ? "red*" : indexHealth.getStatus().toString().toLowerCase(Locale.getDefault())); + table.addCell(index); + table.addCell(indexHealth == null ? null : indexHealth.getNumberOfShards()); + table.addCell(indexHealth == null ? null : indexHealth.getNumberOfReplicas()); + table.addCell(indexStats == null ? null : indexStats.getPrimaries().getDocs().getCount()); + table.addCell(indexStats == null ? null : indexStats.getPrimaries().getDocs().getDeleted()); + table.addCell(indexStats == null ? null : indexStats.getPrimaries().getStore().size()); + table.addCell(indexStats == null ? null : indexStats.getTotal().getStore().size()); + table.endRow(); + } + + return table; + } +} diff --git a/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java b/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java index afe0bb10bde..52d096727bf 100644 --- a/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java +++ b/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java @@ -34,10 +34,13 @@ import org.elasticsearch.common.Table; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; +import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.monitor.fs.FsStats; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestTable; import java.io.IOException; +import java.util.Iterator; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -60,12 +63,12 @@ public class RestNodesAction extends BaseRestHandler { @Override public void onResponse(final ClusterStateResponse clusterStateResponse) { NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(); - nodesInfoRequest.clear().jvm(true).os(true); + nodesInfoRequest.clear().jvm(true).os(true).process(true); client.admin().cluster().nodesInfo(nodesInfoRequest, new ActionListener() { @Override public void onResponse(final NodesInfoResponse nodesInfoResponse) { NodesStatsRequest nodesStatsRequest = new NodesStatsRequest(); - nodesStatsRequest.clear().jvm(true); + nodesStatsRequest.clear().jvm(true).fs(true); client.admin().cluster().nodesStats(nodesStatsRequest, new ActionListener() { @Override public void onResponse(NodesStatsResponse nodesStatsResponse) { @@ -109,14 +112,17 @@ public class RestNodesAction extends BaseRestHandler { } private Table buildTable(ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) { + String masterId = state.getState().nodes().masterNodeId(); + Table table = new Table(); table.startHeaders(); table.addCell("id"); + table.addCell("pid"); table.addCell("ip"); table.addCell("port"); - // Considering supporting params like jvm, os, http to turn various columns on/off table.addCell("jdk"); + table.addCell("diskfree", "text-align:right;"); table.addCell("heapmax", "text-align:right;"); table.addCell("memmax", "text-align:right;"); @@ -127,16 +133,26 @@ public class RestNodesAction extends BaseRestHandler { table.endHeaders(); for (DiscoveryNode node : state.getState().nodes()) { - String masterId = state.getState().nodes().masterNodeId(); NodeInfo info = nodesInfo.getNodesMap().get(node.id()); NodeStats stats = nodesStats.getNodesMap().get(node.id()); + long availableDisk = -1; + + if (!(stats.getFs() == null)) { + availableDisk = 0; + Iterator it = stats.getFs().iterator(); + while (it.hasNext()) { + availableDisk += it.next().getAvailable().bytes(); + } + } table.startRow(); table.addCell(node.id()); + table.addCell(info.getProcess().id()); table.addCell(((InetSocketTransportAddress) node.address()).address().getAddress().getHostAddress()); table.addCell(((InetSocketTransportAddress) node.address()).address().getPort()); table.addCell(info.getJvm().version()); + table.addCell(availableDisk < 0 ? null : ByteSizeValue.parseBytesSizeValue(new Long(availableDisk).toString())); table.addCell(info.getJvm().mem().heapMax()); table.addCell(info.getOs().mem() == null ? null : info.getOs().mem().total()); // sigar fails to load in IntelliJ table.addCell(stats.getJvm().uptime()); diff --git a/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java b/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java index dde48bf1f43..5f41c17c928 100644 --- a/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java @@ -97,8 +97,8 @@ public class RestShardsAction extends BaseRestHandler { .addCell("shard", "default:true;") .addCell("p/r", "default:true;") .addCell("state", "default:true;") - .addCell("docs", "default:true;") - .addCell("store", "default:true;") + .addCell("docs", "text-align:right;") + .addCell("store", "text-align:right;") .addCell("ip", "default:true;") .addCell("node", "default:true;") .endHeaders(); @@ -115,8 +115,19 @@ public class RestShardsAction extends BaseRestHandler { table.addCell(shardStats == null ? null : shardStats.getDocs().getCount()); table.addCell(shardStats == null ? null : shardStats.getStore().getSize()); if (shard.assignedToNode()) { - table.addCell(((InetSocketTransportAddress) state.getState().nodes().get(shard.currentNodeId()).address()).address().getAddress().getHostAddress()); - table.addCell(state.getState().nodes().get(shard.currentNodeId()).name()); + String ip = ((InetSocketTransportAddress) state.getState().nodes().get(shard.currentNodeId()).address()).address().getAddress().getHostAddress(); + StringBuilder name = new StringBuilder(); + name.append(state.getState().nodes().get(shard.currentNodeId()).name()); + if (shard.relocating()) { + String reloIp = ((InetSocketTransportAddress) state.getState().nodes().get(shard.relocatingNodeId()).address()).address().getAddress().getHostAddress(); + String reloNme = state.getState().nodes().get(shard.relocatingNodeId()).name(); + name.append(" -> "); + name.append(reloIp); + name.append(" "); + name.append(reloNme); + } + table.addCell(ip); + table.addCell(name); } else { table.addCell(null); table.addCell(null);