hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject svn commit: r925417 - in /hadoop/hbase/branches/0.20: ./ src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/ src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate...
Date Fri, 19 Mar 2010 21:01:27 GMT
Author: apurtell
Date: Fri Mar 19 21:01:26 2010
New Revision: 925417

URL: http://svn.apache.org/viewvc?rev=925417&view=rev
Log:
HBASE-2319 [stargate] multiuser mode: request shaping

Added:
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/User.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/HTableTokenBucket.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/SoftUserData.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/TokenBucket.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/UserData.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/util/
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/util/TestHTableTokenBucket.java
Removed:
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/User.java
Modified:
    hadoop/hbase/branches/0.20/CHANGES.txt
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/Constants.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RESTServlet.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RegionsResource.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ResultGenerator.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RootResource.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResource.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResultGenerator.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowSpec.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerInstanceResource.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResource.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResultGenerator.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/SchemaResource.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterStatusResource.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterVersionResource.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/TableResource.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/VersionResource.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/Authenticator.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/HBCAuthenticator.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/HTableAuthenticator.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/JDBCAuthenticator.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/ZooKeeperAuthenticator.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/MiniClusterTestCase.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestHBCAuthenticator.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestHTableAuthenticator.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestJDBCAuthenticator.java
    hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestZooKeeperAuthenticator.java

Modified: hadoop/hbase/branches/0.20/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/CHANGES.txt?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/CHANGES.txt (original)
+++ hadoop/hbase/branches/0.20/CHANGES.txt Fri Mar 19 21:01:26 2010
@@ -46,8 +46,8 @@ Release 0.20.4 - Unreleased
    HBASE-2323  filter.RegexStringComparator does not work with certain bytes
                (Benoit Sigoure via Stack)
    HBASE-2283  row level atomicity (Kannan Muthukkaruppan via Stack)
-   HBASE-2344  InfoServer and hence HBase Master doesn't fully start if you have
-               HADOOP-6151 patch (Kannan Muthukkaruppan via Stack)
+   HBASE-2344  InfoServer and hence HBase Master doesn't fully start if you
+               have HADOOP-6151 patch (Kannan Muthukkaruppan via Stack)
 
   IMPROVEMENTS
    HBASE-2180  Bad read performance from synchronizing hfile.fddatainputstream
@@ -83,6 +83,7 @@ Release 0.20.4 - Unreleased
    HBASE-2302  Optimize M-R by bulk excluding regions - less InputSplit-s to
                avoid traffic on region servers when performing M-R on a subset
                of the table (Kay Kay via Stack)
+   HBASE-2319  [stargate] multiuser mode: request shaping
 
 Release 0.20.3 - January 25th, 2010
   INCOMPATIBLE CHANGES

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/Constants.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/Constants.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/Constants.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/Constants.java Fri Mar 19 21:01:26 2010
@@ -31,10 +31,12 @@ public interface Constants {
   public static final String STATUS_REPORT_PERIOD_KEY =
     "stargate.status.period";
 
+  public static final String USERS_TABLE = "users";
+
   public static final String INSTANCE_ZNODE_ROOT = "/stargate/instance";
   public static final String USERS_ZNODE_ROOT = "/stargate/users";
 
-  public static final int DEFAULT_MAX_AGE = 60 * 60 * 4;       // 4 hours
+  public static final int DEFAULT_MAX_AGE = 60 * 60 * 4;  // 4 hours
 
   public static final String MIMETYPE_TEXT = "text/plain";
   public static final String MIMETYPE_HTML = "text/html";

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RESTServlet.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RESTServlet.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RESTServlet.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RESTServlet.java Fri Mar 19 21:01:26 2010
@@ -43,6 +43,9 @@ import org.apache.hadoop.hbase.stargate.
 import org.apache.hadoop.hbase.stargate.auth.JDBCAuthenticator;
 import org.apache.hadoop.hbase.stargate.auth.ZooKeeperAuthenticator;
 import org.apache.hadoop.hbase.stargate.metrics.StargateMetrics;
+import org.apache.hadoop.hbase.stargate.util.HTableTokenBucket;
+import org.apache.hadoop.hbase.stargate.util.SoftUserData;
+import org.apache.hadoop.hbase.stargate.util.UserData;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWrapper;
@@ -188,6 +191,7 @@ public class RESTServlet extends Servlet
     this.wrapper = initZooKeeperWrapper();
     this.statusReporter = new StatusReporter(
       conf.getInt(STATUS_REPORT_PERIOD_KEY, 1000 * 60), stopping);
+    this.multiuser = conf.getBoolean("stargate.multiuser", false);
   }
 
   @Override
@@ -327,4 +331,26 @@ public class RESTServlet extends Servlet
     this.authenticator = authenticator;
   }
 
+  /**
+   * Check if the user has exceeded their request token limit within the
+   * current interval
+   * @param user the user
+   * @param want the number of tokens desired
+   * @throws IOException
+   */
+  public boolean userRequestLimit(final User user, int want) 
+      throws IOException {
+    UserData ud = SoftUserData.get(user);
+    HTableTokenBucket tb = (HTableTokenBucket) ud.get(UserData.TOKENBUCKET);
+    if (tb == null) {
+      tb = new HTableTokenBucket(conf, Bytes.toBytes(user.getToken()));
+      ud.put(UserData.TOKENBUCKET, tb);
+    }
+    if (tb.available() < want) {
+      return false;
+    }
+    tb.remove(want);
+    return true;
+  }
+
 }

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RegionsResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RegionsResource.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RegionsResource.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RegionsResource.java Fri Mar 19 21:01:26 2010
@@ -40,7 +40,7 @@ import org.apache.hadoop.hbase.HServerAd
 import org.apache.hadoop.hbase.TableNotFoundException;
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.HTablePool;
-import org.apache.hadoop.hbase.stargate.auth.User;
+import org.apache.hadoop.hbase.stargate.User;
 import org.apache.hadoop.hbase.stargate.model.TableInfoModel;
 import org.apache.hadoop.hbase.stargate.model.TableRegionModel;
 
@@ -79,7 +79,7 @@ public class RegionsResource implements 
 
   @GET
   @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
-  public Response get(@Context UriInfo uriInfo) {
+  public Response get(final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("GET " + uriInfo.getAbsolutePath());
     }
@@ -106,4 +106,5 @@ public class RegionsResource implements 
                   Response.Status.SERVICE_UNAVAILABLE);
     }
   }
+
 }

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ResultGenerator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ResultGenerator.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ResultGenerator.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ResultGenerator.java Fri Mar 19 21:01:26 2010
@@ -40,10 +40,12 @@ public abstract class ResultGenerator im
     }
   }
 
