本文整理了Java中org.apache.hadoop.hbase.client.Connection.getAdmin()
方法的一些代码示例,展示了Connection.getAdmin()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Connection.getAdmin()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Connection
类名称:Connection
方法名:getAdmin
[英]Retrieve an Admin implementation to administer an HBase cluster. The returned Admin is not guaranteed to be thread-safe. A new instance should be created for each using thread. This is a lightweight operation. Pooling or caching of the returned Admin is not recommended.
The caller is responsible for calling Admin#close() on the returned Admin instance.
[中]检索管理实现以管理HBase群集。返回的管理员不保证是线程安全的。应该为每个使用线程创建一个新实例。这是一个轻量级操作。不建议对返回的管理员进行池或缓存。
调用方负责对返回的Admin实例调用Admin#close()。
代码示例来源:origin: apache/hbase
/**
* Constructor that creates a connection to the local ZooKeeper ensemble.
* @param conf Configuration to use
* @throws IOException if an internal replication error occurs
* @throws RuntimeException if replication isn't enabled.
*/
public ReplicationAdmin(Configuration conf) throws IOException {
this.connection = ConnectionFactory.createConnection(conf);
admin = connection.getAdmin();
}
代码示例来源:origin: alibaba/canal
public boolean tableExists(String tableName) {
try (HBaseAdmin admin = (HBaseAdmin) getConnection().getAdmin()) {
return admin.tableExists(TableName.valueOf(tableName));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: apache/hbase
private static void deleteTable(Configuration conf, String[] args) {
TableName tableName = TableName.valueOf(args[0]);
try (Connection connection = ConnectionFactory.createConnection(conf);
Admin admin = connection.getAdmin()) {
try {
admin.disableTable(tableName);
} catch (TableNotEnabledException e) {
LOG.debug("Dry mode: Table: " + tableName + " already disabled, so just deleting it.");
}
admin.deleteTable(tableName);
} catch (IOException e) {
LOG.error(format("***Dry run: Failed to delete table '%s'.***%n%s", tableName,
e.toString()));
return;
}
LOG.info(format("Dry run: Deleted table '%s'.", tableName));
}
代码示例来源:origin: apache/hbase
private RegionMover(RegionMoverBuilder builder) throws IOException {
this.hostname = builder.hostname;
this.filename = builder.filename;
this.excludeFile = builder.excludeFile;
this.maxthreads = builder.maxthreads;
this.ack = builder.ack;
this.port = builder.port;
this.timeout = builder.timeout;
setConf(builder.conf);
this.conn = ConnectionFactory.createConnection(conf);
this.admin = conn.getAdmin();
}
代码示例来源:origin: apache/hbase
/**
* Test things basically work.
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Configuration conf = HBaseConfiguration.create();
LocalHBaseCluster cluster = new LocalHBaseCluster(conf);
cluster.startup();
Connection connection = ConnectionFactory.createConnection(conf);
Admin admin = connection.getAdmin();
try {
HTableDescriptor htd =
new HTableDescriptor(TableName.valueOf(cluster.getClass().getName()));
admin.createTable(htd);
} finally {
admin.close();
}
connection.close();
cluster.shutdown();
}
}
代码示例来源:origin: alibaba/canal
public void createTable(String tableName, String... familyNames) {
try (HBaseAdmin admin = (HBaseAdmin) getConnection().getAdmin()) {
HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));
// 添加列簇
if (familyNames != null) {
for (String familyName : familyNames) {
HColumnDescriptor hcd = new HColumnDescriptor(familyName);
desc.addFamily(hcd);
}
}
admin.createTable(desc);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: apache/hbase
public static boolean isSecurityAvailable(Configuration conf) throws IOException {
try (Connection conn = ConnectionFactory.createConnection(conf)) {
try (Admin admin = conn.getAdmin()) {
return admin.tableExists(AccessControlLists.ACL_TABLE_NAME);
}
}
}
代码示例来源:origin: apache/hbase
@Before
public void setUp() throws Exception {
utility = new HBaseTestingUtility(conf);
utility.startMiniCluster(2);
conn = ConnectionFactory.createConnection(utility.getConfiguration());
admin = conn.getAdmin();
String methodName = testName.getMethodName();
tableName = TableName.valueOf(methodName.substring(0, methodName.length() - 3));
}
代码示例来源:origin: apache/kylin
public static boolean tableExists(Connection conn, String tableName) throws IOException {
Admin hbase = conn.getAdmin();
try {
return hbase.tableExists(TableName.valueOf(tableName));
} finally {
hbase.close();
}
}
代码示例来源:origin: apache/kylin
public UpdateHTableHostCLI(List<String> htables, String oldHostValue) throws IOException {
this.htables = htables;
this.oldHostValue = oldHostValue;
try (Connection conn = ConnectionFactory.createConnection(HBaseConfiguration.create());) {
hbaseAdmin = conn.getAdmin();
this.kylinConfig = KylinConfig.getInstanceFromEnv();
}
}
代码示例来源:origin: apache/hbase
public void manualTest(String args[]) throws Exception {
Configuration conf = HBaseConfiguration.create();
util = new HBaseTestingUtility(conf);
if ("newtable".equals(args[0])) {
TableName tname = TableName.valueOf(args[1]);
byte[][] splitKeys = generateRandomSplitKeys(4);
Table table = util.createTable(tname, FAMILIES, splitKeys);
} else if ("incremental".equals(args[0])) {
TableName tname = TableName.valueOf(args[1]);
try(Connection c = ConnectionFactory.createConnection(conf);
Admin admin = c.getAdmin();
RegionLocator regionLocator = c.getRegionLocator(tname)) {
Path outDir = new Path("incremental-out");
runIncrementalPELoad(conf, Arrays.asList(new HFileOutputFormat2.TableInfo(admin
.getTableDescriptor(tname), regionLocator)), outDir, false);
}
} else {
throw new RuntimeException(
"usage: TestHFileOutputFormat2 newtable | incremental");
}
}
代码示例来源:origin: apache/hbase
@Override
public void addToBackupSet(String name, TableName[] tables) throws IOException {
String[] tableNames = new String[tables.length];
try (final BackupSystemTable table = new BackupSystemTable(conn);
final Admin admin = conn.getAdmin()) {
for (int i = 0; i < tables.length; i++) {
tableNames[i] = tables[i].getNameAsString();
if (!admin.tableExists(TableName.valueOf(tableNames[i]))) {
throw new IOException("Cannot add " + tableNames[i] + " because it doesn't exist");
}
}
table.addToBackupSet(name, tableNames);
LOG.info("Added tables [" + StringUtils.join(tableNames, " ") + "] to '" + name
+ "' backup set");
}
}
代码示例来源:origin: apache/hbase
TableDescriptor[] getTableDescriptors(List<TableName> tableNames) {
LOG.info("getTableDescriptors == tableNames => " + tableNames);
try (Connection conn = ConnectionFactory.createConnection(getConf());
Admin admin = conn.getAdmin()) {
List<TableDescriptor> tds = admin.listTableDescriptors(tableNames);
return tds.toArray(new TableDescriptor[tds.size()]);
} catch (IOException e) {
LOG.debug("Exception getting table descriptors", e);
}
return new TableDescriptor[0];
}
代码示例来源:origin: apache/hbase
@Test
public void testRegionObserverSingleRegion() throws IOException {
final TableName tableName = TableName.valueOf(name.getMethodName());
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
admin.createTable(
new HTableDescriptor(tableName)
.addFamily(new HColumnDescriptor(foo))
// add the coprocessor for the region
.addCoprocessor(CustomRegionObserver.class.getName()));
try (Table table = connection.getTable(tableName)) {
table.get(new Get(foo));
table.get(new Get(foo)); // 2 gets
}
}
assertPreGetRequestsCounter(CustomRegionObserver.class);
}
代码示例来源:origin: apache/kylin
@Override
protected String createMetaStoreUUID() throws IOException {
try (final Admin hbaseAdmin = HBaseConnection.get(metadataUrl).getAdmin()) {
final String metaStoreName = metadataUrl.getIdentifier();
final HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(metaStoreName));
String uuid = desc.getValue(HBaseConnection.HTABLE_UUID_TAG);
if (uuid != null)
return uuid;
return UUID.randomUUID().toString();
} catch (Exception e) {
return null;
}
}
代码示例来源:origin: apache/hbase
private void validateTables(ClassLoader classLoader, Pattern pattern,
List<CoprocessorViolation> violations) throws IOException {
try (Connection connection = ConnectionFactory.createConnection(getConf());
Admin admin = connection.getAdmin()) {
validateTables(classLoader, admin, pattern, violations);
}
}
代码示例来源:origin: apache/hbase
@Override
protected void createSchema() throws IOException {
LOG.info("Creating tables");
// Create three tables
boolean acl = AccessControlClient.isAccessControllerRunning(ConnectionFactory
.createConnection(getConf()));
if(!acl) {
LOG.info("No ACL available.");
}
try (Connection conn = ConnectionFactory.createConnection(getConf());
Admin admin = conn.getAdmin()) {
for (int i = 0; i < DEFAULT_TABLES_COUNT; i++) {
TableName tableName = IntegrationTestBigLinkedListWithVisibility.getTableName(i);
createTable(admin, tableName, false, acl);
}
TableName tableName = TableName.valueOf(COMMON_TABLE_NAME);
createTable(admin, tableName, true, acl);
}
}
代码示例来源:origin: apache/kylin
public static void deleteTable(Connection conn, String tableName) throws IOException {
Admin hbase = conn.getAdmin();
try {
if (!tableExists(conn, tableName)) {
logger.debug("HTable '" + tableName + "' does not exists");
return;
}
logger.debug("delete HTable '" + tableName + "'");
if (hbase.isTableEnabled(TableName.valueOf(tableName))) {
hbase.disableTable(TableName.valueOf(tableName));
}
hbase.deleteTable(TableName.valueOf(tableName));
logger.debug("HTable '" + tableName + "' deleted");
} finally {
hbase.close();
}
}
代码示例来源:origin: apache/hive
private Admin getHBaseAdmin() throws MetaException {
try {
if (admin == null) {
Connection conn = ConnectionFactory.createConnection(hbaseConf);
admin = conn.getAdmin();
}
return admin;
} catch (IOException ioe) {
throw new MetaException(StringUtils.stringifyException(ioe));
}
}
代码示例来源:origin: apache/hbase
@Test
public void testPriorityRegionIsOpenedWithSeparateThreadPool() throws Exception {
final TableName tableName = TableName.valueOf(TestRegionOpen.class.getSimpleName());
ThreadPoolExecutor exec = getRS().getExecutorService()
.getExecutorThreadPool(ExecutorType.RS_OPEN_PRIORITY_REGION);
long completed = exec.getCompletedTaskCount();
HTableDescriptor htd = new HTableDescriptor(tableName);
htd.setPriority(HConstants.HIGH_QOS);
htd.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
try (Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration());
Admin admin = connection.getAdmin()) {
admin.createTable(htd);
}
assertEquals(completed + 1, exec.getCompletedTaskCount());
}
内容来源于网络,如有侵权,请联系作者删除!