From d63783420e7d1789f3dfe15ae1100ad2f4e7a510 Mon Sep 17 00:00:00 2001 From: Eric Hartmann Date: Wed, 16 Aug 2017 18:04:18 +0200 Subject: [PATCH] SONAR-9731 Update clustering property names --- .../application/cluster/AppStateClusterImpl.java | 8 ++++---- .../application/cluster/ClusterProperties.java | 14 ++------------ .../sonar/application/config/ClusterSettings.java | 8 ++++---- .../org/sonar/application/AppStateFactoryTest.java | 3 ++- .../application/cluster/ClusterPropertiesTest.java | 12 ++++++++---- .../application/cluster/HazelcastClusterTest.java | 2 +- .../application/cluster/HazelcastTestHelper.java | 1 + .../config/ClusterSettingsLoopbackTest.java | 4 ++-- .../java/org/sonar/process/ProcessProperties.java | 8 ++++---- .../java/org/sonarqube/tests/cluster/Cluster.java | 12 +++++------- 10 files changed, 33 insertions(+), 39 deletions(-) diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/AppStateClusterImpl.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/AppStateClusterImpl.java index 5e5f2b0c717..19c001081b6 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/cluster/AppStateClusterImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/AppStateClusterImpl.java @@ -40,13 +40,13 @@ public class AppStateClusterImpl implements AppState { 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()); diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProperties.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProperties.java index aad11cfe302..22c403a20d4 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProperties.java +++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProperties.java @@ -42,17 +42,15 @@ public final class ClusterProperties { private static final Logger LOGGER = LoggerFactory.getLogger(ClusterProperties.class); private final int port; - private final boolean enabled; private final List hosts; private final List 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( @@ -65,10 +63,6 @@ public final class ClusterProperties { return port; } - boolean isEnabled() { - return enabled; - } - public NodeType getNodeType() { return nodeType; } @@ -86,10 +80,6 @@ public final class ClusterProperties { } void validate() { - if (!enabled) { - return; - } - // Test validity of port checkArgument( port > 0 && port < 65_536, diff --git a/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java b/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java index 3861936d858..3c502807ce6 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java +++ b/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java @@ -45,7 +45,7 @@ import static java.util.Collections.singletonList; 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; @@ -91,13 +91,13 @@ public class ClusterSettings implements Consumer { 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) { diff --git a/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java b/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java index ffffcc00855..760c6021c3b 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java @@ -34,11 +34,12 @@ public class AppStateFactoryTest { @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 diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterPropertiesTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterPropertiesTest.java index 05e471c7ffd..d08d0e7b7a6 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterPropertiesTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterPropertiesTest.java @@ -41,14 +41,14 @@ public class ClusterPropertiesTest { @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()) @@ -59,10 +59,11 @@ public class ClusterPropertiesTest { 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); @@ -77,7 +78,8 @@ public class ClusterPropertiesTest { 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); @@ -90,6 +92,7 @@ public class ClusterPropertiesTest { 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(); @@ -99,6 +102,7 @@ public class ClusterPropertiesTest { 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( diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java index 3d9291aab69..bda7d36a702 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java @@ -237,7 +237,7 @@ public class HazelcastClusterTest { @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)) { diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastTestHelper.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastTestHelper.java index 76724b38c4d..b95a7c6e787 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastTestHelper.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastTestHelper.java @@ -69,6 +69,7 @@ public class HazelcastTestHelper { 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; } } diff --git a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java index cd5534fda75..4e0c1e500ed 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java @@ -36,7 +36,7 @@ import org.sonar.process.MessageException; 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; @@ -112,7 +112,7 @@ public class ClusterSettingsLoopbackTest { @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) }; diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java index 802c4bf27a6..a4bd2f15e35 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java +++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java @@ -33,8 +33,8 @@ public class ProcessProperties { 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"; @@ -137,9 +137,9 @@ public class ProcessProperties { 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; diff --git a/tests/src/test/java/org/sonarqube/tests/cluster/Cluster.java b/tests/src/test/java/org/sonarqube/tests/cluster/Cluster.java index 3fd8aa7627e..cf81dd3342c 100644 --- a/tests/src/test/java/org/sonarqube/tests/cluster/Cluster.java +++ b/tests/src/test/java/org/sonarqube/tests/cluster/Cluster.java @@ -46,13 +46,11 @@ import static org.sonarqube.tests.cluster.Cluster.NodeType.SEARCH; 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"; @@ -176,9 +174,9 @@ public class Cluster { 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); -- 2.39.5