private void checkForApplicationNode(Props props) {
ensureNotH2(props);
requireValue(props, AUTH_JWT_SECRET);
- Set<AddressAndPort> hzNodes = parseHosts(CLUSTER_HZ_HOSTS, requireValue(props, CLUSTER_HZ_HOSTS));
+ Set<AddressAndPort> hzNodes = parseAndCheckHosts(CLUSTER_HZ_HOSTS, requireValue(props, CLUSTER_HZ_HOSTS));
ensureNotLoopbackAddresses(CLUSTER_HZ_HOSTS, hzNodes);
checkClusterNodeHost(props);
checkClusterSearchHosts(props);
}
private void checkClusterSearchHosts(Props props) {
- Set<AddressAndPort> searchHosts = parseHosts(CLUSTER_SEARCH_HOSTS, requireValue(props, CLUSTER_SEARCH_HOSTS));
+ Set<AddressAndPort> searchHosts = parseAndCheckHosts(CLUSTER_SEARCH_HOSTS, requireValue(props, CLUSTER_SEARCH_HOSTS));
ensureNotLoopbackAddresses(CLUSTER_SEARCH_HOSTS, searchHosts);
}
private void checkClusterEsHosts(Props props) {
- Set<AddressAndPort> esHosts = parseHosts(CLUSTER_ES_HOSTS, requireValue(props, CLUSTER_ES_HOSTS));
+ Set<AddressAndPort> esHosts = parseHosts(requireValue(props, CLUSTER_ES_HOSTS));
ensureNotLoopbackAddresses(CLUSTER_ES_HOSTS, esHosts);
ensureEitherPortsAreProvidedOrOnlyHosts(CLUSTER_ES_HOSTS, esHosts);
}
- private Set<AddressAndPort> parseHosts(Property property, String value) {
- Set<AddressAndPort> res = stream(value.split(","))
+ private static Set<AddressAndPort> parseHosts(String value) {
+ return stream(value.split(","))
.filter(Objects::nonNull)
.map(String::trim)
.map(ClusterSettings::parseHost)
.collect(toSet());
+ }
+
+ private Set<AddressAndPort> parseAndCheckHosts(Property property, String value) {
+ Set<AddressAndPort> res = parseHosts( value);
checkValidHosts(property, res);
return res;
}
private void checkValidHosts(Property property, Set<AddressAndPort> addressAndPorts) {
- List<String> invalidHosts = addressAndPorts.stream()
+ List<String> invalidHosts = addressAndPorts.stream()
.map(AddressAndPort::getHost)
.filter(t -> !network.toInetAddress(t).isPresent())
.sorted()
import static java.lang.String.valueOf;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_ES_DISCOVERY_SEED_HOSTS;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_ES_HOSTS;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_ES_KEYSTORE;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_ES_TRUSTSTORE;
builder.put(ES_NETWORK_HOST_KEY, nodeTransportHost);
String hosts = props.value(CLUSTER_ES_HOSTS.getKey(), loopbackAddress.getHostAddress());
+ String discoveryHosts = props.value(CLUSTER_ES_DISCOVERY_SEED_HOSTS.getKey(), hosts);
LOGGER.info("Elasticsearch cluster enabled. Connect to hosts [{}]", hosts);
- builder.put("discovery.seed_hosts", hosts);
+ builder.put("discovery.seed_hosts", discoveryHosts);
builder.put("cluster.initial_master_nodes", hosts);
}
}
@Test
- public void validate_host_resolved_in_any_cluster_property_of_SEARCH_node() {
+ public void validate_host_resolved_in_node_search_host_property_of_SEARCH_node() {
TestAppSettings settings = new TestAppSettings(ImmutableMap.<String, String>builder()
.put(CLUSTER_ENABLED.getKey(), "true")
.put(CLUSTER_NODE_TYPE.getKey(), "search")
.put(CLUSTER_NODE_SEARCH_HOST.getKey(), "search_host")
.put(CLUSTER_NODE_ES_HOST.getKey(), "search_host").build());
- verifyHostIsChecked(settings, ImmutableList.of("remote_search_host_1"), "Address in property sonar.cluster.es.hosts is not a valid address: remote_search_host_1");
- verifyHostIsChecked(settings, ImmutableList.of("remote_search_host_2"), "Address in property sonar.cluster.es.hosts is not a valid address: remote_search_host_2");
verifyHostIsChecked(settings, ImmutableList.of("search_host"), "Address in property sonar.cluster.node.search.host is not a valid address: search_host");
}