use of org.apache.hadoop.hbase.rest.model.VersionModel in project hbase by apache.
the class VersionResource method get.
/**
* Build a response for a version request.
* @param context servlet context
* @param uriInfo (JAX-RS context variable) request URL
* @return a response for a version request
*/
@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final ServletContext context, @Context final UriInfo uriInfo) {
if (LOG.isTraceEnabled()) {
LOG.trace("GET " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
ResponseBuilder response = Response.ok(new VersionModel(context));
response.cacheControl(cacheControl);
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.build();
}
use of org.apache.hadoop.hbase.rest.model.VersionModel in project hbase by apache.
the class TestVersionResource method testGetStargateVersionPB.
@Test
public void testGetStargateVersionPB() throws IOException {
Response response = client.get("/version", Constants.MIMETYPE_PROTOBUF);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
VersionModel model = new VersionModel();
model.getObjectFromMessage(response.getBody());
validate(model);
response = client.get("/version", Constants.MIMETYPE_PROTOBUF_IETF);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
model = new VersionModel();
model.getObjectFromMessage(response.getBody());
validate(model);
}
use of org.apache.hadoop.hbase.rest.model.VersionModel in project hbase by apache.
the class TestVersionResource method testGetStargateVersionJSON.
@Test
public void testGetStargateVersionJSON() throws IOException {
Response response = client.get("/version", Constants.MIMETYPE_JSON);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(VersionModel.class, MediaType.APPLICATION_JSON_TYPE);
VersionModel model = mapper.readValue(response.getBody(), VersionModel.class);
validate(model);
LOG.info("success retrieving Stargate version as JSON");
}
use of org.apache.hadoop.hbase.rest.model.VersionModel in project hbase by apache.
the class TestVersionResource method testGetStargateVersionXML.
@Test
public void testGetStargateVersionXML() throws IOException, JAXBException {
Response response = client.get("/version", Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
VersionModel model = (VersionModel) context.createUnmarshaller().unmarshal(new ByteArrayInputStream(response.getBody()));
validate(model);
LOG.info("success retrieving Stargate version as XML");
}
use of org.apache.hadoop.hbase.rest.model.VersionModel in project hbase by apache.
the class RemoteAdmin method getRestVersion.
/**
* @return string representing the rest api's version
* @throws IOException
* if the endpoint does not exist, there is a timeout, or some other
* general failure mode
*/
public VersionModel getRestVersion() throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
if (accessToken != null) {
path.append(accessToken);
path.append('/');
}
path.append("version/rest");
int code = 0;
for (int i = 0; i < maxRetries; i++) {
Response response = client.get(path.toString(), Constants.MIMETYPE_PROTOBUF);
code = response.getCode();
switch(code) {
case 200:
VersionModel v = new VersionModel();
return (VersionModel) v.getObjectFromMessage(response.getBody());
case 404:
throw new IOException("REST version not found");
case 509:
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
}
break;
default:
throw new IOException("get request to " + path.toString() + " returned " + code);
}
}
throw new IOException("get request to " + path.toString() + " timed out");
}
Aggregations