aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-09-04 10:34:41 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-09-13 15:50:52 +0200
commitfd6e8e2666d60d19cf5cc1036ca4db7fce26467d (patch)
tree682ed88104ef3a0a43ddf5109c8c00702622c6d4 /server
parent81b30756f2baecc347ce5cf97795ab861b8e4781 (diff)
downloadsonarqube-fd6e8e2666d60d19cf5cc1036ca4db7fce26467d.tar.gz
sonarqube-fd6e8e2666d60d19cf5cc1036ca4db7fce26467d.zip
SONAR-9740 rename HazelcastClient#getConnectedClients to getMemberUuids
which now return UUID of all members of the HZ cluster, both members and local clients to these member also rename #getClientUuid to getUuid
Diffstat (limited to 'server')
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/CeDistributedInformationImpl.java6
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/CeDistributedInformationImplTest.java16
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterObjectKeys.java2
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/cluster/health/SharedHealthStateImpl.java4
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/cluster/internal/HazelcastTestHelper.java4
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClient.java15
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastLocalClient.java11
-rw-r--r--server/sonar-cluster/src/test/java/org/sonar/cluster/health/SharedHealthStateImplTest.java8
-rw-r--r--server/sonar-cluster/src/test/java/org/sonar/cluster/localclient/HazelcastLocalClientTest.java4
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java16
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java8
11 files changed, 52 insertions, 42 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/CeDistributedInformationImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/CeDistributedInformationImpl.java
index 96cfbb6fdf5..1f48d9323b5 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/CeDistributedInformationImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/CeDistributedInformationImpl.java
@@ -45,7 +45,7 @@ public class CeDistributedInformationImpl implements CeDistributedInformation, S
@Override
public Set<String> getWorkerUUIDs() {
- Set<String> connectedWorkerUUIDs = hazelcastClient.getConnectedClients();
+ Set<String> connectedWorkerUUIDs = hazelcastClient.getMemberUuids();
return getClusteredWorkerUUIDs().entrySet().stream()
.filter(e -> connectedWorkerUUIDs.contains(e.getKey()))
@@ -56,7 +56,7 @@ public class CeDistributedInformationImpl implements CeDistributedInformation, S
@Override
public void broadcastWorkerUUIDs() {
- getClusteredWorkerUUIDs().put(hazelcastClient.getClientUUID(), ceCeWorkerFactory.getWorkerUUIDs());
+ getClusteredWorkerUUIDs().put(hazelcastClient.getUUID(), ceCeWorkerFactory.getWorkerUUIDs());
}
@Override
@@ -72,7 +72,7 @@ public class CeDistributedInformationImpl implements CeDistributedInformation, S
@Override
public void stop() {
// Removing the worker UUIDs
- getClusteredWorkerUUIDs().remove(hazelcastClient.getClientUUID());
+ getClusteredWorkerUUIDs().remove(hazelcastClient.getUUID());
}
private Map<String, Set<String>> getClusteredWorkerUUIDs() {
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/CeDistributedInformationImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/CeDistributedInformationImplTest.java
index 782db8bc4a4..630de3cf30f 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/CeDistributedInformationImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/CeDistributedInformationImplTest.java
@@ -49,8 +49,8 @@ public class CeDistributedInformationImplTest {
@Test
public void getWorkerUUIDs_returns_union_of_workers_uuids_of_local_and_cluster_worker_uuids() {
- when(hzClientWrapper.getClientUUID()).thenReturn(clientUUID1);
- when(hzClientWrapper.getConnectedClients()).thenReturn(ImmutableSet.of(clientUUID1, clientUUID2, clientUUID3));
+ when(hzClientWrapper.getUUID()).thenReturn(clientUUID1);
+ when(hzClientWrapper.getMemberUuids()).thenReturn(ImmutableSet.of(clientUUID1, clientUUID2, clientUUID3));
when(hzClientWrapper.getReplicatedMap(WORKER_UUIDS)).thenReturn(workerMap);
CeDistributedInformation ceDistributedInformation = new CeDistributedInformationImpl(hzClientWrapper, mock(CeWorkerFactory.class));
@@ -59,8 +59,8 @@ public class CeDistributedInformationImplTest {
@Test
public void getWorkerUUIDs_must_filter_absent_client() {
- when(hzClientWrapper.getClientUUID()).thenReturn(clientUUID1);
- when(hzClientWrapper.getConnectedClients()).thenReturn(ImmutableSet.of(clientUUID1, clientUUID2));
+ when(hzClientWrapper.getUUID()).thenReturn(clientUUID1);
+ when(hzClientWrapper.getMemberUuids()).thenReturn(ImmutableSet.of(clientUUID1, clientUUID2));
when(hzClientWrapper.getReplicatedMap(WORKER_UUIDS)).thenReturn(workerMap);
CeDistributedInformation ceDistributedInformation = new CeDistributedInformationImpl(hzClientWrapper, mock(CeWorkerFactory.class));
@@ -74,8 +74,8 @@ public class CeDistributedInformationImplTest {
connectedClients.add(clientUUID1);
connectedClients.add(clientUUID2);
- when(hzClientWrapper.getClientUUID()).thenReturn(clientUUID1);
- when(hzClientWrapper.getConnectedClients()).thenReturn(connectedClients);
+ when(hzClientWrapper.getUUID()).thenReturn(clientUUID1);
+ when(hzClientWrapper.getMemberUuids()).thenReturn(connectedClients);
when(hzClientWrapper.getReplicatedMap(WORKER_UUIDS)).thenReturn(modifiableWorkerMap);
CeWorkerFactory ceWorkerFactory = mock(CeWorkerFactory.class);
@@ -101,8 +101,8 @@ public class CeDistributedInformationImplTest {
Map modifiableWorkerMap = new HashMap();
modifiableWorkerMap.putAll(workerMap);
- when(hzClientWrapper.getClientUUID()).thenReturn(clientUUID1);
- when(hzClientWrapper.getConnectedClients()).thenReturn(connectedClients);
+ when(hzClientWrapper.getUUID()).thenReturn(clientUUID1);
+ when(hzClientWrapper.getMemberUuids()).thenReturn(connectedClients);
when(hzClientWrapper.getReplicatedMap(WORKER_UUIDS)).thenReturn(modifiableWorkerMap);
CeDistributedInformationImpl ceDistributedInformation = new CeDistributedInformationImpl(hzClientWrapper, mock(CeWorkerFactory.class));
diff --git a/server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterObjectKeys.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterObjectKeys.java
index b9634c02f41..ce0a4185850 100644
--- a/server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterObjectKeys.java
+++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterObjectKeys.java
@@ -65,7 +65,7 @@ public final class ClusterObjectKeys {
/**
* The key of the Set holding the UUIDs of clients
*/
- public static final String CLIENT_UUIDS = "CLIENT_UUIDS";
+ public static final String LOCAL_MEMBER_UUIDS = "LOCAL_MEMBER_UUIDS";
/**
* The key of replicated map holding the CeWorker UUIDs
*/
diff --git a/server/sonar-cluster/src/main/java/org/sonar/cluster/health/SharedHealthStateImpl.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/health/SharedHealthStateImpl.java
index 782af0dbc08..ca1375b47b0 100644
--- a/server/sonar-cluster/src/main/java/org/sonar/cluster/health/SharedHealthStateImpl.java
+++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/health/SharedHealthStateImpl.java
@@ -47,13 +47,13 @@ public class SharedHealthStateImpl implements SharedHealthState {
if (LOG.isTraceEnabled()) {
LOG.trace("Reading {} and adding {}", new HashMap<>(sqHealthState), nodeHealth);
}
- sqHealthState.put(hazelcastClient.getClientUUID(), nodeHealth);
+ sqHealthState.put(hazelcastClient.getUUID(), nodeHealth);
}
@Override
public void clearMine() {
Map<String, NodeHealth> sqHealthState = hazelcastClient.getReplicatedMap(SQ_HEALTH_STATE_REPLICATED_MAP_IDENTIFIER);
- String clientUUID = hazelcastClient.getClientUUID();
+ String clientUUID = hazelcastClient.getUUID();
if (LOG.isTraceEnabled()) {
LOG.trace("Reading {} and clear for {}", new HashMap<>(sqHealthState), clientUUID);
}
diff --git a/server/sonar-cluster/src/main/java/org/sonar/cluster/internal/HazelcastTestHelper.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/internal/HazelcastTestHelper.java
index f3a51e8757f..0ae1554f66a 100644
--- a/server/sonar-cluster/src/main/java/org/sonar/cluster/internal/HazelcastTestHelper.java
+++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/internal/HazelcastTestHelper.java
@@ -85,12 +85,12 @@ public class HazelcastTestHelper {
@Override
public void clientConnected(Client client) {
- hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS).add(client.getUuid());
+ hzInstance.getSet(ClusterObjectKeys.LOCAL_MEMBER_UUIDS).add(client.getUuid());
}
@Override
public void clientDisconnected(Client client) {
- hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS).remove(client.getUuid());
+ hzInstance.getSet(ClusterObjectKeys.LOCAL_MEMBER_UUIDS).remove(client.getUuid());
}
}
}
diff --git a/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClient.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClient.java
index b37718f46cc..03689945860 100644
--- a/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClient.java
+++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClient.java
@@ -50,17 +50,18 @@ public interface HazelcastClient {
<K,V> Map<K,V> getReplicatedMap(String name);
/**
- * Retrieve the local UUID
+ * The UUID of the Hazelcast client.
+ *
+ * <p>The uuid of the member of the current client is a member, otherwise the UUID of the client if the
+ * member is a local client of one of the members.</p>
*/
- String getClientUUID();
+ String getUUID();
/**
- * Retrieve the Set of connected clients.
- * The client is only CE for the time being
- *
- * @return the connected clients
+ * The UUIDs of all the members (both members and local clients of these members) currently connected to the
+ * Hazelcast cluster.
*/
- Set<String> getConnectedClients();
+ Set<String> getMemberUuids();
/**
* Gets lock among the cluster, identified by name
diff --git a/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastLocalClient.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastLocalClient.java
index cc90fcce27b..4e31de83ca8 100644
--- a/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastLocalClient.java
+++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastLocalClient.java
@@ -21,8 +21,10 @@
package org.sonar.cluster.localclient;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableSet;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.core.Member;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -89,13 +91,16 @@ public class HazelcastLocalClient implements Startable, HazelcastClient {
}
@Override
- public String getClientUUID() {
+ public String getUUID() {
return hzInstance.getLocalEndpoint().getUuid();
}
@Override
- public Set<String> getConnectedClients() {
- return hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS);
+ public Set<String> getMemberUuids() {
+ ImmutableSet.Builder<String> builder = ImmutableSet.builder();
+ builder.addAll(hzInstance.getSet(ClusterObjectKeys.LOCAL_MEMBER_UUIDS));
+ hzInstance.getCluster().getMembers().stream().map(Member::getUuid).forEach(builder::add);
+ return builder.build();
}
@Override
diff --git a/server/sonar-cluster/src/test/java/org/sonar/cluster/health/SharedHealthStateImplTest.java b/server/sonar-cluster/src/test/java/org/sonar/cluster/health/SharedHealthStateImplTest.java
index 778daeeab55..1af5ec14ab9 100644
--- a/server/sonar-cluster/src/test/java/org/sonar/cluster/health/SharedHealthStateImplTest.java
+++ b/server/sonar-cluster/src/test/java/org/sonar/cluster/health/SharedHealthStateImplTest.java
@@ -67,7 +67,7 @@ public class SharedHealthStateImplTest {
Map<String, NodeHealth> map = new HashMap<>();
doReturn(map).when(hazelcastClient).getReplicatedMap(MAP_SQ_HEALTH_STATE);
String uuid = randomAlphanumeric(5);
- when(hazelcastClient.getClientUUID()).thenReturn(uuid);
+ when(hazelcastClient.getUUID()).thenReturn(uuid);
underTest.writeMine(nodeHealth);
@@ -84,7 +84,7 @@ public class SharedHealthStateImplTest {
map.put(randomAlphanumeric(4), randomNodeHealth());
doReturn(new HashMap<>(map)).when(hazelcastClient).getReplicatedMap(MAP_SQ_HEALTH_STATE);
String uuid = randomAlphanumeric(5);
- when(hazelcastClient.getClientUUID()).thenReturn(uuid);
+ when(hazelcastClient.getUUID()).thenReturn(uuid);
underTest.writeMine(newNodeHealth);
@@ -125,7 +125,7 @@ public class SharedHealthStateImplTest {
Map<String, NodeHealth> map = mock(Map.class);
doReturn(map).when(hazelcastClient).getReplicatedMap(MAP_SQ_HEALTH_STATE);
String uuid = randomAlphanumeric(5);
- when(hazelcastClient.getClientUUID()).thenReturn(uuid);
+ when(hazelcastClient.getUUID()).thenReturn(uuid);
underTest.clearMine();
@@ -141,7 +141,7 @@ public class SharedHealthStateImplTest {
map.put(randomAlphanumeric(4), randomNodeHealth());
doReturn(map).when(hazelcastClient).getReplicatedMap(MAP_SQ_HEALTH_STATE);
String uuid = randomAlphanumeric(5);
- when(hazelcastClient.getClientUUID()).thenReturn(uuid);
+ when(hazelcastClient.getUUID()).thenReturn(uuid);
underTest.clearMine();
diff --git a/server/sonar-cluster/src/test/java/org/sonar/cluster/localclient/HazelcastLocalClientTest.java b/server/sonar-cluster/src/test/java/org/sonar/cluster/localclient/HazelcastLocalClientTest.java
index e783eb6dc33..084941a7d0c 100644
--- a/server/sonar-cluster/src/test/java/org/sonar/cluster/localclient/HazelcastLocalClientTest.java
+++ b/server/sonar-cluster/src/test/java/org/sonar/cluster/localclient/HazelcastLocalClientTest.java
@@ -160,8 +160,8 @@ public class HazelcastLocalClientTest {
try {
hazelcastClientWrapperImpl.start();
clientListener.counter.await(5, TimeUnit.SECONDS);
- assertThat(hazelcastClientWrapperImpl.getConnectedClients()).hasSize(1);
- assertThat(hazelcastClientWrapperImpl.getClientUUID()).isNotEmpty();
+ assertThat(hazelcastClientWrapperImpl.getMemberUuids()).hasSize(2);
+ assertThat(hazelcastClientWrapperImpl.getUUID()).isNotEmpty();
} finally {
hazelcastClientWrapperImpl.stop();
}
diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java
index b107751c055..737953f49ec 100644
--- a/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java
+++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java
@@ -20,6 +20,7 @@
package org.sonar.application.cluster;
+import com.google.common.collect.ImmutableSet;
import com.hazelcast.config.Config;
import com.hazelcast.config.JoinConfig;
import com.hazelcast.config.NetworkConfig;
@@ -58,11 +59,11 @@ import org.sonar.process.ProcessId;
import static java.lang.String.format;
import static java.util.stream.Collectors.toList;
import static org.sonar.application.cluster.ClusterProperties.HAZELCAST_CLUSTER_NAME;
-import static org.sonar.cluster.ClusterObjectKeys.CLIENT_UUIDS;
import static org.sonar.cluster.ClusterObjectKeys.CLUSTER_NAME;
import static org.sonar.cluster.ClusterObjectKeys.HOSTNAME;
import static org.sonar.cluster.ClusterObjectKeys.IP_ADDRESSES;
import static org.sonar.cluster.ClusterObjectKeys.LEADER;
+import static org.sonar.cluster.ClusterObjectKeys.LOCAL_MEMBER_UUIDS;
import static org.sonar.cluster.ClusterObjectKeys.NODE_NAME;
import static org.sonar.cluster.ClusterObjectKeys.NODE_TYPE;
import static org.sonar.cluster.ClusterObjectKeys.OPERATIONAL_PROCESSES;
@@ -313,13 +314,16 @@ public class HazelcastCluster implements AutoCloseable {
}
@Override
- public String getClientUUID() {
+ public String getUUID() {
return hzInstance.getLocalEndpoint().getUuid();
}
@Override
- public Set<String> getConnectedClients() {
- return hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS);
+ public Set<String> getMemberUuids() {
+ ImmutableSet.Builder<String> builder = ImmutableSet.builder();
+ builder.addAll(hzInstance.getSet(ClusterObjectKeys.LOCAL_MEMBER_UUIDS));
+ hzInstance.getCluster().getMembers().stream().map(Member::getUuid).forEach(builder::add);
+ return builder.build();
}
@Override
@@ -367,12 +371,12 @@ public class HazelcastCluster implements AutoCloseable {
private class ConnectedClientListener implements ClientListener {
@Override
public void clientConnected(Client client) {
- hzInstance.getSet(CLIENT_UUIDS).add(client.getUuid());
+ hzInstance.getSet(LOCAL_MEMBER_UUIDS).add(client.getUuid());
}
@Override
public void clientDisconnected(Client client) {
- hzInstance.getSet(CLIENT_UUIDS).remove(client.getUuid());
+ hzInstance.getSet(LOCAL_MEMBER_UUIDS).remove(client.getUuid());
}
}
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 11a77839f35..15ecf7a1df8 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
@@ -157,12 +157,12 @@ public class HazelcastClusterTest {
testAppSettings.set(CLUSTER_NAME, "a_cluster_");
ClusterProperties clusterProperties = new ClusterProperties(testAppSettings);
try (HazelcastCluster hzCluster = HazelcastCluster.create(clusterProperties)) {
- assertThat(hzCluster.hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS)).isEmpty();
+ assertThat(hzCluster.hzInstance.getSet(ClusterObjectKeys.LOCAL_MEMBER_UUIDS)).isEmpty();
HazelcastInstance hzClient = createHazelcastClient(hzCluster);
- assertThat(hzCluster.hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS)).containsExactly(hzClient.getLocalEndpoint().getUuid());
+ assertThat(hzCluster.hzInstance.getSet(ClusterObjectKeys.LOCAL_MEMBER_UUIDS)).containsExactly(hzClient.getLocalEndpoint().getUuid());
CountDownLatch latch = new CountDownLatch(1);
- hzCluster.hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS).addItemListener(new ItemListener<Object>() {
+ hzCluster.hzInstance.getSet(ClusterObjectKeys.LOCAL_MEMBER_UUIDS).addItemListener(new ItemListener<Object>() {
@Override
public void itemAdded(ItemEvent<Object> item) {
}
@@ -175,7 +175,7 @@ public class HazelcastClusterTest {
hzClient.shutdown();
if (latch.await(5, TimeUnit.SECONDS)) {
- assertThat(hzCluster.hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS).size()).isEqualTo(0);
+ assertThat(hzCluster.hzInstance.getSet(ClusterObjectKeys.LOCAL_MEMBER_UUIDS).size()).isEqualTo(0);
} else {
fail("The client UUID have not been removed from the Set within 5 seconds' time lapse");
}