@Test public void testMetadataChanged() { Node node0 = new Node(0, "localhost", 100, "rack0"); Node node1 = new Node(1, "localhost", 100, "rack1"); Node node2 = new Node(2, "localhost", 100, "rack2"); Node[] nodesWithOrder1 = {node0, node1}; Node[] nodesWithOrder2 = {node1, node0}; Node[] nodes2 = {node0, node2}; String topic0 = "topic0"; String topic1 = "topic1"; String topic2 = "topic2"; PartitionInfo t0p0 = new PartitionInfo(topic0, 0, node0, nodesWithOrder1, nodesWithOrder2); PartitionInfo t0p1 = new PartitionInfo(topic0, 1, node1, nodesWithOrder1, nodesWithOrder2); PartitionInfo t1p0 = new PartitionInfo(topic1, 0, node2, nodesWithOrder1, nodesWithOrder2); PartitionInfo t1p1 = new PartitionInfo(topic1, 1, node0, nodesWithOrder1, nodesWithOrder2); Set<PartitionInfo> partitions1 = new HashSet<>(Arrays.asList(t0p0, t0p1, t1p0, t1p1)); Cluster cluster1 = new Cluster("cluster", Arrays.asList(node0, node1, node2), partitions1, Collections.emptySet(), Collections.emptySet()); PartitionInfo t2p0 = new PartitionInfo(topic2, 0, node1, nodesWithOrder1, nodesWithOrder2); Cluster cluster2 = cluster1.withPartitions(Collections.singletonMap(new TopicPartition(topic2, 0), t2p0)); PartitionInfo t0p2 = new PartitionInfo(topic0, 2, node1, nodesWithOrder1, nodesWithOrder2); Cluster cluster3 = cluster1.withPartitions(Collections.singletonMap(new TopicPartition(topic2, 2), t0p2)); PartitionInfo t0p0DifferentOrder = new PartitionInfo(topic0, 0, node0, nodesWithOrder2, nodesWithOrder2); Cluster cluster4 = cluster1.withPartitions(Collections.singletonMap(new TopicPartition(topic0, 0), t0p0DifferentOrder)); PartitionInfo t0p0DifferentAssignment = new PartitionInfo(topic0, 0, node0, nodes2, nodesWithOrder2); Cluster cluster5 = cluster1.withPartitions(Collections.singletonMap(new TopicPartition(topic0, 0), t0p0DifferentAssignment)); PartitionInfo t0p0DifferentLeader = new PartitionInfo(topic0, 0, node1, nodesWithOrder1, nodesWithOrder2); Cluster cluster6 = cluster1.withPartitions(Collections.singletonMap(new TopicPartition(topic0, 0), t0p0DifferentLeader)); PartitionInfo t0p0DifferentIsr = new PartitionInfo(topic0, 0, node0, nodesWithOrder1, new Node[]{node0}); Cluster cluster7 = cluster1.withPartitions(Collections.singletonMap(new TopicPartition(topic0, 0), t0p0DifferentIsr)); assertTrue(MonitorUtils.metadataChanged(cluster1, cluster2)); assertTrue(MonitorUtils.metadataChanged(cluster1, cluster3)); assertTrue(MonitorUtils.metadataChanged(cluster1, cluster4)); assertTrue(MonitorUtils.metadataChanged(cluster1, cluster5)); assertTrue(MonitorUtils.metadataChanged(cluster1, cluster6)); assertFalse(MonitorUtils.metadataChanged(cluster1, cluster7)); }
public static boolean metadataChanged(Cluster prev, Cluster curr) { Set<Node> prevNodeSet = new HashSet<>(prev.nodes()); if (prevNodeSet.size() != curr.nodes().size()) { return true; } prevNodeSet.removeAll(curr.nodes()); if (!prevNodeSet.isEmpty()) { return true; } if (!prev.topics().equals(curr.topics())) { return true; } for (String topic : prev.topics()) { if (!prev.partitionCountForTopic(topic).equals(curr.partitionCountForTopic(topic))) { return true; } for (PartitionInfo prevPartInfo : prev.partitionsForTopic(topic)) { PartitionInfo currPartInfo = curr.partition(new TopicPartition(prevPartInfo.topic(), prevPartInfo.partition())); if (leaderChanged(prevPartInfo, currPartInfo) || replicaListChanged(prevPartInfo, currPartInfo)) { return true; } } } return false; }
MonitorUtils { public static boolean metadataChanged(Cluster prev, Cluster curr) { Set<Node> prevNodeSet = new HashSet<>(prev.nodes()); if (prevNodeSet.size() != curr.nodes().size()) { return true; } prevNodeSet.removeAll(curr.nodes()); if (!prevNodeSet.isEmpty()) { return true; } if (!prev.topics().equals(curr.topics())) { return true; } for (String topic : prev.topics()) { if (!prev.partitionCountForTopic(topic).equals(curr.partitionCountForTopic(topic))) { return true; } for (PartitionInfo prevPartInfo : prev.partitionsForTopic(topic)) { PartitionInfo currPartInfo = curr.partition(new TopicPartition(prevPartInfo.topic(), prevPartInfo.partition())); if (leaderChanged(prevPartInfo, currPartInfo) || replicaListChanged(prevPartInfo, currPartInfo)) { return true; } } } return false; } }
MonitorUtils { public static boolean metadataChanged(Cluster prev, Cluster curr) { Set<Node> prevNodeSet = new HashSet<>(prev.nodes()); if (prevNodeSet.size() != curr.nodes().size()) { return true; } prevNodeSet.removeAll(curr.nodes()); if (!prevNodeSet.isEmpty()) { return true; } if (!prev.topics().equals(curr.topics())) { return true; } for (String topic : prev.topics()) { if (!prev.partitionCountForTopic(topic).equals(curr.partitionCountForTopic(topic))) { return true; } for (PartitionInfo prevPartInfo : prev.partitionsForTopic(topic)) { PartitionInfo currPartInfo = curr.partition(new TopicPartition(prevPartInfo.topic(), prevPartInfo.partition())); if (leaderChanged(prevPartInfo, currPartInfo) || replicaListChanged(prevPartInfo, currPartInfo)) { return true; } } } return false; } private  MonitorUtils(); }
MonitorUtils { public static boolean metadataChanged(Cluster prev, Cluster curr) { Set<Node> prevNodeSet = new HashSet<>(prev.nodes()); if (prevNodeSet.size() != curr.nodes().size()) { return true; } prevNodeSet.removeAll(curr.nodes()); if (!prevNodeSet.isEmpty()) { return true; } if (!prev.topics().equals(curr.topics())) { return true; } for (String topic : prev.topics()) { if (!prev.partitionCountForTopic(topic).equals(curr.partitionCountForTopic(topic))) { return true; } for (PartitionInfo prevPartInfo : prev.partitionsForTopic(topic)) { PartitionInfo currPartInfo = curr.partition(new TopicPartition(prevPartInfo.topic(), prevPartInfo.partition())); if (leaderChanged(prevPartInfo, currPartInfo) || replicaListChanged(prevPartInfo, currPartInfo)) { return true; } } } return false; } private  MonitorUtils(); static boolean metadataChanged(Cluster prev, Cluster curr); static ModelCompletenessRequirements combineLoadRequirementOptions(Collection<Goal> goals); static int totalNumPartitions(Cluster cluster); static String getRackHandleNull(Node node); }
MonitorUtils { public static boolean metadataChanged(Cluster prev, Cluster curr) { Set<Node> prevNodeSet = new HashSet<>(prev.nodes()); if (prevNodeSet.size() != curr.nodes().size()) { return true; } prevNodeSet.removeAll(curr.nodes()); if (!prevNodeSet.isEmpty()) { return true; } if (!prev.topics().equals(curr.topics())) { return true; } for (String topic : prev.topics()) { if (!prev.partitionCountForTopic(topic).equals(curr.partitionCountForTopic(topic))) { return true; } for (PartitionInfo prevPartInfo : prev.partitionsForTopic(topic)) { PartitionInfo currPartInfo = curr.partition(new TopicPartition(prevPartInfo.topic(), prevPartInfo.partition())); if (leaderChanged(prevPartInfo, currPartInfo) || replicaListChanged(prevPartInfo, currPartInfo)) { return true; } } } return false; } private  MonitorUtils(); static boolean metadataChanged(Cluster prev, Cluster curr); static ModelCompletenessRequirements combineLoadRequirementOptions(Collection<Goal> goals); static int totalNumPartitions(Cluster cluster); static String getRackHandleNull(Node node); static final double UNIT_INTERVAL_TO_PERCENTAGE; static final Map<Resource, Double> EMPTY_BROKER_CAPACITY; static final long BROKER_CAPACITY_FETCH_TIMEOUT_MS; }