Package org.apache.hadoop.hbase.client

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


    return getHTableDescriptors(tableNames);
  }

  HTableDescriptor[] getHTableDescriptors(List<TableName> tableNames) {
    HTableDescriptor[] htd = new HTableDescriptor[0];
    Admin admin = null;
    try {
      LOG.info("getHTableDescriptors == tableNames => " + tableNames);
      admin = new HBaseAdmin(getConf());
      htd = admin.getTableDescriptorsByTableName(tableNames);
    } catch (IOException e) {
      LOG.debug("Exception getting table descriptors", e);
    } finally {
      if (admin != null) {
        try {
          admin.close();
        } catch (IOException e) {
          LOG.debug("Exception closing HBaseAdmin", e);
        }
      }
    }
View Full Code Here


    util.shutdownMiniCluster();
  }

  @Test
  public void testSimpleProcedureManager() throws IOException {
    Admin admin = util.getHBaseAdmin();

    byte[] result = admin.execProcedureWithRet(SimpleMasterProcedureManager.SIMPLE_SIGNATURE,
        "mytest", new HashMap<String, String>());
    assertArrayEquals("Incorrect return data from execProcedure",
      SimpleMasterProcedureManager.SIMPLE_DATA.getBytes(), result);
  }
View Full Code Here

    HTableDescriptor table = new HTableDescriptor(TableName.valueOf(TABLE_NAME));
    HColumnDescriptor fam = new HColumnDescriptor(FAMILY);
    fam.setMaxVersions(3);
    fam.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
    table.addFamily(fam);
    Admin admin = null;
    try {
      admin = new HBaseAdmin(conf1);
      admin.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
    } finally {
      if (admin != null) {
        admin.close();
      }
    }
    try {
      admin = new HBaseAdmin(conf2);
      admin.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
    } finally {
      if(admin != null){
        admin.close();
      }
    }
    htable1 = new HTable(conf1, TABLE_NAME);
    htable1.setWriteBufferSize(1024);
    htable2 = new HTable(conf2, TABLE_NAME);
View Full Code Here

    final TableName name =
        TableName.valueOf("testTableExists");
    assertFalse(MetaTableAccessor.tableExists(hConnection, name));
    UTIL.createTable(name, HConstants.CATALOG_FAMILY);
    assertTrue(MetaTableAccessor.tableExists(hConnection, name));
    Admin admin = UTIL.getHBaseAdmin();
    admin.disableTable(name);
    admin.deleteTable(name);
    assertFalse(MetaTableAccessor.tableExists(hConnection, name));
    assertTrue(MetaTableAccessor.tableExists(hConnection,
      TableName.META_TABLE_NAME));
  }
View Full Code Here

    TEST_UTIL.shutdownMiniCluster();
  }

  @Test
  public void testCreateTableWithDefault() throws IOException {
    Admin admin = TEST_UTIL.getHBaseAdmin();
    // Create a table with one family
    HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
    HColumnDescriptor hcd = new HColumnDescriptor(FAMILY);
    baseHtd.addFamily(hcd);
    admin.createTable(baseHtd);
    admin.disableTable(TABLE_NAME);
    try {
      // Verify the column descriptor
      verifyHColumnDescriptor(1, TABLE_NAME, FAMILY);
    } finally {
      admin.deleteTable(TABLE_NAME);
    }
  }
View Full Code Here

  public void testCreateTableWithDefaultFromConf() throws Exception {
    TEST_UTIL.shutdownMiniCluster();
    TEST_UTIL.getConfiguration().setInt("hbase.column.max.version", 3);
    TEST_UTIL.startMiniCluster(1);

    Admin admin = TEST_UTIL.getHBaseAdmin();
    // Create a table with one family
    HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
    HColumnDescriptor hcd = new HColumnDescriptor(FAMILY);
    hcd.setMaxVersions(TEST_UTIL.getConfiguration().getInt("hbase.column.max.version", 1));
    baseHtd.addFamily(hcd);
    admin.createTable(baseHtd);
    admin.disableTable(TABLE_NAME);
    try {
      // Verify the column descriptor
      verifyHColumnDescriptor(3, TABLE_NAME, FAMILY);
    } finally {
      admin.deleteTable(TABLE_NAME);
    }
  }
View Full Code Here

  public void testCreateTableWithSetVersion() throws Exception {
    TEST_UTIL.shutdownMiniCluster();
    TEST_UTIL.getConfiguration().setInt("hbase.column.max.version", 3);
    TEST_UTIL.startMiniCluster(1);

    Admin admin = TEST_UTIL.getHBaseAdmin();
    // Create a table with one family
    HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
    HColumnDescriptor hcd =
        new HColumnDescriptor(FAMILY, 5, HColumnDescriptor.DEFAULT_COMPRESSION,
            HColumnDescriptor.DEFAULT_IN_MEMORY, HColumnDescriptor.DEFAULT_BLOCKCACHE,
            HColumnDescriptor.DEFAULT_TTL, HColumnDescriptor.DEFAULT_BLOOMFILTER);
    baseHtd.addFamily(hcd);
    admin.createTable(baseHtd);
    admin.disableTable(TABLE_NAME);
    try {
      // Verify the column descriptor
      verifyHColumnDescriptor(5, TABLE_NAME, FAMILY);

    } finally {
      admin.deleteTable(TABLE_NAME);
    }
  }
View Full Code Here

    }
  }

  private void verifyHColumnDescriptor(int expected, final TableName tableName,
      final byte[]... families) throws IOException {
    Admin admin = TEST_UTIL.getHBaseAdmin();

    // Verify descriptor from master
    HTableDescriptor htd = admin.getTableDescriptor(tableName);
    HColumnDescriptor[] hcds = htd.getColumnFamilies();
    verifyHColumnDescriptor(expected, hcds, tableName, families);

    // Verify descriptor from HDFS
    MasterFileSystem mfs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem();
View Full Code Here

    } else {
      if(!masterIsRunning) {
        throw new IllegalStateException(
            "HBase instance must be running to merge a normal table");
      }
      Admin admin = new HBaseAdmin(conf);
      try {
        if (!admin.isTableDisabled(tableName)) {
          throw new TableNotDisabledException(tableName);
        }
      } finally {
        admin.close();
      }
      new OnlineMerger(conf, fs, tableName).process();
    }
  }
View Full Code Here

   */
  public static List<UserPermission> getUserPermissions(Configuration conf, String tableRegex)
      throws Throwable {
    List<UserPermission> permList = new ArrayList<UserPermission>();
    Table ht = null;
    Admin ha = null;
    try {
      TableName aclTableName =
          TableName.valueOf(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR, "acl");
      ha = new HBaseAdmin(conf);
      ht = new HTable(conf, aclTableName.getName());
      CoprocessorRpcChannel service = ht.coprocessorService(HConstants.EMPTY_START_ROW);
      BlockingInterface protocol =
          AccessControlProtos.AccessControlService.newBlockingStub(service);
      HTableDescriptor[] htds = null;
     
      if (tableRegex != null) {
        htds = ha.listTables(Pattern.compile(tableRegex));
        for (HTableDescriptor hd: htds) {
          permList.addAll(ProtobufUtil.getUserPermissions(protocol, hd.getTableName()));
        }
      } else {
        permList = ProtobufUtil.getUserPermissions(protocol);
      }
    } finally {
      if (ht != null) {
        ht.close();
      }
      if (ha != null) {
        ha.close();
      }
    }
    return permList;
  }
View Full Code Here

TOP

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

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.