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.VersionModel; 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.Produces; 030import org.apache.hbase.thirdparty.javax.ws.rs.core.CacheControl; 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.Response.ResponseBuilder; 034import org.apache.hbase.thirdparty.javax.ws.rs.core.UriInfo; 035 036/** 037 * Implements REST software version reporting 038 * <p> 039 * <tt>/version/rest</tt> 040 * <p> 041 * <tt>/version</tt> (alias for <tt>/version/rest</tt>) 042 */ 043@InterfaceAudience.Private 044public class VersionResource extends ResourceBase { 045 046 private static final Logger LOG = LoggerFactory.getLogger(VersionResource.class); 047 048 static CacheControl cacheControl; 049 static { 050 cacheControl = new CacheControl(); 051 cacheControl.setNoCache(true); 052 cacheControl.setNoTransform(false); 053 } 054 055 /** 056 * Constructor n 057 */ 058 public VersionResource() throws IOException { 059 super(); 060 } 061 062 /** 063 * Build a response for a version request. 064 * @param context servlet context 065 * @param uriInfo (JAX-RS context variable) request URL 066 * @return a response for a version request 067 */ 068 @GET 069 @Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, 070 MIMETYPE_PROTOBUF_IETF }) 071 public Response get(final @Context ServletContext context, final @Context UriInfo uriInfo) { 072 if (LOG.isTraceEnabled()) { 073 LOG.trace("GET " + uriInfo.getAbsolutePath()); 074 } 075 servlet.getMetrics().incrementRequests(1); 076 ResponseBuilder response = Response.ok(new VersionModel(context)); 077 response.cacheControl(cacheControl); 078 servlet.getMetrics().incrementSucessfulGetRequests(1); 079 return response.build(); 080 } 081 082 /** 083 * Dispatch to StorageClusterVersionResource 084 */ 085 @Path("cluster") 086 public StorageClusterVersionResource getClusterVersionResource() throws IOException { 087 return new StorageClusterVersionResource(); 088 } 089 090 /** 091 * Dispatch <tt>/version/rest</tt> to self. 092 */ 093 @Path("rest") 094 public VersionResource getVersionResource() { 095 return this; 096 } 097}