3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 package org
.apache
.hadoop
.hbase
.rest
;
22 import java
.io
.IOException
;
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
;
33 import org
.apache
.yetus
.audience
.InterfaceAudience
;
34 import org
.slf4j
.Logger
;
35 import org
.slf4j
.LoggerFactory
;
36 import org
.apache
.hadoop
.hbase
.rest
.model
.NamespacesModel
;
39 * Implements REST GET list of all namespaces.
41 * <tt>/namespaces</tt>
44 @InterfaceAudience.Private
45 public class NamespacesResource
extends ResourceBase
{
47 private static final Logger LOG
= LoggerFactory
.getLogger(NamespacesResource
.class);
53 public NamespacesResource() throws IOException
{
58 * Build a response for a list of all namespaces request.
59 * @param context servlet context
60 * @param uriInfo (JAX-RS context variable) request URL
61 * @return a response for a version request
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());
70 servlet
.getMetrics().incrementRequests(1);
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.");
83 * Dispatch to NamespaceInstanceResource
86 public NamespacesInstanceResource
getNamespaceInstanceResource(
87 final @PathParam("namespace") String namespace
) throws IOException
{
88 return new NamespacesInstanceResource(namespace
);