Search in sources :

Example 11 with UnknownServerException

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) AclDeleteResult(org.apache.kafka.server.authorizer.AclDeleteResult) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) ApiException(org.apache.kafka.common.errors.ApiException)

Example 12 with UnknownServerException

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) AclCreateResult(org.apache.kafka.server.authorizer.AclCreateResult) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) ApiException(org.apache.kafka.common.errors.ApiException)

Example 13 with UnknownServerException

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));
}
Also used : Callback(org.apache.kafka.clients.producer.Callback) Schema(org.apache.kafka.connect.data.Schema) ConnectorStatus(org.apache.kafka.connect.runtime.ConnectorStatus) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) Struct(org.apache.kafka.connect.data.Struct) Test(org.junit.Test)

Example 14 with UnknownServerException

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;
    });
}
Also used : EarliestDeadlineFunction(org.apache.kafka.queue.EventQueue.EarliestDeadlineFunction) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) NotControllerException(org.apache.kafka.common.errors.NotControllerException)

Example 15 with UnknownServerException

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));
    }
}
Also used : UnknownServerException(org.apache.kafka.common.errors.UnknownServerException)

Aggregations

UnknownServerException (org.apache.kafka.common.errors.UnknownServerException)28 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)7 List (java.util.List)7 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)7 Test (org.junit.jupiter.api.Test)7 LinkedList (java.util.LinkedList)6 TopicPartition (org.apache.kafka.common.TopicPartition)6 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)5 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)5 Iterator (java.util.Iterator)4 KafkaFuture (org.apache.kafka.common.KafkaFuture)4 AclBinding (org.apache.kafka.common.acl.AclBinding)4 ApiException (org.apache.kafka.common.errors.ApiException)4 Test (org.junit.Test)4 Map (java.util.Map)3 Callback (org.apache.kafka.clients.producer.Callback)3 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2