001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.rest; 019 020import java.io.IOException; 021import javax.servlet.ServletContext; 022import org.apache.hadoop.hbase.rest.model.NamespacesModel; 023import org.apache.yetus.audience.InterfaceAudience; 024import org.slf4j.Logger; 025import org.slf4j.LoggerFactory; 026 027import org.apache.hbase.thirdparty.javax.ws.rs.GET; 028import org.apache.hbase.thirdparty.javax.ws.rs.Path; 029import org.apache.hbase.thirdparty.javax.ws.rs.PathParam; 030import org.apache.hbase.thirdparty.javax.ws.rs.Produces; 031import org.apache.hbase.thirdparty.javax.ws.rs.core.Context; 032import org.apache.hbase.thirdparty.javax.ws.rs.core.Response; 033import org.apache.hbase.thirdparty.javax.ws.rs.core.UriInfo; 034 035/** 036 * Implements REST GET list of all namespaces. 037 * <p> 038 * <tt>/namespaces</tt> 039 * <p> 040 */ 041@InterfaceAudience.Private 042public class NamespacesResource extends ResourceBase { 043 044 private static final Logger LOG = LoggerFactory.getLogger(NamespacesResource.class); 045 046 /** 047 * Constructor n 048 */ 049 public NamespacesResource() throws IOException { 050 super(); 051 } 052 053 /** 054 * Build a response for a list of all namespaces request. 055 * @param context servlet context 056 * @param uriInfo (JAX-RS context variable) request URL 057 * @return a response for a version request 058 */ 059 @GET 060 @Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, 061 MIMETYPE_PROTOBUF_IETF }) 062 public Response get(final @Context ServletContext context, final @Context UriInfo uriInfo) { 063 if (LOG.isTraceEnabled()) { 064 LOG.trace("GET " + uriInfo.getAbsolutePath()); 065 } 066 servlet.getMetrics().incrementRequests(1); 067 try { 068 NamespacesModel rowModel = null; 069 rowModel = new NamespacesModel(servlet.getAdmin()); 070 servlet.getMetrics().incrementSucessfulGetRequests(1); 071 return Response.ok(rowModel).build(); 072 } catch (IOException e) { 073 servlet.getMetrics().incrementFailedGetRequests(1); 074 throw new RuntimeException("Cannot retrieve list of namespaces."); 075 } 076 } 077 078 /** 079 * Dispatch to NamespaceInstanceResource 080 */ 081 @Path("{namespace}") 082 public NamespacesInstanceResource getNamespaceInstanceResource( 083 final @PathParam("namespace") String namespace) throws IOException { 084 return new NamespacesInstanceResource(namespace); 085 } 086}