You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2009/06/29 04:49:26 UTC

svn commit: r789195 [2/11] - in /hadoop/hbase/trunk_on_hadoop-0.18.3/contrib: ./ stargate/ stargate/conf/ stargate/lib/ stargate/src/ stargate/src/java/ stargate/src/java/org/ stargate/src/java/org/apache/ stargate/src/java/org/apache/hadoop/ stargate/...

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResource.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResource.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResource.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,313 @@
+/*
+ * Copyright 2009 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;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.CacheControl;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.client.Delete;
+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.model.CellModel;
+import org.apache.hadoop.hbase.stargate.model.CellSetModel;
+import org.apache.hadoop.hbase.stargate.model.RowModel;
+import org.apache.hadoop.hbase.util.Bytes;
+
+public class RowResource implements Constants {
+  private static final Log LOG = LogFactory.getLog(RowResource.class);
+
+  private String table;
+  private RowSpec rowspec;
+  private CacheControl cacheControl;
+
+  public RowResource(String table, String rowspec, String versions) 
+      throws IOException {
+    this.table = table;
+    this.rowspec = new RowSpec(rowspec);
+    if (versions != null) {
+      this.rowspec.setMaxVersions(Integer.valueOf(versions));
+    }
+    cacheControl = new CacheControl();
+    cacheControl.setMaxAge(RESTServlet.getInstance().getMaxAge(table));
+    cacheControl.setNoTransform(false);
+  }
+
+  @GET
+  @Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
+    MIMETYPE_PROTOBUF})
+  public Response get(@Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("GET " + uriInfo.getAbsolutePath());
+    }
+    try {
+      ResultGenerator generator = ResultGenerator.fromRowSpec(table, rowspec);
+      if (!generator.hasNext()) {
+        throw new WebApplicationException(Response.Status.NOT_FOUND);
+      }
+      CellSetModel model = new CellSetModel();
+      KeyValue value = generator.next();
+      byte[] rowKey = value.getRow();
+      RowModel rowModel = new RowModel(rowKey);
+      do {
+        if (!Bytes.equals(value.getRow(), rowKey)) {
+          model.addRow(rowModel);
+          rowKey = value.getRow();
+          rowModel = new RowModel(rowKey);
+        }
+        rowModel.addCell(
+          new CellModel(value.getColumn(), value.getTimestamp(),
+              value.getValue()));
+        value = generator.next();
+      } while (value != null);
+      model.addRow(rowModel);
+      ResponseBuilder response = Response.ok(model);
+      response.cacheControl(cacheControl);
+      return response.build();
+    } catch (IOException e) {
+      throw new WebApplicationException(e,
+                  Response.Status.SERVICE_UNAVAILABLE);
+    }
+  }
+
+  @GET
+  @Produces(MIMETYPE_BINARY)
+  public Response getBinary(@Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("GET " + uriInfo.getAbsolutePath() + " as "+ MIMETYPE_BINARY);
+    }
+    // doesn't make sense to use a non specific coordinate as this can only
+    // return a single cell
+    if (!rowspec.hasColumns() || rowspec.getColumns().length > 1) {
+      throw new WebApplicationException(Response.Status.BAD_REQUEST);
+    }
+    try {
+      ResultGenerator generator = ResultGenerator.fromRowSpec(table, rowspec);
+      if (!generator.hasNext()) {
+        throw new WebApplicationException(Response.Status.NOT_FOUND);
+      }
+      KeyValue value = generator.next();
+      ResponseBuilder response = Response.ok(value.getValue());
+      response.cacheControl(cacheControl);
+      response.header("X-Timestamp", value.getTimestamp());
+      return response.build();
+    } catch (IOException e) {
+      throw new WebApplicationException(e,
+                  Response.Status.SERVICE_UNAVAILABLE);
+    }
+  }
+
+  private Response update(CellSetModel model, boolean replace) {
+    HTablePool pool;
+    try {
+      pool = RESTServlet.getInstance().getTablePool(this.table);
+    } catch (IOException e) {
+      throw new WebApplicationException(e, 
+                  Response.Status.INTERNAL_SERVER_ERROR);
+    }
+    HTable table = null;
+    try {
+      table = pool.get();
+      for (RowModel row: model.getRows()) {
+        Put put = new Put(row.getKey());
+        for (CellModel cell: row.getCells()) {
+          byte [][] parts = KeyValue.parseColumn(cell.getColumn());
+          if (cell.hasUserTimestamp()) {
+            put.add(parts[0], parts[1], cell.getTimestamp(), cell.getValue());
+          } else {
+            put.add(parts[0], parts[1], cell.getValue());
+          }
+        }
+        table.put(put);
+        if (LOG.isDebugEnabled()) {
+          LOG.debug("PUT " + put.toString());
+        }
+      }
+      table.flushCommits();
+      ResponseBuilder response = Response.ok();
+      return response.build();
+    } catch (IOException e) {
+      throw new WebApplicationException(e,
+                  Response.Status.SERVICE_UNAVAILABLE);
+    } finally {
+      if (table != null) {
+        pool.put(table);
+      }
+    }
+  }
+
+  private Response updateBinary(byte[] message, HttpHeaders headers, 
+      boolean replace) {
+    HTablePool pool;
+    try {
+      pool = RESTServlet.getInstance().getTablePool(this.table);
+    } catch (IOException e) {
+      throw new WebApplicationException(e, 
+                  Response.Status.INTERNAL_SERVER_ERROR);
+    }
+    HTable table = null;    
+    try {
+      byte[] row = rowspec.getRow();
+      byte[][] columns = rowspec.getColumns();
+      byte[] column = null;
+      if (columns != null) {
+        column = columns[0];
+      }
+      long timestamp = -1;
+      List<String> vals = headers.getRequestHeader("X-Row");
+      if (vals != null && !vals.isEmpty()) {
+        row = Bytes.toBytes(vals.get(0));
+      }
+      vals = headers.getRequestHeader("X-Column");
+      if (vals != null && !vals.isEmpty()) {
+        column = Bytes.toBytes(vals.get(0));
+      }
+      vals = headers.getRequestHeader("X-Timestamp");
+      if (vals != null && !vals.isEmpty()) {
+        timestamp = Long.valueOf(vals.get(0));
+      }
+      if (column == null) {
+        throw new WebApplicationException(Response.Status.BAD_REQUEST);
+      }
+      Put put = new Put(row);
+      byte parts[][] = KeyValue.parseColumn(column);
+      if (timestamp >= 0) {
+        put.add(parts[0], parts[1], timestamp, message);
+      } else {
+        put.add(parts[0], parts[1], message);
+      }
+      table = pool.get();
+      table.put(put);
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("PUT " + put.toString());
+      }
+      table.flushCommits();
+      return Response.ok().build();
+    } catch (IOException e) {
+      throw new WebApplicationException(e,
+                  Response.Status.SERVICE_UNAVAILABLE);
+    } finally {
+      if (table != null) {
+        pool.put(table);
+      }
+    }
+  }
+
+  @PUT
+  @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
+    MIMETYPE_PROTOBUF})
+  public Response put(CellSetModel model, @Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("PUT " + uriInfo.getAbsolutePath());
+    }
+    return update(model, true);
+  }
+
+  @PUT
+  @Consumes(MIMETYPE_BINARY)
+  public Response putBinary(byte[] message, @Context UriInfo uriInfo, 
+      @Context HttpHeaders headers)
+  {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("PUT " + uriInfo.getAbsolutePath() + " as "+ MIMETYPE_BINARY);
+    }
+    return updateBinary(message, headers, true);
+  }
+
+  @POST
+  @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
+    MIMETYPE_PROTOBUF})
+  public Response post(CellSetModel model, @Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("POST " + uriInfo.getAbsolutePath());
+    }
+    return update(model, false);
+  }
+
+  @POST
+  @Consumes(MIMETYPE_BINARY)
+  public Response postBinary(byte[] message, @Context UriInfo uriInfo, 
+      @Context HttpHeaders headers)
+  {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("POST " + uriInfo.getAbsolutePath() + " as "+ MIMETYPE_BINARY);
+    }
+    return updateBinary(message, headers, false);
+  }
+
+  @DELETE
+  public Response delete(@Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("DELETE " + uriInfo.getAbsolutePath());
+    }
+    Delete delete = new Delete(rowspec.getRow());
+    for (byte[] column: rowspec.getColumns()) {
+      byte[][] split = KeyValue.parseColumn(column);
+      if (rowspec.hasTimestamp()) {
+        delete.deleteColumns(split[0], split[1], rowspec.getTimestamp());
+      } else {
+        delete.deleteColumns(split[0], split[1]);        
+      }
+    }
+    HTablePool pool;
+    try {
+      pool = RESTServlet.getInstance().getTablePool(this.table);
+    } catch (IOException e) {
+      throw new WebApplicationException(e, 
+                  Response.Status.INTERNAL_SERVER_ERROR);
+    }
+    HTable table = null;
+    try {
+      table = pool.get();
+      table.delete(delete);
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("DELETE " + delete.toString());
+      }
+      table.flushCommits();
+    } catch (IOException e) {
+      throw new WebApplicationException(e, 
+                  Response.Status.SERVICE_UNAVAILABLE);
+    } finally {
+      if (table != null) {
+        pool.put(table);
+      }
+    }
+    return Response.ok().build();
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResultGenerator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResultGenerator.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResultGenerator.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResultGenerator.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2009 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;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+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.HTablePool;
+import org.apache.hadoop.hbase.client.Result;
+
+public class RowResultGenerator extends ResultGenerator {
+  private Iterator<KeyValue> valuesI;
+
+  public RowResultGenerator(String tableName, RowSpec rowspec)
+      throws IllegalArgumentException, IOException {
+    HTablePool pool = RESTServlet.getInstance().getTablePool(tableName); 
+    HTable table = pool.get();
+    try {
+      Get get = new Get(rowspec.getRow());
+      if (rowspec.hasColumns()) {
+        get.addColumns(rowspec.getColumns());
+      } else {
+        // rowspec does not explicitly specify columns, return them all
+        for (HColumnDescriptor family: 
+            table.getTableDescriptor().getFamilies()) {
+          get.addFamily(family.getName());
+        }
+      }
+      get.setTimeRange(rowspec.getStartTime(), rowspec.getEndTime());
+      get.setMaxVersions(rowspec.getMaxVersions());
+      Result result = table.get(get);
+      if (result != null && !result.isEmpty()) {
+        valuesI = result.list().iterator();
+      }
+    } finally {
+      pool.put(table);
+    }
+  }
+
+  public void close() {
+  }
+
+  public boolean hasNext() {
+    if (valuesI == null) {
+      return false;
+    }
+    return valuesI.hasNext();
+  }
+
+  public KeyValue next() {
+    if (valuesI == null) {
+      return null;
+    }
+    try {
+      return valuesI.next();
+    } catch (NoSuchElementException e) {
+      return null;
+    }
+  }
+
+  public void remove() {
+    throw new UnsupportedOperationException("remove not supported");
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowSpec.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowSpec.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowSpec.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowSpec.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,310 @@
+/*
+ * Copyright 2009 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;
+
+import java.util.Collection;
+import java.util.TreeSet;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.util.Bytes;
+
+public class RowSpec {
+  public static final long DEFAULT_START_TIMESTAMP = 0;
+  public static final long DEFAULT_END_TIMESTAMP = Long.MAX_VALUE;
+
+  private byte[] row = HConstants.EMPTY_START_ROW;
+  private byte[] endRow = null;
+  private TreeSet<byte[]> columns =
+    new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
+  private long startTime = DEFAULT_START_TIMESTAMP;
+  private long endTime = DEFAULT_END_TIMESTAMP;
+  private int maxVersions = HColumnDescriptor.DEFAULT_VERSIONS;
+
+  public RowSpec(String path) throws IllegalArgumentException {
+    int i = 0;
+    while (path.charAt(i) == '/') {
+      i++;
+    }
+    i = parseRowKeys(path, i);
+    i = parseColumns(path, i);
+    i = parseTimestamp(path, i);
+  }
+
+  private int parseRowKeys(String path, int i)
+      throws IllegalArgumentException {
+    StringBuilder startRow = new StringBuilder();
+    StringBuilder endRow = null;
+    try {
+      char c;
+      boolean doEndRow = false;
+      while (i < path.length() && (c = path.charAt(i)) != '/') {
+        if (c == ',') {
+          doEndRow = true;
+          i++;
+          break;
+        }
+        startRow.append(c);
+        i++;
+      }
+      i++;
+      this.row = Bytes.toBytes(startRow.toString());
+      if (doEndRow) {
+        endRow = new StringBuilder();
+        while ((c = path.charAt(i)) != '/') {
+          endRow.append(c);
+          i++;
+        }
+        i++;
+      }
+    } catch (IndexOutOfBoundsException e) {
+      throw new IllegalArgumentException(e);
+    }
+    // HBase does not support wildcards on row keys so we will emulate a
+    // suffix glob by synthesizing appropriate start and end row keys for
+    // table scanning
+    if (startRow.charAt(startRow.length() - 1) == '*') {
+      if (endRow != null)
+        throw new IllegalArgumentException("invalid path: start row "+
+          "specified with wildcard");
+      this.row = Bytes.toBytes(startRow.substring(0, 
+                   startRow.lastIndexOf("*")));
+      this.endRow = new byte[this.row.length + 1];
+      System.arraycopy(this.row, 0, this.endRow, 0, this.row.length);
+      this.endRow[this.row.length] = (byte)255;
+    } else {
+      this.row = Bytes.toBytes(startRow.toString());
+      if (endRow != null) {
+        this.endRow = Bytes.toBytes(endRow.toString());
+      }
+    }
+    return i;
+  }
+
+  private int parseColumns(String path, int i)
+      throws IllegalArgumentException {
+    if (i >= path.length()) {
+      return i;
+    }
+    try {
+      char c;
+      StringBuilder column = new StringBuilder();
+      boolean hasColon = false;
+      while (i < path.length() && (c = path.charAt(i)) != '/') {
+        if (c == ',') {
+          if (column.length() < 1) {
+            throw new IllegalArgumentException("invalid path");
+          }
+          if (!hasColon) {
+            column.append(':');
+          }
+          this.columns.add(Bytes.toBytes(column.toString()));
+          column = new StringBuilder();
+          hasColon = false;
+          i++;
+          continue;
+        }
+        if (c == ':') {
+          hasColon = true;
+        }
+        column.append(c);
+        i++;
+      }
+      i++;
+      // trailing list entry
+      if (column.length() > 1) {
+        if (!hasColon) {
+          column.append(':');
+        }
+        this.columns.add(Bytes.toBytes(column.toString()));
+      }
+    } catch (IndexOutOfBoundsException e) {
+      throw new IllegalArgumentException(e);
+    }
+    return i;
+  }
+
+  private int parseTimestamp(String path, int i)
+      throws IllegalArgumentException {
+    if (i >= path.length()) {
+      return i;
+    }
+    long time0 = 0, time1 = 0;
+    try {
+      char c = 0;
+      StringBuilder stamp = new StringBuilder();
+      while (i < path.length()) {
+        c = path.charAt(i);
+        if (c == '/' || c == ',') {
+          break;
+        }
+        stamp.append(c);
+        i++;
+      }
+      try {
+        time0 = Long.valueOf(stamp.toString());
+      } catch (NumberFormatException e) {
+        throw new IllegalArgumentException(e);
+      }
+      if (c == ',') {
+        stamp = new StringBuilder();
+        i++;
+        while (i < path.length() && ((c = path.charAt(i)) != '/')) {
+          stamp.append(c);
+          i++;
+        }
+        try {
+          time1 = Long.valueOf(stamp.toString());
+        } catch (NumberFormatException e) {
+          throw new IllegalArgumentException(e);
+        }
+      }
+      if (c == '/') {
+        i++;
+      }
+    } catch (IndexOutOfBoundsException e) {
+      throw new IllegalArgumentException(e);
+    }
+    if (time1 != 0) {
+      startTime = time0;
+      endTime = time1;
+    } else {
+      endTime = time0;
+    }
+    return i;
+  }
+
+  public RowSpec(byte[] startRow, byte[] endRow, byte[][] columns,
+      long startTime, long endTime, int maxVersions) {
+    this.row = startRow;
+    this.endRow = endRow;
+    if (columns != null) {
+      for (byte[] col: columns) {
+        this.columns.add(col);
+      }
+    }
+    this.startTime = startTime;
+    this.endTime = endTime;
+    this.maxVersions = maxVersions;
+  }
+
+  public RowSpec(byte[] startRow, byte[] endRow, Collection<byte[]> columns,
+      long startTime, long endTime, int maxVersions) {
+    this.row = startRow;
+    this.endRow = endRow;
+    if (columns != null) {
+      this.columns.addAll(columns);
+    }
+    this.startTime = startTime;
+    this.endTime = endTime;
+    this.maxVersions = maxVersions;
+  }
+
+  public boolean isSingleRow() {
+    return endRow == null;
+  }
+
+  public int getMaxVersions() {
+    return maxVersions;
+  }
+
+  public void setMaxVersions(int maxVersions) {
+    this.maxVersions = maxVersions;
+  }
+
+  public boolean hasColumns() {
+    return !columns.isEmpty();
+  }
+
+  public byte[] getRow() {
+    return row;
+  }
+
+  public byte[] getStartRow() {
+    return row;
+  }
+
+  public boolean hasEndRow() {
+    return endRow != null;
+  }
+
+  public byte[] getEndRow() {
+    return endRow;
+  }
+
+  public void addColumn(byte[] column) {
+    columns.add(column);
+  }
+
+  public byte[][] getColumns() {
+    return columns.toArray(new byte[columns.size()][]);
+  }
+
+  public boolean hasTimestamp() {
+    return (startTime == 0) && (endTime != Long.MAX_VALUE);
+  }
+
+  public long getTimestamp() {
+    return endTime;
+  }
+
+  public long getStartTime() {
+    return startTime;
+  }
+
+  public void setStartTime(long startTime) {
+    this.startTime = startTime;
+  }
+
+  public long getEndTime() {
+    return endTime;
+  }
+
+  public void setEndTime(long endTime) {
+    this.endTime = endTime;
+  }
+
+  public String toString() {
+    StringBuilder result = new StringBuilder();
+    result.append("{startRow => '");
+    if (row != null) {
+      result.append(Bytes.toString(row));
+    }
+    result.append("', endRow => '");
+    if (endRow != null)  {
+      result.append(Bytes.toString(endRow));
+    }
+    result.append("', columns => [");
+    for (byte[] col: columns) {
+      result.append(" '");
+      result.append(Bytes.toString(col));
+      result.append("'");
+    }
+    result.append(" ], startTime => ");
+    result.append(Long.toString(startTime));
+    result.append(", endTime => ");
+    result.append(Long.toString(endTime));
+    result.append(", maxVersions => ");
+    result.append(Integer.toString(maxVersions));
+    result.append("}");
+    return result.toString();
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerInstanceResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerInstanceResource.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerInstanceResource.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerInstanceResource.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2009 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;
+
+import java.io.IOException;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.CacheControl;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.stargate.model.CellModel;
+import org.apache.hadoop.hbase.stargate.model.CellSetModel;
+import org.apache.hadoop.hbase.stargate.model.RowModel;
+import org.apache.hadoop.hbase.util.Bytes;
+
+import com.sun.jersey.core.util.Base64;
+
+public class ScannerInstanceResource implements Constants {
+  private static final Log LOG =
+    LogFactory.getLog(ScannerInstanceResource.class);
+
+  protected ResultGenerator generator;
+  private String id;
+  private int batch;
+  private CacheControl cacheControl;
+
+  public ScannerInstanceResource(String table, String id, 
+      ResultGenerator generator, int batch) throws IOException {
+    this.id = id;
+    this.generator = generator;
+    this.batch = batch;
+    cacheControl = new CacheControl();
+    cacheControl.setNoCache(true);
+    cacheControl.setNoTransform(false);
+  }
+
+  @GET
+  @Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
+    MIMETYPE_PROTOBUF})
+  public Response get(@Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("GET " + uriInfo.getAbsolutePath());
+    }
+    CellSetModel model = new CellSetModel();
+    RowModel rowModel = null;
+    byte[] rowKey = null;
+    int count = batch;
+    do {
+      KeyValue value = null;
+      try {
+        value = generator.next();
+      } catch (IllegalStateException e) {
+        ScannerResource.delete(id);
+        throw new WebApplicationException(Response.Status.GONE);
+      }
+      if (value == null) {
+        LOG.info("generator exhausted");
+        // respond with 204 (No Content) if an empty cell set would be
+        // returned
+        if (count == batch) {
+          return Response.noContent().build();
+        }
+        break;
+      }
+      if (rowKey == null) {
+        rowKey = value.getRow();
+        rowModel = new RowModel(rowKey);
+      }
+      if (!Bytes.equals(value.getRow(), rowKey)) {
+        model.addRow(rowModel);
+        rowKey = value.getRow();
+        rowModel = new RowModel(rowKey);
+      }
+      rowModel.addCell(
+        new CellModel(value.getColumn(), value.getTimestamp(),
+              value.getValue()));
+    } while (--count > 0);
+    model.addRow(rowModel);
+    ResponseBuilder response = Response.ok(model);
+    response.cacheControl(cacheControl);
+    return response.build();
+  }
+
+  @GET
+  @Produces(MIMETYPE_BINARY)
+  public Response getBinary(@Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("GET " + uriInfo.getAbsolutePath() + " as " +
+        MIMETYPE_BINARY);
+    }
+    try {
+      KeyValue value = generator.next();
+      if (value == null) {
+        LOG.info("generator exhausted");
+        return Response.noContent().build();
+      }
+      ResponseBuilder response = Response.ok(value.getValue());
+      response.cacheControl(cacheControl);
+      response.header("X-Row", Base64.encode(value.getRow()));
+      response.header("X-Column", Base64.encode(value.getColumn()));
+      response.header("X-Timestamp", value.getTimestamp());
+      return response.build();
+    } catch (IllegalStateException e) {
+      ScannerResource.delete(id);
+      throw new WebApplicationException(Response.Status.GONE);
+    }
+  }
+
+  @DELETE
+  public Response delete(@Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("DELETE " + uriInfo.getAbsolutePath());
+    }
+    ScannerResource.delete(id);
+    return Response.ok().build();
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResource.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResource.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResource.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2009 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;
+
+import com.google.protobuf.InvalidProtocolBufferException;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.hadoop.hbase.stargate.model.ScannerModel;
+
+public class ScannerResource implements Constants {
+
+  private static final Log LOG = LogFactory.getLog(ScannerResource.class);
+  protected static final Map<String,ScannerInstanceResource> scanners = 
+    new HashMap<String,ScannerInstanceResource>();
+
+  private String table;
+
+  public ScannerResource(String table) {
+    this.table = table;
+  }
+
+  private Response update(ScannerModel model, boolean replace,
+      UriInfo uriInfo) {
+    try {
+      byte[] endRow = model.hasEndRow() ? model.getEndRow() : null;
+      RowSpec spec = new RowSpec(model.getStartRow(), endRow,
+        model.getColumns(), model.getStartTime(), model.getEndTime(), 1);
+      ScannerResultGenerator gen = new ScannerResultGenerator(table, spec);
+      String id = gen.getID();
+      ScannerInstanceResource instance = 
+        new ScannerInstanceResource(table, id, gen, model.getBatch());
+      synchronized (scanners) {
+        scanners.put(id, instance);
+      }
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("new scanner: " + id);
+      }
+      UriBuilder builder = uriInfo.getAbsolutePathBuilder();
+      URI uri = builder.path(id).build();
+      return Response.created(uri).build();
+    } catch (InvalidProtocolBufferException e) {
+      throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
+    } catch (IOException e) {
+      throw new WebApplicationException(e,
+              Response.Status.SERVICE_UNAVAILABLE);
+    }
+  }
+
+  @PUT
+  @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
+    MIMETYPE_PROTOBUF})
+  public Response put(ScannerModel model, @Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("PUT " + uriInfo.getAbsolutePath());
+    }
+    return update(model, true, uriInfo);
+  }
+
+  @POST
+  @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
+    MIMETYPE_PROTOBUF})
+  public Response post(ScannerModel model, @Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("POST " + uriInfo.getAbsolutePath());
+    }
+    return update(model, false, uriInfo);
+  }
+
+  @Path("{scanner: .+}")
+  public ScannerInstanceResource getScannerInstanceResource(
+      @PathParam("scanner") String id) {
+    synchronized (scanners) {
+      ScannerInstanceResource instance = scanners.get(id);
+      if (instance == null) {
+        throw new WebApplicationException(Response.Status.NOT_FOUND);
+      }
+      return instance;
+    }
+  }
+
+  static void delete(String id) {
+    synchronized (scanners) {
+      ScannerInstanceResource instance = scanners.remove(id);
+      if (instance != null) {
+        instance.generator.close();
+      }
+    }
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResultGenerator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResultGenerator.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResultGenerator.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/ScannerResultGenerator.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2009 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;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.UnknownScannerException;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.HTablePool;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.util.StringUtils;
+
+public class ScannerResultGenerator extends ResultGenerator {
+  private static final Log LOG =
+    LogFactory.getLog(ScannerResultGenerator.class);
+  
+  private String id;
+  private Iterator<KeyValue> rowI;
+  private ResultScanner scanner;
+  private Result cached;
+
+  public ScannerResultGenerator(String tableName, RowSpec rowspec)
+      throws IllegalArgumentException, IOException {
+    HTablePool pool = RESTServlet.getInstance().getTablePool(tableName); 
+    HTable table = pool.get();
+    try {
+      Scan scan;
+      if (rowspec.hasEndRow()) {
+        scan = new Scan(rowspec.getStartRow(), rowspec.getEndRow());
+      } else {
+        scan = new Scan(rowspec.getStartRow());
+      }
+      if (rowspec.hasColumns()) {
+        scan.addColumns(rowspec.getColumns());
+      } else {
+        for (HColumnDescriptor family: 
+            table.getTableDescriptor().getFamilies()) {
+          scan.addFamily(family.getName());
+        }
+      }
+      scan.setTimeRange(rowspec.getStartTime(), rowspec.getEndTime());          
+      scan.setMaxVersions(rowspec.getMaxVersions());
+      scanner = table.getScanner(scan);
+      cached = null;
+      id = Long.toString(System.currentTimeMillis()) +
+             Integer.toHexString(scanner.hashCode());
+    } finally {
+      pool.put(table);
+    }
+  }
+
+  public String getID() {
+    return id;
+  }
+
+  public void close() {
+  }
+
+  public boolean hasNext() {
+    if (rowI != null && rowI.hasNext()) {
+      return true;
+    }
+    if (cached != null) {
+      return true;
+    }
+    try {
+      Result result = scanner.next();
+      if (result != null && !result.isEmpty()) {
+        cached = result;
+      }
+    } catch (UnknownScannerException e) {
+      throw new IllegalArgumentException(e);
+    } catch (IOException e) {
+      LOG.error(StringUtils.stringifyException(e));
+    }
+    return cached != null;
+  }
+
+  public KeyValue next() {
+    boolean loop;
+    do {
+      loop = false;
+      if (rowI != null) {
+        if (rowI.hasNext()) {
+          return rowI.next();
+        } else {
+          rowI = null;
+        }
+      }
+      if (cached != null) {
+        rowI = cached.list().iterator();
+        loop = true;
+        cached = null;
+      } else {
+        Result result = null;
+        try {
+          result = scanner.next();
+        } catch (UnknownScannerException e) {
+          throw new IllegalArgumentException(e);
+        } catch (IOException e) {
+          LOG.error(StringUtils.stringifyException(e));
+        }
+        if (result != null && !result.isEmpty()) {
+          rowI = result.list().iterator();
+          loop = true;
+        }
+      }
+    } while (loop);
+    return null;
+  }
+
+  public void remove() {
+    throw new UnsupportedOperationException("remove not supported");
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/SchemaResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/SchemaResource.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/SchemaResource.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/SchemaResource.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,189 @@
+/*
+ * Copyright 2009 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;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.CacheControl;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.UriInfo;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.TableExistsException;
+import org.apache.hadoop.hbase.TableNotFoundException;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+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.model.ColumnSchemaModel;
+import org.apache.hadoop.hbase.stargate.model.TableSchemaModel;
+import org.apache.hadoop.hbase.util.Bytes;
+
+public class SchemaResource implements Constants {
+  private static final Log LOG = LogFactory.getLog(SchemaResource.class);
+
+  private String table;
+  private CacheControl cacheControl;
+
+  public SchemaResource(String table) {
+    this.table = table;
+    cacheControl = new CacheControl();
+    cacheControl.setNoCache(true);
+    cacheControl.setNoTransform(false);
+  }
+
+  private HTableDescriptor getTableSchema() throws IOException,
+      TableNotFoundException {
+    HTablePool pool = RESTServlet.getInstance().getTablePool(this.table);
+    HTable table = pool.get();
+    try {
+      return table.getTableDescriptor();
+    } finally {
+      pool.put(table);
+    }
+  }
+
+  @GET
+  @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
+    MIMETYPE_PROTOBUF})
+  public Response get(@Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("GET " + uriInfo.getAbsolutePath());
+    }
+    try {
+      HTableDescriptor htd = getTableSchema();
+      TableSchemaModel model = new TableSchemaModel();
+      model.setName(htd.getNameAsString());
+      for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e:
+          htd.getValues().entrySet()) {
+        model.addAttribute(Bytes.toString(e.getKey().get()), 
+            Bytes.toString(e.getValue().get()));
+      }
+      for (HColumnDescriptor hcd: htd.getFamilies()) {
+        ColumnSchemaModel columnModel = new ColumnSchemaModel();
+        columnModel.setName(hcd.getNameAsString());
+        for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e:
+          hcd.getValues().entrySet()) {
+        columnModel.addAttribute(Bytes.toString(e.getKey().get()), 
+          Bytes.toString(e.getValue().get()));
+      }
+        model.addColumnFamily(columnModel);
+      }
+      ResponseBuilder response = Response.ok(model);
+      response.cacheControl(cacheControl);
+      return response.build();
+    } catch (TableNotFoundException e) {
+      throw new WebApplicationException(Response.Status.NOT_FOUND);
+    } catch (IOException e) {
+      throw new WebApplicationException(e,
+                  Response.Status.SERVICE_UNAVAILABLE);
+    }
+  }
+
+  private Response update(TableSchemaModel model, boolean replace,
+      UriInfo uriInfo) {
+    // NOTE: 'replace' is currently ignored... we always replace the schema
+    try {
+      HTableDescriptor htd = new HTableDescriptor(table);
+      for (Map.Entry<QName,Object> e: model.getAny().entrySet()) {
+        htd.setValue(e.getKey().getLocalPart(), e.getValue().toString());
+      }
+      for (ColumnSchemaModel family: model.getColumns()) {
+        HColumnDescriptor hcd = new HColumnDescriptor(family.getName());
+        for (Map.Entry<QName,Object> e: family.getAny().entrySet()) {
+          hcd.setValue(e.getKey().getLocalPart(), e.getValue().toString());
+        }
+        htd.addFamily(hcd);
+      }
+      RESTServlet server = RESTServlet.getInstance();
+      HBaseAdmin admin = new HBaseAdmin(server.getConfiguration());
+      if (admin.tableExists(table)) {
+        admin.disableTable(table);
+        admin.modifyTable(Bytes.toBytes(table), htd);
+        server.invalidateMaxAge(table);
+        admin.enableTable(table);
+        return Response.ok().build();
+      } else {
+        admin.createTable(htd);
+        return Response.created(uriInfo.getAbsolutePath()).build();
+      }
+    } catch (TableExistsException e) {
+      // race, someone else created a table with the same name
+      throw new WebApplicationException(e, Response.Status.NOT_MODIFIED);
+    } catch (IOException e) {
+      throw new WebApplicationException(e, 
+            Response.Status.SERVICE_UNAVAILABLE);
+    }
+  }
+
+  @PUT
+  @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
+    MIMETYPE_PROTOBUF})
+  public Response put(TableSchemaModel model, @Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("PUT " + uriInfo.getAbsolutePath());
+    }
+    return update(model, true, uriInfo);
+  }
+
+  @POST
+  @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
+    MIMETYPE_PROTOBUF})
+  public Response post(TableSchemaModel model, @Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("PUT " + uriInfo.getAbsolutePath());
+    }
+    return update(model, false, uriInfo);
+  }
+
+  @DELETE
+  public Response delete(@Context UriInfo uriInfo) {     
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("DELETE " + uriInfo.getAbsolutePath());
+    }
+    try {
+      HBaseAdmin admin =
+        new HBaseAdmin(RESTServlet.getInstance().getConfiguration());
+      admin.disableTable(table);
+      admin.deleteTable(table);
+      return Response.ok().build();
+    } catch (TableNotFoundException e) {
+      throw new WebApplicationException(Response.Status.NOT_FOUND);
+    } catch (IOException e) {
+      throw new WebApplicationException(e, 
+            Response.Status.SERVICE_UNAVAILABLE);
+    }
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterStatusResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterStatusResource.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterStatusResource.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterStatusResource.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2009 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;
+
+import java.io.IOException;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.CacheControl;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.hadoop.hbase.ClusterStatus;
+import org.apache.hadoop.hbase.HServerInfo;
+import org.apache.hadoop.hbase.HServerLoad;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.stargate.model.StorageClusterStatusModel;
+
+@Path(Constants.PATH_STATUS_CLUSTER)
+public class StorageClusterStatusResource implements Constants {
+  private static final Log LOG =
+    LogFactory.getLog(StorageClusterStatusResource.class);
+
+  private CacheControl cacheControl;
+
+  public StorageClusterStatusResource() {
+    cacheControl = new CacheControl();
+    cacheControl.setNoCache(true);
+    cacheControl.setNoTransform(false);
+  }
+
+  @GET
+  @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
+    MIMETYPE_PROTOBUF})
+  public Response get(@Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("GET " + uriInfo.getAbsolutePath());
+    }
+    try {
+      RESTServlet server = RESTServlet.getInstance();
+      HBaseAdmin admin = new HBaseAdmin(server.getConfiguration());
+      ClusterStatus status = admin.getClusterStatus();
+      StorageClusterStatusModel model = new StorageClusterStatusModel();
+      model.setRegions(status.getRegionsCount());
+      model.setRequests(status.getRequestsCount());
+      model.setAverageLoad(status.getAverageLoad());
+      for (HServerInfo info: status.getServerInfo()) {
+        StorageClusterStatusModel.Node node = 
+          model.addLiveNode(
+            info.getServerAddress().getHostname() + ":" + 
+            Integer.toString(info.getServerAddress().getPort()),
+            info.getStartCode());
+        HServerLoad load = info.getLoad();
+        node.setRequests(load.getNumberOfRequests());
+        for (HServerLoad.RegionLoad region: load.getRegionsLoad()) {
+          node.addRegion(region.getName());
+        }
+      }
+      for (String name: status.getDeadServerNames()) {
+        model.addDeadNode(name);
+      }
+      ResponseBuilder response = Response.ok(model);
+      response.cacheControl(cacheControl);
+      return response.build();
+    } catch (IOException e) {
+      throw new WebApplicationException(e, 
+                  Response.Status.SERVICE_UNAVAILABLE);
+    }
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterVersionResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterVersionResource.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterVersionResource.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/StorageClusterVersionResource.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2009 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;
+
+import java.io.IOException;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.CacheControl;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.stargate.model.StorageClusterVersionModel;
+
+@Path(Constants.PATH_VERSION_CLUSTER)
+public class StorageClusterVersionResource implements Constants {
+  private static final Log LOG =
+    LogFactory.getLog(StorageClusterVersionResource.class);
+
+  private CacheControl cacheControl;
+
+  public StorageClusterVersionResource() {
+    cacheControl = new CacheControl();
+    cacheControl.setNoCache(true);
+    cacheControl.setNoTransform(false);
+  }
+
+  @GET
+  @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
+    MIMETYPE_PROTOBUF})
+  public Response get(@Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("GET " + uriInfo.getAbsolutePath());
+    }
+    try {
+      RESTServlet server = RESTServlet.getInstance();
+      HBaseAdmin admin = new HBaseAdmin(server.getConfiguration());
+      StorageClusterVersionModel model = new StorageClusterVersionModel();
+      model.setVersion(admin.getClusterStatus().getHBaseVersion());
+      ResponseBuilder response = Response.ok(model);
+      response.cacheControl(cacheControl);
+      return response.build();
+    } catch (IOException e) {
+      throw new WebApplicationException(e, 
+                  Response.Status.SERVICE_UNAVAILABLE);
+    }
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/TableResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/TableResource.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/TableResource.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/TableResource.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2009 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;
+
+import java.io.IOException;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.CacheControl;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+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.model.TableListModel;
+import org.apache.hadoop.hbase.stargate.model.TableModel;
+
+@Path("/")
+public class TableResource implements Constants {
+  private static final Log LOG = LogFactory.getLog(TableResource.class);
+
+  private CacheControl cacheControl;
+
+  public TableResource() {
+    cacheControl = new CacheControl();
+    cacheControl.setNoCache(true);
+    cacheControl.setNoTransform(false);
+  }
+
+  private HTableDescriptor[] getTableList() throws IOException {
+    HBaseAdmin admin =
+      new HBaseAdmin(RESTServlet.getInstance().getConfiguration());
+    HTableDescriptor[] list = admin.listTables();
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("getTableList:");
+      for (HTableDescriptor htd: list) {
+        LOG.debug(htd.toString());
+      }
+    }
+    return list;
+  }
+
+  @GET
+  @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
+    MIMETYPE_PROTOBUF})
+  public Response get(@Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("GET " + uriInfo.getAbsolutePath());
+    }
+    try {
+      TableListModel tableList = new TableListModel();
+      for (HTableDescriptor htd: getTableList()) {
+        if (htd.isMetaRegion()) {
+          continue;
+        }
+        tableList.add(new TableModel(htd.getNameAsString()));
+      }
+      ResponseBuilder response = Response.ok(tableList);
+      response.cacheControl(cacheControl);
+      return response.build();
+    } catch (IOException e) {
+      throw new WebApplicationException(e, 
+                  Response.Status.SERVICE_UNAVAILABLE);
+    }
+  }
+
+  @Path("{table}/regions")
+  public RegionsResource getRegionsResource(
+      @PathParam("table") String table) {
+    return new RegionsResource(table);    
+  }
+
+  @Path("{table}/scanner")
+  public ScannerResource getScannerResource(
+      @PathParam("table") String table) {
+    return new ScannerResource(table);    
+  }
+
+  @Path("{table}/schema")
+  public SchemaResource getSchemaResource(
+      @PathParam("table") String table) {
+    return new SchemaResource(table);    
+  }
+
+  @Path("{table}/{rowspec: .+}")
+  public RowResource getRowResource(
+      @PathParam("table") String table,
+      @PathParam("rowspec") String rowspec,
+      @QueryParam("v") String versions) {
+    try {
+      return new RowResource(table, rowspec, versions);
+    } catch (IOException e) {
+      throw new WebApplicationException(e, 
+                  Response.Status.INTERNAL_SERVER_ERROR);
+    }
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/VersionResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/VersionResource.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/VersionResource.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/VersionResource.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2009 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;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.CacheControl;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.stargate.model.VersionModel;
+
+@Path(Constants.PATH_VERSION)
+public class VersionResource implements Constants {
+  private static final Log LOG = LogFactory.getLog(VersionResource.class);
+
+  private CacheControl cacheControl;
+
+  public VersionResource() {
+    cacheControl = new CacheControl();
+    cacheControl.setNoCache(true);
+    cacheControl.setNoTransform(false);
+  }
+
+  @GET
+  @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
+    MIMETYPE_PROTOBUF})
+  public Response get(@Context ServletContext context, @Context UriInfo uriInfo) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("GET " + uriInfo.getAbsolutePath());
+    }
+    ResponseBuilder response = Response.ok(new VersionModel(context));
+    response.cacheControl(cacheControl);
+    return response.build();
+  }
+  
+  // "/version/stargate" is an alias for "/version"
+  @Path("stargate")
+  public VersionResource getVersionResource() {
+    return this;
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Client.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Client.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Client.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Client.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,242 @@
+/*
+ * Copyright 2009 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.client;
+
+import java.io.IOException;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.URI;
+import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.HeadMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.params.HttpClientParams;
+import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class Client {
+  public static final Header[] EMPTY_HEADER_ARRAY = new Header[0];
+
+  private static final Log LOG = LogFactory.getLog(Client.class);
+
+  private HttpClient httpClient;
+  private Cluster cluster;
+
+  public Client() {
+    this(null);
+  }
+
+  public Client(Cluster cluster) {
+    this.cluster = cluster;
+    httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
+    HttpConnectionManagerParams managerParams =
+      httpClient.getHttpConnectionManager().getParams();
+    managerParams.setConnectionTimeout(2000); // 2 s
+    HttpClientParams clientParams = httpClient.getParams();
+    clientParams.setVersion(HttpVersion.HTTP_1_1);
+  }
+
+  public void shutdown() {
+    MultiThreadedHttpConnectionManager manager = 
+      (MultiThreadedHttpConnectionManager) httpClient.getHttpConnectionManager();
+    manager.shutdown();
+  }
+
+  @SuppressWarnings("deprecation")
+  public int executePathOnly(Cluster c, HttpMethod method, Header[] headers,
+      String path) throws IOException {
+    IOException lastException;
+    if (c.nodes.size() < 1) {
+      throw new IOException("Cluster is empty");
+    }
+    int start = (int)Math.round((c.nodes.size() - 1) * Math.random());
+    int i = start;
+    do {
+      c.lastHost = c.nodes.get(i);
+      try {
+        StringBuffer sb = new StringBuffer();
+        sb.append("http://");
+        sb.append(c.lastHost);
+        sb.append(path);
+        URI uri = new URI(sb.toString());
+        return executeURI(method, headers, uri.toString());
+      } catch (IOException e) {
+        lastException = e;
+      }
+    } while (++i != start && i < c.nodes.size());
+    throw lastException;
+  }
+
+  @SuppressWarnings("deprecation")
+  public int executeURI(HttpMethod method, Header[] headers, String uri)
+      throws IOException {
+    method.setURI(new URI(uri));
+    if (headers != null) {
+      for (Header header: headers) {
+        method.addRequestHeader(header);
+      }
+    }
+    long startTime = System.currentTimeMillis();
+    int code = httpClient.executeMethod(method);
+    long endTime = System.currentTimeMillis();
+    if (LOG.isDebugEnabled()) {
+      LOG.debug(method.getName() + " " + uri + ": " + code + " " +
+        method.getStatusText() + " in " + (endTime - startTime) + " ms");
+    }
+    return code;
+  }
+
+  public int execute(Cluster c, HttpMethod method, Header[] headers,
+      String path) throws IOException {
+    if (path.startsWith("/")) {
+      return executePathOnly(c, method, headers, path);
+    }
+    return executeURI(method, headers, path);
+  }
+
+  public Cluster getCluster() {
+    return cluster;
+  }
+
+  public void setCluster(Cluster cluster) {
+    this.cluster = cluster;
+  }
+
+  public Response head(String path) throws IOException {
+    return head(cluster, path);
+  }
+
+  public Response head(Cluster c, String path) throws IOException {
+    HeadMethod method = new HeadMethod();
+    int code = execute(c, method, null, path);
+    Header[] headers = method.getResponseHeaders();
+    method.releaseConnection();
+    return new Response(code, headers, null);
+  }
+
+  public Response get(String path) throws IOException {
+    return get(cluster, path);
+  }
+
+  public Response get(Cluster c, String path) throws IOException {
+    return get(c, path, EMPTY_HEADER_ARRAY);
+  }
+
+  public Response get(String path, String accept) throws IOException {
+    return get(cluster, path, accept);
+  }
+
+  public Response get(Cluster c, String path, String accept)
+      throws IOException {
+    Header[] headers = new Header[1];
+    headers[0] = new Header("Accept", accept);
+    return get(c, path, headers);
+  }
+
+  public Response get(String path, Header[] headers) throws IOException {
+    return get(cluster, path, headers);
+  }
+
+  public Response get(Cluster c, String path, Header[] headers) 
+      throws IOException {
+    GetMethod method = new GetMethod();
+    int code = execute(c, method, headers, path);
+    headers = method.getResponseHeaders();
+    byte[] body = method.getResponseBody();
+    method.releaseConnection();
+    return new Response(code, headers, body);
+  }
+
+  public Response put(String path, String contentType, byte[] content)
+      throws IOException {
+    return put(cluster, path, contentType, content);
+  }
+
+  public Response put(Cluster c, String path, String contentType, 
+      byte[] content) throws IOException {
+    Header[] headers = new Header[1];
+    headers[0] = new Header("Content-Type", contentType);
+    return put(c, path, headers, content);
+  }
+
+  public Response put(String path, Header[] headers, byte[] body) 
+      throws IOException {
+    return put(cluster, path, headers, body);
+  }
+
+  public Response put(Cluster c, String path, Header[] headers, 
+      byte[] body) throws IOException {
+    PutMethod method = new PutMethod();
+    method.setRequestEntity(new ByteArrayRequestEntity(body));
+    int code = execute(c, method, headers, path);
+    headers = method.getResponseHeaders();
+    body = method.getResponseBody();
+    method.releaseConnection();
+    return new Response(code, headers, body);
+  }
+
+  public Response post(String path, String contentType, byte[] content)
+      throws IOException {
+    return post(cluster, path, contentType, content);
+  }
+
+  public Response post(Cluster c, String path, String contentType, 
+      byte[] content) throws IOException {
+    Header[] headers = new Header[1];
+    headers[0] = new Header("Content-Type", contentType);
+    return post(c, path, headers, content);
+  }
+
+  public Response post(String path, Header[] headers, byte[] content) 
+      throws IOException {
+    return post(cluster, path, headers, content);
+  }
+
+  public Response post(Cluster c, String path, Header[] headers, 
+      byte[] content) throws IOException {
+    PostMethod method = new PostMethod();
+    method.setRequestEntity(new ByteArrayRequestEntity(content));
+    int code = execute(c, method, headers, path);
+    headers = method.getResponseHeaders();
+    content = method.getResponseBody();
+    method.releaseConnection();
+    return new Response(code, headers, content);
+  }
+
+  public Response delete(String path) throws IOException {
+    return delete(cluster, path);
+  }
+
+  public Response delete(Cluster c, String path) throws IOException {
+    DeleteMethod method = new DeleteMethod();
+    int code = execute(c, method, null, path);
+    Header[] headers = method.getResponseHeaders();
+    method.releaseConnection();
+    return new Response(code, headers);
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Cluster.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Cluster.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Cluster.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Cluster.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2009 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.client;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class Cluster {
+  protected List<String> nodes = 
+    Collections.synchronizedList(new ArrayList<String>());
+  protected String lastHost;
+
+  /**
+   * Constructor
+   */
+  public Cluster() {}
+
+  /**
+   * Constructor
+   * @param nodes a list of service locations, in 'host:port' format
+   */
+  public Cluster(List<String> nodes) {
+    nodes.addAll(nodes);
+  }
+
+  /**
+   * Add a node to the cluster
+   * @param name the service location in 'host:port' format
+   */
+  public Cluster add(String node) {
+    nodes.add(node);
+    return this;
+  }
+
+  /**
+   * Add a node to the cluster
+   * @param name host name
+   * @param port service port
+   */
+  public Cluster add(String name, int port) {
+    StringBuilder sb = new StringBuilder();
+    sb.append(name);
+    sb.append(':');
+    sb.append(port);
+    return add(sb.toString());
+  }
+
+  /**
+   * Remove a node from the cluster
+   * @param name the service location in 'host:port' format
+   */
+  public Cluster remove(String node) {
+    nodes.remove(node);
+    return this;
+  }
+
+  /**
+   * Remove a node from the cluster
+   * @param name host name
+   * @param port service port
+   */
+  public Cluster remove(String name, int port) {
+    StringBuilder sb = new StringBuilder();
+    sb.append(name);
+    sb.append(':');
+    sb.append(port);
+    return remove(sb.toString());
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Response.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Response.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Response.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Response.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2009 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.client;
+
+import org.apache.commons.httpclient.Header;
+
+public class Response {
+  private int code;
+  private Header[] headers;
+  private byte[] body;
+
+  /**
+   * Constructor
+   * @param code the HTTP response code
+   */
+  public Response(int code) {
+    this(code, null, null);
+  }
+
+  /**
+   * Constructor
+   * @param code the HTTP response code
+   * @param headers the HTTP response headers
+   */
+  public Response(int code, Header[] headers) {
+    this(code, headers, null);
+  }
+
+  /**
+   * Constructor
+   * @param code the HTTP response code
+   * @param headers the HTTP response headers
+   * @param body the response body, can be null
+   */
+  public Response(int code, Header[] headers, byte[] body) {
+    this.code = code;
+    this.headers = headers;
+    this.body = body;
+  }
+
+  /**
+   * @return the HTTP response code
+   */
+  public int getCode() {
+    return code;
+  }
+
+  /**
+   * @return the HTTP response headers
+   */
+  public Header[] getHeaders() {
+    return headers;
+  }
+
+  /**
+   * @return the value of the Location header
+   */
+  public String getLocation() {
+    for (Header header: headers) {
+      if (header.getName().equals("Location")) {
+        return header.getValue();
+      }
+    }
+    return null;
+  }
+
+  /**
+   * @return true if a response body was sent
+   */
+  public boolean hasBody() {
+    return body != null;
+  }
+
+  /**
+   * @return the HTTP response body
+   */
+  public byte[] getBody() {
+    return body;
+  }
+
+  /**
+   * @param code the HTTP response code
+   */
+  public void setCode(int code) {
+    this.code = code;
+  }
+
+  /**
+   * @param headers the HTTP response headers
+   */
+  public void setHeaders(Header[] headers) {
+    this.headers = headers;
+  }
+
+  /**
+   * @param body the response body
+   */
+  public void setBody(byte[] body) {
+    this.body = body;
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/model/CellModel.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/model/CellModel.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/model/CellModel.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/model/CellModel.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2009 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.model;
+
+import java.io.IOException;
+import java.io.Serializable;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlValue;
+
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.stargate.protobuf.generated.CellMessage.Cell;
+
+import com.google.protobuf.ByteString;
+
+@XmlRootElement(name="Cell")
+@XmlType(propOrder={"column","timestamp"})
+public class CellModel implements IProtobufWrapper, Serializable {
+  private static final long serialVersionUID = 1L;
+  
+  private long   timestamp = HConstants.LATEST_TIMESTAMP;
+  private byte[] column;
+  private byte[] value;
+
+  public CellModel() {}
+
+  /**
+   * @param column
+   * @param value
+   */
+  public CellModel(byte[] column, byte[] value) {
+    super();
+    this.column = column;
+    this.value = value;
+  }
+
+  /**
+   * @param column
+   * @param timestamp
+   * @param value
+   */
+  public CellModel(byte[] column, long timestamp, byte[] value) {
+    super();
+    this.column = column;
+    this.timestamp = timestamp;
+    this.value = value;
+  }
+  
+  /**
+   * @return the column
+   */
+  @XmlAttribute
+  public byte[] getColumn() {
+    return column;
+  }
+
+  /**
+   * @param column the column to set
+   */
+  public void setColumn(byte[] column) {
+    this.column = column;
+  }
+
+  /**
+   * @return true if the timestamp property has been specified by the
+   * user
+   */
+  public boolean hasUserTimestamp() {
+    return timestamp != HConstants.LATEST_TIMESTAMP;
+  }
+
+  /**
+   * @return the timestamp
+   */
+  @XmlAttribute
+  public long getTimestamp() {
+    return timestamp;
+  }
+
+  /**
+   * @param timestamp the timestamp to set
+   */
+  public void setTimestamp(long timestamp) {
+    this.timestamp = timestamp;
+  }
+
+  /**
+   * @return the value
+   */
+  @XmlValue
+  public byte[] getValue() {
+    return value;
+  }
+
+  /**
+   * @param value the value to set
+   */
+  public void setValue(byte[] value) {
+    this.value = value;
+  }
+
+  @Override
+  public byte[] createProtobufOutput() {
+    Cell.Builder builder = Cell.newBuilder();
+    builder.setColumn(ByteString.copyFrom(getColumn()));
+    builder.setData(ByteString.copyFrom(getValue()));
+    if (hasUserTimestamp()) {
+      builder.setTimestamp(getTimestamp());
+    }
+    return builder.build().toByteArray();
+  }
+
+  @Override
+  public IProtobufWrapper getObjectFromMessage(byte[] message)
+      throws IOException {
+    Cell.Builder builder = Cell.newBuilder();
+    builder.mergeFrom(message);
+    setColumn(builder.getColumn().toByteArray());
+    setValue(builder.getData().toByteArray());
+    if (builder.hasTimestamp()) {
+      setTimestamp(builder.getTimestamp());
+    }
+    return this;
+  }
+}

Added: hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/model/CellSetModel.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/model/CellSetModel.java?rev=789195&view=auto
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/model/CellSetModel.java (added)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/model/CellSetModel.java Mon Jun 29 02:49:21 2009
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2009 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.model;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlElement;
+
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.stargate.protobuf.generated.CellMessage.Cell;
+import org.apache.hadoop.hbase.stargate.protobuf.generated.CellSetMessage.CellSet;
+
+import com.google.protobuf.ByteString;
+
+@XmlRootElement(name="CellSet")
+public class CellSetModel implements Serializable, IProtobufWrapper {
+
+  private static final long serialVersionUID = 1L;
+  
+  private List<RowModel> rows;
+  
+  
+  public CellSetModel() {
+    this.rows = new ArrayList<RowModel>();
+  }
+  
+  /**
+   * @param rows
+   */
+  
+  public CellSetModel(List<RowModel> rows) {
+    super();
+    this.rows = rows;
+  }
+  
+  /**
+   * Add a row to this cell set
+   * 
+   * @param row
+   */
+  public void addRow(RowModel row) {
+    rows.add(row);
+  }
+
+  /**
+   * @return the rows
+   */
+  @XmlElement(name="Row")
+  public List<RowModel> getRows() {
+    return rows;
+  }
+
+  @Override
+  public byte[] createProtobufOutput() {
+    CellSet.Builder builder = CellSet.newBuilder();
+    for (RowModel row: getRows()) {
+      CellSet.Row.Builder rowBuilder = CellSet.Row.newBuilder();
+      rowBuilder.setKey(ByteString.copyFrom(row.getKey()));
+      for (CellModel cell: row.getCells()) {
+        Cell.Builder cellBuilder = Cell.newBuilder();
+        cellBuilder.setColumn(ByteString.copyFrom(cell.getColumn()));
+        cellBuilder.setData(ByteString.copyFrom(cell.getValue()));
+        if (cell.hasUserTimestamp()) {
+          cellBuilder.setTimestamp(cell.getTimestamp());
+        }
+        rowBuilder.addValues(cellBuilder);
+      }
+      builder.addRows(rowBuilder);
+    }
+    return builder.build().toByteArray();
+  }
+
+  @Override
+  public IProtobufWrapper getObjectFromMessage(byte[] message)
+      throws IOException {
+    CellSet.Builder builder = CellSet.newBuilder();
+    builder.mergeFrom(message);
+    for (CellSet.Row row: builder.getRowsList()) {
+      RowModel rowModel = new RowModel(row.getKey().toByteArray());
+      for (Cell cell: row.getValuesList()) {
+        long timestamp = HConstants.LATEST_TIMESTAMP;
+        if (cell.hasTimestamp()) {
+          timestamp = cell.getTimestamp();
+        }
+        rowModel.addCell(
+            new CellModel(cell.getColumn().toByteArray(), timestamp,
+                  cell.getData().toByteArray()));
+      }
+      addRow(rowModel);
+    }
+    return this;
+  }
+}