From d8130b676481993c2b258ea326a5778356d93085 Mon Sep 17 00:00:00 2001 From: Zipeng WU Date: Tue, 13 Apr 2021 09:14:07 +0200 Subject: [PATCH] SONAR-14625 Upgrade to Hazelcast 4.2 --- build.gradle | 3 +- .../ce/CeDistributedInformationImpl.java | 5 +- .../ce/CeDistributedInformationImplTest.java | 50 +++++++++++-------- .../AppNodesClusterHostsConsistency.java | 6 +-- .../cluster/ClusterAppStateImpl.java | 38 +++++++------- .../application/cluster/ClusterProcess.java | 7 +-- .../AppNodesClusterHostsConsistencyTest.java | 15 +++--- .../cluster/ClusterAppStateImplTest.java | 18 +++++++ .../cluster/ClusterProcessTest.java | 10 ++-- .../cluster/health/SharedHealthStateImpl.java | 17 ++++--- .../process/cluster/hz/DistributedAnswer.java | 6 +-- .../cluster/hz/DistributedCallback.java | 2 +- .../process/cluster/hz/HazelcastMember.java | 13 ++--- .../cluster/hz/HazelcastMemberBuilder.java | 15 +++--- .../cluster/hz/HazelcastMemberImpl.java | 17 ++++--- .../cluster/hz/HazelcastMemberSelectors.java | 4 +- .../health/SharedHealthStateImplTest.java | 50 +++++++++---------- .../cluster/hz/DistributedAnswerTest.java | 36 +++++++------ .../hz/HazelcastMemberBuilderTest.java | 11 ++-- .../cluster/hz/HazelcastMemberImplTest.java | 2 +- .../hz/HazelcastMemberSelectorsTest.java | 16 +++--- .../cluster/AppNodesInfoLoaderImpl.java | 6 +-- .../cluster/AppNodesInfoLoaderImplTest.java | 13 +++-- 23 files changed, 198 insertions(+), 162 deletions(-) diff --git a/build.gradle b/build.gradle index b200d44736c..8d87d5eab87 100644 --- a/build.gradle +++ b/build.gradle @@ -264,9 +264,8 @@ subprojects { dependency "com.google.protobuf:protobuf-java:${protobufVersion}" // Do not upgrade H2 to 1.4.200 because of instability: https://github.com/h2database/h2database/issues/2205 dependency 'com.h2database:h2:1.4.199' - dependencySet(group: 'com.hazelcast', version: '3.12.12') { + dependencySet(group: 'com.hazelcast', version: '4.2') { entry 'hazelcast' - entry 'hazelcast-client' } dependency 'com.ibm.icu:icu4j:3.4.4' dependency 'com.microsoft.sqlserver:mssql-jdbc:9.2.0.jre11' 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 4fd8053b3a8..02d8257aa96 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 @@ -22,6 +22,7 @@ package org.sonar.ce; import com.hazelcast.spi.exception.RetryableHazelcastException; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.concurrent.locks.Lock; import org.picocontainer.Startable; import org.sonar.api.utils.log.Logger; @@ -50,7 +51,7 @@ public class CeDistributedInformationImpl implements CeDistributedInformation, S @Override public Set getWorkerUUIDs() { - Set connectedWorkerUUIDs = hazelcastMember.getMemberUuids(); + Set connectedWorkerUUIDs = hazelcastMember.getMemberUuids(); return getClusteredWorkerUUIDs().entrySet().stream() .filter(e -> connectedWorkerUUIDs.contains(e.getKey())) @@ -86,7 +87,7 @@ public class CeDistributedInformationImpl implements CeDistributedInformation, S } } - private Map> getClusteredWorkerUUIDs() { + private Map> getClusteredWorkerUUIDs() { return hazelcastMember.getReplicatedMap(WORKER_UUIDS); } } 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 fb1ad1c611f..94c2c67bac8 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 @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.Test; @@ -39,46 +40,54 @@ import static org.mockito.Mockito.when; import static org.sonar.process.cluster.hz.HazelcastObjects.WORKER_UUIDS; public class CeDistributedInformationImplTest { - private String clientUUID1 = "1"; - private String clientUUID2 = "2"; - private String clientUUID3 = "3"; - private Map workerMap = ImmutableMap.of( - clientUUID1, ImmutableSet.of("1", "2"), - clientUUID2, ImmutableSet.of("3"), - clientUUID3, ImmutableSet.of("4", "5", "6")); + private final UUID clientUUID1 = UUID.randomUUID(); + private final UUID clientUUID2 = UUID.randomUUID(); + private final UUID clientUUID3 = UUID.randomUUID(); - private HazelcastMember hzClientWrapper = mock(HazelcastMember.class); + private final String w1 = UUID.randomUUID().toString(); + private final String w2 = UUID.randomUUID().toString(); + private final String w3 = UUID.randomUUID().toString(); + private final String w4 = UUID.randomUUID().toString(); + private final String w5 = UUID.randomUUID().toString(); + private final String w6 = UUID.randomUUID().toString(); + + private final Map> workerMap = ImmutableMap.of( + clientUUID1, ImmutableSet.of(w1, w2), + clientUUID2, ImmutableSet.of(w3), + clientUUID3, ImmutableSet.of(w4, w5, w6)); + + private final HazelcastMember hzClientWrapper = mock(HazelcastMember.class); @Test public void getWorkerUUIDs_returns_union_of_workers_uuids_of_local_and_cluster_worker_uuids() { when(hzClientWrapper.getUuid()).thenReturn(clientUUID1); when(hzClientWrapper.getMemberUuids()).thenReturn(ImmutableSet.of(clientUUID1, clientUUID2, clientUUID3)); - when(hzClientWrapper.getReplicatedMap(WORKER_UUIDS)).thenReturn(workerMap); + when(hzClientWrapper.>getReplicatedMap(WORKER_UUIDS)).thenReturn(workerMap); CeDistributedInformation ceDistributedInformation = new CeDistributedInformationImpl(hzClientWrapper, mock(CeWorkerFactory.class)); - assertThat(ceDistributedInformation.getWorkerUUIDs()).containsExactly("1", "2", "3", "4", "5", "6"); + assertThat(ceDistributedInformation.getWorkerUUIDs()).containsExactlyInAnyOrder(w1, w2, w3, w4, w5, w6); } @Test public void getWorkerUUIDs_must_filter_absent_client() { when(hzClientWrapper.getUuid()).thenReturn(clientUUID1); when(hzClientWrapper.getMemberUuids()).thenReturn(ImmutableSet.of(clientUUID1, clientUUID2)); - when(hzClientWrapper.getReplicatedMap(WORKER_UUIDS)).thenReturn(workerMap); + when(hzClientWrapper.>getReplicatedMap(WORKER_UUIDS)).thenReturn(workerMap); CeDistributedInformation ceDistributedInformation = new CeDistributedInformationImpl(hzClientWrapper, mock(CeWorkerFactory.class)); - assertThat(ceDistributedInformation.getWorkerUUIDs()).containsExactly("1", "2", "3"); + assertThat(ceDistributedInformation.getWorkerUUIDs()).containsExactlyInAnyOrder(w1, w2, w3); } @Test public void broadcastWorkerUUIDs_adds_local_workerUUIDs_to_shared_map_under_key_of_localendpoint_uuid() { - Set connectedClients = new HashSet<>(); - Map modifiableWorkerMap = new HashMap<>(); + Set connectedClients = new HashSet<>(); + Map> modifiableWorkerMap = new HashMap<>(); connectedClients.add(clientUUID1); connectedClients.add(clientUUID2); when(hzClientWrapper.getUuid()).thenReturn(clientUUID1); when(hzClientWrapper.getMemberUuids()).thenReturn(connectedClients); - when(hzClientWrapper.getReplicatedMap(WORKER_UUIDS)).thenReturn(modifiableWorkerMap); + when(hzClientWrapper.>getReplicatedMap(WORKER_UUIDS)).thenReturn(modifiableWorkerMap); CeWorkerFactory ceWorkerFactory = mock(CeWorkerFactory.class); Set ceWorkers = Stream.of("a10", "a11").map(uuid -> { @@ -100,20 +109,19 @@ public class CeDistributedInformationImplTest { @Test public void stop_must_remove_local_workerUUIDs() { - Set connectedClients = new HashSet<>(); + Set connectedClients = new HashSet<>(); connectedClients.add(clientUUID1); connectedClients.add(clientUUID2); connectedClients.add(clientUUID3); - Map modifiableWorkerMap = new HashMap(workerMap); + Map> modifiableWorkerMap = new HashMap<>(workerMap); when(hzClientWrapper.getUuid()).thenReturn(clientUUID1); when(hzClientWrapper.getMemberUuids()).thenReturn(connectedClients); - when(hzClientWrapper.getReplicatedMap(WORKER_UUIDS)).thenReturn(modifiableWorkerMap); + when(hzClientWrapper.>getReplicatedMap(WORKER_UUIDS)).thenReturn(modifiableWorkerMap); CeDistributedInformationImpl ceDistributedInformation = new CeDistributedInformationImpl(hzClientWrapper, mock(CeWorkerFactory.class)); ceDistributedInformation.stop(); - assertThat(modifiableWorkerMap).containsExactly( - entry(clientUUID2, ImmutableSet.of("3")), - entry(clientUUID3, ImmutableSet.of("4", "5", "6"))); + assertThat(modifiableWorkerMap).containsExactlyInAnyOrderEntriesOf( + ImmutableMap.of(clientUUID2, ImmutableSet.of(w3), clientUUID3, ImmutableSet.of(w4, w5, w6))); } } diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/AppNodesClusterHostsConsistency.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/AppNodesClusterHostsConsistency.java index 358facf4032..49e32144f66 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/cluster/AppNodesClusterHostsConsistency.java +++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/AppNodesClusterHostsConsistency.java @@ -20,10 +20,10 @@ package org.sonar.application.cluster; import com.google.common.annotations.VisibleForTesting; +import com.hazelcast.cluster.Address; +import com.hazelcast.cluster.Member; +import com.hazelcast.cluster.MemberSelector; import com.hazelcast.cluster.memberselector.MemberSelectors; -import com.hazelcast.core.Member; -import com.hazelcast.core.MemberSelector; -import com.hazelcast.nio.Address; import java.util.Arrays; import java.util.Collections; import java.util.List; diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterAppStateImpl.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterAppStateImpl.java index 76f30de035c..b2f7ab578e6 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterAppStateImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterAppStateImpl.java @@ -19,21 +19,21 @@ */ package org.sonar.application.cluster; +import com.hazelcast.cluster.Member; +import com.hazelcast.cluster.MembershipEvent; +import com.hazelcast.cluster.MembershipListener; import com.hazelcast.core.EntryEvent; import com.hazelcast.core.EntryListener; import com.hazelcast.core.HazelcastInstanceNotActiveException; -import com.hazelcast.core.IAtomicReference; -import com.hazelcast.core.MapEvent; -import com.hazelcast.core.Member; -import com.hazelcast.core.MemberAttributeEvent; -import com.hazelcast.core.MembershipEvent; -import com.hazelcast.core.MembershipListener; -import com.hazelcast.core.ReplicatedMap; +import com.hazelcast.cp.IAtomicReference; +import com.hazelcast.map.MapEvent; +import com.hazelcast.replicatedmap.ReplicatedMap; import java.util.ArrayList; import java.util.EnumMap; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.UUID; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,8 +63,8 @@ public class ClusterAppStateImpl implements ClusterAppState { private final List listeners = new ArrayList<>(); private final Map operationalLocalProcesses = new EnumMap<>(ProcessId.class); private final ReplicatedMap operationalProcesses; - private final String operationalProcessListenerUUID; - private final String nodeDisconnectedListenerUUID; + private final UUID operationalProcessListenerUUID; + private final UUID nodeDisconnectedListenerUUID; private final EsConnector esConnector; private HealthStateSharing healthStateSharing = null; @@ -120,7 +120,7 @@ public class ClusterAppStateImpl implements ClusterAppState { @Override public boolean tryToLockWebLeader() { - IAtomicReference leader = hzMember.getAtomicReference(LEADER); + IAtomicReference leader = hzMember.getAtomicReference(LEADER); return leader.compareAndSet(null, hzMember.getUuid()); } @@ -159,9 +159,9 @@ public class ClusterAppStateImpl implements ClusterAppState { @Override public Optional getLeaderHostName() { - String leaderId = (String) hzMember.getAtomicReference(LEADER).get(); - if (leaderId != null) { - Optional leader = hzMember.getCluster().getMembers().stream().filter(m -> m.getUuid().equals(leaderId)).findFirst(); + UUID leaderUuid = (UUID) hzMember.getAtomicReference(LEADER).get(); + if (leaderUuid != null) { + Optional leader = hzMember.getCluster().getMembers().stream().filter(m -> m.getUuid().equals(leaderUuid)).findFirst(); if (leader.isPresent()) { return Optional.of(leader.get().getAddress().getHost()); } @@ -239,6 +239,11 @@ public class ClusterAppStateImpl implements ClusterAppState { public void mapEvicted(MapEvent event) { // Ignore it } + + @Override + public void entryExpired(EntryEvent event) { + // Ignore it + } } private class NodeDisconnectedListener implements MembershipListener { @@ -252,12 +257,7 @@ public class ClusterAppStateImpl implements ClusterAppState { removeOperationalProcess(membershipEvent.getMember().getUuid()); } - @Override - public void memberAttributeChanged(MemberAttributeEvent memberAttributeEvent) { - // Nothing to do - } - - private void removeOperationalProcess(String uuid) { + private void removeOperationalProcess(UUID uuid) { for (ClusterProcess clusterProcess : operationalProcesses.keySet()) { if (clusterProcess.getNodeUuid().equals(uuid)) { LOGGER.debug("Set node process off for [{}:{}] : ", clusterProcess.getNodeUuid(), clusterProcess.getProcessId()); diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProcess.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProcess.java index cf7859c7b16..d48591bb056 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProcess.java +++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProcess.java @@ -21,15 +21,16 @@ package org.sonar.application.cluster; import java.io.Serializable; import java.util.Objects; +import java.util.UUID; import org.sonar.process.ProcessId; import static java.util.Objects.requireNonNull; public class ClusterProcess implements Serializable { private final ProcessId processId; - private final String nodeUuid; + private final UUID nodeUuid; - public ClusterProcess(String nodeUuid, ProcessId processId) { + public ClusterProcess(UUID nodeUuid, ProcessId processId) { this.processId = requireNonNull(processId); this.nodeUuid = requireNonNull(nodeUuid); } @@ -38,7 +39,7 @@ public class ClusterProcess implements Serializable { return processId; } - public String getNodeUuid() { + public UUID getNodeUuid() { return nodeUuid; } diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/AppNodesClusterHostsConsistencyTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/AppNodesClusterHostsConsistencyTest.java index cdae656ebd7..0107499267a 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/AppNodesClusterHostsConsistencyTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/AppNodesClusterHostsConsistencyTest.java @@ -20,11 +20,11 @@ package org.sonar.application.cluster; import com.google.common.collect.ImmutableMap; -import com.hazelcast.core.Cluster; -import com.hazelcast.core.IAtomicReference; -import com.hazelcast.core.Member; -import com.hazelcast.core.MemberSelector; -import com.hazelcast.nio.Address; +import com.hazelcast.cluster.Address; +import com.hazelcast.cluster.Cluster; +import com.hazelcast.cluster.Member; +import com.hazelcast.cluster.MemberSelector; +import com.hazelcast.cp.IAtomicReference; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; @@ -33,6 +33,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.concurrent.locks.Lock; import java.util.function.Consumer; import org.junit.After; @@ -164,12 +165,12 @@ public class AppNodesClusterHostsConsistencyTest { } @Override - public String getUuid() { + public UUID getUuid() { throw new IllegalStateException("not expected to be called"); } @Override - public Set getMemberUuids() { + public Set getMemberUuids() { throw new IllegalStateException("not expected to be called"); } diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java index eef179ed076..1501f6f6243 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java @@ -20,6 +20,7 @@ package org.sonar.application.cluster; import java.net.InetAddress; +import java.util.Optional; import org.junit.Rule; import org.junit.Test; import org.junit.rules.DisableOnDebug; @@ -145,6 +146,23 @@ public class ClusterAppStateImplTest { } } + @Test + public void return_hostname_if_node_is_leader() { + try (ClusterAppStateImpl underTest = createClusterAppState()) { + underTest.tryToLockWebLeader(); + Optional hostname = underTest.getLeaderHostName(); + assertThat(hostname).isNotEmpty(); + } + } + + @Test + public void return_null_if_node_is_not_leader() { + try (ClusterAppStateImpl underTest = createClusterAppState()) { + Optional hostname = underTest.getLeaderHostName(); + assertThat(hostname).isEmpty(); + } + } + private ClusterAppStateImpl createClusterAppState() { return new ClusterAppStateImpl(new TestAppSettings(), newHzMember(), mock(EsConnector.class), mock(AppNodesClusterHostsConsistency.class)); } diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterProcessTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterProcessTest.java index 2b7586a2403..38d5a862161 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterProcessTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterProcessTest.java @@ -19,6 +19,7 @@ */ package org.sonar.application.cluster; +import java.util.UUID; import org.junit.Test; import org.sonar.process.ProcessId; @@ -27,13 +28,14 @@ import static org.assertj.core.api.Assertions.assertThat; public class ClusterProcessTest { @Test public void test_equality() { - ClusterProcess clusterProcess = new ClusterProcess("A", ProcessId.WEB_SERVER); + UUID nodeUuid = UUID.randomUUID(); + ClusterProcess clusterProcess = new ClusterProcess(nodeUuid, ProcessId.WEB_SERVER); assertThat(clusterProcess) .isNotEqualTo(null) .isEqualTo(clusterProcess) - .isNotEqualTo(new ClusterProcess("B", ProcessId.WEB_SERVER)) - .isNotEqualTo(new ClusterProcess("A", ProcessId.ELASTICSEARCH)) - .isEqualTo(new ClusterProcess("A", ProcessId.WEB_SERVER)); + .isNotEqualTo(new ClusterProcess(UUID.randomUUID(), ProcessId.WEB_SERVER)) + .isNotEqualTo(new ClusterProcess(nodeUuid, ProcessId.ELASTICSEARCH)) + .isEqualTo(new ClusterProcess(nodeUuid, ProcessId.WEB_SERVER)); } } diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/health/SharedHealthStateImpl.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/health/SharedHealthStateImpl.java index 5849cc37179..70a353ed6bf 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/health/SharedHealthStateImpl.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/health/SharedHealthStateImpl.java @@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableSet; import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.function.Predicate; import java.util.stream.Collectors; import org.slf4j.Logger; @@ -50,7 +51,7 @@ public class SharedHealthStateImpl implements SharedHealthState { public void writeMine(NodeHealth nodeHealth) { requireNonNull(nodeHealth, "nodeHealth can't be null"); - Map sqHealthState = readReplicatedMap(); + Map sqHealthState = readReplicatedMap(); if (LOG.isTraceEnabled()) { LOG.trace("Reading {} and adding {}", new HashMap<>(sqHealthState), nodeHealth); } @@ -59,8 +60,8 @@ public class SharedHealthStateImpl implements SharedHealthState { @Override public void clearMine() { - Map sqHealthState = readReplicatedMap(); - String clientUUID = hzMember.getUuid(); + Map sqHealthState = readReplicatedMap(); + UUID clientUUID = hzMember.getUuid(); if (LOG.isTraceEnabled()) { LOG.trace("Reading {} and clearing for {}", new HashMap<>(sqHealthState), clientUUID); } @@ -71,8 +72,8 @@ public class SharedHealthStateImpl implements SharedHealthState { public Set readAll() { long clusterTime = hzMember.getClusterTime(); long timeout = clusterTime - TIMEOUT_30_SECONDS; - Map sqHealthState = readReplicatedMap(); - Set hzMemberUUIDs = hzMember.getMemberUuids(); + Map sqHealthState = readReplicatedMap(); + Set hzMemberUUIDs = hzMember.getMemberUuids(); Set existingNodeHealths = sqHealthState.entrySet().stream() .filter(outOfDate(timeout)) .filter(ofNonExistentMember(hzMemberUUIDs)) @@ -84,7 +85,7 @@ public class SharedHealthStateImpl implements SharedHealthState { return ImmutableSet.copyOf(existingNodeHealths); } - private static Predicate> outOfDate(long timeout) { + private static Predicate> outOfDate(long timeout) { return entry -> { boolean res = entry.getValue().getTimestamp() > timeout; if (!res) { @@ -94,7 +95,7 @@ public class SharedHealthStateImpl implements SharedHealthState { }; } - private static Predicate> ofNonExistentMember(Set hzMemberUUIDs) { + private static Predicate> ofNonExistentMember(Set hzMemberUUIDs) { return entry -> { boolean res = hzMemberUUIDs.contains(entry.getKey()); if (!res) { @@ -104,7 +105,7 @@ public class SharedHealthStateImpl implements SharedHealthState { }; } - private Map readReplicatedMap() { + private Map readReplicatedMap() { return hzMember.getReplicatedMap(HazelcastObjects.SQ_HEALTH_STATE); } diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java index c32fa6d67fc..784f315b14b 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java @@ -19,7 +19,7 @@ */ package org.sonar.process.cluster.hz; -import com.hazelcast.core.Member; +import com.hazelcast.cluster.Member; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -77,7 +77,7 @@ public class DistributedAnswer { public void propagateExceptions() { if (!failedMembers.isEmpty()) { String failedMemberNames = failedMembers.keySet().stream() - .map(m -> m.getStringAttribute(NODE_NAME.getKey())) + .map(m -> m.getAttribute(NODE_NAME.getKey())) .collect(Collectors.joining(", ")); throw new IllegalStateException("Distributed cluster action in cluster nodes " + failedMemberNames + " (other nodes may have timed out)", failedMembers.values().iterator().next()); @@ -85,7 +85,7 @@ public class DistributedAnswer { if (!timedOutMembers.isEmpty()) { String timedOutMemberNames = timedOutMembers.stream() - .map(m -> m.getStringAttribute(NODE_NAME.getKey())) + .map(m -> m.getAttribute(NODE_NAME.getKey())) .collect(Collectors.joining(", ")); throw new IllegalStateException("Distributed cluster action timed out in cluster nodes " + timedOutMemberNames); } diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedCallback.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedCallback.java index 456ab3ebdb8..e919a775536 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedCallback.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedCallback.java @@ -19,7 +19,7 @@ */ package org.sonar.process.cluster.hz; -import com.hazelcast.core.Member; +import com.hazelcast.cluster.Member; import java.util.Map; @FunctionalInterface diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java index 00226faea62..7196172671f 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java @@ -19,11 +19,12 @@ */ package org.sonar.process.cluster.hz; -import com.hazelcast.core.Cluster; -import com.hazelcast.core.IAtomicReference; -import com.hazelcast.core.MemberSelector; +import com.hazelcast.cluster.Cluster; +import com.hazelcast.cluster.MemberSelector; +import com.hazelcast.cp.IAtomicReference; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.concurrent.locks.Lock; import org.sonar.process.ProcessId; @@ -54,18 +55,18 @@ public interface HazelcastMember extends AutoCloseable { /** * Gets the replicated map shared by the cluster and identified by name. - * Result can be casted to {@link com.hazelcast.core.ReplicatedMap} if needed to + * Result can be casted to {@link com.hazelcast.replicatedmap.ReplicatedMap} if needed to * benefit from listeners. */ Map getReplicatedMap(String name); - String getUuid(); + UUID getUuid(); /** * The UUIDs of all the members (both members and local clients of these members) currently connected to the * Hazelcast cluster. */ - Set getMemberUuids(); + Set getMemberUuids(); /** * Gets lock among the cluster, identified by name diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java index e5bc3e8cec6..c2552ef3e20 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java @@ -24,6 +24,7 @@ import com.hazelcast.config.JoinConfig; import com.hazelcast.config.MemberAttributeConfig; import com.hazelcast.config.NetworkConfig; import com.hazelcast.core.Hazelcast; +import com.hazelcast.internal.util.AddressUtil; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collection; @@ -31,8 +32,8 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import javax.annotation.CheckForNull; - -import com.hazelcast.util.AddressUtil; +import org.sonar.api.utils.log.Logger; +import org.sonar.api.utils.log.Loggers; import org.sonar.process.ProcessId; import org.sonar.process.cluster.hz.HazelcastMember.Attribute; @@ -40,8 +41,6 @@ import static java.lang.String.format; import static java.util.Collections.singletonList; import static java.util.Objects.requireNonNull; import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; public class HazelcastMemberBuilder { @@ -102,7 +101,7 @@ public class HazelcastMemberBuilder { return Collections.singletonList(host.contains(":") ? host : format("%s:%s", host, CLUSTER_NODE_HZ_PORT.getDefaultValue())); } else { List membersToAdd = new ArrayList<>(); - for (String memberIp : getAllByName(hostStripped)){ + for (String memberIp : getAllByName(hostStripped)) { String prefix = memberIp.split("/")[1]; LOG.debug("Found IP for: " + hostStripped + " : " + prefix); String memberPort = host.contains(":") ? host.split(":")[1] : CLUSTER_NODE_HZ_PORT.getDefaultValue(); @@ -129,7 +128,7 @@ public class HazelcastMemberBuilder { // 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"); + config.setClusterName("SonarQube"); // Configure network NetworkConfig netConfig = config.getNetworkConfig(); @@ -162,8 +161,8 @@ public class HazelcastMemberBuilder { .setProperty("hazelcast.logging.type", "slf4j"); MemberAttributeConfig attributes = config.getMemberAttributeConfig(); - attributes.setStringAttribute(Attribute.NODE_NAME.getKey(), requireNonNull(nodeName, "Node name is missing")); - attributes.setStringAttribute(Attribute.PROCESS_KEY.getKey(), requireNonNull(processId, "Process key is missing").getKey()); + attributes.setAttribute(Attribute.NODE_NAME.getKey(), requireNonNull(nodeName, "Node name is missing")); + attributes.setAttribute(Attribute.PROCESS_KEY.getKey(), requireNonNull(processId, "Process key is missing").getKey()); return new HazelcastMemberImpl(Hazelcast.newHazelcastInstance(config)); } diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberImpl.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberImpl.java index 965135802ef..3dba93b572d 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberImpl.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberImpl.java @@ -19,16 +19,17 @@ */ package org.sonar.process.cluster.hz; -import com.hazelcast.core.Cluster; +import com.hazelcast.cluster.Cluster; +import com.hazelcast.cluster.Member; +import com.hazelcast.cluster.MemberSelector; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.HazelcastInstanceNotActiveException; -import com.hazelcast.core.IAtomicReference; import com.hazelcast.core.IExecutorService; -import com.hazelcast.core.Member; -import com.hazelcast.core.MemberSelector; import com.hazelcast.core.MultiExecutionCallback; +import com.hazelcast.cp.IAtomicReference; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -47,7 +48,7 @@ class HazelcastMemberImpl implements HazelcastMember { @Override public IAtomicReference getAtomicReference(String name) { - return hzInstance.getAtomicReference(name); + return hzInstance.getCPSubsystem().getAtomicReference(name); } @Override @@ -56,18 +57,18 @@ class HazelcastMemberImpl implements HazelcastMember { } @Override - public String getUuid() { + public UUID getUuid() { return hzInstance.getLocalEndpoint().getUuid(); } @Override - public Set getMemberUuids() { + public Set getMemberUuids() { return hzInstance.getCluster().getMembers().stream().map(Member::getUuid).collect(Collectors.toSet()); } @Override public Lock getLock(String s) { - return hzInstance.getLock(s); + return hzInstance.getCPSubsystem().getLock(s); } @Override diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java index 9a9ddc7003d..7696c926027 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java @@ -19,7 +19,7 @@ */ package org.sonar.process.cluster.hz; -import com.hazelcast.core.MemberSelector; +import com.hazelcast.cluster.MemberSelector; import java.util.List; import org.sonar.process.ProcessId; @@ -35,7 +35,7 @@ public class HazelcastMemberSelectors { public static MemberSelector selectorForProcessIds(ProcessId... processIds) { List processIdList = asList(processIds); return member -> { - ProcessId memberProcessId = fromKey(member.getStringAttribute(PROCESS_KEY.getKey())); + ProcessId memberProcessId = fromKey(member.getAttribute(PROCESS_KEY.getKey())); return processIdList.contains(memberProcessId); }; } diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/SharedHealthStateImplTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/SharedHealthStateImplTest.java index 41cd02d708e..fdd9b44bfc7 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/SharedHealthStateImplTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/SharedHealthStateImplTest.java @@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableSet; import java.util.HashMap; import java.util.Map; import java.util.Random; +import java.util.UUID; import java.util.stream.IntStream; import org.junit.Rule; import org.junit.Test; @@ -66,16 +67,16 @@ public class SharedHealthStateImplTest { @Test public void write_put_arg_into_map_sq_health_state_under_current_client_uuid() { NodeHealth nodeHealth = randomNodeHealth(); - Map map = new HashMap<>(); + Map map = new HashMap<>(); doReturn(map).when(hazelcastMember).getReplicatedMap(MAP_SQ_HEALTH_STATE); long clusterTime = random.nextLong(); - String uuid = randomAlphanumeric(5); + UUID uuid = UUID.randomUUID(); when(hazelcastMember.getUuid()).thenReturn(uuid); when(hazelcastMember.getClusterTime()).thenReturn(clusterTime); underTest.writeMine(nodeHealth); - assertThat(map.size()).isEqualTo(1); + assertThat(map).hasSize(1); assertThat(map.get(uuid)).isEqualTo(new TimestampedNodeHealth(nodeHealth, clusterTime)); assertThat(logging.getLogs()).isEmpty(); } @@ -87,7 +88,7 @@ public class SharedHealthStateImplTest { Map map = new HashMap<>(); map.put(randomAlphanumeric(4), new TimestampedNodeHealth(randomNodeHealth(), random.nextLong())); doReturn(new HashMap<>(map)).when(hazelcastMember).getReplicatedMap(MAP_SQ_HEALTH_STATE); - String uuid = randomAlphanumeric(5); + UUID uuid = UUID.randomUUID(); when(hazelcastMember.getUuid()).thenReturn(uuid); underTest.writeMine(newNodeHealth); @@ -99,15 +100,14 @@ public class SharedHealthStateImplTest { @Test public void readAll_returns_all_NodeHealth_in_map_sq_health_state_for_existing_client_uuids_aged_less_than_30_seconds() { NodeHealth[] nodeHealths = IntStream.range(0, 1 + random.nextInt(6)).mapToObj(i -> randomNodeHealth()).toArray(NodeHealth[]::new); - Map allNodeHealths = new HashMap<>(); - Map expected = new HashMap<>(); - String randomUuidBase = randomAlphanumeric(5); - for (int i = 0; i < nodeHealths.length; i++) { - String memberUuid = randomUuidBase + i; - TimestampedNodeHealth timestampedNodeHealth = new TimestampedNodeHealth(nodeHealths[i], clusterTime - random.nextInt(30 * 1000)); + Map allNodeHealths = new HashMap<>(); + Map expected = new HashMap<>(); + for (NodeHealth nodeHealth : nodeHealths) { + UUID memberUuid = UUID.randomUUID(); + TimestampedNodeHealth timestampedNodeHealth = new TimestampedNodeHealth(nodeHealth, clusterTime - random.nextInt(30 * 1000)); allNodeHealths.put(memberUuid, timestampedNodeHealth); if (random.nextBoolean()) { - expected.put(memberUuid, nodeHealths[i]); + expected.put(memberUuid, nodeHealth); } } doReturn(allNodeHealths).when(hazelcastMember).getReplicatedMap(MAP_SQ_HEALTH_STATE); @@ -122,8 +122,8 @@ public class SharedHealthStateImplTest { @Test public void readAll_ignores_NodeHealth_of_30_seconds_before_cluster_time() { NodeHealth nodeHealth = randomNodeHealth(); - Map map = new HashMap<>(); - String memberUuid = randomAlphanumeric(5); + Map map = new HashMap<>(); + UUID memberUuid = UUID.randomUUID(); TimestampedNodeHealth timestampedNodeHealth = new TimestampedNodeHealth(nodeHealth, clusterTime - 30 * 1000); map.put(memberUuid, timestampedNodeHealth); doReturn(map).when(hazelcastMember).getReplicatedMap(MAP_SQ_HEALTH_STATE); @@ -136,8 +136,8 @@ public class SharedHealthStateImplTest { @Test public void readAll_ignores_NodeHealth_of_more_than_30_seconds_before_cluster_time() { NodeHealth nodeHealth = randomNodeHealth(); - Map map = new HashMap<>(); - String memberUuid = randomAlphanumeric(5); + Map map = new HashMap<>(); + UUID memberUuid = UUID.randomUUID(); TimestampedNodeHealth timestampedNodeHealth = new TimestampedNodeHealth(nodeHealth, clusterTime - 30 * 1000 - random.nextInt(99)); map.put(memberUuid, timestampedNodeHealth); doReturn(map).when(hazelcastMember).getReplicatedMap(MAP_SQ_HEALTH_STATE); @@ -150,8 +150,8 @@ public class SharedHealthStateImplTest { @Test public void readAll_logs_map_sq_health_state_content_and_the_content_effectively_returned_if_TRACE() { logging.setLevel(Level.TRACE); - Map map = new HashMap<>(); - String uuid = randomAlphanumeric(44); + Map map = new HashMap<>(); + UUID uuid = UUID.randomUUID(); NodeHealth nodeHealth = randomNodeHealth(); map.put(uuid, new TimestampedNodeHealth(nodeHealth, clusterTime - 1)); when(hazelcastMember.getClusterTime()).thenReturn(clusterTime); @@ -188,9 +188,9 @@ public class SharedHealthStateImplTest { @Test public void readAll_logs_message_for_each_timed_out_NodeHealth_ignored_if_TRACE() { logging.setLevel(Level.TRACE); - Map map = new HashMap<>(); - String memberUuid1 = randomAlphanumeric(44); - String memberUuid2 = randomAlphanumeric(44); + Map map = new HashMap<>(); + UUID memberUuid1 = UUID.randomUUID(); + UUID memberUuid2 = UUID.randomUUID(); map.put(memberUuid1, new TimestampedNodeHealth(randomNodeHealth(), clusterTime - 30 * 1000)); map.put(memberUuid2, new TimestampedNodeHealth(randomNodeHealth(), clusterTime - 30 * 1000)); doReturn(map).when(hazelcastMember).getReplicatedMap(MAP_SQ_HEALTH_STATE); @@ -209,9 +209,9 @@ public class SharedHealthStateImplTest { @Test public void clearMine_clears_entry_into_map_sq_health_state_under_current_client_uuid() { - Map map = mock(Map.class); + Map map = mock(Map.class); doReturn(map).when(hazelcastMember).getReplicatedMap(MAP_SQ_HEALTH_STATE); - String uuid = randomAlphanumeric(5); + UUID uuid = UUID.randomUUID(); when(hazelcastMember.getUuid()).thenReturn(uuid); underTest.clearMine(); @@ -224,10 +224,10 @@ public class SharedHealthStateImplTest { @Test public void clearMine_logs_map_sq_health_state_and_current_client_uuid_if_TRACE() { logging.setLevel(Level.TRACE); - Map map = new HashMap<>(); - map.put(randomAlphanumeric(4), new TimestampedNodeHealth(randomNodeHealth(), random.nextLong())); + Map map = new HashMap<>(); + map.put(UUID.randomUUID(), new TimestampedNodeHealth(randomNodeHealth(), random.nextLong())); doReturn(map).when(hazelcastMember).getReplicatedMap(MAP_SQ_HEALTH_STATE); - String uuid = randomAlphanumeric(5); + UUID uuid = UUID.randomUUID(); when(hazelcastMember.getUuid()).thenReturn(uuid); underTest.clearMine(); diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/DistributedAnswerTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/DistributedAnswerTest.java index 191fa3be677..4562615320b 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/DistributedAnswerTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/DistributedAnswerTest.java @@ -19,8 +19,9 @@ */ package org.sonar.process.cluster.hz; -import com.hazelcast.core.Member; +import com.hazelcast.cluster.Member; import java.io.IOException; +import java.util.UUID; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -30,20 +31,19 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.NODE_NAME; - public class DistributedAnswerTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - private Member member = newMember("member1"); - private DistributedAnswer underTest = new DistributedAnswer(); + private final Member member = newMember(UUID.randomUUID()); + private final DistributedAnswer underTest = new DistributedAnswer<>(); @Test public void getMembers_return_all_members() { underTest.setAnswer(member, "foo"); - underTest.setTimedOut(newMember("bar")); - underTest.setFailed(newMember("baz"), new IOException("BOOM")); + underTest.setTimedOut(newMember(UUID.randomUUID())); + underTest.setFailed(newMember(UUID.randomUUID()), new IOException("BOOM")); assertThat(underTest.getMembers()).hasSize(3); } @@ -103,7 +103,7 @@ public class DistributedAnswerTest { @Test public void propagateExceptions_does_nothing_if_no_errors() { - underTest.setAnswer(newMember("foo"), "bar"); + underTest.setAnswer(newMember(UUID.randomUUID()), "bar"); // no errors underTest.propagateExceptions(); @@ -111,30 +111,36 @@ public class DistributedAnswerTest { @Test public void propagateExceptions_throws_ISE_if_at_least_one_timeout() { - underTest.setAnswer(newMember("bar"), "baz"); - underTest.setTimedOut(newMember("foo")); + UUID uuid = UUID.randomUUID(); + UUID otherUuid = UUID.randomUUID(); + + underTest.setAnswer(newMember(uuid), "baz"); + underTest.setTimedOut(newMember(otherUuid)); expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Distributed cluster action timed out in cluster nodes foo"); + expectedException.expectMessage("Distributed cluster action timed out in cluster nodes " + otherUuid); underTest.propagateExceptions(); } @Test public void propagateExceptions_throws_ISE_if_at_least_one_failure() { - underTest.setAnswer(newMember("bar"), "baz"); - underTest.setFailed(newMember("foo"), new IOException("BOOM")); + UUID foo = UUID.randomUUID(); + UUID bar = UUID.randomUUID(); + + underTest.setAnswer(newMember(bar), "baz"); + underTest.setFailed(newMember(foo), new IOException("BOOM")); expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Distributed cluster action in cluster nodes foo (other nodes may have timed out)"); + expectedException.expectMessage("Distributed cluster action in cluster nodes " + foo + " (other nodes may have timed out)"); underTest.propagateExceptions(); } - private static Member newMember(String uuid) { + private static Member newMember(UUID uuid) { Member member = mock(Member.class); when(member.getUuid()).thenReturn(uuid); - when(member.getStringAttribute(NODE_NAME.getKey())).thenReturn(uuid); + when(member.getAttribute(NODE_NAME.getKey())).thenReturn(uuid.toString()); return member; } } diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java index 2fc1df20d3c..ff730e80f51 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java @@ -24,7 +24,6 @@ import java.net.UnknownHostException; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Set; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -49,9 +48,9 @@ public class HazelcastMemberBuilderTest { public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60)); // use loopback for support of offline builds - private InetAddress loopback = InetAddress.getLoopbackAddress(); - private InetAdressResolver inetAdressResolver = mock(InetAdressResolver.class); - private HazelcastMemberBuilder underTest = new HazelcastMemberBuilder(inetAdressResolver); + private final InetAddress loopback = InetAddress.getLoopbackAddress(); + private final InetAdressResolver inetAdressResolver = mock(InetAdressResolver.class); + private final HazelcastMemberBuilder underTest = new HazelcastMemberBuilder(inetAdressResolver); @Before public void before() throws UnknownHostException { @@ -79,8 +78,8 @@ public class HazelcastMemberBuilderTest { .setNetworkInterface(loopback.getHostAddress()) .build(); - assertThat(member.getUuid()).isNotEmpty(); - assertThat(member.getClusterTime()).isGreaterThan(0); + assertThat(member.getUuid()).isNotNull(); + assertThat(member.getClusterTime()).isPositive(); assertThat(member.getCluster().getMembers()).hasSize(1); assertThat(member.getMemberUuids()).containsOnlyOnce(member.getUuid()); diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java index 11caec23c0f..039ccb3b440 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java @@ -19,8 +19,8 @@ */ package org.sonar.process.cluster.hz; +import com.hazelcast.cluster.Member; import com.hazelcast.cluster.memberselector.MemberSelectors; -import com.hazelcast.core.Member; import java.net.InetAddress; import java.util.Arrays; import java.util.List; diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java index cf16622889a..844130a829c 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java @@ -19,8 +19,8 @@ */ package org.sonar.process.cluster.hz; -import com.hazelcast.core.Member; -import com.hazelcast.core.MemberSelector; +import com.hazelcast.cluster.Member; +import com.hazelcast.cluster.MemberSelector; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -38,13 +38,13 @@ public class HazelcastMemberSelectorsTest { Member member = mock(Member.class); MemberSelector underTest = HazelcastMemberSelectors.selectorForProcessIds(COMPUTE_ENGINE); - when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(COMPUTE_ENGINE.getKey()); + when(member.getAttribute(PROCESS_KEY.getKey())).thenReturn(COMPUTE_ENGINE.getKey()); assertThat(underTest.select(member)).isTrue(); - when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(WEB_SERVER.getKey()); + when(member.getAttribute(PROCESS_KEY.getKey())).thenReturn(WEB_SERVER.getKey()); assertThat(underTest.select(member)).isFalse(); - when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey()); + when(member.getAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey()); assertThat(underTest.select(member)).isFalse(); } @@ -53,13 +53,13 @@ public class HazelcastMemberSelectorsTest { Member member = mock(Member.class); MemberSelector underTest = HazelcastMemberSelectors.selectorForProcessIds(WEB_SERVER, APP); - when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(COMPUTE_ENGINE.getKey()); + when(member.getAttribute(PROCESS_KEY.getKey())).thenReturn(COMPUTE_ENGINE.getKey()); assertThat(underTest.select(member)).isFalse(); - when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(WEB_SERVER.getKey()); + when(member.getAttribute(PROCESS_KEY.getKey())).thenReturn(WEB_SERVER.getKey()); assertThat(underTest.select(member)).isTrue(); - when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey()); + when(member.getAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey()); assertThat(underTest.select(member)).isTrue(); } } diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java index d2c45b8be67..d8db18f1d2a 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java @@ -19,8 +19,8 @@ */ package org.sonar.server.platform.monitoring.cluster; -import com.hazelcast.core.Member; -import com.hazelcast.core.MemberSelector; +import com.hazelcast.cluster.Member; +import com.hazelcast.cluster.MemberSelector; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -57,7 +57,7 @@ public class AppNodesInfoLoaderImpl implements AppNodesInfoLoader { MemberSelector memberSelector = HazelcastMemberSelectors.selectorForProcessIds(ProcessId.WEB_SERVER, ProcessId.COMPUTE_ENGINE); DistributedAnswer distributedAnswer = hzMember.call(ProcessInfoProvider::provide, memberSelector, DISTRIBUTED_TIMEOUT_MS); for (Member member : distributedAnswer.getMembers()) { - String nodeName = member.getStringAttribute(NODE_NAME.getKey()); + String nodeName = member.getAttribute(NODE_NAME.getKey()); NodeInfo nodeInfo = nodesByName.computeIfAbsent(nodeName, name -> { NodeInfo info = new NodeInfo(name); info.setHost(member.getAddress().getHost()); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImplTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImplTest.java index ec34e93e52e..d36ce91ee3a 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImplTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImplTest.java @@ -19,9 +19,9 @@ */ package org.sonar.server.platform.monitoring.cluster; -import com.hazelcast.core.Member; -import com.hazelcast.core.MemberSelector; -import com.hazelcast.nio.Address; +import com.hazelcast.cluster.Address; +import com.hazelcast.cluster.Member; +import com.hazelcast.cluster.MemberSelector; import java.io.IOException; import java.net.InetAddress; import java.util.Collection; @@ -41,7 +41,6 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - public class AppNodesInfoLoaderImplTest { private static final InetAddress AN_ADDRESS = InetAddress.getLoopbackAddress(); @@ -49,8 +48,8 @@ public class AppNodesInfoLoaderImplTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - private HazelcastMember hzMember = mock(HazelcastMember.class); - private AppNodesInfoLoaderImpl underTest = new AppNodesInfoLoaderImpl(hzMember); + private final HazelcastMember hzMember = mock(HazelcastMember.class); + private final AppNodesInfoLoaderImpl underTest = new AppNodesInfoLoaderImpl(hzMember); @Test public void load_info_from_all_nodes() throws Exception { @@ -90,7 +89,7 @@ public class AppNodesInfoLoaderImplTest { private Member newMember(String name) { Member member = mock(Member.class, Mockito.RETURNS_MOCKS); - when(member.getStringAttribute(HazelcastMember.Attribute.NODE_NAME.getKey())).thenReturn(name); + when(member.getAttribute(HazelcastMember.Attribute.NODE_NAME.getKey())).thenReturn(name); when(member.getAddress()).thenReturn(new Address(AN_ADDRESS, 6789)); return member; } -- 2.39.5