1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
35
36 @InterfaceAudience.Private
37 public class QuotaStatusCalls {
38
39
40
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
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
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
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 }