Java Code Examples for org.apache.hadoop.hbase.client.HBaseAdmin#close()

The following examples show how to use org.apache.hadoop.hbase.client.HBaseAdmin#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HBaseFactoryTest.java    From bigdata-tutorial with Apache License 2.0 6 votes vote down vote up
public Boolean createTable(String tableName, String familyName) throws Exception {
	HBaseAdmin admin = new HBaseAdmin(conn);
	if (admin.tableExists(tableName)) {
		LOGGER.warn(">>>> Table {} exists!", tableName);
		admin.close();
		return false;
	}
	HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(tableName));
	tableDesc.addFamily(new HColumnDescriptor(familyName));
	admin.createTable(tableDesc);
	LOGGER.info(">>>> Table {} create success!", tableName);

	admin.close();
	return true;

}
 
Example 2
Source File: ReverseScanIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@BeforeClass
@Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class)
public static void doSetup() throws Exception {
    Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
    setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
    // Ensures our split points will be used
    // TODO: do deletePriorTables before test?
    Connection conn = DriverManager.getConnection(getUrl());
    HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
    try {
        admin.disableTable(TestUtil.ATABLE_NAME);
        admin.deleteTable(TestUtil.ATABLE_NAME);
    } catch (TableNotFoundException e) {
    } finally {
        admin.close();
        conn.close();
    }
 }
 
Example 3
Source File: BaseTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Disable and drop all the tables except SYSTEM.CATALOG and SYSTEM.SEQUENCE
 */
private static void disableAndDropNonSystemTables() throws Exception {
    HBaseAdmin admin = driver.getConnectionQueryServices(null, null).getAdmin();
    try {
        HTableDescriptor[] tables = admin.listTables();
        for (HTableDescriptor table : tables) {
            String schemaName = SchemaUtil.getSchemaNameFromFullName(table.getName());
            if (!QueryConstants.SYSTEM_SCHEMA_NAME.equals(schemaName)) {
                admin.disableTable(table.getName());
                admin.deleteTable(table.getName());
            }
        }
    } finally {
        admin.close();
    }
}
 
Example 4
Source File: NativeHBaseTypesIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void doBeforeTestSetup() throws Exception {
    HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).getAdmin();
    try {
        try {
            admin.disableTable(HBASE_NATIVE_BYTES);
            admin.deleteTable(HBASE_NATIVE_BYTES);
        } catch (org.apache.hadoop.hbase.TableNotFoundException e) {
        }
        @SuppressWarnings("deprecation")
        HTableDescriptor descriptor = new HTableDescriptor(HBASE_NATIVE_BYTES);
        HColumnDescriptor columnDescriptor =  new HColumnDescriptor(FAMILY_NAME);
        columnDescriptor.setKeepDeletedCells(true);
        descriptor.addFamily(columnDescriptor);
        admin.createTable(descriptor, SPLITS);
        initTableValues();
    } finally {
        admin.close();
    }
}
 
Example 5
Source File: HBaseFactoryTest.java    From bigdata-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * @param tableName
 * @return
 */
public boolean deleteTable(String tableName) throws IOException {

	HBaseAdmin admin = new HBaseAdmin(conn);
	if (admin.tableExists(tableName)) {
		try {
			admin.disableTable(tableName);
			admin.deleteTable(tableName);
			LOGGER.info(">>>> Table {} delete success!", tableName);
		} catch (Exception ex) {
			LOGGER.error("delete table error:", ex);
			return false;
		}
	} else {
		LOGGER.warn(">>>> Table {} delete but not exist.", tableName);
	}
	admin.close();
	return true;
}
 
Example 6
Source File: HBaseDDLHandler.java    From bigdata-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * @param tableName
 * @return
 */
public boolean deleteTable(String tableName) throws IOException {

	HBaseAdmin admin = new HBaseAdmin(getConnPool().getConn());
	if (admin.tableExists(tableName)) {
		try {
			if (admin.isTableEnabled(tableName)) {
				admin.disableTable(tableName);
			}
			admin.deleteTable(tableName);
			LOGGER.info(">>>> Table {} delete success!", tableName);
		} catch (Exception ex) {
			LOGGER.error("delete table error:", ex);
			return false;
		}
	} else {
		LOGGER.warn(">>>> Table {} delete but not exist.", tableName);
	}
	admin.close();
	return true;
}
 
Example 7
Source File: ProductMetricsTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test to repro ArrayIndexOutOfBoundException that happens during filtering in BinarySubsetComparator
 * only after a flush is performed
 * @throws Exception
 */
