зеркало из
https://github.com/SonarSource/sonarqube.git
synced 2024-07-29 08:17:28 +02:00
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
Этот коммит содержится в:
родитель
81b30756f2
Коммит
fd6e8e2666
@ -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() {
|
||||
|
@ -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));
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user