use of org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel in project hbase by apache.
the class RemoteAdmin method getClusterVersion.
/**
* @return string representing the cluster's version
* @throws IOException
* if the endpoint does not exist, there is a timeout, or some other
* general failure mode
*/
public StorageClusterVersionModel getClusterVersion() throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
if (accessToken != null) {
path.append(accessToken);
path.append('/');
}
path.append("version/cluster");
int code = 0;
for (int i = 0; i < maxRetries; i++) {
Response response = client.get(path.toString(), Constants.MIMETYPE_XML);
code = response.getCode();
switch(code) {
case 200:
try {
return (StorageClusterVersionModel) getUnmarsheller().unmarshal(getInputStream(response));
} catch (JAXBException jaxbe) {
throw new IOException("Issue parsing StorageClusterVersionModel object in XML form: " + jaxbe.getLocalizedMessage(), jaxbe);
}
case 404:
throw new IOException("Cluster version not found");
case 509:
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
}
break;
default:
throw new IOException(path.toString() + " request returned " + code);
}
}
throw new IOException("get request to " + path.toString() + " request timed out");
}
use of org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel in project hbase by apache.
the class StorageClusterVersionResource method get.
@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON })
public Response get(@Context final UriInfo uriInfo) {
if (LOG.isTraceEnabled()) {
LOG.trace("GET " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
try {
StorageClusterVersionModel model = new StorageClusterVersionModel();
model.setVersion(servlet.getAdmin().getClusterStatus().getHBaseVersion());
ResponseBuilder response = Response.ok(model);
response.cacheControl(cacheControl);
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.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.StorageClusterVersionModel in project hbase by apache.
the class TestXmlParsing method testParsingClusterVersion.
@Test
public void testParsingClusterVersion() throws Exception {
final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<ClusterVersion>2.0.0</ClusterVersion>";
Client client = mock(Client.class);
RemoteAdmin admin = new RemoteAdmin(client, HBaseConfiguration.create(), null);
Response resp = new Response(200, null, xml.getBytes());
when(client.get("/version/cluster", Constants.MIMETYPE_XML)).thenReturn(resp);
StorageClusterVersionModel cv = admin.getClusterVersion();
assertEquals("2.0.0", cv.getVersion());
}
use of org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel in project hbase by apache.
the class TestVersionResource method testGetStorageClusterVersionXML.
@Test
public void testGetStorageClusterVersionXML() throws IOException, JAXBException {
Response response = client.get("/version/cluster", Constants.MIMETYPE_XML);
assertTrue(response.getCode() == 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
StorageClusterVersionModel clusterVersionModel = (StorageClusterVersionModel) context.createUnmarshaller().unmarshal(new ByteArrayInputStream(response.getBody()));
assertNotNull(clusterVersionModel);
assertNotNull(clusterVersionModel.getVersion());
LOG.info("success retrieving storage cluster version as XML");
}
Aggregations