@Test
public void testFilterOnTrailingKeyColumn() throws Exception {
	long ts = nextTimestamp();
    String tenantId = getOrganizationId();
    Properties props = new Properties(TEST_PROPERTIES);
    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts+1));
    Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);

    HBaseAdmin admin = null;
    try {
        initTableValues(tenantId, getSplits(tenantId), ts);
        admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
        admin.flush(SchemaUtil.getTableNameAsBytes(PRODUCT_METRICS_SCHEMA_NAME,PRODUCT_METRICS_NAME));
        String query = "SELECT SUM(TRANSACTIONS) FROM " + PRODUCT_METRICS_NAME + " WHERE FEATURE=?";
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, F1);
        ResultSet rs = statement.executeQuery();
        assertTrue(rs.next());
        assertEquals(1200, rs.getInt(1));
    } finally {
        if (admin != null) admin.close();
        conn.close();
    }	
}
 
Example 8
Source File: HBaseWindowStore.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
public void connect() throws IOException
{
  super.connect();
  HTableDescriptor tdesc = table.getTableDescriptor();
  if (!tdesc.hasFamily(columnFamilyBytes)) {
    HBaseAdmin admin = new HBaseAdmin(table.getConfiguration());
    admin.disableTable(table.getTableName());
    try {
      HColumnDescriptor cdesc = new HColumnDescriptor(columnFamilyBytes);
      admin.addColumn(table.getTableName(), cdesc);
    } finally {
      admin.enableTable(table.getTableName());
      admin.close();
    }
  }
}
 
Example 9
Source File: NativeHBaseTypesTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@BeforeClass
public static void doBeforeTestSetup() throws Exception {
    HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TEST_PROPERTIES).getAdmin();
    try {
        try {
            admin.disableTable(HBASE_NATIVE_BYTES);
            admin.deleteTable(HBASE_NATIVE_BYTES);
        } catch (org.apache.hadoop.hbase.TableNotFoundException e) {
        }
        HTableDescriptor descriptor = new HTableDescriptor(HBASE_NATIVE_BYTES);
        HColumnDescriptor columnDescriptor =  new HColumnDescriptor(FAMILY_NAME);
        columnDescriptor.setKeepDeletedCells(true);
        descriptor.addFamily(columnDescriptor);
        admin.createTable(descriptor, SPLITS);
        initTableValues();
    } finally {
        admin.close();
    }
}
 
