1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.rest;
22
23 import java.io.IOException;
24
25 import javax.ws.rs.GET;
26 import javax.ws.rs.Produces;
27 import javax.ws.rs.WebApplicationException;
28 import javax.ws.rs.core.CacheControl;
29 import javax.ws.rs.core.Context;
30 import javax.ws.rs.core.Response;
31 import javax.ws.rs.core.UriInfo;
32 import javax.ws.rs.core.Response.ResponseBuilder;
33
34 import org.apache.commons.logging.Log;
35 import org.apache.commons.logging.LogFactory;
36
37 import org.apache.hadoop.hbase.client.HBaseAdmin;
38 import org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel;
39
40 public class StorageClusterVersionResource extends ResourceBase {
41 private static final Log LOG =
42 LogFactory.getLog(StorageClusterVersionResource.class);
43
44 static CacheControl cacheControl;
45 static {
46 cacheControl = new CacheControl();
47 cacheControl.setNoCache(true);
48 cacheControl.setNoTransform(false);
49 }
50
51
52
53
54
55 public StorageClusterVersionResource() throws IOException {
56 super();
57 }
58
59 @GET
60 @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON})
61 public Response get(final @Context UriInfo uriInfo) {
62 if (LOG.isDebugEnabled()) {
63 LOG.debug("GET " + uriInfo.getAbsolutePath());
64 }
65 servlet.getMetrics().incrementRequests(1);
66 try {
67 HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
68 StorageClusterVersionModel model = new StorageClusterVersionModel();
69 model.setVersion(admin.getClusterStatus().getHBaseVersion());
70 ResponseBuilder response = Response.ok(model);
71 response.cacheControl(cacheControl);
72 return response.build();
73 } catch (IOException e) {
74 throw new WebApplicationException(e,
75 Response.Status.SERVICE_UNAVAILABLE);
76 }
77 }
78 }