View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.hadoop.hbase.client;
18  
19  import java.io.IOException;
20  
21  import org.apache.hadoop.hbase.ServerName;
22  import org.apache.hadoop.hbase.classification.InterfaceAudience;
23  import org.apache.hadoop.hbase.ipc.RpcControllerFactory;
24  import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
25  import org.apache.hadoop.hbase.protobuf.RequestConverter;
26  import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.AdminService;
27  import org.apache.hadoop.hbase.protobuf.generated.QuotaProtos.GetQuotaStatesResponse;
28  import org.apache.hadoop.hbase.protobuf.generated.QuotaProtos.GetSpaceQuotaRegionSizesResponse;
29  import org.apache.hadoop.hbase.protobuf.generated.QuotaProtos.GetSpaceQuotaSnapshotsResponse;
30  
31  import com.google.protobuf.ServiceException;
32  
33  /**
34   * Client class to wrap RPCs to HBase servers for space quota status information.
35   */
36  @InterfaceAudience.Private
37  public class QuotaStatusCalls {
38  
39    /**
40     * See {@link #getMasterRegionSizes(ClusterConnection, RpcControllerFactory, RpcRetryingCallerFactory, int)}
41     */
42    public static GetSpaceQuotaRegionSizesResponse getMasterRegionSizes(
43        ClusterConnection clusterConn, int timeout) throws IOException {
44      RpcControllerFactory rpcController = clusterConn.getRpcControllerFactory();
45      RpcRetryingCallerFactory rpcCaller = clusterConn.getRpcRetryingCallerFactory();
46      return getMasterRegionSizes(clusterConn, rpcController, rpcCaller, timeout);
47    }
48  
49    public static GetSpaceQuotaRegionSizesResponse getMasterRegionSizes(
50        ClusterConnection conn, final RpcControllerFactory factory,
51        RpcRetryingCallerFactory rpcCaller, int timeout) throws IOException {
52      MasterCallable<GetSpaceQuotaRegionSizesResponse> callable =
53          new MasterCallable<GetSpaceQuotaRegionSizesResponse>(conn) {
54        @Override
55        public GetSpaceQuotaRegionSizesResponse call(int callTimeout) throws Exception {
56          return master.getSpaceQuotaRegionSizes(
57              factory.newController(), RequestConverter.buildGetSpaceQuotaRegionSizesRequest());
58        }
59      };
60      RpcRetryingCaller<GetSpaceQuotaRegionSizesResponse> caller = rpcCaller.newCaller();
61      try {
62        return caller.callWithoutRetries(callable, timeout);
63      } finally {
64        callable.close();
65      }
66    }
67  
68    /**
69     * See {@link #getMasterQuotaStates(ClusterConnection, RpcControllerFactory, RpcRetryingCallerFactory, int)}
70     */
71    public static GetQuotaStatesResponse getMasterQuotaStates(
72        ClusterConnection clusterConn, int timeout) throws IOException {
73      RpcControllerFactory rpcController = clusterConn.getRpcControllerFactory();
74      RpcRetryingCallerFactory rpcCaller = clusterConn.getRpcRetryingCallerFactory();
75      return getMasterQuotaStates(clusterConn, rpcController, rpcCaller, timeout);
76    }
77  
78    /**
79     * Executes an RPC tot he HBase master to fetch its view on space quotas.
80     */
81    public static GetQuotaStatesResponse getMasterQuotaStates(
82        ClusterConnection conn, final RpcControllerFactory factory,
83        RpcRetryingCallerFactory rpcCaller, int timeout) throws IOException {
84      MasterCallable<GetQuotaStatesResponse> callable =
85          new MasterCallable<GetQuotaStatesResponse>(conn) {
86        @Override
87        public GetQuotaStatesResponse call(int callTimeout) throws Exception {
88          return master.getQuotaStates(
89              factory.newController(), RequestConverter.buildGetQuotaStatesRequest());
90        }
91      };
92      RpcRetryingCaller<GetQuotaStatesResponse> caller = rpcCaller.newCaller();
93      try {
94        return caller.callWithoutRetries(callable, timeout);
95      } finally {
96        callable.close();
97      }
98    }
99  
100   /**
101    * See {@link #getRegionServerQuotaSnapshot(ClusterConnection, RpcControllerFactory, int, ServerName)}
102    */
103   public static GetSpaceQuotaSnapshotsResponse getRegionServerQuotaSnapshot(
104       ClusterConnection clusterConn, int timeout, ServerName sn) throws IOException {
105     RpcControllerFactory rpcController = clusterConn.getRpcControllerFactory();
106     return getRegionServerQuotaSnapshot(clusterConn, rpcController, timeout, sn);
107   }
108 
109   public static GetSpaceQuotaSnapshotsResponse getRegionServerQuotaSnapshot(
110       ClusterConnection conn, RpcControllerFactory factory,
111       int timeout, ServerName sn) throws IOException {
112     final AdminService.BlockingInterface admin = conn.getAdmin(sn);
113     try {
114       return admin.getSpaceQuotaSnapshots(
115           factory.newController(), RequestConverter.buildGetSpaceQuotaSnapshotsRequest());
116     } catch (ServiceException se) {
117       throw ProtobufUtil.getRemoteException(se);
118     }
119   }
120 }