1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.rest;
21
22 import java.io.IOException;
23
24 import javax.ws.rs.GET;
25 import javax.ws.rs.Path;
26 import javax.ws.rs.PathParam;
27 import javax.ws.rs.Produces;
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.classification.InterfaceAudience;
38 import org.apache.hadoop.hbase.TableName;
39 import org.apache.hadoop.hbase.rest.model.TableListModel;
40 import org.apache.hadoop.hbase.rest.model.TableModel;
41
42 @Path("/")
43 @InterfaceAudience.Private
44 public class RootResource extends ResourceBase {
45 private static final Log LOG = LogFactory.getLog(RootResource.class);
46
47 static CacheControl cacheControl;
48 static {
49 cacheControl = new CacheControl();
50 cacheControl.setNoCache(true);
51 cacheControl.setNoTransform(false);
52 }
53
54
55
56
57
58 public RootResource() throws IOException {
59 super();
60 }
61
62 private final TableListModel getTableList() throws IOException {
63 TableListModel tableList = new TableListModel();
64 TableName[] tableNames = servlet.getAdmin().listTableNames();
65 for (TableName name: tableNames) {
66 tableList.add(new TableModel(name.getNameAsString()));
67 }
68 return tableList;
69 }
70
71 @GET
72 @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
73 MIMETYPE_PROTOBUF_IETF})
74 public Response get(final @Context UriInfo uriInfo) {
75 if (LOG.isTraceEnabled()) {
76 LOG.trace("GET " + uriInfo.getAbsolutePath());
77 }
78 servlet.getMetrics().incrementRequests(1);
79 try {
80 ResponseBuilder response = Response.ok(getTableList());
81 response.cacheControl(cacheControl);
82 servlet.getMetrics().incrementSucessfulGetRequests(1);
83 return response.build();
84 } catch (Exception e) {
85 servlet.getMetrics().incrementFailedGetRequests(1);
86 return processException(e);
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
107 @Path("namespaces")
108 public NamespacesResource getNamespaceResource() throws IOException {
109 return new NamespacesResource();
110 }
111 }