Package org.apache.hadoop.hbase

Examples of org.apache.hadoop.hbase.HBaseAdmin


  public void init() throws ServletException {
    super.init();
   
    HBaseConfiguration conf = new HBaseConfiguration();
    HBaseAdmin admin = null;
   
    try{
      admin = new HBaseAdmin(conf);
      metaHandler = new MetaHandler(conf, admin);
      tableHandler = new TableHandler(conf, admin);
      scannerHandler = new ScannerHandler(conf, admin);
    } catch(Exception e){
      throw new ServletException(e);
View Full Code Here


     *
     * @throws MasterNotRunningException
     */
    HBaseHandler() throws MasterNotRunningException {
      conf = new HBaseConfiguration();
      admin = new HBaseAdmin(conf);
      scannerMap = new HashMap<Integer, HScannerInterface>();
    }
View Full Code Here

      HConnection conn = HConnectionManager.getConnection(conf);
      if (!conn.tableExists(tableName)) {
        return new ReturnMsg(0, "'" + tableName + "'" + TABLE_NOT_FOUND);
      }

      HBaseAdmin admin = new HBaseAdmin(conf);
      HTable hTable = new HTable(conf, tableName);

      if (rowKey != null) {
        long lockID = hTable.startUpdate(rowKey);
        for (Text column : getColumnList(admin, hTable)) {
          hTable.delete(lockID, new Text(column));
        }
        hTable.commit(lockID);
      } else {
        admin.disableTable(tableName);
        for (Text column : getColumnList(admin, hTable)) {
          admin.deleteColumn(tableName, new Text(column));
        }
        admin.enableTable(tableName);
      }

      return new ReturnMsg(1, "Column(s) deleted successfully.");
    } catch (IOException e) {
      String[] msg = e.getMessage().split("[\n]");
View Full Code Here

    if (tableList == null) {
      throw new IllegalArgumentException("List of tables is null.");
    }

    try {
      HBaseAdmin admin = new HBaseAdmin(conf);
      HConnection conn = HConnectionManager.getConnection(conf);

      int count = 0;
      for (String table : tableList) {
        if (!conn.tableExists(new Text(table))) {
          println("'" + table + "' table not found.");
        } else {
          println("Dropping " + table + "... Please wait.");
          admin.deleteTable(new Text(table));
          count++;
        }
      }

      if (count > 0) {
View Full Code Here

      HConnection conn = HConnectionManager.getConnection(conf);
      if (conn.tableExists(tableName)) {
        return new ReturnMsg(0, "'" + tableName + "' table already exist.");
      }

      HBaseAdmin admin = new HBaseAdmin(conf);
      HTableDescriptor tableDesc = new HTableDescriptor(tableName.toString());
      HColumnDescriptor columnDesc = null;
      Set<String> columns = columnSpecMap.keySet();
      for (String column : columns) {
        columnDesc = getColumnDescriptor(column, columnSpecMap.get(column));
        tableDesc.addFamily(columnDesc);
      }

      println("Creating table... Please wait.");

      admin.createTable(tableDesc);
      return new ReturnMsg(0, "Table created successfully.");
    } catch (Exception e) {
      return new ReturnMsg(0, extractErrMsg(e));
    }
  }
View Full Code Here

      HConnection conn = HConnectionManager.getConnection(conf);
      if (!conn.tableExists(new Text(tableName))) {
        return new ReturnMsg(0, "'" + tableName + "'" + TABLE_NOT_FOUND);
      }

      HBaseAdmin admin = new HBaseAdmin(conf);
      admin.enableTable(new Text(tableName));
      return new ReturnMsg(1, "Table enabled successfully.");
    } catch (IOException e) {
      String[] msg = e.getMessage().split("[\n]");
      return new ReturnMsg(0, msg[0]);
    }
View Full Code Here

  public ReturnMsg execute(final HBaseConfiguration conf) {
    if (command == null) {
      return new ReturnMsg(0, "Syntax error : Please check 'Show' syntax.");
    }
    try {
      HBaseAdmin admin = new HBaseAdmin(conf);
      int tableLength = 0;
      HTableDescriptor[] tables = admin.listTables();
      tableLength = tables.length;
      if (tableLength == 0) {
        return new ReturnMsg(0, "No tables found.");
      }
      formatter.header(HEADER);
View Full Code Here

      if (!conn.tableExists(tableName) && !isMetaTable()) {
        return new ReturnMsg(0, "'" + tableName + "'" + TABLE_NOT_FOUND);
      }

      HTable table = new HTable(conf, tableName);
      HBaseAdmin admin = new HBaseAdmin(conf);
      int count = 0;
      if (whereClause) {
        if (countFunction) {
          count = 1;
        } else {
View Full Code Here

      HConnection conn = HConnectionManager.getConnection(conf);
      if (!conn.tableExists(new Text(this.tableName))) {
        return new ReturnMsg(0, "'" + this.tableName + "'" + TABLE_NOT_FOUND);
      }

      HBaseAdmin admin = new HBaseAdmin(conf);
      Set<String> columns = null;
      HColumnDescriptor columnDesc = null;
      switch (operationType) {
        case ADD:
          disableTable(admin, tableName);
          columns = columnSpecMap.keySet();
          for (String c : columns) {
            columnDesc = getColumnDescriptor(c, columnSpecMap.get(c));
            println("Adding " + c + " to " + tableName + "... Please wait.");
            admin.addColumn(new Text(tableName), columnDesc);
          }
          enableTable(admin, tableName);
          break;
        case DROP:
          disableTable(admin, tableName);
          println("Dropping " + column + " from " + tableName + "... Please wait.");
          column = appendDelimiter(column);
          admin.deleteColumn(new Text(tableName), new Text(column));
          enableTable(admin, tableName);
          break;
        case CHANGE:
          disableTable(admin, tableName);

          Map.Entry<String, Map<String, Object>> columnEntry = (Map.Entry<String, Map<String, Object>>) columnSpecMap
              .entrySet().toArray()[0];

          // add the : if there isn't one
          Text columnName = new Text(
              columnEntry.getKey().endsWith(":") ? columnEntry.getKey()
                  : columnEntry.getKey() + ":");

          // get the table descriptor so we can get the old column descriptor
          HTableDescriptor tDesc = getTableDescByName(admin, tableName);
          HColumnDescriptor oldColumnDesc = tDesc.families().get(columnName);

          // combine the options specified in the shell with the options
          // from the exiting descriptor to produce the new descriptor
          columnDesc = getColumnDescriptor(columnName.toString(), columnEntry
              .getValue(), oldColumnDesc);

          // send the changes out to the master
          admin.modifyColumn(new Text(tableName), columnName, columnDesc);

          enableTable(admin, tableName);
          break;
        case NOOP:
          return new ReturnMsg(0, "Invalid operation type.");
View Full Code Here

      HConnection conn = HConnectionManager.getConnection(conf);
      if (!conn.tableExists(new Text(tableName))) {
        return new ReturnMsg(0, "'" + tableName + "'" + TABLE_NOT_FOUND);
      }

      HBaseAdmin admin = new HBaseAdmin(conf);
      admin.disableTable(new Text(tableName));

      return new ReturnMsg(1, "Table disabled successfully.");
    } catch (IOException e) {
      String[] msg = e.getMessage().split("[\n]");
      return new ReturnMsg(0, msg[0]);
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.HBaseAdmin

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.