use of org.apache.kafka.common.quota.ClientQuotaEntity in project kafka by apache.
the class ClientQuotasImage method write.
public void write(Consumer<List<ApiMessageAndVersion>> out) {
for (Entry<ClientQuotaEntity, ClientQuotaImage> entry : entities.entrySet()) {
ClientQuotaEntity entity = entry.getKey();
ClientQuotaImage clientQuotaImage = entry.getValue();
clientQuotaImage.write(entity, out);
}
}
use of org.apache.kafka.common.quota.ClientQuotaEntity in project kafka by apache.
the class ClientQuotasDelta method replay.
public void replay(ClientQuotaRecord record) {
ClientQuotaEntity entity = ClientQuotaImage.dataToEntity(record.entity());
ClientQuotaDelta change = changes.computeIfAbsent(entity, __ -> new ClientQuotaDelta(image.entities().getOrDefault(entity, ClientQuotaImage.EMPTY)));
change.replay(record);
}
use of org.apache.kafka.common.quota.ClientQuotaEntity in project kafka by apache.
the class ClientQuotasDelta method finishSnapshot.
public void finishSnapshot() {
for (Entry<ClientQuotaEntity, ClientQuotaImage> entry : image.entities().entrySet()) {
ClientQuotaEntity entity = entry.getKey();
ClientQuotaImage quotaImage = entry.getValue();
ClientQuotaDelta quotaDelta = changes.computeIfAbsent(entity, __ -> new ClientQuotaDelta(quotaImage));
quotaDelta.finishSnapshot();
}
}
use of org.apache.kafka.common.quota.ClientQuotaEntity in project kafka by apache.
the class KafkaAdminClientTest method testAlterClientQuotas.
@Test
public void testAlterClientQuotas() throws Exception {
try (AdminClientUnitTestEnv env = mockClientEnv()) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
ClientQuotaEntity goodEntity = newClientQuotaEntity(ClientQuotaEntity.USER, "user-1");
ClientQuotaEntity unauthorizedEntity = newClientQuotaEntity(ClientQuotaEntity.USER, "user-0");
ClientQuotaEntity invalidEntity = newClientQuotaEntity("", "user-0");
Map<ClientQuotaEntity, ApiError> responseData = new HashMap<>(2);
responseData.put(goodEntity, new ApiError(Errors.CLUSTER_AUTHORIZATION_FAILED, "Authorization failed"));
responseData.put(unauthorizedEntity, new ApiError(Errors.CLUSTER_AUTHORIZATION_FAILED, "Authorization failed"));
responseData.put(invalidEntity, new ApiError(Errors.INVALID_REQUEST, "Invalid quota entity"));
env.kafkaClient().prepareResponse(AlterClientQuotasResponse.fromQuotaEntities(responseData, 0));
List<ClientQuotaAlteration> entries = new ArrayList<>(3);
entries.add(new ClientQuotaAlteration(goodEntity, singleton(new ClientQuotaAlteration.Op("consumer_byte_rate", 10000.0))));
entries.add(new ClientQuotaAlteration(unauthorizedEntity, singleton(new ClientQuotaAlteration.Op("producer_byte_rate", 10000.0))));
entries.add(new ClientQuotaAlteration(invalidEntity, singleton(new ClientQuotaAlteration.Op("producer_byte_rate", 100.0))));
AlterClientQuotasResult result = env.adminClient().alterClientQuotas(entries);
result.values().get(goodEntity);
TestUtils.assertFutureError(result.values().get(unauthorizedEntity), ClusterAuthorizationException.class);
TestUtils.assertFutureError(result.values().get(invalidEntity), InvalidRequestException.class);
}
}
use of org.apache.kafka.common.quota.ClientQuotaEntity in project kafka by apache.
the class ClientQuotaControlManagerTest method testInvalidEntityTypes.
@Test
public void testInvalidEntityTypes() {
SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
ClientQuotaControlManager manager = new ClientQuotaControlManager(snapshotRegistry);
// Unknown type "foo"
assertInvalidEntity(manager, entity("foo", "bar"));
// Null type
assertInvalidEntity(manager, entity(null, "null"));
// Valid + unknown combo
assertInvalidEntity(manager, entity(ClientQuotaEntity.USER, "user-1", "foo", "bar"));
assertInvalidEntity(manager, entity("foo", "bar", ClientQuotaEntity.IP, "1.2.3.4"));
// Invalid combinations
assertInvalidEntity(manager, entity(ClientQuotaEntity.USER, "user-1", ClientQuotaEntity.IP, "1.2.3.4"));
assertInvalidEntity(manager, entity(ClientQuotaEntity.CLIENT_ID, "user-1", ClientQuotaEntity.IP, "1.2.3.4"));
// Empty
assertInvalidEntity(manager, new ClientQuotaEntity(Collections.emptyMap()));
}
Aggregations