001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to you under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.hadoop.hbase.client; 018 019import java.io.IOException; 020import java.util.concurrent.Callable; 021 022import org.apache.hadoop.hbase.ServerName; 023import org.apache.yetus.audience.InterfaceAudience; 024import org.apache.hadoop.hbase.ipc.RpcControllerFactory; 025import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; 026import org.apache.hadoop.hbase.shaded.protobuf.RequestConverter; 027import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService; 028import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.GetQuotaStatesResponse; 029import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.GetSpaceQuotaRegionSizesResponse; 030import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.GetSpaceQuotaSnapshotsResponse; 031 032/** 033 * Client class to wrap RPCs to HBase servers for space quota status information. 034 */ 035@InterfaceAudience.Private 036public class QuotaStatusCalls { 037 038 /** 039 * See {@link #getMasterRegionSizes(Connection, RpcControllerFactory, RpcRetryingCallerFactory, int)} 040 */ 041 public static GetSpaceQuotaRegionSizesResponse getMasterRegionSizes( 042 ClusterConnection clusterConn, int timeout) throws IOException { 043 RpcControllerFactory rpcController = clusterConn.getRpcControllerFactory(); 044 RpcRetryingCallerFactory rpcCaller = clusterConn.getRpcRetryingCallerFactory(); 045 return getMasterRegionSizes(clusterConn, rpcController, rpcCaller, timeout); 046 } 047 048 /** 049 * Executes an RPC to the HBase master to fetch its view on the Region sizes. 050 */ 051 public static GetSpaceQuotaRegionSizesResponse getMasterRegionSizes( 052 Connection conn, RpcControllerFactory factory, RpcRetryingCallerFactory rpcCaller, 053 int timeout) throws IOException { 054 MasterCallable<GetSpaceQuotaRegionSizesResponse> callable = 055 new MasterCallable<GetSpaceQuotaRegionSizesResponse>(conn, factory) { 056 @Override 057 protected GetSpaceQuotaRegionSizesResponse rpcCall() throws Exception { 058 return master.getSpaceQuotaRegionSizes( 059 getRpcController(), RequestConverter.buildGetSpaceQuotaRegionSizesRequest()); 060 } 061 }; 062 RpcRetryingCaller<GetSpaceQuotaRegionSizesResponse> caller = rpcCaller.newCaller(); 063 try { 064 return caller.callWithoutRetries(callable, timeout); 065 } finally { 066 callable.close(); 067 } 068 } 069 070 /** 071 * See {@link #getMasterQuotaStates(Connection, RpcControllerFactory, RpcRetryingCallerFactory, int)} 072 */ 073 public static GetQuotaStatesResponse getMasterQuotaStates( 074 ClusterConnection clusterConn, int timeout) throws IOException { 075 RpcControllerFactory rpcController = clusterConn.getRpcControllerFactory(); 076 RpcRetryingCallerFactory rpcCaller = clusterConn.getRpcRetryingCallerFactory(); 077 return getMasterQuotaStates(clusterConn, rpcController, rpcCaller, timeout); 078 } 079 080 /** 081 * Executes an RPC tot he HBase master to fetch its view on space quotas. 082 */ 083 public static GetQuotaStatesResponse getMasterQuotaStates( 084 Connection conn, RpcControllerFactory factory, RpcRetryingCallerFactory rpcCaller, 085 int timeout) throws IOException { 086 MasterCallable<GetQuotaStatesResponse> callable = 087 new MasterCallable<GetQuotaStatesResponse>(conn, factory) { 088 @Override 089 protected GetQuotaStatesResponse rpcCall() throws Exception { 090 return master.getQuotaStates( 091 getRpcController(), RequestConverter.buildGetQuotaStatesRequest()); 092 } 093 }; 094 RpcRetryingCaller<GetQuotaStatesResponse> caller = rpcCaller.newCaller(); 095 try { 096 return caller.callWithoutRetries(callable, timeout); 097 } finally { 098 callable.close(); 099 } 100 } 101 102 /** 103 * See {@link #getRegionServerQuotaSnapshot(ClusterConnection, RpcControllerFactory, int, ServerName)} 104 */ 105 public static GetSpaceQuotaSnapshotsResponse getRegionServerQuotaSnapshot( 106 ClusterConnection clusterConn, int timeout, ServerName sn) throws IOException { 107 RpcControllerFactory rpcController = clusterConn.getRpcControllerFactory(); 108 return getRegionServerQuotaSnapshot(clusterConn, rpcController, timeout, sn); 109 } 110 111 /** 112 * Executes an RPC to the RegionServer identified by the {@code ServerName} to fetch its view 113 * on space quotas. 114 */ 115 public static GetSpaceQuotaSnapshotsResponse getRegionServerQuotaSnapshot( 116 ClusterConnection conn, RpcControllerFactory factory, 117 int timeout, ServerName sn) throws IOException { 118 final AdminService.BlockingInterface admin = conn.getAdmin(sn); 119 Callable<GetSpaceQuotaSnapshotsResponse> callable = 120 new Callable<GetSpaceQuotaSnapshotsResponse>() { 121 @Override 122 public GetSpaceQuotaSnapshotsResponse call() throws Exception { 123 return admin.getSpaceQuotaSnapshots( 124 factory.newController(), RequestConverter.buildGetSpaceQuotaSnapshotsRequest()); 125 } 126 }; 127 return ProtobufUtil.call(callable); 128 } 129}