Skip to content

Commit dc7819d

Browse files
authored
KAFKA-14594: Move LogDirsCommand to tools module (#13122)
Reviewers: Mickael Maison <mickael.maison@gmail.com>
1 parent d46c3f2 commit dc7819d

File tree

7 files changed

+367
-211
lines changed

7 files changed

+367
-211
lines changed

bin/kafka-log-dirs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
exec $(dirname $0)/kafka-run-class.sh kafka.admin.LogDirsCommand "$@"
17+
exec $(dirname $0)/kafka-run-class.sh org.apache.kafka.tools.LogDirsCommand "$@"

bin/windows/kafka-log-dirs.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
rem See the License for the specific language governing permissions and
1515
rem limitations under the License.
1616

17-
"%~dp0kafka-run-class.bat" kafka.admin.LogDirsCommand %*
17+
"%~dp0kafka-run-class.bat" org.apache.kafka.tools.LogDirsCommand %*

clients/src/test/java/org/apache/kafka/clients/admin/MockAdminClient.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,37 @@ synchronized public AlterReplicaLogDirsResult alterReplicaLogDirs(
945945
@Override
946946
synchronized public DescribeLogDirsResult describeLogDirs(Collection<Integer> brokers,
947947
DescribeLogDirsOptions options) {
948-
throw new UnsupportedOperationException("Not implemented yet");
948+
Map<Integer, Map<String, LogDirDescription>> unwrappedResults = new HashMap<>();
949+
950+
for (Integer broker : brokers) {
951+
unwrappedResults.putIfAbsent(broker, new HashMap<>());
952+
}
953+
954+
for (Map.Entry<String, TopicMetadata> entry : allTopics.entrySet()) {
955+
String topicName = entry.getKey();
956+
TopicMetadata topicMetadata = entry.getValue();
957+
// For tests, we make the assumption that there will always be only 1 entry.
958+
List<String> partitionLogDirs = topicMetadata.partitionLogDirs;
959+
List<TopicPartitionInfo> topicPartitionInfos = topicMetadata.partitions;
960+
for (TopicPartitionInfo topicPartitionInfo : topicPartitionInfos) {
961+
List<Node> nodes = topicPartitionInfo.replicas();
962+
for (Node node : nodes) {
963+
Map<String, LogDirDescription> logDirDescriptionMap = unwrappedResults.get(node.id());
964+
LogDirDescription logDirDescription = logDirDescriptionMap.getOrDefault(partitionLogDirs.get(0), new LogDirDescription(null, new HashMap<>()));
965+
logDirDescription.replicaInfos().put(new TopicPartition(topicName, topicPartitionInfo.partition()), new ReplicaInfo(0, 0, false));
966+
}
967+
}
968+
}
969+
970+
Map<Integer, KafkaFuture<Map<String, LogDirDescription>>> results = new HashMap<>();
971+
972+
for (Map.Entry<Integer, Map<String, LogDirDescription>> entry : unwrappedResults.entrySet()) {
973+
KafkaFutureImpl<Map<String, LogDirDescription>> kafkaFuture = new KafkaFutureImpl<>();
974+
kafkaFuture.complete(entry.getValue());
975+
results.put(entry.getKey(), kafkaFuture);
976+
}
977+
978+
return new DescribeLogDirsResult(results);
949979
}
950980

951981
@Override

core/src/main/scala/kafka/admin/LogDirsCommand.scala

Lines changed: 0 additions & 132 deletions
This file was deleted.

core/src/test/scala/unit/kafka/admin/LogDirsCommandTest.scala

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)