use of org.apache.hadoop.hbase.ClusterStatus in project hbase by apache.
the class TestRSGroupsBase method getTableServerRegionMap.
public Map<TableName, Map<ServerName, List<String>>> getTableServerRegionMap() throws IOException {
Map<TableName, Map<ServerName, List<String>>> map = Maps.newTreeMap();
ClusterStatus status = TEST_UTIL.getHBaseClusterInterface().getClusterStatus();
for (ServerName serverName : status.getServers()) {
for (RegionLoad rl : status.getLoad(serverName).getRegionsLoad().values()) {
TableName tableName = null;
try {
tableName = HRegionInfo.getTable(rl.getName());
} catch (IllegalArgumentException e) {
LOG.warn("Failed parse a table name from regionname=" + Bytes.toStringBinary(rl.getName()));
continue;
}
if (!map.containsKey(tableName)) {
map.put(tableName, new TreeMap<>());
}
if (!map.get(tableName).containsKey(serverName)) {
map.get(tableName).put(serverName, new LinkedList<>());
}
map.get(tableName).get(serverName).add(rl.getNameAsString());
}
}
return map;
}
use of org.apache.hadoop.hbase.ClusterStatus in project hbase by apache.
the class TestRSGroupsBase method getNumServers.
// return the real number of region servers, excluding the master embedded region server in 2.0+
public int getNumServers() throws IOException {
ClusterStatus status = admin.getClusterStatus();
ServerName master = status.getMaster();
int count = 0;
for (ServerName sn : status.getServers()) {
if (!sn.equals(master)) {
count++;
}
}
return count;
}
use of org.apache.hadoop.hbase.ClusterStatus in project cdap by caskdata.
the class HBaseTableUtil method getTableStats.
/**
* Collects HBase table stats
* //TODO: Explore the possiblitity of returning a {@code Map<TableId, TableStats>}
* @param admin instance of {@link HBaseAdmin} to communicate with HBase
* @return map of table name -> table stats
* @throws IOException
*/
public Map<TableId, TableStats> getTableStats(HBaseAdmin admin) throws IOException {
// The idea is to walk thru live region servers, collect table region stats and aggregate them towards table total
// metrics.
Map<TableId, TableStats> datasetStat = Maps.newHashMap();
ClusterStatus clusterStatus = admin.getClusterStatus();
for (ServerName serverName : clusterStatus.getServers()) {
Map<byte[], RegionLoad> regionsLoad = clusterStatus.getLoad(serverName).getRegionsLoad();
for (RegionLoad regionLoad : regionsLoad.values()) {
TableName tableName = HRegionInfo.getTable(regionLoad.getName());
HTableDescriptor tableDescriptor;
try {
tableDescriptor = admin.getTableDescriptor(tableName);
} catch (TableNotFoundException exception) {
// this can happen if the table has been deleted; the region stats get removed afterwards
LOG.warn("Table not found for table name {}. Skipping collecting stats for it. Reason: {}", tableName, exception.getMessage());
continue;
}
if (!isCDAPTable(tableDescriptor)) {
continue;
}
TableId tableId = HTableNameConverter.from(tableDescriptor);
TableStats stat = datasetStat.get(tableId);
if (stat == null) {
stat = new TableStats(regionLoad.getStorefileSizeMB(), regionLoad.getMemStoreSizeMB());
datasetStat.put(tableId, stat);
} else {
stat.incStoreFileSizeMB(regionLoad.getStorefileSizeMB());
stat.incMemStoreSizeMB(regionLoad.getMemStoreSizeMB());
}
}
}
return datasetStat;
}
Aggregations