Search in sources :

Example 1 with Quotas

use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas in project hbase by apache.

the class QuotaUtil method fetchGlobalQuotas.

public static <K> Map<K, QuotaState> fetchGlobalQuotas(final String type, final Connection connection, final List<Get> gets, final KeyFromRow<K> kfr) throws IOException {
    long nowTs = EnvironmentEdgeManager.currentTime();
    Result[] results = doGet(connection, gets);
    Map<K, QuotaState> globalQuotas = new HashMap<>(results.length);
    for (int i = 0; i < results.length; ++i) {
        byte[] row = gets.get(i).getRow();
        K key = kfr.getKeyFromRow(row);
        QuotaState quotaInfo = new QuotaState(nowTs);
        globalQuotas.put(key, quotaInfo);
        if (results[i].isEmpty())
            continue;
        assert Bytes.equals(row, results[i].getRow());
        byte[] data = results[i].getValue(QUOTA_FAMILY_INFO, QUOTA_QUALIFIER_SETTINGS);
        if (data == null)
            continue;
        try {
            Quotas quotas = quotasFromData(data);
            quotaInfo.setQuotas(quotas);
        } catch (IOException e) {
            LOG.error("Unable to parse " + type + " '" + key + "' quotas", e);
            globalQuotas.remove(key);
        }
    }
    return globalQuotas;
}
Also used : HashMap(java.util.HashMap) Quotas(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result)

Example 2 with Quotas

use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas in project hbase by apache.

the class QuotaRetriever method next.

public QuotaSettings next() throws IOException {
    if (cache.isEmpty()) {
        Result result = scanner.next();
        if (result == null)
            return null;
        QuotaTableUtil.parseResult(result, new QuotaTableUtil.QuotasVisitor() {

            @Override
            public void visitUserQuotas(String userName, Quotas quotas) {
                cache.addAll(QuotaSettingsFactory.fromUserQuotas(userName, quotas));
            }

            @Override
            public void visitUserQuotas(String userName, TableName table, Quotas quotas) {
                cache.addAll(QuotaSettingsFactory.fromUserQuotas(userName, table, quotas));
            }

            @Override
            public void visitUserQuotas(String userName, String namespace, Quotas quotas) {
                cache.addAll(QuotaSettingsFactory.fromUserQuotas(userName, namespace, quotas));
            }

            @Override
            public void visitTableQuotas(TableName tableName, Quotas quotas) {
                cache.addAll(QuotaSettingsFactory.fromTableQuotas(tableName, quotas));
            }

            @Override
            public void visitNamespaceQuotas(String namespace, Quotas quotas) {
                cache.addAll(QuotaSettingsFactory.fromNamespaceQuotas(namespace, quotas));
            }
        });
    }
    return cache.poll();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Quotas(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas) Result(org.apache.hadoop.hbase.client.Result)

Example 3 with Quotas

use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas in project hbase by apache.

the class QuotaTableUtil method parseUserResult.

protected static void parseUserResult(final String userName, final Result result, final UserQuotasVisitor visitor) throws IOException {
    Map<byte[], byte[]> familyMap = result.getFamilyMap(QUOTA_FAMILY_INFO);
    if (familyMap == null || familyMap.isEmpty())
        return;
    for (Map.Entry<byte[], byte[]> entry : familyMap.entrySet()) {
        Quotas quotas = quotasFromData(entry.getValue());
        if (Bytes.startsWith(entry.getKey(), QUOTA_QUALIFIER_SETTINGS_PREFIX)) {
            String name = Bytes.toString(entry.getKey(), QUOTA_QUALIFIER_SETTINGS_PREFIX.length);
            if (name.charAt(name.length() - 1) == TableName.NAMESPACE_DELIM) {
                String namespace = name.substring(0, name.length() - 1);
                visitor.visitUserQuotas(userName, namespace, quotas);
            } else {
                TableName table = TableName.valueOf(name);
                visitor.visitUserQuotas(userName, table, quotas);
            }
        } else if (Bytes.equals(entry.getKey(), QUOTA_QUALIFIER_SETTINGS)) {
            visitor.visitUserQuotas(userName, quotas);
        }
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Quotas(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas) Map(java.util.Map)

Example 4 with Quotas

use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas in project hbase by apache.

the class QuotaTableUtil method parseTableResult.

protected static void parseTableResult(final TableName table, final Result result, final TableQuotasVisitor visitor) throws IOException {
    byte[] data = result.getValue(QUOTA_FAMILY_INFO, QUOTA_QUALIFIER_SETTINGS);
    if (data != null) {
        Quotas quotas = quotasFromData(data);
        visitor.visitTableQuotas(table, quotas);
    }
}
Also used : Quotas(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas)

Example 5 with Quotas

use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas in project hbase by apache.

the class TestQuotaTableUtil method testNamespaceQuotaUtil.

@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);
}
Also used : Quotas(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas) Test(org.junit.Test)

Aggregations

Quotas (org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas)10 TableName (org.apache.hadoop.hbase.TableName)4 Test (org.junit.Test)4 Result (org.apache.hadoop.hbase.client.Result)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)1 ServerName (org.apache.hadoop.hbase.ServerName)1 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1 SnapshotDescription (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.SnapshotDescription)1