use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.
the class ClientCacheHelperTest method testEnableStatisticManagementOnNodes_sneakyThrowsException.
@Test(expected = IllegalArgumentException.class)
public void testEnableStatisticManagementOnNodes_sneakyThrowsException() {
Member member = mock(Member.class);
when(member.getUuid()).thenThrow(new IllegalArgumentException("expected"));
Collection<Member> members = singletonList(member);
when(exceptionThrowingClient.getClientClusterService().getMemberList()).thenReturn(members);
enableStatisticManagementOnNodes(exceptionThrowingClient, CACHE_NAME, false, false);
}
use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.
the class SqlErrorAbstractTest method newHazelcastInstance.
/**
* Start the new Hazelcast instance.
*
* @param awaitAssignment whether to wait for a partition assignment to a new member
* @return created instance
*/
protected HazelcastInstance newHazelcastInstance(boolean awaitAssignment) {
HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
if (awaitAssignment) {
assertTrueEventually(() -> {
Set<UUID> memberIds = new HashSet<>();
for (Member member : instance.getCluster().getMembers()) {
memberIds.add(member.getUuid());
}
PartitionService partitionService = instance.getPartitionService();
Set<UUID> assignedMemberIds = new HashSet<>();
for (Partition partition : partitionService.getPartitions()) {
Member owner = partition.getOwner();
assertNotNull(owner);
assignedMemberIds.add(owner.getUuid());
}
assertEquals(memberIds, assignedMemberIds);
});
}
return instance;
}
use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.
the class ClusterViewListenerService method getPartitions.
/**
* If any partition does not have an owner, this method returns empty collection
*
* @param partitionTableView will be converted to address->partitions mapping
* @return address->partitions mapping, where address is the client address of the member
*/
public Map<UUID, List<Integer>> getPartitions(PartitionTableView partitionTableView) {
Map<UUID, List<Integer>> partitionsMap = new HashMap<>();
int partitionCount = partitionTableView.length();
for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
PartitionReplica owner = partitionTableView.getReplica(partitionId, 0);
if (owner == null || owner.uuid() == null) {
partitionsMap.clear();
return partitionsMap;
}
partitionsMap.computeIfAbsent(owner.uuid(), k -> new LinkedList<>()).add(partitionId);
}
return partitionsMap;
}
use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.
the class TcpClientConnectionManager method getRandomConnection.
@Override
public ClientConnection getRandomConnection() {
// Try getting the connection from the load balancer, if smart routing is enabled
if (isSmartRoutingEnabled) {
Member member = loadBalancer.next();
// Failed to get a member
ClientConnection connection = member != null ? activeConnections.get(member.getUuid()) : null;
if (connection != null) {
return connection;
}
}
// Otherwise iterate over connections and return the first one
for (Map.Entry<UUID, TcpClientConnection> connectionEntry : activeConnections.entrySet()) {
return connectionEntry.getValue();
}
// Failed to get a connection
return null;
}
use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.
the class TcpClientConnectionManager method doConnectToCandidateCluster.
private boolean doConnectToCandidateCluster(CandidateClusterContext context, boolean switchingToNextCluster) {
Set<Address> triedAddresses = new HashSet<>();
try {
waitStrategy.reset();
do {
Set<Address> triedAddressesPerAttempt = new HashSet<>();
List<Member> memberList = new ArrayList<>(client.getClientClusterService().getMemberList());
if (shuffleMemberList) {
Collections.shuffle(memberList);
}
// try to connect to a member in the member list first
for (Member member : memberList) {
checkClientActive();
triedAddressesPerAttempt.add(member.getAddress());
Connection connection = connect(member, o -> getOrConnectToMember((Member) o, switchingToNextCluster));
if (connection != null) {
return true;
}
}
// try to connect to a member given via config(explicit config/discovery mechanisms)
for (Address address : getPossibleMemberAddresses(context.getAddressProvider())) {
checkClientActive();
if (!triedAddressesPerAttempt.add(address)) {
// if we can not add it means that it is already tried to be connected with the member list
continue;
}
Connection connection = connect(address, o -> getOrConnectToAddress((Address) o, switchingToNextCluster));
if (connection != null) {
return true;
}
}
triedAddresses.addAll(triedAddressesPerAttempt);
// and the lifecycle check is missing, hence we need to repeat the same check at this point.
if (triedAddressesPerAttempt.isEmpty()) {
checkClientActive();
}
} while (waitStrategy.sleep());
} catch (ClientNotAllowedInClusterException | InvalidConfigurationException e) {
logger.warning("Stopped trying on the cluster: " + context.getClusterName() + " reason: " + e.getMessage());
}
logger.info("Unable to connect to any address from the cluster with name: " + context.getClusterName() + ". The following addresses were tried: " + triedAddresses);
return false;
}
Aggregations