HBASE-24944 Remove MetaTableAccessor.getTableRegionsAndLocations in hbase-rest module (#2302)
Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
parent
1220a8775c
commit
6b0707f541
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package org.apache.hadoop.hbase.rest;
|
package org.apache.hadoop.hbase.rest;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.CacheControl;
|
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;
|
||||||
import javax.ws.rs.core.Response.ResponseBuilder;
|
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
import java.io.IOException;
|
import org.apache.hadoop.hbase.HRegionLocation;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.MetaTableAccessor;
|
|
||||||
import org.apache.hadoop.hbase.ServerName;
|
import org.apache.hadoop.hbase.ServerName;
|
||||||
import org.apache.hadoop.hbase.TableName;
|
import org.apache.hadoop.hbase.TableName;
|
||||||
import org.apache.hadoop.hbase.TableNotFoundException;
|
import org.apache.hadoop.hbase.TableNotFoundException;
|
||||||
import org.apache.hadoop.hbase.client.Connection;
|
import org.apache.hadoop.hbase.client.Connection;
|
||||||
import org.apache.hadoop.hbase.client.ConnectionFactory;
|
import org.apache.hadoop.hbase.client.ConnectionFactory;
|
||||||
import org.apache.hadoop.hbase.client.RegionInfo;
|
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.TableInfoModel;
|
||||||
import org.apache.hadoop.hbase.rest.model.TableRegionModel;
|
import org.apache.hadoop.hbase.rest.model.TableRegionModel;
|
||||||
import org.apache.hadoop.hbase.util.Pair;
|
|
||||||
import org.apache.yetus.audience.InterfaceAudience;
|
import org.apache.yetus.audience.InterfaceAudience;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -78,16 +77,16 @@ public class RegionsResource extends ResourceBase {
|
||||||
TableName tableName = TableName.valueOf(tableResource.getName());
|
TableName tableName = TableName.valueOf(tableResource.getName());
|
||||||
TableInfoModel model = new TableInfoModel(tableName.getNameAsString());
|
TableInfoModel model = new TableInfoModel(tableName.getNameAsString());
|
||||||
|
|
||||||
Connection connection = ConnectionFactory.createConnection(servlet.getConfiguration());
|
List<HRegionLocation> locs;
|
||||||
List<Pair<RegionInfo, ServerName>> regions = MetaTableAccessor
|
try (Connection connection = ConnectionFactory.createConnection(servlet.getConfiguration());
|
||||||
.getTableRegionsAndLocations(connection, tableName);
|
RegionLocator locator = connection.getRegionLocator(tableName)) {
|
||||||
connection.close();
|
locs = locator.getAllRegionLocations();
|
||||||
for (Pair<RegionInfo,ServerName> e: regions) {
|
}
|
||||||
RegionInfo hri = e.getFirst();
|
for (HRegionLocation loc : locs) {
|
||||||
ServerName addr = e.getSecond();
|
RegionInfo hri = loc.getRegion();
|
||||||
model.add(
|
ServerName addr = loc.getServerName();
|
||||||
new TableRegionModel(tableName.getNameAsString(), hri.getRegionId(),
|
model.add(new TableRegionModel(tableName.getNameAsString(), hri.getRegionId(),
|
||||||
hri.getStartKey(), hri.getEndKey(), addr.getAddress().toString()));
|
hri.getStartKey(), hri.getEndKey(), addr.getAddress().toString()));
|
||||||
}
|
}
|
||||||
ResponseBuilder response = Response.ok(model);
|
ResponseBuilder response = Response.ok(model);
|
||||||
response.cacheControl(cacheControl);
|
response.cacheControl(cacheControl);
|
||||||
|
|
Loading…
Reference in New Issue