Example 10
Source File: HBaseUtils.java    From bigdata-tutorial with Apache License 2.0 5 votes vote down vote up
public static void close(HBaseAdmin admin) {
	try {
		if (null != admin) {
			admin.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 11
Source File: RemoveTables.java    From hadoop-arch-book with Apache License 2.0 5 votes vote down vote up
public static void executeDeleteTables(Configuration config) throws IOException {
  HBaseAdmin admin = new HBaseAdmin(config);

  if (admin.tableExists(HBaseTableMetaModel.profileCacheTableName)) {
    admin.disableTable(HBaseTableMetaModel.profileCacheTableName);
    admin.deleteTable(HBaseTableMetaModel.profileCacheTableName);
  }

  if (admin.tableExists(HBaseTableMetaModel.validationRulesTableName)) {
    admin.disableTable(HBaseTableMetaModel.validationRulesTableName);
    admin.deleteTable(HBaseTableMetaModel.validationRulesTableName);
  }

  admin.close();
}
 
Example 12
Source File: StatsCollectorIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void compactTable(Connection conn, String tableName) throws IOException, InterruptedException, SQLException {
    ConnectionQueryServices services = conn.unwrap(PhoenixConnection.class).getQueryServices();
    HBaseAdmin admin = services.getAdmin();
    try {
        admin.flush(tableName);
        admin.majorCompact(tableName);
        Thread.sleep(10000); // FIXME: how do we know when compaction is done?
    } finally {
        admin.close();
    }
}
 
Example 13
Source File: RegionSizeCalculator.java    From tajo with Apache License 2.0 5 votes vote down vote up
/**
 * Computes size of each region for table and given column families.
 *
 * @deprecated Use {@link #RegionSizeCalculator(RegionLocator, Admin)} instead.
 */
@Deprecated
public RegionSizeCalculator(HTable table) throws IOException {
  HBaseAdmin admin = new HBaseAdmin(table.getConfiguration());
  try {
    init(table, admin);
  } finally {
    admin.close();
  }
}
 
Example 14
Source File: CoprocessorToolITSuite.java    From eagle with Apache License 2.0 5 votes vote down vote up
private void ensureTable() throws IOException {
    LOGGER.info("Creating table {}", toolITTableName);
    HBaseAdmin admin = new HBaseAdmin(new Configuration());
    HTableDescriptor hTableDescriptor = new HTableDescriptor(TableName.valueOf(toolITTableName));
    hTableDescriptor.addFamily(new HColumnDescriptor("f"));
    admin.createTable(hTableDescriptor);
    admin.close();
    LOGGER.info("Created table {}", toolITTableName);
}
 
Example 15
Source File: SkipScanAfterManualSplitIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static void initTable() throws Exception {
    Connection conn = DriverManager.getConnection(getUrl());
    conn.createStatement().execute("CREATE TABLE " + TABLE_NAME + "("
            + "a VARCHAR PRIMARY KEY, b VARCHAR) " 
            + HTableDescriptor.MAX_FILESIZE + "=" + MAX_FILESIZE + ","
            + " SALT_BUCKETS = 4");
    PreparedStatement stmt = conn.prepareStatement("UPSERT INTO s VALUES(?,?)");
    int rowCount = 0;
    for (int c1 = MIN_CHAR; c1 <= MAX_CHAR; c1++) {
        for (int c2 = MIN_CHAR; c2 <= MAX_CHAR; c2++) {
            String pk = Character.toString((char)c1) + Character.toString((char)c2);
            stmt.setString(1, pk);
            stmt.setString(2, PAYLOAD);
            stmt.execute();
            rowCount++;
            if (rowCount % BATCH_SIZE == 0) {
                conn.commit();
            }
        }
    }
    conn.commit();
    ConnectionQueryServices services = conn.unwrap(PhoenixConnection.class).getQueryServices();
    HBaseAdmin admin = services.getAdmin();
    try {
        admin.flush(TABLE_NAME);
    } finally {
        admin.close();
    }
    conn.close();
}
 
Example 16
Source File: Create3.java    From examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
  Configuration conf = HBaseConfiguration.create();
  HBaseAdmin admin = new HBaseAdmin(conf);
  // tag::CREATE3[]
  HTableDescriptor desc = new HTableDescriptor(TableName.valueOf("crc"));
  desc.setMaxFileSize((long)20*1024*1024*1024);
  desc.setConfiguration("hbase.hstore.compaction.min", "5");
  HColumnDescriptor family = new HColumnDescriptor("c");
  family.setInMemory(true);
  desc.addFamily(family);
  UniformSplit uniformSplit = new UniformSplit();
  admin.createTable(desc, uniformSplit.split(64));
  // end::CREATE3[]
  admin.close();
}
 
Example 17
Source File: ProductMetricsTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void destroyTable() throws Exception {
    // Physically delete HBase table so that splits occur as expected for each test
    Properties props = new Properties(TEST_PROPERTIES);
    ConnectionQueryServices services = DriverManager.getConnection(getUrl(), props).unwrap(PhoenixConnection.class).getQueryServices();
    HBaseAdmin admin = services.getAdmin();
    try {
        try {
            admin.disableTable(PRODUCT_METRICS_NAME);
            admin.deleteTable(PRODUCT_METRICS_NAME);
        } catch (TableNotFoundException e) {
        }
   } finally {
            admin.close();
    }
}
 
Example 18
Source File: Create1.java    From examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
  throws MasterNotRunningException, ZooKeeperConnectionException,
         IOException {
  // tag::CREATE1[]
  Configuration conf = HBaseConfiguration.create();
  HBaseAdmin admin = new HBaseAdmin(conf);
  HTableDescriptor desc = 
    new HTableDescriptor(TableName.valueOf("testtable_create1"));
  HColumnDescriptor family = new HColumnDescriptor("f1");
  desc.addFamily(family);
  admin.createTable(desc);
  // end::CREATE1[]
  admin.close();
}
 
Example 19
Source File: CreateTable.java    From HBase-ToHDFS with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception{
  
  if (args.length == 0) {
    System.out.println("CreateTables {tableName} {columnFamilyName} {RegionCount}");
    return;
  }
  
  String tableName = args[0];
  String columnFamilyName = args[1];
  String regionCount = args[2];
  
  long regionMaxSize = 107374182400l;
  
  Configuration config = HBaseConfiguration.addHbaseResources(new Configuration());
  
  HBaseAdmin admin = new HBaseAdmin(config);
  
  createTable(tableName, columnFamilyName, Short.parseShort(regionCount), regionMaxSize, admin);
  
  admin.close();
  System.out.println("Done");
}
 
Example 20
Source File: CreateTables.java    From hadoop-arch-book with Apache License 2.0 3 votes vote down vote up
public static void executeCreateTables(Configuration config) throws IOException {
  HBaseAdmin admin = new HBaseAdmin(config);

  createProfileCacheTable(admin);

  createValidationRuleTable(admin);

  admin.close();
}