Revert "HBASE-26523 Upgrade hbase-thirdparty dependency to 4.0.0 (#3910)"
[hbase.git] / hbase-rest / src / main / java / org / apache / hadoop / hbase / rest / NamespacesResource.java
blobfe48bafd4734eb97939c37714312c6c9335ce509
1 /*
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;
38 /**
39 * Implements REST GET list of all namespaces.
40 * <p>
41 * <tt>/namespaces</tt>
42 * <p>
44 @InterfaceAudience.Private
45 public class NamespacesResource extends ResourceBase {
47 private static final Logger LOG = LoggerFactory.getLogger(NamespacesResource.class);
49 /**
50 * Constructor
51 * @throws IOException
53 public NamespacesResource() throws IOException {
54 super();
57 /**
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
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());
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.");
82 /**
83 * Dispatch to NamespaceInstanceResource
85 @Path("{namespace}")
86 public NamespacesInstanceResource getNamespaceInstanceResource(
87 final @PathParam("namespace") String namespace) throws IOException {
88 return new NamespacesInstanceResource(namespace);