Java Code Examples for org.apache.hadoop.hbase.client.Admin#getClusterMetrics()

The following examples show how to use org.apache.hadoop.hbase.client.Admin#getClusterMetrics() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestReplicationStatusAfterLagging.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testReplicationStatusAfterLagging() throws Exception {
  UTIL2.shutdownMiniHBaseCluster();
  restartSourceCluster(1);
  // add some values to cluster 1
  for (int i = 0; i < NB_ROWS_IN_BATCH; i++) {
    Put p = new Put(Bytes.toBytes("row" + i));
    p.addColumn(famName, Bytes.toBytes("col1"), Bytes.toBytes("val" + i));
    htable1.put(p);
  }
  UTIL2.startMiniHBaseCluster();
  Thread.sleep(10000);
  Admin hbaseAdmin = UTIL1.getAdmin();
  ServerName serverName = UTIL1.getHBaseCluster().getRegionServer(0).getServerName();
  ClusterMetrics metrics = hbaseAdmin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
  List<ReplicationLoadSource> loadSources =
    metrics.getLiveServerMetrics().get(serverName).getReplicationLoadSourceList();
  assertEquals(1, loadSources.size());
  ReplicationLoadSource loadSource = loadSources.get(0);
  assertTrue(loadSource.hasEditsSinceRestart());
  assertTrue(loadSource.getTimestampOfLastShippedOp() > 0);
  assertEquals(0, loadSource.getReplicationLag());
}
 
Example 2
Source File: TestReplicationStatusSourceStartedTargetStoppedNewOp.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testReplicationStatusSourceStartedTargetStoppedNewOp() throws Exception {
  UTIL2.shutdownMiniHBaseCluster();
  restartSourceCluster(1);
  Admin hbaseAdmin = UTIL1.getAdmin();
  // add some values to source cluster
  for (int i = 0; i < NB_ROWS_IN_BATCH; i++) {
    Put p = new Put(Bytes.toBytes("row" + i));
    p.addColumn(famName, Bytes.toBytes("col1"), Bytes.toBytes("val" + i));
    htable1.put(p);
  }
  Thread.sleep(10000);
  ServerName serverName = UTIL1.getHBaseCluster().getRegionServer(0).getServerName();
  ClusterMetrics metrics = hbaseAdmin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
  List<ReplicationLoadSource> loadSources =
    metrics.getLiveServerMetrics().get(serverName).getReplicationLoadSourceList();
  assertEquals(1, loadSources.size());
  ReplicationLoadSource loadSource = loadSources.get(0);
  assertTrue(loadSource.hasEditsSinceRestart());
  assertEquals(0, loadSource.getTimestampOfLastShippedOp());
  assertTrue(loadSource.getReplicationLag() > 0);
  assertFalse(loadSource.isRecovered());
}
 
Example 3
Source File: TestReplicationStatusSourceStartedTargetStoppedNoOps.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testReplicationStatusSourceStartedTargetStoppedNoOps() throws Exception {
  UTIL2.shutdownMiniHBaseCluster();
  restartSourceCluster(1);
  Admin hbaseAdmin = UTIL1.getAdmin();
  ServerName serverName = UTIL1.getHBaseCluster().getRegionServer(0).getServerName();
  Thread.sleep(10000);
  ClusterMetrics metrics = hbaseAdmin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
  List<ReplicationLoadSource> loadSources =
    metrics.getLiveServerMetrics().get(serverName).getReplicationLoadSourceList();
  assertEquals(1, loadSources.size());
  ReplicationLoadSource loadSource = loadSources.get(0);
  assertFalse(loadSource.hasEditsSinceRestart());
  assertEquals(0, loadSource.getTimestampOfLastShippedOp());
  assertEquals(0, loadSource.getReplicationLag());
  assertFalse(loadSource.isRecovered());
}
 
Example 4
Source File: BaseTestHBaseFsck.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Get region info from local cluster.
 */
