本文整理匯總了Java中org.apache.hadoop.hbase.client.HBaseAdmin類的典型用法代碼示例。如果您正苦於以下問題:Java HBaseAdmin類的具體用法?Java HBaseAdmin怎麽用?Java HBaseAdmin使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HBaseAdmin類屬於org.apache.hadoop.hbase.client包,在下文中一共展示了HBaseAdmin類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getHealth
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
@Override
public HealthCheck.Result getHealth() {
try {
HBaseAdmin.checkHBaseAvailable(configuration);
return HealthCheck.Result.builder()
.healthy()
.withMessage("HBase running on:")
.withDetail("quorum", quorum)
.withDetail("clientPort", clientPort)
.withDetail("znodeParent", znodeParent)
.build();
} catch (Exception e) {
return HealthCheck.Result.builder()
.unhealthy(e)
.build();
}
}
示例2: creatTable
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
/**
* Create a hbaseBtable in case the table is not there Else prints table already exist conf is the
* configuration file object which needs to be passed, hbase-site.xml
* @method creatTable
* @inputParameters: tablename as String, ColumnFamalies as String Array[]
* @return NA as is a voild method
**/
public static void creatTable(String myHbaseBtableName, String[] cfamlies) throws Exception {
HBaseAdmin hbaseBadmin = new HBaseAdmin(hbaseBconf);
if (hbaseBadmin.tableExists(myHbaseBtableName)) {
System.out.println("Ohh.. this table is already there");
} else {
@SuppressWarnings("deprecation")
HTableDescriptor hbaseBtableDesc = new HTableDescriptor(myHbaseBtableName);
for (int i = 0; i < cfamlies.length; i++) {
hbaseBtableDesc.addFamily(new HColumnDescriptor(cfamlies[i]));
}
hbaseBadmin.createTable(hbaseBtableDesc);// creating a table
System.out.println("create table " + myHbaseBtableName + " Done.");
// Table is created and printed with the name.
}
}
示例3: open
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
/**
* 連接HBase
*/
public static void open() {
try {
config = HBaseConfiguration.create();
conn = HConnectionManager.createConnection(config);
admin = new HBaseAdmin(conn);
hbase_table = conn.getTable(ISAXIndex.TABLE_NAME);
} catch (IOException e) {
e.printStackTrace();
}
}
示例4: testDisableTableAndRestart
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
@Test(timeout = 300000)
public void testDisableTableAndRestart() throws Exception {
final TableName tableName = TableName.valueOf("testDisableTableAndRestart");
final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
final HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
final HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor(FAMILYNAME));
admin.createTable(desc);
admin.disableTable(tableName);
TEST_UTIL.waitTableDisabled(tableName.getName());
TEST_UTIL.getHBaseCluster().shutdown();
TEST_UTIL.getHBaseCluster().waitUntilShutDown();
TEST_UTIL.restartHBaseCluster(2);
admin.enableTable(tableName);
TEST_UTIL.waitTableEnabled(tableName);
}
示例5: createTable
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
public static void createTable(HBaseTestingUtility testUtil, HBaseAdmin admin,
HTableDescriptor htd, byte [][] splitKeys)
throws Exception {
// NOTE: We need a latch because admin is not sync,
// so the postOp coprocessor method may be called after the admin operation returned.
MasterSyncObserver observer = (MasterSyncObserver)testUtil.getHBaseCluster().getMaster()
.getMasterCoprocessorHost().findCoprocessor(MasterSyncObserver.class.getName());
observer.tableCreationLatch = new CountDownLatch(1);
if (splitKeys != null) {
admin.createTable(htd, splitKeys);
} else {
admin.createTable(htd);
}
observer.tableCreationLatch.await();
observer.tableCreationLatch = null;
testUtil.waitUntilAllRegionsAssigned(htd.getTableName());
}
示例6: deleteTable
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
public static void deleteTable(HBaseTestingUtility testUtil, HBaseAdmin admin,
TableName tableName)
throws Exception {
// NOTE: We need a latch because admin is not sync,
// so the postOp coprocessor method may be called after the admin operation returned.
MasterSyncObserver observer = (MasterSyncObserver)testUtil.getHBaseCluster().getMaster()
.getMasterCoprocessorHost().findCoprocessor(MasterSyncObserver.class.getName());
observer.tableDeletionLatch = new CountDownLatch(1);
try {
admin.disableTable(tableName);
} catch (Exception e) {
LOG.debug("Table: " + tableName + " already disabled, so just deleting it.");
}
admin.deleteTable(tableName);
observer.tableDeletionLatch.await();
observer.tableDeletionLatch = null;
}
示例7: prepareForLoadTest
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
protected void prepareForLoadTest() throws IOException {
LOG.info("Starting load test: dataBlockEncoding=" + dataBlockEncoding +
", isMultiPut=" + isMultiPut);
numKeys = numKeys();
Admin admin = new HBaseAdmin(conf);
while (admin.getClusterStatus().getServers().size() < NUM_RS) {
LOG.info("Sleeping until " + NUM_RS + " RSs are online");
Threads.sleepWithoutInterrupt(1000);
}
admin.close();
HTableDescriptor htd = new HTableDescriptor(TABLE);
HColumnDescriptor hcd = new HColumnDescriptor(CF)
.setCompressionType(compression)
.setDataBlockEncoding(dataBlockEncoding);
createPreSplitLoadTestTable(htd, hcd);
LoadTestDataGenerator dataGen = new MultiThreadedAction.DefaultDataGenerator(CF);
writerThreads = prepareWriterThreads(dataGen, conf, TABLE);
readerThreads = prepareReaderThreads(dataGen, conf, TABLE, 100);
}
示例8: getDeployedHRIs
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
/**
* Get region info from local cluster.
*/
Map<ServerName, List<String>> getDeployedHRIs(final HBaseAdmin admin) throws IOException {
ClusterStatus status = admin.getClusterStatus();
Collection<ServerName> regionServers = status.getServers();
Map<ServerName, List<String>> mm =
new HashMap<ServerName, List<String>>();
for (ServerName hsi : regionServers) {
AdminProtos.AdminService.BlockingInterface server = ((HConnection) connection).getAdmin(hsi);
// list all online regions from this region server
List<HRegionInfo> regions = ProtobufUtil.getOnlineRegions(server);
List<String> regionNames = new ArrayList<String>();
for (HRegionInfo hri : regions) {
regionNames.add(hri.getRegionNameAsString());
}
mm.put(hsi, regionNames);
}
return mm;
}
示例9: prepareData
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
private Store prepareData() throws IOException {
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
if (admin.tableExists(tableName)) {
admin.disableTable(tableName);
admin.deleteTable(tableName);
}
HTable table = TEST_UTIL.createTable(tableName, family);
Random rand = new Random();
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
byte[] value = new byte[128 * 1024];
rand.nextBytes(value);
table.put(new Put(Bytes.toBytes(i * 10 + j)).add(family, qualifier, value));
}
admin.flush(tableName);
}
return getStoreWithName(tableName);
}
示例10: compactAndWait
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
private void compactAndWait() throws IOException, InterruptedException {
LOG.debug("Compacting table " + tableName);
HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0);
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
admin.majorCompact(tableName);
// Waiting for the compaction to start, at least .5s.
final long maxWaitime = System.currentTimeMillis() + 500;
boolean cont;
do {
cont = rs.compactSplitThread.getCompactionQueueSize() == 0;
Threads.sleep(1);
} while (cont && System.currentTimeMillis() < maxWaitime);
while (rs.compactSplitThread.getCompactionQueueSize() > 0) {
Threads.sleep(1);
}
LOG.debug("Compaction queue size reached 0, continuing");
}
示例11: runTestFromCommandLine
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
@Override
public int runTestFromCommandLine() throws Exception {
IntegrationTestingUtility.setUseDistributedCluster(getConf());
int numPresplits = getConf().getInt("loadmapper.numPresplits", 5);
// create HTableDescriptor for specified table
HTableDescriptor htd = new HTableDescriptor(getTablename());
htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
Admin admin = new HBaseAdmin(getConf());
try {
admin.createTable(htd, Bytes.toBytes(0L), Bytes.toBytes(-1L), numPresplits);
} finally {
admin.close();
}
doLoad(getConf(), htd);
doVerify(getConf(), htd);
getTestingUtil(getConf()).deleteTable(htd.getName());
return 0;
}
示例12: create
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
public static void create() throws Exception {
HBaseAdmin admin = new HBaseAdmin(cfg);
if (admin.tableExists(tableName)) {
System.out.println("[info]table has created!");
} else {
try {
TableName table = TableName.valueOf(tableName);
HTableDescriptor tableDescriptor = new HTableDescriptor(table);
tableDescriptor.addFamily(new HColumnDescriptor(familyName));
admin.createTable(tableDescriptor);
} catch (TableExistsException e) {
System.out.println("[warning] table exists!");
}
}
System.out.println("[info]create table success!");
}
示例13: create
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
public static void create() throws Exception
{
HBaseAdmin admin = new HBaseAdmin(cfg);
if (admin.tableExists(tableName)) {
System.out.println("[info]table has created!");
} else {
TableName table = TableName.valueOf(tableName);
HTableDescriptor tableDescriptor = new HTableDescriptor(table);
tableDescriptor.addFamily(new HColumnDescriptor(familyName));
try{
admin.createTable(tableDescriptor);
}catch(TableExistsException e)
{
System.out.println("[warning] table exists!");
}
}
System.out.println("[info]create table success!");
}
示例14: delete
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
public static boolean delete(String tablename) throws IOException{
HBaseAdmin admin=new HBaseAdmin(cfg);
if(admin.tableExists(tablename)){
try
{
admin.disableTable(tablename);
admin.deleteTable(tablename);
}catch(Exception ex){
ex.printStackTrace();
return false;
}
}
return true;
}
示例15: setUp
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入依賴的package包/類
@BeforeMethod
public void setUp() throws Exception {
HBaseAdmin admin = testutil.getHBaseAdmin();
if (!admin.tableExists(DEFAULT_TIMESTAMP_STORAGE_TABLE_NAME)) {
HTableDescriptor desc = new HTableDescriptor(TABLE_NAME);
HColumnDescriptor datafam = new HColumnDescriptor(DEFAULT_TIMESTAMP_STORAGE_CF_NAME);
datafam.setMaxVersions(Integer.MAX_VALUE);
desc.addFamily(datafam);
admin.createTable(desc);
}
if (admin.isTableDisabled(DEFAULT_TIMESTAMP_STORAGE_TABLE_NAME)) {
admin.enableTable(DEFAULT_TIMESTAMP_STORAGE_TABLE_NAME);
}
HTableDescriptor[] tables = admin.listTables();
for (HTableDescriptor t : tables) {
LOG.info(t.getNameAsString());
}
}