Search in sources :

Example 1 with TableInfoModel

use of org.apache.hadoop.hbase.rest.model.TableInfoModel 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());
        if (!tableResource.exists()) {
            throw new TableNotFoundException(tableName);
        }
        TableInfoModel model = new TableInfoModel(tableName.getNameAsString());
        List<HRegionLocation> 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);
        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 : TableInfoModel(org.apache.hadoop.hbase.rest.model.TableInfoModel) TableName(org.apache.hadoop.hbase.TableName) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) Connection(org.apache.hadoop.hbase.client.Connection) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TableRegionModel(org.apache.hadoop.hbase.rest.model.TableRegionModel) IOException(java.io.IOException) ResponseBuilder(org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder) Produces(org.apache.hbase.thirdparty.javax.ws.rs.Produces) GET(org.apache.hbase.thirdparty.javax.ws.rs.GET)

Example 2 with TableInfoModel

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

the class TestTableResource method testTableInfoXML.

@Test
public void testTableInfoXML() throws IOException, JAXBException {
    Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
    TableInfoModel model = (TableInfoModel) context.createUnmarshaller().unmarshal(new ByteArrayInputStream(response.getBody()));
    checkTableInfo(model);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) TableInfoModel(org.apache.hadoop.hbase.rest.model.TableInfoModel) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 3 with TableInfoModel

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

the class TestTableResource method testTableInfoPB.

@Test
public void testTableInfoPB() throws IOException, JAXBException {
    Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_PROTOBUF);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
    TableInfoModel model = new TableInfoModel();
    model.getObjectFromMessage(response.getBody());
    checkTableInfo(model);
    response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_PROTOBUF_IETF);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
    model = new TableInfoModel();
    model.getObjectFromMessage(response.getBody());
    checkTableInfo(model);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) TableInfoModel(org.apache.hadoop.hbase.rest.model.TableInfoModel) Test(org.junit.Test)

Aggregations

TableInfoModel (org.apache.hadoop.hbase.rest.model.TableInfoModel)3 Response (org.apache.hadoop.hbase.rest.client.Response)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)1 ServerName (org.apache.hadoop.hbase.ServerName)1 TableName (org.apache.hadoop.hbase.TableName)1 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1 Connection (org.apache.hadoop.hbase.client.Connection)1 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)1 RegionLocator (org.apache.hadoop.hbase.client.RegionLocator)1 TableRegionModel (org.apache.hadoop.hbase.rest.model.TableRegionModel)1 GET (org.apache.hbase.thirdparty.javax.ws.rs.GET)1 Produces (org.apache.hbase.thirdparty.javax.ws.rs.Produces)1 ResponseBuilder (org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder)1