|
|
|
@ -1077,19 +1077,33 @@ public class KafkaAdminClient extends AdminClient {
@@ -1077,19 +1077,33 @@ public class KafkaAdminClient extends AdminClient {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns true if a topic name cannot be represented in an RPC. This function does NOT check |
|
|
|
|
* whether the name is too long, contains invalid characters, etc. It is better to enforce |
|
|
|
|
* those policies on the server, so that they can be changed in the future if needed. |
|
|
|
|
*/ |
|
|
|
|
private static boolean topicNameIsUnrepresentable(String topicName) { |
|
|
|
|
return (topicName == null) || topicName.isEmpty(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public CreateTopicsResult createTopics(final Collection<NewTopic> newTopics, |
|
|
|
|
final CreateTopicsOptions options) { |
|
|
|
|
final Map<String, KafkaFutureImpl<Void>> topicFutures = new HashMap<>(newTopics.size()); |
|
|
|
|
final Map<String, CreateTopicsRequest.TopicDetails> topicsMap = new HashMap<>(newTopics.size()); |
|
|
|
|
for (NewTopic newTopic : newTopics) { |
|
|
|
|
if (topicFutures.get(newTopic.name()) == null) { |
|
|
|
|
if (topicNameIsUnrepresentable(newTopic.name())) { |
|
|
|
|
KafkaFutureImpl<Void> future = new KafkaFutureImpl<>(); |
|
|
|
|
future.completeExceptionally(new InvalidTopicException("The given topic name '" + |
|
|
|
|
newTopic.name() + "' cannot be represented in a request.")); |
|
|
|
|
topicFutures.put(newTopic.name(), future); |
|
|
|
|
} else if (!topicFutures.containsKey(newTopic.name())) { |
|
|
|
|
topicFutures.put(newTopic.name(), new KafkaFutureImpl<Void>()); |
|
|
|
|
topicsMap.put(newTopic.name(), newTopic.convertToTopicDetails()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
final long now = time.milliseconds(); |
|
|
|
|
runnable.call(new Call("createTopics", calcDeadlineMs(now, options.timeoutMs()), |
|
|
|
|
Call call = new Call("createTopics", calcDeadlineMs(now, options.timeoutMs()), |
|
|
|
|
new ControllerNodeProvider()) { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -1128,7 +1142,10 @@ public class KafkaAdminClient extends AdminClient {
@@ -1128,7 +1142,10 @@ public class KafkaAdminClient extends AdminClient {
|
|
|
|
|
void handleFailure(Throwable throwable) { |
|
|
|
|
completeAllExceptionally(topicFutures.values(), throwable); |
|
|
|
|
} |
|
|
|
|
}, now); |
|
|
|
|
}; |
|
|
|
|
if (!topicsMap.isEmpty()) { |
|
|
|
|
runnable.call(call, now); |
|
|
|
|
} |
|
|
|
|
return new CreateTopicsResult(new HashMap<String, KafkaFuture<Void>>(topicFutures)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1137,12 +1154,17 @@ public class KafkaAdminClient extends AdminClient {
@@ -1137,12 +1154,17 @@ public class KafkaAdminClient extends AdminClient {
|
|
|
|
|
DeleteTopicsOptions options) { |
|
|
|
|
final Map<String, KafkaFutureImpl<Void>> topicFutures = new HashMap<>(topicNames.size()); |
|
|
|
|
for (String topicName : topicNames) { |
|
|
|
|
if (topicFutures.get(topicName) == null) { |
|
|
|
|
if (topicNameIsUnrepresentable(topicName)) { |
|
|
|
|
KafkaFutureImpl<Void> future = new KafkaFutureImpl<>(); |
|
|
|
|
future.completeExceptionally(new InvalidTopicException("The given topic name '" + |
|
|
|
|
topicName + "' cannot be represented in a request.")); |
|
|
|
|
topicFutures.put(topicName, future); |
|
|
|
|
} else if (!topicFutures.containsKey(topicName)) { |
|
|
|
|
topicFutures.put(topicName, new KafkaFutureImpl<Void>()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
final long now = time.milliseconds(); |
|
|
|
|
runnable.call(new Call("deleteTopics", calcDeadlineMs(now, options.timeoutMs()), |
|
|
|
|
Call call = new Call("deleteTopics", calcDeadlineMs(now, options.timeoutMs()), |
|
|
|
|
new ControllerNodeProvider()) { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -1181,7 +1203,10 @@ public class KafkaAdminClient extends AdminClient {
@@ -1181,7 +1203,10 @@ public class KafkaAdminClient extends AdminClient {
|
|
|
|
|
void handleFailure(Throwable throwable) { |
|
|
|
|
completeAllExceptionally(topicFutures.values(), throwable); |
|
|
|
|
} |
|
|
|
|
}, now); |
|
|
|
|
}; |
|
|
|
|
if (!topicNames.isEmpty()) { |
|
|
|
|
runnable.call(call, now); |
|
|
|
|
} |
|
|
|
|
return new DeleteTopicsResult(new HashMap<String, KafkaFuture<Void>>(topicFutures)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1223,13 +1248,18 @@ public class KafkaAdminClient extends AdminClient {
@@ -1223,13 +1248,18 @@ public class KafkaAdminClient extends AdminClient {
|
|
|
|
|
final Map<String, KafkaFutureImpl<TopicDescription>> topicFutures = new HashMap<>(topicNames.size()); |
|
|
|
|
final ArrayList<String> topicNamesList = new ArrayList<>(); |
|
|
|
|
for (String topicName : topicNames) { |
|
|
|
|
if (!topicFutures.containsKey(topicName)) { |
|
|
|
|
if (topicNameIsUnrepresentable(topicName)) { |
|
|
|
|
KafkaFutureImpl<TopicDescription> future = new KafkaFutureImpl<TopicDescription>(); |
|
|
|
|
future.completeExceptionally(new InvalidTopicException("The given topic name '" + |
|
|
|
|
topicName + "' cannot be represented in a request.")); |
|
|
|
|
topicFutures.put(topicName, future); |
|
|
|
|
} else if (!topicFutures.containsKey(topicName)) { |
|
|
|
|
topicFutures.put(topicName, new KafkaFutureImpl<TopicDescription>()); |
|
|
|
|
topicNamesList.add(topicName); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
final long now = time.milliseconds(); |
|
|
|
|
runnable.call(new Call("describeTopics", calcDeadlineMs(now, options.timeoutMs()), |
|
|
|
|
Call call = new Call("describeTopics", calcDeadlineMs(now, options.timeoutMs()), |
|
|
|
|
new ControllerNodeProvider()) { |
|
|
|
|
|
|
|
|
|
private boolean supportsDisablingTopicCreation = true; |
|
|
|
@ -1298,7 +1328,10 @@ public class KafkaAdminClient extends AdminClient {
@@ -1298,7 +1328,10 @@ public class KafkaAdminClient extends AdminClient {
|
|
|
|
|
void handleFailure(Throwable throwable) { |
|
|
|
|
completeAllExceptionally(topicFutures.values(), throwable); |
|
|
|
|
} |
|
|
|
|
}, now); |
|
|
|
|
}; |
|
|
|
|
if (!topicNamesList.isEmpty()) { |
|
|
|
|
runnable.call(call, now); |
|
|
|
|
} |
|
|
|
|
return new DescribeTopicsResult(new HashMap<String, KafkaFuture<TopicDescription>>(topicFutures)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|