From 77ca743d095de11bbe30cdc230d8198f0c3d7d4d Mon Sep 17 00:00:00 2001 From: Reid Chan Date: Sat, 9 Sep 2017 03:27:47 +0800 Subject: [PATCH] HBASE-18621 Refactor ClusterOptions before applying to code base Signed-off-by: Chia-Ping Tsai --- .../apache/hadoop/hbase/ClusterStatus.java | 236 +++--------------- .../org/apache/hadoop/hbase/client/Admin.java | 17 +- .../hadoop/hbase/client/AsyncAdmin.java | 5 +- .../hadoop/hbase/client/AsyncHBaseAdmin.java | 13 +- .../hadoop/hbase/client/HBaseAdmin.java | 7 +- .../hbase/client/RawAsyncHBaseAdmin.java | 7 +- .../hbase/shaded/protobuf/ProtobufUtil.java | 93 ++++--- .../shaded/protobuf/RequestConverter.java | 7 +- .../src/main/protobuf/ClusterStatus.proto | 20 +- .../src/main/protobuf/Master.proto | 2 +- .../src/main/protobuf/ClusterStatus.proto | 20 +- .../apache/hadoop/hbase/master/HMaster.java | 73 +++--- .../hbase/master/MasterRpcServices.java | 2 +- .../hbase/client/TestClientClusterStatus.java | 54 ++-- 14 files changed, 203 insertions(+), 353 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 0dc4984cdeb..d12ad0db908 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 @@ -29,6 +29,8 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.master.RegionState; import org.apache.hadoop.io.VersionedWritable; +import com.google.common.base.Objects; + /** * Status information on the HBase cluster. @@ -47,26 +49,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));
      * }
      * 
    */ @@ -208,23 +207,23 @@ public class ClusterStatus extends VersionedWritable { if (!(o instanceof ClusterStatus)) { return false; } - return (getVersion() == ((ClusterStatus)o).getVersion()) && - getHBaseVersion().equals(((ClusterStatus)o).getHBaseVersion()) && - this.liveServers.equals(((ClusterStatus)o).liveServers) && - this.deadServers.containsAll(((ClusterStatus)o).deadServers) && - Arrays.equals(this.masterCoprocessors, - ((ClusterStatus)o).masterCoprocessors) && - this.master.equals(((ClusterStatus)o).master) && - this.backupMasters.containsAll(((ClusterStatus)o).backupMasters); + ClusterStatus other = (ClusterStatus) o; + //TODO Override the equals() methods in ServerLoad. + return (getVersion() == other.getVersion()) && + Objects.equal(getHBaseVersion(), other.getHBaseVersion()) && + Objects.equal(this.liveServers, other.liveServers) && + getDeadServerNames().containsAll(other.getDeadServerNames()) && + Arrays.equals(getMasterCoprocessors(), other.getMasterCoprocessors()) && + Objects.equal(getMaster(), other.getMaster()) && + getBackupMasters().containsAll(other.getBackupMasters()); } /** * @see java.lang.Object#hashCode() */ public int hashCode() { - return VERSION + hbaseVersion.hashCode() + this.liveServers.hashCode() + - this.deadServers.hashCode() + this.master.hashCode() + - this.backupMasters.hashCode(); + return VERSION + Objects.hashCode(hbaseVersion, liveServers, deadServers, + master, backupMasters); } /** @return the object version number */ @@ -436,194 +435,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 26384c94b9f..9f2084c256f 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.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.NamespaceDescriptor; @@ -1231,17 +1232,27 @@ public interface Admin extends Abortable, Closeable { void stopRegionServer(final String hostnamePort) throws IOException; /** + * Get whole cluster status, containing status about: + *
    +   * hbase version
    +   * cluster id
    +   * primary/backup master(s)
    +   * master's coprocessors
    +   * live/dead regionservers
    +   * balancer
    +   * regions in transition
    +   * 
    * @return cluster status * @throws IOException if a remote or network exception occurs */ 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