hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1346748 [1/3] - in /hbase/trunk/hbase-server/src: main/java/org/apache/hadoop/hbase/ main/java/org/apache/hadoop/hbase/client/ main/java/org/apache/hadoop/hbase/ipc/ main/java/org/apache/hadoop/hbase/master/ main/java/org/apache/hadoop/hba...
Date Wed, 06 Jun 2012 06:26:23 GMT
Author: stack
Date: Wed Jun  6 06:26:22 2012
New Revision: 1346748

URL: http://svn.apache.org/viewvc?rev=1346748&view=rev
Log:
HBASE-6038 Add getClusterStatus PB-based call to HMasterInterface

Added:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/protobuf/generated/ClusterStatusProtos.java
    hbase/trunk/hbase-server/src/main/protobuf/ClusterId.proto
    hbase/trunk/hbase-server/src/main/protobuf/ClusterStatus.proto
    hbase/trunk/hbase-server/src/main/protobuf/FS.proto
Removed:
    hbase/trunk/hbase-server/src/protobuf/ClusterId.proto
    hbase/trunk/hbase-server/src/protobuf/FS.proto
Modified:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HServerLoad.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/protobuf/RequestConverter.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/protobuf/generated/MasterProtos.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
    hbase/trunk/hbase-server/src/main/protobuf/Master.proto
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java?rev=1346748&r1=1346747&r2=1346748&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java Wed
Jun  6 06:26:22 2012
@@ -28,12 +28,20 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.HashSet;
 import org.apache.hadoop.hbase.HServerLoad;
+import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
+import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos;
+import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.LiveServerInfo;
+import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.RegionInTransition;
+import org.apache.hadoop.hbase.protobuf.generated.FSProtos.HBaseVersionFileContent;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
+import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier;
+import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType;
 import org.apache.hadoop.hbase.ServerLoad;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
@@ -43,6 +51,8 @@ import org.apache.hadoop.hbase.util.Byte
 import org.apache.hadoop.io.VersionMismatchException;
 import org.apache.hadoop.io.VersionedWritable;
 
+import com.google.protobuf.ByteString;
+
 /**
  * Status information on the HBase cluster.
  * <p>
@@ -78,7 +88,7 @@ public class ClusterStatus extends Versi
   private static final byte VERSION = 2;
 
   private String hbaseVersion;
-  private Map<ServerName, HServerLoad> liveServers;
+  private Map<ServerName, ServerLoad> liveServers;
   private Collection<ServerName> deadServers;
   private ServerName master;
   private Collection<ServerName> backupMasters;
@@ -88,7 +98,9 @@ public class ClusterStatus extends Versi
 
   /**
    * Constructor, for Writable
+   * @deprecated Used by Writables and Writables are going away.
    */
+  @Deprecated
   public ClusterStatus() {
     super();
   }
