use of org.elasticsearch.discovery.FileBasedSeedHostsProvider.UNICAST_HOSTS_FILE in project crate by crate.
the class InternalTestCluster method rebuildUnicastHostFiles.
private void rebuildUnicastHostFiles(List<NodeAndClient> newNodes) {
// cannot be a synchronized method since it's called on other threads from within synchronized startAndPublishNodesAndClients()
synchronized (discoveryFileMutex) {
try {
final Collection<NodeAndClient> currentNodes = nodes.values();
Stream<NodeAndClient> unicastHosts = Stream.concat(currentNodes.stream(), newNodes.stream());
List<String> discoveryFileContents = unicastHosts.map(nac -> nac.node.injector().getInstance(TransportService.class)).filter(Objects::nonNull).map(TransportService::getLocalNode).filter(Objects::nonNull).filter(DiscoveryNode::isMasterEligibleNode).map(n -> n.getAddress().toString()).distinct().collect(Collectors.toList());
Set<Path> configPaths = Stream.concat(currentNodes.stream(), newNodes.stream()).map(nac -> nac.node.getEnvironment().configFile()).collect(Collectors.toSet());
logger.debug("configuring discovery with {} at {}", discoveryFileContents, configPaths);
for (final Path configPath : configPaths) {
Files.createDirectories(configPath);
Files.write(configPath.resolve(UNICAST_HOSTS_FILE), discoveryFileContents);
}
} catch (IOException e) {
throw new AssertionError("failed to configure file-based discovery", e);
}
}
}
Aggregations