/** * Apply the new quota settings. * @param quota the quota settings * @throws IOException if a remote or network exception occurs */ @Override public void setQuota(final QuotaSettings quota) throws IOException { executeCallable(new MasterCallable<Void>(getConnection()) { @Override public Void call(int callTimeout) throws ServiceException { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setCallTimeout(callTimeout); this.master.setQuota(controller, QuotaSettings.buildSetQuotaRequestProto(quota)); return null; } }); }
@Test public void testThrottleType() throws Exception { String userName = User.getCurrent().getShortName(); admin.setQuota( QuotaSettingsFactory.throttleUser(userName, ThrottleType.READ_NUMBER, 6, TimeUnit.MINUTES)) .get(); admin.setQuota( QuotaSettingsFactory.throttleUser(userName, ThrottleType.WRITE_NUMBER, 12, TimeUnit.MINUTES)) .get(); admin.setQuota(QuotaSettingsFactory.bypassGlobals(userName, true)).get(); int countThrottle = 0; int countGlobalBypass = 0; for (QuotaSettings settings : admin.getQuota(null).get()) { switch (settings.getQuotaType()) { case THROTTLE: countThrottle++; break; case GLOBAL_BYPASS: countGlobalBypass++; break; default: fail("unexpected settings type: " + settings.getQuotaType()); } } assertEquals(2, countThrottle); assertEquals(1, countGlobalBypass); admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName)).get(); assertNumResults(1, null); admin.setQuota(QuotaSettingsFactory.bypassGlobals(userName, false)).get(); assertNumResults(0, null); }
private int countResults(final QuotaFilter filter) throws Exception { int count = 0; for (QuotaSettings settings : admin.getQuota(filter).get()) { LOG.debug(Objects.toString(settings)); count++; } return count; }
@Override public void setQuota(final QuotaSettings quota) throws IOException { executeCallable(new MasterCallable<Void>(getConnection(), getRpcControllerFactory()) { @Override protected Void rpcCall() throws Exception { this.master.setQuota(getRpcController(), QuotaSettings.buildSetQuotaRequestProto(quota)); return null; } }); }
@Override public List<QuotaSettings> getQuota(QuotaFilter filter) throws IOException { List<QuotaSettings> quotas = new LinkedList<>(); try (QuotaRetriever retriever = QuotaRetriever.open(conf, filter)) { Iterator<QuotaSettings> iterator = retriever.iterator(); while (iterator.hasNext()) { quotas.add(iterator.next()); } } return quotas; }
@Override public CompletableFuture<Void> setQuota(QuotaSettings quota) { return this .<Void> newMasterCaller() .action( (controller, stub) -> this.<SetQuotaRequest, SetQuotaResponse, Void> call(controller, stub, QuotaSettings.buildSetQuotaRequestProto(quota), (s, c, req, done) -> s.setQuota(c, req, done), (resp) -> null)).call(); }
@Override public CompletableFuture<List<QuotaSettings>> getQuota(QuotaFilter filter) { CompletableFuture<List<QuotaSettings>> future = new CompletableFuture<>(); Scan scan = QuotaTableUtil.makeScan(filter); this.connection.getTableBuilder(QuotaTableUtil.QUOTA_TABLE_NAME).build() .scan(scan, new AdvancedScanResultConsumer() { List<QuotaSettings> settings = new ArrayList<>(); @Override public void onNext(Result[] results, ScanController controller) { for (Result result : results) { try { QuotaTableUtil.parseResultToCollection(result, settings); } catch (IOException e) { controller.terminate(); future.completeExceptionally(e); } } } @Override public void onError(Throwable error) { future.completeExceptionally(error); } @Override public void onComplete() { future.complete(settings); } }); return future; }
@Override public void setQuota(QuotaSettings quota) throws IOException { throw new UnsupportedOperationException("setQuota"); }
@Override public void setQuota(QuotaSettings qs) throws IOException { wrappedHbaseAdmin.setQuota(qs); }
@Override public CompletableFuture<Void> setQuota(QuotaSettings quota) { return wrap(rawAdmin.setQuota(quota)); }
@Override public CompletableFuture<List<QuotaSettings>> getQuota(QuotaFilter filter) { return wrap(rawAdmin.getQuota(filter)); }
/** * Apply the new quota settings. * @param quota the quota settings * @throws IOException if a remote or network exception occurs */ void setQuota(final QuotaSettings quota) throws IOException;
/** * Apply the new quota settings. * * @param quota the quota settings * @throws IOException if a remote or network exception occurs */ void setQuota(QuotaSettings quota) throws IOException;
/** * List the quotas based on the filter. * @param filter the quota settings filter * @return the QuotaSetting list * @throws IOException if a remote or network exception occurs */ List<QuotaSettings> getQuota(QuotaFilter filter) throws IOException;
/** * Apply the new quota settings. * @param quota the quota settings */ CompletableFuture<Void> setQuota(QuotaSettings quota);
/** * List the quotas based on the filter. * @param filter the quota settings filter * @return the QuotaSetting list, which wrapped by a CompletableFuture. */ CompletableFuture<List<QuotaSettings>> getQuota(QuotaFilter filter);