Search in sources :

Example 11 with ApiException

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;
}
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 ApiException

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;
}
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 ApiException

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;
}
Also used : HashMap(java.util.HashMap) MetricConfig(org.apache.kafka.common.metrics.MetricConfig) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) ArrayList(java.util.ArrayList) AlterConfigsRequest(org.apache.kafka.common.requests.AlterConfigsRequest) AlterConfigsResponse(org.apache.kafka.common.requests.AlterConfigsResponse) AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) ConfigResource(org.apache.kafka.common.config.ConfigResource) Resource(org.apache.kafka.common.requests.Resource) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) ConfigResource(org.apache.kafka.common.config.ConfigResource) ApiException(org.apache.kafka.common.errors.ApiException)

Example 14 with ApiException

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

Example 15 with ApiException

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);
}
Also used : Uuid(org.apache.kafka.common.Uuid) TimelineHashMap(org.apache.kafka.timeline.TimelineHashMap) HashMap(java.util.HashMap) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ArrayList(java.util.ArrayList) ApiError(org.apache.kafka.common.requests.ApiError) InvalidReplicationFactorException(org.apache.kafka.common.errors.InvalidReplicationFactorException) NoReassignmentInProgressException(org.apache.kafka.common.errors.NoReassignmentInProgressException) InvalidTopicException(org.apache.kafka.common.errors.InvalidTopicException) InvalidPartitionsException(org.apache.kafka.common.errors.InvalidPartitionsException) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) UnknownTopicIdException(org.apache.kafka.common.errors.UnknownTopicIdException) BrokerIdNotRegisteredException(org.apache.kafka.common.errors.BrokerIdNotRegisteredException) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) PolicyViolationException(org.apache.kafka.common.errors.PolicyViolationException) NoSuchElementException(java.util.NoSuchElementException) InvalidReplicaAssignmentException(org.apache.kafka.common.errors.InvalidReplicaAssignmentException) InvalidRequestException(org.apache.kafka.common.errors.InvalidRequestException) ApiException(org.apache.kafka.common.errors.ApiException) ApiException(org.apache.kafka.common.errors.ApiException)

Aggregations

ApiException (org.apache.kafka.common.errors.ApiException)19 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 InvalidTopicException (org.apache.kafka.common.errors.InvalidTopicException)8 UnknownServerException (org.apache.kafka.common.errors.UnknownServerException)8 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)7 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)7 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)7 Map (java.util.Map)6 ApiError (org.apache.kafka.common.requests.ApiError)6 ConfigResource (org.apache.kafka.common.config.ConfigResource)5 InvalidRequestException (org.apache.kafka.common.errors.InvalidRequestException)4 UnknownTopicOrPartitionException (org.apache.kafka.common.errors.UnknownTopicOrPartitionException)4 Errors (org.apache.kafka.common.protocol.Errors)4 Cluster (org.apache.kafka.common.Cluster)3 KafkaException (org.apache.kafka.common.KafkaException)3 KafkaFuture (org.apache.kafka.common.KafkaFuture)3 TopicPartition (org.apache.kafka.common.TopicPartition)3 ConfigException (org.apache.kafka.common.config.ConfigException)3 AuthenticationException (org.apache.kafka.common.errors.AuthenticationException)3