Skip to content

Rejection of Port Ranges in module discovery.seed_hosts #41425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ public class SettingsBasedSeedHostsProvider implements SeedHostsProvider {
private final List<String> configuredHosts;
private final int limitPortCounts;


public SettingsBasedSeedHostsProvider(Settings settings, TransportService transportService) {
if (DISCOVERY_SEED_HOSTS_SETTING.exists(settings)) {
configuredHosts = DISCOVERY_SEED_HOSTS_SETTING.get(settings);
// we only limit to 1 address, makes no sense to ping 100 ports
limitPortCounts = LIMIT_FOREIGN_PORTS_COUNT;
checkInvalidPorts(configuredHosts);
} else {
// if unicast hosts are not specified, fill with simple defaults on the local machine
configuredHosts = transportService.getLocalAddresses();
Expand All @@ -68,6 +70,15 @@ public SettingsBasedSeedHostsProvider(Settings settings, TransportService transp
logger.debug("using initial hosts {}", configuredHosts);
}

public void checkInvalidPorts(List<String> configuredHosts) {
for (String host : configuredHosts) {
if (host.contains("-")) {
throw new IllegalArgumentException("Configuration Setting discovery.seed_hosts does not support a range of ports, [" +
host + "] was found in provided seed hosts");
}
}
}

@Override
public List<TransportAddress> getSeedAddresses(HostsResolver hostsResolver) {
return hostsResolver.resolveHosts(configuredHosts, limitPortCounts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,28 @@ public void testGetsHostsFromSetting() {
.build(), null).getSeedAddresses(hostsResolver);
assertTrue(hostsResolver.getResolvedHosts());
}

public void testExceptionOnPortRange() {
boolean exceptionThrown = false;
try {
new SettingsBasedSeedHostsProvider(Settings.builder()
.putList(SettingsBasedSeedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey(), "localhost:9200-9300")
.build(), null);
} catch (IllegalArgumentException e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}

public void testSeedWithoutPortRange() {
boolean exceptionThrown = false;
try {
new SettingsBasedSeedHostsProvider(Settings.builder()
.putList(SettingsBasedSeedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey(), "localhost:9200")
.build(), null);
} catch (Exception e) {
exceptionThrown = true;
}
assertFalse(exceptionThrown);
}
}