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:
Enis Soztutar 2014-04-18 17:40:38 +00:00
parent 996ce5211c
commit b1afd6e117
7 changed files with 1234 additions and 2 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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();
}

View File

@ -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 =