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.servlet.ServletContext;
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.Context;
30 import javax.ws.rs.core.Response;
31 import javax.ws.rs.core.UriInfo;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35 import org.apache.hadoop.hbase.classification.InterfaceAudience;
36 import org.apache.hadoop.hbase.rest.model.NamespacesModel;
37
38
39
40
41
42
43
44 @InterfaceAudience.Private
45 public class NamespacesResource extends ResourceBase {
46
47 private static final Log LOG = LogFactory.getLog(NamespacesResource.class);
48
49
50
51
52
53 public NamespacesResource() throws IOException {
54 super();
55 }
56
57
58
59
60
61
62
63 @GET
64 @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
65 MIMETYPE_PROTOBUF_IETF})
66 public Response get(final @Context ServletContext context, final @Context UriInfo uriInfo) {
67 if (LOG.isTraceEnabled()) {
68 LOG.trace("GET " + uriInfo.getAbsolutePath());
69 }
70 servlet.getMetrics().incrementRequests(1);
71 try {
72 NamespacesModel rowModel = null;
73 rowModel = new NamespacesModel(servlet.getAdmin());
74 servlet.getMetrics().incrementSucessfulGetRequests(1);
75 return Response.ok(rowModel).build();
76 } catch (IOException e) {
77 servlet.getMetrics().incrementFailedGetRequests(1);
78 throw new RuntimeException("Cannot retrieve list of namespaces.");
79 }
80 }
81
82
83
84
85 @Path("{namespace}")
86 public NamespacesInstanceResource getNamespaceInstanceResource(
87 final @PathParam("namespace") String namespace) throws IOException {
88 return new NamespacesInstanceResource(namespace);
89 }
90 }