forked from apache/kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KAFKA-16720] AdminClient Support for ListShareGroupOffsets (1/n) (ap…
…ache#18571) Reviewers: Apoorv Mittal <apoorvmittal10@gmail.com>, Andrew Schofield <aschofield@confluent.io>
- Loading branch information
1 parent
9649902
commit bcbc72e
Showing
27 changed files
with
2,422 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
clients/src/main/java/org/apache/kafka/clients/admin/ListShareGroupOffsetsOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.kafka.clients.admin; | ||
|
||
import org.apache.kafka.common.annotation.InterfaceStability; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Options for {@link Admin#listShareGroupOffsets(Map, ListShareGroupOffsetsOptions)}. | ||
* <p> | ||
* The API of this class is evolving, see {@link Admin} for details. | ||
*/ | ||
@InterfaceStability.Evolving | ||
public class ListShareGroupOffsetsOptions extends AbstractOptions<ListShareGroupOffsetsOptions> { | ||
} |
77 changes: 77 additions & 0 deletions
77
clients/src/main/java/org/apache/kafka/clients/admin/ListShareGroupOffsetsResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.kafka.clients.admin; | ||
|
||
import org.apache.kafka.clients.admin.internals.CoordinatorKey; | ||
import org.apache.kafka.common.KafkaFuture; | ||
import org.apache.kafka.common.TopicPartition; | ||
import org.apache.kafka.common.annotation.InterfaceStability; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* The result of the {@link Admin#listShareGroupOffsets(Map, ListShareGroupOffsetsOptions)} call. | ||
* <p> | ||
* The API of this class is evolving, see {@link Admin} for details. | ||
*/ | ||
@InterfaceStability.Evolving | ||
public class ListShareGroupOffsetsResult { | ||
|
||
private final Map<String, KafkaFuture<Map<TopicPartition, Long>>> futures; | ||
|
||
ListShareGroupOffsetsResult(final Map<CoordinatorKey, KafkaFuture<Map<TopicPartition, Long>>> futures) { | ||
this.futures = futures.entrySet().stream() | ||
.collect(Collectors.toMap(e -> e.getKey().idValue, Map.Entry::getValue)); | ||
} | ||
|
||
/** | ||
* Return the future when the requests for all groups succeed. | ||
* | ||
* @return - Future which yields all Map<String, Map<TopicPartition, Long> objects, if requests for all the groups succeed. | ||
*/ | ||
public KafkaFuture<Map<String, Map<TopicPartition, Long>>> all() { | ||
return KafkaFuture.allOf(futures.values().toArray(new KafkaFuture[0])).thenApply( | ||
nil -> { | ||
Map<String, Map<TopicPartition, Long>> offsets = new HashMap<>(futures.size()); | ||
futures.forEach((groupId, future) -> { | ||
try { | ||
offsets.put(groupId, future.get()); | ||
} catch (InterruptedException | ExecutionException e) { | ||
// This should be unreachable, since the KafkaFuture#allOf already ensured | ||
// that all the futures completed successfully. | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
return offsets; | ||
}); | ||
} | ||
|
||
/** | ||
* @param groupId - The groupId for which the Map<TopicPartition, Long> is needed | ||
* @return - Future which yields a map of topic partitions to offsets for the specified group. | ||
*/ | ||
public KafkaFuture<Map<TopicPartition, Long>> partitionsToOffset(String groupId) { | ||
if (!futures.containsKey(groupId)) { | ||
throw new IllegalArgumentException("Group ID not found: " + groupId); | ||
} | ||
return futures.get(groupId); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
clients/src/main/java/org/apache/kafka/clients/admin/ListShareGroupOffsetsSpec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.kafka.clients.admin; | ||
|
||
import org.apache.kafka.common.TopicPartition; | ||
import org.apache.kafka.common.annotation.InterfaceStability; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Specification of share group offsets to list using {@link Admin#listShareGroupOffsets(Map, ListShareGroupOffsetsOptions)}. | ||
* <p> | ||
* The API of this class is evolving, see {@link Admin} for details. | ||
*/ | ||
@InterfaceStability.Evolving | ||
public class ListShareGroupOffsetsSpec { | ||
|
||
private Collection<TopicPartition> topicPartitions; | ||
|
||
/** | ||
* Set the topic partitions whose offsets are to be listed for a share group. | ||
*/ | ||
public ListShareGroupOffsetsSpec topicPartitions(Collection<TopicPartition> topicPartitions) { | ||
this.topicPartitions = topicPartitions; | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns the topic partitions whose offsets are to be listed for a share group. | ||
*/ | ||
public Collection<TopicPartition> topicPartitions() { | ||
return topicPartitions == null ? List.of() : topicPartitions; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof ListShareGroupOffsetsSpec)) { | ||
return false; | ||
} | ||
ListShareGroupOffsetsSpec that = (ListShareGroupOffsetsSpec) o; | ||
return Objects.equals(topicPartitions, that.topicPartitions); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(topicPartitions); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ListShareGroupOffsetsSpec(" + | ||
"topicPartitions=" + (topicPartitions != null ? topicPartitions : "null") + | ||
')'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.