import org.sonar.process.cluster.hz.HazelcastMemberBuilder;
import static java.util.Arrays.asList;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_HOSTS;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_HZ_HOSTS;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NAME;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS;
public class AppStateFactory {
private static HazelcastMember createHzMember(Props props) {
HazelcastMemberBuilder builder = new HazelcastMemberBuilder()
.setNetworkInterface(props.nonNullValue(CLUSTER_NODE_HOST.getKey()))
- .setMembers(asList(props.nonNullValue(CLUSTER_HOSTS.getKey()).split(",")))
+ .setMembers(asList(props.nonNullValue(CLUSTER_HZ_HOSTS.getKey()).split(",")))
.setNodeName(props.nonNullValue(CLUSTER_NODE_NAME.getKey()))
- .setPort(Integer.parseInt(props.nonNullValue(CLUSTER_NODE_PORT.getKey())))
+ .setPort(Integer.parseInt(props.nonNullValue(CLUSTER_NODE_HZ_PORT.getKey())))
.setProcessId(ProcessId.APP);
return builder.build();
}
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT;
public class SearchNodeHealthProvider implements NodeHealthProvider {
.setType(NodeDetails.Type.SEARCH)
.setName(props.nonNullValue(CLUSTER_NODE_NAME.getKey()))
.setHost(getHost(props, networkUtils))
- .setPort(Integer.valueOf(props.nonNullValue(CLUSTER_NODE_PORT.getKey())))
+ .setPort(Integer.valueOf(props.nonNullValue(CLUSTER_NODE_HZ_PORT.getKey())))
.setStartedAt(clock.now())
.build();
}
import static org.apache.commons.lang.StringUtils.isBlank;
import static org.sonar.process.ProcessProperties.Property.AUTH_JWT_SECRET;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_HOSTS;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_HZ_HOSTS;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_WEB_STARTUP_LEADER;
case APPLICATION:
ensureNotH2(props);
requireValue(props, AUTH_JWT_SECRET.getKey());
+ ensureNotLoopbackAddresses(props, CLUSTER_HZ_HOSTS.getKey());
break;
case SEARCH:
requireValue(props, SEARCH_HOST.getKey());
ensureLocalButNotLoopbackAddress(props, SEARCH_HOST.getKey());
- if (props.contains(CLUSTER_NODE_PORT.getKey())) {
- LoggerFactory.getLogger(getClass()).warn("Property {} is ignored on search nodes since 7.2", CLUSTER_NODE_PORT.getKey());
+ if (props.contains(CLUSTER_NODE_HZ_PORT.getKey())) {
+ LoggerFactory.getLogger(getClass()).warn("Property {} is ignored on search nodes since 7.2", CLUSTER_NODE_HZ_PORT.getKey());
}
break;
default:
throw new UnsupportedOperationException("Unknown value: " + nodeType);
}
- ensureNotLoopbackAddresses(props, CLUSTER_HOSTS.getKey());
requireValue(props, CLUSTER_NODE_HOST.getKey());
ensureLocalButNotLoopbackAddress(props, CLUSTER_NODE_HOST.getKey());
ensureNotLoopbackAddresses(props, CLUSTER_SEARCH_HOSTS.getKey());
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeThat;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_HOSTS;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_HZ_HOSTS;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NAME;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE;
settings.set(CLUSTER_ENABLED.getKey(), "true");
settings.set(CLUSTER_NODE_TYPE.getKey(), "application");
settings.set(CLUSTER_NODE_HOST.getKey(), ip.get().getHostAddress());
- settings.set(CLUSTER_HOSTS.getKey(), ip.get().getHostAddress());
+ settings.set(CLUSTER_HZ_HOSTS.getKey(), ip.get().getHostAddress());
settings.set(CLUSTER_NAME.getKey(), "foo");
settings.set(CLUSTER_SEARCH_HOSTS.getKey(), "localhost:9001");
import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE;
public class SchedulerImplTest {
private void addRequiredNodeProperties() {
settings.set(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(4));
settings.set(CLUSTER_NODE_HOST.getKey(), randomAlphanumeric(4));
- settings.set(CLUSTER_NODE_PORT.getKey(), String.valueOf(1 + new Random().nextInt(999)));
+ settings.set(CLUSTER_NODE_HZ_PORT.getKey(), String.valueOf(1 + new Random().nextInt(999)));
}
private class TestCommandFactory implements CommandFactory {
import static org.mockito.Mockito.when;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT;
public class SearchNodeHealthProviderTest {
@Rule
String port = randomAlphabetic(3);
Properties properties = new Properties();
properties.put(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3));
- properties.put(CLUSTER_NODE_PORT.getKey(), port);
+ properties.put(CLUSTER_NODE_HZ_PORT.getKey(), port);
when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(34));
Props props = new Props(properties);
int port = 1 + random.nextInt(4);
Properties properties = new Properties();
properties.setProperty(CLUSTER_NODE_NAME.getKey(), name);
- properties.setProperty(CLUSTER_NODE_PORT.getKey(), valueOf(port));
+ properties.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), valueOf(port));
when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(34));
when(clock.now()).thenReturn(1L + random.nextInt(87));
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock);
// change values in properties
properties.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(6));
- properties.setProperty(CLUSTER_NODE_PORT.getKey(), valueOf(1 + random.nextInt(99)));
+ properties.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), valueOf(1 + random.nextInt(99)));
NodeHealth newNodeHealth = underTest.get();
String host = randomAlphanumeric(55);
Properties properties = new Properties();
properties.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3));
- properties.setProperty(CLUSTER_NODE_PORT.getKey(), valueOf(1 + random.nextInt(4)));
+ properties.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), valueOf(1 + random.nextInt(4)));
properties.setProperty(CLUSTER_NODE_HOST.getKey(), host);
when(clock.now()).thenReturn(1L + random.nextInt(87));
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock);
String host = randomAlphanumeric(34);
Properties properties = new Properties();
properties.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3));
- properties.setProperty(CLUSTER_NODE_PORT.getKey(), valueOf(1 + random.nextInt(4)));
+ properties.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), valueOf(1 + random.nextInt(4)));
if (hostPropertyValue != null) {
properties.setProperty(CLUSTER_NODE_HOST.getKey(), hostPropertyValue);
}
private long setRequiredPropertiesAndMocks(Properties properties) {
properties.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3));
- properties.setProperty(CLUSTER_NODE_PORT.getKey(), valueOf(1 + random.nextInt(4)));
+ properties.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), valueOf(1 + random.nextInt(4)));
long now = 1L + random.nextInt(87);
when(clock.now()).thenReturn(now);
when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(34));
import static org.junit.Assume.assumeThat;
import static org.mockito.Mockito.spy;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_HOSTS;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_HZ_HOSTS;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS;
public void ClusterSettings_throws_MessageException_if_host_of_search_node_is_loopback() {
verifySearchFailureIfLoopback(CLUSTER_NODE_HOST.getKey());
verifySearchFailureIfLoopback(CLUSTER_SEARCH_HOSTS.getKey());
- verifySearchFailureIfLoopback(CLUSTER_HOSTS.getKey());
+ verifySearchFailureIfLoopback(CLUSTER_HZ_HOSTS.getKey());
verifySearchFailureIfLoopback(SEARCH_HOST.getKey());
}
public void ClusterSettings_throws_MessageException_if_host_of_app_node_is_loopback() {
verifyAppFailureIfLoopback(CLUSTER_NODE_HOST.getKey());
verifyAppFailureIfLoopback(CLUSTER_SEARCH_HOSTS.getKey());
- verifyAppFailureIfLoopback(CLUSTER_HOSTS.getKey());
+ verifyAppFailureIfLoopback(CLUSTER_HZ_HOSTS.getKey());
}
private void verifySearchFailureIfLoopback(String propertyKey) {
.set(CLUSTER_ENABLED.getKey(), "true")
.set(CLUSTER_NODE_TYPE.getKey(), "application")
.set(CLUSTER_NODE_HOST.getKey(), nonLoopbackLocal.getHostAddress())
- .set(CLUSTER_HOSTS.getKey(), nonLoopbackLocal.getHostAddress())
+ .set(CLUSTER_HZ_HOSTS.getKey(), nonLoopbackLocal.getHostAddress())
.set(CLUSTER_SEARCH_HOSTS.getKey(), nonLoopbackLocal.getHostAddress())
.set("sonar.auth.jwtBase64Hs256Secret", "abcde")
.set(JDBC_URL.getKey(), "jdbc:mysql://localhost:3306/sonar");
.set(CLUSTER_ENABLED.getKey(), "true")
.set(CLUSTER_NODE_TYPE.getKey(), "search")
.set(CLUSTER_NODE_HOST.getKey(), nonLoopbackLocal.getHostAddress())
- .set(CLUSTER_HOSTS.getKey(), nonLoopbackLocal.getHostAddress())
+ .set(CLUSTER_HZ_HOSTS.getKey(), nonLoopbackLocal.getHostAddress())
.set(CLUSTER_SEARCH_HOSTS.getKey(), nonLoopbackLocal.getHostAddress())
.set(SEARCH_HOST.getKey(), nonLoopbackLocal.getHostAddress());
}
import static org.sonar.process.ProcessId.ELASTICSEARCH;
import static org.sonar.process.ProcessId.WEB_SERVER;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_HOSTS;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_HZ_HOSTS;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS;
}
@Test
- public void accept_throws_MessageException_if_clusterHosts_is_missing() {
- TestAppSettings settings = newSettingsForSearchNode();
- settings.clearProperty(CLUSTER_HOSTS.getKey());
- assertThatPropertyIsMandatory(settings, CLUSTER_HOSTS.getKey());
+ public void accept_throws_MessageException_on_app_node_if_clusterHosts_is_missing() {
+ TestAppSettings settings = newSettingsForAppNode();
+ settings.clearProperty(CLUSTER_HZ_HOSTS.getKey());
+ assertThatPropertyIsMandatory(settings, CLUSTER_HZ_HOSTS.getKey());
}
@Test
.set(CLUSTER_ENABLED.getKey(), "true")
.set(CLUSTER_NODE_TYPE.getKey(), "application")
.set(CLUSTER_NODE_HOST.getKey(), nonLoopbackLocal.getHostAddress())
- .set(CLUSTER_HOSTS.getKey(), nonLoopbackLocal.getHostAddress())
+ .set(CLUSTER_HZ_HOSTS.getKey(), nonLoopbackLocal.getHostAddress())
.set(CLUSTER_SEARCH_HOSTS.getKey(), nonLoopbackLocal.getHostAddress())
.set("sonar.auth.jwtBase64Hs256Secret", "abcde")
.set(JDBC_URL.getKey(), "jdbc:mysql://localhost:3306/sonar");
.set(CLUSTER_ENABLED.getKey(), "true")
.set(CLUSTER_NODE_TYPE.getKey(), "search")
.set(CLUSTER_NODE_HOST.getKey(), nonLoopbackLocal.getHostAddress())
- .set(CLUSTER_HOSTS.getKey(), nonLoopbackLocal.getHostAddress())
+ .set(CLUSTER_HZ_HOSTS.getKey(), nonLoopbackLocal.getHostAddress())
.set(CLUSTER_SEARCH_HOSTS.getKey(), nonLoopbackLocal.getHostAddress())
.set(SEARCH_HOST.getKey(), nonLoopbackLocal.getHostAddress());
}
CLUSTER_ENABLED("sonar.cluster.enabled", "false"),
CLUSTER_NODE_TYPE("sonar.cluster.node.type"),
CLUSTER_SEARCH_HOSTS("sonar.cluster.search.hosts"),
- CLUSTER_HOSTS("sonar.cluster.hosts"),
- CLUSTER_NODE_PORT("sonar.cluster.node.port", "9003"),
+ CLUSTER_HZ_HOSTS("sonar.cluster.hosts"),
+ CLUSTER_NODE_HZ_PORT("sonar.cluster.node.port", "9003"),
CLUSTER_NODE_HOST("sonar.cluster.node.host"),
CLUSTER_NODE_NAME("sonar.cluster.node.name", "sonarqube-" + UUID.randomUUID().toString()),
CLUSTER_NAME("sonar.cluster.name", "sonarqube"),
import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT;
public class HazelcastMemberBuilder {
*/
public HazelcastMemberBuilder setMembers(Collection<String> c) {
this.members = c.stream()
- .map(host -> host.contains(":") ? host : format("%s:%s", host, CLUSTER_NODE_PORT.getDefaultValue()))
+ .map(host -> host.contains(":") ? host : format("%s:%s", host, CLUSTER_NODE_HZ_PORT.getDefaultValue()))
.collect(Collectors.toList());
return this;
}
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT;
public class HazelcastMemberBuilderTest {
underTest.setMembers(asList("foo", "bar:9100", "1.2.3.4"));
assertThat(underTest.getMembers()).containsExactly(
- "foo:" + CLUSTER_NODE_PORT.getDefaultValue(),
+ "foo:" + CLUSTER_NODE_HZ_PORT.getDefaultValue(),
"bar:9100",
- "1.2.3.4:" + CLUSTER_NODE_PORT.getDefaultValue());
+ "1.2.3.4:" + CLUSTER_NODE_HZ_PORT.getDefaultValue());
}
@Test
import static java.lang.String.format;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT;
import static org.sonar.process.cluster.health.NodeDetails.newNodeDetailsBuilder;
import static org.sonar.process.cluster.health.NodeHealth.newNodeHealthBuilder;
}
private static int computePort(Configuration configuration) {
- return configuration.getInt(CLUSTER_NODE_PORT.getKey())
- .orElseThrow(missingPropertyISE(CLUSTER_NODE_PORT.getKey()));
+ return configuration.getInt(CLUSTER_NODE_HZ_PORT.getKey())
+ .orElseThrow(missingPropertyISE(CLUSTER_NODE_HZ_PORT.getKey()));
}
private static Supplier<IllegalStateException> missingPropertyISE(String propertyName) {
import static org.mockito.Mockito.when;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT;
public class NodeHealthProviderImplTest {
@Rule
String name = randomAlphanumeric(3);
int port = 1 + random.nextInt(4);
mapSettings.setProperty(CLUSTER_NODE_NAME.getKey(), name);
- mapSettings.setProperty(CLUSTER_NODE_PORT.getKey(), port);
+ mapSettings.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), port);
setStartedAt();
when(healthChecker.checkNode()).thenReturn(Health.newHealthCheckBuilder()
.setStatus(Health.Status.values()[random.nextInt(Health.Status.values().length)])
public void get_returns_host_from_property_if_set_at_constructor_time() {
String host = randomAlphanumeric(4);
mapSettings.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3));
- mapSettings.setProperty(CLUSTER_NODE_PORT.getKey(), 1 + random.nextInt(4));
+ mapSettings.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), 1 + random.nextInt(4));
mapSettings.setProperty(CLUSTER_NODE_HOST.getKey(), host);
setStartedAt();
when(healthChecker.checkNode()).thenReturn(Health.newHealthCheckBuilder()
private void setRequiredPropertiesForConstructor() {
mapSettings.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3));
- mapSettings.setProperty(CLUSTER_NODE_PORT.getKey(), 1 + random.nextInt(4));
+ mapSettings.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), 1 + random.nextInt(4));
}
}