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 java.util.EnumSet; 022import org.apache.hadoop.hbase.ClusterMetrics.Option; 023import org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel; 024import org.apache.yetus.audience.InterfaceAudience; 025import org.slf4j.Logger; 026import org.slf4j.LoggerFactory; 027 028import org.apache.hbase.thirdparty.javax.ws.rs.GET; 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@InterfaceAudience.Private 037public class StorageClusterVersionResource extends ResourceBase { 038 private static final Logger LOG = LoggerFactory.getLogger(StorageClusterVersionResource.class); 039 040 static CacheControl cacheControl; 041 static { 042 cacheControl = new CacheControl(); 043 cacheControl.setNoCache(true); 044 cacheControl.setNoTransform(false); 045 } 046 047 /** 048 * Constructor n 049 */ 050 public StorageClusterVersionResource() throws IOException { 051 super(); 052 } 053 054 @GET 055 @Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON }) 056 public Response get(final @Context UriInfo uriInfo) { 057 if (LOG.isTraceEnabled()) { 058 LOG.trace("GET " + uriInfo.getAbsolutePath()); 059 } 060 servlet.getMetrics().incrementRequests(1); 061 try { 062 StorageClusterVersionModel model = new StorageClusterVersionModel(); 063 model.setVersion( 064 servlet.getAdmin().getClusterMetrics(EnumSet.of(Option.HBASE_VERSION)).getHBaseVersion()); 065 ResponseBuilder response = Response.ok(model); 066 response.cacheControl(cacheControl); 067 servlet.getMetrics().incrementSucessfulGetRequests(1); 068 return response.build(); 069 } catch (IOException e) { 070 servlet.getMetrics().incrementFailedGetRequests(1); 071 return Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT) 072 .entity("Unavailable" + CRLF).build(); 073 } 074 } 075}