HBASE-10934 Provide Admin interface to abstract HBaseAdmin (Contributed by Carter)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1588528 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
996ce5211c
commit
b1afd6e117
1193
hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java
Normal file
1193
hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -110,6 +110,11 @@ class ConnectionAdapter implements ClusterConnection {
|
||||
return wrappedConnection.getTable(tableName, pool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Admin getAdmin() throws IOException {
|
||||
return wrappedConnection.getAdmin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMasterRunning() throws MasterNotRunningException,
|
||||
ZooKeeperConnectionException {
|
||||
|
@ -630,6 +630,14 @@ class ConnectionManager {
|
||||
return new HTable(tableName, this, pool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Admin getAdmin() throws IOException {
|
||||
if (managed) {
|
||||
throw new IOException("The connection has to be unmanaged.");
|
||||
}
|
||||
return new HBaseAdmin(this);
|
||||
}
|
||||
|
||||
private ExecutorService getBatchPool() {
|
||||
if (batchPool == null) {
|
||||
// shared HTable thread executor not yet initialized
|
||||
|
@ -158,7 +158,7 @@ import com.google.protobuf.ServiceException;
|
||||
*/
|
||||
@InterfaceAudience.Public
|
||||
@InterfaceStability.Evolving
|
||||
public class HBaseAdmin implements Abortable, Closeable {
|
||||
public class HBaseAdmin implements Admin {
|
||||
private static final Log LOG = LogFactory.getLog(HBaseAdmin.class);
|
||||
|
||||
// We use the implementation class rather then the interface because we
|
||||
|
@ -153,6 +153,17 @@ public interface HConnection extends Abortable, Closeable {
|
||||
*/
|
||||
public HTableInterface getTable(TableName tableName, ExecutorService pool) throws IOException;
|
||||
|
||||
/**
|
||||
* 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. Note that HConnection needs to be unmanaged
|
||||
* (created with {@link HConnectionManager#createConnection(Configuration)}).
|
||||
*
|
||||
* @return an Admin instance for cluster administration
|
||||
*/
|
||||
Admin getAdmin() throws IOException;
|
||||
|
||||
/** @return - true if the master server is running
|
||||
* @deprecated internal method, do not use thru HConnection */
|
||||
@Deprecated
|
||||
|
@ -132,6 +132,8 @@ public class CoprocessorHConnection implements ClusterConnection {
|
||||
return delegate.getTable(tableName, pool);
|
||||
}
|
||||
|
||||
public Admin getAdmin() throws IOException { return delegate.getAdmin(); }
|
||||
|
||||
public boolean isMasterRunning() throws MasterNotRunningException, ZooKeeperConnectionException {
|
||||
return delegate.isMasterRunning();
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ import org.junit.experimental.categories.Category;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* This class is for testing HCM features
|
||||
* This class is for testing HBaseConnectionManager features
|
||||
*/
|
||||
@Category(MediumTests.class)
|
||||
public class TestHCM {
|
||||
@ -199,6 +199,19 @@ public class TestHCM {
|
||||
otherPool.shutdownNow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Naive test to check that HConnection#getAdmin returns a properly constructed HBaseAdmin object
|
||||
* @throws IOException Unable to construct admin
|
||||
*/
|
||||
@Test
|
||||
public void testAdminFactory() throws IOException {
|
||||
HConnection con1 = HConnectionManager.createConnection(TEST_UTIL.getConfiguration());
|
||||
HBaseAdmin admin = (HBaseAdmin)con1.getAdmin();
|
||||
assertTrue(admin.getConnection() == con1);
|
||||
assertTrue(admin.getConfiguration() == TEST_UTIL.getConfiguration());
|
||||
con1.close();
|
||||
}
|
||||
|
||||
@Ignore ("Fails in IDEs: HBASE-9042") @Test(expected = RegionServerStoppedException.class)
|
||||
public void testClusterStatus() throws Exception {
|
||||
TableName tn =
|
||||
|
Loading…
x
Reference in New Issue
Block a user