@Override public GlobalQuotaSettingsImpl fetch() throws IOException { return new GlobalQuotaSettingsImpl(null, null, namespace, null, QuotaUtil.getNamespaceQuota(masterServices.getConnection(), namespace)); } @Override
@Override public void postDeleteNamespace( ObserverContext<MasterCoprocessorEnvironment> ctx, String namespace) throws IOException { // Do nothing if quotas aren't enabled if (!quotasEnabled) { return; } final Connection conn = ctx.getEnvironment().getConnection(); Quotas quotas = QuotaUtil.getNamespaceQuota(conn, namespace); if (quotas != null) { if (quotas.hasSpace()) { QuotaSettings settings = QuotaSettingsFactory.removeNamespaceSpaceLimit(namespace); try (Admin admin = conn.getAdmin()) { admin.setQuota(settings); } } if (quotas.hasThrottle()) { QuotaSettings settings = QuotaSettingsFactory.unthrottleNamespace(namespace); try (Admin admin = conn.getAdmin()) { admin.setQuota(settings); } } } } }
@Test public void testNamespaceQuotaUtil() throws Exception { final String namespace = "testNamespaceQuotaUtilNS"; Quotas quota = Quotas.newBuilder() .setThrottle(Throttle.newBuilder() .setReqNum(ProtobufUtil.toTimedQuota(1000, TimeUnit.SECONDS, QuotaScope.MACHINE)) .setWriteNum(ProtobufUtil.toTimedQuota(600, TimeUnit.SECONDS, QuotaScope.MACHINE)) .setReadSize(ProtobufUtil.toTimedQuota(8192, TimeUnit.SECONDS, QuotaScope.MACHINE)) .build()) .build(); // Add user quota and verify it QuotaUtil.addNamespaceQuota(this.connection, namespace, quota); Quotas resQuota = QuotaUtil.getNamespaceQuota(this.connection, namespace); assertEquals(quota, resQuota); // Remove user quota and verify it QuotaUtil.deleteNamespaceQuota(this.connection, namespace); resQuota = QuotaUtil.getNamespaceQuota(this.connection, namespace); assertEquals(null, resQuota); }
@Override public Quotas fetch() throws IOException { return QuotaUtil.getNamespaceQuota(masterServices.getConnection(), namespace); }
@Test public void testNamespaceQuotaUtil() throws Exception { final String namespace = "testNamespaceQuotaUtilNS"; Quotas quota = Quotas.newBuilder() .setThrottle(Throttle.newBuilder() .setReqNum(ProtobufUtil.toTimedQuota(1000, TimeUnit.SECONDS, QuotaScope.MACHINE)) .setWriteNum(ProtobufUtil.toTimedQuota(600, TimeUnit.SECONDS, QuotaScope.MACHINE)) .setReadSize(ProtobufUtil.toTimedQuota(8192, TimeUnit.SECONDS, QuotaScope.MACHINE)) .build()) .build(); // Add user quota and verify it QuotaUtil.addNamespaceQuota(this.connection, namespace, quota); Quotas resQuota = QuotaUtil.getNamespaceQuota(this.connection, namespace); assertEquals(quota, resQuota); // Remove user quota and verify it QuotaUtil.deleteNamespaceQuota(this.connection, namespace); resQuota = QuotaUtil.getNamespaceQuota(this.connection, namespace); assertEquals(null, resQuota); }