HBASE-7469. [REST] Share a HBaseAdmin instance

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1427226 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Kyle Purtell 2012-12-31 19:12:26 +00:00
parent deeb84ae5a
commit e204b6a2d4
6 changed files with 13 additions and 18 deletions

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTablePool;
/**
@ -34,6 +35,7 @@ public class RESTServlet implements Constants {
private final Configuration conf;
private final HTablePool pool;
private final MetricsREST metrics = new MetricsREST();
private final HBaseAdmin admin;
/**
* @return the RESTServlet singleton instance
@ -69,6 +71,11 @@ public class RESTServlet implements Constants {
RESTServlet(Configuration conf) throws IOException {
this.conf = conf;
this.pool = new HTablePool(conf, 10);
this.admin = new HBaseAdmin(conf);
}
HBaseAdmin getAdmin() {
return admin;
}
HTablePool getTablePool() {

View File

@ -37,7 +37,6 @@ import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.rest.model.TableListModel;
import org.apache.hadoop.hbase.rest.model.TableModel;
@ -63,8 +62,7 @@ public class RootResource extends ResourceBase {
private final TableListModel getTableList() throws IOException {
TableListModel tableList = new TableListModel();
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
HTableDescriptor[] list = admin.listTables();
HTableDescriptor[] list = servlet.getAdmin().listTables();
for (HTableDescriptor htd: list) {
tableList.add(new TableModel(htd.getNameAsString()));
}

View File

@ -183,7 +183,7 @@ public class SchemaResource extends ResourceBase {
final UriInfo uriInfo) {
try {
byte[] name = Bytes.toBytes(tableResource.getName());
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
HBaseAdmin admin = servlet.getAdmin();
if (replace || !admin.tableExists(name)) {
return replace(name, model, uriInfo, admin);
} else {
@ -225,7 +225,7 @@ public class SchemaResource extends ResourceBase {
}
servlet.getMetrics().incrementRequests(1);
try {
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
HBaseAdmin admin = servlet.getAdmin();
boolean success = false;
for (int i = 0; i < 10; i++) try {
admin.disableTable(tableResource.getName());

View File

@ -38,7 +38,6 @@ import org.apache.hadoop.hbase.ClusterStatus;
import org.apache.hadoop.hbase.ServerLoad;
import org.apache.hadoop.hbase.RegionLoad;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel;
@InterfaceAudience.Private
@ -69,8 +68,7 @@ public class StorageClusterStatusResource extends ResourceBase {
}
servlet.getMetrics().incrementRequests(1);
try {
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
ClusterStatus status = admin.getClusterStatus();
ClusterStatus status = servlet.getAdmin().getClusterStatus();
StorageClusterStatusModel model = new StorageClusterStatusModel();
model.setRegions(status.getRegionsCount());
model.setRequests(status.getRequestsCount());

View File

@ -34,7 +34,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel;
@InterfaceAudience.Private
@ -65,9 +64,8 @@ public class StorageClusterVersionResource extends ResourceBase {
}
servlet.getMetrics().incrementRequests(1);
try {
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
StorageClusterVersionModel model = new StorageClusterVersionModel();
model.setVersion(admin.getClusterStatus().getHBaseVersion());
model.setVersion(servlet.getAdmin().getClusterStatus().getHBaseVersion());
ResponseBuilder response = Response.ok(model);
response.cacheControl(cacheControl);
servlet.getMetrics().incrementSucessfulGetRequests(1);

View File

@ -27,7 +27,6 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.hbase.client.HBaseAdmin;
@InterfaceAudience.Private
public class TableResource extends ResourceBase {
@ -54,12 +53,7 @@ public class TableResource extends ResourceBase {
* @throws IOException
*/
boolean exists() throws IOException {
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
try {
return admin.tableExists(table);
} finally {
admin.close();
}
return servlet.getAdmin().tableExists(table);
}
@Path("exists")