Search in sources :

Example 1 with DeletableTopicResult

use of org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResult in project kafka by apache.

the class KafkaAdminClient method getDeleteTopicsCall.

private Call getDeleteTopicsCall(final DeleteTopicsOptions options, final Map<String, KafkaFutureImpl<Void>> futures, final List<String> topics, final Map<String, ThrottlingQuotaExceededException> quotaExceededExceptions, final long now, final long deadline) {
    return new Call("deleteTopics", deadline, new ControllerNodeProvider()) {

        @Override
        DeleteTopicsRequest.Builder createRequest(int timeoutMs) {
            return new DeleteTopicsRequest.Builder(new DeleteTopicsRequestData().setTopicNames(topics).setTimeoutMs(timeoutMs));
        }

        @Override
        void handleResponse(AbstractResponse abstractResponse) {
            // Check for controller change
            handleNotControllerError(abstractResponse);
            // Handle server responses for particular topics.
            final DeleteTopicsResponse response = (DeleteTopicsResponse) abstractResponse;
            final List<String> retryTopics = new ArrayList<>();
            final Map<String, ThrottlingQuotaExceededException> retryTopicQuotaExceededExceptions = new HashMap<>();
            for (DeletableTopicResult result : response.data().responses()) {
                KafkaFutureImpl<Void> future = futures.get(result.name());
                if (future == null) {
                    log.warn("Server response mentioned unknown topic {}", result.name());
                } else {
                    ApiError error = new ApiError(result.errorCode(), result.errorMessage());
                    if (error.isFailure()) {
                        if (error.is(Errors.THROTTLING_QUOTA_EXCEEDED)) {
                            ThrottlingQuotaExceededException quotaExceededException = new ThrottlingQuotaExceededException(response.throttleTimeMs(), error.messageWithFallback());
                            if (options.shouldRetryOnQuotaViolation()) {
                                retryTopics.add(result.name());
                                retryTopicQuotaExceededExceptions.put(result.name(), quotaExceededException);
                            } else {
                                future.completeExceptionally(quotaExceededException);
                            }
                        } else {
                            future.completeExceptionally(error.exception());
                        }
                    } else {
                        future.complete(null);
                    }
                }
            }
            // If there are topics to retry, retry them; complete unrealized futures otherwise.
            if (retryTopics.isEmpty()) {
                // The server should send back a response for every topic. But do a sanity check anyway.
                completeUnrealizedFutures(futures.entrySet().stream(), topic -> "The controller response did not contain a result for topic " + topic);
            } else {
                final long now = time.milliseconds();
                final Call call = getDeleteTopicsCall(options, futures, retryTopics, retryTopicQuotaExceededExceptions, now, deadline);
                runnable.call(call, now);
            }
        }

        @Override
        void handleFailure(Throwable throwable) {
            // If there were any topics retries due to a quota exceeded exception, we propagate
            // the initial error back to the caller if the request timed out.
            maybeCompleteQuotaExceededException(options.shouldRetryOnQuotaViolation(), throwable, futures, quotaExceededExceptions, (int) (time.milliseconds() - now));
            // Fail all the other remaining futures
            completeAllExceptionally(futures.values(), throwable);
        }
    };
}
Also used : AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) HashMap(java.util.HashMap) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) DeleteTopicsRequestData(org.apache.kafka.common.message.DeleteTopicsRequestData) ArrayList(java.util.ArrayList) DeleteTopicsRequest(org.apache.kafka.common.requests.DeleteTopicsRequest) ThrottlingQuotaExceededException(org.apache.kafka.common.errors.ThrottlingQuotaExceededException) DeleteTopicsResponse(org.apache.kafka.common.requests.DeleteTopicsResponse) DeletableTopicResult(org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResult) ApiError(org.apache.kafka.common.requests.ApiError)

Example 2 with DeletableTopicResult

use of org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResult in project kafka by apache.

