Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LI-HOTFIX] Add list federated topic znodes rpc #493

Merged
merged 7 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,15 @@ default ListFederatedTopicZnodesResult listFederatedTopicZnodes() {
}

/**
* List federated topic znodes match given topic names
* List federated topic znodes match given topic names; if empty list passed, all existing federated topic znodes
* will be listed
* @param federatedTopics topic names
* @param options the options to use when list federated topic znodes
* @return empty list if the given topic names' znode don't exist; otherwise return the federated topics formatted
* /namespace/topic
*/
ListFederatedTopicZnodesResult listFederatedTopicZnodes(List<String> federatedTopics,
ListFederatedTopicZnodesOptions options);
ListFederatedTopicZnodesOptions options);

/**
* Describe some topics in the cluster, with the default options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@ void handleFailure(Throwable throwable) {

@Override
public ListFederatedTopicZnodesResult listFederatedTopicZnodes(List<String> federatedTopics,
ListFederatedTopicZnodesOptions options) {
ListFederatedTopicZnodesOptions options) {
final KafkaFutureImpl<List<String>> federatedTopicZnodesListingFuture = new KafkaFutureImpl<>();
List<LiListFederatedTopicZnodesRequestData.FederatedTopics> topicsRequested = new ArrayList<>();
federatedTopics.forEach(topic ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
{"name": "Name", "type": "string", "versions": "0+", "about": "The topic name"}
]}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
{ "name": "ThrottleTimeMs", "type": "int32", "versions": "0+", "ignorable": true,
"about": "The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota." }
]
}
}
29 changes: 20 additions & 9 deletions core/src/main/scala/kafka/server/KafkaApis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3820,26 +3820,37 @@ class KafkaApis(val requestChannel: RequestChannel,
val listfederatedTopicZnodesRequest = request.body[LiListFederatedTopicZnodesRequest]
val zkSupport = metadataSupport.requireZkOrThrow(KafkaApis.shouldNeverReceive(request))
val requestedTopics = listfederatedTopicZnodesRequest.data().topics()
val hasClusterAuthorization = authHelper.authorize(request.context, DESCRIBE, CLUSTER, CLUSTER_NAME)

try {
if (requestedTopics.isEmpty || requestedTopics.size() == 0) {
if (requestedTopics.isEmpty) {
// if empty list passed, list all existing federated topics
kehuum marked this conversation as resolved.
Show resolved Hide resolved
val allFederatedTopicZnodes = zkSupport.zkClient.getAllFederatedTopics.toList.asJava

requestHelper.sendResponseMaybeThrottle(request, requestThrottleMs =>
new LiListFederatedTopicZnodesResponse(
new LiListFederatedTopicZnodesResponseData().setTopics(allFederatedTopicZnodes)
.setThrottleTimeMs(requestThrottleMs), listfederatedTopicZnodesRequest.version()
// either return all federated topics or none, if cluster doesn't allow describe operation
if (hasClusterAuthorization) {
requestHelper.sendResponseMaybeThrottle(request, requestThrottleMs =>
new LiListFederatedTopicZnodesResponse(
new LiListFederatedTopicZnodesResponseData().setTopics(allFederatedTopicZnodes)
.setThrottleTimeMs(requestThrottleMs), listfederatedTopicZnodesRequest.version()
)
)
)
} else {
requestHelper.sendResponseExemptThrottle(request,
listfederatedTopicZnodesRequest.getErrorResponse(
new ClusterAuthorizationException("List all federated topic znodes operation not allowed"))
)
}
} else {
// if non-empty list passed, only list znode values for the given topics
val foundFederatedTopicZnodes = mutable.Set[String]()

requestedTopics.forEach(topic => {
val curFederatedTopicZnode = zkSupport.zkClient.getFederatedTopic(topic.name())
if (curFederatedTopicZnode != null) {
foundFederatedTopicZnodes.add(curFederatedTopicZnode)
if (hasClusterAuthorization || authHelper.authorize(request.context, DESCRIBE, TOPIC, topic.name())) {
lmr3796 marked this conversation as resolved.
Show resolved Hide resolved
val curFederatedTopicZnode = zkSupport.zkClient.getFederatedTopic(topic.name())
if (curFederatedTopicZnode != null) {
foundFederatedTopicZnodes.add(curFederatedTopicZnode)
}
}
})

Expand Down
Loading