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();
}
}
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);
}
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);
}
Aggregations