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.Path;
27 import javax.ws.rs.PathParam;
28 import javax.ws.rs.Produces;
29 import javax.ws.rs.core.CacheControl;
30 import javax.ws.rs.core.Context;
31 import javax.ws.rs.core.Response;
32 import javax.ws.rs.core.UriInfo;
33 import javax.ws.rs.core.Response.ResponseBuilder;
34
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38 import org.apache.hadoop.hbase.rest.model.TableListModel;
39 import org.apache.hadoop.hbase.rest.model.TableModel;
40
41 @Path("/")
42 public class RootResource extends ResourceBase {
43 private static final Log LOG = LogFactory.getLog(RootResource.class);
44
45 static CacheControl cacheControl;
46 static {
47 cacheControl = new CacheControl();
48 cacheControl.setNoCache(true);
49 cacheControl.setNoTransform(false);
50 }
51
52
53
54
55
56 public RootResource() throws IOException {
57 super();
58 }
59
60 private final TableListModel getTableList() throws IOException {
61 TableListModel tableList = new TableListModel();
62 String[] tableNames = servlet.getAdmin().getTableNames();
63 for (String name: tableNames) {
64 tableList.add(new TableModel(name));
65 }
66 return tableList;
67 }
68
69 @GET
70 @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
71 MIMETYPE_PROTOBUF_IETF})
72 public Response get(final @Context UriInfo uriInfo) {
73 if (LOG.isDebugEnabled()) {
74 LOG.debug("GET " + uriInfo.getAbsolutePath());
75 }
76 servlet.getMetrics().incrementRequests(1);
77 try {
78 ResponseBuilder response = Response.ok(getTableList());
79 response.cacheControl(cacheControl);
80 servlet.getMetrics().incrementSucessfulGetRequests(1);
81 return response.build();
82 } catch (IOException e) {
83 servlet.getMetrics().incrementFailedGetRequests(1);
84 return Response.status(Response.Status.SERVICE_UNAVAILABLE)
85 .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
86 .build();
87 }
88 }
89
90 @Path("status/cluster")
91 public StorageClusterStatusResource getClusterStatusResource()
92 throws IOException {
93 return new StorageClusterStatusResource();
94 }
95
96 @Path("version")
97 public VersionResource getVersionResource() throws IOException {
98 return new VersionResource();
99 }
100
101 @Path("{table}")
102 public TableResource getTableResource(
103 final @PathParam("table") String table) throws IOException {
104 return new TableResource(table);
105 }
106 }