use of org.apache.kafka.common.errors.ApiException in project kafka by apache.
the class ClusterMetadataAuthorizer method deleteAcls.
/**
* Delete ACLs based on filters. This function must be called on the active
* controller, or else the futures will fail with NOT_CONTROLLER.
*
* @param requestContext The request context.
* @param filters The ACL filters.
*
* @return a list of futures, one per input acl filter. Each future will be completed
* once the relevant deleteAcls have been called on the controller (if any), and th
* ACL deletions have been persisted to the cluster metadata log (if any).
*/
default List<? extends CompletionStage<AclDeleteResult>> deleteAcls(AuthorizableRequestContext requestContext, List<AclBindingFilter> filters) {
List<CompletableFuture<AclDeleteResult>> futures = new ArrayList<>(filters.size());
AclMutator aclMutator = aclMutatorOrException();
filters.forEach(b -> futures.add(new CompletableFuture<>()));
aclMutator.deleteAcls(filters).whenComplete((results, throwable) -> {
if (throwable == null && results.size() != futures.size()) {
throwable = new UnknownServerException("Invalid size " + "of result set from controller. Expected " + futures.size() + "; got " + results.size());
}
if (throwable == null) {
for (int i = 0; i < futures.size(); i++) {
futures.get(i).complete(results.get(i));
}
} else {
for (CompletableFuture<AclDeleteResult> future : futures) {
ApiException e = (throwable instanceof ApiException) ? (ApiException) throwable : ApiError.fromThrowable(throwable).exception();
future.complete(new AclDeleteResult(e));
}
}
});
return futures;
}
use of org.apache.kafka.common.errors.ApiException in project kafka by apache.
the class ClusterMetadataAuthorizer method createAcls.
/**
* Create ACLs. This function must be called on the active controller, or else
* the futures will fail with NOT_CONTROLLER.
*
* @param requestContext The request context.
* @param aclBindings The ACL bindings to create.
*
* @return a list of futures, one per input acl binding. Each future will be completed
* once addAcl has been called on the controller, and the ACL has been persisted to
* the cluster metadata log.
*/
default List<? extends CompletionStage<AclCreateResult>> createAcls(AuthorizableRequestContext requestContext, List<AclBinding> aclBindings) {
List<CompletableFuture<AclCreateResult>> futures = new ArrayList<>(aclBindings.size());
AclMutator aclMutator = aclMutatorOrException();
aclBindings.forEach(b -> futures.add(new CompletableFuture<>()));
aclMutator.createAcls(aclBindings).whenComplete((results, throwable) -> {
if (throwable == null && results.size() != futures.size()) {
throwable = new UnknownServerException("Invalid size " + "of result set from controller. Expected " + futures.size() + "; got " + results.size());
}
if (throwable == null) {
for (int i = 0; i < futures.size(); i++) {
futures.get(i).complete(results.get(i));
}
} else {
for (CompletableFuture<AclCreateResult> future : futures) {
ApiException e = (throwable instanceof ApiException) ? (ApiException) throwable : ApiError.fromThrowable(throwable).exception();
future.complete(new AclCreateResult(e));
}
}
});
return futures;
}
use of org.apache.kafka.common.errors.ApiException in project apache-kafka-on-k8s by banzaicloud.
the class KafkaAdminClient method alterConfigs.
private Map<ConfigResource, KafkaFutureImpl<Void>> alterConfigs(Map<ConfigResource, Config> configs, final AlterConfigsOptions options, Collection<ConfigResource> resources, NodeProvider nodeProvider) {
final Map<ConfigResource, KafkaFutureImpl<Void>> futures = new HashMap<>();
final Map<Resource, AlterConfigsRequest.Config> requestMap = new HashMap<>(resources.size());
for (ConfigResource resource : resources) {
List<AlterConfigsRequest.ConfigEntry> configEntries = new ArrayList<>();
for (ConfigEntry configEntry : configs.get(resource).entries()) configEntries.add(new AlterConfigsRequest.ConfigEntry(configEntry.name(), configEntry.value()));
requestMap.put(configResourceToResource(resource), new AlterConfigsRequest.Config(configEntries));
futures.put(resource, new KafkaFutureImpl<Void>());
}
final long now = time.milliseconds();
runnable.call(new Call("alterConfigs", calcDeadlineMs(now, options.timeoutMs()), nodeProvider) {
@Override
public AbstractRequest.Builder createRequest(int timeoutMs) {
return new AlterConfigsRequest.Builder(requestMap, options.shouldValidateOnly());
}
@Override
public void handleResponse(AbstractResponse abstractResponse) {
AlterConfigsResponse response = (AlterConfigsResponse) abstractResponse;
for (Map.Entry<ConfigResource, KafkaFutureImpl<Void>> entry : futures.entrySet()) {
KafkaFutureImpl<Void> future = entry.getValue();
ApiException exception = response.errors().get(configResourceToResource(entry.getKey())).exception();
if (exception != null) {
future.completeExceptionally(exception);
} else {
future.complete(null);
}
}
}
@Override
void handleFailure(Throwable throwable) {
completeAllExceptionally(futures.values(), throwable);
}
}, now);
return futures;
}
use of org.apache.kafka.common.errors.ApiException in project apache-kafka-on-k8s by banzaicloud.
the class ErrorsTest method testForExceptionDefault.
@Test
public void testForExceptionDefault() {
Errors error = Errors.forException(new ApiException());
assertEquals("forException should default to unknown", Errors.UNKNOWN_SERVER_ERROR, error);
}
use of org.apache.kafka.common.errors.ApiException in project kafka by apache.
the class ReplicationControlManager method deleteTopics.
ControllerResult<Map<Uuid, ApiError>> deleteTopics(Collection<Uuid> ids) {
Map<Uuid, ApiError> results = new HashMap<>(ids.size());
List<ApiMessageAndVersion> records = new ArrayList<>(ids.size());
for (Uuid id : ids) {
try {
deleteTopic(id, records);
results.put(id, ApiError.NONE);
} catch (ApiException e) {
results.put(id, ApiError.fromThrowable(e));
} catch (Exception e) {
log.error("Unexpected deleteTopics error for {}", id, e);
results.put(id, ApiError.fromThrowable(e));
}
}
return ControllerResult.atomicOf(records, results);
}
Aggregations