Rancho-7 commented on code in PR #20301: URL: https://github.com/apache/kafka/pull/20301#discussion_r2298566652
########## tools/src/main/java/org/apache/kafka/tools/EndToEndLatency.java: ########## @@ -221,4 +290,173 @@ private static KafkaProducer<byte[], byte[]> createKafkaProducer(Optional<String producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); return new KafkaProducer<>(producerProps); } + + /** + * Converts legacy positional arguments to named arguments for backward compatibility. + * + * @param args the command line arguments to convert + * @return converted named arguments + * @throws Exception if the legacy arguments are invalid + * @deprecated Positional argument usage is deprecated and will be removed in Apache Kafka 5.0. + * Use named arguments instead: --bootstrap-server, --topic, --num-records, --producer-acks, --record-size, --command-config + */ + @Deprecated(since = "4.2", forRemoval = true) + static String[] convertLegacyArgsIfNeeded(String[] args) throws Exception { + if (args.length == 0) { + return args; + } + + boolean hasRequiredNamedArgs = Arrays.stream(args).anyMatch(arg -> + arg.equals("--bootstrap-server") || + arg.equals("--topic") || + arg.equals("--num-records") || + arg.equals("--producer-acks") || + arg.equals("--record-size")); + if (hasRequiredNamedArgs) { + return args; + } + + if (args.length != 5 && args.length != 6) { + throw new TerseException("Invalid number of arguments. Expected 5 or 6 positional arguments, but got " + args.length + ". " + + "Usage: bootstrap-server topic num-records producer-acks record-size [optional] command-config"); + } + + return convertLegacyArgs(args); + } + + private static String[] convertLegacyArgs(String[] legacyArgs) { + List<String> newArgs = new ArrayList<>(); + + // broker_list -> --bootstrap-server + newArgs.add("--bootstrap-server"); + newArgs.add(legacyArgs[0]); + + // topic -> --topic + newArgs.add("--topic"); + newArgs.add(legacyArgs[1]); + + // num_messages -> --num-records + newArgs.add("--num-records"); + newArgs.add(legacyArgs[2]); + + // producer_acks -> --producer-acks + newArgs.add("--producer-acks"); + newArgs.add(legacyArgs[3]); + + // message_size_bytes -> --record-size + newArgs.add("--record-size"); + newArgs.add(legacyArgs[4]); + + // properties_file -> --command-config + if (legacyArgs.length == 6 && !legacyArgs[5].trim().isEmpty()) { Review Comment: Will remove it, thanks! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org