Map<ServerName, List<String>> getDeployedHRIs(final Admin admin) throws IOException {
  ClusterMetrics status = admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
  Collection<ServerName> regionServers = status.getLiveServerMetrics().keySet();
  Map<ServerName, List<String>> mm = new HashMap<>();
  for (ServerName hsi : regionServers) {
    // list all online regions from this region server
    List<RegionInfo> regions = admin.getRegions(hsi);
    List<String> regionNames = new ArrayList<>(regions.size());
    for (RegionInfo hri : regions) {
      regionNames.add(hri.getRegionNameAsString());
    }
    mm.put(hsi, regionNames);
  }
  return mm;
}
 
Example 5
Source File: TestReplicationStatusSink.java    From hbase with Apache License 2.0 5 votes vote down vote up
private ReplicationLoadSink getLatestSinkMetric(Admin admin, ServerName server)
    throws IOException {
  ClusterMetrics metrics =
    admin.getClusterMetrics(EnumSet.of(ClusterMetrics.Option.LIVE_SERVERS));
  ServerMetrics sm = metrics.getLiveServerMetrics().get(server);
  return sm.getReplicationLoadSink();
}
 
Example 6
Source File: TestReplicationStatusSourceStartedTargetStoppedWithRecovery.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testReplicationStatusSourceStartedTargetStoppedWithRecovery() throws Exception {
  UTIL2.shutdownMiniHBaseCluster();
  // add some values to cluster 1
  for (int i = 0; i < NB_ROWS_IN_BATCH; i++) {
    Put p = new Put(Bytes.toBytes("row" + i));
    p.addColumn(famName, Bytes.toBytes("col1"), Bytes.toBytes("val" + i));
    htable1.put(p);
  }
  Thread.sleep(10000);
  restartSourceCluster(1);
  Admin hbaseAdmin = UTIL1.getAdmin();
  ServerName serverName = UTIL1.getHBaseCluster().getRegionServer(0).getServerName();
  Thread.sleep(10000);
  ClusterMetrics metrics = hbaseAdmin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
  List<ReplicationLoadSource> loadSources =
    metrics.getLiveServerMetrics().get(serverName).getReplicationLoadSourceList();
  assertEquals(2, loadSources.size());
  boolean foundRecovery = false;
  boolean foundNormal = false;
  for (ReplicationLoadSource loadSource : loadSources) {
    if (loadSource.isRecovered()) {
      foundRecovery = true;
      assertTrue(loadSource.hasEditsSinceRestart());
      assertEquals(0, loadSource.getTimestampOfLastShippedOp());
      assertTrue(loadSource.getReplicationLag() > 0);
    } else {
      foundNormal = true;
      assertFalse(loadSource.hasEditsSinceRestart());
      assertEquals(0, loadSource.getTimestampOfLastShippedOp());
      assertEquals(0, loadSource.getReplicationLag());
    }
  }
  assertTrue("No normal queue found.", foundNormal);
  assertTrue("No recovery queue found.", foundRecovery);
}
 
Example 7
Source File: TestRSGroupsBase.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected Map<TableName, Map<ServerName, List<String>>> getTableServerRegionMap()
  throws IOException {
  Map<TableName, Map<ServerName, List<String>>> map = Maps.newTreeMap();
  Admin admin = TEST_UTIL.getAdmin();
  ClusterMetrics metrics =
    admin.getClusterMetrics(EnumSet.of(ClusterMetrics.Option.SERVERS_NAME));
  for (ServerName serverName : metrics.getServersName()) {
    for (RegionInfo region : admin.getRegions(serverName)) {
      TableName tableName = region.getTable();
      map.computeIfAbsent(tableName, k -> new TreeMap<>())
        .computeIfAbsent(serverName, k -> new ArrayList<>()).add(region.getRegionNameAsString());
    }
  }
  return map;
}
 
Example 8
Source File: IntegrationTestMTTR.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean doAction() throws Exception {
  Admin admin = null;
  try {
    admin = util.getAdmin();
    ClusterMetrics status = admin.getClusterMetrics();
    return status != null;
  } finally {
    if (admin != null) {
      admin.close();
    }
  }
}