Introduce abstract superclass, group cat module bindings, and short-circuit helps.
This commit is contained in:
commit
9e4b5ea242
|
@ -21,6 +21,7 @@ package org.elasticsearch.rest.action;
|
|||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.multibindings.Multibinder;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.action.admin.cluster.health.RestClusterHealthAction;
|
||||
import org.elasticsearch.rest.action.admin.cluster.node.hotthreads.RestNodesHotThreadsAction;
|
||||
|
@ -207,17 +208,20 @@ public class RestActionModule extends AbstractModule {
|
|||
|
||||
bind(RestExplainAction.class).asEagerSingleton();
|
||||
|
||||
bind(RestAllocationAction.class).asEagerSingleton();
|
||||
bind(RestShardsAction.class).asEagerSingleton();
|
||||
bind(RestMasterAction.class).asEagerSingleton();
|
||||
bind(RestNodesAction.class).asEagerSingleton();
|
||||
bind(RestIndicesAction.class).asEagerSingleton();
|
||||
// cat API
|
||||
Multibinder<AbstractCatAction> catActionMultibinder = Multibinder.newSetBinder(binder(), AbstractCatAction.class);
|
||||
catActionMultibinder.addBinding().to(RestAllocationAction.class).asEagerSingleton();
|
||||
catActionMultibinder.addBinding().to(RestShardsAction.class).asEagerSingleton();
|
||||
catActionMultibinder.addBinding().to(RestMasterAction.class).asEagerSingleton();
|
||||
catActionMultibinder.addBinding().to(RestNodesAction.class).asEagerSingleton();
|
||||
catActionMultibinder.addBinding().to(RestIndicesAction.class).asEagerSingleton();
|
||||
// Fully qualified to prevent interference with rest.action.count.RestCountAction
|
||||
bind(org.elasticsearch.rest.action.cat.RestCountAction.class).asEagerSingleton();
|
||||
bind(RestRecoveryAction.class).asEagerSingleton();
|
||||
bind(RestHealthAction.class).asEagerSingleton();
|
||||
catActionMultibinder.addBinding().to(org.elasticsearch.rest.action.cat.RestCountAction.class).asEagerSingleton();
|
||||
catActionMultibinder.addBinding().to(RestRecoveryAction.class).asEagerSingleton();
|
||||
catActionMultibinder.addBinding().to(RestHealthAction.class).asEagerSingleton();
|
||||
catActionMultibinder.addBinding().to(org.elasticsearch.rest.action.cat.RestPendingClusterTasksAction.class).asEagerSingleton();
|
||||
// no abstract cat action
|
||||
bind(RestCatAction.class).asEagerSingleton();
|
||||
bind(RestHelpAction.class).asEagerSingleton();
|
||||
bind(org.elasticsearch.rest.action.cat.RestPendingClusterTasksAction.class).asEagerSingleton();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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.client.Client;
|
||||
import org.elasticsearch.common.Table;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.rest.*;
|
||||
|
||||
import static org.elasticsearch.rest.action.support.RestTable.buildHelpWidths;
|
||||
import static org.elasticsearch.rest.action.support.RestTable.pad;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractCatAction extends BaseRestHandler {
|
||||
|
||||
public AbstractCatAction(Settings settings, Client client) {
|
||||
super(settings, client);
|
||||
}
|
||||
|
||||
abstract void doRequest(final RestRequest request, final RestChannel channel);
|
||||
abstract void documentation(StringBuilder sb);
|
||||
abstract Table getTableWithHeader(final RestRequest request);
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
boolean helpWanted = request.paramAsBoolean("h", false);
|
||||
if (helpWanted) {
|
||||
Table table = getTableWithHeader(request);
|
||||
int[] width = buildHelpWidths(table, request, false);
|
||||
StringBuilder out = new StringBuilder();
|
||||
for (Table.Cell cell : table.getHeaders()) {
|
||||
// need to do left-align always, so create new cells
|
||||
pad(new Table.Cell(cell.value), width[0], request, out);
|
||||
out.append(" ");
|
||||
pad(new Table.Cell(cell.attr.containsKey("desc") ? cell.attr.get("desc") : "not available"), width[1], request, out);
|
||||
out.append("\n");
|
||||
}
|
||||
channel.sendResponse(new StringRestResponse(RestStatus.OK, out.toString()));
|
||||
} else {
|
||||
doRequest(request, channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -46,7 +46,8 @@ import java.util.Locale;
|
|||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
|
||||
|
||||
public class RestAllocationAction extends BaseRestHandler{
|
||||
public class RestAllocationAction extends AbstractCatAction {
|
||||
|
||||
@Inject
|
||||
public RestAllocationAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
|
@ -55,7 +56,12 @@ public class RestAllocationAction extends BaseRestHandler{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
void documentation(StringBuilder sb) {
|
||||
sb.append("/_cat/allocation\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
final String[] nodes = Strings.splitStringByCommaToArray(request.param("nodes"));
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.filterMetaData(true);
|
||||
|
@ -72,7 +78,7 @@ public class RestAllocationAction extends BaseRestHandler{
|
|||
@Override
|
||||
public void onResponse(NodesStatsResponse stats) {
|
||||
try {
|
||||
Table tab = buildTable(state, stats);
|
||||
Table tab = buildTable(request, state, stats);
|
||||
channel.sendResponse(RestTable.buildResponse(tab, request, channel));
|
||||
} catch (Throwable e) {
|
||||
onFailure(e);
|
||||
|
@ -102,7 +108,21 @@ public class RestAllocationAction extends BaseRestHandler{
|
|||
|
||||
}
|
||||
|
||||
private Table buildTable(final ClusterStateResponse state, final NodesStatsResponse stats) {
|
||||
@Override
|
||||
Table getTableWithHeader(final RestRequest request) {
|
||||
final Table table = new Table();
|
||||
table.startHeaders();
|
||||
table.addCell("shards", "text-align:right;");
|
||||
table.addCell("diskUsed", "text-align:right;");
|
||||
table.addCell("diskAvail", "text-align:right;");
|
||||
table.addCell("diskRatio", "text-align:right;");
|
||||
table.addCell("ip");
|
||||
table.addCell("node");
|
||||
table.endHeaders();
|
||||
return table;
|
||||
}
|
||||
|
||||
private Table buildTable(RestRequest request, final ClusterStateResponse state, final NodesStatsResponse stats) {
|
||||
final ObjectIntOpenHashMap<String> allocs = new ObjectIntOpenHashMap<String>();
|
||||
|
||||
for (ShardRouting shard : state.getState().routingTable().allShards()) {
|
||||
|
@ -115,15 +135,7 @@ public class RestAllocationAction extends BaseRestHandler{
|
|||
allocs.addTo(nodeId, 1);
|
||||
}
|
||||
|
||||
final Table table = new Table();
|
||||
table.startHeaders();
|
||||
table.addCell("shards", "text-align:right;");
|
||||
table.addCell("diskUsed", "text-align:right;");
|
||||
table.addCell("diskAvail", "text-align:right;");
|
||||
table.addCell("diskRatio", "text-align:right;");
|
||||
table.addCell("ip");
|
||||
table.addCell("node");
|
||||
table.endHeaders();
|
||||
Table table = getTableWithHeader(request);
|
||||
|
||||
for (NodeStats nodeStats : stats.getNodes()) {
|
||||
DiscoveryNode node = nodeStats.getNode();
|
||||
|
|
|
@ -38,7 +38,7 @@ import java.io.IOException;
|
|||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
|
||||
public class RestCountAction extends BaseRestHandler {
|
||||
public class RestCountAction extends AbstractCatAction {
|
||||
|
||||
@Inject
|
||||
protected RestCountAction(Settings settings, Client client, RestController restController) {
|
||||
|
@ -48,7 +48,13 @@ public class RestCountAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
void documentation(StringBuilder sb) {
|
||||
sb.append("/_cat/count\n");
|
||||
sb.append("/_cat/count/{index}\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
CountRequest countRequest = new CountRequest(indices);
|
||||
countRequest.operationThreading(BroadcastOperationThreading.SINGLE_THREAD);
|
||||
|
@ -67,7 +73,7 @@ public class RestCountAction extends BaseRestHandler {
|
|||
@Override
|
||||
public void onResponse(CountResponse countResponse) {
|
||||
try {
|
||||
channel.sendResponse(RestTable.buildResponse(buildTable(countResponse), request, channel));
|
||||
channel.sendResponse(RestTable.buildResponse(buildTable(request, countResponse), request, channel));
|
||||
} catch (Throwable t) {
|
||||
onFailure(t);
|
||||
}
|
||||
|
@ -84,13 +90,17 @@ public class RestCountAction extends BaseRestHandler {
|
|||
});
|
||||
}
|
||||
|
||||
private Table buildTable(CountResponse response) {
|
||||
|
||||
@Override
|
||||
Table getTableWithHeader(final RestRequest request) {
|
||||
Table table = new TimestampedTable();
|
||||
table.startHeaders();
|
||||
table.addCell("count", "desc:the document count");
|
||||
table.endHeaders();
|
||||
return table;
|
||||
}
|
||||
|
||||
private Table buildTable(RestRequest request, CountResponse response) {
|
||||
Table table = getTableWithHeader(request);
|
||||
table.startRow();
|
||||
table.addCell(response.getCount());
|
||||
table.endRow();
|
||||
|
|
|
@ -35,7 +35,7 @@ import java.util.Locale;
|
|||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
|
||||
public class RestHealthAction extends BaseRestHandler {
|
||||
public class RestHealthAction extends AbstractCatAction {
|
||||
|
||||
@Inject
|
||||
public RestHealthAction(Settings settings, Client client, RestController controller) {
|
||||
|
@ -44,15 +44,19 @@ public class RestHealthAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
void documentation(StringBuilder sb) {
|
||||
sb.append("/_cat/health\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
ClusterHealthRequest clusterHealthRequest = new ClusterHealthRequest();
|
||||
final boolean timeStamp = request.paramAsBoolean("ts", true);
|
||||
|
||||
client.admin().cluster().health(clusterHealthRequest, new ActionListener<ClusterHealthResponse>() {
|
||||
@Override
|
||||
public void onResponse(final ClusterHealthResponse health) {
|
||||
try {
|
||||
channel.sendResponse(RestTable.buildResponse(buildTable(health, timeStamp), request, channel));
|
||||
channel.sendResponse(RestTable.buildResponse(buildTable(health, request), request, channel));
|
||||
} catch (Throwable t) {
|
||||
onFailure(t);
|
||||
}
|
||||
|
@ -69,28 +73,33 @@ public class RestHealthAction extends BaseRestHandler {
|
|||
});
|
||||
}
|
||||
|
||||
private Table buildTable (final ClusterHealthResponse health, boolean timeStamp) {
|
||||
@Override
|
||||
Table getTableWithHeader(final RestRequest request) {
|
||||
final boolean timeStamp = request.paramAsBoolean("ts", true);
|
||||
Table t;
|
||||
|
||||
if (timeStamp) {
|
||||
t = new TimestampedTable();
|
||||
} else {
|
||||
t = new Table();
|
||||
}
|
||||
t.startHeaders();
|
||||
t.addCell("cluster");
|
||||
t.addCell("status");
|
||||
t.addCell("nodeTotal", "text-align:right;");
|
||||
t.addCell("nodeData", "text-align:right;");
|
||||
t.addCell("shards", "text-align:right;");
|
||||
t.addCell("pri", "text-align:right;");
|
||||
t.addCell("relo", "text-align:right;");
|
||||
t.addCell("init", "text-align:right;");
|
||||
t.addCell("unassign", "text-align:right;");
|
||||
t.endHeaders();
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
private Table buildTable (final ClusterHealthResponse health, final RestRequest request) {
|
||||
if (null != health) {
|
||||
t.startHeaders();
|
||||
t.addCell("cluster");
|
||||
t.addCell("status");
|
||||
t.addCell("nodeTotal", "text-align:right;");
|
||||
t.addCell("nodeData", "text-align:right;");
|
||||
t.addCell("shards", "text-align:right;");
|
||||
t.addCell("pri", "text-align:right;");
|
||||
t.addCell("relo", "text-align:right;");
|
||||
t.addCell("init", "text-align:right;");
|
||||
t.addCell("unassign", "text-align:right;");
|
||||
t.endHeaders();
|
||||
|
||||
Table t = getTableWithHeader(request);
|
||||
t.startRow();
|
||||
t.addCell(health.getClusterName());
|
||||
t.addCell(health.getStatus().name().toLowerCase(Locale.ROOT));
|
||||
|
@ -102,7 +111,8 @@ public class RestHealthAction extends BaseRestHandler {
|
|||
t.addCell(health.getInitializingShards());
|
||||
t.addCell(health.getUnassignedShards());
|
||||
t.endRow();
|
||||
return t;
|
||||
}
|
||||
return t;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,42 +20,33 @@
|
|||
package org.elasticsearch.rest.action.cat;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.inject.Guice;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.rest.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
|
||||
|
||||
public class RestHelpAction extends BaseRestHandler {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@Inject
|
||||
public RestHelpAction(Settings settings, Client client, RestController controller) {
|
||||
public RestHelpAction(Settings settings, Client client, RestController controller, Set<AbstractCatAction> catActions) {
|
||||
super(settings, client);
|
||||
controller.registerHandler(GET, "/_cat/help", this);
|
||||
controller.registerHandler(GET, "/_cat/halp", this);
|
||||
sb.append("Try:\n\n");
|
||||
sb.append("/_cat/help\n");
|
||||
for (AbstractCatAction catAction : catActions) {
|
||||
catAction.documentation(sb);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
// Maybe build this list from a classloader or the RestActionModule injector
|
||||
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append("Try:\n\n");
|
||||
s.append("/_cat/allocation\n");
|
||||
s.append("/_cat/count\n");
|
||||
s.append("/_cat/count/{index}\n");
|
||||
s.append("/_cat/health\n");
|
||||
s.append("/_cat/indices\n");
|
||||
s.append("/_cat/indices/{index}\n");
|
||||
s.append("/_cat/master\n");
|
||||
s.append("/_cat/nodes\n");
|
||||
s.append("/_cat/pending_tasks\n");
|
||||
s.append("/_cat/recovery\n");
|
||||
s.append("/_cat/shards\n");
|
||||
s.append("/_cat/shards/{index}\n");
|
||||
channel.sendResponse(new StringRestResponse(RestStatus.OK, s.toString()));
|
||||
channel.sendResponse(new StringRestResponse(RestStatus.OK, sb.toString()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,11 +39,10 @@ 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;
|
||||
|
||||
public class RestIndicesAction extends BaseRestHandler {
|
||||
public class RestIndicesAction extends AbstractCatAction {
|
||||
|
||||
@Inject
|
||||
public RestIndicesAction(Settings settings, Client client, RestController controller) {
|
||||
|
@ -53,7 +52,13 @@ public class RestIndicesAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
void documentation(StringBuilder sb) {
|
||||
sb.append("/_cat/indices\n");
|
||||
sb.append("/_cat/indices/{index}\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.filteredIndices(indices);
|
||||
|
@ -75,7 +80,7 @@ public class RestIndicesAction extends BaseRestHandler {
|
|||
@Override
|
||||
public void onResponse(IndicesStatsResponse indicesStatsResponse) {
|
||||
try {
|
||||
Table tab = buildTable(concreteIndices, clusterHealthResponse, indicesStatsResponse);
|
||||
Table tab = buildTable(request, concreteIndices, clusterHealthResponse, indicesStatsResponse);
|
||||
channel.sendResponse(RestTable.buildResponse(tab, request, channel));
|
||||
} catch (Throwable e) {
|
||||
onFailure(e);
|
||||
|
@ -116,7 +121,8 @@ public class RestIndicesAction extends BaseRestHandler {
|
|||
});
|
||||
}
|
||||
|
||||
private Table buildTable(String[] indices, ClusterHealthResponse health, IndicesStatsResponse stats) {
|
||||
@Override
|
||||
Table getTableWithHeader(final RestRequest request) {
|
||||
Table table = new Table();
|
||||
table.startHeaders();
|
||||
table.addCell("health");
|
||||
|
@ -128,6 +134,11 @@ public class RestIndicesAction extends BaseRestHandler {
|
|||
table.addCell("size/pri", "text-align:right;");
|
||||
table.addCell("size/total", "text-align:right;");
|
||||
table.endHeaders();
|
||||
return table;
|
||||
}
|
||||
|
||||
private Table buildTable(RestRequest request, String[] indices, ClusterHealthResponse health, IndicesStatsResponse stats) {
|
||||
Table table = getTableWithHeader(request);
|
||||
|
||||
for (String index : indices) {
|
||||
ClusterIndexHealth indexHealth = health.getIndices().get(index);
|
||||
|
|
|
@ -34,7 +34,7 @@ import java.io.IOException;
|
|||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
|
||||
public class RestMasterAction extends BaseRestHandler {
|
||||
public class RestMasterAction extends AbstractCatAction {
|
||||
|
||||
@Inject
|
||||
public RestMasterAction(Settings settings, Client client, RestController controller) {
|
||||
|
@ -43,7 +43,12 @@ public class RestMasterAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
void documentation(StringBuilder sb) {
|
||||
sb.append("/_cat/master\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.filterMetaData(true);
|
||||
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
|
||||
|
@ -53,7 +58,7 @@ public class RestMasterAction extends BaseRestHandler {
|
|||
@Override
|
||||
public void onResponse(final ClusterStateResponse clusterStateResponse) {
|
||||
try {
|
||||
channel.sendResponse(RestTable.buildResponse(buildTable(clusterStateResponse), request, channel));
|
||||
channel.sendResponse(RestTable.buildResponse(buildTable(request, clusterStateResponse), request, channel));
|
||||
} catch (Throwable e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -70,14 +75,19 @@ public class RestMasterAction extends BaseRestHandler {
|
|||
});
|
||||
}
|
||||
|
||||
private Table buildTable(ClusterStateResponse state) {
|
||||
@Override
|
||||
Table getTableWithHeader(final RestRequest request) {
|
||||
Table table = new Table();
|
||||
table.startHeaders()
|
||||
.addCell("id")
|
||||
.addCell("ip")
|
||||
.addCell("node")
|
||||
.endHeaders();
|
||||
return table;
|
||||
}
|
||||
|
||||
private Table buildTable(RestRequest request, ClusterStateResponse state) {
|
||||
Table table = getTableWithHeader(request);
|
||||
String masterId = state.getState().nodes().masterNodeId();
|
||||
String masterIp = ((InetSocketTransportAddress) state.getState().nodes().get(masterId).address()).address().getAddress().getHostAddress();
|
||||
String masterName = state.getState().nodes().masterNode().name();
|
||||
|
|
|
@ -45,7 +45,7 @@ import java.util.Locale;
|
|||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
|
||||
public class RestNodesAction extends BaseRestHandler {
|
||||
public class RestNodesAction extends AbstractCatAction {
|
||||
|
||||
@Inject
|
||||
public RestNodesAction(Settings settings, Client client, RestController controller) {
|
||||
|
@ -54,7 +54,12 @@ public class RestNodesAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
void documentation(StringBuilder sb) {
|
||||
sb.append("/_cat/nodes\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.filterMetaData(true);
|
||||
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
|
||||
|
@ -112,11 +117,8 @@ public class RestNodesAction extends BaseRestHandler {
|
|||
});
|
||||
}
|
||||
|
||||
private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) {
|
||||
boolean fullId = req.paramAsBoolean("full_id", false);
|
||||
|
||||
String masterId = state.getState().nodes().masterNodeId();
|
||||
|
||||
@Override
|
||||
Table getTableWithHeader(final RestRequest request) {
|
||||
Table table = new Table();
|
||||
table.startHeaders();
|
||||
table.addCell("nodeId");
|
||||
|
@ -138,6 +140,14 @@ public class RestNodesAction extends BaseRestHandler {
|
|||
table.addCell("master");
|
||||
table.addCell("name");
|
||||
table.endHeaders();
|
||||
return table;
|
||||
}
|
||||
|
||||
private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) {
|
||||
boolean fullId = req.paramAsBoolean("full_id", false);
|
||||
|
||||
String masterId = state.getState().nodes().masterNodeId();
|
||||
Table table = getTableWithHeader(req);
|
||||
|
||||
for (DiscoveryNode node : state.getState().nodes()) {
|
||||
NodeInfo info = nodesInfo.getNodesMap().get(node.id());
|
||||
|
|
|
@ -34,7 +34,7 @@ import java.io.IOException;
|
|||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
|
||||
public class RestPendingClusterTasksAction extends BaseRestHandler {
|
||||
public class RestPendingClusterTasksAction extends AbstractCatAction {
|
||||
@Inject
|
||||
public RestPendingClusterTasksAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
|
@ -42,13 +42,18 @@ public class RestPendingClusterTasksAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
void documentation(StringBuilder sb) {
|
||||
sb.append("/_cat/pending_tasks\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
PendingClusterTasksRequest pendingClusterTasksRequest = new PendingClusterTasksRequest();
|
||||
client.admin().cluster().pendingClusterTasks(pendingClusterTasksRequest, new ActionListener<PendingClusterTasksResponse>() {
|
||||
@Override
|
||||
public void onResponse(PendingClusterTasksResponse pendingClusterTasks) {
|
||||
try {
|
||||
Table tab = buildTable(pendingClusterTasks);
|
||||
Table tab = buildTable(request, pendingClusterTasks);
|
||||
channel.sendResponse(RestTable.buildResponse(tab, request, channel));
|
||||
} catch (Throwable e) {
|
||||
onFailure(e);
|
||||
|
@ -66,15 +71,20 @@ public class RestPendingClusterTasksAction extends BaseRestHandler {
|
|||
});
|
||||
}
|
||||
|
||||
private Table buildTable(PendingClusterTasksResponse tasks) {
|
||||
@Override
|
||||
Table getTableWithHeader(final RestRequest request) {
|
||||
Table t = new Table();
|
||||
|
||||
t.startHeaders();
|
||||
t.addCell("insertOrder", "text-align:right;desc:Task insertion order");
|
||||
t.addCell("timeInQueue", "text-align:right;desc:How long task has been in queue");
|
||||
t.addCell("priority", "desc:Task priority");
|
||||
t.addCell("source", "desc:Task source");
|
||||
t.endHeaders();
|
||||
return t;
|
||||
}
|
||||
|
||||
private Table buildTable(RestRequest request, PendingClusterTasksResponse tasks) {
|
||||
Table t = getTableWithHeader(request);
|
||||
|
||||
for (PendingClusterTask task : tasks) {
|
||||
t.startRow();
|
||||
|
|
|
@ -47,7 +47,7 @@ import static org.elasticsearch.rest.RestRequest.Method.GET;
|
|||
* in a string format, designed to be used at the command line. An Index can
|
||||
* be specified to limit output to a particular index or indices.
|
||||
*/
|
||||
public class RestRecoveryAction extends BaseRestHandler {
|
||||
public class RestRecoveryAction extends AbstractCatAction {
|
||||
|
||||
@Inject
|
||||
protected RestRecoveryAction(Settings settings, Client client, RestController restController) {
|
||||
|
@ -57,7 +57,13 @@ public class RestRecoveryAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
void documentation(StringBuilder sb) {
|
||||
sb.append("/_cat/recovery\n");
|
||||
sb.append("/_cat/recovery/{index}\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.filterMetaData(true);
|
||||
|
@ -90,7 +96,7 @@ public class RestRecoveryAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
try {
|
||||
channel.sendResponse(RestTable.buildResponse(buildRecoveryTable(clusterStateResponse, primarySizes, replicas), request, channel));
|
||||
channel.sendResponse(RestTable.buildResponse(buildRecoveryTable(request, clusterStateResponse, primarySizes, replicas), request, channel));
|
||||
} catch (Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new XContentThrowableRestResponse(request, e));
|
||||
|
@ -123,15 +129,8 @@ public class RestRecoveryAction extends BaseRestHandler {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* buildRecoveryTable will build a table of recovery information suitable
|
||||
* for displaying at the command line.
|
||||
* @param state Current cluster state.
|
||||
* @param primarySizes A Map of {@code index + shardId} strings to store size for all primary shards.
|
||||
* @param recoveringReplicas A Set of {@link ShardStatus} objects for each recovering replica to be displayed.
|
||||
* @return A table containing index, shardId, node, target size, recovered size and percentage for each recovering replica
|
||||
*/
|
||||
public static Table buildRecoveryTable(ClusterStateResponse state, Map<String, Long> primarySizes, Set<ShardStatus> recoveringReplicas) {
|
||||
@Override
|
||||
Table getTableWithHeader(RestRequest request) {
|
||||
Table t = new Table();
|
||||
t.startHeaders().addCell("index")
|
||||
.addCell("shard")
|
||||
|
@ -141,6 +140,21 @@ public class RestRecoveryAction extends BaseRestHandler {
|
|||
.addCell("ip")
|
||||
.addCell("node")
|
||||
.endHeaders();
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* buildRecoveryTable will build a table of recovery information suitable
|
||||
* for displaying at the command line.
|
||||
*
|
||||
* @param request
|
||||
* @param state Current cluster state.
|
||||
* @param primarySizes A Map of {@code index + shardId} strings to store size for all primary shards.
|
||||
* @param recoveringReplicas A Set of {@link org.elasticsearch.action.admin.indices.status.ShardStatus} objects for each recovering replica to be displayed.
|
||||
* @return A table containing index, shardId, node, target size, recovered size and percentage for each recovering replica
|
||||
*/
|
||||
public Table buildRecoveryTable(RestRequest request, ClusterStateResponse state, Map<String, Long> primarySizes, Set<ShardStatus> recoveringReplicas) {
|
||||
Table t = getTableWithHeader(request);
|
||||
for (ShardStatus status : recoveringReplicas) {
|
||||
DiscoveryNode node = state.getState().nodes().get(status.getShardRouting().currentNodeId());
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ import java.util.Set;
|
|||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
|
||||
public class RestShardsAction extends BaseRestHandler {
|
||||
public class RestShardsAction extends AbstractCatAction {
|
||||
|
||||
@Inject
|
||||
public RestShardsAction(Settings settings, Client client, RestController controller) {
|
||||
|
@ -51,7 +51,13 @@ public class RestShardsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
void documentation(StringBuilder sb) {
|
||||
sb.append("/_cat/shards\n");
|
||||
sb.append("/_cat/shards/{index}\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
|
||||
|
@ -67,7 +73,7 @@ public class RestShardsAction extends BaseRestHandler {
|
|||
@Override
|
||||
public void onResponse(IndicesStatsResponse indicesStatsResponse) {
|
||||
try {
|
||||
channel.sendResponse(RestTable.buildResponse(buildTable(concreteIndices, clusterStateResponse, indicesStatsResponse), request, channel));
|
||||
channel.sendResponse(RestTable.buildResponse(buildTable(request, concreteIndices, clusterStateResponse, indicesStatsResponse), request, channel));
|
||||
} catch (Throwable e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -95,8 +101,8 @@ public class RestShardsAction extends BaseRestHandler {
|
|||
});
|
||||
}
|
||||
|
||||
private Table buildTable(String[] concreteIndices, ClusterStateResponse state, IndicesStatsResponse stats) {
|
||||
Set<String> indices = Sets.newHashSet(concreteIndices);
|
||||
@Override
|
||||
Table getTableWithHeader(final RestRequest request) {
|
||||
Table table = new Table();
|
||||
table.startHeaders()
|
||||
.addCell("index", "default:true;")
|
||||
|
@ -108,7 +114,13 @@ public class RestShardsAction extends BaseRestHandler {
|
|||
.addCell("ip", "default:true;")
|
||||
.addCell("node", "default:true;")
|
||||
.endHeaders();
|
||||
return table;
|
||||
}
|
||||
|
||||
private Table buildTable(RestRequest request, String[] concreteIndices, ClusterStateResponse state, IndicesStatsResponse stats) {
|
||||
Table table = getTableWithHeader(request);
|
||||
|
||||
Set<String> indices = Sets.newHashSet(concreteIndices);
|
||||
for (ShardRouting shard : state.getState().routingTable().allShards()) {
|
||||
if (!indices.contains(shard.index())) {
|
||||
continue;
|
||||
|
|
|
@ -127,7 +127,7 @@ public class RestTable {
|
|||
return display;
|
||||
}
|
||||
|
||||
private static int[] buildHelpWidths(Table table, RestRequest request, boolean verbose) {
|
||||
public static int[] buildHelpWidths(Table table, RestRequest request, boolean verbose) {
|
||||
int[] width = new int[2];
|
||||
for (Table.Cell cell : table.getHeaders()) {
|
||||
String v = renderValue(request, cell.value);
|
||||
|
@ -170,7 +170,7 @@ public class RestTable {
|
|||
return width;
|
||||
}
|
||||
|
||||
private static void pad(Table.Cell cell, int width, RestRequest request, StringBuilder out) {
|
||||
public static void pad(Table.Cell cell, int width, RestRequest request, StringBuilder out) {
|
||||
String sValue = renderValue(request, cell.value);
|
||||
int length = sValue == null ? 0 : sValue.length();
|
||||
byte leftOver = (byte) (width - length);
|
||||
|
|
Loading…
Reference in New Issue