]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9802 fix support of overridden cluster name
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 21 Sep 2017 13:45:30 +0000 (15:45 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 26 Sep 2017 21:49:38 +0000 (23:49 +0200)
server/sonar-main/src/main/java/org/sonar/application/AppStateFactory.java
server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java
server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java
server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java
server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java
server/sonar-server/src/main/java/org/sonar/server/cluster/StartableHazelcastMember.java
tests/src/test/java/org/sonarqube/tests/cluster/ClusterTest.java

index 0498f2e41005bbc3d1d91e3f5a927d781c1218cf..75f1577c432e6f15b91d4f92bb32e6b56a2a06ef 100644 (file)
@@ -49,7 +49,6 @@ public class AppStateFactory {
 
   private static HazelcastMember createHzMember(Props props) {
     HazelcastMemberBuilder builder = new HazelcastMemberBuilder()
-      .setClusterName("sonarqube")
       .setNetworkInterface(props.nonNullValue(ProcessProperties.CLUSTER_NODE_HOST))
       .setMembers(asList(props.nonNullValue(ProcessProperties.CLUSTER_HOSTS).split(",")))
       .setNodeType(NodeType.parse(props.nonNullValue(ProcessProperties.CLUSTER_NODE_TYPE)))
index ba85353df39d4877d50d05bf6aa1f62cadb5837a..7af7c97e83f90feeb151e07956aa6efd9b0cdb19 100644 (file)
@@ -141,7 +141,6 @@ public class ClusterAppStateImplTest {
     return new HazelcastMemberBuilder()
       .setNodeType(NodeType.APPLICATION)
       .setProcessId(ProcessId.COMPUTE_ENGINE)
-      .setClusterName("foo")
       .setNodeName("bar")
       .setPort(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback))
       .setNetworkInterface(loopback.getHostAddress())
index 55a5dd0a4edf0db7e77bed0ddecf30854a10dbce..73ba63abfa42cebefe1f07a2ea7254ee3d7b0e85 100644 (file)
@@ -41,7 +41,6 @@ import static java.util.Objects.requireNonNull;
 
 public class HazelcastMemberBuilder {
 
-  private String clusterName;
   private String nodeName;
   private int port;
   private NodeType nodeType;
@@ -49,11 +48,6 @@ public class HazelcastMemberBuilder {
   private String networkInterface;
   private List<String> members = new ArrayList<>();
 
-  public HazelcastMemberBuilder setClusterName(String s) {
-    this.clusterName = s;
-    return this;
-  }
-
   public HazelcastMemberBuilder setNodeName(String s) {
     this.nodeName = s;
     return this;
@@ -97,7 +91,11 @@ public class HazelcastMemberBuilder {
 
   public HazelcastMember build() {
     Config config = new Config();
-    config.getGroupConfig().setName(requireNonNull(clusterName, "Cluster name is missing"));
+    // do not use the value defined by property sonar.cluster.name.
+    // Hazelcast does not fail when joining a cluster with different name.
+    // Apparently this behavior exists since Hazelcast 3.8.2 (see note
+    // at http://docs.hazelcast.org/docs/3.8.6/manual/html-single/index.html#creating-cluster-groups)
+    config.getGroupConfig().setName("SonarQube");
 
     // Configure network
     NetworkConfig netConfig = config.getNetworkConfig();
index 6a4973b8d13926eeeec9b09e9e79a202b87c0d89..b01223d76167508b996d9437e6d36b98e5995894 100644 (file)
@@ -47,7 +47,6 @@ public class HazelcastMemberBuilderTest {
     HazelcastMember member = underTest
       .setNodeType(NodeType.APPLICATION)
       .setProcessId(ProcessId.COMPUTE_ENGINE)
-      .setClusterName("foo")
       .setNodeName("bar")
       .setPort(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback))
       .setNetworkInterface(loopback.getHostAddress())
index 4d83a82f2333078ca8ed7cd771bd1d042da458cd..3bf649baecdaf3846934fa2a9500eaa01a84d123 100644 (file)
@@ -114,7 +114,6 @@ public class HazelcastMemberImplTest {
     return new HazelcastMemberBuilder()
       .setNodeType(NodeType.APPLICATION)
       .setProcessId(ProcessId.COMPUTE_ENGINE)
-      .setClusterName("foo")
       .setNodeName("name" + port)
       .setPort(port)
       .setNetworkInterface(loopback.getHostAddress())
index 1e430e17d293c56999dbc6922d0f617c1556fcf4..7bf6c82d48786a81406bab27642bd65f1f537080 100644 (file)
@@ -140,7 +140,6 @@ public class StartableHazelcastMember implements HazelcastMember, Startable {
       throw new IllegalStateException(format("Can not resolve address %s", networkAddress), e);
     }
     this.member = new HazelcastMemberBuilder()
-      .setClusterName(config.get(ProcessProperties.CLUSTER_NAME).orElseThrow(() -> new IllegalStateException("Missing cluster name")))
       .setNodeName(config.get(ProcessProperties.CLUSTER_NODE_NAME).orElseThrow(() -> new IllegalStateException("Missing node name")))
       .setNodeType(NodeType.parse(config.get(CLUSTER_NODE_TYPE).orElseThrow(() -> new IllegalStateException("Missing node type"))))
       .setPort(freePort)
index 169e9a2caade1151fa7d9a8be36b12207d948961..b7221c8bb03f2bf54fe67e9d91d25e021b4ac023 100644 (file)
@@ -232,6 +232,24 @@ public class ClusterTest {
     }
   }
 
+  @Test
+  public void cluster_name_can_be_overridden() throws Exception {
+    try (Cluster cluster = new Cluster("foo")) {
+      NodeConfig searchConfig1 = newSearchConfig("Search 1");
+      NodeConfig searchConfig2 = newSearchConfig("Search 2");
+      NodeConfig appConfig = newApplicationConfig("App 1");
+      NodeConfig.interconnectBus(searchConfig1, searchConfig2, appConfig);
+      NodeConfig.interconnectSearch(searchConfig1, searchConfig2, appConfig);
+
+      cluster.startNode(searchConfig1, nothing());
+      cluster.startNode(searchConfig2, nothing());
+      cluster.startNode(appConfig, nothing());
+
+      Node appNode = cluster.getAppNode(0);
+      appNode.waitForStatusUp();
+    }
+  }
+
   @Test
   public void node_fails_to_join_cluster_if_different_cluster_name() throws Exception {
     try (Cluster cluster = new Cluster("foo")) {