-  public static Filter buildFilter(String filter) throws Exception {
+  public static Filter buildFilter(final String filter) throws Exception {
     return ScannerModel.buildFilter(new JSONObject(filter));
   }
 
+  public abstract void putBack(KeyValue kv);
+
   public abstract void close();
 
 }

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RootResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RootResource.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RootResource.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RootResource.java Fri Mar 19 21:01:26 2010
@@ -35,9 +35,10 @@ import javax.ws.rs.core.Response.Respons
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.stargate.auth.User;
+import org.apache.hadoop.hbase.stargate.User;
 import org.apache.hadoop.hbase.stargate.model.TableListModel;
 import org.apache.hadoop.hbase.stargate.model.TableModel;
 
@@ -55,7 +56,15 @@ public class RootResource implements Con
     cacheControl.setNoTransform(false);
   }
 
-  TableListModel getTableList() throws IOException {
+  private final User auth(final String token) throws IOException {
+    User user = servlet.getAuthenticator().getUserForToken(token);
+    if (user == null || user.isDisabled()) {
+      throw new WebApplicationException(Response.Status.FORBIDDEN);
+    }
+    return user;
+  }
+
+  private final TableListModel getTableList() throws IOException {
     TableListModel tableList = new TableListModel();
     HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
     HTableDescriptor[] list = admin.listTables();
@@ -65,7 +74,8 @@ public class RootResource implements Con
     return tableList;
   }
 
-  TableListModel getTableListForUser(User user) throws IOException {
+  private final TableListModel getTableListForUser(final User user) 
+      throws IOException {
     TableListModel tableList;
     if (user.isAdmin()) {
       tableList = getTableList();
@@ -87,7 +97,7 @@ public class RootResource implements Con
 
   @GET
   @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
-  public Response get(@Context UriInfo uriInfo) throws IOException {
+  public Response get(final @Context UriInfo uriInfo) throws IOException {
     if (LOG.isDebugEnabled()) {
       LOG.debug("GET " + uriInfo.getAbsolutePath());
     }
@@ -121,11 +131,11 @@ public class RootResource implements Con
 
   @Path("{token: [0-9a-fA-F]{32} }") // 128 bit md5 sums
   public Response getTableRootResource(
-      @PathParam("token") String token) throws IOException {
+      final @PathParam("token") String token) throws IOException {
     if (servlet.isMultiUser()) {
-      User user = servlet.getAuthenticator().getUserForToken(token);
-      if (user == null || user.isDisabled()) {
-        throw new WebApplicationException(Response.Status.FORBIDDEN);
+      User user = auth(token);
+      if (!servlet.userRequestLimit(user, 1)) {
+        throw new WebApplicationException(Response.status(509).build());
       }
       try {
         ResponseBuilder response = Response.ok(getTableListForUser(user));
@@ -141,10 +151,13 @@ public class RootResource implements Con
 
   @Path("{token: [0-9a-fA-F]{32} }/status/cluster") // 128 bit md5 sums
   public StorageClusterStatusResource getClusterStatusResourceAuthorized(
-      @PathParam("token") String token) throws IOException {
+      final @PathParam("token") String token) throws IOException {
     if (servlet.isMultiUser()) {
-      User user = servlet.getAuthenticator().getUserForToken(token);
-      if (user != null && user.isAdmin() && !user.isDisabled()) {
+      User user = auth(token);
+      if (user.isAdmin()) {
+        if (!servlet.userRequestLimit(user, 1)) {
+          throw new WebApplicationException(Response.status(509).build());
+        }
         return new StorageClusterStatusResource();
       }
       throw new WebApplicationException(Response.Status.FORBIDDEN);
@@ -153,12 +166,13 @@ public class RootResource implements Con
   }
 
   @Path("{token: [0-9a-fA-F]{32} }/{table}")
-  public TableResource getTableResource(@PathParam("token") String token, 
-      @PathParam("table") String table) throws IOException {
-    if (servlet.isMultiUser()) {
-      User user = servlet.getAuthenticator().getUserForToken(token);
-      if (user == null || user.isDisabled()) {
-        throw new WebApplicationException(Response.Status.FORBIDDEN);
+  public TableResource getTableResource(
+      final @PathParam("token") String token, 
+      final @PathParam("table") String table) throws IOException {
+    if (servlet.isMultiUser()) {
+      User user = auth(token);
+      if (!servlet.userRequestLimit(user, 1)) {
+        throw new WebApplicationException(Response.status(509).build());
       }
       return new TableResource(user, table);
     }
@@ -166,8 +180,8 @@ public class RootResource implements Con
   }
 
   @Path("{table}")
-  public TableResource getTableResource(@PathParam("table") String table)
-    throws IOException {
+  public TableResource getTableResource(
+      final @PathParam("table") String table) throws IOException {
     if (servlet.isMultiUser()) {
       throw new WebApplicationException(Response.Status.BAD_REQUEST);
     }

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResource.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResource.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResource.java Fri Mar 19 21:01:26 2010
@@ -46,7 +46,7 @@ import org.apache.hadoop.hbase.client.De
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.HTablePool;
 import org.apache.hadoop.hbase.client.Put;
-import org.apache.hadoop.hbase.stargate.auth.User;
+import org.apache.hadoop.hbase.stargate.User;
 import org.apache.hadoop.hbase.stargate.model.CellModel;
 import org.apache.hadoop.hbase.stargate.model.CellSetModel;
 import org.apache.hadoop.hbase.stargate.model.RowModel;
@@ -55,6 +55,7 @@ import org.apache.hadoop.hbase.util.Byte
 public class RowResource implements Constants {
   private static final Log LOG = LogFactory.getLog(RowResource.class);
 
+  User user;
   String tableName;
   String actualTableName;
   RowSpec rowspec;
@@ -63,6 +64,7 @@ public class RowResource implements Cons
 
   public RowResource(User user, String table, String rowspec, String versions)
       throws IOException {
+    this.user = user;
     if (user != null) {
       this.actualTableName =
         !user.isAdmin() ? user.getName() + "." + table : table;
@@ -83,7 +85,7 @@ public class RowResource implements Cons
 
   @GET
   @Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
-  public Response get(@Context UriInfo uriInfo) {
+  public Response get(final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("GET " + uriInfo.getAbsolutePath());
     }
@@ -121,7 +123,7 @@ public class RowResource implements Cons
 
   @GET
   @Produces(MIMETYPE_BINARY)
-  public Response getBinary(@Context UriInfo uriInfo) {
+  public Response getBinary(final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("GET " + uriInfo.getAbsolutePath() + " as "+ MIMETYPE_BINARY);
     }
@@ -148,13 +150,19 @@ public class RowResource implements Cons
     }
   }
 
-  Response update(CellSetModel model, boolean replace) {
+  Response update(final CellSetModel model, final boolean replace) {
     servlet.getMetrics().incrementRequests(1);
     HTablePool pool = servlet.getTablePool();
     HTable table = null;
     try {
+      List<RowModel> rows = model.getRows();
+      // the user request limit is a transaction limit, so we need to
+      // account for updates by row
+      if (user != null && !servlet.userRequestLimit(user, rows.size())) {
+        throw new WebApplicationException(Response.status(509).build());
+      }
       table = pool.getTable(actualTableName);
-      for (RowModel row: model.getRows()) {
+      for (RowModel row: rows) {
         byte[] key = row.getKey();
         Put put = new Put(key);
         for (CellModel cell: row.getCells()) {
@@ -179,8 +187,9 @@ public class RowResource implements Cons
     }
   }
 
-  Response updateBinary(byte[] message, HttpHeaders headers, 
-      boolean replace) {
+  // This currently supports only update of one row at a time.
+  Response updateBinary(final byte[] message, final HttpHeaders headers,
+      final boolean replace) {
     servlet.getMetrics().incrementRequests(1);
     HTablePool pool = servlet.getTablePool();
     HTable table = null;    
@@ -229,7 +238,8 @@ public class RowResource implements Cons
 
   @PUT
   @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
-  public Response put(CellSetModel model, @Context UriInfo uriInfo) {
+  public Response put(final CellSetModel model,
+      final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("PUT " + uriInfo.getAbsolutePath());
     }
@@ -238,8 +248,8 @@ public class RowResource implements Cons
 
   @PUT
   @Consumes(MIMETYPE_BINARY)
-  public Response putBinary(byte[] message, @Context UriInfo uriInfo, 
-      @Context HttpHeaders headers)
+  public Response putBinary(final byte[] message,
+      final @Context UriInfo uriInfo, final @Context HttpHeaders headers)
   {
     if (LOG.isDebugEnabled()) {
       LOG.debug("PUT " + uriInfo.getAbsolutePath() + " as "+ MIMETYPE_BINARY);
@@ -249,7 +259,8 @@ public class RowResource implements Cons
 
   @POST
   @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
-  public Response post(CellSetModel model, @Context UriInfo uriInfo) {
+  public Response post(final CellSetModel model,
+      final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("POST " + uriInfo.getAbsolutePath());
     }
@@ -258,9 +269,8 @@ public class RowResource implements Cons
 
   @POST
   @Consumes(MIMETYPE_BINARY)
-  public Response postBinary(byte[] message, @Context UriInfo uriInfo, 
-      @Context HttpHeaders headers)
-  {
+  public Response postBinary(final byte[] message,
+      final @Context UriInfo uriInfo, final @Context HttpHeaders headers) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("POST " + uriInfo.getAbsolutePath() + " as "+MIMETYPE_BINARY);
     }
@@ -268,7 +278,7 @@ public class RowResource implements Cons
   }
 
   @DELETE
-  public Response delete(@Context UriInfo uriInfo) {
+  public Response delete(final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("DELETE " + uriInfo.getAbsolutePath());
     }
@@ -314,4 +324,5 @@ public class RowResource implements Cons
     }
     return Response.ok().build();
   }
+
 }

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResultGenerator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResultGenerator.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResultGenerator.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResultGenerator.java Fri Mar 19 21:01:26 2010
@@ -34,6 +34,7 @@ import org.apache.hadoop.hbase.filter.Fi
 
 public class RowResultGenerator extends ResultGenerator {
   private Iterator<KeyValue> valuesI;
+  private KeyValue cache;
 
   public RowResultGenerator(final String tableName, final RowSpec rowspec,
       final Filter filter) throws IllegalArgumentException, IOException {
@@ -68,6 +69,9 @@ public class RowResultGenerator extends 
   }
 
   public boolean hasNext() {
+    if (cache != null) {
+      return true;
+    }
     if (valuesI == null) {
       return false;
     }
@@ -75,6 +79,11 @@ public class RowResultGenerator extends 
   }
 
   public KeyValue next() {
+    if (cache != null) {
+      KeyValue kv = cache;
+      cache = null;
+      return kv;
+    }
     if (valuesI == null) {
       return null;
     }
@@ -85,7 +94,12 @@ public class RowResultGenerator extends 
     }
   }
 
+  public void putBack(KeyValue kv) {
+    this.cache = kv;
+  }
+
   public void remove() {
     throw new UnsupportedOperationException("remove not supported");
   }
+
 }

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowSpec.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowSpec.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowSpec.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowSpec.java Fri Mar 19 21:01:26 2010
@@ -55,7 +55,7 @@ public class RowSpec {
     i = parseTimestamp(path, i);
   }
 
-  private int parseRowKeys(String path, int i)
+  private int parseRowKeys(final String path, int i)
       throws IllegalArgumentException {
     StringBuilder startRow = new StringBuilder();
     StringBuilder endRow = null;
@@ -105,7 +105,7 @@ public class RowSpec {
     return i;
   }
 
-  private int parseColumns(String path, int i)
+  private int parseColumns(final String path, int i)
       throws IllegalArgumentException {
     if (i >= path.length()) {
       return i;
@@ -148,7 +148,7 @@ public class RowSpec {
     return i;
   }
 
-  private int parseTimestamp(String path, int i)
+  private int parseTimestamp(final String path, int i)
       throws IllegalArgumentException {
     if (i >= path.length()) {
       return i;
@@ -232,7 +232,7 @@ public class RowSpec {
     return maxVersions;
   }
 
-  public void setMaxVersions(int maxVersions) {
+  public void setMaxVersions(final int maxVersions) {
     this.maxVersions = maxVersions;
   }
 
@@ -256,7 +256,7 @@ public class RowSpec {
     return endRow;
   }
 
-  public void addColumn(byte[] column) {
+  public void addColumn(final byte[] column) {
     columns.add(column);
   }
 
@@ -276,7 +276,7 @@ public class RowSpec {
     return startTime;
   }
 
-  public void setStartTime(long startTime) {
+  public void setStartTime(final long startTime) {
     this.startTime = startTime;
   }
 
@@ -313,4 +313,5 @@ public class RowSpec {
     result.append("}");
     return result.toString();
   }
+
 }

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerInstanceResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerInstanceResource.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerInstanceResource.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerInstanceResource.java Fri Mar 19 21:01:26 2010
@@ -47,14 +47,16 @@ public class ScannerInstanceResource imp
   private static final Log LOG =
     LogFactory.getLog(ScannerInstanceResource.class);
 
+  User user;
   ResultGenerator generator;
   String id;
   int batch;
   RESTServlet servlet;
   CacheControl cacheControl;
 
-  public ScannerInstanceResource(String table, String id, 
+  public ScannerInstanceResource(User user, String table, String id, 
       ResultGenerator generator, int batch) throws IOException {
+    this.user = user;
     this.id = id;
     this.generator = generator;
     this.batch = batch;
@@ -66,7 +68,7 @@ public class ScannerInstanceResource imp
 
   @GET
   @Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
-  public Response get(@Context UriInfo uriInfo) {
+  public Response get(final @Context UriInfo uriInfo) throws IOException {
     if (LOG.isDebugEnabled()) {
       LOG.debug("GET " + uriInfo.getAbsolutePath());
     }
@@ -97,6 +99,12 @@ public class ScannerInstanceResource imp
         rowModel = new RowModel(rowKey);
       }
       if (!Bytes.equals(value.getRow(), rowKey)) {
+        // the user request limit is a transaction limit, so we need to
+        // account for scanner.next()
+        if (user != null && !servlet.userRequestLimit(user, 1)) {
+          generator.putBack(value);
+          break;
+        }
         model.addRow(rowModel);
         rowKey = value.getRow();
         rowModel = new RowModel(rowKey);
@@ -113,7 +121,7 @@ public class ScannerInstanceResource imp
 
   @GET
   @Produces(MIMETYPE_BINARY)
-  public Response getBinary(@Context UriInfo uriInfo) {
+  public Response getBinary(final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("GET " + uriInfo.getAbsolutePath() + " as " +
         MIMETYPE_BINARY);
@@ -138,7 +146,7 @@ public class ScannerInstanceResource imp
   }
 
   @DELETE
-  public Response delete(@Context UriInfo uriInfo) {
+  public Response delete(final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("DELETE " + uriInfo.getAbsolutePath());
     }

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResource.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResource.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResource.java Fri Mar 19 21:01:26 2010
@@ -41,7 +41,7 @@ import org.apache.commons.logging.LogFac
 
 import org.apache.hadoop.hbase.filter.Filter;
 
-import org.apache.hadoop.hbase.stargate.auth.User;
+import org.apache.hadoop.hbase.stargate.User;
 import org.apache.hadoop.hbase.stargate.model.ScannerModel;
 
 public class ScannerResource implements Constants {
@@ -68,7 +68,7 @@ public class ScannerResource implements 
     servlet = RESTServlet.getInstance();
   }
 
-  static void delete(String id) {
+  static void delete(final String id) {
     synchronized (scanners) {
       ScannerInstanceResource instance = scanners.remove(id);
       if (instance != null) {
@@ -77,7 +77,8 @@ public class ScannerResource implements 
     }
   }
 
-  Response update(ScannerModel model, boolean replace, UriInfo uriInfo) {
+  Response update(final ScannerModel model, final boolean replace, 
+      final UriInfo uriInfo) {
     servlet.getMetrics().incrementRequests(1);
     byte[] endRow = model.hasEndRow() ? model.getEndRow() : null;
     RowSpec spec = new RowSpec(model.getStartRow(), endRow,
@@ -88,7 +89,8 @@ public class ScannerResource implements 
         new ScannerResultGenerator(actualTableName, spec, filter);
       String id = gen.getID();
       ScannerInstanceResource instance = 
-        new ScannerInstanceResource(actualTableName, id, gen, model.getBatch());
+        new ScannerInstanceResource(user, actualTableName, id, gen, 
+          model.getBatch());
       synchronized (scanners) {
         scanners.put(id, instance);
       }
@@ -108,7 +110,8 @@ public class ScannerResource implements 
 
   @PUT
   @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
-  public Response put(ScannerModel model, @Context UriInfo uriInfo) {
+  public Response put(final ScannerModel model, 
+      final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("PUT " + uriInfo.getAbsolutePath());
     }
@@ -117,7 +120,8 @@ public class ScannerResource implements 
 
   @POST
   @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
-  public Response post(ScannerModel model, @Context UriInfo uriInfo) {
+  public Response post(final ScannerModel model,
+      final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("POST " + uriInfo.getAbsolutePath());
     }
@@ -126,7 +130,7 @@ public class ScannerResource implements 
 
   @Path("{scanner: .+}")
   public ScannerInstanceResource getScannerInstanceResource(
-      @PathParam("scanner") String id) {
+      final @PathParam("scanner") String id) {
     synchronized (scanners) {
       ScannerInstanceResource instance = scanners.get(id);
       if (instance == null) {

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResultGenerator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResultGenerator.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResultGenerator.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResultGenerator.java Fri Mar 19 21:01:26 2010
@@ -42,7 +42,7 @@ public class ScannerResultGenerator exte
   private static final Log LOG =
     LogFactory.getLog(ScannerResultGenerator.class);
 
-  public static Filter buildFilterFromModel(ScannerModel model) 
+  public static Filter buildFilterFromModel(final ScannerModel model) 
       throws Exception {
     String filter = model.getFilter();
     if (filter == null || filter.length() == 0) {
@@ -53,6 +53,7 @@ public class ScannerResultGenerator exte
 
   private String id;
   private Iterator<KeyValue> rowI;
+  private KeyValue cache;
   private ResultScanner scanner;
   private Result cached;
 
@@ -88,7 +89,7 @@ public class ScannerResultGenerator exte
       if (filter != null) {
         scan.setFilter(filter);
       }
-      // always disable block caching on the cluster
+      // always disable block caching on the cluster when scanning
       scan.setCacheBlocks(false);
       scanner = table.getScanner(scan);
       cached = null;
@@ -107,6 +108,9 @@ public class ScannerResultGenerator exte
   }
 
   public boolean hasNext() {
+    if (cache != null) {
+      return true;
+    }
     if (rowI != null && rowI.hasNext()) {
       return true;
     }
@@ -127,6 +131,11 @@ public class ScannerResultGenerator exte
   }
 
   public KeyValue next() {
+    if (cache != null) {
+      KeyValue kv = cache;
+      cache = null;
+      return kv;
+    }
     boolean loop;
     do {
       loop = false;
@@ -159,6 +168,10 @@ public class ScannerResultGenerator exte
     return null;
   }
 
+  public void putBack(KeyValue kv) {
+    this.cache = kv;
+  }
+
   public void remove() {
     throw new UnsupportedOperationException("remove not supported");
   }

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/SchemaResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/SchemaResource.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/SchemaResource.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/SchemaResource.java Fri Mar 19 21:01:26 2010
@@ -47,7 +47,7 @@ import org.apache.hadoop.hbase.client.HB
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.HTablePool;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.apache.hadoop.hbase.stargate.auth.User;
+import org.apache.hadoop.hbase.stargate.User;
 import org.apache.hadoop.hbase.stargate.model.ColumnSchemaModel;
 import org.apache.hadoop.hbase.stargate.model.TableSchemaModel;
 import org.apache.hadoop.hbase.util.Bytes;
@@ -89,7 +89,7 @@ public class SchemaResource implements C
 
   @GET
   @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
-  public Response get(@Context UriInfo uriInfo) {
+  public Response get(final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("GET " + uriInfo.getAbsolutePath());
     }
@@ -124,8 +124,9 @@ public class SchemaResource implements C
     }
   }
 
-  private Response replace(byte[] tableName, TableSchemaModel model,
-      UriInfo uriInfo, HBaseAdmin admin) {
+  private Response replace(final byte[] tableName, 
+      final TableSchemaModel model, final UriInfo uriInfo,
+      final HBaseAdmin admin) {
     try {
       HTableDescriptor htd = new HTableDescriptor(tableName);
       for (Map.Entry<QName,Object> e: model.getAny().entrySet()) {
@@ -155,8 +156,8 @@ public class SchemaResource implements C
     }      
   } 
 
-  private Response update(byte[] tableName, TableSchemaModel model,
-      UriInfo uriInfo, HBaseAdmin admin) {
+  private Response update(final byte[] tableName,final TableSchemaModel model,
+      final UriInfo uriInfo, final HBaseAdmin admin) {
     try {
       HTableDescriptor htd = admin.getTableDescriptor(tableName);
       admin.disableTable(tableName);
@@ -185,8 +186,8 @@ public class SchemaResource implements C
     }
   }
 
-  private Response update(TableSchemaModel model, boolean replace,
-      UriInfo uriInfo) {
+  private Response update(final TableSchemaModel model, final boolean replace,
+      final UriInfo uriInfo) {
     try {
       servlet.invalidateMaxAge(tableName);
       byte[] tableName = Bytes.toBytes(actualTableName);
@@ -204,7 +205,8 @@ public class SchemaResource implements C
 
   @PUT
   @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
-  public Response put(TableSchemaModel model, @Context UriInfo uriInfo) {
+  public Response put(final TableSchemaModel model, 
+      final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("PUT " + uriInfo.getAbsolutePath());
     }
@@ -220,7 +222,8 @@ public class SchemaResource implements C
 
   @POST
   @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
-  public Response post(TableSchemaModel model, @Context UriInfo uriInfo) {
+  public Response post(final TableSchemaModel model, 
+      final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("PUT " + uriInfo.getAbsolutePath());
     }
@@ -235,7 +238,7 @@ public class SchemaResource implements C
   }
 
   @DELETE
-  public Response delete(@Context UriInfo uriInfo) {     
+  public Response delete(final @Context UriInfo uriInfo) {     
     if (LOG.isDebugEnabled()) {
       LOG.debug("DELETE " + uriInfo.getAbsolutePath());
     }
@@ -252,4 +255,5 @@ public class SchemaResource implements C
             Response.Status.SERVICE_UNAVAILABLE);
     }
   }
+
 }

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterStatusResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterStatusResource.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterStatusResource.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterStatusResource.java Fri Mar 19 21:01:26 2010
@@ -56,7 +56,7 @@ public class StorageClusterStatusResourc
 
   @GET
   @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
-  public Response get(@Context UriInfo uriInfo) {
+  public Response get(final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("GET " + uriInfo.getAbsolutePath());
     }

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterVersionResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterVersionResource.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterVersionResource.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterVersionResource.java Fri Mar 19 21:01:26 2010
@@ -53,7 +53,7 @@ public class StorageClusterVersionResour
 
   @GET
   @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON})
-  public Response get(@Context UriInfo uriInfo) {
+  public Response get(final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("GET " + uriInfo.getAbsolutePath());
     }

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/TableResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/TableResource.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/TableResource.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/TableResource.java Fri Mar 19 21:01:26 2010
@@ -28,7 +28,7 @@ import javax.ws.rs.QueryParam;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
 
-import org.apache.hadoop.hbase.stargate.auth.User;
+import org.apache.hadoop.hbase.stargate.User;
 
 public class TableResource implements Constants {
 
@@ -56,8 +56,9 @@ public class TableResource implements Co
   }
 
   @Path("{rowspec: .+}")
-  public RowResource getRowResource(@PathParam("rowspec") String rowspec,
-      @QueryParam("v") String versions) {
+  public RowResource getRowResource(
+      final @PathParam("rowspec") String rowspec,
+      final @QueryParam("v") String versions) {
     try {
       return new RowResource(user, table, rowspec, versions);
     } catch (IOException e) {

Added: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/User.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/User.java?rev=925417&view=auto
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/User.java (added)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/User.java Fri Mar 19 21:01:26 2010
@@ -0,0 +1,155 @@
+package org.apache.hadoop.hbase.stargate;
+
+import java.security.MessageDigest;
+
+import org.apache.hadoop.hbase.util.Bytes;
+
+/** Representation of an authorized user */
+public class User implements Constants {
+
+  public static final User DEFAULT_USER = new User("default",
+    "00000000000000000000000000000000", false, true);
+
+  private String name;
+  private String token;
+  private boolean admin;
+  private boolean disabled = false;
+
+  /**
+   * Constructor
+   * <p>
+   * Creates an access token. (Normally, you don't want this.)
+   * @param name user name
+   * @param admin true if user has administrator privilege
+   * @throws Exception 
+   */
+  public User(String name, boolean admin) throws Exception {
+    this.name = name;
+    this.admin = admin;
+    byte[] digest = MessageDigest.getInstance("MD5")
+      .digest(Bytes.toBytes(name));
+    StringBuffer sb = new StringBuffer();
+    for (int i = 0; i < digest.length; i++) {
+      sb.append(Integer.toHexString(0xff & digest[i]));
+    }
+    this.token = sb.toString();
+  }
+
+  /**
+   * Constructor
+   * @param name user name
+   * @param token access token, a 16 char hex string
+   * @param admin true if user has administrator privilege
+   */
+  public User(String name, String token, boolean admin) {
+    this(name, token, admin, false);
+  }
+
+  /**
+   * Constructor
+   * @param name user name
+   * @param token access token, a 16 char hex string
+   * @param admin true if user has administrator privilege
+   * @param disabled true if user is disabled
+   */
+  public User(String name, String token, boolean admin, boolean disabled) {
+    this.name = name;
+    this.token = token;
+    this.admin = admin;
+    this.disabled = disabled;
+  }
+
+  /**
+   * @return user name
+   */
+  public String getName() {
+    return name;
+  }
+
+  /**
+   * @param name user name
+   */
+  public void setName(final String name) {
+    this.name = name;
+  }
+
+  /**
+   * @return access token, a 16 char hex string
+   */
+  public String getToken() {
+    return token;
+  }
+
+  /**
+   * @param token access token, a 16 char hex string
+   */
+  public void setToken(final String token) {
+    this.token = token;
+  }
+
+  /**
+   * @return true if user has administrator privilege
+   */
+  public boolean isAdmin() {
+    return admin;
+  }
+
+  /**
+   * @param admin true if user has administrator privilege
+   */
+  public void setAdmin(final boolean admin) {
+    this.admin = admin;
+  }
+
+  /**
+   * @return true if user is disabled
+   */
+  public boolean isDisabled() {
+    return disabled;
+  }
+
+  /**
+   * @param admin true if user is disabled
+   */
+  public void setDisabled(boolean disabled) {
+    this.disabled = disabled;
+  }
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + (admin ? 1231 : 1237);
+    result = prime * result + (disabled ? 1231 : 1237);
+    result = prime * result + ((name == null) ? 0 : name.hashCode());
+    result = prime * result + ((token == null) ? 0 : token.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    User other = (User) obj;
+    if (admin != other.admin)
+      return false;
+    if (disabled != other.disabled)
+      return false;
+    if (name == null) {
+      if (other.name != null)
+        return false;
+    } else if (!name.equals(other.name))
+      return false;
+    if (token == null) {
+      if (other.token != null)
+        return false;
+    } else if (!token.equals(other.token))
+      return false;
+    return true;
+  }
+
+}

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/VersionResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/VersionResource.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/VersionResource.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/VersionResource.java Fri Mar 19 21:01:26 2010
@@ -64,8 +64,8 @@ public class VersionResource implements 
    */
   @GET
   @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
-  public Response get(@Context ServletContext context, 
-      @Context UriInfo uriInfo) {
+  public Response get(final @Context ServletContext context, 
+      final @Context UriInfo uriInfo) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("GET " + uriInfo.getAbsolutePath());
     }

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/Authenticator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/Authenticator.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/Authenticator.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/Authenticator.java Fri Mar 19 21:01:26 2010
@@ -2,6 +2,8 @@ package org.apache.hadoop.hbase.stargate
 
 import java.io.IOException;
 
+import org.apache.hadoop.hbase.stargate.User;
+
 public abstract class Authenticator {
 
   public abstract User getUserForToken(String token) throws IOException;

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/HBCAuthenticator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/HBCAuthenticator.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/HBCAuthenticator.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/HBCAuthenticator.java Fri Mar 19 21:01:26 2010
@@ -1,6 +1,7 @@
 package org.apache.hadoop.hbase.stargate.auth;
 
 import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.stargate.User;
 
 public class HBCAuthenticator extends Authenticator {
 

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/HTableAuthenticator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/HTableAuthenticator.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/HTableAuthenticator.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/HTableAuthenticator.java Fri Mar 19 21:01:26 2010
@@ -3,12 +3,15 @@ package org.apache.hadoop.hbase.stargate
 import java.io.IOException;
 
 import org.apache.hadoop.hbase.HBaseConfiguration;
+
 import org.apache.hadoop.hbase.client.Get;
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.stargate.Constants;
+import org.apache.hadoop.hbase.stargate.User;
 import org.apache.hadoop.hbase.util.Bytes;
 
-public class HTableAuthenticator extends Authenticator {
+public class HTableAuthenticator extends Authenticator implements Constants {
 
   static final byte[] USER = Bytes.toBytes("user");
   static final byte[] NAME = Bytes.toBytes("name");
@@ -31,9 +34,7 @@ public class HTableAuthenticator extends
    * @param conf
    */
   public HTableAuthenticator(HBaseConfiguration conf) {
-    this.conf = conf;
-    this.tableName = conf.get("stargate.auth.htable.name",
-      "stargate.users");
+    this(conf, conf.get("stargate.auth.htable.name", USERS_TABLE));
   }
 
   /**

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/JDBCAuthenticator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/JDBCAuthenticator.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/JDBCAuthenticator.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/JDBCAuthenticator.java Fri Mar 19 21:01:26 2010
@@ -7,12 +7,16 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.stargate.User;
 import org.apache.hadoop.util.StringUtils;
-import org.mortbay.log.Log;
 
 public class JDBCAuthenticator extends Authenticator {
 
+  static final Log LOG = LogFactory.getLog(JDBCAuthenticator.class);
   static final int MAX_RETRIES = 5;
   static final long RETRY_SLEEP_TIME = 1000 * 2;
 
@@ -73,7 +77,7 @@ public class JDBCAuthenticator extends A
       if (++retries > MAX_RETRIES) {
         throw new IOException(e);
       } else try {
-        Log.warn(StringUtils.stringifyException(e));
+        LOG.warn(StringUtils.stringifyException(e));
         Thread.sleep(RETRY_SLEEP_TIME);
       } catch (InterruptedException ex) {
         // ignore

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/ZooKeeperAuthenticator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/ZooKeeperAuthenticator.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/ZooKeeperAuthenticator.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/auth/ZooKeeperAuthenticator.java Fri Mar 19 21:01:26 2010
@@ -25,7 +25,9 @@ import java.io.IOException;
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.stargate.Constants;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.stargate.User;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWrapper;
+
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.WatchedEvent;

Added: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/HTableTokenBucket.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/HTableTokenBucket.java?rev=925417&view=auto
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/HTableTokenBucket.java (added)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/HTableTokenBucket.java Fri Mar 19 21:01:26 2010
@@ -0,0 +1,193 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.stargate.util;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.RowLock;
+import org.apache.hadoop.hbase.stargate.Constants;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.util.StringUtils;
+
+/**
+ * A HTable-backed token bucket.
+ * <p>
+ * Can be configured with <t>rate</t>, the number of tokens to add to the
+ * bucket each second, and <t>size</t>, the maximum number of tokens allowed
+ * to burst. Configuration is stored in the HTable adjacent to the token
+ * count and is periodically refreshed.
+ * <p>
+ * Expected columns:
+ * <p>
+ * <ul>
+ *   <li>user:
+ *   <ul>
+ *     <li>user:tokens</li>
+ *     <li>user:tokens.rate</li>
+ *     <li>user:tokens.size</li>
+ *   </ul></li>
+ * </ul>
+ */
+public class HTableTokenBucket implements Constants {
+
+  static final Log LOG = LogFactory.getLog(HTableTokenBucket.class);
+
+  static final byte[] USER = Bytes.toBytes("user");
+  static final byte[] TOKENS = Bytes.toBytes("tokens");
+  static final byte[] TOKENS_RATE = Bytes.toBytes("tokens.rate");
+  static final byte[] TOKENS_SIZE = Bytes.toBytes("tokens.size");
+
+  HBaseConfiguration conf;
+  String tableName;
+  HTable table;
+  byte[] row;
+  int tokens;
+  double rate = 10.0; // default, 10 ops added per second
+  int size = 100;     // burst
+  long lastUpdated = System.currentTimeMillis();
+  long configUpdateInterval;
+  long lastConfigUpdated = System.currentTimeMillis();
+
+  void updateConfig() throws IOException {
+    Get get = new Get(row);
+    get.addColumn(USER, TOKENS_RATE);
+    get.addColumn(USER, TOKENS_SIZE);
+    Result result = table.get(get);
+    byte[] value = result.getValue(USER, TOKENS_RATE);
+    if (value != null) {
+      this.rate = (int)Bytes.toDouble(value);
+    }
+    value = result.getValue(USER, TOKENS_SIZE);
+    if (value != null) {
+      this.size = (int)Bytes.toLong(value);
+    }
+  }
+
+  /**
+   * Constructor
+   * @param conf configuration
+   * @param row row key for user
+   * @throws IOException
+   */
+  public HTableTokenBucket(HBaseConfiguration conf, byte[] row) 
+      throws IOException {
+    this(conf, conf.get("stargate.tb.htable.name", USERS_TABLE), row);
+  }
+
+  /**
+   * Constructor
+   * @param conf configuration
+   * @param tableName the table to use
+   * @param row row key for user
+   * @throws IOException
+   */
+  public HTableTokenBucket(HBaseConfiguration conf, String tableName,
+      byte[] row) throws IOException {
+    this.conf = conf;
+    this.tableName = tableName;
+    this.row = row;
+    this.table = new HTable(conf, tableName);
+    this.configUpdateInterval = 
+      conf.getLong("stargate.tb.update.interval", 1000 * 60);
+    updateConfig();
+  }
+
+  /**
+   * @return the number of remaining tokens in the bucket (roughly)
+   * @throws IOException
+   */
+  public int available() throws IOException {
+    long now = System.currentTimeMillis();
+    if (now - lastConfigUpdated > configUpdateInterval) {
+      try {
+        updateConfig();
+      } catch (IOException e) { 
+        LOG.warn(StringUtils.stringifyException(e));
+      }
+      lastConfigUpdated = now;
+    }
+
+    // We can't simply use incrementColumnValue here because the timestamp of
+    // the keyvalue will not be changed as long as it remains in memstore, so
+    // there will be some unavoidable contention on the row if multiple 
+    // Stargate instances are concurrently serving the same user, and three
+    // more round trips than otherwise.
+    RowLock rl = table.lockRow(row);
+    try {
+      Get get = new Get(row, rl);
+      get.addColumn(USER, TOKENS);
+      List<KeyValue> kvs = table.get(get).list();
+      if (kvs != null && !kvs.isEmpty()) {
+        KeyValue kv = kvs.get(0);
+        tokens = (int)Bytes.toLong(kv.getValue());
+        lastUpdated = kv.getTimestamp();
+      } else {
+        tokens = (int)rate;
+      }
+      long elapsed = now - lastUpdated;
+      int i = (int)((elapsed / 1000) * rate); // convert sec <-> ms
+      if (tokens + i > size) {
+        i = size - tokens;
+      }
+      if (i > 0) {
+        tokens += i;
+        Put put = new Put(row, rl);
+        put.add(USER, TOKENS, Bytes.toBytes((long)tokens));
+        put.setWriteToWAL(false);
+        table.put(put);
+        table.flushCommits();
+      }
+    } finally {
+      table.unlockRow(rl);
+    }
+    return tokens;
+  }
+
+  /**
+   * @param t the number of tokens to consume from the bucket
+   * @throws IOException
+   */
+  public void remove(int t) throws IOException {
+    // Here we don't care about timestamp changes; actually it's advantageous
+    // if they are not updated, otherwise available() and remove() must be
+    // used as near to each other in time as possible.
+    table.incrementColumnValue(row, USER, TOKENS, (long) -t, false);
+  }
+
+  public double getRate() {
+    return rate;
+  }
+
+  public int getSize() {
+    return size;
+  }
+
+}

Added: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/SoftUserData.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/SoftUserData.java?rev=925417&view=auto
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/SoftUserData.java (added)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/SoftUserData.java Fri Mar 19 21:01:26 2010
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.stargate.util;
+
+import java.util.Map;
+
+import org.apache.hadoop.hbase.stargate.User;
+import org.apache.hadoop.hbase.util.SoftValueMap;
+
+/**
+ * Provides a softmap backed collection of user data. The collection can be
+ * reclaimed by the garbage collector at any time when under heap pressure.
+ */
+public class SoftUserData extends UserData {
+
+  static final Map<User,UserData> map = new SoftValueMap<User,UserData>();
+
+  public static synchronized UserData get(final User user) {
+    UserData data = map.get(user);
+    if (data == null) {
+      data = new UserData();
+      map.put(user, data);
+    }
+    return data;
+  }
+
+  public static synchronized UserData put(final User user,
+      final UserData data) {
+    return map.put(user, data);
+  }
+
+}

Added: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/TokenBucket.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/TokenBucket.java?rev=925417&view=auto
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/TokenBucket.java (added)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/TokenBucket.java Fri Mar 19 21:01:26 2010
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.stargate.util;
+
+public class TokenBucket {
+
+  private int tokens;
+  private int rate;
+  private int size;
+  private long lastUpdated;
+
+  /**
+   * Constructor
+   * @param rate limit in units per second
+   * @param size maximum burst in units per second
+   */
+  public TokenBucket(int rate, int size) {
+    this.rate = rate;
+    this.tokens = this.size = size;
+  }
+
+  /**
+   * @return the number of remaining tokens in the bucket
+   */
+  public int available() {
+    long now = System.currentTimeMillis();
+    long elapsed = now - lastUpdated;
+    lastUpdated = now;
+    tokens += elapsed * rate;
+    if (tokens > size) {
+      tokens = size;
+    }
+    return tokens;
+  }
+
+  /**
+   * @param t the number of tokens to consume from the bucket
+   */
+  public void remove(int t) {
+    tokens -= t;
+  }
+
+}

Added: hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/UserData.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/UserData.java?rev=925417&view=auto
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/UserData.java (added)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/util/UserData.java Fri Mar 19 21:01:26 2010
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.stargate.util;
+
+import java.util.ArrayList;
+
+/**
+ * Generic storage for per user information.
+ */
+public class UserData {
+
+  public static final int TOKENBUCKET = 0;
+
+  ArrayList<Object> data = new ArrayList<Object>();
+
+  public synchronized boolean has(final int sel) {
+    try {
+      return data.get(sel) != null;
+    } catch (IndexOutOfBoundsException e) {
+      return false;
+    }
+  }
+
+  public synchronized Object get(final int sel) {
+    try {
+      return data.get(sel);
+    } catch (IndexOutOfBoundsException e) {
+      return null;
+    }
+  }
+
+  public synchronized Object put(final int sel, final Object o) {
+    Object old = null;
+    try {
+      old = data.get(sel);
+    } catch (IndexOutOfBoundsException e) {
+      // do nothing
+    }
+    data.set(sel, o);
+    return old;
+  }
+
+  public synchronized Object remove(int sel) {
+    return put(sel, null);
+  }
+
+}

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/MiniClusterTestCase.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/MiniClusterTestCase.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/MiniClusterTestCase.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/MiniClusterTestCase.java Fri Mar 19 21:01:26 2010
@@ -47,7 +47,7 @@ import com.sun.jersey.spi.container.serv
 import junit.framework.TestCase;
 
 public class MiniClusterTestCase extends TestCase {
-  private static final Log LOG =
+  protected static final Log LOG =
     LogFactory.getLog(MiniClusterTestCase.class);
 
   public static final String MIMETYPE_BINARY = "application/octet-stream";

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestHBCAuthenticator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestHBCAuthenticator.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestHBCAuthenticator.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestHBCAuthenticator.java Fri Mar 19 21:01:26 2010
@@ -21,6 +21,7 @@
 package org.apache.hadoop.hbase.stargate.auth;
 
 import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.stargate.User;
 
 import junit.framework.TestCase;
 

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestHTableAuthenticator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestHTableAuthenticator.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestHTableAuthenticator.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestHTableAuthenticator.java Fri Mar 19 21:01:26 2010
@@ -26,6 +26,7 @@ import org.apache.hadoop.hbase.client.HB
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.stargate.MiniClusterTestCase;
+import org.apache.hadoop.hbase.stargate.User;
 import org.apache.hadoop.hbase.util.Bytes;
 
 public class TestHTableAuthenticator extends MiniClusterTestCase {

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestJDBCAuthenticator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestJDBCAuthenticator.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestJDBCAuthenticator.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestJDBCAuthenticator.java Fri Mar 19 21:01:26 2010
@@ -25,6 +25,8 @@ import java.sql.DriverManager;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
+import org.apache.hadoop.hbase.stargate.User;
 import org.apache.hadoop.util.StringUtils;
 
 import junit.framework.TestCase;

Modified: hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestZooKeeperAuthenticator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestZooKeeperAuthenticator.java?rev=925417&r1=925416&r2=925417&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestZooKeeperAuthenticator.java (original)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/auth/TestZooKeeperAuthenticator.java Fri Mar 19 21:01:26 2010
@@ -20,8 +20,8 @@
 
 package org.apache.hadoop.hbase.stargate.auth;
 
-import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.stargate.MiniClusterTestCase;
+import org.apache.hadoop.hbase.stargate.User;
 import org.apache.hadoop.hbase.util.Bytes;
 
 import org.apache.zookeeper.CreateMode;

Added: hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/util/TestHTableTokenBucket.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/util/TestHTableTokenBucket.java?rev=925417&view=auto
==============================================================================
--- hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/util/TestHTableTokenBucket.java (added)
+++ hadoop/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/util/TestHTableTokenBucket.java Fri Mar 19 21:01:26 2010
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.stargate.util;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.stargate.MiniClusterTestCase;
+import org.apache.hadoop.hbase.stargate.util.HTableTokenBucket;
+import org.apache.hadoop.hbase.util.Bytes;
+
+public class TestHTableTokenBucket extends MiniClusterTestCase {
+
+  static final String TABLE = "users";
+  static final byte[] USER = Bytes.toBytes("user");
+  static final byte[] NAME = Bytes.toBytes("name");
+  static final byte[] TOKENS = Bytes.toBytes("tokens");
+  static final byte[] TOKENS_RATE = Bytes.toBytes("tokens.rate");
+  static final byte[] TOKENS_SIZE = Bytes.toBytes("tokens.size");
+  static final String USER_TOKEN = "da4829144e3a2febd909a6e1b4ed7cfa";
+  static final String USER_USERNAME = "testUser";
+  static final double RATE = 1; // per second
+  static final long SIZE = 10;
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    HBaseAdmin admin = new HBaseAdmin(conf);
+    if (!admin.tableExists(TABLE)) {
+      HTableDescriptor htd = new HTableDescriptor(TABLE);
+      htd.addFamily(new HColumnDescriptor(USER));
+      admin.createTable(htd);
+      HTable table = new HTable(TABLE);
+      Put put = new Put(Bytes.toBytes(USER_TOKEN));
+      put.add(USER, NAME, Bytes.toBytes(USER_USERNAME));
+      put.add(USER, TOKENS_RATE, Bytes.toBytes(RATE));
+      put.add(USER, TOKENS_SIZE, Bytes.toBytes(SIZE));
+      table.put(put);
+      table.flushCommits();
+    }
+  }
+
+  public void testTokenBucketConfig() throws Exception {
+    HTableTokenBucket tb = new HTableTokenBucket(conf, TABLE, 
+      Bytes.toBytes(USER_TOKEN));
+    assertEquals(tb.getRate(), RATE);
+    assertEquals(tb.getSize(), SIZE);
+  }
+
+  public void testTokenBucket() throws Exception {
+    HTableTokenBucket tb = new HTableTokenBucket(conf, TABLE, 
+      Bytes.toBytes(USER_TOKEN));
+    int last = 0;
+    for (int i = 0; i <= 5 && last < 10; i++) {
+      int avail = tb.available();
+      assertTrue("bucket did not increment", avail > last);
+      assertTrue("bucket updated too quickly", avail - last < 3);
+      last = avail;
+      Thread.sleep(2000);
+    }
+    assertTrue("bucket did not fill", last >= 10);
+    assertTrue("bucket overfilled", last == 10);
+  }
+
+}



Mime
View raw message