Package org.apache.hadoop.hbase.client

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


   * @throws java.io.IOException
   * @throws StorageTableNotFoundException
   */
  public Result get(String tableName, Get get) throws IOException,
      StorageTableNotFoundException {
    HTableInterface tableInterface = getTable(tableName);

    try {
      return tableInterface.get(get);
    } finally {
      // return table to hTable pool
      tableInterface.close();
    }
  }
View Full Code Here


   * @throws java.io.IOException
   * @throws StorageTableNotFoundException
   */
  public boolean exits(String tableName, Get get) throws IOException,
      StorageTableNotFoundException {
    HTableInterface tableInterface = getTable(tableName);

    try {
      return tableInterface.exists(get);
    } finally {
      // return table to hTable pool
      tableInterface.close();
    }
  }
View Full Code Here

   * @throws java.io.IOException
   * @throws StorageTableNotFoundException
   */
  public Result[] get(String tableName, List<Get> gets) throws IOException,
      StorageTableNotFoundException {
    HTableInterface tableInterface = getTable(tableName);

    try {
      return tableInterface.get(gets);
    } finally {
      // return table to hTable pool
      tableInterface.close();
    }
  }
View Full Code Here

   * @throws StorageTableNotFoundException
   * @throws InterruptedException
   */
  public void batch(String tableName, final List<? extends Row> actions)
      throws IOException, StorageTableNotFoundException, InterruptedException {
    HTableInterface tableInterface = getTable(tableName);

    try {
      tableInterface.batch(actions);
    } finally {
      // return table to hTable pool
      tableInterface.close();
    }
  }
View Full Code Here

   * @throws StorageTableNotFoundException
   * @throws java.io.IOException
   */
  public ResultScanner scan(String tableName, Scan scan)
      throws StorageTableNotFoundException, IOException {
    HTableInterface tableInterface = getTable(tableName);
    try {
      return tableInterface.getScanner(scan);
    } finally {
      // return table to hTable pool
      tableInterface.close();
    }
  }
View Full Code Here

   *
   * @return false if storage system is not available
   */
  public boolean checkStorageSystem() {
    try {
      HTableInterface htable = this.getActionManager().getTable(
          conf.get(FConstants.METASTORE_TABLE,
              FConstants.DEFAULT_METASTORE_TABLE));
      htable.close();
    } catch (Throwable e) {
      return false;
    }
    return true;
  }
View Full Code Here

    } 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();
    } catch (IOException e) {
      servlet.getMetrics().incrementFailedPutRequests(1);
      return Response.status(Response.Status.SERVICE_UNAVAILABLE)
        .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
        .build();
    } finally {
      if (table != null) try {
        table.close();
      } catch (IOException ioe) {
        LOG.debug("Exception received while closing the table", ioe);
      }
    }
  }
View Full Code Here

      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);
      return Response.ok().build();
    } catch (IOException e) {
      servlet.getMetrics().incrementFailedPutRequests(1);
      return Response.status(Response.Status.SERVICE_UNAVAILABLE)
        .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
        .build();
    } finally {
      if (table != null) try {
        table.close();
      } catch (IOException ioe) { }
    }
  }
View Full Code Here

          delete.deleteFamily(split[0]);
        }
      }
    }
    HTablePool pool = servlet.getTablePool();
    HTableInterface table = null;
    try {
      table = pool.getTable(tableResource.getName());
      table.delete(delete);
      servlet.getMetrics().incrementSucessfulDeleteRequests(1);
      if (LOG.isDebugEnabled()) {
        LOG.debug("DELETE " + delete.toString());
      }
    } catch (IOException e) {
      servlet.getMetrics().incrementFailedDeleteRequests(1);
      return Response.status(Response.Status.SERVICE_UNAVAILABLE)
        .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
        .build();
    } finally {
      if (table != null) try {
        table.close();
      } catch (IOException ioe) { }
    }
    return Response.ok().build();
  }
View Full Code Here

   * @param model instance of CellSetModel
   * @return Response 200 OK, 304 Not modified, 400 Bad request
   */
  Response checkAndPut(final CellSetModel model) {
    HTablePool pool = servlet.getTablePool();
    HTableInterface table = null;
    try {
      if (model.getRows().size() != 1) {
        return Response.status(Response.Status.BAD_REQUEST)
          .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
          .build();
      }

      RowModel rowModel = model.getRows().get(0);
      byte[] key = rowModel.getKey();
      if (key == null) {
        key = rowspec.getRow();
      }

      List<CellModel> cellModels = rowModel.getCells();
      int cellModelCount = cellModels.size();
      if (key == null || cellModelCount <= 1) {
        return Response.status(Response.Status.BAD_REQUEST)
          .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
          .build();
      }

      Put put = new Put(key);
      CellModel valueToCheckCell = cellModels.get(cellModelCount - 1);
      byte[] valueToCheckColumn = valueToCheckCell.getColumn();
      byte[][] valueToPutParts = KeyValue.parseColumn(valueToCheckColumn);
      if (valueToPutParts.length == 2 && valueToPutParts[1].length > 0) {
        CellModel valueToPutCell = null;
        for (int i = 0, n = cellModelCount - 1; i < n ; i++) {
          if(Bytes.equals(cellModels.get(i).getColumn(),
              valueToCheckCell.getColumn())) {
            valueToPutCell = cellModels.get(i);
            break;
          }
        }
        if (valueToPutCell != null) {
          put.add(valueToPutParts[0], valueToPutParts[1], valueToPutCell
            .getTimestamp(), valueToPutCell.getValue());
        } else {
          return Response.status(Response.Status.BAD_REQUEST)
            .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
            .build();
        }
      } else {
        return Response.status(Response.Status.BAD_REQUEST)
          .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
          .build();
      }

      table = pool.getTable(this.tableResource.getName());
      boolean retValue = table.checkAndPut(key, valueToPutParts[0],
        valueToPutParts[1], valueToCheckCell.getValue(), put);
      if (LOG.isDebugEnabled()) {
        LOG.debug("CHECK-AND-PUT " + put.toString() + ", returns " + retValue);
      }
      table.flushCommits();
      ResponseBuilder response = Response.ok();
      if (!retValue) {
        response = Response.status(304);
      }
      return response.build();
    } catch (IOException e) {
      return Response.status(Response.Status.SERVICE_UNAVAILABLE)
        .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
        .build();
    } finally {
      if (table != null) try {
        table.close();
      } catch (IOException ioe) { }
    }
  }
View Full Code Here

TOP

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

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.