the class RequestResponseTest method testDeletableTopicResultErrorMessageIsNullByDefault.

@Test
public void testDeletableTopicResultErrorMessageIsNullByDefault() {
    DeletableTopicResult result = new DeletableTopicResult().setName("topic").setErrorCode(Errors.THROTTLING_QUOTA_EXCEEDED.code());
    assertEquals("topic", result.name());
    assertEquals(Errors.THROTTLING_QUOTA_EXCEEDED.code(), result.errorCode());
    assertNull(result.errorMessage());
}
Also used : DeletableTopicResult(org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResult) Test(org.junit.jupiter.api.Test)

Example 3 with DeletableTopicResult

use of org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResult in project kafka by apache.

the class DeleteTopicsRequest method getErrorResponse.

@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    DeleteTopicsResponseData response = new DeleteTopicsResponseData();
    if (version() >= 1) {
        response.setThrottleTimeMs(throttleTimeMs);
    }
    ApiError apiError = ApiError.fromThrowable(e);
    for (DeleteTopicState topic : topics()) {
        response.responses().add(new DeletableTopicResult().setName(topic.name()).setTopicId(topic.topicId()).setErrorCode(apiError.error().code()));
    }
    return new DeleteTopicsResponse(response);
}
Also used : DeleteTopicsResponseData(org.apache.kafka.common.message.DeleteTopicsResponseData) DeleteTopicState(org.apache.kafka.common.message.DeleteTopicsRequestData.DeleteTopicState) DeletableTopicResult(org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResult)

Example 4 with DeletableTopicResult

use of org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResult in project kafka by apache.

the class KafkaAdminClientTest method prepareDeleteTopicsResponseWithTopicId.

private static DeleteTopicsResponse prepareDeleteTopicsResponseWithTopicId(Uuid id, Errors error) {
    DeleteTopicsResponseData data = new DeleteTopicsResponseData();
    data.responses().add(new DeletableTopicResult().setTopicId(id).setErrorCode(error.code()));
    return new DeleteTopicsResponse(data);
}
Also used : DeleteTopicsResponse(org.apache.kafka.common.requests.DeleteTopicsResponse) DeleteTopicsResponseData(org.apache.kafka.common.message.DeleteTopicsResponseData) DeletableTopicResult(org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResult)

Example 5 with DeletableTopicResult

use of org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResult in project kafka by apache.

the class KafkaAdminClientTest method prepareDeleteTopicsResponse.

private static DeleteTopicsResponse prepareDeleteTopicsResponse(String topicName, Errors error) {
    DeleteTopicsResponseData data = new DeleteTopicsResponseData();
    data.responses().add(new DeletableTopicResult().setName(topicName).setErrorCode(error.code()));
    return new DeleteTopicsResponse(data);
}
Also used : DeleteTopicsResponse(org.apache.kafka.common.requests.DeleteTopicsResponse) DeleteTopicsResponseData(org.apache.kafka.common.message.DeleteTopicsResponseData) DeletableTopicResult(org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResult)

Aggregations

DeletableTopicResult (org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResult)7 DeleteTopicsResponseData (org.apache.kafka.common.message.DeleteTopicsResponseData)4 DeleteTopicsResponse (org.apache.kafka.common.requests.DeleteTopicsResponse)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ThrottlingQuotaExceededException (org.apache.kafka.common.errors.ThrottlingQuotaExceededException)2 DeleteTopicsRequestData (org.apache.kafka.common.message.DeleteTopicsRequestData)2 DeleteTopicState (org.apache.kafka.common.message.DeleteTopicsRequestData.DeleteTopicState)2 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)2 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)2 ApiError (org.apache.kafka.common.requests.ApiError)2 DeleteTopicsRequest (org.apache.kafka.common.requests.DeleteTopicsRequest)2 Uuid (org.apache.kafka.common.Uuid)1 Test (org.junit.jupiter.api.Test)1