Search in sources :

Example 1 with EntryData

use of org.apache.kafka.common.message.AlterClientQuotasResponseData.EntryData in project kafka by apache.

the class AlterClientQuotasResponse method complete.

public void complete(Map<ClientQuotaEntity, KafkaFutureImpl<Void>> futures) {
    for (EntryData entryData : data.entries()) {
        Map<String, String> entityEntries = new HashMap<>(entryData.entity().size());
        for (EntityData entityData : entryData.entity()) {
            entityEntries.put(entityData.entityType(), entityData.entityName());
        }
        ClientQuotaEntity entity = new ClientQuotaEntity(entityEntries);
        KafkaFutureImpl<Void> future = futures.get(entity);
        if (future == null) {
            throw new IllegalArgumentException("Future map must contain entity " + entity);
        }
        Errors error = Errors.forCode(entryData.errorCode());
        if (error == Errors.NONE) {
            future.complete(null);
        } else {
            future.completeExceptionally(error.exception(entryData.errorMessage()));
        }
    }
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) EntryData(org.apache.kafka.common.message.AlterClientQuotasResponseData.EntryData) HashMap(java.util.HashMap) EntityData(org.apache.kafka.common.message.AlterClientQuotasResponseData.EntityData) ClientQuotaEntity(org.apache.kafka.common.quota.ClientQuotaEntity)

Example 2 with EntryData

use of org.apache.kafka.common.message.AlterClientQuotasResponseData.EntryData in project kafka by apache.

the class AlterClientQuotasResponse method fromQuotaEntities.

public static AlterClientQuotasResponse fromQuotaEntities(Map<ClientQuotaEntity, ApiError> result, int throttleTimeMs) {
    List<EntryData> entries = new ArrayList<>(result.size());
    for (Map.Entry<ClientQuotaEntity, ApiError> entry : result.entrySet()) {
        ApiError e = entry.getValue();
        entries.add(new EntryData().setErrorCode(e.error().code()).setErrorMessage(e.message()).setEntity(toEntityData(entry.getKey())));
    }
    return new AlterClientQuotasResponse(new AlterClientQuotasResponseData().setThrottleTimeMs(throttleTimeMs).setEntries(entries));
}
Also used : EntryData(org.apache.kafka.common.message.AlterClientQuotasResponseData.EntryData) AlterClientQuotasResponseData(org.apache.kafka.common.message.AlterClientQuotasResponseData) ArrayList(java.util.ArrayList) ClientQuotaEntity(org.apache.kafka.common.quota.ClientQuotaEntity) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)2 EntryData (org.apache.kafka.common.message.AlterClientQuotasResponseData.EntryData)2 ClientQuotaEntity (org.apache.kafka.common.quota.ClientQuotaEntity)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 AlterClientQuotasResponseData (org.apache.kafka.common.message.AlterClientQuotasResponseData)1 EntityData (org.apache.kafka.common.message.AlterClientQuotasResponseData.EntityData)1 Errors (org.apache.kafka.common.protocol.Errors)1