@@ -102,40 +114,7 @@ public class ClusterStatus extends Versi
       final String[] masterCoprocessors) {
     this.hbaseVersion = hbaseVersion;
 
-    // TODO: This conversion of ServerLoad to HServerLoad is temporary,
-    // will be cleaned up in HBASE-5445.  Using the ClusterStatus proto brings
-    // in a lot of other changes, so it makes sense to break this up.
-    Map<ServerName, HServerLoad> convertedLoad =
-      new HashMap<ServerName,HServerLoad>();
-    for (Map.Entry<ServerName,ServerLoad> entry : servers.entrySet()) {
-      ServerLoad sl = entry.getValue();
-
-      Map<byte[],RegionLoad> regionLoad = new HashMap<byte[],RegionLoad>();
-      for (HBaseProtos.RegionLoad rl : sl.getRegionLoadsList()) {
-        Set<String> regionCoprocessors = new HashSet<String>();
-        for (HBaseProtos.Coprocessor coprocessor
-            : rl.getCoprocessorsList()) {
-          regionCoprocessors.add(coprocessor.getName());
-        }
-
-        byte [] regionName = rl.getRegionSpecifier().getValue().toByteArray();
-        RegionLoad converted = new RegionLoad(regionName,
-          rl.getStores(),rl.getStorefiles(),rl.getStoreUncompressedSizeMB(),
-          rl.getStorefileSizeMB(),rl.getMemstoreSizeMB(),
-          rl.getStorefileIndexSizeMB(),rl.getRootIndexSizeKB(),
-          rl.getTotalStaticIndexSizeKB(),rl.getTotalStaticBloomSizeKB(),
-          rl.getReadRequestsCount(),rl.getWriteRequestsCount(),
-          rl.getTotalCompactingKVs(),rl.getCurrentCompactedKVs(),
-          regionCoprocessors);
-        regionLoad.put(regionName, converted);
-      }
-
-      HServerLoad hsl = new HServerLoad(sl.getTotalNumberOfRequests(),
-        sl.getRequestsPerSecond(),sl.getUsedHeapMB(),sl.getMaxHeapMB(),
-        regionLoad,new HashSet<String>(Arrays.asList(masterCoprocessors)));
-      convertedLoad.put(entry.getKey(), hsl);
-    }
-    this.liveServers = convertedLoad;
+    this.liveServers = servers;
     this.deadServers = deadServers;
     this.master = master;
     this.backupMasters = backupMasters;
@@ -178,8 +157,8 @@ public class ClusterStatus extends Versi
    */
   public int getRegionsCount() {
     int count = 0;
-    for (Map.Entry<ServerName, HServerLoad> e: this.liveServers.entrySet()) {
-      count += e.getValue().getNumberOfRegions();
+    for (Map.Entry<ServerName, ServerLoad> e: this.liveServers.entrySet()) {
+      count += e.getValue().getRegionLoadsCount();
     }
     return count;
   }
@@ -189,8 +168,8 @@ public class ClusterStatus extends Versi
    */
   public int getRequestsCount() {
     int count = 0;
-    for (Map.Entry<ServerName, HServerLoad> e: this.liveServers.entrySet()) {
-      count += e.getValue().getNumberOfRequests();
+    for (Map.Entry<ServerName, ServerLoad> e: this.liveServers.entrySet()) {
+      count += e.getValue().getTotalNumberOfRequests();
     }
     return count;
   }
@@ -281,7 +260,7 @@ public class ClusterStatus extends Versi
    * @return Server's load or null if not found.
    */
   public HServerLoad getLoad(final ServerName sn) {
-    return this.liveServers.get(sn);
+    return HServerLoad.convert(this.liveServers.get(sn));
   }
 
   public Map<String, RegionState> getRegionsInTransition() {
@@ -296,95 +275,74 @@ public class ClusterStatus extends Versi
      return masterCoprocessors;
   }
 
-  //
-  // Writable
-  //
-
-  public void write(DataOutput out) throws IOException {
-    super.write(out);
-    out.writeUTF(hbaseVersion);
-    out.writeInt(getServersSize());
-    for (Map.Entry<ServerName, HServerLoad> e: this.liveServers.entrySet()) {
-      Bytes.writeByteArray(out, e.getKey().getVersionedBytes());
-      e.getValue().write(out);
-    }
-    out.writeInt(deadServers.size());
-    for (ServerName server: deadServers) {
-      Bytes.writeByteArray(out, server.getVersionedBytes());
-    }
-    out.writeInt(this.intransition.size());
-    for (Map.Entry<String, RegionState> e: this.intransition.entrySet()) {
-      out.writeUTF(e.getKey());
-      e.getValue().write(out);
-    }
-    out.writeUTF(clusterId);
-    out.writeInt(masterCoprocessors.length);
-    for(String masterCoprocessor: masterCoprocessors) {
-      out.writeUTF(masterCoprocessor);
-    }
-    Bytes.writeByteArray(out, this.master.getVersionedBytes());
-    out.writeInt(this.backupMasters.size());
-    for (ServerName backupMaster: this.backupMasters) {
-      Bytes.writeByteArray(out, backupMaster.getVersionedBytes());
-    }
-  }
-
-  public void readFields(DataInput in) throws IOException {
-    int version = getVersion();
-    try {
-      super.readFields(in);
-    } catch (VersionMismatchException e) {
-      /*
-       * No API in VersionMismatchException to get the expected and found
-       * versions.  We use the only tool available to us: toString(), whose
-       * output has a dependency on hadoop-common.  Boo.
-       */
-      int startIndex = e.toString().lastIndexOf('v') + 1;
-      version = Integer.parseInt(e.toString().substring(startIndex));
-    }
-    hbaseVersion = in.readUTF();
-    int count = in.readInt();
-    this.liveServers = new HashMap<ServerName, HServerLoad>(count);
-    for (int i = 0; i < count; i++) {
-      byte [] versionedBytes = Bytes.readByteArray(in);
-      HServerLoad hsl = new HServerLoad();
-      hsl.readFields(in);
-      this.liveServers.put(ServerName.parseVersionedServerName(versionedBytes), hsl);
-    }
-    count = in.readInt();
-    deadServers = new ArrayList<ServerName>(count);
-    for (int i = 0; i < count; i++) {
-      deadServers.add(ServerName.parseVersionedServerName(Bytes.readByteArray(in)));
-    }
-    count = in.readInt();
-    this.intransition = new TreeMap<String, RegionState>();
-    for (int i = 0; i < count; i++) {
-      String key = in.readUTF();
-      RegionState regionState = new RegionState();
-      regionState.readFields(in);
-      this.intransition.put(key, regionState);
-    }
-    this.clusterId = in.readUTF();
-    int masterCoprocessorsLength = in.readInt();
-    masterCoprocessors = new String[masterCoprocessorsLength];
-    for(int i = 0; i < masterCoprocessorsLength; i++) {
-      masterCoprocessors[i] = in.readUTF();
-    }
-    // Only read extra fields for master and backup masters if
-    // version indicates that we should do so, else use defaults
-    if (version >= VERSION_MASTER_BACKUPMASTERS) {
-      this.master = ServerName.parseVersionedServerName(
-                      Bytes.readByteArray(in));
-      count = in.readInt();
-      this.backupMasters = new ArrayList<ServerName>(count);
-      for (int i = 0; i < count; i++) {
-        this.backupMasters.add(ServerName.parseVersionedServerName(
-                                 Bytes.readByteArray(in)));
-      }
-    } else {
-      this.master = new ServerName(ServerName.UNKNOWN_SERVERNAME, -1,
-                                   ServerName.NON_STARTCODE);
-      this.backupMasters = new ArrayList<ServerName>(0);
-    }
+   /**
+    * Convert a ClutserStatus to a protobuf ClusterStatus
+    *
+    * @return the protobuf ClusterStatus
+    */
+  public ClusterStatusProtos.ClusterStatus convert() {
+    ClusterStatusProtos.ClusterStatus.Builder builder = ClusterStatusProtos.ClusterStatus.newBuilder();
+    builder.setHbaseVersion(HBaseVersionFileContent.newBuilder().setVersion(getHBaseVersion()));
+
+    for (Map.Entry<ServerName, ServerLoad> entry : liveServers.entrySet()) {
+      LiveServerInfo.Builder lsi =
+        LiveServerInfo.newBuilder().setServer(ProtobufUtil.toServerName(entry.getKey()));
+      lsi.setServerLoad(entry.getValue().getServerLoadPB());
+      builder.addLiveServers(lsi.build());
+    }
+    for (ServerName deadServer : getDeadServerNames()) {
+      builder.addDeadServers(ProtobufUtil.toServerName(deadServer));
+    }
+    for (Map.Entry<String, RegionState> rit : getRegionsInTransition().entrySet())
{
+      ClusterStatusProtos.RegionState rs = rit.getValue().convert();
+      RegionSpecifier.Builder spec =
+        RegionSpecifier.newBuilder().setType(RegionSpecifierType.REGION_NAME);
+      spec.setValue(ByteString.copyFrom(Bytes.toBytes(rit.getKey())));
+
+      RegionInTransition pbRIT =
+        RegionInTransition.newBuilder().setSpec(spec.build()).setRegionState(rs).build();
+      builder.addRegionsInTransition(pbRIT);
+    }
+    builder.setClusterId(new ClusterId(getClusterId()).convert());
+    for (String coprocessor : getMasterCoprocessors()) {
+      builder.addMasterCoprocessors(HBaseProtos.Coprocessor.newBuilder().setName(coprocessor));
+    }
+    builder.setMaster(
+      ProtobufUtil.toServerName(getMaster()));
+    for (ServerName backup : getBackupMasters()) {
+      builder.addBackupMasters(ProtobufUtil.toServerName(backup));
+    }
+    return builder.build();
+  }
+
+  /**
+   * Convert a protobuf ClusterStatus to a ClusterStatus
+   *
+   * @param proto the protobuf ClusterStatus
+   * @return the converted ClusterStatus
+   */
+  public static ClusterStatus convert(ClusterStatusProtos.ClusterStatus proto) {
+    Map<ServerName, ServerLoad> servers = new HashMap<ServerName, ServerLoad>();
+    for (LiveServerInfo lsi : proto.getLiveServersList()) {
+      servers.put(ProtobufUtil.toServerName(lsi.getServer()), new ServerLoad(lsi.getServerLoad()));
+    }
+    Collection<ServerName> deadServers = new LinkedList<ServerName>();
+    for (HBaseProtos.ServerName sn : proto.getDeadServersList()) {
+      deadServers.add(ProtobufUtil.toServerName(sn));
+    }
+    Collection<ServerName> backupMasters = new LinkedList<ServerName>();
+    for (HBaseProtos.ServerName sn : proto.getBackupMastersList()) {
+      backupMasters.add(ProtobufUtil.toServerName(sn));
+    }
+    final Map<String, RegionState> rit = new HashMap<String, RegionState>();
+    for (RegionInTransition region : proto.getRegionsInTransitionList()) {
+      String key = new String(region.getSpec().getValue().toByteArray());
+      RegionState value = RegionState.convert(region.getRegionState());
+      rit.put(key,value);
+    }
+    final String[] masterCoprocessors = proto.getMasterCoprocessorsList().toArray(new String[0]);
+    return new ClusterStatus(proto.getHbaseVersion().getVersion(),
+      ClusterId.convert(proto.getClusterId()).toString(),servers,deadServers,
+      ProtobufUtil.toServerName(proto.getMaster()),backupMasters,rit,masterCoprocessors);
   }
 }

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java?rev=1346748&r1=1346747&r2=1346748&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java Wed Jun
 6 06:26:22 2012
@@ -835,7 +835,6 @@ implements WritableComparable<HRegionInf
   /**
    * Convert a HRegionInfo to a RegionInfo
    *
-   * @param info the HRegionInfo to convert
    * @return the converted RegionInfo
    */
   RegionInfo convert() {

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HServerLoad.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HServerLoad.java?rev=1346748&r1=1346747&r2=1346748&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HServerLoad.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HServerLoad.java Wed Jun
 6 06:26:22 2012
@@ -24,6 +24,8 @@ import java.io.DataOutput;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
@@ -31,6 +33,7 @@ import java.util.TreeSet;
 
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Strings;
 import org.apache.hadoop.io.VersionedWritable;
@@ -709,8 +712,44 @@ implements WritableComparable<HServerLoa
     return count;
   }
 
+  public static HServerLoad convert(ServerLoad sl) {
+  // TODO: This conversion of ServerLoad to HServerLoad is temporary,
+  // will be cleaned up in HBASE-5445.  Using the ClusterStatus proto brings
+  // in a lot of other changes, so it makes sense to break this up.
+    Map<byte[],RegionLoad> regionLoad = new HashMap<byte[],RegionLoad>();
+    for (HBaseProtos.RegionLoad rl : sl.getRegionLoadsList()) {
+      Set<String> regionCoprocessors = new HashSet<String>();
+      for (HBaseProtos.Coprocessor coprocessor
+          : rl.getCoprocessorsList()) {
+        regionCoprocessors.add(coprocessor.getName());
+      }
+
+      byte [] regionName = rl.getRegionSpecifier().getValue().toByteArray();
+      RegionLoad converted = new RegionLoad(regionName,
+        rl.getStores(),rl.getStorefiles(),rl.getStoreUncompressedSizeMB(),
+        rl.getStorefileSizeMB(),rl.getMemstoreSizeMB(),
+        rl.getStorefileIndexSizeMB(),rl.getRootIndexSizeKB(),
+        rl.getTotalStaticIndexSizeKB(),rl.getTotalStaticBloomSizeKB(),
+        rl.getReadRequestsCount(),rl.getWriteRequestsCount(),
+        rl.getTotalCompactingKVs(),rl.getCurrentCompactedKVs(),
+        regionCoprocessors);
+      regionLoad.put(regionName, converted);
+    }
+
+    Set<String> coprocessors =
+      new HashSet<String>(Arrays.asList(ServerLoad.getRegionServerCoprocessors(sl)));
+    HServerLoad hsl = new HServerLoad(sl.getTotalNumberOfRequests(),
+      sl.getRequestsPerSecond(),sl.getUsedHeapMB(),sl.getMaxHeapMB(),
+      regionLoad,coprocessors);
+
+    return hsl;
+  }
   // Writable
 
+  /**
+   * @deprecated Writables are going away.
+   */
+  @Deprecated
   public void readFields(DataInput in) throws IOException {
     super.readFields(in);
     int version = in.readByte();
@@ -731,6 +770,10 @@ implements WritableComparable<HServerLoa
     }
   }
 
+  /**
+   * @deprecated Writables are going away.
+   */
+  @Deprecated
   public void write(DataOutput out) throws IOException {
     super.write(out);
     out.writeByte(VERSION);

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1346748&r1=1346747&r2=1346748&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
Wed Jun  6 06:26:22 2012
@@ -88,6 +88,7 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ModifyColumnRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ModifyTableRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.AssignRegionRequest;
+import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetClusterStatusRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.MoveRegionRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SetBalancerRunningRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.UnassignRegionRequest;
@@ -1710,8 +1711,9 @@ public class HBaseAdmin implements Abort
   public ClusterStatus getClusterStatus() throws IOException {
     return execute(new MasterCallable<ClusterStatus>() {
       @Override
-      public ClusterStatus call() {
-        return master.getClusterStatus();
+      public ClusterStatus call() throws ServiceException {
+        GetClusterStatusRequest req = RequestConverter.buildGetClusterStatusRequest();
+        return ClusterStatus.convert(master.getClusterStatus(null,req).getClusterStatus());
       }
     });
   }

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java?rev=1346748&r1=1346747&r2=1346748&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java
Wed Jun  6 06:26:22 2012
@@ -65,6 +65,8 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ShutdownResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.StopMasterRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.StopMasterResponse;
+import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetClusterStatusRequest;
+import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetClusterStatusResponse;
 import org.apache.hadoop.hbase.UnknownRegionException;
 import org.apache.hadoop.hbase.security.TokenInfo;
 import org.apache.hadoop.hbase.security.KerberosInfo;
@@ -240,9 +242,13 @@ public interface HMasterInterface extend
 
   /**
    * Return cluster status.
+   * @param controller Unused (set to null).
+   * @param req GetClusterStatusRequest
    * @return status object
+   * @throws ServiceException
    */
-  public ClusterStatus getClusterStatus();
+  public GetClusterStatusResponse getClusterStatus(RpcController controller, GetClusterStatusRequest
req)
+  throws ServiceException;
 
   /**
    * Offline a region from the assignment manager's in-memory state.  The

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java?rev=1346748&r1=1346747&r2=1346748&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
Wed Jun  6 06:26:22 2012
@@ -73,6 +73,7 @@ import org.apache.hadoop.hbase.master.ha
 import org.apache.hadoop.hbase.master.handler.ServerShutdownHandler;
 import org.apache.hadoop.hbase.master.handler.SplitRegionHandler;
 import org.apache.hadoop.hbase.master.metrics.MasterMetrics;
+import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos;
 import org.apache.hadoop.hbase.regionserver.RegionAlreadyInTransitionException;
 import org.apache.hadoop.hbase.regionserver.RegionOpeningState;
 import org.apache.hadoop.hbase.regionserver.RegionServerStoppedException;
@@ -3511,6 +3512,97 @@ public class AssignmentManager extends Z
         + ", server=" + serverName;
     }
 
+    /**
+     * Convert a RegionState to an HBaseProtos.RegionState
+     *
+     * @return the converted HBaseProtos.RegionState
+     */
+    public ClusterStatusProtos.RegionState convert() {
+      ClusterStatusProtos.RegionState.Builder regionState = ClusterStatusProtos.RegionState.newBuilder();
+      ClusterStatusProtos.RegionState.State rs;
+      switch (regionState.getState()) {
+      case OFFLINE:
+        rs = ClusterStatusProtos.RegionState.State.OFFLINE;
+        break;
+      case PENDING_OPEN:
+        rs = ClusterStatusProtos.RegionState.State.PENDING_OPEN;
+        break;
+      case OPENING:
+        rs = ClusterStatusProtos.RegionState.State.OPENING;
+        break;
+      case OPEN:
+        rs = ClusterStatusProtos.RegionState.State.OPEN;
+        break;
+      case PENDING_CLOSE:
+        rs = ClusterStatusProtos.RegionState.State.PENDING_CLOSE;
+    	break;
+      case CLOSING:
+        rs = ClusterStatusProtos.RegionState.State.CLOSING;
+        break;
+      case CLOSED:
+        rs = ClusterStatusProtos.RegionState.State.CLOSED;
+        break;
+      case SPLITTING:
+        rs = ClusterStatusProtos.RegionState.State.SPLITTING;
+        break;
+      case SPLIT:
+        rs = ClusterStatusProtos.RegionState.State.SPLIT;
+        break;
+      default:
+        throw new IllegalStateException("");
+      }
+      regionState.setRegionInfo(HRegionInfo.convert(region));
+      regionState.setState(rs);
+      regionState.setStamp(getStamp());
+      return regionState.build();
+    }
+
+    /**
+     * Convert a protobuf HBaseProtos.RegionState to a RegionState
+     *
+     * @return the RegionState
+     */
+    public static RegionState convert(ClusterStatusProtos.RegionState proto) {
+      RegionState.State state;
+      switch (proto.getState()) {
+      case OFFLINE:
+        state = State.OFFLINE;
+        break;
+      case PENDING_OPEN:
+        state = State.PENDING_OPEN;
+        break;
+      case OPENING:
+        state = State.OPENING;
+        break;
+      case OPEN:
+        state = State.OPEN;
+        break;
+      case PENDING_CLOSE:
+        state = State.PENDING_CLOSE;
+    	break;
+      case CLOSING:
+        state = State.CLOSING;
+        break;
+      case CLOSED:
+        state = State.CLOSED;
+        break;
+      case SPLITTING:
+        state = State.SPLITTING;
+        break;
+      case SPLIT:
+        state = State.SPLIT;
+        break;
+      default:
+        throw new IllegalStateException("");
+      }
+
+      return new RegionState(HRegionInfo.convert(proto.getRegionInfo()),state,proto.getStamp(),null);
+    }
+
+    /**
+     * @deprecated Writables are going away
+     */
+    @Deprecated
     @Override
     public void readFields(DataInput in) throws IOException {
       region = new HRegionInfo();
@@ -3519,6 +3611,10 @@ public class AssignmentManager extends Z
       stamp.set(in.readLong());
     }
 
+    /**
+     * @deprecated Writables are going away
+     */
+    @Deprecated
     @Override
     public void write(DataOutput out) throws IOException {
       region.write(out);

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=1346748&r1=1346747&r2=1346748&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Wed
Jun  6 06:26:22 2012
@@ -168,6 +168,8 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ShutdownResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.StopMasterRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.StopMasterResponse;
+import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetClusterStatusRequest;
+import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetClusterStatusResponse;
 import com.google.protobuf.ServiceException;
 
 /**
@@ -1627,6 +1629,13 @@ Server {
     }
   }
 
+  @Override
+  public GetClusterStatusResponse getClusterStatus(RpcController controller, GetClusterStatusRequest
req)
+  throws ServiceException {
+    GetClusterStatusResponse.Builder response = GetClusterStatusResponse.newBuilder();
+    response.setClusterStatus(getClusterStatus().convert());
+    return response.build();
+  }
   /**
    * @return cluster status
    */

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java?rev=1346748&r1=1346747&r2=1346748&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
Wed Jun  6 06:26:22 2012
@@ -274,7 +274,7 @@ public class ServerManager {
 
   /**
    * @param serverName
-   * @return HServerLoad if serverName is known else null
+   * @return ServerLoad if serverName is known else null
    */
   public ServerLoad getLoad(final ServerName serverName) {
     return this.onlineServers.get(serverName);
@@ -282,7 +282,7 @@ public class ServerManager {
 
   /**
    * @param address
-   * @return HServerLoad if serverName is known else null
+   * @return ServerLoad if serverName is known else null
    * @deprecated Use {@link #getLoad(HServerAddress)}
    */
   public ServerLoad getLoad(final HServerAddress address) {

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/protobuf/RequestConverter.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/protobuf/RequestConverter.java?rev=1346748&r1=1346747&r2=1346748&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/protobuf/RequestConverter.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/protobuf/RequestConverter.java
Wed Jun  6 06:26:22 2012
@@ -97,6 +97,7 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.BalanceRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsMasterRunningRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SetBalancerRunningRequest;
+import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetClusterStatusRequest;
 import org.apache.hadoop.hbase.regionserver.wal.HLog;
 import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
@@ -1101,4 +1102,13 @@ public final class RequestConverter {
   public static SetBalancerRunningRequest buildLoadBalancerIsRequest(boolean on, boolean
synchronous) {
     return SetBalancerRunningRequest.newBuilder().setOn(on).setSynchronous(synchronous).build();
   }
+
+  /**
+   * Creates a protocol buffer GetClusterStatusRequest
+   *
+   * @return A GetClusterStatusRequest
+   */
+  public static GetClusterStatusRequest buildGetClusterStatusRequest() {
+    return GetClusterStatusRequest.newBuilder().build();
+  }
 }



Mime
View raw message