/** * Get cluster status with a set of {@link Option} to get desired status. * @return cluster status * @throws IOException if a remote or network exception occurs */ ClusterMetrics getClusterMetrics(EnumSet<Option> options) throws IOException;
/** * Get the info port of the current master if one is available. * @return master info port * @throws IOException */ default int getMasterInfoPort() throws IOException { return getClusterMetrics(EnumSet.of(Option.MASTER_INFO_PORT)).getMasterInfoPort(); }
/** * @return current master server name * @throws IOException if a remote or network exception occurs */ default ServerName getMaster() throws IOException { return getClusterMetrics(EnumSet.of(Option.MASTER)).getMasterName(); }
/** * @return current backup master list * @throws IOException if a remote or network exception occurs */ default Collection<ServerName> getBackupMasters() throws IOException { return getClusterMetrics(EnumSet.of(Option.BACKUP_MASTERS)).getBackupMasterNames(); }
/** * Returns a ClusterStatus for this HBase cluster * @throws IOException */ @Override public ClusterMetrics getClusterMetrics() throws IOException { return admin.getClusterMetrics(); }
/** * @return current live region servers list * @throws IOException if a remote or network exception occurs */ default Collection<ServerName> getRegionServers() throws IOException { return getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet(); }
/** * Helper that delegates to getClusterMetrics().getMasterCoprocessorNames(). * @return an array of master coprocessors * @see org.apache.hadoop.hbase.ClusterMetrics#getMasterCoprocessorNames() */ default List<String> getMasterCoprocessorNames() throws IOException { return getClusterMetrics(EnumSet.of(Option.MASTER_COPROCESSORS)) .getMasterCoprocessorNames(); }
/** * List dead region servers. * @return List of dead region servers. */ default List<ServerName> listDeadServers() throws IOException { return getClusterMetrics(EnumSet.of(Option.DEAD_SERVERS)).getDeadServerNames(); }
/** * Alternative getCurrentNrHRS which is no longer available. * @param connection * @return Rough count of regionservers out on cluster. * @throws IOException if a remote or network exception occurs */ private static int getRegionServerCount(final Connection connection) throws IOException { try (Admin admin = connection.getAdmin()) { ClusterMetrics status = admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)); Collection<ServerName> servers = status.getLiveServerMetrics().keySet(); return servers == null || servers.isEmpty()? 0: servers.size(); } }
/** * Exclude master from list of RSs to move regions to */ private void stripMaster(List<ServerName> regionServers) throws IOException { ServerName master = admin.getClusterMetrics(EnumSet.of(Option.MASTER)).getMasterName(); stripServer(regionServers, master.getHostname(), master.getPort()); }
static ServerName [] getServers(Admin admin) throws IOException { Collection<ServerName> serversList = admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet(); return serversList.toArray(new ServerName[serversList.size()]); }
@Override public boolean evaluate() throws Exception { ClusterMetrics metrics = ADMIN.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)); Assert.assertNotNull(metrics); return metrics.getRegionCount() > 0; } });
@Test public void testObserver() throws IOException { int preCount = MyObserver.PRE_COUNT.get(); int postCount = MyObserver.POST_COUNT.get(); Assert.assertTrue(ADMIN.getClusterMetrics().getMasterCoprocessorNames().stream() .anyMatch(s -> s.equals(MyObserver.class.getSimpleName()))); Assert.assertEquals(preCount + 1, MyObserver.PRE_COUNT.get()); Assert.assertEquals(postCount + 1, MyObserver.POST_COUNT.get()); }
public int getNumServers() throws IOException { ClusterMetrics status = admin.getClusterMetrics(EnumSet.of(Option.MASTER, Option.LIVE_SERVERS)); ServerName masterName = status.getMasterName(); int count = 0; for (ServerName sn : status.getLiveServerMetrics().keySet()) { if (!sn.equals(masterName)) { count++; } } return count; }
@Override public boolean evaluate() throws Exception { ClusterStatus status = new ClusterStatus(ADMIN.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS))); Assert.assertNotNull(status); return status.getRegionsCount() > 0; } });
@Test public void testNone() throws Exception { ClusterMetrics status0 = ADMIN.getClusterMetrics(EnumSet.allOf(Option.class)); ClusterMetrics status1 = ADMIN.getClusterMetrics(EnumSet.noneOf(Option.class)); // Do a rough compare. More specific compares can fail because all regions not deployed yet // or more requests than expected. Assert.assertEquals(status0.getLiveServerMetrics().size(), status1.getLiveServerMetrics().size()); checkPbObjectNotNull(new ClusterStatus(status0)); checkPbObjectNotNull(new ClusterStatus(status1)); }
@BeforeClass public static void setupBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); conf.setBoolean("hbase.tests.use.shortcircuit.reads", false); TEST_UTIL.startMiniCluster(numSlaves); CONNECTION = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration()); ADMIN = CONNECTION.getAdmin(); while(ADMIN.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)) .getLiveServerMetrics().size() < numSlaves) { Thread.sleep(100); } }
private void testReadRequests(byte[] regionName, int expectedReadRequests) throws Exception { for (ServerName serverName : serverNames) { ServerLoad serverLoad = new ServerLoad(admin.getClusterMetrics( EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().get(serverName)); Map<byte[], RegionLoad> regionsLoad = serverLoad.getRegionsLoad(); RegionLoad regionLoad = regionsLoad.get(regionName); if (regionLoad != null) { LOG.debug("server read request is " + serverLoad.getReadRequestsCount() + ", region read request is " + regionLoad.getReadRequestsCount()); assertEquals(3, serverLoad.getReadRequestsCount()); assertEquals(3, regionLoad.getReadRequestsCount()); } } }
@Test public void testOtherStatusInfos() throws Exception { EnumSet<Option> options = EnumSet.of(Option.MASTER_COPROCESSORS, Option.HBASE_VERSION, Option.CLUSTER_ID, Option.BALANCER_ON); ClusterMetrics metrics = ADMIN.getClusterMetrics(options); Assert.assertEquals(1, metrics.getMasterCoprocessorNames().size()); Assert.assertNotNull(metrics.getHBaseVersion()); Assert.assertNotNull(metrics.getClusterId()); Assert.assertTrue(metrics.getAverageLoad() == 0.0); Assert.assertNotNull(metrics.getBalancerOn()); }
@Test public void testOtherStatusInfos() throws Exception { EnumSet<Option> options = EnumSet.of(Option.MASTER_COPROCESSORS, Option.HBASE_VERSION, Option.CLUSTER_ID, Option.BALANCER_ON); ClusterStatus status = new ClusterStatus(ADMIN.getClusterMetrics(options)); Assert.assertTrue(status.getMasterCoprocessors().length == 1); Assert.assertNotNull(status.getHBaseVersion()); Assert.assertNotNull(status.getClusterId()); Assert.assertTrue(status.getAverageLoad() == 0.0); Assert.assertNotNull(status.getBalancerOn()); }