use of org.apache.kafka.common.errors.InvalidTopicException in project kafka by apache.
the class KafkaAdminClient method handleDeleteTopicsUsingIds.
private Map<Uuid, KafkaFuture<Void>> handleDeleteTopicsUsingIds(final Collection<Uuid> topicIds, final DeleteTopicsOptions options) {
final Map<Uuid, KafkaFutureImpl<Void>> topicFutures = new HashMap<>(topicIds.size());
final List<Uuid> validTopicIds = new ArrayList<>(topicIds.size());
for (Uuid topicId : topicIds) {
if (topicId.equals(Uuid.ZERO_UUID)) {
KafkaFutureImpl<Void> future = new KafkaFutureImpl<>();
future.completeExceptionally(new InvalidTopicException("The given topic ID '" + topicId + "' cannot be represented in a request."));
topicFutures.put(topicId, future);
} else if (!topicFutures.containsKey(topicId)) {
topicFutures.put(topicId, new KafkaFutureImpl<>());
validTopicIds.add(topicId);
}
}
if (!validTopicIds.isEmpty()) {
final long now = time.milliseconds();
final long deadline = calcDeadlineMs(now, options.timeoutMs());
final Call call = getDeleteTopicsWithIdsCall(options, topicFutures, validTopicIds, Collections.emptyMap(), now, deadline);
runnable.call(call, now);
}
return new HashMap<>(topicFutures);
}
use of org.apache.kafka.common.errors.InvalidTopicException in project kafka by apache.
the class KafkaAdminClient method listPartitionReassignments.
@Override
public ListPartitionReassignmentsResult listPartitionReassignments(Optional<Set<TopicPartition>> partitions, ListPartitionReassignmentsOptions options) {
final KafkaFutureImpl<Map<TopicPartition, PartitionReassignment>> partitionReassignmentsFuture = new KafkaFutureImpl<>();
if (partitions.isPresent()) {
for (TopicPartition tp : partitions.get()) {
String topic = tp.topic();
int partition = tp.partition();
if (topicNameIsUnrepresentable(topic)) {
partitionReassignmentsFuture.completeExceptionally(new InvalidTopicException("The given topic name '" + topic + "' cannot be represented in a request."));
} else if (partition < 0) {
partitionReassignmentsFuture.completeExceptionally(new InvalidTopicException("The given partition index " + partition + " is not valid."));
}
if (partitionReassignmentsFuture.isCompletedExceptionally())
return new ListPartitionReassignmentsResult(partitionReassignmentsFuture);
}
}
final long now = time.milliseconds();
runnable.call(new Call("listPartitionReassignments", calcDeadlineMs(now, options.timeoutMs()), new ControllerNodeProvider()) {
@Override
ListPartitionReassignmentsRequest.Builder createRequest(int timeoutMs) {
ListPartitionReassignmentsRequestData listData = new ListPartitionReassignmentsRequestData();
listData.setTimeoutMs(timeoutMs);
if (partitions.isPresent()) {
Map<String, ListPartitionReassignmentsTopics> reassignmentTopicByTopicName = new HashMap<>();
for (TopicPartition tp : partitions.get()) {
if (!reassignmentTopicByTopicName.containsKey(tp.topic()))
reassignmentTopicByTopicName.put(tp.topic(), new ListPartitionReassignmentsTopics().setName(tp.topic()));
reassignmentTopicByTopicName.get(tp.topic()).partitionIndexes().add(tp.partition());
}
listData.setTopics(new ArrayList<>(reassignmentTopicByTopicName.values()));
}
return new ListPartitionReassignmentsRequest.Builder(listData);
}
@Override
void handleResponse(AbstractResponse abstractResponse) {
ListPartitionReassignmentsResponse response = (ListPartitionReassignmentsResponse) abstractResponse;
Errors error = Errors.forCode(response.data().errorCode());
switch(error) {
case NONE:
break;
case NOT_CONTROLLER:
handleNotControllerError(error);
break;
default:
partitionReassignmentsFuture.completeExceptionally(new ApiError(error, response.data().errorMessage()).exception());
break;
}
Map<TopicPartition, PartitionReassignment> reassignmentMap = new HashMap<>();
for (OngoingTopicReassignment topicReassignment : response.data().topics()) {
String topicName = topicReassignment.name();
for (OngoingPartitionReassignment partitionReassignment : topicReassignment.partitions()) {
reassignmentMap.put(new TopicPartition(topicName, partitionReassignment.partitionIndex()), new PartitionReassignment(partitionReassignment.replicas(), partitionReassignment.addingReplicas(), partitionReassignment.removingReplicas()));
}
}
partitionReassignmentsFuture.complete(reassignmentMap);
}
@Override
void handleFailure(Throwable throwable) {
partitionReassignmentsFuture.completeExceptionally(throwable);
}
}, now);
return new ListPartitionReassignmentsResult(partitionReassignmentsFuture);
}
use of org.apache.kafka.common.errors.InvalidTopicException in project kafka by apache.
the class DescribeProducersHandler method handlePartitionError.
private void handlePartitionError(TopicPartition topicPartition, ApiError apiError, Map<TopicPartition, Throwable> failed, List<TopicPartition> unmapped) {
switch(apiError.error()) {
case NOT_LEADER_OR_FOLLOWER:
if (options.brokerId().isPresent()) {
// Typically these errors are retriable, but if the user specified the brokerId
// explicitly, then they are fatal.
int brokerId = options.brokerId().getAsInt();
log.error("Not leader error in `DescribeProducers` response for partition {} " + "for brokerId {} set in options", topicPartition, brokerId, apiError.exception());
failed.put(topicPartition, apiError.error().exception("Failed to describe active producers " + "for partition " + topicPartition + " on brokerId " + brokerId));
} else {
// Otherwise, we unmap the partition so that we can find the new leader
log.debug("Not leader error in `DescribeProducers` response for partition {}. " + "Will retry later.", topicPartition);
unmapped.add(topicPartition);
}
break;
case UNKNOWN_TOPIC_OR_PARTITION:
log.debug("Unknown topic/partition error in `DescribeProducers` response for partition {}. " + "Will retry later.", topicPartition);
break;
case INVALID_TOPIC_EXCEPTION:
log.error("Invalid topic in `DescribeProducers` response for partition {}", topicPartition, apiError.exception());
failed.put(topicPartition, new InvalidTopicException("Failed to fetch metadata for partition " + topicPartition + " due to invalid topic error: " + apiError.messageWithFallback(), Collections.singleton(topicPartition.topic())));
break;
case TOPIC_AUTHORIZATION_FAILED:
log.error("Authorization failed in `DescribeProducers` response for partition {}", topicPartition, apiError.exception());
failed.put(topicPartition, new TopicAuthorizationException("Failed to describe " + "active producers for partition " + topicPartition + " due to authorization failure on topic" + " `" + topicPartition.topic() + "`", Collections.singleton(topicPartition.topic())));
break;
default:
log.error("Unexpected error in `DescribeProducers` response for partition {}", topicPartition, apiError.exception());
failed.put(topicPartition, apiError.error().exception("Failed to describe active " + "producers for partition " + topicPartition + " due to unexpected error"));
break;
}
}
Aggregations