diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java index b70c13d27a2..c3eed6a2eec 100644 --- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java +++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java @@ -19,6 +19,8 @@ package org.apache.hadoop.hbase.rest; +import java.io.IOException; +import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Produces; import javax.ws.rs.core.CacheControl; @@ -26,19 +28,16 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.UriInfo; -import java.io.IOException; -import java.util.List; - -import org.apache.hadoop.hbase.MetaTableAccessor; +import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.RegionInfo; +import org.apache.hadoop.hbase.client.RegionLocator; import org.apache.hadoop.hbase.rest.model.TableInfoModel; import org.apache.hadoop.hbase.rest.model.TableRegionModel; -import org.apache.hadoop.hbase.util.Pair; import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -78,16 +77,16 @@ public class RegionsResource extends ResourceBase { TableName tableName = TableName.valueOf(tableResource.getName()); TableInfoModel model = new TableInfoModel(tableName.getNameAsString()); - Connection connection = ConnectionFactory.createConnection(servlet.getConfiguration()); - List> regions = MetaTableAccessor - .getTableRegionsAndLocations(connection, tableName); - connection.close(); - for (Pair e: regions) { - RegionInfo hri = e.getFirst(); - ServerName addr = e.getSecond(); - model.add( - new TableRegionModel(tableName.getNameAsString(), hri.getRegionId(), - hri.getStartKey(), hri.getEndKey(), addr.getAddress().toString())); + List locs; + try (Connection connection = ConnectionFactory.createConnection(servlet.getConfiguration()); + RegionLocator locator = connection.getRegionLocator(tableName)) { + locs = locator.getAllRegionLocations(); + } + for (HRegionLocation loc : locs) { + RegionInfo hri = loc.getRegion(); + ServerName addr = loc.getServerName(); + model.add(new TableRegionModel(tableName.getNameAsString(), hri.getRegionId(), + hri.getStartKey(), hri.getEndKey(), addr.getAddress().toString())); } ResponseBuilder response = Response.ok(model); response.cacheControl(cacheControl);