@@ -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' |
@@ -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<String> getWorkerUUIDs() { | |||
Set<String> connectedWorkerUUIDs = hazelcastMember.getMemberUuids(); | |||
Set<UUID> 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<String, Set<String>> getClusteredWorkerUUIDs() { | |||
private Map<UUID, Set<String>> getClusteredWorkerUUIDs() { | |||
return hazelcastMember.getReplicatedMap(WORKER_UUIDS); | |||
} | |||
} |
@@ -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<UUID, Set<String>> 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.<UUID, Set<String>>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.<UUID, Set<String>>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<String> connectedClients = new HashSet<>(); | |||
Map modifiableWorkerMap = new HashMap<>(); | |||
Set<UUID> connectedClients = new HashSet<>(); | |||
Map<UUID, Set<String>> 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.<UUID, Set<String>>getReplicatedMap(WORKER_UUIDS)).thenReturn(modifiableWorkerMap); | |||
CeWorkerFactory ceWorkerFactory = mock(CeWorkerFactory.class); | |||
Set<CeWorker> ceWorkers = Stream.of("a10", "a11").map(uuid -> { | |||
@@ -100,20 +109,19 @@ public class CeDistributedInformationImplTest { | |||
@Test | |||
public void stop_must_remove_local_workerUUIDs() { | |||
Set<String> connectedClients = new HashSet<>(); | |||
Set<UUID> connectedClients = new HashSet<>(); | |||
connectedClients.add(clientUUID1); | |||
connectedClients.add(clientUUID2); | |||
connectedClients.add(clientUUID3); | |||
Map modifiableWorkerMap = new HashMap(workerMap); | |||
Map<UUID, Set<String>> modifiableWorkerMap = new HashMap<>(workerMap); | |||
when(hzClientWrapper.getUuid()).thenReturn(clientUUID1); | |||
when(hzClientWrapper.getMemberUuids()).thenReturn(connectedClients); | |||
when(hzClientWrapper.getReplicatedMap(WORKER_UUIDS)).thenReturn(modifiableWorkerMap); | |||
when(hzClientWrapper.<UUID, Set<String>>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))); | |||
} | |||
} |
@@ -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; |
@@ -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<AppStateListener> listeners = new ArrayList<>(); | |||
private final Map<ProcessId, Boolean> operationalLocalProcesses = new EnumMap<>(ProcessId.class); | |||
private final ReplicatedMap<ClusterProcess, Boolean> 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<String> leader = hzMember.getAtomicReference(LEADER); | |||
IAtomicReference<UUID> leader = hzMember.getAtomicReference(LEADER); | |||
return leader.compareAndSet(null, hzMember.getUuid()); | |||
} | |||
@@ -159,9 +159,9 @@ public class ClusterAppStateImpl implements ClusterAppState { | |||
@Override | |||
public Optional<String> getLeaderHostName() { | |||
String leaderId = (String) hzMember.getAtomicReference(LEADER).get(); | |||
if (leaderId != null) { | |||
Optional<Member> leader = hzMember.getCluster().getMembers().stream().filter(m -> m.getUuid().equals(leaderId)).findFirst(); | |||
UUID leaderUuid = (UUID) hzMember.getAtomicReference(LEADER).get(); | |||
if (leaderUuid != null) { | |||
Optional<Member> 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<ClusterProcess, Boolean> 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()); |
@@ -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; | |||
} | |||
@@ -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<String> getMemberUuids() { | |||
public Set<UUID> getMemberUuids() { | |||
throw new IllegalStateException("not expected to be called"); | |||
} | |||
@@ -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<String> hostname = underTest.getLeaderHostName(); | |||
assertThat(hostname).isNotEmpty(); | |||
} | |||
} | |||
@Test | |||
public void return_null_if_node_is_not_leader() { | |||
try (ClusterAppStateImpl underTest = createClusterAppState()) { | |||
Optional<String> hostname = underTest.getLeaderHostName(); | |||
assertThat(hostname).isEmpty(); | |||
} | |||
} | |||
private ClusterAppStateImpl createClusterAppState() { | |||
return new ClusterAppStateImpl(new TestAppSettings(), newHzMember(), mock(EsConnector.class), mock(AppNodesClusterHostsConsistency.class)); | |||
} |
@@ -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)); | |||
} | |||
} |
@@ -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<String, TimestampedNodeHealth> sqHealthState = readReplicatedMap(); | |||
Map<UUID, TimestampedNodeHealth> 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<String, TimestampedNodeHealth> sqHealthState = readReplicatedMap(); | |||
String clientUUID = hzMember.getUuid(); | |||
Map<UUID, TimestampedNodeHealth> 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<NodeHealth> readAll() { | |||
long clusterTime = hzMember.getClusterTime(); | |||
long timeout = clusterTime - TIMEOUT_30_SECONDS; | |||
Map<String, TimestampedNodeHealth> sqHealthState = readReplicatedMap(); | |||
Set<String> hzMemberUUIDs = hzMember.getMemberUuids(); | |||
Map<UUID, TimestampedNodeHealth> sqHealthState = readReplicatedMap(); | |||
Set<UUID> hzMemberUUIDs = hzMember.getMemberUuids(); | |||
Set<NodeHealth> 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<Map.Entry<String, TimestampedNodeHealth>> outOfDate(long timeout) { | |||
private static Predicate<Map.Entry<UUID, TimestampedNodeHealth>> 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<Map.Entry<String, TimestampedNodeHealth>> ofNonExistentMember(Set<String> hzMemberUUIDs) { | |||
private static Predicate<Map.Entry<UUID, TimestampedNodeHealth>> ofNonExistentMember(Set<UUID> hzMemberUUIDs) { | |||
return entry -> { | |||
boolean res = hzMemberUUIDs.contains(entry.getKey()); | |||
if (!res) { | |||
@@ -104,7 +105,7 @@ public class SharedHealthStateImpl implements SharedHealthState { | |||
}; | |||
} | |||
private Map<String, TimestampedNodeHealth> readReplicatedMap() { | |||
private Map<UUID, TimestampedNodeHealth> readReplicatedMap() { | |||
return hzMember.getReplicatedMap(HazelcastObjects.SQ_HEALTH_STATE); | |||
} | |||
@@ -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<T> { | |||
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<T> { | |||
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); | |||
} |
@@ -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 |
@@ -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. | |||
*/ | |||
<K, V> Map<K, V> 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<String> getMemberUuids(); | |||
Set<UUID> getMemberUuids(); | |||
/** | |||
* Gets lock among the cluster, identified by name |
@@ -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<String> 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)); | |||
} |
@@ -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 <E> IAtomicReference<E> 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<String> getMemberUuids() { | |||
public Set<UUID> 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 |
@@ -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<ProcessId> 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); | |||
}; | |||
} |
@@ -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<String, TimestampedNodeHealth> map = new HashMap<>(); | |||
Map<UUID, TimestampedNodeHealth> 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<String, TimestampedNodeHealth> 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<String, TimestampedNodeHealth> allNodeHealths = new HashMap<>(); | |||
Map<String, NodeHealth> 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<UUID, TimestampedNodeHealth> allNodeHealths = new HashMap<>(); | |||
Map<UUID, NodeHealth> 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<String, TimestampedNodeHealth> map = new HashMap<>(); | |||
String memberUuid = randomAlphanumeric(5); | |||
Map<UUID, TimestampedNodeHealth> 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<String, TimestampedNodeHealth> map = new HashMap<>(); | |||
String memberUuid = randomAlphanumeric(5); | |||
Map<UUID, TimestampedNodeHealth> 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<String, TimestampedNodeHealth> map = new HashMap<>(); | |||
String uuid = randomAlphanumeric(44); | |||
Map<UUID, TimestampedNodeHealth> 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<String, TimestampedNodeHealth> map = new HashMap<>(); | |||
String memberUuid1 = randomAlphanumeric(44); | |||
String memberUuid2 = randomAlphanumeric(44); | |||
Map<UUID, TimestampedNodeHealth> 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<String, TimestampedNodeHealth> map = mock(Map.class); | |||
Map<UUID, TimestampedNodeHealth> 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<String, TimestampedNodeHealth> map = new HashMap<>(); | |||
map.put(randomAlphanumeric(4), new TimestampedNodeHealth(randomNodeHealth(), random.nextLong())); | |||
Map<UUID, TimestampedNodeHealth> 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(); |
@@ -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<String> 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; | |||
} | |||
} |
@@ -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()); | |||
@@ -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; |
@@ -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(); | |||
} | |||
} |
@@ -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<ProtobufSystemInfo.SystemInfo> 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()); |
@@ -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; | |||
} |