use of org.apache.kafka.common.errors.UnknownServerException 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.UnknownServerException 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.UnknownServerException in project kafka by apache.
the class KafkaStatusBackingStoreTest method putConnectorStateNonRetriableFailure.
@Test
public void putConnectorStateNonRetriableFailure() {
byte[] value = new byte[0];
when(converter.fromConnectData(eq(STATUS_TOPIC), any(Schema.class), any(Struct.class))).thenReturn(value);
doAnswer(invocation -> {
((Callback) invocation.getArgument(2)).onCompletion(null, new UnknownServerException());
return null;
}).when(kafkaBasedLog).send(eq("status-connector-conn"), eq(value), any(Callback.class));
// the error is logged and ignored
ConnectorStatus status = new ConnectorStatus(CONNECTOR, ConnectorStatus.State.RUNNING, WORKER_ID, 0);
store.put(status);
// state is not visible until read back from the log
assertNull(store.get(CONNECTOR));
}
use of org.apache.kafka.common.errors.UnknownServerException in project kafka by apache.
the class QuorumController method scheduleDeferredWriteEvent.
private <T> void scheduleDeferredWriteEvent(String name, long deadlineNs, ControllerWriteOperation<T> op) {
ControllerWriteEvent<T> event = new ControllerWriteEvent<>(name, op);
queue.scheduleDeferred(name, new EarliestDeadlineFunction(deadlineNs), event);
event.future.exceptionally(e -> {
if (e instanceof UnknownServerException && e.getCause() != null && e.getCause() instanceof RejectedExecutionException) {
log.error("Cancelling deferred write event {} because the event queue " + "is now closed.", name);
return null;
} else if (e instanceof NotControllerException) {
log.debug("Cancelling deferred write event {} because this controller " + "is no longer active.", name);
return null;
}
log.error("Unexpected exception while executing deferred write event {}. " + "Rescheduling for a minute from now.", name, e);
scheduleDeferredWriteEvent(name, deadlineNs + NANOSECONDS.convert(1, TimeUnit.MINUTES), op);
return null;
});
}
use of org.apache.kafka.common.errors.UnknownServerException in project kafka by apache.
the class RequestResponseTest method checkOlderFetchVersions.
private void checkOlderFetchVersions() throws Exception {
int latestVersion = ApiKeys.FETCH.latestVersion();
for (int i = 0; i < latestVersion; ++i) {
checkErrorResponse(createFetchRequest(i), new UnknownServerException());
checkRequest(createFetchRequest(i));
}
}
Aggregations