Search in sources :

Example 1 with TableRegionModel

use of org.apache.hadoop.hbase.rest.model.TableRegionModel in project hbase by apache.

the class RegionsResource method get.

@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final UriInfo uriInfo) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("GET " + uriInfo.getAbsolutePath());
    }
    servlet.getMetrics().incrementRequests(1);
    try {
        TableName tableName = TableName.valueOf(tableResource.getName());
        TableInfoModel model = new TableInfoModel(tableName.getNameAsString());
        Connection connection = ConnectionFactory.createConnection(servlet.getConfiguration());
        @SuppressWarnings("deprecation") Map<HRegionInfo, ServerName> regions = MetaTableAccessor.allTableRegions(connection, tableName);
        connection.close();
        for (Map.Entry<HRegionInfo, ServerName> e : regions.entrySet()) {
            HRegionInfo hri = e.getKey();
            ServerName addr = e.getValue();
            model.add(new TableRegionModel(tableName.getNameAsString(), hri.getRegionId(), hri.getStartKey(), hri.getEndKey(), addr.getHostAndPort()));
        }
        ResponseBuilder response = Response.ok(model);
        response.cacheControl(cacheControl);
        servlet.getMetrics().incrementSucessfulGetRequests(1);
        return response.build();
    } catch (TableNotFoundException e) {
        servlet.getMetrics().incrementFailedGetRequests(1);
        return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF).build();
    } catch (IOException e) {
        servlet.getMetrics().incrementFailedGetRequests(1);
        return Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT).entity("Unavailable" + CRLF).build();
    }
}
Also used : Connection(org.apache.hadoop.hbase.client.Connection) IOException(java.io.IOException) TableInfoModel(org.apache.hadoop.hbase.rest.model.TableInfoModel) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) ServerName(org.apache.hadoop.hbase.ServerName) TableRegionModel(org.apache.hadoop.hbase.rest.model.TableRegionModel) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Map(java.util.Map) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with TableRegionModel

use of org.apache.hadoop.hbase.rest.model.TableRegionModel in project hbase by apache.

the class TestTableResource method checkTableInfo.

void checkTableInfo(TableInfoModel model) {
    assertEquals(model.getName(), TABLE.getNameAsString());
    Iterator<TableRegionModel> regions = model.getRegions().iterator();
    assertTrue(regions.hasNext());
    while (regions.hasNext()) {
        TableRegionModel region = regions.next();
        boolean found = false;
        for (HRegionLocation e : regionMap) {
            HRegionInfo hri = e.getRegionInfo();
            String hriRegionName = hri.getRegionNameAsString();
            String regionName = region.getName();
            if (hriRegionName.equals(regionName)) {
                found = true;
                byte[] startKey = hri.getStartKey();
                byte[] endKey = hri.getEndKey();
                ServerName serverName = e.getServerName();
                InetSocketAddress sa = new InetSocketAddress(serverName.getHostname(), serverName.getPort());
                String location = sa.getHostName() + ":" + Integer.valueOf(sa.getPort());
                assertEquals(hri.getRegionId(), region.getId());
                assertTrue(Bytes.equals(startKey, region.getStartKey()));
                assertTrue(Bytes.equals(endKey, region.getEndKey()));
                assertEquals(location, region.getLocation());
                break;
            }
        }
        assertTrue(found);
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) InetSocketAddress(java.net.InetSocketAddress) ServerName(org.apache.hadoop.hbase.ServerName) TableRegionModel(org.apache.hadoop.hbase.rest.model.TableRegionModel)

Aggregations

HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)2 ServerName (org.apache.hadoop.hbase.ServerName)2 TableRegionModel (org.apache.hadoop.hbase.rest.model.TableRegionModel)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Map (java.util.Map)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)1 TableName (org.apache.hadoop.hbase.TableName)1 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1 Connection (org.apache.hadoop.hbase.client.Connection)1 TableInfoModel (org.apache.hadoop.hbase.rest.model.TableInfoModel)1