]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9731 Update clustering property names
authorEric Hartmann <hartmann.eric@gmail.com>
Wed, 16 Aug 2017 16:04:18 +0000 (18:04 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 5 Sep 2017 12:24:13 +0000 (14:24 +0200)
server/sonar-main/src/main/java/org/sonar/application/cluster/AppStateClusterImpl.java
server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProperties.java
server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java
server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java
server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterPropertiesTest.java
server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java
server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastTestHelper.java
server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java
server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java
tests/src/test/java/org/sonarqube/tests/cluster/Cluster.java

index 5e5f2b0c7170a7fe5ad864e04a27f73708623581..19c001081b6b714a975da552e7ce18c0a5823033 100644 (file)
@@ -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());
index aad11cfe302eb19b57259dbd105fcab7b8bb42de..22c403a20d46a7a6db653440ef04432a01c74703 100644 (file)
@@ -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<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(
@@ -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,
index 3861936d858723e55c3d8dd38b41f0d3fa9dc1fa..3c502807ce6b1519b297c2d06c63773850895e81 100644 (file)
@@ -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<Props> {
       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) {
index ffffcc00855b2670328fd1b7dfb160396d0792f3..760c6021c3b60ed1f01e4d498a702f340e6c6d01 100644 (file)
@@ -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
index 05e471c7ffd578824c40d4a97cc77850e4a1623f..d08d0e7b7a67747fdfa240c393f684d0387a251a 100644 (file)
@@ -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(
index 3d9291aab69ca8bfe4c3aa7278be30da2ca3f953..bda7d36a7025de4798aaf046bb3410c80b47b4c3 100644 (file)
@@ -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)) {
index 76724b38c4da14748da3f77a8bdf7a994f23385e..b95a7c6e78700833185eb160bd23544bd9d69ca8 100644 (file)
@@ -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;
   }
 }
index cd5534fda757228e065bc2367a697e3306f10f8d..4e0c1e500ed8dd0bb3affe7af58fc82e8563fb9f 100644 (file)
@@ -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)
   };
index 802c4bf27a624c41048bab016d9a0f8c8e31769a..a4bd2f15e35a3deb6c3e1363943a07cfc7b0a3c6 100644 (file)
@@ -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;
index 3fd8aa7627ec7eafc54bb55f863cadb164985306..cf81dd3342c420c9b2d8bea47a30e8e2eff5e309 100644 (file)
@@ -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);