Package org.apache.hadoop.hbase.client

Examples of org.apache.hadoop.hbase.client.HTablePool


    this.tableResource = tableResource;
  }

  private HTableDescriptor getTableSchema() throws IOException,
      TableNotFoundException {
    HTablePool pool = servlet.getTablePool();
    HTableInterface table = pool.getTable(tableResource.getName());
    try {
      return table.getTableDescriptor();
    } finally {
      table.close();
    }
View Full Code Here


    output = new OutputCollector();
    reporter = new Reporter();
    if(conf.getBoolean("hbase.writer.verify.schema", false)) {
      verifyHbaseSchema();     
    }
    pool = new HTablePool(hconf, 60);
  }
View Full Code Here

   * @param conf
   */
  public StorageActionManager(Configuration conf) throws IOException {
    try {
      hbc = HBaseConfiguration.create(conf);
      pool = new HTablePool(hbc, conf.getInt(
          FConstants.WASP_FSERVER_MAX_TABLE_COUNT, MAX_TABLE_COUNT));
      admin = new HBaseAdmin(hbc);
    } catch (MasterNotRunningException e) {
      LOG.error("HBaseActionManager initlized failed.HMaster is not running.",
          e);
View Full Code Here

   * Constructor
   * @throws IOException
   */
  public RESTServlet() throws IOException {
    this.conf = new HBaseConfiguration();
    this.pool = new HTablePool(conf, 10);
  }
View Full Code Here

  private ResultScanner scanner;
  private Result cached;

  public ScannerResultGenerator(String tableName, RowSpec rowspec)
      throws IllegalArgumentException, IOException {
    HTablePool pool = RESTServlet.getInstance().getTablePool();
    HTable table = pool.getTable(tableName);
    try {
      Scan scan;
      if (rowspec.hasEndRow()) {
        scan = new Scan(rowspec.getStartRow(), rowspec.getEndRow());
      } else {
        scan = new Scan(rowspec.getStartRow());
      }
      if (rowspec.hasColumns()) {
        byte[][] columns = rowspec.getColumns();
        for (byte[] column: columns) {
          byte[][] split = KeyValue.parseColumn(column);
          if (split.length == 2 && split[1].length != 0) {
            scan.addColumn(split[0], split[1]);
          } else {
            scan.addFamily(split[0]);
          }
        }
      } 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.putTable(table);
    }
  }
View Full Code Here

                  Response.Status.SERVICE_UNAVAILABLE);
    }
  }

  private Response update(CellSetModel model, boolean replace) {
    HTablePool pool;
    try {
      pool = RESTServlet.getInstance().getTablePool();
    } catch (IOException e) {
      throw new WebApplicationException(e,
                  Response.Status.INTERNAL_SERVER_ERROR);
    }
    HTable table = null;
    try {
      table = pool.getTable(this.table);
      for (RowModel row: model.getRows()) {
        byte[] key = row.getKey();
        Put put = new Put(key);
        for (CellModel cell: row.getCells()) {
          byte [][] parts = KeyValue.parseColumn(cell.getColumn());
          put.add(parts[0], parts[1], cell.getTimestamp(), 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.putTable(table);
      }
    }
  }
View Full Code Here

    }
  }

  private Response updateBinary(byte[] message, HttpHeaders headers,
      boolean replace) {
    HTablePool pool;
    try {
      pool = RESTServlet.getInstance().getTablePool();
    } 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 = HConstants.LATEST_TIMESTAMP;
      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);
      put.add(parts[0], parts[1], timestamp, message);
      table = pool.getTable(this.table);
      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.putTable(table);
      }
    }
  }
View Full Code Here

        } else {
          delete.deleteFamily(split[0]);
        }
      }
    }
    HTablePool pool;
    try {
      pool = RESTServlet.getInstance().getTablePool();
    } catch (IOException e) {
      throw new WebApplicationException(e,
                  Response.Status.INTERNAL_SERVER_ERROR);
    }
    HTable table = null;
    try {
      table = pool.getTable(this.table);
      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.putTable(table);
      }
    }
    return Response.ok().build();
  }
View Full Code Here

      return checkAndDelete(model);
    } else if (check != null && check.length() > 0) {
      LOG.warn("Unknown check value: " + check + ", ignored");
    }

    HTablePool pool = servlet.getTablePool();
    HTableInterface table = null;
    try {
      List<RowModel> rows = model.getRows();
      List<Put> puts = new ArrayList<Put>();
      for (RowModel row: rows) {
        byte[] key = row.getKey();
        if (key == null) {
          key = rowspec.getRow();
        }
        if (key == null) {
          return Response.status(Response.Status.BAD_REQUEST)
            .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
            .build();
        }
        Put put = new Put(key);
        int i = 0;
        for (CellModel cell: row.getCells()) {
          byte[] col = cell.getColumn();
          if (col == null) try {
            col = rowspec.getColumns()[i++];
          } catch (ArrayIndexOutOfBoundsException e) {
            col = null;
          }
          if (col == null) {
            return Response.status(Response.Status.BAD_REQUEST)
              .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
              .build();
          }
          byte [][] parts = KeyValue.parseColumn(col);
          if (parts.length == 2 && parts[1].length > 0) {
            put.add(parts[0], parts[1], cell.getTimestamp(), cell.getValue());
          } else {
            put.add(parts[0], null, cell.getTimestamp(), cell.getValue());
          }
        }
        puts.add(put);
        if (LOG.isDebugEnabled()) {
          LOG.debug("PUT " + put.toString());
        }
      }
      table = pool.getTable(tableResource.getName());
      table.put(puts);
      table.flushCommits();
      ResponseBuilder response = Response.ok();
      servlet.getMetrics().incrementSucessfulPutRequests(1);
      return response.build();
View Full Code Here

    if (servlet.isReadOnly()) {
      return Response.status(Response.Status.FORBIDDEN)
        .type(MIMETYPE_TEXT).entity("Forbidden" + CRLF)
        .build();
    }
    HTablePool pool = servlet.getTablePool();
    HTableInterface table = null;
    try {
      byte[] row = rowspec.getRow();
      byte[][] columns = rowspec.getColumns();
      byte[] column = null;
      if (columns != null) {
        column = columns[0];
      }
      long timestamp = HConstants.LATEST_TIMESTAMP;
      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) {
        return Response.status(Response.Status.BAD_REQUEST)
          .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
          .build();
      }
      Put put = new Put(row);
      byte parts[][] = KeyValue.parseColumn(column);
      if (parts.length == 2 && parts[1].length > 0) {
        put.add(parts[0], parts[1], timestamp, message);
      } else {
        put.add(parts[0], null, timestamp, message);
      }
      table = pool.getTable(tableResource.getName());
      table.put(put);
      if (LOG.isDebugEnabled()) {
        LOG.debug("PUT " + put.toString());
      }
      servlet.getMetrics().incrementSucessfulPutRequests(1);
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.client.HTablePool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.