@Test void testGenerateTopology() throws FreeIpaClientException { Set<String> nodes = new HashSet<>(); assertSetEquivlance(underTest.generateTopology(Set.of("")), Set.of()); nodes.add("node1"); assertSetEquivlance(underTest.generateTopology(nodes), Set.of()); nodes.add("node2"); assertSetEquivlance(underTest.generateTopology(nodes), Set.of( new FreeIpaTopologyService.UnorderedPair("node1", "node2"))); nodes.add("node3"); assertSetEquivlance(underTest.generateTopology(nodes), Set.of( new FreeIpaTopologyService.UnorderedPair("node1", "node2"), new FreeIpaTopologyService.UnorderedPair("node1", "node3"), new FreeIpaTopologyService.UnorderedPair("node2", "node3"))); nodes.add("node4"); assertSetEquivlance(underTest.generateTopology(nodes), Set.of( new FreeIpaTopologyService.UnorderedPair("node1", "node2"), new FreeIpaTopologyService.UnorderedPair("node1", "node3"), new FreeIpaTopologyService.UnorderedPair("node1", "node4"), new FreeIpaTopologyService.UnorderedPair("node2", "node3"), new FreeIpaTopologyService.UnorderedPair("node2", "node4"), new FreeIpaTopologyService.UnorderedPair("node3", "node4"))); nodes.add("node5"); assertSetEquivlance(underTest.generateTopology(nodes), Set.of( new FreeIpaTopologyService.UnorderedPair("node1", "node2"), new FreeIpaTopologyService.UnorderedPair("node1", "node3"), new FreeIpaTopologyService.UnorderedPair("node1", "node4"), new FreeIpaTopologyService.UnorderedPair("node1", "node5"), new FreeIpaTopologyService.UnorderedPair("node2", "node3"), new FreeIpaTopologyService.UnorderedPair("node2", "node4"), new FreeIpaTopologyService.UnorderedPair("node2", "node5"), new FreeIpaTopologyService.UnorderedPair("node3", "node4"), new FreeIpaTopologyService.UnorderedPair("node3", "node5"), new FreeIpaTopologyService.UnorderedPair("node4", "node5"))); nodes.add("node6"); assertSetEquivlance(underTest.generateTopology(nodes), Set.of( new FreeIpaTopologyService.UnorderedPair("node1", "node2"), new FreeIpaTopologyService.UnorderedPair("node1", "node3"), new FreeIpaTopologyService.UnorderedPair("node1", "node4"), new FreeIpaTopologyService.UnorderedPair("node1", "node5"), new FreeIpaTopologyService.UnorderedPair("node2", "node6"), new FreeIpaTopologyService.UnorderedPair("node2", "node3"), new FreeIpaTopologyService.UnorderedPair("node2", "node4"), new FreeIpaTopologyService.UnorderedPair("node3", "node5"), new FreeIpaTopologyService.UnorderedPair("node3", "node6"), new FreeIpaTopologyService.UnorderedPair("node4", "node5"), new FreeIpaTopologyService.UnorderedPair("node4", "node6"), new FreeIpaTopologyService.UnorderedPair("node5", "node6"))); nodes.add("node7"); assertSetEquivlance(underTest.generateTopology(nodes), Set.of( new FreeIpaTopologyService.UnorderedPair("node1", "node2"), new FreeIpaTopologyService.UnorderedPair("node1", "node3"), new FreeIpaTopologyService.UnorderedPair("node1", "node4"), new FreeIpaTopologyService.UnorderedPair("node1", "node5"), new FreeIpaTopologyService.UnorderedPair("node2", "node6"), new FreeIpaTopologyService.UnorderedPair("node2", "node7"), new FreeIpaTopologyService.UnorderedPair("node2", "node3"), new FreeIpaTopologyService.UnorderedPair("node3", "node4"), new FreeIpaTopologyService.UnorderedPair("node3", "node5"), new FreeIpaTopologyService.UnorderedPair("node4", "node6"), new FreeIpaTopologyService.UnorderedPair("node4", "node7"), new FreeIpaTopologyService.UnorderedPair("node5", "node6"), new FreeIpaTopologyService.UnorderedPair("node5", "node7"), new FreeIpaTopologyService.UnorderedPair("node6", "node7"))); }
@VisibleForTesting Set<UnorderedPair> generateTopology(Set<String> nodes) { LOGGER.debug("Generating topology for FreeIPA [{}}", nodes); Map<String, Integer> connectionRemaining = nodes.stream() .sorted() .collect(Collectors.toMap(n -> n, n -> MAX_REPLICATION_CONNECTIONS, (k, v) -> v, LinkedHashMap::new)); Set<UnorderedPair> ret = new HashSet<>(); Iterator<String> itr2 = null; for (Map.Entry<String, Integer> entry : connectionRemaining.entrySet()) { String node = entry.getKey(); Integer remainingConnectionsForNode = entry.getValue(); for (int i = remainingConnectionsForNode; i > 0; i--) { if (itr2 == null || !itr2.hasNext()) { itr2 = getIteratorAfterCurrentNode(node, connectionRemaining.keySet()); if (!itr2.hasNext()) { break; } } String node2 = itr2.next(); connectionRemaining.put(node2, connectionRemaining.get(node2) - 1); ret.add(new UnorderedPair(node, node2)); } } return ret; }
FreeIpaTopologyService { @VisibleForTesting Set<UnorderedPair> generateTopology(Set<String> nodes) { LOGGER.debug("Generating topology for FreeIPA [{}}", nodes); Map<String, Integer> connectionRemaining = nodes.stream() .sorted() .collect(Collectors.toMap(n -> n, n -> MAX_REPLICATION_CONNECTIONS, (k, v) -> v, LinkedHashMap::new)); Set<UnorderedPair> ret = new HashSet<>(); Iterator<String> itr2 = null; for (Map.Entry<String, Integer> entry : connectionRemaining.entrySet()) { String node = entry.getKey(); Integer remainingConnectionsForNode = entry.getValue(); for (int i = remainingConnectionsForNode; i > 0; i--) { if (itr2 == null || !itr2.hasNext()) { itr2 = getIteratorAfterCurrentNode(node, connectionRemaining.keySet()); if (!itr2.hasNext()) { break; } } String node2 = itr2.next(); connectionRemaining.put(node2, connectionRemaining.get(node2) - 1); ret.add(new UnorderedPair(node, node2)); } } return ret; } }
FreeIpaTopologyService { @VisibleForTesting Set<UnorderedPair> generateTopology(Set<String> nodes) { LOGGER.debug("Generating topology for FreeIPA [{}}", nodes); Map<String, Integer> connectionRemaining = nodes.stream() .sorted() .collect(Collectors.toMap(n -> n, n -> MAX_REPLICATION_CONNECTIONS, (k, v) -> v, LinkedHashMap::new)); Set<UnorderedPair> ret = new HashSet<>(); Iterator<String> itr2 = null; for (Map.Entry<String, Integer> entry : connectionRemaining.entrySet()) { String node = entry.getKey(); Integer remainingConnectionsForNode = entry.getValue(); for (int i = remainingConnectionsForNode; i > 0; i--) { if (itr2 == null || !itr2.hasNext()) { itr2 = getIteratorAfterCurrentNode(node, connectionRemaining.keySet()); if (!itr2.hasNext()) { break; } } String node2 = itr2.next(); connectionRemaining.put(node2, connectionRemaining.get(node2) - 1); ret.add(new UnorderedPair(node, node2)); } } return ret; }  }
FreeIpaTopologyService { @VisibleForTesting Set<UnorderedPair> generateTopology(Set<String> nodes) { LOGGER.debug("Generating topology for FreeIPA [{}}", nodes); Map<String, Integer> connectionRemaining = nodes.stream() .sorted() .collect(Collectors.toMap(n -> n, n -> MAX_REPLICATION_CONNECTIONS, (k, v) -> v, LinkedHashMap::new)); Set<UnorderedPair> ret = new HashSet<>(); Iterator<String> itr2 = null; for (Map.Entry<String, Integer> entry : connectionRemaining.entrySet()) { String node = entry.getKey(); Integer remainingConnectionsForNode = entry.getValue(); for (int i = remainingConnectionsForNode; i > 0; i--) { if (itr2 == null || !itr2.hasNext()) { itr2 = getIteratorAfterCurrentNode(node, connectionRemaining.keySet()); if (!itr2.hasNext()) { break; } } String node2 = itr2.next(); connectionRemaining.put(node2, connectionRemaining.get(node2) - 1); ret.add(new UnorderedPair(node, node2)); } } return ret; }  void updateReplicationTopology(Long stackId, FreeIpaClient freeIpaClient); }
FreeIpaTopologyService { @VisibleForTesting Set<UnorderedPair> generateTopology(Set<String> nodes) { LOGGER.debug("Generating topology for FreeIPA [{}}", nodes); Map<String, Integer> connectionRemaining = nodes.stream() .sorted() .collect(Collectors.toMap(n -> n, n -> MAX_REPLICATION_CONNECTIONS, (k, v) -> v, LinkedHashMap::new)); Set<UnorderedPair> ret = new HashSet<>(); Iterator<String> itr2 = null; for (Map.Entry<String, Integer> entry : connectionRemaining.entrySet()) { String node = entry.getKey(); Integer remainingConnectionsForNode = entry.getValue(); for (int i = remainingConnectionsForNode; i > 0; i--) { if (itr2 == null || !itr2.hasNext()) { itr2 = getIteratorAfterCurrentNode(node, connectionRemaining.keySet()); if (!itr2.hasNext()) { break; } } String node2 = itr2.next(); connectionRemaining.put(node2, connectionRemaining.get(node2) - 1); ret.add(new UnorderedPair(node, node2)); } } return ret; }  void updateReplicationTopology(Long stackId, FreeIpaClient freeIpaClient);  }