From 1e1817d027a62174b8977a1e7da245bcf1bf8284 Mon Sep 17 00:00:00 2001 From: Chao-Heng Lee Date: Fri, 19 May 2023 21:36:00 +0800 Subject: [PATCH 01/11] replace NodeInfo with Broker. tests are not included. --- .../java/org/astraea/app/backup/Backup.java | 2 +- .../astraea/app/performance/Performance.java | 2 +- .../app/publisher/MetricPublisher.java | 16 +- .../org/astraea/app/web/BalancerHandler.java | 2 +- .../org/astraea/app/web/BrokerHandler.java | 10 +- .../astraea/app/web/ReassignmentHandler.java | 6 +- .../app/web/SkewedPartitionScenario.java | 4 +- .../org/astraea/app/web/ThrottleHandler.java | 16 +- .../org/astraea/app/web/TopicHandler.java | 2 +- .../java/org/astraea/app/web/WebService.java | 4 +- .../app/performance/PerformanceTest.java | 6 +- .../astraea/app/web/BalancerHandlerTest.java | 6 +- .../app/web/ReassignmentHandlerTest.java | 14 +- .../astraea/app/web/ThrottleHandlerTest.java | 5 +- .../java/org/astraea/common/ByteUtils.java | 15 +- .../java/org/astraea/common/admin/Admin.java | 2 +- .../org/astraea/common/admin/AdminImpl.java | 45 ++++-- .../java/org/astraea/common/admin/Broker.java | 143 ++++++------------ .../org/astraea/common/admin/ClusterInfo.java | 22 +-- .../common/admin/ClusterInfoBuilder.java | 105 ++----------- .../astraea/common/admin/ConsumerGroup.java | 2 +- .../common/admin/OptimizedClusterInfo.java | 19 +-- .../org/astraea/common/admin/Partition.java | 6 +- .../org/astraea/common/admin/Replica.java | 4 +- .../astraea/common/admin/ReplicaBuilder.java | 22 +-- .../common/balancer/BalancerConsoleImpl.java | 8 +- .../executor/StraightPlanExecutor.java | 2 +- .../balancer/tweakers/ShuffleTweaker.java | 6 +- .../common/cost/BrokerDiskSpaceCost.java | 4 +- .../org/astraea/common/cost/CostUtils.java | 4 +- .../astraea/common/cost/MigrationCost.java | 8 +- .../org/astraea/common/cost/NetworkCost.java | 8 +- .../common/cost/NetworkIngressCost.java | 2 +- .../astraea/common/cost/NodeMetricsCost.java | 4 +- .../astraea/common/cost/RecordSizeCost.java | 4 +- .../common/cost/ReplicaLeaderSizeCost.java | 2 +- .../common/cost/ReplicaNumberCost.java | 6 +- .../common/cost/utils/ClusterInfoSensor.java | 8 +- .../common/metrics/MetricSeriesBuilder.java | 8 +- .../common/partitioner/RoundRobinKeeper.java | 4 +- .../org/astraea/common/admin/AdminTest.java | 20 +-- .../admin/AdminWithOfflineBrokerTest.java | 2 +- .../common/admin/ClusterInfoBuilderTest.java | 26 ++-- .../astraea/common/admin/ClusterInfoTest.java | 4 +- .../admin/ClusterInfoWithOfflineNodeTest.java | 8 +- .../admin/SomePartitionOfflineTest.java | 4 +- .../balancer/BalancerConfigTestSuite.java | 2 +- .../common/balancer/FakeClusterInfo.java | 75 ++------- .../executor/StraightPlanExecutorTest.java | 6 +- .../balancer/tweakers/ShuffleTweakerTest.java | 12 +- .../common/cost/BrokerDiskSpaceCostTest.java | 54 +++---- .../astraea/common/cost/CostUtilsTest.java | 28 ++-- .../common/cost/MigrationCostTest.java | 32 ++-- .../astraea/common/cost/NetworkCostTest.java | 4 +- .../common/cost/RecordSizeCostTest.java | 6 +- .../common/cost/ReplicaLeaderCostTest.java | 14 +- .../cost/ReplicaLeaderSizeCostTest.java | 8 +- .../cost/utils/ClusterInfoSensorTest.java | 2 +- .../StrictCostPartitionerPerfTest.java | 6 +- .../StrictCostPartitionerTest.java | 10 +- .../main/java/org/astraea/gui/Context.java | 6 +- .../java/org/astraea/gui/tab/BrokerNode.java | 8 +- .../astraea/gui/tab/health/BalancerNode.java | 8 +- .../astraea/gui/tab/topic/ReplicaNode.java | 4 +- .../org/astraea/gui/tab/topic/TopicNode.java | 3 +- .../gui/tab/health/BalancerNodeTest.java | 8 +- .../gui/tab/topic/ReplicaNodeTest.java | 8 +- 67 files changed, 383 insertions(+), 543 deletions(-) diff --git a/app/src/main/java/org/astraea/app/backup/Backup.java b/app/src/main/java/org/astraea/app/backup/Backup.java index 0becc9f4cd..efb81424cf 100644 --- a/app/src/main/java/org/astraea/app/backup/Backup.java +++ b/app/src/main/java/org/astraea/app/backup/Backup.java @@ -50,7 +50,7 @@ public void restoreDistribution(ClusterInfo clusterInfo, String bootstrapServers .sorted( Comparator.comparing( replica -> !replica.isLeader())) - .map(replica -> replica.nodeInfo().id()) + .map(replica -> replica.broker().id()) .collect(Collectors.toUnmodifiableList())))))) .configs(topic.config().raw()) .run() diff --git a/app/src/main/java/org/astraea/app/performance/Performance.java b/app/src/main/java/org/astraea/app/performance/Performance.java index 07067472e0..e8846bd7ac 100644 --- a/app/src/main/java/org/astraea/app/performance/Performance.java +++ b/app/src/main/java/org/astraea/app/performance/Performance.java @@ -385,7 +385,7 @@ else if (specifiedByBroker) { .join() .replicaStream() .filter(Replica::isLeader) - .filter(replica -> specifyBrokers.contains(replica.nodeInfo().id())) + .filter(replica -> specifyBrokers.contains(replica.broker().id())) .map(replica -> TopicPartition.of(replica.topic(), replica.partition())) .distinct() .collect(Collectors.toUnmodifiableList()); diff --git a/app/src/main/java/org/astraea/app/publisher/MetricPublisher.java b/app/src/main/java/org/astraea/app/publisher/MetricPublisher.java index d99c040995..e260bf42ac 100644 --- a/app/src/main/java/org/astraea/app/publisher/MetricPublisher.java +++ b/app/src/main/java/org/astraea/app/publisher/MetricPublisher.java @@ -25,7 +25,7 @@ import org.astraea.app.argument.StringMapField; import org.astraea.common.Utils; import org.astraea.common.admin.Admin; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.collector.MetricFetcher; @@ -50,17 +50,17 @@ static void execute(Arguments arguments) { .clientSupplier( () -> admin - .nodeInfos() + .brokers() .thenApply( - nodes -> - nodes.stream() + brokers -> + brokers.stream() .collect( Collectors.toUnmodifiableMap( - NodeInfo::id, - node -> + Broker::id, + broker -> JndiClient.of( - node.host(), - arguments.idToJmxPort().apply(node.id())))))) + broker.host(), + arguments.idToJmxPort().apply(broker.id())))))) .fetchBeanDelay(arguments.period) .fetchMetadataDelay(Duration.ofMinutes(5)) .threads(3) diff --git a/app/src/main/java/org/astraea/app/web/BalancerHandler.java b/app/src/main/java/org/astraea/app/web/BalancerHandler.java index 9fbd533f36..433f6daf38 100644 --- a/app/src/main/java/org/astraea/app/web/BalancerHandler.java +++ b/app/src/main/java/org/astraea/app/web/BalancerHandler.java @@ -256,7 +256,7 @@ static class Placement { final Optional size; Placement(Replica replica, Optional size) { - this.brokerId = replica.nodeInfo().id(); + this.brokerId = replica.broker().id(); this.directory = replica.path(); this.size = size; } diff --git a/app/src/main/java/org/astraea/app/web/BrokerHandler.java b/app/src/main/java/org/astraea/app/web/BrokerHandler.java index af92a5b7b6..17e51c0373 100644 --- a/app/src/main/java/org/astraea/app/web/BrokerHandler.java +++ b/app/src/main/java/org/astraea/app/web/BrokerHandler.java @@ -25,7 +25,7 @@ import java.util.concurrent.CompletionStage; import java.util.stream.Collectors; import org.astraea.common.admin.Admin; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.TopicPartition; class BrokerHandler implements Handler { @@ -44,8 +44,12 @@ CompletionStage> brokers(Optional target) { .orElseGet( () -> admin - .nodeInfos() - .thenApply(ns -> ns.stream().map(NodeInfo::id).collect(Collectors.toSet()))); + .brokers() + .thenApply( + ns -> + ns.stream() + .map(org.astraea.common.admin.Broker::id) + .collect(Collectors.toSet()))); } catch (NumberFormatException e) { return CompletableFuture.failedFuture( new NoSuchElementException("the broker id must be number")); diff --git a/app/src/main/java/org/astraea/app/web/ReassignmentHandler.java b/app/src/main/java/org/astraea/app/web/ReassignmentHandler.java index 05312ee909..dcdda72c31 100644 --- a/app/src/main/java/org/astraea/app/web/ReassignmentHandler.java +++ b/app/src/main/java/org/astraea/app/web/ReassignmentHandler.java @@ -31,8 +31,8 @@ import java.util.stream.Stream; import org.astraea.common.FutureUtils; import org.astraea.common.admin.Admin; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.admin.TopicPartition; import org.astraea.common.admin.TopicPartitionReplica; @@ -112,7 +112,7 @@ public CompletionStage post(Channel channel) { availableBrokers.stream() .filter( b -> b.topicPartitions().contains(tp)) - .map(NodeInfo::id) + .map(Broker::id) .collect(Collectors.toList()); if (!ids.isEmpty()) return ids; return List.of( @@ -213,7 +213,7 @@ static class AddingReplica implements Response { AddingReplica(Replica addingReplica, long leaderSize) { this.topicName = addingReplica.topic(); this.partition = addingReplica.partition(); - this.broker = addingReplica.nodeInfo().id(); + this.broker = addingReplica.broker().id(); this.dataFolder = addingReplica.path(); this.size = addingReplica.size(); this.leaderSize = leaderSize; diff --git a/app/src/main/java/org/astraea/app/web/SkewedPartitionScenario.java b/app/src/main/java/org/astraea/app/web/SkewedPartitionScenario.java index 7e45b7700a..12791045b3 100644 --- a/app/src/main/java/org/astraea/app/web/SkewedPartitionScenario.java +++ b/app/src/main/java/org/astraea/app/web/SkewedPartitionScenario.java @@ -30,7 +30,7 @@ import org.apache.commons.math3.distribution.IntegerDistribution; import org.apache.commons.math3.util.Pair; import org.astraea.common.admin.Admin; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.TopicPartition; import org.astraea.common.admin.TopicPartitionReplica; @@ -63,7 +63,7 @@ public CompletionStage apply(Admin admin) { Map.of(topicName, partitions), Duration.ofSeconds(4))) .thenCompose(ignored -> admin.brokers()) .thenApply( - brokers -> brokers.stream().map(NodeInfo::id).sorted().collect(Collectors.toList())) + brokers -> brokers.stream().map(Broker::id).sorted().collect(Collectors.toList())) .thenCompose( brokerIds -> { var distribution = diff --git a/app/src/main/java/org/astraea/app/web/ThrottleHandler.java b/app/src/main/java/org/astraea/app/web/ThrottleHandler.java index d47e14a856..67cc5843de 100644 --- a/app/src/main/java/org/astraea/app/web/ThrottleHandler.java +++ b/app/src/main/java/org/astraea/app/web/ThrottleHandler.java @@ -30,8 +30,8 @@ import org.astraea.common.EnumInfo; import org.astraea.common.FutureUtils; import org.astraea.common.admin.Admin; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.BrokerConfigs; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.TopicConfigs; import org.astraea.common.admin.TopicPartitionReplica; import org.astraea.common.json.TypeRef; @@ -100,9 +100,8 @@ public CompletionStage post(Channel channel) { var topicToAppends = admin - .nodeInfos() - .thenApply( - nodeInfos -> nodeInfos.stream().map(NodeInfo::id).collect(Collectors.toSet())) + .brokers() + .thenApply(brokers -> brokers.stream().map(Broker::id).collect(Collectors.toSet())) .thenCompose(admin::topicPartitionReplicas) .thenApply( replicas -> @@ -197,9 +196,8 @@ public CompletionStage delete(Channel channel) { var topicToSubtracts = admin - .nodeInfos() - .thenApply( - nodeInfos -> nodeInfos.stream().map(NodeInfo::id).collect(Collectors.toSet())) + .brokers() + .thenApply(brokers -> brokers.stream().map(Broker::id).collect(Collectors.toSet())) .thenCompose(admin::topicPartitionReplicas) .thenApply( replicas -> { @@ -251,11 +249,11 @@ public CompletionStage delete(Channel channel) { var brokerToUnset = admin - .nodeInfos() + .brokers() .thenApply( ns -> ns.stream() - .map(NodeInfo::id) + .map(Broker::id) .filter( id -> !channel.queries().containsKey("broker") diff --git a/app/src/main/java/org/astraea/app/web/TopicHandler.java b/app/src/main/java/org/astraea/app/web/TopicHandler.java index d4320a3033..1aa1adb071 100644 --- a/app/src/main/java/org/astraea/app/web/TopicHandler.java +++ b/app/src/main/java/org/astraea/app/web/TopicHandler.java @@ -316,7 +316,7 @@ private Replica() { Replica(org.astraea.common.admin.Replica replica) { this( - replica.nodeInfo().id(), + replica.broker().id(), replica.lag(), replica.size(), replica.isLeader(), diff --git a/app/src/main/java/org/astraea/app/web/WebService.java b/app/src/main/java/org/astraea/app/web/WebService.java index c81f2a7b36..ccd0d03956 100644 --- a/app/src/main/java/org/astraea/app/web/WebService.java +++ b/app/src/main/java/org/astraea/app/web/WebService.java @@ -35,7 +35,7 @@ import org.astraea.app.argument.NonNegativeIntegerField; import org.astraea.common.Utils; import org.astraea.common.admin.Admin; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MBeanClient; import org.astraea.common.metrics.collector.MetricSensor; @@ -62,7 +62,7 @@ public WebService( brokers.stream() .collect( Collectors.toUnmodifiableMap( - NodeInfo::id, + Broker::id, b -> JndiClient.of(b.host(), brokerIdToJmxPort.apply(b.id()))))); var metricStore = diff --git a/app/src/test/java/org/astraea/app/performance/PerformanceTest.java b/app/src/test/java/org/astraea/app/performance/PerformanceTest.java index c1dad4673b..90f56293a5 100644 --- a/app/src/test/java/org/astraea/app/performance/PerformanceTest.java +++ b/app/src/test/java/org/astraea/app/performance/PerformanceTest.java @@ -193,7 +193,7 @@ void testPartitionSupplier() { .join() .replicaStream() .filter(Replica::isLeader) - .filter(r -> r.nodeInfo().id() == 1) + .filter(r -> r.broker().id() == 1) .map(Replica::topicPartition) .collect(Collectors.toUnmodifiableSet()); @@ -239,7 +239,7 @@ void testPartitionSupplier() { .join() .replicaStream() .filter(Replica::isLeader) - .filter(replica -> replica.nodeInfo().id() == 1) + .filter(replica -> replica.broker().id() == 1) .map(Replica::topicPartition) .collect(Collectors.toSet()); var selector2 = args.topicPartitionSelector(); @@ -273,7 +273,7 @@ void testPartitionSupplier() { .replicaStream() .findFirst() .get() - .nodeInfo() + .broker() .id(); var noPartitionBroker = (validBroker == 3) ? 1 : validBroker + 1; args = diff --git a/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java b/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java index 73c9ba3aed..32166ac170 100644 --- a/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java +++ b/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java @@ -235,7 +235,7 @@ void testBestPlan() { Replica.builder() .topic("topic") .partition(0) - .nodeInfo(NodeInfo.of(10, "host", 22)) + .broker(NodeInfo.of(10, "host", 22)) .lag(0) .size(100) .isLeader(true) @@ -987,7 +987,7 @@ void testChangeOrder() { (short) 10, r -> Replica.builder(r) - .nodeInfo(base.node(srcIter.next())) + .broker(base.node(srcIter.next())) .isPreferredLeader(srcPrefIter.next()) .path(srcDirIter.next()) .build()) @@ -1003,7 +1003,7 @@ void testChangeOrder() { (short) 10, r -> Replica.builder(r) - .nodeInfo(base.node(dstIter.next())) + .broker(base.node(dstIter.next())) .isPreferredLeader(dstPrefIter.next()) .path(dstDirIter.next()) .build()) diff --git a/app/src/test/java/org/astraea/app/web/ReassignmentHandlerTest.java b/app/src/test/java/org/astraea/app/web/ReassignmentHandlerTest.java index 83577b5616..01570fdca4 100644 --- a/app/src/test/java/org/astraea/app/web/ReassignmentHandlerTest.java +++ b/app/src/test/java/org/astraea/app/web/ReassignmentHandlerTest.java @@ -60,7 +60,7 @@ void testMigrateToAnotherBroker() { .filter(replica -> replica.partition() == 0) .findFirst() .get() - .nodeInfo() + .broker() .id(); var nextBroker = SERVICE.dataFolders().keySet().stream().filter(i -> i != currentBroker).findAny().get(); @@ -88,7 +88,7 @@ void testMigrateToAnotherBroker() { .filter(replica -> replica.partition() == 0) .findFirst() .get() - .nodeInfo() + .broker() .id()); } } @@ -111,7 +111,7 @@ void testMigrateToAnotherPath() { .findFirst() .get(); - var currentBroker = currentReplica.nodeInfo().id(); + var currentBroker = currentReplica.broker().id(); var currentPath = currentReplica.path(); var nextPath = SERVICE.dataFolders().get(currentBroker).stream() @@ -170,7 +170,7 @@ void testExcludeSpecificBroker() { .filter(replica -> replica.partition() == 0) .findFirst() .get() - .nodeInfo() + .broker() .id(); var body = @@ -194,7 +194,7 @@ void testExcludeSpecificBroker() { .filter(replica -> replica.partition() == 0) .findFirst() .get() - .nodeInfo() + .broker() .id()); Assertions.assertEquals( 0, @@ -221,7 +221,7 @@ void testExcludeSpecificBrokerTopic() { .filter(replica -> replica.partition() == 0) .findFirst() .get() - .nodeInfo() + .broker() .id(); var body = @@ -247,7 +247,7 @@ void testExcludeSpecificBrokerTopic() { .filter(replica -> replica.partition() == 0) .findFirst() .get() - .nodeInfo() + .broker() .id()); Assertions.assertNotEquals( 0, diff --git a/app/src/test/java/org/astraea/app/web/ThrottleHandlerTest.java b/app/src/test/java/org/astraea/app/web/ThrottleHandlerTest.java index c00a850fa5..eaa3966c9d 100644 --- a/app/src/test/java/org/astraea/app/web/ThrottleHandlerTest.java +++ b/app/src/test/java/org/astraea/app/web/ThrottleHandlerTest.java @@ -30,6 +30,7 @@ import org.astraea.common.DataRate; import org.astraea.common.Utils; import org.astraea.common.admin.Admin; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.BrokerConfigs; import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.TopicConfigs; @@ -55,13 +56,13 @@ static void closeService() { public void cleanup() { try (var admin = Admin.of(SERVICE.bootstrapServers())) { admin - .nodeInfos() + .brokers() .thenApply( ns -> ns.stream() .collect( Collectors.toMap( - NodeInfo::id, + Broker::id, ignored -> Set.of( BrokerConfigs.LEADER_REPLICATION_THROTTLED_RATE_CONFIG, diff --git a/common/src/main/java/org/astraea/common/ByteUtils.java b/common/src/main/java/org/astraea/common/ByteUtils.java index 38a509fe52..fa429abb38 100644 --- a/common/src/main/java/org/astraea/common/ByteUtils.java +++ b/common/src/main/java/org/astraea/common/ByteUtils.java @@ -26,6 +26,8 @@ import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; + +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Config; import org.astraea.common.admin.NodeInfo; @@ -218,9 +220,9 @@ public static byte[] toBytes(ClusterInfo value) { .setPartition(replica.partition()) .setNodeInfo( ClusterInfoOuterClass.ClusterInfo.NodeInfo.newBuilder() - .setId(replica.nodeInfo().id()) - .setHost(replica.nodeInfo().host()) - .setPort(replica.nodeInfo().port()) + .setId(replica.broker().id()) + .setHost(replica.broker().host()) + .setPort(replica.broker().port()) .build()) .setLag(replica.lag()) .setSize(replica.size()) @@ -320,6 +322,7 @@ public static BeanObject readBeanObject(byte[] bytes) throws SerializationExcept } } + // TODO: change NodeInfo to Broker. Some information has not yet been serialized. /** Deserialize to ClusterInfo with protocol buffer */ public static ClusterInfo readClusterInfo(byte[] bytes) { try { @@ -328,7 +331,7 @@ public static ClusterInfo readClusterInfo(byte[] bytes) { outerClusterInfo.getClusterId(), outerClusterInfo.getNodeInfoList().stream() .map( - nodeInfo -> NodeInfo.of(nodeInfo.getId(), nodeInfo.getHost(), nodeInfo.getPort())) + nodeInfo -> Broker.of(nodeInfo.getId(), nodeInfo.getHost(), nodeInfo.getPort())) .collect(Collectors.toList()), outerClusterInfo.getTopicList().stream() .map( @@ -363,8 +366,8 @@ public Set topicPartitions() { Replica.builder() .topic(replica.getTopic()) .partition(replica.getPartition()) - .nodeInfo( - NodeInfo.of( + .broker( + Broker.of( replica.getNodeInfo().getId(), replica.getNodeInfo().getHost(), replica.getNodeInfo().getPort())) diff --git a/common/src/main/java/org/astraea/common/admin/Admin.java b/common/src/main/java/org/astraea/common/admin/Admin.java index 68a39c4b96..45c58e3bb8 100644 --- a/common/src/main/java/org/astraea/common/admin/Admin.java +++ b/common/src/main/java/org/astraea/common/admin/Admin.java @@ -187,7 +187,7 @@ default CompletionStage>> brokerFolders() { brokers.stream() .collect( Collectors.toMap( - NodeInfo::id, + Broker::id, n -> n.dataFolders().stream() .map(Broker.DataFolder::path) diff --git a/common/src/main/java/org/astraea/common/admin/AdminImpl.java b/common/src/main/java/org/astraea/common/admin/AdminImpl.java index 1f51b1ac0a..27ea4fa980 100644 --- a/common/src/main/java/org/astraea/common/admin/AdminImpl.java +++ b/common/src/main/java/org/astraea/common/admin/AdminImpl.java @@ -405,7 +405,11 @@ public CompletionStage> partitions(Set topics) { ts -> ts.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().isInternal()))), - (earliestOffsets, latestOffsets, maxTimestamps, tpInfos, topicAndInternal) -> + brokers() + .thenApply( + brokers -> + brokers.stream().collect(Collectors.toMap(Broker::id, Function.identity()))), + (earliestOffsets, latestOffsets, maxTimestamps, tpInfos, topicAndInternal, brokers) -> tpInfos.keySet().stream() .map( tp -> { @@ -416,11 +420,15 @@ public CompletionStage> partitions(Set topics) { var leader = tpInfo.leader() == null || tpInfo.leader().isEmpty() ? null - : NodeInfo.of(tpInfo.leader()); + : brokers.get(tpInfo.leader().id()); var replicas = - tpInfo.replicas().stream().map(NodeInfo::of).collect(Collectors.toList()); + tpInfo.replicas().stream() + .map(replicaBroker -> brokers.get(replicaBroker.id())) + .collect(Collectors.toList()); var isr = - tpInfo.isr().stream().map(NodeInfo::of).collect(Collectors.toList()); + tpInfo.isr().stream() + .map(isrBroker -> brokers.get(isrBroker.id())) + .collect(Collectors.toList()); return new Partition( tp.topic(), tp.partition(), @@ -483,7 +491,7 @@ private CompletionStage>> clusterIdAndBrokers() { configs.get(String.valueOf(node.id())), logDirs.get(node.id()), topics.values())) - .sorted(Comparator.comparing(NodeInfo::id)) + .sorted(Comparator.comparing(Broker::id)) .collect(Collectors.toList()))); } @@ -514,7 +522,11 @@ public CompletionStage> consumerGroups(Set consumerG .collect(Collectors.toUnmodifiableList())) .thenApply( s -> s.stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))), - (consumerGroupDescriptions, consumerGroupMetadata) -> + brokers() + .thenApply( + brokers -> + brokers.stream().collect(Collectors.toMap(Broker::id, Function.identity()))), + (consumerGroupDescriptions, consumerGroupMetadata, brokers) -> consumerGroupIds.stream() .map( groupId -> @@ -522,7 +534,7 @@ public CompletionStage> consumerGroups(Set consumerG groupId, consumerGroupDescriptions.get(groupId).partitionAssignor(), consumerGroupDescriptions.get(groupId).state().name(), - NodeInfo.of(consumerGroupDescriptions.get(groupId).coordinator()), + brokers.get(consumerGroupDescriptions.get(groupId).coordinator().id()), consumerGroupMetadata.get(groupId).entrySet().stream() .collect( Collectors.toUnmodifiableMap( @@ -623,9 +635,7 @@ public CompletionStage clusterInfo(Set topics) { topicList.stream().collect(Collectors.toUnmodifiableMap(Topic::name, t -> t)); return ClusterInfo.of( clusterIdAndBrokers.getKey(), - clusterIdAndBrokers.getValue().stream() - .map(x -> (NodeInfo) x) - .collect(Collectors.toUnmodifiableList()), + clusterIdAndBrokers.getValue(), topicMap, replicas); }); @@ -642,7 +652,11 @@ private CompletionStage> replicas(Set topics) { // supported version: 2.4.0 // https://issues.apache.org/jira/browse/KAFKA-8345 .exceptionally(exceptionHandler(UnsupportedVersionException.class, Map.of())), - (logDirs, ts, reassignmentMap) -> + brokers() + .thenApply( + brokers -> + brokers.stream().collect(Collectors.toMap(Broker::id, Function.identity()))), + (logDirs, ts, reassignmentMap, brokers) -> ts.values().stream() .flatMap(topic -> topic.partitions().stream().map(p -> Map.entry(topic.name(), p))) .flatMap( @@ -687,7 +701,7 @@ private CompletionStage> replicas(Set topics) { .internal(internal) .isAdding(isAdding) .isRemoving(isRemoving) - .nodeInfo(NodeInfo.of(node)) + .broker(brokers.get(node.id())) .lag(pathAndReplica.getValue().offsetLag()) .size(pathAndReplica.getValue().size()) .isLeader( @@ -716,7 +730,7 @@ private CompletionStage> replicas(Set topics) { .sorted( Comparator.comparing(Replica::topic) .thenComparing(Replica::partition) - .thenComparing(r -> r.nodeInfo().id())) + .thenComparing(r -> r.broker().id())) .collect(Collectors.toUnmodifiableList())); } @@ -1374,10 +1388,9 @@ public void close() { Integer, Map>>> logDirs() { - return nodeInfos() + return brokers() .thenApply( - nodeInfos -> - nodeInfos.stream().map(NodeInfo::id).collect(Collectors.toUnmodifiableSet())) + nodeInfos -> nodeInfos.stream().map(Broker::id).collect(Collectors.toUnmodifiableSet())) .thenCompose(ids -> to(kafkaAdmin.describeLogDirs(ids).allDescriptions())) .thenApply( ds -> diff --git a/common/src/main/java/org/astraea/common/admin/Broker.java b/common/src/main/java/org/astraea/common/admin/Broker.java index 69ecb71e97..68cf8db99a 100644 --- a/common/src/main/java/org/astraea/common/admin/Broker.java +++ b/common/src/main/java/org/astraea/common/admin/Broker.java @@ -23,7 +23,34 @@ import java.util.stream.Collectors; import org.apache.kafka.common.requests.DescribeLogDirsResponse; -public interface Broker extends NodeInfo { +public record Broker( + int id, + String host, + int port, + boolean isController, + // config used by this node + Config config, + // the disk folder used to stored data by this node + List dataFolders, + Set topicPartitions, + // partition leaders hosted by this broker + Set topicPartitionLeaders) + implements NodeInfo { + + /** + * @return true if the broker is offline. An offline node can't offer host or port information. + */ + public boolean offline() { + return host() == null || host().isEmpty() || port() < 0; + } + + public static Broker of( + int id, + String host, + int port + ) { + return new Broker(id, host, port, false, Config.EMPTY, List.of(), Set.of(), Set.of()); + } static Broker of( boolean isController, @@ -60,26 +87,9 @@ static Broker of( tpAndSize -> !partitionsFromTopicDesc.contains(tpAndSize.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - return (DataFolder) - new DataFolder() { - - @Override - public String path() { - return path; - } - - @Override - public Map partitionSizes() { - return partitionSizes; - } - - @Override - public Map orphanPartitionSizes() { - return orphanPartitionSizes; - } - }; + return new DataFolder(path, partitionSizes, orphanPartitionSizes); }) - .collect(Collectors.toList()); + .toList(); var topicPartitionLeaders = topics.stream() .flatMap( @@ -88,83 +98,22 @@ public Map orphanPartitionSizes() { .filter(p -> p.leader() != null && p.leader().id() == nodeInfo.id()) .map(p -> TopicPartition.of(topic.name(), p.partition()))) .collect(Collectors.toUnmodifiableSet()); - return new Broker() { - @Override - public String host() { - return nodeInfo.host(); - } - - @Override - public int port() { - return nodeInfo.port(); - } - - @Override - public int id() { - return nodeInfo.id(); - } - - @Override - public boolean isController() { - return isController; - } - - @Override - public Config config() { - return config; - } - - @Override - public List dataFolders() { - return folders; - } - - @Override - public Set topicPartitions() { - return partitionsFromTopicDesc; - } - - @Override - public Set topicPartitionLeaders() { - return topicPartitionLeaders; - } - }; + return new Broker( + nodeInfo.id(), + nodeInfo.host(), + nodeInfo.port(), + isController, + config, + folders, + partitionsFromTopicDesc, + topicPartitionLeaders); } - boolean isController(); - - /** - * @return config used by this node - */ - Config config(); - - /** - * @return the disk folder used to stored data by this node - */ - List dataFolders(); - - Set topicPartitions(); - - /** - * @return partition leaders hosted by this broker - */ - Set topicPartitionLeaders(); - - interface DataFolder { - - /** - * @return the path on the local disk - */ - String path(); - - /** - * @return topic partition hosed by this node and size of files - */ - Map partitionSizes(); - - /** - * @return topic partition located by this node but not traced by cluster - */ - Map orphanPartitionSizes(); - } + public record DataFolder( + // the path on the local disk + String path, + // topic partition hosed by this node and size of files + Map partitionSizes, + // topic partition located by this node but not traced by cluster + Map orphanPartitionSizes) {} } diff --git a/common/src/main/java/org/astraea/common/admin/ClusterInfo.java b/common/src/main/java/org/astraea/common/admin/ClusterInfo.java index 9411ed170c..5f986db947 100644 --- a/common/src/main/java/org/astraea/common/admin/ClusterInfo.java +++ b/common/src/main/java/org/astraea/common/admin/ClusterInfo.java @@ -87,14 +87,14 @@ static boolean placementMatch( .sorted( Comparator.comparing(Replica::isPreferredLeader) .reversed() - .thenComparing(r -> r.nodeInfo().id())) + .thenComparing(r -> r.broker().id())) .collect(Collectors.toUnmodifiableList()); final var targetIds = targetReplicas.stream() .sorted( Comparator.comparing(Replica::isPreferredLeader) .reversed() - .thenComparing(r -> r.nodeInfo().id())) + .thenComparing(r -> r.broker().id())) .collect(Collectors.toUnmodifiableList()); return IntStream.range(0, sourceIds.size()) .allMatch( @@ -102,7 +102,7 @@ static boolean placementMatch( final var source = sourceIds.get(index); final var target = targetIds.get(index); return source.isPreferredLeader() == target.isPreferredLeader() - && source.nodeInfo().id() == target.nodeInfo().id() + && source.broker().id() == target.broker().id() && Objects.equals(source.path(), target.path()); }); } @@ -121,7 +121,7 @@ static String toString(ClusterInfo allocation) { .forEach( log -> stringBuilder.append( - String.format("(%s, %s) ", log.nodeInfo().id(), log.path()))); + String.format("(%s, %s) ", log.broker().id(), log.path()))); stringBuilder.append(System.lineSeparator()); }); @@ -147,7 +147,7 @@ static String toString(ClusterInfo allocation) { * @return cluster info */ static ClusterInfo of( - String clusterId, List nodes, Map topics, List replicas) { + String clusterId, List nodes, Map topics, List replicas) { return new OptimizedClusterInfo(clusterId, nodes, topics, replicas); } @@ -306,7 +306,7 @@ default Set topicPartitionReplicas() { * @return the node information. It throws NoSuchElementException if specify node id is not * associated to any node */ - default NodeInfo node(int id) { + default Broker node(int id) { return nodes().stream() .filter(n -> n.id() == id) .findAny() @@ -321,7 +321,7 @@ default Map> brokerFolders() { return brokers().stream() .collect( Collectors.toUnmodifiableMap( - NodeInfo::id, + Broker::id, node -> node.dataFolders().stream() .map(Broker.DataFolder::path) @@ -332,7 +332,7 @@ default Map> brokerFolders() { // implements following methods by smart index to speed up the queries default Stream replicaStream(int broker) { - return replicaStream().filter(r -> r.nodeInfo().id() == broker); + return replicaStream().filter(r -> r.broker().id() == broker); } default Stream replicaStream(String topic) { @@ -341,7 +341,7 @@ default Stream replicaStream(String topic) { default Stream replicaStream(BrokerTopic brokerTopic) { return replicaStream(brokerTopic.topic()) - .filter(r -> r.nodeInfo().id() == brokerTopic.broker()); + .filter(r -> r.broker().id() == brokerTopic.broker()); } default Stream replicaStream(TopicPartition partition) { @@ -350,7 +350,7 @@ default Stream replicaStream(TopicPartition partition) { default Stream replicaStream(TopicPartitionReplica replica) { return replicaStream(replica.topicPartition()) - .filter(r -> r.nodeInfo().id() == replica.brokerId()); + .filter(r -> r.broker().id() == replica.brokerId()); } // ---------------------[abstract methods]---------------------// @@ -358,7 +358,7 @@ default Stream replicaStream(TopicPartitionReplica replica) { /** * @return The known nodes */ - List nodes(); + List nodes(); default List brokers() { return nodes().stream() diff --git a/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java b/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java index c06919747a..bba81853bd 100644 --- a/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java +++ b/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java @@ -36,7 +36,7 @@ public class ClusterInfoBuilder { private final ClusterInfo sourceCluster; private final List< - BiFunction, List, Map.Entry, List>>> + BiFunction, List, Map.Entry, List>>> alterations; ClusterInfoBuilder(ClusterInfo source) { @@ -51,7 +51,7 @@ public class ClusterInfoBuilder { * @return this. */ public ClusterInfoBuilder applyNodes( - BiFunction, List, List> alteration) { + BiFunction, List, List> alteration) { this.alterations.add( (nodes, replicas) -> Map.entry(alteration.apply(nodes, replicas), replicas)); return this; @@ -64,7 +64,7 @@ public ClusterInfoBuilder applyNodes( * @return this. */ public ClusterInfoBuilder applyReplicas( - BiFunction, List, List> alteration) { + BiFunction, List, List> alteration) { this.alterations.add((nodes, replicas) -> Map.entry(nodes, alteration.apply(nodes, replicas))); return this; } @@ -108,14 +108,15 @@ public ClusterInfoBuilder addFolders(Map> folders) { .map( node -> { if (folders.containsKey(node.id())) - return FakeBroker.of( + return fakeBroker( node.id(), node.host(), node.port(), Stream.concat( ((Broker) node).dataFolders().stream(), - folders.get(node.id()).stream().map(FakeDataFolder::of)) - .collect(Collectors.toUnmodifiableList())); + folders.get(node.id()).stream() + .map(ClusterInfoBuilder::fakeDataFolder)) + .toList()); else return node; }) .collect(Collectors.toUnmodifiableList()); @@ -172,7 +173,7 @@ public ClusterInfoBuilder addTopic( Broker.DataFolder::path, x -> new AtomicInteger())))); replicas.forEach( replica -> - folderLogCounter.get(replica.nodeInfo()).get(replica.path()).incrementAndGet()); + folderLogCounter.get(replica.broker()).get(replica.path()).incrementAndGet()); folderLogCounter.forEach( (node, folders) -> { @@ -202,7 +203,7 @@ public ClusterInfoBuilder addTopic( return Replica.builder() .topic(tp.topic()) .partition(tp.partition()) - .nodeInfo(broker) + .broker(broker) .isAdding(false) .isRemoving(false) .lag(0) @@ -259,7 +260,7 @@ public ClusterInfoBuilder reassignReplica( r -> { if (r.topicPartitionReplica().equals(replica)) { matched.set(true); - return Replica.builder(r).nodeInfo(newNode).path(toDir).build(); + return Replica.builder(r).broker(newNode).path(toDir).build(); } else { return r; } @@ -325,90 +326,14 @@ private static Broker fakeNode(int brokerId) { var port = new Random(brokerId).nextInt(65535) + 1; var folders = List.of(); - return FakeBroker.of(brokerId, host, port, folders); + return fakeBroker(brokerId, host, port, folders); } - interface FakeBroker extends Broker { - - static FakeBroker of(int id, String host, int port, List folders) { - var hashCode = Objects.hash(id, host, port); - return new FakeBroker() { - @Override - public List dataFolders() { - return folders; - } - - @Override - public String host() { - return host; - } - - @Override - public int port() { - return port; - } - - @Override - public int id() { - return id; - } - - @Override - public String toString() { - return "FakeNodeInfo{" + "host=" + host() + ", id=" + id() + ", port=" + port() + '}'; - } - - @Override - public int hashCode() { - return hashCode; - } - - @Override - public boolean equals(Object other) { - if (other instanceof NodeInfo) { - var node = (NodeInfo) other; - return id() == node.id() && port() == node.port() && host().equals(node.host()); - } - return false; - } - }; - } - - @Override - default boolean isController() { - throw new UnsupportedOperationException(); - } - - @Override - default Config config() { - throw new UnsupportedOperationException(); - } - - @Override - default Set topicPartitions() { - throw new UnsupportedOperationException(); - } - - @Override - default Set topicPartitionLeaders() { - throw new UnsupportedOperationException(); - } + static Broker fakeBroker(int Id, String host, int port, List dataFolders) { + return new Broker(Id, host, port, false, new Config(Map.of()), dataFolders, Set.of(), Set.of()); } - interface FakeDataFolder extends Broker.DataFolder { - - static FakeDataFolder of(String path) { - return () -> path; - } - - @Override - default Map partitionSizes() { - throw new UnsupportedOperationException(); - } - - @Override - default Map orphanPartitionSizes() { - throw new UnsupportedOperationException(); - } + private static Broker.DataFolder fakeDataFolder(String path) { + return new Broker.DataFolder(path, Map.of(), Map.of()); } } diff --git a/common/src/main/java/org/astraea/common/admin/ConsumerGroup.java b/common/src/main/java/org/astraea/common/admin/ConsumerGroup.java index 29691e8337..9269ec0540 100644 --- a/common/src/main/java/org/astraea/common/admin/ConsumerGroup.java +++ b/common/src/main/java/org/astraea/common/admin/ConsumerGroup.java @@ -23,6 +23,6 @@ public record ConsumerGroup( String groupId, String assignor, String state, - NodeInfo coordinator, + Broker coordinator, Map consumeProgress, Map> assignment) {} diff --git a/common/src/main/java/org/astraea/common/admin/OptimizedClusterInfo.java b/common/src/main/java/org/astraea/common/admin/OptimizedClusterInfo.java index d9448b92a6..3a18d2b795 100644 --- a/common/src/main/java/org/astraea/common/admin/OptimizedClusterInfo.java +++ b/common/src/main/java/org/astraea/common/admin/OptimizedClusterInfo.java @@ -28,7 +28,7 @@ /** It optimizes all queries by pre-allocated Map collection. */ class OptimizedClusterInfo implements ClusterInfo { private final String clusterId; - private final List nodeInfos; + private final List brokers; private final List all; private final Lazy> topics; @@ -44,12 +44,9 @@ class OptimizedClusterInfo implements ClusterInfo { private final Lazy>> byReplica; OptimizedClusterInfo( - String clusterId, - List nodeInfos, - Map topics, - List replicas) { + String clusterId, List brokers, Map topics, List replicas) { this.clusterId = clusterId; - this.nodeInfos = nodeInfos; + this.brokers = brokers; this.all = replicas; this.topics = Lazy.of( @@ -104,7 +101,7 @@ && internal() == objTopic.internal() all.stream() .collect( Collectors.groupingBy( - r -> BrokerTopic.of(r.nodeInfo().id(), r.topic()), + r -> BrokerTopic.of(r.broker().id(), r.topic()), Collectors.toUnmodifiableList()))); this.byBrokerTopicForLeader = Lazy.of( @@ -114,7 +111,7 @@ && internal() == objTopic.internal() .filter(Replica::isLeader) .collect( Collectors.groupingBy( - r -> BrokerTopic.of(r.nodeInfo().id(), r.topic()), + r -> BrokerTopic.of(r.broker().id(), r.topic()), Collectors.toUnmodifiableList()))); this.byBroker = @@ -123,7 +120,7 @@ && internal() == objTopic.internal() all.stream() .collect( Collectors.groupingBy( - r -> r.nodeInfo().id(), Collectors.toUnmodifiableList()))); + r -> r.broker().id(), Collectors.toUnmodifiableList()))); this.byTopic = Lazy.of( @@ -204,8 +201,8 @@ public Set topicNames() { } @Override - public List nodes() { - return nodeInfos; + public List nodes() { + return brokers; } @Override diff --git a/common/src/main/java/org/astraea/common/admin/Partition.java b/common/src/main/java/org/astraea/common/admin/Partition.java index 1bbc40ecc6..3e9d876efd 100644 --- a/common/src/main/java/org/astraea/common/admin/Partition.java +++ b/common/src/main/java/org/astraea/common/admin/Partition.java @@ -33,9 +33,9 @@ public record Partition( long earliestOffset, long latestOffset, Optional maxTimestamp, - Optional leader, - List replicas, - List isr, + Optional leader, + List replicas, + List isr, boolean internal) { public TopicPartition topicPartition() { diff --git a/common/src/main/java/org/astraea/common/admin/Replica.java b/common/src/main/java/org/astraea/common/admin/Replica.java index 4bab1648c2..84a82b3c13 100644 --- a/common/src/main/java/org/astraea/common/admin/Replica.java +++ b/common/src/main/java/org/astraea/common/admin/Replica.java @@ -32,7 +32,7 @@ static ReplicaBuilder builder(Replica replica) { * @return TopicPartitionReplica */ default TopicPartitionReplica topicPartitionReplica() { - return TopicPartitionReplica.of(topic(), partition(), nodeInfo().id()); + return TopicPartitionReplica.of(topic(), partition(), broker().id()); } /** @@ -57,7 +57,7 @@ default TopicPartition topicPartition() { /** * @return information of the node hosts this replica */ - NodeInfo nodeInfo(); + Broker broker(); /** * @return true if this replica is a leader replica diff --git a/common/src/main/java/org/astraea/common/admin/ReplicaBuilder.java b/common/src/main/java/org/astraea/common/admin/ReplicaBuilder.java index a499e79e1a..9d0e718fe4 100644 --- a/common/src/main/java/org/astraea/common/admin/ReplicaBuilder.java +++ b/common/src/main/java/org/astraea/common/admin/ReplicaBuilder.java @@ -22,7 +22,7 @@ public class ReplicaBuilder { private String topic; private int partition; - private NodeInfo nodeInfo; + private Broker broker; private long lag; private long size; @@ -40,7 +40,7 @@ public class ReplicaBuilder { ReplicaBuilder replica(Replica replica) { this.topic = replica.topic(); this.partition = replica.partition(); - this.nodeInfo = replica.nodeInfo(); + this.broker = replica.broker(); this.lag = replica.lag(); this.size = replica.size(); this.isLeader = replica.isLeader(); @@ -63,8 +63,8 @@ public ReplicaBuilder partition(int partition) { return this; } - public ReplicaBuilder nodeInfo(NodeInfo nodeInfo) { - this.nodeInfo = nodeInfo; + public ReplicaBuilder broker(Broker broker) { + this.broker = broker; return this; } @@ -166,7 +166,7 @@ public Replica build() { private static class ReplicaImpl implements Replica { private final String topic; private final int partition; - private final NodeInfo nodeInfo; + private final Broker broker; private final long lag; private final long size; @@ -185,7 +185,7 @@ private static class ReplicaImpl implements Replica { private ReplicaImpl(ReplicaBuilder builder) { this.topic = Objects.requireNonNull(builder.topic); this.partition = builder.partition; - this.nodeInfo = Objects.requireNonNull(builder.nodeInfo); + this.broker = Objects.requireNonNull(builder.broker); this.isAdding = builder.isAdding; this.isRemoving = builder.isRemoving; this.lag = builder.lag; @@ -240,8 +240,8 @@ public int partition() { } @Override - public NodeInfo nodeInfo() { - return nodeInfo; + public Broker broker() { + return broker; } @Override @@ -286,7 +286,7 @@ public boolean equals(Object o) { && isOffline == replica.isOffline && isPreferredLeader == replica.isPreferredLeader && topic.equals(replica.topic) - && nodeInfo.equals(replica.nodeInfo) + && broker.equals(replica.broker) && Objects.equals(path, replica.path); } @@ -299,7 +299,7 @@ public String toString() { + ", partition=" + partition() + ", broker=" - + nodeInfo() + + broker() + ", path='" + path() + '\'' @@ -313,7 +313,7 @@ public int hashCode() { return Objects.hash( topic, partition, - nodeInfo, + broker, lag, size, internal, diff --git a/common/src/main/java/org/astraea/common/balancer/BalancerConsoleImpl.java b/common/src/main/java/org/astraea/common/balancer/BalancerConsoleImpl.java index b13e679d40..aa9b5c2343 100644 --- a/common/src/main/java/org/astraea/common/balancer/BalancerConsoleImpl.java +++ b/common/src/main/java/org/astraea/common/balancer/BalancerConsoleImpl.java @@ -270,8 +270,8 @@ private CompletionStage checkPlanConsistency(Balancer.Plan plan) { .sorted( Comparator.comparing(Replica::isPreferredLeader) .reversed() - .thenComparing(x -> x.nodeInfo().id())) - .map(x -> Map.entry(x.nodeInfo().id(), x.path())) + .thenComparing(x -> x.broker().id())) + .map(x -> Map.entry(x.broker().id(), x.path())) .collect(Collectors.toUnmodifiableList()))); return admin .topicNames(false) @@ -292,8 +292,8 @@ private CompletionStage checkPlanConsistency(Balancer.Plan plan) { .sorted( Comparator.comparing(Replica::isPreferredLeader) .reversed() - .thenComparing(x -> x.nodeInfo().id())) - .map(x -> Map.entry(x.nodeInfo().id(), x.path())) + .thenComparing(x -> x.broker().id())) + .map(x -> Map.entry(x.broker().id(), x.path())) .collect(Collectors.toUnmodifiableList()))); var mismatchPartitions = before.entrySet().stream() diff --git a/common/src/main/java/org/astraea/common/balancer/executor/StraightPlanExecutor.java b/common/src/main/java/org/astraea/common/balancer/executor/StraightPlanExecutor.java index d295bc66fc..89169fd847 100644 --- a/common/src/main/java/org/astraea/common/balancer/executor/StraightPlanExecutor.java +++ b/common/src/main/java/org/astraea/common/balancer/executor/StraightPlanExecutor.java @@ -80,7 +80,7 @@ public CompletionStage run(Admin admin, ClusterInfo logAllocation, Duratio Collectors.groupingBy( Replica::topicPartition, Collectors.mapping( - r -> r.nodeInfo().id(), Collectors.toList())))) + r -> r.broker().id(), Collectors.toList())))) .thenApply(ignored -> replicas)) // step 2: wait replicas get reassigned .thenCompose( diff --git a/common/src/main/java/org/astraea/common/balancer/tweakers/ShuffleTweaker.java b/common/src/main/java/org/astraea/common/balancer/tweakers/ShuffleTweaker.java index b75bddfafd..4febc3aaf5 100644 --- a/common/src/main/java/org/astraea/common/balancer/tweakers/ShuffleTweaker.java +++ b/common/src/main/java/org/astraea/common/balancer/tweakers/ShuffleTweaker.java @@ -80,7 +80,7 @@ public Stream generate(ClusterInfo baseAllocation) { .filter(tp -> this.allowedTopics.test(tp.topic())) .filter(tp -> eligiblePartition(baseAllocation.replicas(tp))) .flatMap(baseAllocation::replicaStream) - .filter(r -> this.allowedBrokers.test(r.nodeInfo().id())) + .filter(r -> this.allowedBrokers.test(r.broker().id())) .toList(); return Stream.generate( @@ -108,7 +108,7 @@ public Stream generate(ClusterInfo baseAllocation) { // leader pair follower, follower pair leader .filter(r -> r.isFollower() != sourceReplica.isFollower()) // this follower is located at allowed broker - .filter(r -> this.allowedBrokers.test(r.nodeInfo().id())) + .filter(r -> this.allowedBrokers.test(r.broker().id())) // not forbidden .filter(r -> !forbiddenReplica.contains(r.topicPartitionReplica())) .map(r -> Map.entry(r, ThreadLocalRandom.current().nextInt())) @@ -136,7 +136,7 @@ public Stream generate(ClusterInfo baseAllocation) { baseAllocation.brokers().stream() // the candidate should not be part of the replica list .filter( - b -> replicaList.stream().noneMatch(r -> r.nodeInfo().id() == b.id())) + b -> replicaList.stream().noneMatch(r -> r.broker().id() == b.id())) // should be an allowed broker .filter(b -> this.allowedBrokers.test(b.id())) .map(b -> Map.entry(b, ThreadLocalRandom.current().nextInt())) diff --git a/common/src/main/java/org/astraea/common/cost/BrokerDiskSpaceCost.java b/common/src/main/java/org/astraea/common/cost/BrokerDiskSpaceCost.java index e524e1a31f..855eb340ef 100644 --- a/common/src/main/java/org/astraea/common/cost/BrokerDiskSpaceCost.java +++ b/common/src/main/java/org/astraea/common/cost/BrokerDiskSpaceCost.java @@ -22,8 +22,8 @@ import java.util.stream.Stream; import org.astraea.common.Configuration; import org.astraea.common.DataSize; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.metrics.ClusterBean; @@ -74,7 +74,7 @@ static boolean brokerDiskUsageSizeOverflow( ClusterInfo before, ClusterInfo after, Map brokerMoveCostLimit) { for (var id : Stream.concat(before.nodes().stream(), after.nodes().stream()) - .map(NodeInfo::id) + .map(Broker::id) .parallel() .collect(Collectors.toSet())) { diff --git a/common/src/main/java/org/astraea/common/cost/CostUtils.java b/common/src/main/java/org/astraea/common/cost/CostUtils.java index b23985d657..e1792d2ad6 100644 --- a/common/src/main/java/org/astraea/common/cost/CostUtils.java +++ b/common/src/main/java/org/astraea/common/cost/CostUtils.java @@ -20,7 +20,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.Replica; final class CostUtils { @@ -33,7 +33,7 @@ static boolean changedRecordSizeOverflow( var totalAddedSize = 0L; for (var id : Stream.concat(before.nodes().stream(), after.nodes().stream()) - .map(NodeInfo::id) + .map(Broker::id) .parallel() .collect(Collectors.toSet())) { var removed = diff --git a/common/src/main/java/org/astraea/common/cost/MigrationCost.java b/common/src/main/java/org/astraea/common/cost/MigrationCost.java index f580d6ee71..55f460d165 100644 --- a/common/src/main/java/org/astraea/common/cost/MigrationCost.java +++ b/common/src/main/java/org/astraea/common/cost/MigrationCost.java @@ -23,7 +23,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.Replica; public class MigrationCost { @@ -107,11 +107,11 @@ private static Map migratedChanged( }) .collect( Collectors.groupingBy( - r -> r.nodeInfo().id(), + r -> r.broker().id(), Collectors.mapping( Function.identity(), Collectors.summingLong(replicaFunction::apply)))); return Stream.concat(dest.nodes().stream(), source.nodes().stream()) - .map(NodeInfo::id) + .map(Broker::id) .distinct() .parallel() .collect(Collectors.toMap(Function.identity(), n -> cost.getOrDefault(n, 0L))); @@ -119,7 +119,7 @@ private static Map migratedChanged( private static Map changedReplicaNumber(ClusterInfo before, ClusterInfo after) { return Stream.concat(before.nodes().stream(), after.nodes().stream()) - .map(NodeInfo::id) + .map(Broker::id) .distinct() .parallel() .collect( diff --git a/common/src/main/java/org/astraea/common/cost/NetworkCost.java b/common/src/main/java/org/astraea/common/cost/NetworkCost.java index bc12ae8e99..5269aaaba2 100644 --- a/common/src/main/java/org/astraea/common/cost/NetworkCost.java +++ b/common/src/main/java/org/astraea/common/cost/NetworkCost.java @@ -30,7 +30,7 @@ import org.astraea.common.EnumInfo; import org.astraea.common.admin.BrokerTopic; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.Replica; import org.astraea.common.admin.TopicPartition; import org.astraea.common.cost.utils.ClusterInfoSensor; @@ -114,7 +114,7 @@ public ClusterCost clusterCost(ClusterInfo clusterInfo, ClusterBean clusterBean) clusterInfo.brokers().stream() .collect( Collectors.toMap( - NodeInfo::id, + Broker::id, broker -> clusterInfo .replicaStream(broker.id()) @@ -128,7 +128,7 @@ public ClusterCost clusterCost(ClusterInfo clusterInfo, ClusterBean clusterBean) clusterInfo.brokers().stream() .collect( Collectors.toMap( - NodeInfo::id, + Broker::id, broker -> clusterInfo .replicaStream(broker.id()) @@ -210,7 +210,7 @@ private Map> mapLeaderAllocation(ClusterInfo clusterI .replicaStream() .filter(Replica::isOnline) .filter(Replica::isLeader) - .map(r -> Map.entry(BrokerTopic.of(r.nodeInfo().id(), r.topic()), r)) + .map(r -> Map.entry(BrokerTopic.of(r.broker().id(), r.topic()), r)) .collect( Collectors.groupingBy( Map.Entry::getKey, diff --git a/common/src/main/java/org/astraea/common/cost/NetworkIngressCost.java b/common/src/main/java/org/astraea/common/cost/NetworkIngressCost.java index 02d54cff92..aa4f99055f 100644 --- a/common/src/main/java/org/astraea/common/cost/NetworkIngressCost.java +++ b/common/src/main/java/org/astraea/common/cost/NetworkIngressCost.java @@ -60,7 +60,7 @@ public PartitionCost partitionCost(ClusterInfo clusterInfo, ClusterBean clusterB .filter(Replica::isOnline) .collect( Collectors.groupingBy( - replica -> replica.nodeInfo().id(), + replica -> replica.broker().id(), Collectors.toMap( Replica::topicPartition, r -> partitionTraffic.get(r.topicPartition())))); diff --git a/common/src/main/java/org/astraea/common/cost/NodeMetricsCost.java b/common/src/main/java/org/astraea/common/cost/NodeMetricsCost.java index 3fc5431e81..2cc67e755e 100644 --- a/common/src/main/java/org/astraea/common/cost/NodeMetricsCost.java +++ b/common/src/main/java/org/astraea/common/cost/NodeMetricsCost.java @@ -22,7 +22,7 @@ import java.util.Map; import java.util.stream.Collectors; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.metrics.ClusterBean; import org.astraea.common.metrics.client.HasNodeMetrics; import org.astraea.common.metrics.client.producer.ProducerMetrics; @@ -60,7 +60,7 @@ public BrokerCost brokerCost(ClusterInfo clusterInfo, ClusterBean clusterBean) { .ifPresent( max -> clusterInfo.nodes().stream() - .map(NodeInfo::id) + .map(Broker::id) .filter(id -> !result.containsKey(id)) .forEach(id -> result.put(id, max))); return () -> result; diff --git a/common/src/main/java/org/astraea/common/cost/RecordSizeCost.java b/common/src/main/java/org/astraea/common/cost/RecordSizeCost.java index 9cbf965952..08bcd38fa3 100644 --- a/common/src/main/java/org/astraea/common/cost/RecordSizeCost.java +++ b/common/src/main/java/org/astraea/common/cost/RecordSizeCost.java @@ -23,7 +23,7 @@ import org.astraea.common.Configuration; import org.astraea.common.DataSize; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.Replica; import org.astraea.common.metrics.ClusterBean; @@ -46,7 +46,7 @@ public BrokerCost brokerCost(ClusterInfo clusterInfo, ClusterBean clusterBean) { clusterInfo.nodes().stream() .collect( Collectors.toMap( - NodeInfo::id, + Broker::id, n -> clusterInfo.replicaStream(n.id()).mapToDouble(Replica::size).sum())); return () -> result; } diff --git a/common/src/main/java/org/astraea/common/cost/ReplicaLeaderSizeCost.java b/common/src/main/java/org/astraea/common/cost/ReplicaLeaderSizeCost.java index d489834fa8..50f9a91539 100644 --- a/common/src/main/java/org/astraea/common/cost/ReplicaLeaderSizeCost.java +++ b/common/src/main/java/org/astraea/common/cost/ReplicaLeaderSizeCost.java @@ -67,7 +67,7 @@ public BrokerCost brokerCost(ClusterInfo clusterInfo, ClusterBean clusterBean) { clusterInfo.replicas().stream() .collect( Collectors.groupingBy( - r -> r.nodeInfo().id(), + r -> r.broker().id(), Collectors.mapping( r -> clusterInfo diff --git a/common/src/main/java/org/astraea/common/cost/ReplicaNumberCost.java b/common/src/main/java/org/astraea/common/cost/ReplicaNumberCost.java index 2460f17766..d2605ccfbe 100644 --- a/common/src/main/java/org/astraea/common/cost/ReplicaNumberCost.java +++ b/common/src/main/java/org/astraea/common/cost/ReplicaNumberCost.java @@ -22,7 +22,7 @@ import java.util.stream.Collectors; import org.astraea.common.Configuration; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.metrics.ClusterBean; /** more replicas migrate -> higher cost */ @@ -59,12 +59,12 @@ public ClusterCost clusterCost(ClusterInfo clusterInfo, ClusterBean clusterBean) var replicaPerBroker = clusterInfo .replicaStream() - .collect(Collectors.groupingBy(r -> r.nodeInfo().id(), Collectors.counting())); + .collect(Collectors.groupingBy(r -> r.broker().id(), Collectors.counting())); var summary = replicaPerBroker.values().stream().mapToLong(x -> x).summaryStatistics(); var anyBrokerEmpty = clusterInfo.brokers().stream() - .map(NodeInfo::id) + .map(Broker::id) .anyMatch(alive -> !replicaPerBroker.containsKey(alive)); var max = summary.getMax(); var min = anyBrokerEmpty ? 0 : summary.getMin(); diff --git a/common/src/main/java/org/astraea/common/cost/utils/ClusterInfoSensor.java b/common/src/main/java/org/astraea/common/cost/utils/ClusterInfoSensor.java index 1e994b9f35..af49af3146 100644 --- a/common/src/main/java/org/astraea/common/cost/utils/ClusterInfoSensor.java +++ b/common/src/main/java/org/astraea/common/cost/utils/ClusterInfoSensor.java @@ -23,7 +23,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.Replica; import org.astraea.common.metrics.ClusterBean; import org.astraea.common.metrics.HasBeanObject; @@ -59,8 +59,8 @@ public static ClusterInfo metricViewCluster(ClusterBean clusterBean) { var nodes = clusterBean.brokerIds().stream() .filter(id -> id != -1) - .map(id -> NodeInfo.of(id, "", -1)) - .collect(Collectors.toUnmodifiableMap(NodeInfo::id, x -> x)); + .map(id -> Broker.of(id, "", -1)) + .collect(Collectors.toUnmodifiableMap(Broker::id, x -> x)); var replicas = clusterBean.brokerTopics().stream() .filter(bt -> bt.broker() != -1) @@ -102,7 +102,7 @@ public static ClusterInfo metricViewCluster(ClusterBean clusterBean) { Replica.builder() .topic(tp.topic()) .partition(tp.partition()) - .nodeInfo(nodes.get(broker)) + .broker(nodes.get(broker)) .path("") .size(size); var isLeader = m.value() != 0; diff --git a/common/src/main/java/org/astraea/common/metrics/MetricSeriesBuilder.java b/common/src/main/java/org/astraea/common/metrics/MetricSeriesBuilder.java index f4c00cdedc..08db00f62f 100644 --- a/common/src/main/java/org/astraea/common/metrics/MetricSeriesBuilder.java +++ b/common/src/main/java/org/astraea/common/metrics/MetricSeriesBuilder.java @@ -28,7 +28,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.Replica; import org.astraea.common.admin.TopicPartition; import org.astraea.common.function.Bi3Function; @@ -131,7 +131,7 @@ public MetricSeriesBuilder seriesByBrokerTopic( cluster.nodes().stream() .collect( Collectors.toUnmodifiableMap( - NodeInfo::id, + Broker::id, node -> Stream.iterate( start, @@ -162,7 +162,7 @@ public MetricSeriesBuilder seriesByBrokerPartition( cluster.nodes().stream() .collect( Collectors.toUnmodifiableMap( - NodeInfo::id, + Broker::id, node -> Stream.iterate( start, @@ -192,7 +192,7 @@ public MetricSeriesBuilder seriesByBrokerReplica( cluster.nodes().stream() .collect( Collectors.toUnmodifiableMap( - NodeInfo::id, + Broker::id, node -> Stream.iterate( start, diff --git a/common/src/main/java/org/astraea/common/partitioner/RoundRobinKeeper.java b/common/src/main/java/org/astraea/common/partitioner/RoundRobinKeeper.java index c0f0680a15..eeb4b7c262 100644 --- a/common/src/main/java/org/astraea/common/partitioner/RoundRobinKeeper.java +++ b/common/src/main/java/org/astraea/common/partitioner/RoundRobinKeeper.java @@ -23,7 +23,7 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; public class RoundRobinKeeper { private final AtomicInteger next = new AtomicInteger(0); @@ -46,7 +46,7 @@ void tryToUpdate(ClusterInfo clusterInfo, Supplier> costToS == now) { var roundRobin = RoundRobin.smooth(costToScore.get()); var ids = - clusterInfo.nodes().stream().map(NodeInfo::id).collect(Collectors.toUnmodifiableSet()); + clusterInfo.nodes().stream().map(Broker::id).collect(Collectors.toUnmodifiableSet()); // TODO: make ROUND_ROBIN_LENGTH configurable ??? for (var index = 0; index < this.roundRobin.length; ++index) this.roundRobin[index] = roundRobin.next(ids).orElse(-1); diff --git a/common/src/test/java/org/astraea/common/admin/AdminTest.java b/common/src/test/java/org/astraea/common/admin/AdminTest.java index 42465de7a5..7eb7e8eca1 100644 --- a/common/src/test/java/org/astraea/common/admin/AdminTest.java +++ b/common/src/test/java/org/astraea/common/admin/AdminTest.java @@ -358,7 +358,7 @@ void testOrder() { .sorted( Comparator.comparing(Replica::topic) .thenComparing(Replica::partition) - .thenComparing(r -> r.nodeInfo().id())) + .thenComparing(r -> r.broker().id())) .collect(Collectors.toList()), replicas); } @@ -416,7 +416,7 @@ void testMoveToAnotherFolder() { var replica = replicas.get(0); var idAndFolder = SERVICE.dataFolders().entrySet().stream() - .filter(e -> e.getKey() == replica.nodeInfo().id()) + .filter(e -> e.getKey() == replica.broker().id()) .map(e -> Map.of(e.getKey(), e.getValue().iterator().next())) .findFirst() .get(); @@ -433,7 +433,7 @@ void testMoveToAnotherFolder() { Assertions.assertEquals(1, newReplicas.size()); var newReplica = newReplicas.get(0); - Assertions.assertEquals(idAndFolder.get(newReplica.nodeInfo().id()), newReplica.path()); + Assertions.assertEquals(idAndFolder.get(newReplica.broker().id()), newReplica.path()); } } @@ -589,7 +589,7 @@ void testDeclarePreferredFoldersWithNoCrossBrokerMovement() { r -> Replica.builder(r) .path( - source.brokerFolders().get(r.nodeInfo().id()).stream() + source.brokerFolders().get(r.broker().id()).stream() .filter(p -> !p.equals(r.path())) .findAny() .orElseThrow()) @@ -719,7 +719,7 @@ void testMigrateToOtherFolders() { .replicaStream() .iterator() .next() - .nodeInfo() + .broker() .id(); var paths = new ArrayList<>(SERVICE.dataFolders().get(id)); @@ -1047,7 +1047,7 @@ void testMigrateSinglePartition() { var partitionReplicas = admin.clusterInfo(Set.of(topic)).toCompletableFuture().join().replicas(); return partitionReplicas.size() == 1 - && partitionReplicas.get(0).nodeInfo().id() == broker; + && partitionReplicas.get(0).broker().id() == broker; }); var currentBroker = @@ -1059,7 +1059,7 @@ void testMigrateSinglePartition() { .filter(replica -> replica.partition() == 0) .findFirst() .get() - .nodeInfo() + .broker() .id(); var allPath = admin.brokerFolders().toCompletableFuture().join(); var otherPath = @@ -1114,7 +1114,7 @@ void testIllegalMigrationArgument() { .findFirst() .get(); - var currentBroker = currentReplica.nodeInfo().id(); + var currentBroker = currentReplica.broker().id(); var notExistReplica = (currentBroker + 1) % SERVICE.dataFolders().keySet().size(); var nextDir = SERVICE.dataFolders().get(notExistReplica).iterator().next(); @@ -1144,7 +1144,7 @@ void testMigrateAllPartitions() { Utils.waitFor( () -> { var replicas = admin.clusterInfo(Set.of(topic)).toCompletableFuture().join().replicas(); - return replicas.stream().allMatch(r -> r.nodeInfo().id() == broker); + return replicas.stream().allMatch(r -> r.broker().id() == broker); }); } } @@ -1388,7 +1388,7 @@ void testReplicasPreferredLeaderFlag() { Collectors.groupingBy( replica -> TopicPartition.of(replica.topic(), replica.partition()), Collectors.mapping( - replica -> replica.nodeInfo().id(), Collectors.toList()))); + replica -> replica.broker().id(), Collectors.toList()))); IntStream.range(0, partitionCount) .forEach(p -> admin.moveToBrokers(Map.of(TopicPartition.of(topic, p), List.of(0, 1, 2)))); diff --git a/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java b/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java index 0b9daa3af5..8b189124a8 100644 --- a/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java +++ b/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java @@ -165,7 +165,7 @@ void testReplicas() { var offlineReplicas = replicas.stream().filter(Replica::isOffline).collect(Collectors.toList()); Assertions.assertNotEquals(PARTITIONS, offlineReplicas.size()); - offlineReplicas.forEach(r -> Assertions.assertTrue(r.nodeInfo().offline())); + offlineReplicas.forEach(r -> Assertions.assertTrue(r.broker().offline())); offlineReplicas.forEach(r -> Assertions.assertNull(r.path())); offlineReplicas.forEach(r -> Assertions.assertEquals(-1, r.size())); offlineReplicas.forEach(r -> Assertions.assertEquals(-1, r.lag())); diff --git a/common/src/test/java/org/astraea/common/admin/ClusterInfoBuilderTest.java b/common/src/test/java/org/astraea/common/admin/ClusterInfoBuilderTest.java index b7d2851632..cd295971a1 100644 --- a/common/src/test/java/org/astraea/common/admin/ClusterInfoBuilderTest.java +++ b/common/src/test/java/org/astraea/common/admin/ClusterInfoBuilderTest.java @@ -38,7 +38,7 @@ void testBuild() { Replica.builder() .topic("MyTopic") .partition(0) - .nodeInfo(host1000) + .broker(host1000) .size(1024) .isPreferredLeader(true) .isLeader(true) @@ -160,7 +160,7 @@ void addTopic() { path -> cluster .replicaStream() - .filter(r -> r.nodeInfo().id() == id) + .filter(r -> r.broker().id() == id) .filter(r -> r.path().equals(path)) .count())); var summary = folderLogs.values().stream().mapToLong(x -> x).summaryStatistics(); @@ -214,7 +214,7 @@ void reassignReplica() { (short) 2, (replica) -> Replica.builder(replica) - .nodeInfo(base.node(replica.isPreferredLeader() ? 1 : 2)) + .broker(base.node(replica.isPreferredLeader() ? 1 : 2)) .path(replica.isPreferredLeader() ? "/ssd1" : "/ssd2") .build()) .build(); @@ -236,22 +236,22 @@ void reassignReplica() { original .replicaStream() .filter(Replica::isPreferredLeader) - .allMatch(r -> r.nodeInfo().id() == 1 && r.path().equals("/ssd1"))); + .allMatch(r -> r.broker().id() == 1 && r.path().equals("/ssd1"))); Assertions.assertTrue( original .replicaStream() .filter(Predicate.not(Replica::isPreferredLeader)) - .allMatch(r -> r.nodeInfo().id() == 2 && r.path().equals("/ssd2"))); + .allMatch(r -> r.broker().id() == 2 && r.path().equals("/ssd2"))); Assertions.assertTrue( altered .replicaStream() .filter(Replica::isPreferredLeader) - .allMatch(r -> r.nodeInfo().id() == 3 && r.path().equals("/ssd3"))); + .allMatch(r -> r.broker().id() == 3 && r.path().equals("/ssd3"))); Assertions.assertTrue( altered .replicaStream() .filter(Predicate.not(Replica::isPreferredLeader)) - .allMatch(r -> r.nodeInfo().id() == 4 && r.path().equals("/ssd4"))); + .allMatch(r -> r.broker().id() == 4 && r.path().equals("/ssd4"))); Assertions.assertThrows( IllegalArgumentException.class, @@ -287,8 +287,8 @@ void setPreferredLeader() { (short) 4, (replica) -> Replica.builder(replica) - .isLeader(replica.nodeInfo().id() == 0) - .isPreferredLeader(replica.nodeInfo().id() == 0) + .isLeader(replica.broker().id() == 0) + .isPreferredLeader(replica.broker().id() == 0) .build()) .build(); var altered = @@ -303,19 +303,19 @@ void setPreferredLeader() { original .replicaStream() .filter((Replica::isPreferredLeader)) - .allMatch(r -> r.nodeInfo().id() == 0)); + .allMatch(r -> r.broker().id() == 0)); Assertions.assertTrue( - original.replicaStream().filter((Replica::isLeader)).allMatch(r -> r.nodeInfo().id() == 0)); + original.replicaStream().filter((Replica::isLeader)).allMatch(r -> r.broker().id() == 0)); Assertions.assertTrue( altered .replicaStream() .filter(Replica::isPreferredLeader) - .allMatch(r -> r.nodeInfo().id() == r.partition())); + .allMatch(r -> r.broker().id() == r.partition())); Assertions.assertTrue( altered .replicaStream() .filter(Replica::isLeader) - .allMatch(r -> r.nodeInfo().id() == r.partition())); + .allMatch(r -> r.broker().id() == r.partition())); Assertions.assertThrows( IllegalArgumentException.class, () -> diff --git a/common/src/test/java/org/astraea/common/admin/ClusterInfoTest.java b/common/src/test/java/org/astraea/common/admin/ClusterInfoTest.java index f965fd57ad..e42ff9c3c7 100644 --- a/common/src/test/java/org/astraea/common/admin/ClusterInfoTest.java +++ b/common/src/test/java/org/astraea/common/admin/ClusterInfoTest.java @@ -48,7 +48,7 @@ public static ClusterInfo of(List replicas) { return ClusterInfo.of( "fake", replicas.stream() - .map(Replica::nodeInfo) + .map(Replica::broker) .collect(Collectors.groupingBy(NodeInfo::id, Collectors.reducing((x, y) -> x))) .values() .stream() @@ -100,7 +100,7 @@ void testReturnCollectionUnmodifiable() { Replica.builder() .topic("topic") .partition(0) - .nodeInfo(NodeInfo.of(0, "", -1)) + .broker(NodeInfo.of(0, "", -1)) .path("f") .buildLeader(); Assertions.assertThrows(Exception.class, () -> cluster.replicas().add(replica)); diff --git a/common/src/test/java/org/astraea/common/admin/ClusterInfoWithOfflineNodeTest.java b/common/src/test/java/org/astraea/common/admin/ClusterInfoWithOfflineNodeTest.java index 4eed309d31..8427928c8a 100644 --- a/common/src/test/java/org/astraea/common/admin/ClusterInfoWithOfflineNodeTest.java +++ b/common/src/test/java/org/astraea/common/admin/ClusterInfoWithOfflineNodeTest.java @@ -77,18 +77,18 @@ void testClusterInfoWithOfflineNode() { "One of the rest replicas should take over the leadership"); Assertions.assertTrue( after.availableReplicas(topicName).stream() - .allMatch(x -> x.nodeInfo().id() != brokerToClose)); + .allMatch(x -> x.broker().id() != brokerToClose)); Assertions.assertTrue( after.replicaLeaders(topicName).stream() - .allMatch(x -> x.nodeInfo().id() != brokerToClose)); + .allMatch(x -> x.broker().id() != brokerToClose)); Assertions.assertTrue( after.replicas(topicName).stream() .filter(Replica::isOffline) - .allMatch(x -> x.nodeInfo().id() == brokerToClose)); + .allMatch(x -> x.broker().id() == brokerToClose)); Assertions.assertTrue( after.replicas(topicName).stream() .filter(x -> !x.isOffline()) - .allMatch(x -> x.nodeInfo().id() != brokerToClose)); + .allMatch(x -> x.broker().id() != brokerToClose)); } } } diff --git a/common/src/test/java/org/astraea/common/admin/SomePartitionOfflineTest.java b/common/src/test/java/org/astraea/common/admin/SomePartitionOfflineTest.java index 812d78c3cb..624379db1e 100644 --- a/common/src/test/java/org/astraea/common/admin/SomePartitionOfflineTest.java +++ b/common/src/test/java/org/astraea/common/admin/SomePartitionOfflineTest.java @@ -63,7 +63,7 @@ void somePartitionsOffline() { .toCompletableFuture() .join() .replicaStream() - .filter(replica -> replica.nodeInfo().id() == 0) + .filter(replica -> replica.broker().id() == 0) .collect( Collectors.groupingBy( replica -> TopicPartition.of(replica.topic(), replica.partition()))); @@ -78,7 +78,7 @@ void somePartitionsOffline() { .toCompletableFuture() .join() .replicaStream() - .filter(replica -> replica.nodeInfo().id() == 0) + .filter(replica -> replica.broker().id() == 0) .collect( Collectors.groupingBy( replica -> TopicPartition.of(replica.topic(), replica.partition()))); diff --git a/common/src/test/java/org/astraea/common/balancer/BalancerConfigTestSuite.java b/common/src/test/java/org/astraea/common/balancer/BalancerConfigTestSuite.java index 693c2be146..fa51b98d01 100644 --- a/common/src/test/java/org/astraea/common/balancer/BalancerConfigTestSuite.java +++ b/common/src/test/java/org/astraea/common/balancer/BalancerConfigTestSuite.java @@ -239,7 +239,7 @@ static void assertOnlyAllowedBrokerMovement( source .replicaStream() // for those replicas that are not allowed to move - .filter(r -> !allowedBroker.test(r.nodeInfo().id())) + .filter(r -> !allowedBroker.test(r.broker().id())) // they should exist as-is in the target allocation .forEach( fixedReplica -> { diff --git a/common/src/test/java/org/astraea/common/balancer/FakeClusterInfo.java b/common/src/test/java/org/astraea/common/balancer/FakeClusterInfo.java index 3857c4d145..c435b23ebc 100644 --- a/common/src/test/java/org/astraea/common/balancer/FakeClusterInfo.java +++ b/common/src/test/java/org/astraea/common/balancer/FakeClusterInfo.java @@ -79,67 +79,18 @@ public static ClusterInfo of( .mapToObj(nodeId -> NodeInfo.of(nodeId, "host" + nodeId, 9092)) .map( node -> - new Broker() { - @Override - public boolean isController() { - throw new UnsupportedOperationException(); - } - - @Override - public Config config() { - throw new UnsupportedOperationException(); - } - - @Override - public List dataFolders() { - return dataDirectories.stream() - .map( - x -> - new DataFolder() { - @Override - public String path() { - return x; - } - - @Override - public Map partitionSizes() { - throw new UnsupportedOperationException(); - } - - @Override - public Map orphanPartitionSizes() { - throw new UnsupportedOperationException(); - } - }) - .collect(Collectors.toUnmodifiableList()); - } - - @Override - public Set topicPartitions() { - throw new UnsupportedOperationException(); - } - - @Override - public Set topicPartitionLeaders() { - throw new UnsupportedOperationException(); - } - - @Override - public String host() { - return node.host(); - } - - @Override - public int port() { - return node.port(); - } - - @Override - public int id() { - return node.id(); - } - }) - .collect(Collectors.toUnmodifiableList()); + new Broker( + node.id(), + node.host(), + node.port(), + false, + new Config(Map.of()), + dataDirectories.stream() + .map(path -> new Broker.DataFolder(path, Map.of(), Map.of())) + .toList(), + Set.of(), + Set.of())) + .toList(); final var dataDirectoryList = List.copyOf(dataDirectories); final var topics = topicNameGenerator.apply(topicCount); final var replicas = @@ -156,7 +107,7 @@ public int id() { Replica.builder() .topic(tp.topic()) .partition(tp.partition()) - .nodeInfo(nodes.get(r)) + .broker(nodes.get(r)) .lag(0) .size(-1) .isLeader(r == 0) diff --git a/common/src/test/java/org/astraea/common/balancer/executor/StraightPlanExecutorTest.java b/common/src/test/java/org/astraea/common/balancer/executor/StraightPlanExecutorTest.java index 2db29c6073..e1c66f333d 100644 --- a/common/src/test/java/org/astraea/common/balancer/executor/StraightPlanExecutorTest.java +++ b/common/src/test/java/org/astraea/common/balancer/executor/StraightPlanExecutorTest.java @@ -78,7 +78,7 @@ void testAsyncRun() { Replica.builder() .topic(tp.topic()) .partition(tp.partition()) - .nodeInfo(NodeInfo.of(broker0, "", -1)) + .broker(NodeInfo.of(broker0, "", -1)) .lag(0) .size(0) .isLeader(true) @@ -91,7 +91,7 @@ void testAsyncRun() { Replica.builder() .topic(tp.topic()) .partition(tp.partition()) - .nodeInfo(NodeInfo.of(broker1, "", -1)) + .broker(NodeInfo.of(broker1, "", -1)) .lag(0) .size(0) .isLeader(false) @@ -163,7 +163,7 @@ void testDisableDataDirMigration() { replica -> Replica.builder(replica) .path( - source.brokerFolders().get(replica.nodeInfo().id()).stream() + source.brokerFolders().get(replica.broker().id()).stream() .filter(p -> !replica.path().equals(p)) .findAny() .orElseThrow()) diff --git a/common/src/test/java/org/astraea/common/balancer/tweakers/ShuffleTweakerTest.java b/common/src/test/java/org/astraea/common/balancer/tweakers/ShuffleTweakerTest.java index baef67f81a..6b0265d474 100644 --- a/common/src/test/java/org/astraea/common/balancer/tweakers/ShuffleTweakerTest.java +++ b/common/src/test/java/org/astraea/common/balancer/tweakers/ShuffleTweakerTest.java @@ -167,7 +167,7 @@ void testEligiblePartition() { Replica.builder() .topic("topic") .partition(0) - .nodeInfo(nodeA) + .broker(nodeA) .lag(0) .size(0) .isLeader(false) @@ -185,8 +185,8 @@ void testEligiblePartition() { .isLeader(true) .isPreferredLeader(true) .build(), - Replica.builder(base).topic("normal-topic").nodeInfo(nodeB).build(), - Replica.builder(base).topic("normal-topic").nodeInfo(nodeC).build(), + Replica.builder(base).topic("normal-topic").broker(nodeB).build(), + Replica.builder(base).topic("normal-topic").broker(nodeC).build(), Replica.builder(base) .topic("offline-single") .isPreferredLeader(true) @@ -195,10 +195,10 @@ void testEligiblePartition() { Replica.builder(base) .topic("no-leader") .isPreferredLeader(true) - .nodeInfo(nodeA) + .broker(nodeA) .build(), - Replica.builder(base).topic("no-leader").nodeInfo(nodeB).build(), - Replica.builder(base).topic("no-leader").nodeInfo(nodeC).build())); + Replica.builder(base).topic("no-leader").broker(nodeB).build(), + Replica.builder(base).topic("no-leader").broker(nodeC).build())); shuffleTweaker .generate(allocation) .limit(30) diff --git a/common/src/test/java/org/astraea/common/cost/BrokerDiskSpaceCostTest.java b/common/src/test/java/org/astraea/common/cost/BrokerDiskSpaceCostTest.java index 0e4c998737..da9954d8d9 100644 --- a/common/src/test/java/org/astraea/common/cost/BrokerDiskSpaceCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/BrokerDiskSpaceCostTest.java @@ -54,42 +54,42 @@ void testMoveCosts() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(2) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(2) - .nodeInfo(NodeInfo.of(2, "broker0", 1111)) + .broker(NodeInfo.of(2, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build()); @@ -98,42 +98,42 @@ void testMoveCosts() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(2, "broker0", 1111)) + .broker(NodeInfo.of(2, "broker0", 1111)) .size(dataSize.bytes()) .path("/path1") .build(), Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(2, "broker0", 1111)) + .broker(NodeInfo.of(2, "broker0", 1111)) .size(dataSize.bytes()) .path("/path1") .build(), Replica.builder() .topic("topic1") .partition(2) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(2) - .nodeInfo(NodeInfo.of(2, "broker0", 1111)) + .broker(NodeInfo.of(2, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build()); @@ -235,7 +235,7 @@ public static ClusterInfo of(List replicas) { return ClusterInfo.of( "fake", replicas.stream() - .map(Replica::nodeInfo) + .map(Replica::broker) .distinct() .map( nodeInfo -> @@ -282,7 +282,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(100) .isLeader(true) .path("/path0") @@ -290,7 +290,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .size(99) .isLeader(false) .path("/path0") @@ -298,7 +298,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(500) .isLeader(true) .path("/path0") @@ -306,7 +306,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .size(499) .isLeader(false) .path("/path0") @@ -314,7 +314,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .nodeInfo(NodeInfo.of(2, "broker0", 1111)) + .broker(NodeInfo.of(2, "broker0", 1111)) .size(1000) .isLeader(true) .path("/path0") @@ -322,7 +322,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(1000) .isLeader(false) .path("/path0") @@ -330,7 +330,7 @@ private static ClusterInfo beforeClusterInfo() { return ClusterInfo.of( "fake", replicas.stream() - .map(Replica::nodeInfo) + .map(Replica::broker) .distinct() .map( nodeInfo -> @@ -363,7 +363,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(2, "broker0", 1111)) + .broker(NodeInfo.of(2, "broker0", 1111)) .size(100) .isLeader(true) .path("/path1") @@ -371,7 +371,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .size(99) .isLeader(false) .path("/path0") @@ -379,7 +379,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(500) .isLeader(true) .path("/path0") @@ -387,7 +387,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(2, "broker0", 1111)) + .broker(NodeInfo.of(2, "broker0", 1111)) .size(500) .isLeader(false) .path("/path1") @@ -395,7 +395,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .size(1000) .isLeader(true) .path("/path1") @@ -403,7 +403,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(1000) .isLeader(false) .path("/path0") @@ -411,7 +411,7 @@ private static ClusterInfo afterClusterInfo() { return ClusterInfo.of( "fake", replicas.stream() - .map(Replica::nodeInfo) + .map(Replica::broker) .distinct() .map( nodeInfo -> diff --git a/common/src/test/java/org/astraea/common/cost/CostUtilsTest.java b/common/src/test/java/org/astraea/common/cost/CostUtilsTest.java index e086242e57..709e595c32 100644 --- a/common/src/test/java/org/astraea/common/cost/CostUtilsTest.java +++ b/common/src/test/java/org/astraea/common/cost/CostUtilsTest.java @@ -90,7 +90,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(100) .isLeader(true) .path("/path0") @@ -98,7 +98,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .size(99) .isLeader(false) .path("/path0") @@ -106,7 +106,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(500) .isLeader(true) .path("/path0") @@ -114,7 +114,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .size(499) .isLeader(false) .path("/path0") @@ -122,7 +122,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .nodeInfo(NodeInfo.of(2, "broker0", 1111)) + .broker(NodeInfo.of(2, "broker0", 1111)) .size(1000) .isLeader(true) .path("/path0") @@ -130,7 +130,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(1000) .isLeader(false) .path("/path0") @@ -138,7 +138,7 @@ private static ClusterInfo beforeClusterInfo() { return ClusterInfo.of( "fake", replicas.stream() - .map(Replica::nodeInfo) + .map(Replica::broker) .distinct() .map( nodeInfo -> @@ -171,7 +171,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(2, "broker0", 1111)) + .broker(NodeInfo.of(2, "broker0", 1111)) .size(100) .isLeader(true) .path("/path1") @@ -179,7 +179,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .size(99) .isLeader(false) .path("/path0") @@ -187,7 +187,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(500) .isLeader(true) .path("/path0") @@ -195,7 +195,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(2, "broker0", 1111)) + .broker(NodeInfo.of(2, "broker0", 1111)) .size(500) .isLeader(false) .path("/path1") @@ -203,7 +203,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .size(1000) .isLeader(true) .path("/path1") @@ -211,7 +211,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .size(1000) .isLeader(false) .path("/path0") @@ -219,7 +219,7 @@ private static ClusterInfo afterClusterInfo() { return ClusterInfo.of( "fake", replicas.stream() - .map(Replica::nodeInfo) + .map(Replica::broker) .distinct() .map( nodeInfo -> diff --git a/common/src/test/java/org/astraea/common/cost/MigrationCostTest.java b/common/src/test/java/org/astraea/common/cost/MigrationCostTest.java index 89ddd813bf..5e50d409a3 100644 --- a/common/src/test/java/org/astraea/common/cost/MigrationCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/MigrationCostTest.java @@ -36,7 +36,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -49,7 +49,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) @@ -62,7 +62,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -75,7 +75,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) @@ -90,7 +90,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(2, "broker0", 1111)) + .broker(NodeInfo.of(2, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -103,7 +103,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) @@ -116,7 +116,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -129,7 +129,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(2, "broker0", 1111)) + .broker(NodeInfo.of(2, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) @@ -176,7 +176,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -189,7 +189,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) @@ -202,7 +202,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -215,7 +215,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) @@ -230,7 +230,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(2, "broker0", 1111)) + .broker(NodeInfo.of(2, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -243,7 +243,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(0) - .nodeInfo(NodeInfo.of(1, "broker0", 1111)) + .broker(NodeInfo.of(1, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) @@ -256,7 +256,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(0, "broker0", 1111)) + .broker(NodeInfo.of(0, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -269,7 +269,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(1) - .nodeInfo(NodeInfo.of(2, "broker0", 1111)) + .broker(NodeInfo.of(2, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) diff --git a/common/src/test/java/org/astraea/common/cost/NetworkCostTest.java b/common/src/test/java/org/astraea/common/cost/NetworkCostTest.java index 7e7daaab04..ebf3869f26 100644 --- a/common/src/test/java/org/astraea/common/cost/NetworkCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/NetworkCostTest.java @@ -184,7 +184,7 @@ void testReplicationAware() { (short) 2, (r) -> Replica.builder(r) - .nodeInfo(base.node(iter1.next())) + .broker(base.node(iter1.next())) .isPreferredLeader(iter2.next()) .isLeader(iter3.next()) .size(1) @@ -195,7 +195,7 @@ void testReplicationAware() { (short) 2, (r) -> Replica.builder(r) - .nodeInfo(base.node(iter4.next())) + .broker(base.node(iter4.next())) .isPreferredLeader(iter5.next()) .isLeader(iter6.next()) .size(1) diff --git a/common/src/test/java/org/astraea/common/cost/RecordSizeCostTest.java b/common/src/test/java/org/astraea/common/cost/RecordSizeCostTest.java index 75698f3ad6..29ac2fc4ae 100644 --- a/common/src/test/java/org/astraea/common/cost/RecordSizeCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/RecordSizeCostTest.java @@ -40,21 +40,21 @@ public class RecordSizeCostTest { Replica.builder() .topic("topic") .partition(0) - .nodeInfo(NodeInfo.of(1, "aa", 22)) + .broker(NodeInfo.of(1, "aa", 22)) .size(100) .path("/tmp/aa") .buildLeader(), Replica.builder() .topic("topic") .partition(0) - .nodeInfo(NodeInfo.of(2, "aa", 22)) + .broker(NodeInfo.of(2, "aa", 22)) .size(99) .path("/tmp/aa") .buildInSyncFollower(), Replica.builder() .topic("topic") .partition(1) - .nodeInfo(NodeInfo.of(1, "aa", 22)) + .broker(NodeInfo.of(1, "aa", 22)) .size(11) .path("/tmp/aa") .buildLeader())); diff --git a/common/src/test/java/org/astraea/common/cost/ReplicaLeaderCostTest.java b/common/src/test/java/org/astraea/common/cost/ReplicaLeaderCostTest.java index 90f0a2db01..4208657147 100644 --- a/common/src/test/java/org/astraea/common/cost/ReplicaLeaderCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/ReplicaLeaderCostTest.java @@ -45,12 +45,12 @@ void testLeaderCount() { "topic1", 3, (short) 1, - r -> Replica.builder(r).nodeInfo(baseCluster.node(1)).build()) + r -> Replica.builder(r).broker(baseCluster.node(1)).build()) .addTopic( "topic2", 3, (short) 1, - r -> Replica.builder(r).nodeInfo(baseCluster.node(2)).build()) + r -> Replica.builder(r).broker(baseCluster.node(2)).build()) .build(); var overFlowTargetCluster = ClusterInfo.builder(baseCluster) @@ -58,12 +58,12 @@ void testLeaderCount() { "topic1", 3, (short) 1, - r -> Replica.builder(r).nodeInfo(baseCluster.node(2)).build()) + r -> Replica.builder(r).broker(baseCluster.node(2)).build()) .addTopic( "topic2", 3, (short) 1, - r -> Replica.builder(r).nodeInfo(baseCluster.node(1)).build()) + r -> Replica.builder(r).broker(baseCluster.node(1)).build()) .build(); var overFlowMoveCost = @@ -87,19 +87,19 @@ void testNoMetrics() { Replica.builder() .topic("topic") .partition(0) - .nodeInfo(NodeInfo.of(10, "broker0", 1111)) + .broker(NodeInfo.of(10, "broker0", 1111)) .path("/tmp/aa") .buildLeader(), Replica.builder() .topic("topic") .partition(0) - .nodeInfo(NodeInfo.of(10, "broker0", 1111)) + .broker(NodeInfo.of(10, "broker0", 1111)) .path("/tmp/aa") .buildLeader(), Replica.builder() .topic("topic") .partition(0) - .nodeInfo(NodeInfo.of(11, "broker1", 1111)) + .broker(NodeInfo.of(11, "broker1", 1111)) .path("/tmp/aa") .buildLeader()); var clusterInfo = diff --git a/common/src/test/java/org/astraea/common/cost/ReplicaLeaderSizeCostTest.java b/common/src/test/java/org/astraea/common/cost/ReplicaLeaderSizeCostTest.java index fe140a0d26..4bdda7c806 100644 --- a/common/src/test/java/org/astraea/common/cost/ReplicaLeaderSizeCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/ReplicaLeaderSizeCostTest.java @@ -74,28 +74,28 @@ private ClusterInfo clusterInfo() { .topic("t") .partition(10) .isLeader(true) - .nodeInfo(NodeInfo.of(0, "", -1)) + .broker(NodeInfo.of(0, "", -1)) .size(777) .build(), Replica.builder() .topic("t") .partition(11) .isLeader(true) - .nodeInfo(NodeInfo.of(1, "", -1)) + .broker(NodeInfo.of(1, "", -1)) .size(700) .build(), Replica.builder() .topic("t") .partition(12) .isLeader(true) - .nodeInfo(NodeInfo.of(2, "", -1)) + .broker(NodeInfo.of(2, "", -1)) .size(500) .build(), Replica.builder() .topic("t") .partition(12) .isLeader(false) - .nodeInfo(NodeInfo.of(0, "", -1)) + .broker(NodeInfo.of(0, "", -1)) .size(499) .build()); return ClusterInfo.of( diff --git a/common/src/test/java/org/astraea/common/cost/utils/ClusterInfoSensorTest.java b/common/src/test/java/org/astraea/common/cost/utils/ClusterInfoSensorTest.java index 639d8872d1..818660d2e6 100644 --- a/common/src/test/java/org/astraea/common/cost/utils/ClusterInfoSensorTest.java +++ b/common/src/test/java/org/astraea/common/cost/utils/ClusterInfoSensorTest.java @@ -101,7 +101,7 @@ void testClusterInfoSensor() { TopicPartition.of(topic, 1), TopicPartition.of(topic, 2)))); // compare broker id - Assertions.assertTrue(info.replicaStream().allMatch(r -> r.nodeInfo().id() == aBroker.id())); + Assertions.assertTrue(info.replicaStream().allMatch(r -> r.broker().id() == aBroker.id())); // compare replica size var realCluster = admin.clusterInfo(Set.of(topic)).toCompletableFuture().join(); Assertions.assertTrue( diff --git a/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerPerfTest.java b/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerPerfTest.java index b8c10b8d71..2c605161bf 100644 --- a/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerPerfTest.java +++ b/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerPerfTest.java @@ -65,19 +65,19 @@ void test() { Replica.builder() .topic("topic") .partition(0) - .nodeInfo(node0) + .broker(node0) .path("/tmp/aa") .buildLeader(), Replica.builder() .topic("topic") .partition(1) - .nodeInfo(node1) + .broker(node1) .path("/tmp/aa") .buildLeader(), Replica.builder() .topic("topic") .partition(2) - .nodeInfo(node2) + .broker(node2) .path("/tmp/aa") .buildLeader())); var admin = Mockito.mock(Admin.class); diff --git a/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerTest.java b/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerTest.java index 24a7718be2..47c102394b 100644 --- a/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerTest.java +++ b/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerTest.java @@ -112,7 +112,7 @@ void testSingleBroker() { .topic("topic") .partition(10) .path("/tmp/aa") - .nodeInfo(nodeInfo) + .broker(nodeInfo) .buildLeader(); try (var partitioner = new StrictCostPartitioner()) { partitioner.configure(Configuration.EMPTY); @@ -138,14 +138,14 @@ void testCostFunctionWithoutSensor() { .topic("topic") .partition(0) .path("/tmp/aa") - .nodeInfo(NodeInfo.of(10, "host", 11111)) + .broker(NodeInfo.of(10, "host", 11111)) .buildLeader(); var replicaInfo1 = Replica.builder() .topic("topic") .partition(0) .path("/tmp/aa") - .nodeInfo(NodeInfo.of(12, "host2", 11111)) + .broker(NodeInfo.of(12, "host2", 11111)) .buildLeader(); try (var partitioner = new StrictCostPartitioner()) { partitioner.configure( @@ -192,14 +192,14 @@ void testReturnedPartition() { .topic("topic") .partition(partitionId) .path("/tmp/aa") - .nodeInfo(NodeInfo.of(brokerId, "host", 11111)) + .broker(NodeInfo.of(brokerId, "host", 11111)) .buildLeader(); var replicaInfo1 = Replica.builder() .topic("topic") .partition(1) .path("/tmp/aa") - .nodeInfo(NodeInfo.of(1111, "host2", 11111)) + .broker(NodeInfo.of(1111, "host2", 11111)) .buildLeader(); Assertions.assertEquals( partitionId, diff --git a/gui/src/main/java/org/astraea/gui/Context.java b/gui/src/main/java/org/astraea/gui/Context.java index ecf305b7a3..c10baec19e 100644 --- a/gui/src/main/java/org/astraea/gui/Context.java +++ b/gui/src/main/java/org/astraea/gui/Context.java @@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicReference; import javafx.stage.Stage; import org.astraea.common.admin.Admin; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.connector.ConnectorClient; import org.astraea.common.metrics.JndiClient; @@ -73,9 +73,9 @@ public void workerJmxPort(int workerJmxPort) { } @SuppressWarnings("resource") - public Map addBrokerClients(List nodeInfos) { + public Map addBrokerClients(List brokers) { if (brokerClients == null) return Map.of(); - nodeInfos.forEach( + brokers.forEach( n -> brokerClients.clients.computeIfAbsent( n.id(), ignored -> JndiClient.of(n.host(), brokerClients.jmxPort))); diff --git a/gui/src/main/java/org/astraea/gui/tab/BrokerNode.java b/gui/src/main/java/org/astraea/gui/tab/BrokerNode.java index d66ac07ae0..874659ff16 100644 --- a/gui/src/main/java/org/astraea/gui/tab/BrokerNode.java +++ b/gui/src/main/java/org/astraea/gui/tab/BrokerNode.java @@ -38,7 +38,7 @@ import org.astraea.common.MapUtils; import org.astraea.common.admin.Broker; import org.astraea.common.admin.BrokerConfigs; -import org.astraea.common.admin.NodeInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.TopicPartition; import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.broker.ControllerMetrics; @@ -224,7 +224,7 @@ static Node metricsNode(Context context) { (argument, logger) -> context .admin() - .nodeInfos() + .brokers() .thenApply( nodes -> context.addBrokerClients(nodes).entrySet().stream() @@ -379,11 +379,11 @@ private static Node configNode(Context context) { brokers.stream() .collect( Collectors.toMap( - NodeInfo::id, b -> input.emptyValueKeys())); + Broker::id, b -> input.emptyValueKeys())); var set = brokers.stream() .collect( - Collectors.toMap(NodeInfo::id, b -> input.nonEmptyTexts())); + Collectors.toMap(Broker::id, b -> input.nonEmptyTexts())); if (unset.isEmpty() && set.isEmpty()) { logger.log("nothing to alter"); return CompletableFuture.completedStage(null); diff --git a/gui/src/main/java/org/astraea/gui/tab/health/BalancerNode.java b/gui/src/main/java/org/astraea/gui/tab/health/BalancerNode.java index 0b02005579..5841264c38 100644 --- a/gui/src/main/java/org/astraea/gui/tab/health/BalancerNode.java +++ b/gui/src/main/java/org/astraea/gui/tab/health/BalancerNode.java @@ -123,20 +123,20 @@ static List> assignmentResult(Balancer.Plan plan) { .filter(Replica::isLeader) .findFirst() .ifPresent( - r -> result.put(PREVIOUS_LEADER_KEY, r.nodeInfo().id() + ":" + r.path())); + r -> result.put(PREVIOUS_LEADER_KEY, r.broker().id() + ":" + r.path())); newAssignments.stream() .filter(Replica::isLeader) .findFirst() - .ifPresent(r -> result.put(NEW_LEADER_KEY, r.nodeInfo().id() + ":" + r.path())); + .ifPresent(r -> result.put(NEW_LEADER_KEY, r.broker().id() + ":" + r.path())); var previousFollowers = previousAssignments.stream() .filter(r -> !r.isLeader()) - .map(r -> r.nodeInfo().id() + ":" + r.path()) + .map(r -> r.broker().id() + ":" + r.path()) .collect(Collectors.joining(",")); var newFollowers = newAssignments.stream() .filter(r -> !r.isLeader()) - .map(r -> r.nodeInfo().id() + ":" + r.path()) + .map(r -> r.broker().id() + ":" + r.path()) .collect(Collectors.joining(",")); if (!previousFollowers.isBlank()) result.put(PREVIOUS_FOLLOWER_KEY, previousFollowers); diff --git a/gui/src/main/java/org/astraea/gui/tab/topic/ReplicaNode.java b/gui/src/main/java/org/astraea/gui/tab/topic/ReplicaNode.java index 3ee8168fd9..8d0e1905a5 100644 --- a/gui/src/main/java/org/astraea/gui/tab/topic/ReplicaNode.java +++ b/gui/src/main/java/org/astraea/gui/tab/topic/ReplicaNode.java @@ -64,7 +64,7 @@ static List> allResult(ClusterInfo clusterInfo) { result.put(TOPIC_NAME_KEY, replica.topic()); result.put(PARTITION_KEY, replica.partition()); result.put("internal", replica.internal()); - result.put("broker", replica.nodeInfo().id()); + result.put("broker", replica.broker().id()); if (replica.path() != null) result.put(PATH_KEY, replica.path()); result.put("isLeader", replica.isLeader()); result.put("isPreferredLeader", replica.isPreferredLeader()); @@ -195,7 +195,7 @@ static List> allResult(ClusterInfo clusterInfo) { .allMatch( entry -> rs.replicas(entry.getKey()).stream() - .map(r -> r.nodeInfo().id()) + .map(r -> r.broker().id()) .collect(Collectors.toSet()) .containsAll(entry.getValue())), Duration.ofSeconds(10), diff --git a/gui/src/main/java/org/astraea/gui/tab/topic/TopicNode.java b/gui/src/main/java/org/astraea/gui/tab/topic/TopicNode.java index bf3ec4fa2d..7fcdf3e730 100644 --- a/gui/src/main/java/org/astraea/gui/tab/topic/TopicNode.java +++ b/gui/src/main/java/org/astraea/gui/tab/topic/TopicNode.java @@ -38,7 +38,6 @@ import org.astraea.common.MapUtils; import org.astraea.common.admin.Broker; import org.astraea.common.admin.ConsumerGroup; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Partition; import org.astraea.common.admin.ProducerState; import org.astraea.common.admin.TopicConfigs; @@ -413,7 +412,7 @@ private static List> basicResult( "number of producer id", topicProducers.getOrDefault(topic, Set.of()).size()); ps.stream() .flatMap(p -> p.replicas().stream()) - .collect(Collectors.groupingBy(NodeInfo::id)) + .collect(Collectors.groupingBy(Broker::id)) .entrySet() .stream() .sorted(Map.Entry.comparingByKey()) diff --git a/gui/src/test/java/org/astraea/gui/tab/health/BalancerNodeTest.java b/gui/src/test/java/org/astraea/gui/tab/health/BalancerNodeTest.java index ebfe02274f..f13ce55ae6 100644 --- a/gui/src/test/java/org/astraea/gui/tab/health/BalancerNodeTest.java +++ b/gui/src/test/java/org/astraea/gui/tab/health/BalancerNodeTest.java @@ -113,7 +113,7 @@ void testResult() { .isPreferredLeader(false) .topic(topic) .partition(0) - .nodeInfo(allNodes.get(0)) + .broker(allNodes.get(0)) .size(leaderSize) .path("/tmp/aaa") .build(), @@ -122,7 +122,7 @@ void testResult() { .isPreferredLeader(true) .topic(topic) .partition(0) - .nodeInfo(allNodes.get(1)) + .broker(allNodes.get(1)) .size(leaderSize) .path("/tmp/bbb") .build()); @@ -133,7 +133,7 @@ void testResult() { .isPreferredLeader(false) .topic(topic) .partition(0) - .nodeInfo(allNodes.get(2)) + .broker(allNodes.get(2)) .size(leaderSize) .path("/tmp/ddd") .build(), @@ -142,7 +142,7 @@ void testResult() { .isPreferredLeader(true) .topic(topic) .partition(0) - .nodeInfo(allNodes.get(1)) + .broker(allNodes.get(1)) .size(leaderSize) .path("/tmp/bbb") .build()); diff --git a/gui/src/test/java/org/astraea/gui/tab/topic/ReplicaNodeTest.java b/gui/src/test/java/org/astraea/gui/tab/topic/ReplicaNodeTest.java index cea7020372..4a0e4efab9 100644 --- a/gui/src/test/java/org/astraea/gui/tab/topic/ReplicaNodeTest.java +++ b/gui/src/test/java/org/astraea/gui/tab/topic/ReplicaNodeTest.java @@ -124,7 +124,7 @@ void testTableAction() { .join() .replicas() .get(0) - .nodeInfo() + .broker() .id()); Assertions.assertEquals( path, @@ -150,7 +150,7 @@ void testResult() { .isLeader(true) .topic(topic) .partition(partition) - .nodeInfo(nodes.get(0)) + .broker(nodes.get(0)) .size(leaderSize) .path("/tmp/aaa") .build(), @@ -158,14 +158,14 @@ void testResult() { .isLeader(false) .topic(topic) .partition(partition) - .nodeInfo(nodes.get(1)) + .broker(nodes.get(1)) .size(20) .build(), Replica.builder() .isLeader(false) .topic(topic) .partition(partition) - .nodeInfo(nodes.get(2)) + .broker(nodes.get(2)) .size(30) .build()); var results = ReplicaNode.allResult(ClusterInfo.of("fake", nodes, Map.of(), replicas)); From c1ef216eedd97a740400c2b99d55ca85fbf5ef1a Mon Sep 17 00:00:00 2001 From: Chao-Heng Lee Date: Fri, 19 May 2023 23:28:33 +0800 Subject: [PATCH 02/11] replace NodeInfo with Broker. --- .../astraea/app/web/BalancerHandlerTest.java | 8 +-- .../astraea/app/web/ThrottleHandlerTest.java | 5 +- .../java/org/astraea/common/ByteUtils.java | 5 +- .../java/org/astraea/common/admin/Admin.java | 5 -- .../org/astraea/common/admin/AdminImpl.java | 12 +---- .../java/org/astraea/common/admin/Broker.java | 13 ++--- .../org/astraea/common/admin/ClusterInfo.java | 3 +- .../common/admin/ClusterInfoBuilder.java | 2 +- .../astraea/common/admin/ReplicaBuilder.java | 2 +- .../executor/StraightPlanExecutor.java | 3 +- .../org/astraea/common/cost/CostUtils.java | 2 +- .../astraea/common/cost/MigrationCost.java | 2 +- .../org/astraea/common/cost/NetworkCost.java | 2 +- .../astraea/common/cost/NodeMetricsCost.java | 2 +- .../astraea/common/cost/RecordSizeCost.java | 2 +- .../common/cost/ReplicaNumberCost.java | 2 +- .../common/cost/utils/ClusterInfoSensor.java | 2 +- .../common/metrics/MetricSeriesBuilder.java | 2 +- .../common/partitioner/RoundRobinKeeper.java | 2 +- .../org/astraea/common/admin/AdminTest.java | 6 +-- .../admin/AdminWithOfflineBrokerTest.java | 6 +-- .../common/admin/ClusterInfoBuilderTest.java | 14 +++--- .../astraea/common/admin/ClusterInfoTest.java | 4 +- .../admin/ClusterInfoWithOfflineNodeTest.java | 3 +- .../astraea/common/balancer/BalancerTest.java | 4 +- .../common/balancer/FakeClusterInfo.java | 3 +- .../executor/StraightPlanExecutorTest.java | 6 +-- .../balancer/tweakers/ShuffleTweakerTest.java | 8 +-- .../common/cost/BrokerDiskSpaceCostTest.java | 49 +++++++++---------- .../astraea/common/cost/CostUtilsTest.java | 25 +++++----- .../common/cost/MigrationCostTest.java | 34 ++++++------- .../common/cost/RecordSizeCostTest.java | 10 ++-- .../common/cost/ReplicaLeaderCostTest.java | 34 +++++-------- .../cost/ReplicaLeaderSizeCostTest.java | 12 ++--- .../StrictCostPartitionerPerfTest.java | 8 +-- .../StrictCostPartitionerTest.java | 12 ++--- .../java/org/astraea/gui/tab/BrokerNode.java | 4 +- .../gui/tab/health/BalancerNodeTest.java | 4 +- .../gui/tab/topic/ReplicaNodeTest.java | 3 +- 39 files changed, 139 insertions(+), 186 deletions(-) diff --git a/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java b/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java index 32166ac170..a48f9f843e 100644 --- a/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java +++ b/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java @@ -58,8 +58,8 @@ import org.astraea.common.DataSize; import org.astraea.common.Utils; import org.astraea.common.admin.Admin; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.admin.TopicPartition; import org.astraea.common.balancer.AlgorithmConfig; @@ -229,13 +229,13 @@ void testBestPlan() { var currentClusterInfo = ClusterInfo.of( "fake", - List.of(NodeInfo.of(10, "host", 22), NodeInfo.of(11, "host", 22)), + List.of(Broker.of(10, "host", 22), Broker.of(11, "host", 22)), Map.of(), List.of( Replica.builder() .topic("topic") .partition(0) - .broker(NodeInfo.of(10, "host", 22)) + .broker(Broker.of(10, "host", 22)) .lag(0) .size(100) .isLeader(true) @@ -1354,7 +1354,7 @@ private MetricStore metricStore(Admin admin, Set costFunctions) { brokers.stream() .collect( Collectors.toUnmodifiableMap( - NodeInfo::id, + Broker::id, b -> JndiClient.of(b.host(), brokerIdToJmxPort.apply(b.id()))))); var cf = Utils.costFunctions(costFunctions, HasClusterCost.class, Configuration.EMPTY); diff --git a/app/src/test/java/org/astraea/app/web/ThrottleHandlerTest.java b/app/src/test/java/org/astraea/app/web/ThrottleHandlerTest.java index eaa3966c9d..180bf83023 100644 --- a/app/src/test/java/org/astraea/app/web/ThrottleHandlerTest.java +++ b/app/src/test/java/org/astraea/app/web/ThrottleHandlerTest.java @@ -32,7 +32,6 @@ import org.astraea.common.admin.Admin; import org.astraea.common.admin.Broker; import org.astraea.common.admin.BrokerConfigs; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.TopicConfigs; import org.astraea.common.admin.TopicPartition; import org.astraea.common.json.JsonConverter; @@ -514,11 +513,11 @@ void testDelete() { Runnable setThrottle = () -> { admin - .nodeInfos() + .brokers() .thenApply( ns -> ns.stream() - .map(NodeInfo::id) + .map(Broker::id) .collect( Collectors.toMap( n -> n, diff --git a/common/src/main/java/org/astraea/common/ByteUtils.java b/common/src/main/java/org/astraea/common/ByteUtils.java index fa429abb38..f02b313124 100644 --- a/common/src/main/java/org/astraea/common/ByteUtils.java +++ b/common/src/main/java/org/astraea/common/ByteUtils.java @@ -26,11 +26,9 @@ import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; - import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Config; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.admin.Topic; import org.astraea.common.admin.TopicPartition; @@ -330,8 +328,7 @@ public static ClusterInfo readClusterInfo(byte[] bytes) { return ClusterInfo.of( outerClusterInfo.getClusterId(), outerClusterInfo.getNodeInfoList().stream() - .map( - nodeInfo -> Broker.of(nodeInfo.getId(), nodeInfo.getHost(), nodeInfo.getPort())) + .map(nodeInfo -> Broker.of(nodeInfo.getId(), nodeInfo.getHost(), nodeInfo.getPort())) .collect(Collectors.toList()), outerClusterInfo.getTopicList().stream() .map( diff --git a/common/src/main/java/org/astraea/common/admin/Admin.java b/common/src/main/java/org/astraea/common/admin/Admin.java index 45c58e3bb8..d6c7068ae2 100644 --- a/common/src/main/java/org/astraea/common/admin/Admin.java +++ b/common/src/main/java/org/astraea/common/admin/Admin.java @@ -164,11 +164,6 @@ default CompletionStage>>> lates CompletionStage> partitions(Set topics); - /** - * @return online node information - */ - CompletionStage> nodeInfos(); - /** * @return online broker information */ diff --git a/common/src/main/java/org/astraea/common/admin/AdminImpl.java b/common/src/main/java/org/astraea/common/admin/AdminImpl.java index 27ea4fa980..039a4274b3 100644 --- a/common/src/main/java/org/astraea/common/admin/AdminImpl.java +++ b/common/src/main/java/org/astraea/common/admin/AdminImpl.java @@ -444,13 +444,6 @@ public CompletionStage> partitions(Set topics) { .collect(Collectors.toList())); } - @Override - public CompletionStage> nodeInfos() { - return to(kafkaAdmin.describeCluster().nodes()) - .thenApply( - nodes -> nodes.stream().map(NodeInfo::of).collect(Collectors.toUnmodifiableList())); - } - @Override public CompletionStage> brokers() { return clusterIdAndBrokers().thenApply(Map.Entry::getValue); @@ -634,10 +627,7 @@ public CompletionStage clusterInfo(Set topics) { var topicMap = topicList.stream().collect(Collectors.toUnmodifiableMap(Topic::name, t -> t)); return ClusterInfo.of( - clusterIdAndBrokers.getKey(), - clusterIdAndBrokers.getValue(), - topicMap, - replicas); + clusterIdAndBrokers.getKey(), clusterIdAndBrokers.getValue(), topicMap, replicas); }); } diff --git a/common/src/main/java/org/astraea/common/admin/Broker.java b/common/src/main/java/org/astraea/common/admin/Broker.java index 68cf8db99a..b94fd29558 100644 --- a/common/src/main/java/org/astraea/common/admin/Broker.java +++ b/common/src/main/java/org/astraea/common/admin/Broker.java @@ -34,8 +34,7 @@ public record Broker( List dataFolders, Set topicPartitions, // partition leaders hosted by this broker - Set topicPartitionLeaders) - implements NodeInfo { + Set topicPartitionLeaders) { /** * @return true if the broker is offline. An offline node can't offer host or port information. @@ -44,15 +43,11 @@ public boolean offline() { return host() == null || host().isEmpty() || port() < 0; } - public static Broker of( - int id, - String host, - int port - ) { - return new Broker(id, host, port, false, Config.EMPTY, List.of(), Set.of(), Set.of()); + public static Broker of(int id, String host, int port) { + return new Broker(id, host, port, false, Config.EMPTY, List.of(), Set.of(), Set.of()); } - static Broker of( + public static Broker of( boolean isController, org.apache.kafka.common.Node nodeInfo, Map configs, diff --git a/common/src/main/java/org/astraea/common/admin/ClusterInfo.java b/common/src/main/java/org/astraea/common/admin/ClusterInfo.java index 5f986db947..8fa96e13e9 100644 --- a/common/src/main/java/org/astraea/common/admin/ClusterInfo.java +++ b/common/src/main/java/org/astraea/common/admin/ClusterInfo.java @@ -340,8 +340,7 @@ default Stream replicaStream(String topic) { } default Stream replicaStream(BrokerTopic brokerTopic) { - return replicaStream(brokerTopic.topic()) - .filter(r -> r.broker().id() == brokerTopic.broker()); + return replicaStream(brokerTopic.topic()).filter(r -> r.broker().id() == brokerTopic.broker()); } default Stream replicaStream(TopicPartition partition) { diff --git a/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java b/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java index bba81853bd..29ced88907 100644 --- a/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java +++ b/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java @@ -330,7 +330,7 @@ private static Broker fakeNode(int brokerId) { } static Broker fakeBroker(int Id, String host, int port, List dataFolders) { - return new Broker(Id, host, port, false, new Config(Map.of()), dataFolders, Set.of(), Set.of()); + return new Broker(Id, host, port, false, Config.EMPTY, dataFolders, Set.of(), Set.of()); } private static Broker.DataFolder fakeDataFolder(String path) { diff --git a/common/src/main/java/org/astraea/common/admin/ReplicaBuilder.java b/common/src/main/java/org/astraea/common/admin/ReplicaBuilder.java index 9d0e718fe4..e06887c001 100644 --- a/common/src/main/java/org/astraea/common/admin/ReplicaBuilder.java +++ b/common/src/main/java/org/astraea/common/admin/ReplicaBuilder.java @@ -313,7 +313,7 @@ public int hashCode() { return Objects.hash( topic, partition, - broker, + broker, lag, size, internal, diff --git a/common/src/main/java/org/astraea/common/balancer/executor/StraightPlanExecutor.java b/common/src/main/java/org/astraea/common/balancer/executor/StraightPlanExecutor.java index 89169fd847..d932266afd 100644 --- a/common/src/main/java/org/astraea/common/balancer/executor/StraightPlanExecutor.java +++ b/common/src/main/java/org/astraea/common/balancer/executor/StraightPlanExecutor.java @@ -79,8 +79,7 @@ public CompletionStage run(Admin admin, ClusterInfo logAllocation, Duratio .collect( Collectors.groupingBy( Replica::topicPartition, - Collectors.mapping( - r -> r.broker().id(), Collectors.toList())))) + Collectors.mapping(r -> r.broker().id(), Collectors.toList())))) .thenApply(ignored -> replicas)) // step 2: wait replicas get reassigned .thenCompose( diff --git a/common/src/main/java/org/astraea/common/cost/CostUtils.java b/common/src/main/java/org/astraea/common/cost/CostUtils.java index e1792d2ad6..77c64daa15 100644 --- a/common/src/main/java/org/astraea/common/cost/CostUtils.java +++ b/common/src/main/java/org/astraea/common/cost/CostUtils.java @@ -19,8 +19,8 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Broker; +import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Replica; final class CostUtils { diff --git a/common/src/main/java/org/astraea/common/cost/MigrationCost.java b/common/src/main/java/org/astraea/common/cost/MigrationCost.java index 55f460d165..9616ffef3a 100644 --- a/common/src/main/java/org/astraea/common/cost/MigrationCost.java +++ b/common/src/main/java/org/astraea/common/cost/MigrationCost.java @@ -22,8 +22,8 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Broker; +import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Replica; public class MigrationCost { diff --git a/common/src/main/java/org/astraea/common/cost/NetworkCost.java b/common/src/main/java/org/astraea/common/cost/NetworkCost.java index 5269aaaba2..097bec5239 100644 --- a/common/src/main/java/org/astraea/common/cost/NetworkCost.java +++ b/common/src/main/java/org/astraea/common/cost/NetworkCost.java @@ -28,9 +28,9 @@ import org.astraea.common.Configuration; import org.astraea.common.DataRate; import org.astraea.common.EnumInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.BrokerTopic; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.Broker; import org.astraea.common.admin.Replica; import org.astraea.common.admin.TopicPartition; import org.astraea.common.cost.utils.ClusterInfoSensor; diff --git a/common/src/main/java/org/astraea/common/cost/NodeMetricsCost.java b/common/src/main/java/org/astraea/common/cost/NodeMetricsCost.java index 2cc67e755e..2a2cb1d126 100644 --- a/common/src/main/java/org/astraea/common/cost/NodeMetricsCost.java +++ b/common/src/main/java/org/astraea/common/cost/NodeMetricsCost.java @@ -21,8 +21,8 @@ import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; -import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Broker; +import org.astraea.common.admin.ClusterInfo; import org.astraea.common.metrics.ClusterBean; import org.astraea.common.metrics.client.HasNodeMetrics; import org.astraea.common.metrics.client.producer.ProducerMetrics; diff --git a/common/src/main/java/org/astraea/common/cost/RecordSizeCost.java b/common/src/main/java/org/astraea/common/cost/RecordSizeCost.java index 08bcd38fa3..c922cfc6d7 100644 --- a/common/src/main/java/org/astraea/common/cost/RecordSizeCost.java +++ b/common/src/main/java/org/astraea/common/cost/RecordSizeCost.java @@ -22,8 +22,8 @@ import java.util.stream.Collectors; import org.astraea.common.Configuration; import org.astraea.common.DataSize; -import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Broker; +import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Replica; import org.astraea.common.metrics.ClusterBean; diff --git a/common/src/main/java/org/astraea/common/cost/ReplicaNumberCost.java b/common/src/main/java/org/astraea/common/cost/ReplicaNumberCost.java index d2605ccfbe..58357dd85d 100644 --- a/common/src/main/java/org/astraea/common/cost/ReplicaNumberCost.java +++ b/common/src/main/java/org/astraea/common/cost/ReplicaNumberCost.java @@ -21,8 +21,8 @@ import java.util.Map; import java.util.stream.Collectors; import org.astraea.common.Configuration; -import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Broker; +import org.astraea.common.admin.ClusterInfo; import org.astraea.common.metrics.ClusterBean; /** more replicas migrate -> higher cost */ diff --git a/common/src/main/java/org/astraea/common/cost/utils/ClusterInfoSensor.java b/common/src/main/java/org/astraea/common/cost/utils/ClusterInfoSensor.java index af49af3146..2e8f796a84 100644 --- a/common/src/main/java/org/astraea/common/cost/utils/ClusterInfoSensor.java +++ b/common/src/main/java/org/astraea/common/cost/utils/ClusterInfoSensor.java @@ -22,8 +22,8 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Broker; +import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Replica; import org.astraea.common.metrics.ClusterBean; import org.astraea.common.metrics.HasBeanObject; diff --git a/common/src/main/java/org/astraea/common/metrics/MetricSeriesBuilder.java b/common/src/main/java/org/astraea/common/metrics/MetricSeriesBuilder.java index 08db00f62f..eede63dfff 100644 --- a/common/src/main/java/org/astraea/common/metrics/MetricSeriesBuilder.java +++ b/common/src/main/java/org/astraea/common/metrics/MetricSeriesBuilder.java @@ -27,8 +27,8 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Broker; +import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Replica; import org.astraea.common.admin.TopicPartition; import org.astraea.common.function.Bi3Function; diff --git a/common/src/main/java/org/astraea/common/partitioner/RoundRobinKeeper.java b/common/src/main/java/org/astraea/common/partitioner/RoundRobinKeeper.java index eeb4b7c262..c04bc7d27f 100644 --- a/common/src/main/java/org/astraea/common/partitioner/RoundRobinKeeper.java +++ b/common/src/main/java/org/astraea/common/partitioner/RoundRobinKeeper.java @@ -22,8 +22,8 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.function.Supplier; import java.util.stream.Collectors; -import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Broker; +import org.astraea.common.admin.ClusterInfo; public class RoundRobinKeeper { private final AtomicInteger next = new AtomicInteger(0); diff --git a/common/src/test/java/org/astraea/common/admin/AdminTest.java b/common/src/test/java/org/astraea/common/admin/AdminTest.java index 7eb7e8eca1..f6eaf4cf9b 100644 --- a/common/src/test/java/org/astraea/common/admin/AdminTest.java +++ b/common/src/test/java/org/astraea/common/admin/AdminTest.java @@ -345,7 +345,7 @@ void testOrder() { .toCompletableFuture() .join()); - Assertions.assertInstanceOf(List.class, admin.nodeInfos().toCompletableFuture().join()); + Assertions.assertInstanceOf(List.class, admin.brokers().toCompletableFuture().join()); var brokers = admin.brokers().toCompletableFuture().join(); Assertions.assertEquals( @@ -854,10 +854,10 @@ void testCreateTopicWithReplicasAssignment() { Assertions.assertTrue(config.raw().containsValue("lz4")); Assertions.assertEquals( List.of(0, 2), - partitions.get(0).replicas().stream().map(NodeInfo::id).collect(Collectors.toList())); + partitions.get(0).replicas().stream().map(Broker::id).collect(Collectors.toList())); Assertions.assertEquals( List.of(2, 1), - partitions.get(1).replicas().stream().map(NodeInfo::id).collect(Collectors.toList())); + partitions.get(1).replicas().stream().map(Broker::id).collect(Collectors.toList())); Assertions.assertEquals(0, partitions.get(0).leader().get().id()); Assertions.assertEquals(2, partitions.get(1).leader().get().id()); } diff --git a/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java b/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java index 8b189124a8..cf1df83962 100644 --- a/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java +++ b/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java @@ -110,10 +110,10 @@ void testProducerStates() { @Test void testNodeInfos() { try (var admin = Admin.of(SERVICE.bootstrapServers())) { - var nodeInfos = admin.nodeInfos().toCompletableFuture().join(); + var nodeInfos = admin.brokers().toCompletableFuture().join(); Assertions.assertEquals(2, nodeInfos.size()); var offlineNodeInfos = - nodeInfos.stream().filter(NodeInfo::offline).collect(Collectors.toList()); + nodeInfos.stream().filter(Broker::offline).collect(Collectors.toList()); Assertions.assertEquals(0, offlineNodeInfos.size()); } } @@ -128,7 +128,7 @@ void testBrokers() { b -> b.dataFolders() .forEach(d -> Assertions.assertEquals(0, d.orphanPartitionSizes().size()))); - var offlineBrokers = brokers.stream().filter(NodeInfo::offline).collect(Collectors.toList()); + var offlineBrokers = brokers.stream().filter(Broker::offline).collect(Collectors.toList()); Assertions.assertEquals(0, offlineBrokers.size()); } } diff --git a/common/src/test/java/org/astraea/common/admin/ClusterInfoBuilderTest.java b/common/src/test/java/org/astraea/common/admin/ClusterInfoBuilderTest.java index cd295971a1..4f77c0db4a 100644 --- a/common/src/test/java/org/astraea/common/admin/ClusterInfoBuilderTest.java +++ b/common/src/test/java/org/astraea/common/admin/ClusterInfoBuilderTest.java @@ -31,9 +31,9 @@ class ClusterInfoBuilderTest { @Test void testBuild() { - var host1000 = NodeInfo.of(1000, "host1000", 9092); - var host2000 = NodeInfo.of(2000, "host2000", 9092); - var host3000 = NodeInfo.of(3000, "host3000", 9092); + var host1000 = Broker.of(1000, "host1000", 9092); + var host2000 = Broker.of(2000, "host2000", 9092); + var host3000 = Broker.of(3000, "host3000", 9092); var replica = Replica.builder() .topic("MyTopic") @@ -59,7 +59,7 @@ void addNode() { Assertions.assertEquals( Set.of(1, 2, 3, 4, 5, 100), ClusterInfo.builder().addNode(Set.of(1, 2, 3, 4, 5, 100)).build().nodes().stream() - .map(NodeInfo::id) + .map(Broker::id) .collect(Collectors.toSet())); Assertions.assertEquals( ClusterInfo.builder().addNode(Set.of(1, 2, 3)).build().nodes(), @@ -332,9 +332,9 @@ void setPreferredLeader() { "300, host3, 3000", }) void testFakeBrokerInteraction(int id, String host, int port) { - var node0 = ClusterInfoBuilder.FakeBroker.of(id, host, port, List.of()); - var node1 = NodeInfo.of(id, host, port); - var node2 = NodeInfo.of(id + 1, host, port); + var node0 = ClusterInfoBuilder.fakeBroker(id, host, port, List.of()); + var node1 = Broker.of(id, host, port); + var node2 = Broker.of(id + 1, host, port); Assertions.assertEquals(node0.hashCode(), node1.hashCode()); Assertions.assertNotEquals(node0.hashCode(), node2.hashCode()); diff --git a/common/src/test/java/org/astraea/common/admin/ClusterInfoTest.java b/common/src/test/java/org/astraea/common/admin/ClusterInfoTest.java index e42ff9c3c7..6cfd150487 100644 --- a/common/src/test/java/org/astraea/common/admin/ClusterInfoTest.java +++ b/common/src/test/java/org/astraea/common/admin/ClusterInfoTest.java @@ -49,7 +49,7 @@ public static ClusterInfo of(List replicas) { "fake", replicas.stream() .map(Replica::broker) - .collect(Collectors.groupingBy(NodeInfo::id, Collectors.reducing((x, y) -> x))) + .collect(Collectors.groupingBy(Broker::id, Collectors.reducing((x, y) -> x))) .values() .stream() .flatMap(Optional::stream) @@ -100,7 +100,7 @@ void testReturnCollectionUnmodifiable() { Replica.builder() .topic("topic") .partition(0) - .broker(NodeInfo.of(0, "", -1)) + .broker(Broker.of(0, "", -1)) .path("f") .buildLeader(); Assertions.assertThrows(Exception.class, () -> cluster.replicas().add(replica)); diff --git a/common/src/test/java/org/astraea/common/admin/ClusterInfoWithOfflineNodeTest.java b/common/src/test/java/org/astraea/common/admin/ClusterInfoWithOfflineNodeTest.java index 8427928c8a..e5b251fd95 100644 --- a/common/src/test/java/org/astraea/common/admin/ClusterInfoWithOfflineNodeTest.java +++ b/common/src/test/java/org/astraea/common/admin/ClusterInfoWithOfflineNodeTest.java @@ -79,8 +79,7 @@ void testClusterInfoWithOfflineNode() { after.availableReplicas(topicName).stream() .allMatch(x -> x.broker().id() != brokerToClose)); Assertions.assertTrue( - after.replicaLeaders(topicName).stream() - .allMatch(x -> x.broker().id() != brokerToClose)); + after.replicaLeaders(topicName).stream().allMatch(x -> x.broker().id() != brokerToClose)); Assertions.assertTrue( after.replicas(topicName).stream() .filter(Replica::isOffline) diff --git a/common/src/test/java/org/astraea/common/balancer/BalancerTest.java b/common/src/test/java/org/astraea/common/balancer/BalancerTest.java index 2956b0f111..6bf32f4edb 100644 --- a/common/src/test/java/org/astraea/common/balancer/BalancerTest.java +++ b/common/src/test/java/org/astraea/common/balancer/BalancerTest.java @@ -31,8 +31,8 @@ import org.astraea.common.Configuration; import org.astraea.common.Utils; import org.astraea.common.admin.Admin; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.admin.TopicPartition; import org.astraea.common.balancer.algorithms.GreedyBalancer; @@ -76,7 +76,7 @@ void testLeaderCountRebalance(Class theClass) { return clusterInfo.nodes().stream() .collect( Collectors.toMap( - NodeInfo::id, + Broker::id, n -> clusterInfo .replicaStream(n.id()) diff --git a/common/src/test/java/org/astraea/common/balancer/FakeClusterInfo.java b/common/src/test/java/org/astraea/common/balancer/FakeClusterInfo.java index c435b23ebc..8331e68f5d 100644 --- a/common/src/test/java/org/astraea/common/balancer/FakeClusterInfo.java +++ b/common/src/test/java/org/astraea/common/balancer/FakeClusterInfo.java @@ -26,7 +26,6 @@ import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Config; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.admin.TopicPartition; @@ -76,7 +75,7 @@ public static ClusterInfo of( .collect(Collectors.toUnmodifiableSet()); final var nodes = IntStream.range(0, nodeCount) - .mapToObj(nodeId -> NodeInfo.of(nodeId, "host" + nodeId, 9092)) + .mapToObj(nodeId -> Broker.of(nodeId, "host" + nodeId, 9092)) .map( node -> new Broker( diff --git a/common/src/test/java/org/astraea/common/balancer/executor/StraightPlanExecutorTest.java b/common/src/test/java/org/astraea/common/balancer/executor/StraightPlanExecutorTest.java index e1c66f333d..15ce073ee1 100644 --- a/common/src/test/java/org/astraea/common/balancer/executor/StraightPlanExecutorTest.java +++ b/common/src/test/java/org/astraea/common/balancer/executor/StraightPlanExecutorTest.java @@ -27,9 +27,9 @@ import org.astraea.common.Configuration; import org.astraea.common.Utils; import org.astraea.common.admin.Admin; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.ClusterInfoTest; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.admin.TopicPartition; import org.astraea.it.Service; @@ -78,7 +78,7 @@ void testAsyncRun() { Replica.builder() .topic(tp.topic()) .partition(tp.partition()) - .broker(NodeInfo.of(broker0, "", -1)) + .broker(Broker.of(broker0, "", -1)) .lag(0) .size(0) .isLeader(true) @@ -91,7 +91,7 @@ void testAsyncRun() { Replica.builder() .topic(tp.topic()) .partition(tp.partition()) - .broker(NodeInfo.of(broker1, "", -1)) + .broker(Broker.of(broker1, "", -1)) .lag(0) .size(0) .isLeader(false) diff --git a/common/src/test/java/org/astraea/common/balancer/tweakers/ShuffleTweakerTest.java b/common/src/test/java/org/astraea/common/balancer/tweakers/ShuffleTweakerTest.java index 6b0265d474..3ce16cb6cc 100644 --- a/common/src/test/java/org/astraea/common/balancer/tweakers/ShuffleTweakerTest.java +++ b/common/src/test/java/org/astraea/common/balancer/tweakers/ShuffleTweakerTest.java @@ -25,9 +25,9 @@ import java.util.concurrent.atomic.LongAdder; import java.util.stream.Collectors; import org.astraea.common.Utils; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.ClusterInfoTest; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.admin.TopicPartition; import org.astraea.common.balancer.FakeClusterInfo; @@ -160,9 +160,9 @@ void testEligiblePartition() { 0, Set.of("/a", "/b", "c"), 1, Set.of("/a", "/b", "c"), 2, Set.of("/a", "/b", "c")); - var nodeA = NodeInfo.of(0, "", -1); - var nodeB = NodeInfo.of(1, "", -1); - var nodeC = NodeInfo.of(2, "", -1); + var nodeA = Broker.of(0, "", -1); + var nodeB = Broker.of(1, "", -1); + var nodeC = Broker.of(2, "", -1); var base = Replica.builder() .topic("topic") diff --git a/common/src/test/java/org/astraea/common/cost/BrokerDiskSpaceCostTest.java b/common/src/test/java/org/astraea/common/cost/BrokerDiskSpaceCostTest.java index da9954d8d9..4fe320e1bf 100644 --- a/common/src/test/java/org/astraea/common/cost/BrokerDiskSpaceCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/BrokerDiskSpaceCostTest.java @@ -28,7 +28,6 @@ import org.astraea.common.DataSize; import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.metrics.ClusterBean; import org.junit.jupiter.api.Assertions; @@ -54,42 +53,42 @@ void testMoveCosts() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(2) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(2) - .broker(NodeInfo.of(2, "broker0", 1111)) + .broker(Broker.of(2, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build()); @@ -98,42 +97,42 @@ void testMoveCosts() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(2, "broker0", 1111)) + .broker(Broker.of(2, "broker0", 1111)) .size(dataSize.bytes()) .path("/path1") .build(), Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(2, "broker0", 1111)) + .broker(Broker.of(2, "broker0", 1111)) .size(dataSize.bytes()) .path("/path1") .build(), Replica.builder() .topic("topic1") .partition(2) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build(), Replica.builder() .topic("topic1") .partition(2) - .broker(NodeInfo.of(2, "broker0", 1111)) + .broker(Broker.of(2, "broker0", 1111)) .size(dataSize.bytes()) .path("/path0") .build()); @@ -282,7 +281,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(100) .isLeader(true) .path("/path0") @@ -290,7 +289,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .size(99) .isLeader(false) .path("/path0") @@ -298,7 +297,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(500) .isLeader(true) .path("/path0") @@ -306,7 +305,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .size(499) .isLeader(false) .path("/path0") @@ -314,7 +313,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .broker(NodeInfo.of(2, "broker0", 1111)) + .broker(Broker.of(2, "broker0", 1111)) .size(1000) .isLeader(true) .path("/path0") @@ -322,7 +321,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(1000) .isLeader(false) .path("/path0") @@ -363,7 +362,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(2, "broker0", 1111)) + .broker(Broker.of(2, "broker0", 1111)) .size(100) .isLeader(true) .path("/path1") @@ -371,7 +370,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .size(99) .isLeader(false) .path("/path0") @@ -379,7 +378,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(500) .isLeader(true) .path("/path0") @@ -387,7 +386,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(2, "broker0", 1111)) + .broker(Broker.of(2, "broker0", 1111)) .size(500) .isLeader(false) .path("/path1") @@ -395,7 +394,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .size(1000) .isLeader(true) .path("/path1") @@ -403,7 +402,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(1000) .isLeader(false) .path("/path0") diff --git a/common/src/test/java/org/astraea/common/cost/CostUtilsTest.java b/common/src/test/java/org/astraea/common/cost/CostUtilsTest.java index 709e595c32..d672cd993d 100644 --- a/common/src/test/java/org/astraea/common/cost/CostUtilsTest.java +++ b/common/src/test/java/org/astraea/common/cost/CostUtilsTest.java @@ -27,7 +27,6 @@ import org.apache.kafka.common.requests.DescribeLogDirsResponse; import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -90,7 +89,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(100) .isLeader(true) .path("/path0") @@ -98,7 +97,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .size(99) .isLeader(false) .path("/path0") @@ -106,7 +105,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(500) .isLeader(true) .path("/path0") @@ -114,7 +113,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .size(499) .isLeader(false) .path("/path0") @@ -122,7 +121,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .broker(NodeInfo.of(2, "broker0", 1111)) + .broker(Broker.of(2, "broker0", 1111)) .size(1000) .isLeader(true) .path("/path0") @@ -130,7 +129,7 @@ private static ClusterInfo beforeClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(1000) .isLeader(false) .path("/path0") @@ -171,7 +170,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(2, "broker0", 1111)) + .broker(Broker.of(2, "broker0", 1111)) .size(100) .isLeader(true) .path("/path1") @@ -179,7 +178,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .size(99) .isLeader(false) .path("/path0") @@ -187,7 +186,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(500) .isLeader(true) .path("/path0") @@ -195,7 +194,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(2, "broker0", 1111)) + .broker(Broker.of(2, "broker0", 1111)) .size(500) .isLeader(false) .path("/path1") @@ -203,7 +202,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .size(1000) .isLeader(true) .path("/path1") @@ -211,7 +210,7 @@ private static ClusterInfo afterClusterInfo() { Replica.builder() .topic("topic1") .partition(2) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .size(1000) .isLeader(false) .path("/path0") diff --git a/common/src/test/java/org/astraea/common/cost/MigrationCostTest.java b/common/src/test/java/org/astraea/common/cost/MigrationCostTest.java index 5e50d409a3..c7ccc33aa0 100644 --- a/common/src/test/java/org/astraea/common/cost/MigrationCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/MigrationCostTest.java @@ -21,8 +21,8 @@ import static org.astraea.common.cost.MigrationCost.replicaNumChanged; import java.util.List; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfoTest; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -36,7 +36,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -49,7 +49,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) @@ -62,7 +62,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -75,7 +75,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) @@ -90,7 +90,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(2, "broker0", 1111)) + .broker(Broker.of(2, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -103,7 +103,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) @@ -116,7 +116,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -129,7 +129,7 @@ void testChangedReplicaLeaderNumber() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(2, "broker0", 1111)) + .broker(Broker.of(2, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) @@ -176,7 +176,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -189,7 +189,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) @@ -202,7 +202,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -215,7 +215,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) @@ -230,7 +230,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(2, "broker0", 1111)) + .broker(Broker.of(2, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -243,7 +243,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(0) - .broker(NodeInfo.of(1, "broker0", 1111)) + .broker(Broker.of(1, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) @@ -256,7 +256,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(0, "broker0", 1111)) + .broker(Broker.of(0, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(true) @@ -269,7 +269,7 @@ void testChangedReplicaNumber() { Replica.builder() .topic("topic1") .partition(1) - .broker(NodeInfo.of(2, "broker0", 1111)) + .broker(Broker.of(2, "broker0", 1111)) .lag(-1) .size(-1) .isLeader(false) diff --git a/common/src/test/java/org/astraea/common/cost/RecordSizeCostTest.java b/common/src/test/java/org/astraea/common/cost/RecordSizeCostTest.java index 29ac2fc4ae..6d099b062d 100644 --- a/common/src/test/java/org/astraea/common/cost/RecordSizeCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/RecordSizeCostTest.java @@ -18,8 +18,8 @@ import java.util.List; import java.util.Map; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.admin.TopicPartition; import org.astraea.common.metrics.ClusterBean; @@ -34,27 +34,27 @@ public class RecordSizeCostTest { private final ClusterInfo clusterInfo = ClusterInfo.of( "fake", - List.of(NodeInfo.of(0, "aa", 22), NodeInfo.of(1, "aa", 22), NodeInfo.of(2, "aa", 22)), + List.of(Broker.of(0, "aa", 22), Broker.of(1, "aa", 22), Broker.of(2, "aa", 22)), Map.of(), List.of( Replica.builder() .topic("topic") .partition(0) - .broker(NodeInfo.of(1, "aa", 22)) + .broker(Broker.of(1, "aa", 22)) .size(100) .path("/tmp/aa") .buildLeader(), Replica.builder() .topic("topic") .partition(0) - .broker(NodeInfo.of(2, "aa", 22)) + .broker(Broker.of(2, "aa", 22)) .size(99) .path("/tmp/aa") .buildInSyncFollower(), Replica.builder() .topic("topic") .partition(1) - .broker(NodeInfo.of(1, "aa", 22)) + .broker(Broker.of(1, "aa", 22)) .size(11) .path("/tmp/aa") .buildLeader())); diff --git a/common/src/test/java/org/astraea/common/cost/ReplicaLeaderCostTest.java b/common/src/test/java/org/astraea/common/cost/ReplicaLeaderCostTest.java index 4208657147..6ceb6e267b 100644 --- a/common/src/test/java/org/astraea/common/cost/ReplicaLeaderCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/ReplicaLeaderCostTest.java @@ -21,8 +21,8 @@ import java.util.Set; import java.util.stream.Collectors; import org.astraea.common.Configuration; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.metrics.ClusterBean; import org.junit.jupiter.api.Assertions; @@ -42,28 +42,16 @@ void testLeaderCount() { var sourceCluster = ClusterInfo.builder(baseCluster) .addTopic( - "topic1", - 3, - (short) 1, - r -> Replica.builder(r).broker(baseCluster.node(1)).build()) + "topic1", 3, (short) 1, r -> Replica.builder(r).broker(baseCluster.node(1)).build()) .addTopic( - "topic2", - 3, - (short) 1, - r -> Replica.builder(r).broker(baseCluster.node(2)).build()) + "topic2", 3, (short) 1, r -> Replica.builder(r).broker(baseCluster.node(2)).build()) .build(); var overFlowTargetCluster = ClusterInfo.builder(baseCluster) .addTopic( - "topic1", - 3, - (short) 1, - r -> Replica.builder(r).broker(baseCluster.node(2)).build()) + "topic1", 3, (short) 1, r -> Replica.builder(r).broker(baseCluster.node(2)).build()) .addTopic( - "topic2", - 3, - (short) 1, - r -> Replica.builder(r).broker(baseCluster.node(1)).build()) + "topic2", 3, (short) 1, r -> Replica.builder(r).broker(baseCluster.node(1)).build()) .build(); var overFlowMoveCost = @@ -87,28 +75,28 @@ void testNoMetrics() { Replica.builder() .topic("topic") .partition(0) - .broker(NodeInfo.of(10, "broker0", 1111)) + .broker(Broker.of(10, "broker0", 1111)) .path("/tmp/aa") .buildLeader(), Replica.builder() .topic("topic") .partition(0) - .broker(NodeInfo.of(10, "broker0", 1111)) + .broker(Broker.of(10, "broker0", 1111)) .path("/tmp/aa") .buildLeader(), Replica.builder() .topic("topic") .partition(0) - .broker(NodeInfo.of(11, "broker1", 1111)) + .broker(Broker.of(11, "broker1", 1111)) .path("/tmp/aa") .buildLeader()); var clusterInfo = ClusterInfo.of( "fake", List.of( - NodeInfo.of(10, "host1", 8080), - NodeInfo.of(11, "host1", 8080), - NodeInfo.of(12, "host1", 8080)), + Broker.of(10, "host1", 8080), + Broker.of(11, "host1", 8080), + Broker.of(12, "host1", 8080)), Map.of(), replicas); var brokerCost = ReplicaLeaderCost.leaderCount(clusterInfo); diff --git a/common/src/test/java/org/astraea/common/cost/ReplicaLeaderSizeCostTest.java b/common/src/test/java/org/astraea/common/cost/ReplicaLeaderSizeCostTest.java index 4bdda7c806..35b450be8e 100644 --- a/common/src/test/java/org/astraea/common/cost/ReplicaLeaderSizeCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/ReplicaLeaderSizeCostTest.java @@ -18,8 +18,8 @@ import java.util.List; import java.util.Map; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.admin.TopicPartition; import org.astraea.common.metrics.ClusterBean; @@ -74,33 +74,33 @@ private ClusterInfo clusterInfo() { .topic("t") .partition(10) .isLeader(true) - .broker(NodeInfo.of(0, "", -1)) + .broker(Broker.of(0, "", -1)) .size(777) .build(), Replica.builder() .topic("t") .partition(11) .isLeader(true) - .broker(NodeInfo.of(1, "", -1)) + .broker(Broker.of(1, "", -1)) .size(700) .build(), Replica.builder() .topic("t") .partition(12) .isLeader(true) - .broker(NodeInfo.of(2, "", -1)) + .broker(Broker.of(2, "", -1)) .size(500) .build(), Replica.builder() .topic("t") .partition(12) .isLeader(false) - .broker(NodeInfo.of(0, "", -1)) + .broker(Broker.of(0, "", -1)) .size(499) .build()); return ClusterInfo.of( "fake", - List.of(NodeInfo.of(0, "", -1), NodeInfo.of(1, "", -1), NodeInfo.of(2, "", -1)), + List.of(Broker.of(0, "", -1), Broker.of(1, "", -1), Broker.of(2, "", -1)), Map.of(), replicas); } diff --git a/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerPerfTest.java b/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerPerfTest.java index 2c605161bf..3e07bc23fe 100644 --- a/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerPerfTest.java +++ b/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerPerfTest.java @@ -29,8 +29,8 @@ import org.astraea.common.Configuration; import org.astraea.common.Utils; import org.astraea.common.admin.Admin; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.metrics.MBeanRegister; import org.junit.jupiter.api.Assertions; @@ -53,9 +53,9 @@ private static AtomicLong createMetric(int brokerId) { @Test void test() { - var node0 = NodeInfo.of(0, "node0", 2222); - var node1 = NodeInfo.of(1, "node1", 2222); - var node2 = NodeInfo.of(2, "node2", 2222); + var node0 = Broker.of(0, "node0", 2222); + var node1 = Broker.of(1, "node1", 2222); + var node2 = Broker.of(2, "node2", 2222); var clusterInfo = ClusterInfo.of( "fake", diff --git a/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerTest.java b/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerTest.java index 47c102394b..0f7a8c8a97 100644 --- a/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerTest.java +++ b/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerTest.java @@ -25,9 +25,9 @@ import java.util.stream.IntStream; import org.astraea.common.Configuration; import org.astraea.common.Utils; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.ClusterInfoTest; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.cost.BrokerCost; import org.astraea.common.cost.BrokerInputCost; @@ -106,7 +106,7 @@ void testNoAvailableBrokers() { @Test void testSingleBroker() { - var nodeInfo = NodeInfo.of(10, "host", 11111); + var nodeInfo = Broker.of(10, "host", 11111); var replicaInfo = Replica.builder() .topic("topic") @@ -138,14 +138,14 @@ void testCostFunctionWithoutSensor() { .topic("topic") .partition(0) .path("/tmp/aa") - .broker(NodeInfo.of(10, "host", 11111)) + .broker(Broker.of(10, "host", 11111)) .buildLeader(); var replicaInfo1 = Replica.builder() .topic("topic") .partition(0) .path("/tmp/aa") - .broker(NodeInfo.of(12, "host2", 11111)) + .broker(Broker.of(12, "host2", 11111)) .buildLeader(); try (var partitioner = new StrictCostPartitioner()) { partitioner.configure( @@ -192,14 +192,14 @@ void testReturnedPartition() { .topic("topic") .partition(partitionId) .path("/tmp/aa") - .broker(NodeInfo.of(brokerId, "host", 11111)) + .broker(Broker.of(brokerId, "host", 11111)) .buildLeader(); var replicaInfo1 = Replica.builder() .topic("topic") .partition(1) .path("/tmp/aa") - .broker(NodeInfo.of(1111, "host2", 11111)) + .broker(Broker.of(1111, "host2", 11111)) .buildLeader(); Assertions.assertEquals( partitionId, diff --git a/gui/src/main/java/org/astraea/gui/tab/BrokerNode.java b/gui/src/main/java/org/astraea/gui/tab/BrokerNode.java index 874659ff16..e9655be4aa 100644 --- a/gui/src/main/java/org/astraea/gui/tab/BrokerNode.java +++ b/gui/src/main/java/org/astraea/gui/tab/BrokerNode.java @@ -38,7 +38,6 @@ import org.astraea.common.MapUtils; import org.astraea.common.admin.Broker; import org.astraea.common.admin.BrokerConfigs; -import org.astraea.common.admin.Broker; import org.astraea.common.admin.TopicPartition; import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.broker.ControllerMetrics; @@ -378,8 +377,7 @@ private static Node configNode(Context context) { var unset = brokers.stream() .collect( - Collectors.toMap( - Broker::id, b -> input.emptyValueKeys())); + Collectors.toMap(Broker::id, b -> input.emptyValueKeys())); var set = brokers.stream() .collect( diff --git a/gui/src/test/java/org/astraea/gui/tab/health/BalancerNodeTest.java b/gui/src/test/java/org/astraea/gui/tab/health/BalancerNodeTest.java index f13ce55ae6..9af5cde14c 100644 --- a/gui/src/test/java/org/astraea/gui/tab/health/BalancerNodeTest.java +++ b/gui/src/test/java/org/astraea/gui/tab/health/BalancerNodeTest.java @@ -26,7 +26,6 @@ import org.astraea.common.Utils; import org.astraea.common.admin.Admin; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.common.balancer.Balancer; import org.astraea.common.cost.ReplicaLeaderSizeCost; @@ -104,8 +103,7 @@ void testGenerator() { void testResult() { var topic = Utils.randomString(); var leaderSize = 100; - var allNodes = - List.of(NodeInfo.of(0, "aa", 0), NodeInfo.of(1, "aa", 0), NodeInfo.of(3, "aa", 0)); + var allNodes = List.of(Broker.of(0, "aa", 0), Broker.of(1, "aa", 0), Broker.of(3, "aa", 0)); var beforeReplicas = List.of( Replica.builder() diff --git a/gui/src/test/java/org/astraea/gui/tab/topic/ReplicaNodeTest.java b/gui/src/test/java/org/astraea/gui/tab/topic/ReplicaNodeTest.java index 4a0e4efab9..f6889a0294 100644 --- a/gui/src/test/java/org/astraea/gui/tab/topic/ReplicaNodeTest.java +++ b/gui/src/test/java/org/astraea/gui/tab/topic/ReplicaNodeTest.java @@ -26,7 +26,6 @@ import org.astraea.common.Utils; import org.astraea.common.admin.Admin; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; import org.astraea.gui.Context; import org.astraea.gui.pane.Argument; @@ -143,7 +142,7 @@ void testResult() { var topic = Utils.randomString(); var partition = 0; var leaderSize = 100; - var nodes = List.of(NodeInfo.of(0, "aa", 0), NodeInfo.of(1, "aa", 0), NodeInfo.of(2, "aa", 0)); + var nodes = List.of(Broker.of(0, "aa", 0), Broker.of(1, "aa", 0), Broker.of(2, "aa", 0)); var replicas = List.of( Replica.builder() From b5edc40fed043da2dee8929eb8478edb01e586b8 Mon Sep 17 00:00:00 2001 From: Chao-Heng Lee Date: Fri, 19 May 2023 23:31:04 +0800 Subject: [PATCH 03/11] fix error. --- .../test/java/org/astraea/gui/tab/health/BalancerNodeTest.java | 1 + gui/src/test/java/org/astraea/gui/tab/topic/ReplicaNodeTest.java | 1 + 2 files changed, 2 insertions(+) diff --git a/gui/src/test/java/org/astraea/gui/tab/health/BalancerNodeTest.java b/gui/src/test/java/org/astraea/gui/tab/health/BalancerNodeTest.java index 9af5cde14c..90ca3ca23b 100644 --- a/gui/src/test/java/org/astraea/gui/tab/health/BalancerNodeTest.java +++ b/gui/src/test/java/org/astraea/gui/tab/health/BalancerNodeTest.java @@ -25,6 +25,7 @@ import java.util.stream.Collectors; import org.astraea.common.Utils; import org.astraea.common.admin.Admin; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Replica; import org.astraea.common.balancer.Balancer; diff --git a/gui/src/test/java/org/astraea/gui/tab/topic/ReplicaNodeTest.java b/gui/src/test/java/org/astraea/gui/tab/topic/ReplicaNodeTest.java index f6889a0294..0530ff0b77 100644 --- a/gui/src/test/java/org/astraea/gui/tab/topic/ReplicaNodeTest.java +++ b/gui/src/test/java/org/astraea/gui/tab/topic/ReplicaNodeTest.java @@ -25,6 +25,7 @@ import java.util.stream.Collectors; import org.astraea.common.Utils; import org.astraea.common.admin.Admin; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Replica; import org.astraea.gui.Context; From 93d8143942613bdac07c26161432966714c3fec7 Mon Sep 17 00:00:00 2001 From: Chao-Heng Lee Date: Sat, 20 May 2023 20:54:52 +0800 Subject: [PATCH 04/11] fix test. --- .../astraea/app/web/BalancerHandlerTest.java | 21 ++++- .../java/org/astraea/common/ByteUtils.java | 3 +- .../org/astraea/common/admin/AdminImpl.java | 33 ++----- .../java/org/astraea/common/admin/Broker.java | 4 + .../common/admin/ClusterInfoBuilder.java | 2 +- .../org/astraea/common/admin/NodeInfo.java | 89 ------------------- .../org/astraea/common/ByteUtilsTest.java | 46 ---------- .../astraea/common/admin/NodeInfoTest.java | 38 -------- .../StrictCostPartitionerPerfTest.java | 41 ++++++--- .../java/org/astraea/gui/tab/SettingNode.java | 2 +- 10 files changed, 63 insertions(+), 216 deletions(-) delete mode 100644 common/src/main/java/org/astraea/common/admin/NodeInfo.java delete mode 100644 common/src/test/java/org/astraea/common/admin/NodeInfoTest.java diff --git a/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java b/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java index a48f9f843e..7d4140c785 100644 --- a/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java +++ b/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java @@ -60,6 +60,7 @@ import org.astraea.common.admin.Admin; import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; +import org.astraea.common.admin.Config; import org.astraea.common.admin.Replica; import org.astraea.common.admin.TopicPartition; import org.astraea.common.balancer.AlgorithmConfig; @@ -229,7 +230,25 @@ void testBestPlan() { var currentClusterInfo = ClusterInfo.of( "fake", - List.of(Broker.of(10, "host", 22), Broker.of(11, "host", 22)), + List.of( + new Broker( + 10, + "host", + 22, + false, + Config.EMPTY, + List.of(new Broker.DataFolder("", Map.of(), Map.of())), + Set.of(), + Set.of()), + new Broker( + 11, + "host", + 22, + false, + Config.EMPTY, + List.of(new Broker.DataFolder("", Map.of(), Map.of())), + Set.of(), + Set.of())), Map.of(), List.of( Replica.builder() diff --git a/common/src/main/java/org/astraea/common/ByteUtils.java b/common/src/main/java/org/astraea/common/ByteUtils.java index f02b313124..11e129a49e 100644 --- a/common/src/main/java/org/astraea/common/ByteUtils.java +++ b/common/src/main/java/org/astraea/common/ByteUtils.java @@ -181,6 +181,7 @@ public static byte[] toBytes(BeanObject value) { return beanBuilder.build().toByteArray(); } + // TODO: Due to the change of NodeInfo to Broker. This and the test should be updated. /** Serialize ClusterInfo by protocol buffer. */ public static byte[] toBytes(ClusterInfo value) { return ClusterInfoOuterClass.ClusterInfo.newBuilder() @@ -320,7 +321,7 @@ public static BeanObject readBeanObject(byte[] bytes) throws SerializationExcept } } - // TODO: change NodeInfo to Broker. Some information has not yet been serialized. + // TODO: Due to the change of NodeInfo to Broker. This and the test should be updated. /** Deserialize to ClusterInfo with protocol buffer */ public static ClusterInfo readClusterInfo(byte[] bytes) { try { diff --git a/common/src/main/java/org/astraea/common/admin/AdminImpl.java b/common/src/main/java/org/astraea/common/admin/AdminImpl.java index 039a4274b3..3aee658767 100644 --- a/common/src/main/java/org/astraea/common/admin/AdminImpl.java +++ b/common/src/main/java/org/astraea/common/admin/AdminImpl.java @@ -405,11 +405,7 @@ public CompletionStage> partitions(Set topics) { ts -> ts.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().isInternal()))), - brokers() - .thenApply( - brokers -> - brokers.stream().collect(Collectors.toMap(Broker::id, Function.identity()))), - (earliestOffsets, latestOffsets, maxTimestamps, tpInfos, topicAndInternal, brokers) -> + (earliestOffsets, latestOffsets, maxTimestamps, tpInfos, topicAndInternal) -> tpInfos.keySet().stream() .map( tp -> { @@ -420,15 +416,10 @@ public CompletionStage> partitions(Set topics) { var leader = tpInfo.leader() == null || tpInfo.leader().isEmpty() ? null - : brokers.get(tpInfo.leader().id()); + : Broker.of(tpInfo.leader()); var replicas = - tpInfo.replicas().stream() - .map(replicaBroker -> brokers.get(replicaBroker.id())) - .collect(Collectors.toList()); - var isr = - tpInfo.isr().stream() - .map(isrBroker -> brokers.get(isrBroker.id())) - .collect(Collectors.toList()); + tpInfo.replicas().stream().map(Broker::of).collect(Collectors.toList()); + var isr = tpInfo.isr().stream().map(Broker::of).collect(Collectors.toList()); return new Partition( tp.topic(), tp.partition(), @@ -515,11 +506,7 @@ public CompletionStage> consumerGroups(Set consumerG .collect(Collectors.toUnmodifiableList())) .thenApply( s -> s.stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))), - brokers() - .thenApply( - brokers -> - brokers.stream().collect(Collectors.toMap(Broker::id, Function.identity()))), - (consumerGroupDescriptions, consumerGroupMetadata, brokers) -> + (consumerGroupDescriptions, consumerGroupMetadata) -> consumerGroupIds.stream() .map( groupId -> @@ -527,7 +514,7 @@ public CompletionStage> consumerGroups(Set consumerG groupId, consumerGroupDescriptions.get(groupId).partitionAssignor(), consumerGroupDescriptions.get(groupId).state().name(), - brokers.get(consumerGroupDescriptions.get(groupId).coordinator().id()), + Broker.of(consumerGroupDescriptions.get(groupId).coordinator()), consumerGroupMetadata.get(groupId).entrySet().stream() .collect( Collectors.toUnmodifiableMap( @@ -642,11 +629,7 @@ private CompletionStage> replicas(Set topics) { // supported version: 2.4.0 // https://issues.apache.org/jira/browse/KAFKA-8345 .exceptionally(exceptionHandler(UnsupportedVersionException.class, Map.of())), - brokers() - .thenApply( - brokers -> - brokers.stream().collect(Collectors.toMap(Broker::id, Function.identity()))), - (logDirs, ts, reassignmentMap, brokers) -> + (logDirs, ts, reassignmentMap) -> ts.values().stream() .flatMap(topic -> topic.partitions().stream().map(p -> Map.entry(topic.name(), p))) .flatMap( @@ -691,7 +674,7 @@ private CompletionStage> replicas(Set topics) { .internal(internal) .isAdding(isAdding) .isRemoving(isRemoving) - .broker(brokers.get(node.id())) + .broker(Broker.of(node)) .lag(pathAndReplica.getValue().offsetLag()) .size(pathAndReplica.getValue().size()) .isLeader( diff --git a/common/src/main/java/org/astraea/common/admin/Broker.java b/common/src/main/java/org/astraea/common/admin/Broker.java index b94fd29558..c81777000b 100644 --- a/common/src/main/java/org/astraea/common/admin/Broker.java +++ b/common/src/main/java/org/astraea/common/admin/Broker.java @@ -47,6 +47,10 @@ public static Broker of(int id, String host, int port) { return new Broker(id, host, port, false, Config.EMPTY, List.of(), Set.of(), Set.of()); } + public static Broker of(org.apache.kafka.common.Node node) { + return of(node.id(), node.host(), node.port()); + } + public static Broker of( boolean isController, org.apache.kafka.common.Node nodeInfo, diff --git a/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java b/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java index 29ced88907..633c643f89 100644 --- a/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java +++ b/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java @@ -113,7 +113,7 @@ public ClusterInfoBuilder addFolders(Map> folders) { node.host(), node.port(), Stream.concat( - ((Broker) node).dataFolders().stream(), + node.dataFolders().stream(), folders.get(node.id()).stream() .map(ClusterInfoBuilder::fakeDataFolder)) .toList()); diff --git a/common/src/main/java/org/astraea/common/admin/NodeInfo.java b/common/src/main/java/org/astraea/common/admin/NodeInfo.java deleted file mode 100644 index fffd74cc35..0000000000 --- a/common/src/main/java/org/astraea/common/admin/NodeInfo.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.astraea.common.admin; - -import java.util.Objects; - -public interface NodeInfo { - - static NodeInfo of(org.apache.kafka.common.Node node) { - return of(node.id(), node.host(), node.port()); - } - - static NodeInfo of(int id, String host, int port) { - return new NodeInfo() { - @Override - public String toString() { - return "NodeInfo{" + "host=" + host + ", id=" + id + ", port=" + port + '}'; - } - - // NodeInfo is used to be key of Map commonly, so creating hash can reduce the memory pressure - private final int hashCode = Objects.hash(id, host, port); - - @Override - public String host() { - return host; - } - - @Override - public int id() { - return id; - } - - @Override - public int port() { - return port; - } - - @Override - public int hashCode() { - return hashCode; - } - - @Override - public boolean equals(Object other) { - if (other instanceof NodeInfo) { - var node = (NodeInfo) other; - return id() == node.id() && port() == node.port() && host().equals(node.host()); - } - return false; - } - }; - } - - /** - * @return The host name for this node - */ - String host(); - - /** - * @return The client (kafka data, jmx, etc.) port for this node - */ - int port(); - - /** - * @return id of broker node. it must be unique. - */ - int id(); - - /** - * @return true if the node is offline. An offline node can't offer host or port information. - */ - default boolean offline() { - return host() == null || host().isEmpty() || port() < 0; - } -} diff --git a/common/src/test/java/org/astraea/common/ByteUtilsTest.java b/common/src/test/java/org/astraea/common/ByteUtilsTest.java index 7cdef95b3c..616229e122 100644 --- a/common/src/test/java/org/astraea/common/ByteUtilsTest.java +++ b/common/src/test/java/org/astraea/common/ByteUtilsTest.java @@ -17,11 +17,6 @@ package org.astraea.common; import java.nio.charset.StandardCharsets; -import java.time.Duration; -import java.util.Set; -import org.astraea.common.admin.Admin; -import org.astraea.common.admin.ClusterInfo; -import org.astraea.it.Service; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -73,45 +68,4 @@ void testBoolean2Bytes() { Assertions.assertArrayEquals(new byte[] {1}, ByteUtils.toBytes(true)); Assertions.assertArrayEquals(new byte[] {0}, ByteUtils.toBytes(false)); } - - @Test - void testReadAndToBytesClusterInfo() { - var topic = Utils.randomString(); - try (var service = Service.builder().numberOfBrokers(3).build()) { - try (var admin = Admin.of(service.bootstrapServers())) { - admin - .creator() - .topic(topic) - .numberOfPartitions(1) - .numberOfReplicas((short) 3) - .run() - .toCompletableFuture() - .join(); - Utils.sleep(Duration.ofSeconds(1)); - var clusterInfo = admin.clusterInfo(Set.of(topic)).toCompletableFuture().join(); - - Assertions.assertDoesNotThrow(() -> ByteUtils.toBytes(clusterInfo)); - var bytes = ByteUtils.toBytes(clusterInfo); - Assertions.assertDoesNotThrow(() -> ByteUtils.readClusterInfo(bytes)); - var deserializedClusterInfo = ByteUtils.readClusterInfo(bytes); - - Assertions.assertEquals(clusterInfo.clusterId(), deserializedClusterInfo.clusterId()); - Assertions.assertTrue(clusterInfo.nodes().containsAll(deserializedClusterInfo.nodes())); - Assertions.assertEquals(clusterInfo.topics(), deserializedClusterInfo.topics()); - Assertions.assertEquals(clusterInfo.replicas(), deserializedClusterInfo.replicas()); - } - } - } - - @Test - void testReadAndToBytesEmptyClusterInfo() { - var clusterInfo = ClusterInfo.empty(); - var serializedInfo = ByteUtils.toBytes(clusterInfo); - var deserializedClusterInfo = ByteUtils.readClusterInfo(serializedInfo); - - Assertions.assertEquals(clusterInfo.clusterId(), deserializedClusterInfo.clusterId()); - Assertions.assertEquals(clusterInfo.nodes(), deserializedClusterInfo.nodes()); - Assertions.assertEquals(clusterInfo.topics(), deserializedClusterInfo.topics()); - Assertions.assertEquals(clusterInfo.replicas(), deserializedClusterInfo.replicas()); - } } diff --git a/common/src/test/java/org/astraea/common/admin/NodeInfoTest.java b/common/src/test/java/org/astraea/common/admin/NodeInfoTest.java deleted file mode 100644 index 5c3d24d9fe..0000000000 --- a/common/src/test/java/org/astraea/common/admin/NodeInfoTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.astraea.common.admin; - -import org.apache.kafka.common.Node; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class NodeInfoTest { - - static Node node() { - return new Node(10, "host", 100); - } - - @Test - void testAllGetters() { - var kafkaNode = node(); - var node = NodeInfo.of(kafkaNode); - - Assertions.assertEquals(kafkaNode.host(), node.host()); - Assertions.assertEquals(kafkaNode.id(), node.id()); - Assertions.assertEquals(kafkaNode.port(), node.port()); - } -} diff --git a/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerPerfTest.java b/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerPerfTest.java index 3e07bc23fe..d10334dd29 100644 --- a/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerPerfTest.java +++ b/common/src/test/java/org/astraea/common/partitioner/StrictCostPartitionerPerfTest.java @@ -32,23 +32,24 @@ import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; import org.astraea.common.admin.Replica; -import org.astraea.common.metrics.MBeanRegister; +import org.astraea.common.metrics.BeanObject; +import org.astraea.common.metrics.ClusterBean; +import org.astraea.common.metrics.client.HasNodeMetrics; +import org.astraea.common.metrics.collector.MetricStore; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.Mockito; public class StrictCostPartitionerPerfTest { - private static AtomicLong createMetric(int brokerId) { - var latency = new AtomicLong(100); - MBeanRegister.local() - .domainName("kafka.producer") - .property("type", "producer-node-metrics") - .property("node-id", String.valueOf(brokerId)) - .property("client-id", "xxxx") - .attribute("request-latency-avg", Double.class, () -> (double) latency.get()) - .register(); - return latency; + private static BeanObject getBeanObject(int brokerId, double latency) { + return new BeanObject( + "kafka.producer", + Map.of( + "type", "producer-node-metrics", + "node-id", String.valueOf(brokerId), + "client-id", "xxxx"), + Map.of("request-latency-avg", latency)); } @Test @@ -86,15 +87,27 @@ void test() { Mockito.when(admin.clusterInfo(Mockito.anySet())) .thenReturn(CompletableFuture.completedStage(clusterInfo)); - var node0Latency = createMetric(0); - var node1Latency = createMetric(1); - var node2Latency = createMetric(2); + var node0Latency = new AtomicLong(100); + var node1Latency = new AtomicLong(100); + var node2Latency = new AtomicLong(100); + + var metricStore = Mockito.mock(MetricStore.class); + Mockito.when(metricStore.clusterBean()) + .thenReturn( + ClusterBean.of( + Map.of( + -1, + List.of( + (HasNodeMetrics) () -> getBeanObject(0, node0Latency.get()), + () -> getBeanObject(1, node1Latency.get()), + () -> getBeanObject(2, node2Latency.get()))))); var key = "key".getBytes(StandardCharsets.UTF_8); var value = "value".getBytes(StandardCharsets.UTF_8); try (var partitioner = new StrictCostPartitioner()) { partitioner.admin = admin; partitioner.configure(Configuration.of(Map.of("round.robin.lease", "2s"))); + partitioner.metricStore = metricStore; Supplier>> resultSupplier = () -> { diff --git a/gui/src/main/java/org/astraea/gui/tab/SettingNode.java b/gui/src/main/java/org/astraea/gui/tab/SettingNode.java index 2b03786ddd..669071a3e2 100644 --- a/gui/src/main/java/org/astraea/gui/tab/SettingNode.java +++ b/gui/src/main/java/org/astraea/gui/tab/SettingNode.java @@ -149,7 +149,7 @@ public static Node of(Context context) { .url(Utils.packException(() -> new URL("http://" + url))) .build()); return FutureUtils.combine( - newAdmin.nodeInfos(), + newAdmin.brokers(), client .map(ConnectorClient::activeWorkers) .orElse(CompletableFuture.completedFuture(List.of())), From e46fb0272d7526cc4e6c6609b5afde6595459ee4 Mon Sep 17 00:00:00 2001 From: Chao-Heng Lee Date: Mon, 22 May 2023 15:37:24 +0800 Subject: [PATCH 05/11] get all information for broker in adm in. --- .../astraea/app/web/ReassignmentHandler.java | 2 +- .../org/astraea/common/admin/AdminImpl.java | 37 +++++++++++++++---- .../astraea/common/admin/ReplicaBuilder.java | 4 +- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/astraea/app/web/ReassignmentHandler.java b/app/src/main/java/org/astraea/app/web/ReassignmentHandler.java index 529f7babb7..2c2245e7e3 100644 --- a/app/src/main/java/org/astraea/app/web/ReassignmentHandler.java +++ b/app/src/main/java/org/astraea/app/web/ReassignmentHandler.java @@ -111,7 +111,7 @@ public CompletionStage post(Channel channel) { .filter( b -> b.topicPartitions().contains(tp)) .map(Broker::id) - .toList(); + .toList(); if (!ids.isEmpty()) return ids; return List.of( availableBrokers diff --git a/common/src/main/java/org/astraea/common/admin/AdminImpl.java b/common/src/main/java/org/astraea/common/admin/AdminImpl.java index 3aee658767..c434e7e7c6 100644 --- a/common/src/main/java/org/astraea/common/admin/AdminImpl.java +++ b/common/src/main/java/org/astraea/common/admin/AdminImpl.java @@ -405,7 +405,11 @@ public CompletionStage> partitions(Set topics) { ts -> ts.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().isInternal()))), - (earliestOffsets, latestOffsets, maxTimestamps, tpInfos, topicAndInternal) -> + brokers() + .thenApply( + brokers -> + brokers.stream().collect(Collectors.toMap(Broker::id, broker -> broker))), + (earliestOffsets, latestOffsets, maxTimestamps, tpInfos, topicAndInternal, brokers) -> tpInfos.keySet().stream() .map( tp -> { @@ -416,10 +420,15 @@ public CompletionStage> partitions(Set topics) { var leader = tpInfo.leader() == null || tpInfo.leader().isEmpty() ? null - : Broker.of(tpInfo.leader()); + : brokers.get(tpInfo.leader().id()); var replicas = - tpInfo.replicas().stream().map(Broker::of).collect(Collectors.toList()); - var isr = tpInfo.isr().stream().map(Broker::of).collect(Collectors.toList()); + tpInfo.replicas().stream() + .map(node -> brokers.getOrDefault(node.id(), Broker.of(node))) + .collect(Collectors.toList()); + var isr = + tpInfo.isr().stream() + .map(node -> brokers.getOrDefault(node.id(), Broker.of(node))) + .collect(Collectors.toList()); return new Partition( tp.topic(), tp.partition(), @@ -506,7 +515,11 @@ public CompletionStage> consumerGroups(Set consumerG .collect(Collectors.toUnmodifiableList())) .thenApply( s -> s.stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))), - (consumerGroupDescriptions, consumerGroupMetadata) -> + brokers() + .thenApply( + brokers -> + brokers.stream().collect(Collectors.toMap(Broker::id, broker -> broker))), + (consumerGroupDescriptions, consumerGroupMetadata, brokers) -> consumerGroupIds.stream() .map( groupId -> @@ -514,7 +527,9 @@ public CompletionStage> consumerGroups(Set consumerG groupId, consumerGroupDescriptions.get(groupId).partitionAssignor(), consumerGroupDescriptions.get(groupId).state().name(), - Broker.of(consumerGroupDescriptions.get(groupId).coordinator()), + brokers.getOrDefault( + consumerGroupDescriptions.get(groupId).coordinator().id(), + Broker.of(consumerGroupDescriptions.get(groupId).coordinator())), consumerGroupMetadata.get(groupId).entrySet().stream() .collect( Collectors.toUnmodifiableMap( @@ -629,7 +644,11 @@ private CompletionStage> replicas(Set topics) { // supported version: 2.4.0 // https://issues.apache.org/jira/browse/KAFKA-8345 .exceptionally(exceptionHandler(UnsupportedVersionException.class, Map.of())), - (logDirs, ts, reassignmentMap) -> + brokers() + .thenApply( + brokers -> + brokers.stream().collect(Collectors.toMap(Broker::id, broker -> broker))), + (logDirs, ts, reassignmentMap, brokers) -> ts.values().stream() .flatMap(topic -> topic.partitions().stream().map(p -> Map.entry(topic.name(), p))) .flatMap( @@ -674,7 +693,9 @@ private CompletionStage> replicas(Set topics) { .internal(internal) .isAdding(isAdding) .isRemoving(isRemoving) - .broker(Broker.of(node)) + .broker( + brokers.getOrDefault( + node.id(), Broker.of(node))) .lag(pathAndReplica.getValue().offsetLag()) .size(pathAndReplica.getValue().size()) .isLeader( diff --git a/common/src/main/java/org/astraea/common/admin/ReplicaBuilder.java b/common/src/main/java/org/astraea/common/admin/ReplicaBuilder.java index e06887c001..b7e1929643 100644 --- a/common/src/main/java/org/astraea/common/admin/ReplicaBuilder.java +++ b/common/src/main/java/org/astraea/common/admin/ReplicaBuilder.java @@ -286,7 +286,9 @@ public boolean equals(Object o) { && isOffline == replica.isOffline && isPreferredLeader == replica.isPreferredLeader && topic.equals(replica.topic) - && broker.equals(replica.broker) + && broker.id() == replica.broker.id() + && broker.host().equals(replica.broker.host()) + && broker.port() == replica.broker.port() && Objects.equals(path, replica.path); } From 7e6c9c166ffa69e94c46c0cec107121c759d1507 Mon Sep 17 00:00:00 2001 From: Chao-Heng Lee Date: Mon, 22 May 2023 16:40:00 +0800 Subject: [PATCH 06/11] fix conflict with incoming update. --- .../java/org/astraea/common/ByteUtils.java | 2 +- .../org/astraea/common/admin/AdminImpl.java | 2 +- .../org/astraea/common/admin/ClusterInfo.java | 13 ++----- .../common/admin/ClusterInfoBuilder.java | 2 +- .../common/admin/OptimizedClusterInfo.java | 2 +- .../common/balancer/BalancerUtils.java | 20 +++++------ .../balancer/tweakers/ShuffleTweaker.java | 4 +-- .../common/cost/BrokerDiskSpaceCost.java | 2 +- .../org/astraea/common/cost/CostUtils.java | 2 +- .../astraea/common/cost/MigrationCost.java | 4 +-- .../org/astraea/common/cost/NetworkCost.java | 2 +- .../astraea/common/cost/NodeMetricsCost.java | 2 +- .../astraea/common/cost/RecordSizeCost.java | 2 +- .../common/cost/ReplicaLeaderCost.java | 2 +- .../common/metrics/MetricSeriesBuilder.java | 8 ++--- .../common/partitioner/RoundRobinKeeper.java | 2 +- .../admin/AdminWithOfflineBrokerTest.java | 12 ------- .../common/admin/ClusterInfoBuilderTest.java | 20 +++++------ .../astraea/common/admin/ClusterInfoTest.java | 2 +- .../balancer/BalancerConfigTestSuite.java | 34 ++++++++----------- .../common/balancer/BalancerConsoleTest.java | 2 +- .../astraea/common/balancer/BalancerTest.java | 2 +- .../common/balancer/BalancerUtilsTest.java | 22 ++++++------ .../common/cost/BrokerDiskSpaceCostTest.java | 18 +++++----- .../astraea/common/cost/CostUtilsTest.java | 12 +++---- .../cost/utils/ClusterInfoSensorTest.java | 2 +- .../common/partitioner/PartitionerTest.java | 2 +- .../java/org/astraea/gui/tab/SettingNode.java | 4 +-- 28 files changed, 89 insertions(+), 114 deletions(-) diff --git a/common/src/main/java/org/astraea/common/ByteUtils.java b/common/src/main/java/org/astraea/common/ByteUtils.java index 84d52e87a7..405c01f3c6 100644 --- a/common/src/main/java/org/astraea/common/ByteUtils.java +++ b/common/src/main/java/org/astraea/common/ByteUtils.java @@ -192,7 +192,7 @@ public static byte[] toBytes(ClusterInfo value) { return ClusterInfoOuterClass.ClusterInfo.newBuilder() .setClusterId(value.clusterId()) .addAllNodeInfo( - value.nodes().stream() + value.brokers().stream() .map( nodeInfo -> ClusterInfoOuterClass.ClusterInfo.NodeInfo.newBuilder() diff --git a/common/src/main/java/org/astraea/common/admin/AdminImpl.java b/common/src/main/java/org/astraea/common/admin/AdminImpl.java index c434e7e7c6..08e80fb9ad 100644 --- a/common/src/main/java/org/astraea/common/admin/AdminImpl.java +++ b/common/src/main/java/org/astraea/common/admin/AdminImpl.java @@ -1384,7 +1384,7 @@ public void close() { logDirs() { return brokers() .thenApply( - nodeInfos -> nodeInfos.stream().map(Broker::id).collect(Collectors.toUnmodifiableSet())) + brokers -> brokers.stream().map(Broker::id).collect(Collectors.toUnmodifiableSet())) .thenCompose(ids -> to(kafkaAdmin.describeLogDirs(ids).allDescriptions())) .thenApply( ds -> diff --git a/common/src/main/java/org/astraea/common/admin/ClusterInfo.java b/common/src/main/java/org/astraea/common/admin/ClusterInfo.java index 8fa96e13e9..0be6ff795a 100644 --- a/common/src/main/java/org/astraea/common/admin/ClusterInfo.java +++ b/common/src/main/java/org/astraea/common/admin/ClusterInfo.java @@ -307,7 +307,7 @@ default Set topicPartitionReplicas() { * associated to any node */ default Broker node(int id) { - return nodes().stream() + return brokers().stream() .filter(n -> n.id() == id) .findAny() .orElseThrow(() -> new NoSuchElementException(id + " is nonexistent")); @@ -355,16 +355,9 @@ default Stream replicaStream(TopicPartitionReplica replica) { // ---------------------[abstract methods]---------------------// /** - * @return The known nodes + * @return The known brokers */ - List nodes(); - - default List brokers() { - return nodes().stream() - .filter(n -> n instanceof Broker) - .map(n -> (Broker) n) - .collect(Collectors.toUnmodifiableList()); - } + List brokers(); /** * @return replica stream to offer effective way to operate a bunch of replicas diff --git a/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java b/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java index 31d99e092e..f943e3005b 100644 --- a/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java +++ b/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java @@ -323,7 +323,7 @@ public ClusterInfoBuilder setPreferredLeader(TopicPartitionReplica replica) { * ClusterInfo}. */ public ClusterInfo build() { - var nodes = sourceCluster.nodes(); + var nodes = sourceCluster.brokers(); var replicas = sourceCluster.replicas(); for (var alteration : alterations) { var e = alteration.apply(nodes, replicas); diff --git a/common/src/main/java/org/astraea/common/admin/OptimizedClusterInfo.java b/common/src/main/java/org/astraea/common/admin/OptimizedClusterInfo.java index 3a18d2b795..e034b9368e 100644 --- a/common/src/main/java/org/astraea/common/admin/OptimizedClusterInfo.java +++ b/common/src/main/java/org/astraea/common/admin/OptimizedClusterInfo.java @@ -201,7 +201,7 @@ public Set topicNames() { } @Override - public List nodes() { + public List brokers() { return brokers; } diff --git a/common/src/main/java/org/astraea/common/balancer/BalancerUtils.java b/common/src/main/java/org/astraea/common/balancer/BalancerUtils.java index d846905f0b..c352de416f 100644 --- a/common/src/main/java/org/astraea/common/balancer/BalancerUtils.java +++ b/common/src/main/java/org/astraea/common/balancer/BalancerUtils.java @@ -26,8 +26,8 @@ import java.util.stream.IntStream; import java.util.stream.Stream; import org.astraea.common.EnumInfo; +import org.astraea.common.admin.Broker; import org.astraea.common.admin.ClusterInfo; -import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.Replica; public final class BalancerUtils { @@ -57,7 +57,7 @@ public static Map balancingMode(ClusterInfo cluster, St (id) -> map.getOrDefault(id, map.getOrDefault("default", BalancingModes.BALANCING)); return cluster.brokers().stream() - .map(NodeInfo::id) + .map(Broker::id) .collect(Collectors.toUnmodifiableMap(Function.identity(), mode)); } @@ -82,7 +82,7 @@ public static void verifyClearBrokerValidness( var ongoingEventReplica = cluster.replicas().stream() - .filter(r -> isDemoted.test(r.nodeInfo().id())) + .filter(r -> isDemoted.test(r.broker().id())) .filter(r -> r.isAdding() || r.isRemoving() || r.isFuture()) .map(Replica::topicPartitionReplica) .collect(Collectors.toUnmodifiableSet()); @@ -102,7 +102,7 @@ public static void verifyClearBrokerValidness( public static ClusterInfo clearedCluster( ClusterInfo initial, Predicate clearBrokers, Predicate allowedBrokers) { final var allowed = - initial.nodes().stream() + initial.brokers().stream() .filter(node -> allowedBrokers.test(node.id())) .filter(node -> Predicate.not(clearBrokers).test(node.id())) .collect(Collectors.toUnmodifiableSet()); @@ -121,12 +121,12 @@ public static ClusterInfo clearedCluster( tp -> tp, tp -> initial.replicas(tp).stream() - .map(Replica::nodeInfo) + .map(Replica::broker) .collect(Collectors.toSet()))); return ClusterInfo.builder(initial) .mapLog( replica -> { - if (!clearBrokers.test(replica.nodeInfo().id())) return replica; + if (!clearBrokers.test(replica.broker().id())) return replica; var currentReplicaList = trackingReplicaList.get(replica.topicPartition()); var broker = IntStream.range(0, allowed.size()) @@ -139,10 +139,10 @@ public static ClusterInfo clearedCluster( "Unable to clear replica " + replica.topicPartitionReplica() + " for broker " - + replica.nodeInfo().id() + + replica.broker().id() + ", the allowed destination brokers are " + allowed.stream() - .map(NodeInfo::id) + .map(Broker::id) .collect(Collectors.toUnmodifiableSet()) + " but all of them already hosting a replica for this partition. " + "There is no broker can adopt this replica.")); @@ -150,10 +150,10 @@ public static ClusterInfo clearedCluster( // update the tracking list. have to do this to avoid putting two replicas from the // same tp to one broker. - currentReplicaList.remove(replica.nodeInfo()); + currentReplicaList.remove(replica.broker()); currentReplicaList.add(broker); - return Replica.builder(replica).nodeInfo(broker).path(folder).build(); + return Replica.builder(replica).broker(broker).path(folder).build(); }) .build(); } diff --git a/common/src/main/java/org/astraea/common/balancer/tweakers/ShuffleTweaker.java b/common/src/main/java/org/astraea/common/balancer/tweakers/ShuffleTweaker.java index 4febc3aaf5..5584294b6f 100644 --- a/common/src/main/java/org/astraea/common/balancer/tweakers/ShuffleTweaker.java +++ b/common/src/main/java/org/astraea/common/balancer/tweakers/ShuffleTweaker.java @@ -65,13 +65,13 @@ public static Builder builder() { public Stream generate(ClusterInfo baseAllocation) { // There is no broker - if (baseAllocation.nodes().isEmpty()) return Stream.of(); + if (baseAllocation.brokers().isEmpty()) return Stream.of(); // No replica to working on. if (baseAllocation.replicas().size() == 0) return Stream.of(); // Only one broker & one folder exists, unable to do any meaningful log migration - if (baseAllocation.nodes().size() == 1 + if (baseAllocation.brokers().size() == 1 && baseAllocation.brokerFolders().values().stream().findFirst().orElseThrow().size() == 1) return Stream.of(); diff --git a/common/src/main/java/org/astraea/common/cost/BrokerDiskSpaceCost.java b/common/src/main/java/org/astraea/common/cost/BrokerDiskSpaceCost.java index 180f9d3d58..db06eb3101 100644 --- a/common/src/main/java/org/astraea/common/cost/BrokerDiskSpaceCost.java +++ b/common/src/main/java/org/astraea/common/cost/BrokerDiskSpaceCost.java @@ -73,7 +73,7 @@ private Map brokerMoveCostLimit(Configuration configuration) static boolean brokerDiskUsageSizeOverflow( ClusterInfo before, ClusterInfo after, Map brokerMoveCostLimit) { for (var id : - Stream.concat(before.nodes().stream(), after.nodes().stream()) + Stream.concat(before.brokers().stream(), after.brokers().stream()) .map(Broker::id) .parallel() .collect(Collectors.toSet())) { diff --git a/common/src/main/java/org/astraea/common/cost/CostUtils.java b/common/src/main/java/org/astraea/common/cost/CostUtils.java index 77c64daa15..32506b9782 100644 --- a/common/src/main/java/org/astraea/common/cost/CostUtils.java +++ b/common/src/main/java/org/astraea/common/cost/CostUtils.java @@ -32,7 +32,7 @@ static boolean changedRecordSizeOverflow( var totalRemovedSize = 0L; var totalAddedSize = 0L; for (var id : - Stream.concat(before.nodes().stream(), after.nodes().stream()) + Stream.concat(before.brokers().stream(), after.brokers().stream()) .map(Broker::id) .parallel() .collect(Collectors.toSet())) { diff --git a/common/src/main/java/org/astraea/common/cost/MigrationCost.java b/common/src/main/java/org/astraea/common/cost/MigrationCost.java index 9616ffef3a..ef673b40be 100644 --- a/common/src/main/java/org/astraea/common/cost/MigrationCost.java +++ b/common/src/main/java/org/astraea/common/cost/MigrationCost.java @@ -110,7 +110,7 @@ private static Map migratedChanged( r -> r.broker().id(), Collectors.mapping( Function.identity(), Collectors.summingLong(replicaFunction::apply)))); - return Stream.concat(dest.nodes().stream(), source.nodes().stream()) + return Stream.concat(dest.brokers().stream(), source.brokers().stream()) .map(Broker::id) .distinct() .parallel() @@ -118,7 +118,7 @@ private static Map migratedChanged( } private static Map changedReplicaNumber(ClusterInfo before, ClusterInfo after) { - return Stream.concat(before.nodes().stream(), after.nodes().stream()) + return Stream.concat(before.brokers().stream(), after.brokers().stream()) .map(Broker::id) .distinct() .parallel() diff --git a/common/src/main/java/org/astraea/common/cost/NetworkCost.java b/common/src/main/java/org/astraea/common/cost/NetworkCost.java index 097bec5239..1619b954ee 100644 --- a/common/src/main/java/org/astraea/common/cost/NetworkCost.java +++ b/common/src/main/java/org/astraea/common/cost/NetworkCost.java @@ -154,7 +154,7 @@ public ClusterCost clusterCost(ClusterInfo clusterInfo, ClusterBean clusterBean) }) .sum())); // add the brokers having no replicas into map - clusterInfo.nodes().stream() + clusterInfo.brokers().stream() .filter(node -> !brokerIngressRate.containsKey(node.id())) .forEach( node -> { diff --git a/common/src/main/java/org/astraea/common/cost/NodeMetricsCost.java b/common/src/main/java/org/astraea/common/cost/NodeMetricsCost.java index 2a2cb1d126..f6acad9bef 100644 --- a/common/src/main/java/org/astraea/common/cost/NodeMetricsCost.java +++ b/common/src/main/java/org/astraea/common/cost/NodeMetricsCost.java @@ -59,7 +59,7 @@ public BrokerCost brokerCost(ClusterInfo clusterInfo, ClusterBean clusterBean) { .max() .ifPresent( max -> - clusterInfo.nodes().stream() + clusterInfo.brokers().stream() .map(Broker::id) .filter(id -> !result.containsKey(id)) .forEach(id -> result.put(id, max))); diff --git a/common/src/main/java/org/astraea/common/cost/RecordSizeCost.java b/common/src/main/java/org/astraea/common/cost/RecordSizeCost.java index 05b480645e..6a1085f792 100644 --- a/common/src/main/java/org/astraea/common/cost/RecordSizeCost.java +++ b/common/src/main/java/org/astraea/common/cost/RecordSizeCost.java @@ -43,7 +43,7 @@ public RecordSizeCost(Configuration config) { @Override public BrokerCost brokerCost(ClusterInfo clusterInfo, ClusterBean clusterBean) { var result = - clusterInfo.nodes().stream() + clusterInfo.brokers().stream() .collect( Collectors.toMap( Broker::id, diff --git a/common/src/main/java/org/astraea/common/cost/ReplicaLeaderCost.java b/common/src/main/java/org/astraea/common/cost/ReplicaLeaderCost.java index 7d4f4346e6..0ea33d71d2 100644 --- a/common/src/main/java/org/astraea/common/cost/ReplicaLeaderCost.java +++ b/common/src/main/java/org/astraea/common/cost/ReplicaLeaderCost.java @@ -62,7 +62,7 @@ public ClusterCost clusterCost(ClusterInfo clusterInfo, ClusterBean clusterBean) } static Map leaderCount(ClusterInfo clusterInfo) { - return clusterInfo.nodes().stream() + return clusterInfo.brokers().stream() .map(nodeInfo -> Map.entry(nodeInfo.id(), clusterInfo.replicaLeaders(nodeInfo.id()).size())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } diff --git a/common/src/main/java/org/astraea/common/metrics/MetricSeriesBuilder.java b/common/src/main/java/org/astraea/common/metrics/MetricSeriesBuilder.java index eede63dfff..206b7c40e7 100644 --- a/common/src/main/java/org/astraea/common/metrics/MetricSeriesBuilder.java +++ b/common/src/main/java/org/astraea/common/metrics/MetricSeriesBuilder.java @@ -109,7 +109,7 @@ public MetricSeriesBuilder seriesByBroker( start, (t) -> t.isBefore(end) || t.isEqual(end), (t) -> t.plus(interval)) .flatMap( time -> - cluster.nodes().stream() + cluster.brokers().stream() .map( node -> Map.entry(node.id(), seriesGenerator.apply(time, node.id())))) @@ -128,7 +128,7 @@ public MetricSeriesBuilder seriesByBrokerTopic( final var interval = sampleInterval; this.series.add( () -> - cluster.nodes().stream() + cluster.brokers().stream() .collect( Collectors.toUnmodifiableMap( Broker::id, @@ -159,7 +159,7 @@ public MetricSeriesBuilder seriesByBrokerPartition( final var interval = sampleInterval; this.series.add( () -> - cluster.nodes().stream() + cluster.brokers().stream() .collect( Collectors.toUnmodifiableMap( Broker::id, @@ -189,7 +189,7 @@ public MetricSeriesBuilder seriesByBrokerReplica( final var interval = sampleInterval; this.series.add( () -> - cluster.nodes().stream() + cluster.brokers().stream() .collect( Collectors.toUnmodifiableMap( Broker::id, diff --git a/common/src/main/java/org/astraea/common/partitioner/RoundRobinKeeper.java b/common/src/main/java/org/astraea/common/partitioner/RoundRobinKeeper.java index c04bc7d27f..b93ebb3b3d 100644 --- a/common/src/main/java/org/astraea/common/partitioner/RoundRobinKeeper.java +++ b/common/src/main/java/org/astraea/common/partitioner/RoundRobinKeeper.java @@ -46,7 +46,7 @@ void tryToUpdate(ClusterInfo clusterInfo, Supplier> costToS == now) { var roundRobin = RoundRobin.smooth(costToScore.get()); var ids = - clusterInfo.nodes().stream().map(Broker::id).collect(Collectors.toUnmodifiableSet()); + clusterInfo.brokers().stream().map(Broker::id).collect(Collectors.toUnmodifiableSet()); // TODO: make ROUND_ROBIN_LENGTH configurable ??? for (var index = 0; index < this.roundRobin.length; ++index) this.roundRobin[index] = roundRobin.next(ids).orElse(-1); diff --git a/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java b/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java index cf1df83962..fe38f66016 100644 --- a/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java +++ b/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java @@ -106,18 +106,6 @@ void testProducerStates() { } } - @Timeout(10) - @Test - void testNodeInfos() { - try (var admin = Admin.of(SERVICE.bootstrapServers())) { - var nodeInfos = admin.brokers().toCompletableFuture().join(); - Assertions.assertEquals(2, nodeInfos.size()); - var offlineNodeInfos = - nodeInfos.stream().filter(Broker::offline).collect(Collectors.toList()); - Assertions.assertEquals(0, offlineNodeInfos.size()); - } - } - @Timeout(10) @Test void testBrokers() { diff --git a/common/src/test/java/org/astraea/common/admin/ClusterInfoBuilderTest.java b/common/src/test/java/org/astraea/common/admin/ClusterInfoBuilderTest.java index d27b71bb1b..8bebbe37a4 100644 --- a/common/src/test/java/org/astraea/common/admin/ClusterInfoBuilderTest.java +++ b/common/src/test/java/org/astraea/common/admin/ClusterInfoBuilderTest.java @@ -47,23 +47,23 @@ void testBuild() { ClusterInfo.of("fake", List.of(host1000, host2000, host3000), Map.of(), List.of(replica)); Assertions.assertEquals( - List.of(host1000, host2000, host3000), ClusterInfo.builder(cluster).build().nodes()); + List.of(host1000, host2000, host3000), ClusterInfo.builder(cluster).build().brokers()); Assertions.assertEquals(List.of(replica), ClusterInfo.builder(cluster).build().replicas()); - Assertions.assertEquals(List.of(), ClusterInfo.builder().build().nodes()); + Assertions.assertEquals(List.of(), ClusterInfo.builder().build().brokers()); Assertions.assertEquals(List.of(), ClusterInfo.builder().build().replicas()); } @Test void addNode() { - Assertions.assertEquals(List.of(), ClusterInfo.builder().addNode(Set.of()).build().nodes()); + Assertions.assertEquals(List.of(), ClusterInfo.builder().addNode(Set.of()).build().brokers()); Assertions.assertEquals( Set.of(1, 2, 3, 4, 5, 100), - ClusterInfo.builder().addNode(Set.of(1, 2, 3, 4, 5, 100)).build().nodes().stream() + ClusterInfo.builder().addNode(Set.of(1, 2, 3, 4, 5, 100)).build().brokers().stream() .map(Broker::id) .collect(Collectors.toSet())); Assertions.assertEquals( - ClusterInfo.builder().addNode(Set.of(1, 2, 3)).build().nodes(), - ClusterInfo.builder().addNode(Set.of(1, 2, 3)).build().nodes(), + ClusterInfo.builder().addNode(Set.of(1, 2, 3)).build().brokers(), + ClusterInfo.builder().addNode(Set.of(1, 2, 3)).build().brokers(), "The port number is generated by deterministic random"); } @@ -350,14 +350,14 @@ void testRemoveNodes() { ClusterInfo.builder(base) .removeNodes(x -> Set.of(4, 5, 6, 7, 8, 9).contains(x)) .build() - .nodes() + .brokers() .stream() - .map(NodeInfo::id) + .map(Broker::id) .collect(Collectors.toSet())); Assertions.assertEquals( Set.of(1, 3, 5, 7, 9), - ClusterInfo.builder(base).removeNodes(x -> x % 2 == 0).build().nodes().stream() - .map(NodeInfo::id) + ClusterInfo.builder(base).removeNodes(x -> x % 2 == 0).build().brokers().stream() + .map(Broker::id) .collect(Collectors.toSet())); } } diff --git a/common/src/test/java/org/astraea/common/admin/ClusterInfoTest.java b/common/src/test/java/org/astraea/common/admin/ClusterInfoTest.java index 6cfd150487..126b46754a 100644 --- a/common/src/test/java/org/astraea/common/admin/ClusterInfoTest.java +++ b/common/src/test/java/org/astraea/common/admin/ClusterInfoTest.java @@ -61,7 +61,7 @@ public static ClusterInfo of(List replicas) { @Test void testEmptyCluster() { var emptyCluster = ClusterInfo.empty(); - Assertions.assertEquals(0, emptyCluster.nodes().size()); + Assertions.assertEquals(0, emptyCluster.brokers().size()); Assertions.assertEquals(0, emptyCluster.replicaStream().count()); } diff --git a/common/src/test/java/org/astraea/common/balancer/BalancerConfigTestSuite.java b/common/src/test/java/org/astraea/common/balancer/BalancerConfigTestSuite.java index fd075d959d..22c0e0a608 100644 --- a/common/src/test/java/org/astraea/common/balancer/BalancerConfigTestSuite.java +++ b/common/src/test/java/org/astraea/common/balancer/BalancerConfigTestSuite.java @@ -220,15 +220,12 @@ public void testBalancingModeDemoted() { .build()); Assertions.assertTrue(plan.isPresent(), testName); var finalCluster = plan.get().proposal(); - Assertions.assertTrue(cluster.replicas().stream().anyMatch(x -> x.nodeInfo().id() == 0)); - Assertions.assertTrue(cluster.replicas().stream().anyMatch(x -> x.nodeInfo().id() == 1)); - Assertions.assertTrue(cluster.replicas().stream().anyMatch(x -> x.nodeInfo().id() == 2)); - Assertions.assertTrue( - finalCluster.replicas().stream().noneMatch(x -> x.nodeInfo().id() == 0)); - Assertions.assertTrue( - finalCluster.replicas().stream().noneMatch(x -> x.nodeInfo().id() == 1)); - Assertions.assertTrue( - finalCluster.replicas().stream().noneMatch(x -> x.nodeInfo().id() == 2)); + Assertions.assertTrue(cluster.replicas().stream().anyMatch(x -> x.broker().id() == 0)); + Assertions.assertTrue(cluster.replicas().stream().anyMatch(x -> x.broker().id() == 1)); + Assertions.assertTrue(cluster.replicas().stream().anyMatch(x -> x.broker().id() == 2)); + Assertions.assertTrue(finalCluster.replicas().stream().noneMatch(x -> x.broker().id() == 0)); + Assertions.assertTrue(finalCluster.replicas().stream().noneMatch(x -> x.broker().id() == 1)); + Assertions.assertTrue(finalCluster.replicas().stream().noneMatch(x -> x.broker().id() == 2)); AssertionsHelper.assertBrokerEmpty( finalCluster, (x) -> Set.of(0, 1, 2).contains(x), testName); } @@ -293,16 +290,13 @@ public void testBalancingModeDemoted() { var node123 = Stream.of(1, 2, 3).map(base::node).iterator(); var testCluster = ClusterInfo.builder(base) - .addTopic("OK", 1, (short) 1, r -> Replica.builder(r).nodeInfo(base.node(1)).build()) + .addTopic("OK", 1, (short) 1, r -> Replica.builder(r).broker(base.node(1)).build()) .addTopic( - "OK_SKIP", 2, (short) 1, r -> Replica.builder(r).nodeInfo(node12.next()).build()) + "OK_SKIP", 2, (short) 1, r -> Replica.builder(r).broker(node12.next()).build()) .addTopic( - "Replica", 1, (short) 2, r -> Replica.builder(r).nodeInfo(node13.next()).build()) + "Replica", 1, (short) 2, r -> Replica.builder(r).broker(node13.next()).build()) .addTopic( - "Partition", - 3, - (short) 1, - r -> Replica.builder(r).nodeInfo(node123.next()).build()) + "Partition", 3, (short) 1, r -> Replica.builder(r).broker(node123.next()).build()) .build(); Assertions.assertDoesNotThrow( @@ -431,15 +425,15 @@ public void testBalancingModeDemoted() { var testName = "[if replica on clear broker is adding/removing/future, raise an exception]"; var adding = ClusterInfo.builder(cluster) - .mapLog(r -> r.nodeInfo().id() != 0 ? r : Replica.builder(r).isAdding(true).build()) + .mapLog(r -> r.broker().id() != 0 ? r : Replica.builder(r).isAdding(true).build()) .build(); var removing = ClusterInfo.builder(cluster) - .mapLog(r -> r.nodeInfo().id() != 0 ? r : Replica.builder(r).isRemoving(true).build()) + .mapLog(r -> r.broker().id() != 0 ? r : Replica.builder(r).isRemoving(true).build()) .build(); var future = ClusterInfo.builder(cluster) - .mapLog(r -> r.nodeInfo().id() != 0 ? r : Replica.builder(r).isFuture(true).build()) + .mapLog(r -> r.broker().id() != 0 ? r : Replica.builder(r).isFuture(true).build()) .build(); for (var cc : List.of(adding, removing, future)) { Assertions.assertThrows( @@ -603,7 +597,7 @@ static void assertBrokerEmpty(ClusterInfo target, Predicate clearBroker var violated = target .replicaStream() - .filter(i -> clearBroker.test(i.nodeInfo().id())) + .filter(i -> clearBroker.test(i.broker().id())) .collect(Collectors.toUnmodifiableSet()); Assertions.assertTrue( violated.isEmpty(), diff --git a/common/src/test/java/org/astraea/common/balancer/BalancerConsoleTest.java b/common/src/test/java/org/astraea/common/balancer/BalancerConsoleTest.java index d66e1f29a4..78b25a664e 100644 --- a/common/src/test/java/org/astraea/common/balancer/BalancerConsoleTest.java +++ b/common/src/test/java/org/astraea/common/balancer/BalancerConsoleTest.java @@ -286,7 +286,7 @@ void testCheckNoOngoingMigration() { CompletableFuture.completedFuture( ClusterInfo.of( cluster.clusterId(), - cluster.nodes(), + cluster.brokers(), cluster.topics(), cluster .replicaStream() diff --git a/common/src/test/java/org/astraea/common/balancer/BalancerTest.java b/common/src/test/java/org/astraea/common/balancer/BalancerTest.java index 3455da5e5a..9b57cfeb75 100644 --- a/common/src/test/java/org/astraea/common/balancer/BalancerTest.java +++ b/common/src/test/java/org/astraea/common/balancer/BalancerTest.java @@ -73,7 +73,7 @@ void testLeaderCountRebalance(Class theClass) { .clusterInfo(admin.topicNames(false).toCompletableFuture().join()) .toCompletableFuture() .join(); - return clusterInfo.nodes().stream() + return clusterInfo.brokers().stream() .collect( Collectors.toMap( Broker::id, diff --git a/common/src/test/java/org/astraea/common/balancer/BalancerUtilsTest.java b/common/src/test/java/org/astraea/common/balancer/BalancerUtilsTest.java index bf27b63426..341968b28b 100644 --- a/common/src/test/java/org/astraea/common/balancer/BalancerUtilsTest.java +++ b/common/src/test/java/org/astraea/common/balancer/BalancerUtilsTest.java @@ -101,9 +101,9 @@ void testVerifyClearBrokerValidness() { var iter = Stream.of(1, 2, 3).map(base::node).iterator(); var cluster = ClusterInfo.builder(base) - .addTopic("A", 1, (short) 1, r -> Replica.builder(r).nodeInfo(iter.next()).build()) - .addTopic("B", 1, (short) 1, r -> Replica.builder(r).nodeInfo(iter.next()).build()) - .addTopic("C", 1, (short) 1, r -> Replica.builder(r).nodeInfo(iter.next()).build()) + .addTopic("A", 1, (short) 1, r -> Replica.builder(r).broker(iter.next()).build()) + .addTopic("B", 1, (short) 1, r -> Replica.builder(r).broker(iter.next()).build()) + .addTopic("C", 1, (short) 1, r -> Replica.builder(r).broker(iter.next()).build()) .build(); Assertions.assertThrows( @@ -173,13 +173,13 @@ void testClearedCluster() { cluster, id -> id == 1 || id == 2, id -> id == 3 || id == 4)); Assertions.assertEquals( - List.of(), clearedCluster.replicas().stream().filter(x -> x.nodeInfo().id() == 1).toList()); + List.of(), clearedCluster.replicas().stream().filter(x -> x.broker().id() == 1).toList()); Assertions.assertEquals( - List.of(), clearedCluster.replicas().stream().filter(x -> x.nodeInfo().id() == 2).toList()); + List.of(), clearedCluster.replicas().stream().filter(x -> x.broker().id() == 2).toList()); Assertions.assertNotEquals( - List.of(), clearedCluster.replicas().stream().filter(x -> x.nodeInfo().id() == 3).toList()); + List.of(), clearedCluster.replicas().stream().filter(x -> x.broker().id() == 3).toList()); Assertions.assertNotEquals( - List.of(), clearedCluster.replicas().stream().filter(x -> x.nodeInfo().id() == 4).toList()); + List.of(), clearedCluster.replicas().stream().filter(x -> x.broker().id() == 4).toList()); var sameCluster = Assertions.assertDoesNotThrow( @@ -193,16 +193,16 @@ void testClearedCluster() { Assertions.assertDoesNotThrow( () -> BalancerUtils.clearedCluster(cluster, id -> id == 1, id -> id == 3)); Assertions.assertEquals( - 0, aCluster.replicas().stream().filter(r -> r.nodeInfo().id() == 1).count(), "Demoted"); + 0, aCluster.replicas().stream().filter(r -> r.broker().id() == 1).count(), "Demoted"); Assertions.assertEquals( 100, - aCluster.replicas().stream().filter(r -> r.nodeInfo().id() == 2).count(), + aCluster.replicas().stream().filter(r -> r.broker().id() == 2).count(), "Not allowed or cleared"); Assertions.assertEquals( 100, - aCluster.replicas().stream().filter(r -> r.nodeInfo().id() == 3).count(), + aCluster.replicas().stream().filter(r -> r.broker().id() == 3).count(), "Accept replicas broker demoted broker"); Assertions.assertEquals( - 0, aCluster.replicas().stream().filter(r -> r.nodeInfo().id() == 4).count(), "Not allowed"); + 0, aCluster.replicas().stream().filter(r -> r.broker().id() == 4).count(), "Not allowed"); } } diff --git a/common/src/test/java/org/astraea/common/cost/BrokerDiskSpaceCostTest.java b/common/src/test/java/org/astraea/common/cost/BrokerDiskSpaceCostTest.java index e39093b12f..c91f089582 100644 --- a/common/src/test/java/org/astraea/common/cost/BrokerDiskSpaceCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/BrokerDiskSpaceCostTest.java @@ -237,12 +237,12 @@ public static ClusterInfo of(List replicas) { .map(Replica::broker) .distinct() .map( - nodeInfo -> + broker -> Broker.of( false, - new Node(nodeInfo.id(), "", nodeInfo.port()), + new Node(broker.id(), "", broker.port()), Map.of(), - dataPath.get(nodeInfo.id()), + dataPath.get(broker.id()), List.of())) .collect(Collectors.toList()), Map.of(), @@ -332,12 +332,12 @@ private static ClusterInfo beforeClusterInfo() { .map(Replica::broker) .distinct() .map( - nodeInfo -> + broker -> Broker.of( false, - new Node(nodeInfo.id(), "", nodeInfo.port()), + new Node(broker.id(), "", broker.port()), Map.of(), - dataPath.get(nodeInfo.id()), + dataPath.get(broker.id()), List.of())) .collect(Collectors.toList()), Map.of(), @@ -413,12 +413,12 @@ private static ClusterInfo afterClusterInfo() { .map(Replica::broker) .distinct() .map( - nodeInfo -> + broker -> Broker.of( false, - new Node(nodeInfo.id(), "", nodeInfo.port()), + new Node(broker.id(), "", broker.port()), Map.of(), - dataPath.get(nodeInfo.id()), + dataPath.get(broker.id()), List.of())) .collect(Collectors.toList()), Map.of(), diff --git a/common/src/test/java/org/astraea/common/cost/CostUtilsTest.java b/common/src/test/java/org/astraea/common/cost/CostUtilsTest.java index d672cd993d..db1817e725 100644 --- a/common/src/test/java/org/astraea/common/cost/CostUtilsTest.java +++ b/common/src/test/java/org/astraea/common/cost/CostUtilsTest.java @@ -140,12 +140,12 @@ private static ClusterInfo beforeClusterInfo() { .map(Replica::broker) .distinct() .map( - nodeInfo -> + broker -> Broker.of( false, - new Node(nodeInfo.id(), "", nodeInfo.port()), + new Node(broker.id(), "", broker.port()), Map.of(), - dataPath.get(nodeInfo.id()), + dataPath.get(broker.id()), List.of())) .collect(Collectors.toList()), Map.of(), @@ -221,12 +221,12 @@ private static ClusterInfo afterClusterInfo() { .map(Replica::broker) .distinct() .map( - nodeInfo -> + broker -> Broker.of( false, - new Node(nodeInfo.id(), "", nodeInfo.port()), + new Node(broker.id(), "", broker.port()), Map.of(), - dataPath.get(nodeInfo.id()), + dataPath.get(broker.id()), List.of())) .collect(Collectors.toList()), Map.of(), diff --git a/common/src/test/java/org/astraea/common/cost/utils/ClusterInfoSensorTest.java b/common/src/test/java/org/astraea/common/cost/utils/ClusterInfoSensorTest.java index 818660d2e6..94fbcc9b4a 100644 --- a/common/src/test/java/org/astraea/common/cost/utils/ClusterInfoSensorTest.java +++ b/common/src/test/java/org/astraea/common/cost/utils/ClusterInfoSensorTest.java @@ -241,7 +241,7 @@ void testClusterId() { var info = ClusterInfoSensor.metricViewCluster(cb); - Assertions.assertEquals(1, info.nodes().size()); + Assertions.assertEquals(1, info.brokers().size()); Assertions.assertEquals(id, info.clusterId()); } diff --git a/common/src/test/java/org/astraea/common/partitioner/PartitionerTest.java b/common/src/test/java/org/astraea/common/partitioner/PartitionerTest.java index af5fa82063..a877df3912 100644 --- a/common/src/test/java/org/astraea/common/partitioner/PartitionerTest.java +++ b/common/src/test/java/org/astraea/common/partitioner/PartitionerTest.java @@ -79,7 +79,7 @@ public int partition(String topic, byte[] key, byte[] value, ClusterInfo cluster Map.of(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, SERVICE.bootstrapServers())); Assertions.assertNotNull(partitioner.admin); Utils.sleep(Duration.ofSeconds(3)); - Assertions.assertNotEquals(0, partitioner.clusterInfo.nodes().size()); + Assertions.assertNotEquals(0, partitioner.clusterInfo.brokers().size()); } } diff --git a/gui/src/main/java/org/astraea/gui/tab/SettingNode.java b/gui/src/main/java/org/astraea/gui/tab/SettingNode.java index 669071a3e2..1e0f40b006 100644 --- a/gui/src/main/java/org/astraea/gui/tab/SettingNode.java +++ b/gui/src/main/java/org/astraea/gui/tab/SettingNode.java @@ -153,12 +153,12 @@ public static Node of(Context context) { client .map(ConnectorClient::activeWorkers) .orElse(CompletableFuture.completedFuture(List.of())), - (nodeInfos, workers) -> { + (brokers, workers) -> { context.replace(newAdmin); client.ifPresent(context::replace); prop.brokerJmxPort.ifPresent(context::brokerJmxPort); prop.workerJmxPort.ifPresent(context::workerJmxPort); - context.addBrokerClients(nodeInfos); + context.addBrokerClients(brokers); context.addWorkerClients( workers.stream() .map(WorkerStatus::hostname) From 51a7b317cd33cfa7cafc474b05aed405d5eacb27 Mon Sep 17 00:00:00 2001 From: Chao-Heng Lee Date: Mon, 22 May 2023 16:55:06 +0800 Subject: [PATCH 07/11] remove redundant casting. --- .../org/astraea/common/admin/ClusterInfoBuilder.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java b/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java index f943e3005b..627e8c82a7 100644 --- a/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java +++ b/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java @@ -169,8 +169,7 @@ public ClusterInfoBuilder addTopic( + nodes.size() + " < " + replicaFactor); - var nodeSelector = - Stream.generate(nodes::stream).flatMap(x -> x).map(x -> (Broker) x).iterator(); + var nodeSelector = Stream.generate(nodes::stream).flatMap(x -> x).iterator(); // simulate the actual Kafka logic of log placement var folderLogCounter = @@ -179,11 +178,10 @@ public ClusterInfoBuilder addTopic( Collectors.toUnmodifiableMap( node -> node, node -> - ((Broker) node) - .dataFolders().stream() - .collect( - Collectors.toMap( - Broker.DataFolder::path, x -> new AtomicInteger())))); + node.dataFolders().stream() + .collect( + Collectors.toMap( + Broker.DataFolder::path, x -> new AtomicInteger())))); replicas.forEach( replica -> folderLogCounter.get(replica.broker()).get(replica.path()).incrementAndGet()); From 676ef25b79e9ee2b98e5be309851e3339543ebd7 Mon Sep 17 00:00:00 2001 From: Chao-Heng Lee Date: Mon, 22 May 2023 17:30:48 +0800 Subject: [PATCH 08/11] remove redundant statement. --- .../main/java/org/astraea/common/admin/ClusterInfoBuilder.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java b/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java index 627e8c82a7..2661d46071 100644 --- a/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java +++ b/common/src/main/java/org/astraea/common/admin/ClusterInfoBuilder.java @@ -161,8 +161,6 @@ public ClusterInfoBuilder addTopic( String topicName, int partitionSize, short replicaFactor, Function mapper) { return applyReplicas( (nodes, replicas) -> { - if (nodes.stream().anyMatch(node -> !(node instanceof Broker))) - throw new IllegalStateException("All the nodes must include the folder info"); if (nodes.size() < replicaFactor) throw new IllegalArgumentException( "Insufficient node for this replica factor: " From d82af44747f400ff9ec0975af9e698ca87253601 Mon Sep 17 00:00:00 2001 From: Chao-Heng Lee Date: Tue, 23 May 2023 16:18:12 +0800 Subject: [PATCH 09/11] add javadoc of Broker. replace consumerGroup.coordinator to coordinatorId. --- .../org/astraea/common/admin/AdminImpl.java | 10 ++------- .../java/org/astraea/common/admin/Broker.java | 21 +++++++++++++------ .../astraea/common/admin/ConsumerGroup.java | 2 +- .../org/astraea/common/admin/AdminTest.java | 2 +- .../java/org/astraea/gui/tab/ClientNode.java | 2 +- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/org/astraea/common/admin/AdminImpl.java b/common/src/main/java/org/astraea/common/admin/AdminImpl.java index 08e80fb9ad..74568e9d3e 100644 --- a/common/src/main/java/org/astraea/common/admin/AdminImpl.java +++ b/common/src/main/java/org/astraea/common/admin/AdminImpl.java @@ -515,11 +515,7 @@ public CompletionStage> consumerGroups(Set consumerG .collect(Collectors.toUnmodifiableList())) .thenApply( s -> s.stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))), - brokers() - .thenApply( - brokers -> - brokers.stream().collect(Collectors.toMap(Broker::id, broker -> broker))), - (consumerGroupDescriptions, consumerGroupMetadata, brokers) -> + (consumerGroupDescriptions, consumerGroupMetadata) -> consumerGroupIds.stream() .map( groupId -> @@ -527,9 +523,7 @@ public CompletionStage> consumerGroups(Set consumerG groupId, consumerGroupDescriptions.get(groupId).partitionAssignor(), consumerGroupDescriptions.get(groupId).state().name(), - brokers.getOrDefault( - consumerGroupDescriptions.get(groupId).coordinator().id(), - Broker.of(consumerGroupDescriptions.get(groupId).coordinator())), + consumerGroupDescriptions.get(groupId).coordinator().id(), consumerGroupMetadata.get(groupId).entrySet().stream() .collect( Collectors.toUnmodifiableMap( diff --git a/common/src/main/java/org/astraea/common/admin/Broker.java b/common/src/main/java/org/astraea/common/admin/Broker.java index c81777000b..9e99102178 100644 --- a/common/src/main/java/org/astraea/common/admin/Broker.java +++ b/common/src/main/java/org/astraea/common/admin/Broker.java @@ -23,17 +23,24 @@ import java.util.stream.Collectors; import org.apache.kafka.common.requests.DescribeLogDirsResponse; +/** + * @param id + * @param host + * @param port + * @param isController + * @param config config used by this node + * @param dataFolders the disk folder used to stored data by this node + * @param topicPartitions + * @param topicPartitionLeaders partition leaders hosted by this broker + */ public record Broker( int id, String host, int port, boolean isController, - // config used by this node Config config, - // the disk folder used to stored data by this node List dataFolders, Set topicPartitions, - // partition leaders hosted by this broker Set topicPartitionLeaders) { /** @@ -108,11 +115,13 @@ public static Broker of( topicPartitionLeaders); } + /** + * @param path the path on the local disk + * @param partitionSizes topic partition hosed by this node and size of files + * @param orphanPartitionSizes topic partition located by this node but not traced by cluster + */ public record DataFolder( - // the path on the local disk String path, - // topic partition hosed by this node and size of files Map partitionSizes, - // topic partition located by this node but not traced by cluster Map orphanPartitionSizes) {} } diff --git a/common/src/main/java/org/astraea/common/admin/ConsumerGroup.java b/common/src/main/java/org/astraea/common/admin/ConsumerGroup.java index 9269ec0540..ef8a696e83 100644 --- a/common/src/main/java/org/astraea/common/admin/ConsumerGroup.java +++ b/common/src/main/java/org/astraea/common/admin/ConsumerGroup.java @@ -23,6 +23,6 @@ public record ConsumerGroup( String groupId, String assignor, String state, - Broker coordinator, + int coordinatorId, Map consumeProgress, Map> assignment) {} diff --git a/common/src/test/java/org/astraea/common/admin/AdminTest.java b/common/src/test/java/org/astraea/common/admin/AdminTest.java index f6eaf4cf9b..448bae7de6 100644 --- a/common/src/test/java/org/astraea/common/admin/AdminTest.java +++ b/common/src/test/java/org/astraea/common/admin/AdminTest.java @@ -999,7 +999,7 @@ void testConsumerGroups() { .forEach( c -> { Assertions.assertNotNull(c.groupId()); - Assertions.assertNotNull(c.coordinator()); + Assertions.assertNotNull(c.coordinatorId()); Assertions.assertNotNull(c.assignor()); Assertions.assertNotNull(c.state()); }); diff --git a/gui/src/main/java/org/astraea/gui/tab/ClientNode.java b/gui/src/main/java/org/astraea/gui/tab/ClientNode.java index f3378f5111..abad4cd470 100644 --- a/gui/src/main/java/org/astraea/gui/tab/ClientNode.java +++ b/gui/src/main/java/org/astraea/gui/tab/ClientNode.java @@ -184,7 +184,7 @@ static List> consumerResult( result.put("group", cg.groupId()); result.put("assignor", cg.assignor()); result.put("state", cg.state()); - result.put("coordinator", cg.coordinator().id()); + result.put("coordinator", cg.coordinatorId()); result.put("topic", tp.topic()); result.put("partition", tp.partition()); Optional.ofNullable(cg.consumeProgress().get(tp)) From de79bcce777d46257af1659ae797c2a71fd88a45 Mon Sep 17 00:00:00 2001 From: Chao-Heng Lee Date: Tue, 23 May 2023 16:58:07 +0800 Subject: [PATCH 10/11] replace Partition.leader to leaderId. --- .../java/org/astraea/common/admin/AdminImpl.java | 2 +- .../java/org/astraea/common/admin/Partition.java | 4 ++-- .../java/org/astraea/common/admin/AdminTest.java | 13 +++++++------ .../common/admin/AdminWithOfflineBrokerTest.java | 4 ++-- .../java/org/astraea/gui/tab/health/HealthNode.java | 10 ++++------ .../org/astraea/gui/tab/topic/PartitionNode.java | 2 +- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/common/src/main/java/org/astraea/common/admin/AdminImpl.java b/common/src/main/java/org/astraea/common/admin/AdminImpl.java index 74568e9d3e..2d0c01eba5 100644 --- a/common/src/main/java/org/astraea/common/admin/AdminImpl.java +++ b/common/src/main/java/org/astraea/common/admin/AdminImpl.java @@ -420,7 +420,7 @@ public CompletionStage> partitions(Set topics) { var leader = tpInfo.leader() == null || tpInfo.leader().isEmpty() ? null - : brokers.get(tpInfo.leader().id()); + : tpInfo.leader().id(); var replicas = tpInfo.replicas().stream() .map(node -> brokers.getOrDefault(node.id(), Broker.of(node))) diff --git a/common/src/main/java/org/astraea/common/admin/Partition.java b/common/src/main/java/org/astraea/common/admin/Partition.java index 3e9d876efd..1addd8330b 100644 --- a/common/src/main/java/org/astraea/common/admin/Partition.java +++ b/common/src/main/java/org/astraea/common/admin/Partition.java @@ -24,7 +24,7 @@ * @param latestOffset existent latest offset * @param maxTimestamp max timestamp of existent records. If the kafka servers don't support to * fetch max timestamp, this method will return empty - * @param leader null if the node gets offline. otherwise, it returns node info. + * @param leaderId null if the node gets offline. otherwise, it returns node id. * @param internal true if this topic is internal (system) topic */ public record Partition( @@ -33,7 +33,7 @@ public record Partition( long earliestOffset, long latestOffset, Optional maxTimestamp, - Optional leader, + Optional leaderId, List replicas, List isr, boolean internal) { diff --git a/common/src/test/java/org/astraea/common/admin/AdminTest.java b/common/src/test/java/org/astraea/common/admin/AdminTest.java index 448bae7de6..a0675e8184 100644 --- a/common/src/test/java/org/astraea/common/admin/AdminTest.java +++ b/common/src/test/java/org/astraea/common/admin/AdminTest.java @@ -24,6 +24,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.SortedSet; @@ -378,10 +379,10 @@ void testMoveLeaderBroker() { var ids = List.of( SERVICE.dataFolders().keySet().stream() - .filter(i -> i != partition.leader().get().id()) + .filter(i -> !Objects.equals(i, partition.leaderId().get())) .findFirst() .get(), - partition.leader().get().id()); + partition.leaderId().get()); admin.moveToBrokers(Map.of(TopicPartition.of(topic, 0), ids)).toCompletableFuture().join(); Utils.sleep(Duration.ofSeconds(2)); @@ -390,7 +391,7 @@ void testMoveLeaderBroker() { var newPartition = newPartitions.get(0); Assertions.assertEquals(ids.size(), newPartition.replicas().size()); Assertions.assertEquals(ids.size(), newPartition.isr().size()); - Assertions.assertNotEquals(ids.get(0), newPartition.leader().get().id()); + Assertions.assertNotEquals(ids.get(0), newPartition.leaderId().get()); admin .preferredLeaderElection( @@ -400,7 +401,7 @@ void testMoveLeaderBroker() { Utils.sleep(Duration.ofSeconds(2)); Assertions.assertEquals( ids.get(0), - admin.partitions(Set.of(topic)).toCompletableFuture().join().get(0).leader().get().id()); + admin.partitions(Set.of(topic)).toCompletableFuture().join().get(0).leaderId().get()); } } @@ -858,8 +859,8 @@ void testCreateTopicWithReplicasAssignment() { Assertions.assertEquals( List.of(2, 1), partitions.get(1).replicas().stream().map(Broker::id).collect(Collectors.toList())); - Assertions.assertEquals(0, partitions.get(0).leader().get().id()); - Assertions.assertEquals(2, partitions.get(1).leader().get().id()); + Assertions.assertEquals(0, partitions.get(0).leaderId().get()); + Assertions.assertEquals(2, partitions.get(1).leaderId().get()); } } diff --git a/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java b/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java index fe38f66016..43a9ebfc3a 100644 --- a/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java +++ b/common/src/test/java/org/astraea/common/admin/AdminWithOfflineBrokerTest.java @@ -80,7 +80,7 @@ static void closeOneBroker() { var allPs = admin.partitions(Set.of(TOPIC_NAME)).toCompletableFuture().join(); NUMBER_OF_ONLINE_PARTITIONS = PARTITIONS - - (int) allPs.stream().filter(p -> p.leader().get().id() == CLOSED_BROKER_ID).count(); + - (int) allPs.stream().filter(p -> p.leaderId().get() == CLOSED_BROKER_ID).count(); Assertions.assertEquals(PARTITIONS, allPs.size()); Utils.sleep(Duration.ofSeconds(2)); } @@ -128,7 +128,7 @@ void testPartitions() { var partitions = admin.partitions(Set.of(TOPIC_NAME)).toCompletableFuture().join(); Assertions.assertEquals(PARTITIONS, partitions.size()); var offlinePartitions = - partitions.stream().filter(p -> p.leader().isEmpty()).collect(Collectors.toList()); + partitions.stream().filter(p -> p.leaderId().isEmpty()).collect(Collectors.toList()); offlinePartitions.forEach( p -> { Assertions.assertEquals(1, p.replicas().size()); diff --git a/gui/src/main/java/org/astraea/gui/tab/health/HealthNode.java b/gui/src/main/java/org/astraea/gui/tab/health/HealthNode.java index 168161d10c..93fac415f2 100644 --- a/gui/src/main/java/org/astraea/gui/tab/health/HealthNode.java +++ b/gui/src/main/java/org/astraea/gui/tab/health/HealthNode.java @@ -109,15 +109,13 @@ static CompletionStage>> unavailablePartitions(Admin ad .filter( p -> p.isr().size() < minInSync.getOrDefault(p.topic(), 1) - || p.leader().isEmpty()) + || p.leaderId().isEmpty()) .map( p -> { var r = new LinkedHashMap(); r.put("topic", p.topic()); r.put("partition", p.partition()); - r.put( - "leader", - p.leader().map(n -> String.valueOf(n.id())).orElse("null")); + r.put("leader", p.leaderId().map(String::valueOf).orElse("null")); r.put( "in-sync replicas", p.isr().stream() @@ -126,10 +124,10 @@ static CompletionStage>> unavailablePartitions(Admin ad r.put( TopicConfigs.MIN_IN_SYNC_REPLICAS_CONFIG, minInSync.getOrDefault(p.topic(), 1)); - r.put("readable", p.leader().isPresent()); + r.put("readable", p.leaderId().isPresent()); r.put( "writable", - p.leader().isPresent() + p.leaderId().isPresent() && p.isr().size() >= minInSync.getOrDefault(p.topic(), 1)); return (Map) r; }) diff --git a/gui/src/main/java/org/astraea/gui/tab/topic/PartitionNode.java b/gui/src/main/java/org/astraea/gui/tab/topic/PartitionNode.java index b1d6e43416..49df25c46d 100644 --- a/gui/src/main/java/org/astraea/gui/tab/topic/PartitionNode.java +++ b/gui/src/main/java/org/astraea/gui/tab/topic/PartitionNode.java @@ -59,7 +59,7 @@ private static List> basicResult(List ps) { result.put(TOPIC_NAME_KEY, p.topic()); result.put(PARTITION_KEY, p.partition()); result.put("internal", p.internal()); - p.leader().ifPresent(l -> result.put("leader", l.id())); + p.leaderId().ifPresent(l -> result.put("leader", l)); result.put( "replicas", p.replicas().stream() From d705c75dd324dfdc5b60472892f5d6382fafba35 Mon Sep 17 00:00:00 2001 From: Chao-Heng Lee Date: Tue, 23 May 2023 20:02:44 +0800 Subject: [PATCH 11/11] spotless. --- app/src/main/java/org/astraea/app/web/WebService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/astraea/app/web/WebService.java b/app/src/main/java/org/astraea/app/web/WebService.java index 97d87b881c..e4e9eab6b4 100644 --- a/app/src/main/java/org/astraea/app/web/WebService.java +++ b/app/src/main/java/org/astraea/app/web/WebService.java @@ -75,7 +75,7 @@ public WebService( brokers.stream() .collect( Collectors.toUnmodifiableMap( - Broker::id, + Broker::id, b -> JndiClient.of(b.host(), brokerIdToJmxPort.apply(b.id())))); yield List.of( MetricStore.Receiver.local(() -> admin.brokers().thenApply(asBeanClientMap)));