Search in sources :

Example 1 with ObjectIntScatterMap

use of com.carrotsearch.hppc.ObjectIntScatterMap in project elasticsearch by elastic.

the class RestAllocationAction method buildTable.

private Table buildTable(RestRequest request, final ClusterStateResponse state, final NodesStatsResponse stats) {
    final ObjectIntScatterMap<String> allocs = new ObjectIntScatterMap<>();
    for (ShardRouting shard : state.getState().routingTable().allShards()) {
        String nodeId = "UNASSIGNED";
        if (shard.assignedToNode()) {
            nodeId = shard.currentNodeId();
        }
        allocs.addTo(nodeId, 1);
    }
    Table table = getTableWithHeader(request);
    for (NodeStats nodeStats : stats.getNodes()) {
        DiscoveryNode node = nodeStats.getNode();
        int shardCount = allocs.getOrDefault(node.getId(), 0);
        ByteSizeValue total = nodeStats.getFs().getTotal().getTotal();
        ByteSizeValue avail = nodeStats.getFs().getTotal().getAvailable();
        //if we don't know how much we use (non data nodes), it means 0
        long used = 0;
        short diskPercent = -1;
        if (total.getBytes() > 0) {
            used = total.getBytes() - avail.getBytes();
            if (used >= 0 && avail.getBytes() >= 0) {
                diskPercent = (short) (used * 100 / (used + avail.getBytes()));
            }
        }
        table.startRow();
        table.addCell(shardCount);
        table.addCell(nodeStats.getIndices().getStore().getSize());
        table.addCell(used < 0 ? null : new ByteSizeValue(used));
        table.addCell(avail.getBytes() < 0 ? null : avail);
        table.addCell(total.getBytes() < 0 ? null : total);
        table.addCell(diskPercent < 0 ? null : diskPercent);
        table.addCell(node.getHostName());
        table.addCell(node.getHostAddress());
        table.addCell(node.getName());
        table.endRow();
    }
    final String UNASSIGNED = "UNASSIGNED";
    if (allocs.containsKey(UNASSIGNED)) {
        table.startRow();
        table.addCell(allocs.get(UNASSIGNED));
        table.addCell(null);
        table.addCell(null);
        table.addCell(null);
        table.addCell(null);
        table.addCell(null);
        table.addCell(null);
        table.addCell(null);
        table.addCell(UNASSIGNED);
        table.endRow();
    }
    return table;
}
Also used : NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ObjectIntScatterMap(com.carrotsearch.hppc.ObjectIntScatterMap) Table(org.elasticsearch.common.Table) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Aggregations

ObjectIntScatterMap (com.carrotsearch.hppc.ObjectIntScatterMap)1 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)1 Table (org.elasticsearch.common.Table)1 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)1