From 987990e4052498318179364c9d1817dc471d1726 Mon Sep 17 00:00:00 2001 From: Reid Chan Date: Thu, 31 Aug 2017 08:35:17 +0800 Subject: [PATCH] HBASE-18621 Refactor ClusterOptions before applying to code base --- .../org/apache/hadoop/hbase/ClusterStatus.java | 212 ++------------------- .../java/org/apache/hadoop/hbase/client/Admin.java | 7 +- .../org/apache/hadoop/hbase/client/AsyncAdmin.java | 5 +- .../hadoop/hbase/client/AsyncHBaseAdmin.java | 7 +- .../org/apache/hadoop/hbase/client/HBaseAdmin.java | 7 +- .../hadoop/hbase/client/RawAsyncHBaseAdmin.java | 7 +- .../hadoop/hbase/shaded/protobuf/ProtobufUtil.java | 90 +++++---- .../hbase/shaded/protobuf/RequestConverter.java | 13 +- .../src/main/protobuf/ClusterStatus.proto | 20 +- .../src/main/protobuf/Master.proto | 2 +- .../src/main/protobuf/ClusterStatus.proto | 20 +- .../org/apache/hadoop/hbase/master/HMaster.java | 73 +++---- .../hadoop/hbase/master/MasterRpcServices.java | 2 +- .../hbase/client/TestClientClusterStatus.java | 49 ++--- 14 files changed, 171 insertions(+), 343 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java index 0dc4984cde..c646a52d3e 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java @@ -47,26 +47,23 @@ import org.apache.hadoop.io.VersionedWritable; *
  • Regions in transition at master
  • *
  • The unique cluster ID
  • * - * {@link Options} provides a way to filter out infos which unwanted. - * The following codes will retrieve all the cluster information. + * {@link Option} provides a way to get desired ClusterStatus information. + * The following codes will get all the cluster information. *
      * {@code
      * // Original version still works
      * Admin admin = connection.getAdmin();
      * ClusterStatus status = admin.getClusterStatus();
      * // or below, a new version which has the same effects
    - * ClusterStatus status = admin.getClusterStatus(Options.defaultOptions());
    + * ClusterStatus status = admin.getClusterStatus(EnumSet.allOf(Option.class));
      * }
      * 
    - * If information about dead servers and master coprocessors are unwanted, + * If information about live servers is the only wanted. * then codes in the following way: *
      * {@code
      * Admin admin = connection.getAdmin();
    - * ClusterStatus status = admin.getClusterStatus(
    - *                                Options.defaultOptions()
    - *                                       .excludeDeadServers()
    - *                                       .excludeMasterCoprocessors());
    + * ClusterStatus status = admin.getClusterStatus(EnumSet.of(Option.LIVE_SERVERS));
      * }
      * 
    */ @@ -436,194 +433,17 @@ public class ClusterStatus extends VersionedWritable { } /** - * Options provides a way to filter out unwanted information. - * For compatibility, default options includes all the information about a ClusterStatus. - * To filter out unwanted information, use the specific excludeXXX() method. + * Kinds of ClusterStatus */ - public static class Options { - private boolean includeHBaseVersion = true; - private boolean includeLiveServers = true; - private boolean includeDeadServers = true; - private boolean includeMaster = true; - private boolean includeBackupMasters = true; - private boolean includeRegionState = true; - private boolean includeClusterId = true; - private boolean includeMasterCoprocessors = true; - private boolean includeBalancerOn = true; - - private Options() {} - - /** - * Include all information about a ClusterStatus. - */ - public static Options getDefaultOptions() { - return new Options(); - } - - /** - * Filter out hbase verision. - */ - public Options excludeHBaseVersion() { - includeHBaseVersion = false; - return this; - } - - /** - * Filter out live servers. - */ - public Options excludeLiveServers() { - includeLiveServers = false; - return this; - } - - /** - * Filter out dead servers info. - */ - public Options excludeDeadServers() { - includeDeadServers = false; - return this; - } - - /** - * Filter out master info. - */ - public Options excludeMaster() { - includeMaster = false; - return this; - } - - /** - * Filter out backup masters info. - */ - public Options excludeBackupMasters() { - includeBackupMasters = false; - return this; - } - - /** - * Filter out region state. - */ - public Options excludeRegionState() { - includeRegionState = false; - return this; - } - - /** - * Filter out cluster id. - */ - public Options excludeClusterId() { - includeClusterId = false; - return this; - } - - /** - * Filter out master's coprocessors info. - */ - public Options excludeMasterCoprocessors() { - includeMasterCoprocessors = false; - return this; - } - - /** - * Filter out balancer on info. - */ - public Options excludeBalancerOn() { - includeBalancerOn = false; - return this; - } - - /** - * Include hbase version info. - */ - public boolean includeHBaseVersion() { - return includeHBaseVersion; - } - - /** - * Include live servers info. - */ - public boolean includeLiveServers() { - return includeLiveServers; - } - - /** - * Include dead servers info. - */ - public boolean includeDeadServers() { - return includeDeadServers; - } - - /** - * Include master info. - */ - public boolean includeMaster() { - return includeMaster; - } - - /** - * Include backup masters info. - */ - public boolean includeBackupMasters() { - return includeBackupMasters; - } - - /** - * Include region states info. - */ - public boolean includeRegionState() { - return includeRegionState; - } - - /** - * Include cluster id info. - */ - public boolean includeClusterId() { - return includeClusterId; - } - - /** - * Include master's coprocessors. - */ - public boolean includeMasterCoprocessors() { - return includeMasterCoprocessors; - } - - /** - * Include balancer on info. - */ - public boolean includeBalancerOn() { - return includeBalancerOn; - } - - /** - * For an options reusable convenience, reset options to default. - */ - public Options reset() { - includeHBaseVersion = true; - includeLiveServers = true; - includeDeadServers = true; - includeMaster = true; - includeBackupMasters = true; - includeRegionState = true; - includeClusterId = true; - includeMasterCoprocessors = true; - includeBalancerOn = true; - return this; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder("ClusterStatus info: ["); - builder.append("include hbase version: " + includeHBaseVersion + ", "); - builder.append("include cluster id: " + includeClusterId + ", "); - builder.append("include master info: " + includeMaster + ", "); - builder.append("include backup masters info: " + includeBackupMasters + ", "); - builder.append("include live servers info: " + includeLiveServers + ", "); - builder.append("include dead servers info: " + includeDeadServers + ", "); - builder.append("include masters coprocessors: " + includeMasterCoprocessors + ", "); - builder.append("include region state: " + includeRegionState + ", "); - builder.append("include balancer on: " + includeBalancerOn + "]"); - return builder.toString(); - } + public enum Option { + HBASE_VERSION, /** status about hbase version */ + CLUSTER_ID, /** status about cluster id */ + BALANCER_ON, /** status about balancer is on or not */ + LIVE_SERVERS, /** status about live region servers */ + DEAD_SERVERS, /** status about dead region servers */ + MASTER, /** status about master */ + BACKUP_MASTERS, /** status about backup masters */ + MASTER_COPROCESSORS, /** status about master coprocessors */ + REGIONS_IN_TRANSITION; /** status about regions in transition */ } } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java index 8de9f89fd1..bfe69cb75e 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java @@ -22,6 +22,7 @@ import java.io.Closeable; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.EnumSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -31,7 +32,7 @@ import java.util.regex.Pattern; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Abortable; import org.apache.hadoop.hbase.ClusterStatus; -import org.apache.hadoop.hbase.ClusterStatus.Options; +import org.apache.hadoop.hbase.ClusterStatus.Option; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; @@ -1322,11 +1323,11 @@ public interface Admin extends Abortable, Closeable { ClusterStatus getClusterStatus() throws IOException; /** - * Get cluster status with options to filter out unwanted status. + * 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 */ - ClusterStatus getClusterStatus(Options options) throws IOException; + ClusterStatus getClusterStatus(EnumSet