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

View File

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

View File

@ -183,7 +183,7 @@ public class SchemaResource extends ResourceBase {
final UriInfo uriInfo) { final UriInfo uriInfo) {
try { try {
byte[] name = Bytes.toBytes(tableResource.getName()); byte[] name = Bytes.toBytes(tableResource.getName());
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration()); HBaseAdmin admin = servlet.getAdmin();
if (replace || !admin.tableExists(name)) { if (replace || !admin.tableExists(name)) {
return replace(name, model, uriInfo, admin); return replace(name, model, uriInfo, admin);
} else { } else {
@ -225,7 +225,7 @@ public class SchemaResource extends ResourceBase {
} }
servlet.getMetrics().incrementRequests(1); servlet.getMetrics().incrementRequests(1);
try { try {
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration()); HBaseAdmin admin = servlet.getAdmin();
boolean success = false; boolean success = false;
for (int i = 0; i < 10; i++) try { for (int i = 0; i < 10; i++) try {
admin.disableTable(tableResource.getName()); 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.ServerLoad;
import org.apache.hadoop.hbase.RegionLoad; import org.apache.hadoop.hbase.RegionLoad;
import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel; import org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel;
@InterfaceAudience.Private @InterfaceAudience.Private
@ -69,8 +68,7 @@ public class StorageClusterStatusResource extends ResourceBase {
} }
servlet.getMetrics().incrementRequests(1); servlet.getMetrics().incrementRequests(1);
try { try {
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration()); ClusterStatus status = servlet.getAdmin().getClusterStatus();
ClusterStatus status = admin.getClusterStatus();
StorageClusterStatusModel model = new StorageClusterStatusModel(); StorageClusterStatusModel model = new StorageClusterStatusModel();
model.setRegions(status.getRegionsCount()); model.setRegions(status.getRegionsCount());
model.setRequests(status.getRequestsCount()); 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.commons.logging.LogFactory;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel; import org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel;
@InterfaceAudience.Private @InterfaceAudience.Private
@ -65,9 +64,8 @@ public class StorageClusterVersionResource extends ResourceBase {
} }
servlet.getMetrics().incrementRequests(1); servlet.getMetrics().incrementRequests(1);
try { try {
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
StorageClusterVersionModel model = new StorageClusterVersionModel(); StorageClusterVersionModel model = new StorageClusterVersionModel();
model.setVersion(admin.getClusterStatus().getHBaseVersion()); model.setVersion(servlet.getAdmin().getClusterStatus().getHBaseVersion());
ResponseBuilder response = Response.ok(model); ResponseBuilder response = Response.ok(model);
response.cacheControl(cacheControl); response.cacheControl(cacheControl);
servlet.getMetrics().incrementSucessfulGetRequests(1); servlet.getMetrics().incrementSucessfulGetRequests(1);

View File

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