RockteMQ-AI commented on code in PR #4508:
URL:
https://github.com/apache/rocketmq-dashboard/pull/4508#discussion_r4035810681
##########
server/src/main/java/org/apache/rocketmq/studio/ops/ai/tool/support/PlatformClusterResolver.java:
##########
@@ -143,16 +155,22 @@ public static List<String> splitEndpoints(String
endpoint) {
private List<ManagedCluster> collect(boolean withVersions) {
Map<String, ManagedCluster> unique = new LinkedHashMap<>();
+ collectAll(withVersions).forEach(cluster ->
unique.putIfAbsent(cluster.clusterName(), cluster));
Review Comment:
Clean separation: `collectAll()` for raw collection, `collect()` for
deduplication. Good refactoring.
##########
server/src/main/java/org/apache/rocketmq/studio/ops/ai/tool/support/PlatformClusterResolver.java:
##########
@@ -114,16 +114,28 @@ public List<ManagedCluster> scanWithBrokerVersions() {
return collect(true);
}
- /** First instance that manages the given physical cluster; 404 when no
instance owns it. */
+ /** Unique instance that manages the given physical cluster; 404 when no
instance owns it. */
public ManagedCluster require(String clusterName) {
if (!StringUtils.hasText(clusterName)) {
throw new BusinessException(400, "clusterName is required");
}
String normalized = clusterName.trim();
- return scan().stream()
+ List<ManagedCluster> matches = collectAll(false).stream()
.filter(cluster -> normalized.equals(cluster.clusterName()))
- .findFirst()
- .orElseThrow(() -> new BusinessException(404, "Cluster not
found: " + normalized));
+ .toList();
+ if (matches.isEmpty()) {
+ throw new BusinessException(404, "Cluster not found: " +
normalized);
+ }
+ if (matches.size() > 1) {
+ String instances = matches.stream()
+ .map(ManagedCluster::instanceId)
Review Comment:
`matches.getFirst()` requires Java 21+. Please verify the project's minimum
Java version. If targeting Java 17 or earlier, use `matches.get(0)` instead.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]