Search in sources :

Example 21 with ClientQuotaEntity

use of org.apache.kafka.common.quota.ClientQuotaEntity in project kafka by apache.

the class DescribeClientQuotasResponse method complete.

public void complete(KafkaFutureImpl<Map<ClientQuotaEntity, Map<String, Double>>> future) {
    Errors error = Errors.forCode(data.errorCode());
    if (error != Errors.NONE) {
        future.completeExceptionally(error.exception(data.errorMessage()));
        return;
    }
    Map<ClientQuotaEntity, Map<String, Double>> result = new HashMap<>(data.entries().size());
    for (EntryData entries : data.entries()) {
        Map<String, String> entity = new HashMap<>(entries.entity().size());
        for (EntityData entityData : entries.entity()) {
            entity.put(entityData.entityType(), entityData.entityName());
        }
        Map<String, Double> values = new HashMap<>(entries.values().size());
        for (ValueData valueData : entries.values()) {
            values.put(valueData.key(), valueData.value());
        }
        result.put(new ClientQuotaEntity(entity), values);
    }
    future.complete(result);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) EntryData(org.apache.kafka.common.message.DescribeClientQuotasResponseData.EntryData) HashMap(java.util.HashMap) EntityData(org.apache.kafka.common.message.DescribeClientQuotasResponseData.EntityData) ClientQuotaEntity(org.apache.kafka.common.quota.ClientQuotaEntity) HashMap(java.util.HashMap) Map(java.util.Map) ValueData(org.apache.kafka.common.message.DescribeClientQuotasResponseData.ValueData)

Example 22 with ClientQuotaEntity

use of org.apache.kafka.common.quota.ClientQuotaEntity in project kafka by apache.

the class KafkaAdminClient method alterClientQuotas.

@Override
public AlterClientQuotasResult alterClientQuotas(Collection<ClientQuotaAlteration> entries, AlterClientQuotasOptions options) {
    Map<ClientQuotaEntity, KafkaFutureImpl<Void>> futures = new HashMap<>(entries.size());
    for (ClientQuotaAlteration entry : entries) {
        futures.put(entry.entity(), new KafkaFutureImpl<>());
    }
    final long now = time.milliseconds();
    runnable.call(new Call("alterClientQuotas", calcDeadlineMs(now, options.timeoutMs()), new LeastLoadedNodeProvider()) {

        @Override
        AlterClientQuotasRequest.Builder createRequest(int timeoutMs) {
            return new AlterClientQuotasRequest.Builder(entries, options.validateOnly());
        }

        @Override
        void handleResponse(AbstractResponse abstractResponse) {
            AlterClientQuotasResponse response = (AlterClientQuotasResponse) abstractResponse;
            response.complete(futures);
        }

        @Override
        void handleFailure(Throwable throwable) {
            completeAllExceptionally(futures.values(), throwable);
        }
    }, now);
    return new AlterClientQuotasResult(Collections.unmodifiableMap(futures));
}
Also used : ClientQuotaAlteration(org.apache.kafka.common.quota.ClientQuotaAlteration) HashMap(java.util.HashMap) AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) AlterClientQuotasResponse(org.apache.kafka.common.requests.AlterClientQuotasResponse) AlterClientQuotasRequest(org.apache.kafka.common.requests.AlterClientQuotasRequest) ClientQuotaEntity(org.apache.kafka.common.quota.ClientQuotaEntity)

Aggregations

ClientQuotaEntity (org.apache.kafka.common.quota.ClientQuotaEntity)22 HashMap (java.util.HashMap)15 ClientQuotaAlteration (org.apache.kafka.common.quota.ClientQuotaAlteration)9 ArrayList (java.util.ArrayList)8 Map (java.util.Map)7 Test (org.junit.jupiter.api.Test)7 SnapshotRegistry (org.apache.kafka.timeline.SnapshotRegistry)6 LogContext (org.apache.kafka.common.utils.LogContext)5 Errors (org.apache.kafka.common.protocol.Errors)4 ClientQuotaRecord (org.apache.kafka.common.metadata.ClientQuotaRecord)3 EntityData (org.apache.kafka.common.metadata.ClientQuotaRecord.EntityData)3 ApiError (org.apache.kafka.common.requests.ApiError)3 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 QuotaConfigs (org.apache.kafka.common.config.internals.QuotaConfigs)2 InvalidRequestException (org.apache.kafka.common.errors.InvalidRequestException)2 EntryData (org.apache.kafka.common.message.AlterClientQuotasResponseData.EntryData)2