use of org.apache.hadoop.hbase.client.RegionStatesCount in project hbase by apache.
the class HMaster method getClusterMetricsWithoutCoprocessor.
public ClusterMetrics getClusterMetricsWithoutCoprocessor(EnumSet<Option> options) throws InterruptedIOException {
ClusterMetricsBuilder builder = ClusterMetricsBuilder.newBuilder();
// we return all information to client if the list of Option is empty.
if (options.isEmpty()) {
options = EnumSet.allOf(Option.class);
}
// TASKS and/or LIVE_SERVERS will populate this map, which will be given to the builder if
// not null after option processing completes.
Map<ServerName, ServerMetrics> serverMetricsMap = null;
for (Option opt : options) {
switch(opt) {
case HBASE_VERSION:
builder.setHBaseVersion(VersionInfo.getVersion());
break;
case CLUSTER_ID:
builder.setClusterId(getClusterId());
break;
case MASTER:
builder.setMasterName(getServerName());
break;
case BACKUP_MASTERS:
builder.setBackerMasterNames(getBackupMasters());
break;
case TASKS:
{
// Master tasks
builder.setMasterTasks(TaskMonitor.get().getTasks().stream().map(task -> ServerTaskBuilder.newBuilder().setDescription(task.getDescription()).setStatus(task.getStatus()).setState(ServerTask.State.valueOf(task.getState().name())).setStartTime(task.getStartTime()).setCompletionTime(task.getCompletionTimestamp()).build()).collect(Collectors.toList()));
// Add entries to serverMetricsMap for all live servers, if we haven't already done so
if (serverMetricsMap == null) {
serverMetricsMap = getOnlineServers();
}
break;
}
case LIVE_SERVERS:
{
// Add entries to serverMetricsMap for all live servers, if we haven't already done so
if (serverMetricsMap == null) {
serverMetricsMap = getOnlineServers();
}
break;
}
case DEAD_SERVERS:
{
if (serverManager != null) {
builder.setDeadServerNames(new ArrayList<>(serverManager.getDeadServers().copyServerNames()));
}
break;
}
case MASTER_COPROCESSORS:
{
if (cpHost != null) {
builder.setMasterCoprocessorNames(Arrays.asList(getMasterCoprocessors()));
}
break;
}
case REGIONS_IN_TRANSITION:
{
if (assignmentManager != null) {
builder.setRegionsInTransition(assignmentManager.getRegionStates().getRegionsStateInTransition());
}
break;
}
case BALANCER_ON:
{
if (loadBalancerTracker != null) {
builder.setBalancerOn(loadBalancerTracker.isBalancerOn());
}
break;
}
case MASTER_INFO_PORT:
{
if (infoServer != null) {
builder.setMasterInfoPort(infoServer.getPort());
}
break;
}
case SERVERS_NAME:
{
if (serverManager != null) {
builder.setServerNames(serverManager.getOnlineServersList());
}
break;
}
case TABLE_TO_REGIONS_COUNT:
{
if (isActiveMaster() && isInitialized() && assignmentManager != null) {
try {
Map<TableName, RegionStatesCount> tableRegionStatesCountMap = new HashMap<>();
Map<String, TableDescriptor> tableDescriptorMap = getTableDescriptors().getAll();
for (TableDescriptor tableDescriptor : tableDescriptorMap.values()) {
TableName tableName = tableDescriptor.getTableName();
RegionStatesCount regionStatesCount = assignmentManager.getRegionStatesCount(tableName);
tableRegionStatesCountMap.put(tableName, regionStatesCount);
}
builder.setTableRegionStatesCount(tableRegionStatesCountMap);
} catch (IOException e) {
LOG.error("Error while populating TABLE_TO_REGIONS_COUNT for Cluster Metrics..", e);
}
}
break;
}
}
}
if (serverMetricsMap != null) {
builder.setLiveServerMetrics(serverMetricsMap);
}
return builder.build();
}
use of org.apache.hadoop.hbase.client.RegionStatesCount in project hbase by apache.
the class TestRegionsRecoveryChore method getClusterMetrics.
private static ClusterMetrics getClusterMetrics(int noOfLiveServer) {
ClusterMetrics clusterMetrics = new ClusterMetrics() {
@Nullable
@Override
public String getHBaseVersion() {
return null;
}
@Override
public List<ServerName> getDeadServerNames() {
return null;
}
@Override
public Map<ServerName, ServerMetrics> getLiveServerMetrics() {
Map<ServerName, ServerMetrics> liveServerMetrics = new HashMap<>();
for (int i = 0; i < noOfLiveServer; i++) {
ServerName serverName = ServerName.valueOf("rs_" + i, 16010, 12345);
liveServerMetrics.put(serverName, TestRegionsRecoveryChore.getServerMetrics(i + 3));
}
return liveServerMetrics;
}
@Nullable
@Override
public ServerName getMasterName() {
return null;
}
@Override
public List<ServerName> getBackupMasterNames() {
return null;
}
@Override
public List<RegionState> getRegionStatesInTransition() {
return null;
}
@Nullable
@Override
public String getClusterId() {
return null;
}
@Override
public List<String> getMasterCoprocessorNames() {
return null;
}
@Nullable
@Override
public Boolean getBalancerOn() {
return null;
}
@Override
public int getMasterInfoPort() {
return 0;
}
@Override
public List<ServerName> getServersName() {
return null;
}
@Override
public Map<TableName, RegionStatesCount> getTableRegionStatesCount() {
return null;
}
@Override
public List<ServerTask> getMasterTasks() {
return null;
}
};
return clusterMetrics;
}
use of org.apache.hadoop.hbase.client.RegionStatesCount in project hbase by apache.
the class TestClientClusterMetrics method testAsyncClient.
@Test
public void testAsyncClient() throws Exception {
try (AsyncConnection asyncConnect = ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get()) {
AsyncAdmin asyncAdmin = asyncConnect.getAdmin();
CompletableFuture<ClusterMetrics> originFuture = asyncAdmin.getClusterMetrics();
CompletableFuture<ClusterMetrics> defaultsFuture = asyncAdmin.getClusterMetrics(EnumSet.allOf(Option.class));
ClusterMetrics origin = originFuture.get();
ClusterMetrics defaults = defaultsFuture.get();
Assert.assertEquals(origin.getHBaseVersion(), defaults.getHBaseVersion());
Assert.assertEquals(origin.getClusterId(), defaults.getClusterId());
Assert.assertEquals(origin.getHBaseVersion(), defaults.getHBaseVersion());
Assert.assertEquals(origin.getClusterId(), defaults.getClusterId());
Assert.assertEquals(origin.getAverageLoad(), defaults.getAverageLoad(), 0);
Assert.assertEquals(origin.getBackupMasterNames().size(), defaults.getBackupMasterNames().size());
Assert.assertEquals(origin.getDeadServerNames().size(), defaults.getDeadServerNames().size());
Assert.assertEquals(origin.getRegionCount(), defaults.getRegionCount());
Assert.assertEquals(origin.getLiveServerMetrics().size(), defaults.getLiveServerMetrics().size());
Assert.assertEquals(origin.getMasterInfoPort(), defaults.getMasterInfoPort());
Assert.assertEquals(origin.getServersName().size(), defaults.getServersName().size());
origin.getTableRegionStatesCount().forEach(((tableName, regionStatesCount) -> {
RegionStatesCount defaultRegionStatesCount = defaults.getTableRegionStatesCount().get(tableName);
Assert.assertEquals(defaultRegionStatesCount, regionStatesCount);
}));
}
}
Aggregations