Aias00 commented on code in PR #4508:
URL:
https://github.com/apache/rocketmq-dashboard/pull/4508#discussion_r4061729429
##########
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:
Verified against `server/pom.xml`: this module targets Java 21
(`<java.version>21</java.version>`), so `List.getFirst()` is supported. The
updated branch was compiled, packaged, and fully tested with JDK 21 (3077 tests
passed).
##########
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:
Retained the `collectAll()` / `collect()` separation. `collectAll()` now
also diagnoses real same-name physical conflicts, while `collect()` preserves
the existing name-deduplicated list contract.
--
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]