View Javadoc

1   /*
2    * Copyright 2010 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package org.apache.hadoop.hbase.rest;
22  
23  import java.io.IOException;
24  
25  import javax.ws.rs.GET;
26  import javax.ws.rs.Produces;
27  import javax.ws.rs.WebApplicationException;
28  import javax.ws.rs.core.CacheControl;
29  import javax.ws.rs.core.Context;
30  import javax.ws.rs.core.Response;
31  import javax.ws.rs.core.UriInfo;
32  import javax.ws.rs.core.Response.ResponseBuilder;
33  
34  import org.apache.commons.logging.Log;
35  import org.apache.commons.logging.LogFactory;
36  
37  import org.apache.hadoop.hbase.client.HBaseAdmin;
38  import org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel;
39  
40  public class StorageClusterVersionResource extends ResourceBase {
41    private static final Log LOG =
42      LogFactory.getLog(StorageClusterVersionResource.class);
43  
44    static CacheControl cacheControl;
45    static {
46      cacheControl = new CacheControl();
47      cacheControl.setNoCache(true);
48      cacheControl.setNoTransform(false);
49    }
50  
51    /**
52     * Constructor
53     * @throws IOException
54     */
55    public StorageClusterVersionResource() throws IOException {
56      super();
57    }
58  
59    @GET
60    @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON})
61    public Response get(final @Context UriInfo uriInfo) {
62      if (LOG.isDebugEnabled()) {
63        LOG.debug("GET " + uriInfo.getAbsolutePath());
64      }
65      servlet.getMetrics().incrementRequests(1);
66      try {
67        HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
68        StorageClusterVersionModel model = new StorageClusterVersionModel();
69        model.setVersion(admin.getClusterStatus().getHBaseVersion());
70        ResponseBuilder response = Response.ok(model);
71        response.cacheControl(cacheControl);
72        return response.build();
73      } catch (IOException e) {
74        throw new WebApplicationException(e, 
75                    Response.Status.SERVICE_UNAVAILABLE);
76      }
77    }
78  }