private final HazelcastCluster hazelcastCluster;
public AppStateClusterImpl(AppSettings appSettings) {
- ClusterProperties clusterProperties = new ClusterProperties(appSettings);
- clusterProperties.validate();
-
- if (!clusterProperties.isEnabled()) {
+ if (!appSettings.getProps().valueAsBoolean(ProcessProperties.CLUSTER_ENABLED)) {
throw new IllegalStateException("Cluster is not enabled on this instance");
}
+ ClusterProperties clusterProperties = new ClusterProperties(appSettings);
+ clusterProperties.validate();
+
hazelcastCluster = HazelcastCluster.create(clusterProperties);
// Add the local endpoint to be used by processes
appSettings.getProps().set(ProcessProperties.CLUSTER_LOCALENDPOINT, hazelcastCluster.getLocalEndPoint());
private static final Logger LOGGER = LoggerFactory.getLogger(ClusterProperties.class);
private final int port;
- private final boolean enabled;
private final List<String> hosts;
private final List<String> networkInterfaces;
private final String name;
private final NodeType nodeType;
ClusterProperties(AppSettings appSettings) {
- port = appSettings.getProps().valueAsInt(ProcessProperties.CLUSTER_PORT);
- enabled = appSettings.getProps().valueAsBoolean(ProcessProperties.CLUSTER_ENABLED);
+ port = appSettings.getProps().valueAsInt(ProcessProperties.CLUSTER_NODE_PORT);
networkInterfaces = extractNetworkInterfaces(
- appSettings.getProps().value(ProcessProperties.CLUSTER_NETWORK_INTERFACES, "")
+ appSettings.getProps().value(ProcessProperties.CLUSTER_NODE_HOST, "")
);
name = appSettings.getProps().nonNullValue(ProcessProperties.CLUSTER_NAME);
hosts = extractHosts(
return port;
}
- boolean isEnabled() {
- return enabled;
- }
-
public NodeType getNodeType() {
return nodeType;
}
}
void validate() {
- if (!enabled) {
- return;
- }
-
// Test validity of port
checkArgument(
port > 0 && port < 65_536,
import static org.apache.commons.lang.StringUtils.isBlank;
import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED;
import static org.sonar.process.ProcessProperties.CLUSTER_HOSTS;
-import static org.sonar.process.ProcessProperties.CLUSTER_NETWORK_INTERFACES;
+import static org.sonar.process.ProcessProperties.CLUSTER_NODE_HOST;
import static org.sonar.process.ProcessProperties.CLUSTER_NODE_TYPE;
import static org.sonar.process.ProcessProperties.CLUSTER_SEARCH_HOSTS;
import static org.sonar.process.ProcessProperties.CLUSTER_WEB_LEADER;
throw new MessageException("Embedded database is not supported in cluster mode");
}
- // Loopback interfaces are forbidden for SEARCH_HOST and CLUSTER_NETWORK_INTERFACES
+ // Loopback interfaces are forbidden for SEARCH_HOST and CLUSTER_NODE_HOST
ensureNotLoopback(props, CLUSTER_HOSTS);
- ensureNotLoopback(props, CLUSTER_NETWORK_INTERFACES);
+ ensureNotLoopback(props, CLUSTER_NODE_HOST);
ensureNotLoopback(props, CLUSTER_SEARCH_HOSTS);
ensureLocalAddress(props, SEARCH_HOST);
- ensureLocalAddress(props, CLUSTER_NETWORK_INTERFACES);
+ ensureLocalAddress(props, CLUSTER_NODE_HOST);
}
private static void ensureMandatoryProperty(Props props, String key) {
@Test
public void create_cluster_implementation_if_cluster_is_enabled() {
settings.set(ProcessProperties.CLUSTER_ENABLED, "true");
+ settings.set(ProcessProperties.CLUSTER_NODE_TYPE, "application");
settings.set(ProcessProperties.CLUSTER_NAME, "foo");
AppState appState = underTest.create();
assertThat(appState).isInstanceOf(AppStateClusterImpl.class);
- ((AppStateClusterImpl) appState).close();
+ appState.close();
}
@Test
@Test
public void test_default_values() throws Exception {
+ appSettings.getProps().set(ProcessProperties.CLUSTER_ENABLED, "true");
+ appSettings.getProps().set(ProcessProperties.CLUSTER_NODE_TYPE, "application");
ClusterProperties props = new ClusterProperties(appSettings);
assertThat(props.getNetworkInterfaces())
.isEqualTo(Collections.emptyList());
assertThat(props.getPort())
.isEqualTo(9003);
- assertThat(props.isEnabled())
- .isEqualTo(false);
assertThat(props.getHosts())
.isEqualTo(Collections.emptyList());
assertThat(props.getName())
public void test_port_parameter() {
appSettings.getProps().set(ProcessProperties.CLUSTER_ENABLED, "true");
appSettings.getProps().set(ProcessProperties.CLUSTER_NAME, "sonarqube");
+ appSettings.getProps().set(ProcessProperties.CLUSTER_NODE_TYPE, "application");
Stream.of("-50", "0", "65536", "128563").forEach(
port -> {
- appSettings.getProps().set(ProcessProperties.CLUSTER_PORT, port);
+ appSettings.getProps().set(ProcessProperties.CLUSTER_NODE_PORT, port);
ClusterProperties clusterProperties = new ClusterProperties(appSettings);
expectedException.expect(IllegalArgumentException.class);
public void test_interfaces_parameter() {
appSettings.getProps().set(ProcessProperties.CLUSTER_ENABLED, "true");
appSettings.getProps().set(ProcessProperties.CLUSTER_NAME, "sonarqube");
- appSettings.getProps().set(ProcessProperties.CLUSTER_NETWORK_INTERFACES, "8.8.8.8"); // This IP belongs to Google
+ appSettings.getProps().set(ProcessProperties.CLUSTER_NODE_HOST, "8.8.8.8"); // This IP belongs to Google
+ appSettings.getProps().set(ProcessProperties.CLUSTER_NODE_TYPE, "application");
ClusterProperties clusterProperties = new ClusterProperties(appSettings);
expectedException.expect(IllegalArgumentException.class);
public void validate_does_not_fail_if_cluster_enabled_and_name_specified() {
appSettings.getProps().set(ProcessProperties.CLUSTER_ENABLED, "true");
appSettings.getProps().set(ProcessProperties.CLUSTER_NAME, "sonarqube");
+ appSettings.getProps().set(ProcessProperties.CLUSTER_NODE_TYPE, "application");
ClusterProperties clusterProperties = new ClusterProperties(appSettings);
clusterProperties.validate();
public void test_members() {
appSettings.getProps().set(ProcessProperties.CLUSTER_ENABLED, "true");
appSettings.getProps().set(ProcessProperties.CLUSTER_NAME, "sonarqube");
+ appSettings.getProps().set(ProcessProperties.CLUSTER_NODE_TYPE, "application");
assertThat(
new ClusterProperties(appSettings).getHosts()).isEqualTo(
@Test
public void simulate_network_cluster() throws InterruptedException {
TestAppSettings settings = newClusterSettings();
- settings.set(ProcessProperties.CLUSTER_NETWORK_INTERFACES, InetAddress.getLoopbackAddress().getHostAddress());
+ settings.set(ProcessProperties.CLUSTER_NODE_HOST, InetAddress.getLoopbackAddress().getHostAddress());
AppStateListener listener = mock(AppStateListener.class);
try (AppStateClusterImpl appStateCluster = new AppStateClusterImpl(settings)) {
TestAppSettings settings = new TestAppSettings();
settings.set(ProcessProperties.CLUSTER_ENABLED, "true");
settings.set(ProcessProperties.CLUSTER_NAME, "sonarqube");
+ settings.set(ProcessProperties.CLUSTER_NODE_TYPE, "application");
return settings;
}
}
import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED;
import static org.sonar.process.ProcessProperties.CLUSTER_HOSTS;
-import static org.sonar.process.ProcessProperties.CLUSTER_NETWORK_INTERFACES;
+import static org.sonar.process.ProcessProperties.CLUSTER_NODE_HOST;
import static org.sonar.process.ProcessProperties.CLUSTER_NODE_TYPE;
import static org.sonar.process.ProcessProperties.CLUSTER_SEARCH_HOSTS;
import static org.sonar.process.ProcessProperties.JDBC_URL;
@DataPoints("key")
public static final Key[] KEYS = {
new Key(SEARCH_HOST, false, false),
- new Key(CLUSTER_NETWORK_INTERFACES, true, false),
+ new Key(CLUSTER_NODE_HOST, true, false),
new Key(CLUSTER_SEARCH_HOSTS, true, true),
new Key(CLUSTER_HOSTS, true, true)
};
public static final String CLUSTER_NODE_TYPE = "sonar.cluster.node.type";
public static final String CLUSTER_SEARCH_HOSTS = "sonar.cluster.search.hosts";
public static final String CLUSTER_HOSTS = "sonar.cluster.hosts";
- public static final String CLUSTER_PORT = "sonar.cluster.port";
- public static final String CLUSTER_NETWORK_INTERFACES = "sonar.cluster.networkInterfaces";
+ public static final String CLUSTER_NODE_PORT = "sonar.cluster.node.port";
+ public static final String CLUSTER_NODE_HOST = "sonar.cluster.node.host";
public static final String CLUSTER_NAME = "sonar.cluster.name";
public static final String HAZELCAST_LOG_LEVEL = "sonar.log.level.app.hazelcast";
public static final String CLUSTER_WEB_LEADER = "sonar.cluster.web.startupLeader";
defaults.put(CLUSTER_ENABLED, "false");
defaults.put(CLUSTER_NAME, "sonarqube");
- defaults.put(CLUSTER_NETWORK_INTERFACES, "");
+ defaults.put(CLUSTER_NODE_HOST, "");
defaults.put(CLUSTER_HOSTS, "");
- defaults.put(CLUSTER_PORT, "9003");
+ defaults.put(CLUSTER_NODE_PORT, "9003");
defaults.put(HAZELCAST_LOG_LEVEL, "WARN");
return defaults;
public class Cluster {
protected static final String CLUSTER_ENABLED = "sonar.cluster.enabled";
- protected static final String CLUSTER_CE_DISABLED = "sonar.cluster.ce.disabled";
- protected static final String CLUSTER_SEARCH_DISABLED = "sonar.cluster.search.disabled";
+ protected static final String CLUSTER_NODE_TYPE = "sonar.cluster.node.type";
protected static final String CLUSTER_SEARCH_HOSTS = "sonar.cluster.search.hosts";
- protected static final String CLUSTER_WEB_DISABLED = "sonar.cluster.web.disabled";
protected static final String CLUSTER_HOSTS = "sonar.cluster.hosts";
- protected static final String CLUSTER_PORT = "sonar.cluster.port";
- protected static final String CLUSTER_NETWORK_INTERFACES = "sonar.cluster.networkInterfaces";
+ protected static final String CLUSTER_NODE_PORT = "sonar.cluster.node.port";
+ protected static final String CLUSTER_NODE_HOST = "sonar.cluster.node.host";
protected static final String CLUSTER_NAME = "sonar.cluster.name";
protected static final String SEARCH_HOST = "sonar.search.host";
nodes.forEach(
node -> {
- node.addProperty(CLUSTER_NETWORK_INTERFACES, inet);
+ node.addProperty(CLUSTER_NODE_HOST, inet);
node.addProperty(CLUSTER_HOSTS, clusterHosts);
- node.addProperty(CLUSTER_PORT, Integer.toString(node.getHzPort() == null ? -1 : node.getHzPort()));
+ node.addProperty(CLUSTER_NODE_PORT, Integer.toString(node.getHzPort() == null ? -1 : node.getHzPort()));
node.addProperty(CLUSTER_SEARCH_HOSTS, elasticsearchHosts);
node.addProperty(SEARCH_PORT, Integer.toString(node.getEsPort() == null ? -1 : node.getEsPort()));
node.addProperty(SEARCH_HOST, inet);