use of io.strimzi.api.kafka.model.KafkaUserQuotas in project strimzi by strimzi.
the class QuotasOperatorIT method getModified.
@Override
KafkaUserQuotas getModified() {
KafkaUserQuotas quotas = new KafkaUserQuotas();
quotas.setProducerByteRate(2 * 1024 * 1024);
quotas.setConsumerByteRate(5 * 1024 * 1024);
quotas.setRequestPercentage(10);
return quotas;
}
use of io.strimzi.api.kafka.model.KafkaUserQuotas in project strimzi-kafka-operator by strimzi.
the class UserST method alterBigAmountOfUsers.
synchronized void alterBigAmountOfUsers(ExtensionContext extensionContext, String userName, String typeOfUser, int numberOfUsers, int producerRate, int consumerRate, int requestsPercentage, double mutationRate) {
KafkaUserQuotas kuq = new KafkaUserQuotas();
kuq.setConsumerByteRate(consumerRate);
kuq.setProducerByteRate(producerRate);
kuq.setRequestPercentage(requestsPercentage);
kuq.setControllerMutationRate(mutationRate);
LOGGER.info("Updating of existing KafkaUsers");
for (int i = 0; i < numberOfUsers; i++) {
String userNameWithSuffix = userName + "-" + i;
if (typeOfUser.equals("TLS")) {
resourceManager.createResource(extensionContext, KafkaUserTemplates.tlsUser(userClusterName, userNameWithSuffix).editMetadata().withNamespace(namespace).endMetadata().editSpec().withQuotas(kuq).endSpec().build());
} else {
resourceManager.createResource(extensionContext, KafkaUserTemplates.scramShaUser(userClusterName, userNameWithSuffix).editMetadata().withNamespace(namespace).endMetadata().editSpec().withQuotas(kuq).endSpec().build());
}
LOGGER.info("[After update] Checking status of KafkaUser {}", userNameWithSuffix);
Condition kafkaCondition = KafkaUserResource.kafkaUserClient().inNamespace(namespace).withName(userNameWithSuffix).get().getStatus().getConditions().get(0);
LOGGER.debug("KafkaUser condition status: {}", kafkaCondition.getStatus());
LOGGER.debug("KafkaUser condition type: {}", kafkaCondition.getType());
assertThat(kafkaCondition.getType(), is(Ready.toString()));
LOGGER.debug("KafkaUser {} is in desired state: {}", userNameWithSuffix, kafkaCondition.getType());
KafkaUserQuotas kuqAfter = KafkaUserResource.kafkaUserClient().inNamespace(namespace).withName(userNameWithSuffix).get().getSpec().getQuotas();
LOGGER.debug("Check altered KafkaUser {} new quotas.", userNameWithSuffix);
assertThat(kuqAfter.getRequestPercentage(), is(requestsPercentage));
assertThat(kuqAfter.getConsumerByteRate(), is(consumerRate));
assertThat(kuqAfter.getProducerByteRate(), is(producerRate));
assertThat(kuqAfter.getControllerMutationRate(), is(mutationRate));
}
}
use of io.strimzi.api.kafka.model.KafkaUserQuotas in project strimzi-kafka-operator by strimzi.
the class KafkaUserOperator method reconcileCredentialsQuotasAndAcls.
/**
* Reconciles the credentials, quotas and ACLs
*
* @param reconciliation Unique identification for the reconciliation
* @param user Model describing the KafkaUser
* @param userStatus Status subresource of the KafkaUser custom resource
*
* @return Future describing the result
*/
private CompositeFuture reconcileCredentialsQuotasAndAcls(Reconciliation reconciliation, KafkaUserModel user, KafkaUserStatus userStatus) {
Set<SimpleAclRule> tlsAcls = null;
Set<SimpleAclRule> scramOrNoneAcls = null;
KafkaUserQuotas tlsQuotas = null;
KafkaUserQuotas scramOrNoneQuotas = null;
if (user.isTlsUser() || user.isTlsExternalUser()) {
tlsAcls = user.getSimpleAclRules();
tlsQuotas = user.getQuotas();
} else if (user.isScramUser() || user.isNoneUser()) {
scramOrNoneAcls = user.getSimpleAclRules();
scramOrNoneQuotas = user.getQuotas();
}
// Reconcile the user SCRAM-SHA-512 credentials
Future<ReconcileResult<String>> scramCredentialsFuture = scramCredentialsOperator.reconcile(reconciliation, user.getName(), user.getScramSha512Password());
// Quotas need to reconciled for both regular and TLS username. It will be (possibly) set for one user and deleted for the other
Future<ReconcileResult<KafkaUserQuotas>> tlsQuotasFuture = quotasOperator.reconcile(reconciliation, KafkaUserModel.getTlsUserName(reconciliation.name()), tlsQuotas);
Future<ReconcileResult<KafkaUserQuotas>> quotasFuture = quotasOperator.reconcile(reconciliation, KafkaUserModel.getScramUserName(reconciliation.name()), scramOrNoneQuotas);
// Reconcile the user secret generated by the user operator with the credentials
Future<ReconcileResult<Secret>> userSecretFuture = reconcileUserSecret(reconciliation, user, userStatus);
// ACLs need to reconciled for both regular and TLS username. It will be (possibly) set for one user and deleted for the other
Future<ReconcileResult<Set<SimpleAclRule>>> aclsTlsUserFuture;
Future<ReconcileResult<Set<SimpleAclRule>>> aclsScramUserFuture;
if (config.isAclsAdminApiSupported()) {
aclsTlsUserFuture = aclOperations.reconcile(reconciliation, KafkaUserModel.getTlsUserName(reconciliation.name()), tlsAcls);
aclsScramUserFuture = aclOperations.reconcile(reconciliation, KafkaUserModel.getScramUserName(reconciliation.name()), scramOrNoneAcls);
} else {
aclsTlsUserFuture = Future.succeededFuture(ReconcileResult.noop(null));
aclsScramUserFuture = Future.succeededFuture(ReconcileResult.noop(null));
}
return CompositeFuture.join(scramCredentialsFuture, tlsQuotasFuture, quotasFuture, aclsTlsUserFuture, aclsScramUserFuture, userSecretFuture);
}
use of io.strimzi.api.kafka.model.KafkaUserQuotas in project strimzi-kafka-operator by strimzi.
the class QuotasOperator method getAsync.
/**
* Retrieves the quotas for the given user.
*
* @param reconciliation The reconciliation
* @param username Name of the user
*
* @return the Future with reconcile result
*/
protected Future<KafkaUserQuotas> getAsync(Reconciliation reconciliation, String username) {
ClientQuotaFilterComponent c = ClientQuotaFilterComponent.ofEntity(ClientQuotaEntity.USER, username);
ClientQuotaFilter f = ClientQuotaFilter.contains(List.of(c));
return Util.kafkaFutureToVertxFuture(reconciliation, vertx, adminClient.describeClientQuotas(f).entities()).compose(quotas -> {
ClientQuotaEntity cqe = new ClientQuotaEntity(Map.of(ClientQuotaEntity.USER, username));
KafkaUserQuotas current = null;
if (quotas.containsKey(cqe)) {
current = QuotaUtils.fromClientQuota(quotas.get(cqe));
}
return Future.succeededFuture(current);
});
}
use of io.strimzi.api.kafka.model.KafkaUserQuotas in project strimzi-kafka-operator by strimzi.
the class QuotasOperatorIT method getModified.
@Override
KafkaUserQuotas getModified() {
KafkaUserQuotas quotas = new KafkaUserQuotas();
quotas.setProducerByteRate(2 * 1024 * 1024);
quotas.setConsumerByteRate(5 * 1024 * 1024);
quotas.setRequestPercentage(10);
return quotas;
}
Aggregations