本文整理匯總了Java中org.apache.hadoop.hbase.client.Admin類的典型用法代碼示例。如果您正苦於以下問題:Java Admin類的具體用法?Java Admin怎麽用?Java Admin使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Admin類屬於org.apache.hadoop.hbase.client包,在下文中一共展示了Admin類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: runCoprocessorConnectionToRemoteTable
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
private void runCoprocessorConnectionToRemoteTable(Class<? extends BaseRegionObserver> clazz,
boolean[] completeCheck) throws Throwable {
HTableDescriptor primary = new HTableDescriptor(primaryTable);
primary.addFamily(new HColumnDescriptor(family));
// add our coprocessor
primary.addCoprocessor(clazz.getName());
HTableDescriptor other = new HTableDescriptor(otherTable);
other.addFamily(new HColumnDescriptor(family));
Admin admin = UTIL.getHBaseAdmin();
admin.createTable(primary);
admin.createTable(other);
Table table = new HTable(UTIL.getConfiguration(), TableName.valueOf("primary"));
Put p = new Put(new byte[] { 'a' });
p.add(family, null, new byte[] { 'a' });
table.put(p);
table.close();
Table target = new HTable(UTIL.getConfiguration(), otherTable);
assertTrue("Didn't complete update to target table!", completeCheck[0]);
assertEquals("Didn't find inserted row", 1, getKeyValueCount(target));
target.close();
}
示例2: createTable
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
/**
* 創建表
*
* @param tableName 表名稱
* @param columns 列族名稱
*/
public void createTable(String tableName, String... columns) {
HBaseConfiguration hBaseConfiguration = new HBaseConfiguration();
Admin admin = hBaseConfiguration.admin();
try {
TableName tn = TableName.valueOf(tableName);
if (admin.tableExists(tn)) {
log.info("表名【" + tableName + "】已存在");
return;
}
HTableDescriptor hTableDescriptor = new HTableDescriptor(tn);
for (String column : columns) {
HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(column);
hTableDescriptor.addFamily(hColumnDescriptor);
}
admin.createTable(hTableDescriptor);
} catch (IOException e) {
e.printStackTrace();
} finally {
hBaseConfiguration.close();
}
}
示例3: enableTable
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
/**
* 激活表
*
* @param tableName
*/
public void enableTable(String tableName) {
HBaseConfiguration hBaseConfiguration = new HBaseConfiguration();
Admin admin = hBaseConfiguration.admin();
TableName tn = TableName.valueOf(tableName);
try {
if (admin.tableExists(tn)) {
admin.enableTable(tn);
} else {
log.info("表名【" + tableName + "】不存在");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
hBaseConfiguration.close();
}
}
示例4: addColumn
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
/**
* 往表中添加列族
*
* @param tableName 表名
* @param familyName 列族名
*/
public void addColumn(String tableName, String familyName) {
HBaseConfiguration hBaseConfiguration = new HBaseConfiguration();
Admin admin = hBaseConfiguration.admin();
TableName tb = TableName.valueOf(tableName);
try {
if (admin.tableExists(tb)) {
HColumnDescriptor columnDescriptor = new HColumnDescriptor(familyName);
columnDescriptor.setMaxVersions(1);//設置列族保留的最多版本
columnDescriptor.setCompressionType(Compression.Algorithm.GZ);//設置壓縮算法
columnDescriptor.setCompactionCompressionType(Compression.Algorithm.GZ);//合並壓縮算法
admin.addColumn(tb, columnDescriptor);
} else {
log.info("表名【" + tableName + "】不存在");
}
} catch (IOException e) {
log.error(e);
} finally {
hBaseConfiguration.close();
}
}
示例5: testDeleteColumn
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
@Test
public void testDeleteColumn() throws IOException {
Admin admin = TEST_UTIL.getHBaseAdmin();
// Create a table with two families
HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
baseHtd.addFamily(new HColumnDescriptor(FAMILY_0));
baseHtd.addFamily(new HColumnDescriptor(FAMILY_1));
admin.createTable(baseHtd);
admin.disableTable(TABLE_NAME);
try {
// Verify the table descriptor
verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);
// Modify the table removing one family and verify the descriptor
admin.deleteColumn(TABLE_NAME, FAMILY_1);
verifyTableDescriptor(TABLE_NAME, FAMILY_0);
} finally {
admin.deleteTable(TABLE_NAME);
}
}
示例6: testLargeRegion
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
/**
* When size of region in megabytes is larger than largest possible integer there could be
* error caused by lost of precision.
* */
@Test
public void testLargeRegion() throws Exception {
RegionLocator regionLocator = mockRegionLocator("largeRegion");
Admin admin = mockAdmin(
mockServer(
mockRegion("largeRegion", Integer.MAX_VALUE)
)
);
RegionSizeCalculator calculator = new RegionSizeCalculator(regionLocator, admin);
assertEquals(((long) Integer.MAX_VALUE) * megabyte, calculator.getRegionSize("largeRegion".getBytes()));
}
示例7: sniff
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
private static List<Future<Void>> sniff(final Admin admin, final Sink sink,
HTableDescriptor tableDesc, ExecutorService executor, TaskType taskType) throws Exception {
Table table = null;
try {
table = admin.getConnection().getTable(tableDesc.getTableName());
} catch (TableNotFoundException e) {
return new ArrayList<Future<Void>>();
}
List<RegionTask> tasks = new ArrayList<RegionTask>();
try {
for (HRegionInfo region : admin.getTableRegions(tableDesc.getTableName())) {
tasks.add(new RegionTask(admin.getConnection(), region, sink, taskType));
}
} finally {
table.close();
}
return executor.invokeAll(tasks);
}
示例8: testCannotDeleteDefaultAndHbaseNamespaces
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
@Test
public void testCannotDeleteDefaultAndHbaseNamespaces() throws IOException {
String defaultPath = "/namespaces/default";
String hbasePath = "/namespaces/hbase";
Response response;
// Check that doesn't exist via non-REST call.
Admin admin = TEST_UTIL.getHBaseAdmin();
assertNotNull(findNamespace(admin, "default"));
assertNotNull(findNamespace(admin, "hbase"));
// Try (but fail) to delete namespaces via REST.
response = client.delete(defaultPath);
assertEquals(503, response.getCode());
response = client.delete(hbasePath);
assertEquals(503, response.getCode());
assertNotNull(findNamespace(admin, "default"));
assertNotNull(findNamespace(admin, "hbase"));
}
示例9: testClassLoadingFromLocalFS
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
@Test
// HBASE-3516: Test CP Class loading from local file system
public void testClassLoadingFromLocalFS() throws Exception {
File jarFile = buildCoprocessorJar(cpName3);
// create a table that references the jar
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(cpName3));
htd.addFamily(new HColumnDescriptor("test"));
htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName3 + "|" +
Coprocessor.PRIORITY_USER);
Admin admin = TEST_UTIL.getHBaseAdmin();
admin.createTable(htd);
waitForTable(htd.getTableName());
// verify that the coprocessor was loaded
boolean found = false;
MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
for (Region region: hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
if (region.getRegionInfo().getRegionNameAsString().startsWith(cpName3)) {
found = (region.getCoprocessorHost().findCoprocessor(cpName3) != null);
}
}
assertTrue("Class " + cpName3 + " was missing on a region", found);
}
示例10: doWork
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
@Override
protected int doWork() throws Exception {
Connection connection = null;
Admin admin = null;
try {
connection = ConnectionFactory.createConnection(getConf());
admin = connection.getAdmin();
HBaseProtos.SnapshotDescription.Type type = HBaseProtos.SnapshotDescription.Type.FLUSH;
if (snapshotType != null) {
type = HBaseProtos.SnapshotDescription.Type.valueOf(snapshotName.toUpperCase());
}
admin.snapshot(snapshotName, TableName.valueOf(tableName), type);
} catch (Exception e) {
return -1;
} finally {
if (admin != null) {
admin.close();
}
if (connection != null) {
connection.close();
}
}
return 0;
}
示例11: assertExistsMatchingSnapshot
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
/**
* Make sure that there is only one snapshot returned from the master and its
* name and table match the passed in parameters.
*/
public static List<SnapshotDescription> assertExistsMatchingSnapshot(
Admin admin, String snapshotName, TableName tableName)
throws IOException {
// list the snapshot
List<SnapshotDescription> snapshots = admin.listSnapshots();
List<SnapshotDescription> returnedSnapshots = new ArrayList<SnapshotDescription>();
for (SnapshotDescription sd : snapshots) {
if (snapshotName.equals(sd.getName()) &&
tableName.equals(TableName.valueOf(sd.getTable()))) {
returnedSnapshots.add(sd);
}
}
Assert.assertTrue("No matching snapshots found.", returnedSnapshots.size()>0);
return returnedSnapshots;
}
示例12: createTable
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
private void createTable(Admin admin, TableName tableName, boolean setVersion,
boolean acl) throws IOException {
if (!admin.tableExists(tableName)) {
HTableDescriptor htd = new HTableDescriptor(tableName);
HColumnDescriptor family = new HColumnDescriptor(FAMILY_NAME);
if (setVersion) {
family.setMaxVersions(DEFAULT_TABLES_COUNT);
}
htd.addFamily(family);
admin.createTable(htd);
if (acl) {
LOG.info("Granting permissions for user " + USER.getShortName());
Permission.Action[] actions = { Permission.Action.READ };
try {
AccessControlClient.grant(ConnectionFactory.createConnection(getConf()), tableName,
USER.getShortName(), null, null, actions);
} catch (Throwable e) {
LOG.fatal("Error in granting permission for the user " + USER.getShortName(), e);
throw new IOException(e);
}
}
}
}
示例13: waitUntilAssigned
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
public static void waitUntilAssigned(Admin admin,
HRegionInfo region) throws IOException, InterruptedException {
long timeout = admin.getConfiguration().getLong("hbase.hbck.assign.timeout", 120000);
long expiration = timeout + EnvironmentEdgeManager.currentTime();
while (EnvironmentEdgeManager.currentTime() < expiration) {
try {
Map<String, RegionState> rits=
admin.getClusterStatus().getRegionsInTransition();
if (rits.keySet() != null && !rits.keySet().contains(region.getEncodedName())) {
// yay! no longer RIT
return;
}
// still in rit
LOG.info("Region still in transition, waiting for "
+ "it to become assigned: " + region);
} catch (IOException e) {
LOG.warn("Exception when waiting for region to become assigned,"
+ " retrying", e);
}
Thread.sleep(1000);
}
throw new IOException("Region " + region + " failed to move out of " +
"transition within timeout " + timeout + "ms");
}
示例14: createTable
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
public static void createTable(HBaseTestingUtility testUtil, Admin 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());
}
示例15: deleteTable
import org.apache.hadoop.hbase.client.Admin; //導入依賴的package包/類
public static void deleteTable(HBaseTestingUtility testUtil, Admin 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 (TableNotEnabledException e) {
LOG.debug("Table: " + tableName + " already disabled, so just deleting it.");
}
admin.deleteTable(tableName);
observer.tableDeletionLatch.await();
observer.tableDeletionLatch = null;
}