use of com.hazelcast.instance.EndpointQualifier in project hazelcast by hazelcast.
the class ClusterDataSerializationTest method testSerializationOf_memberInfo.
@Test
public void testSerializationOf_memberInfo() throws UnknownHostException {
Address memberAddress = new Address("127.0.0.1", 5071);
Address clientAddress = new Address("127.0.0.1", 7654);
Address restAddress = new Address("127.0.0.1", 8080);
// member attributes, test an integer, a String and an IdentifiedDataSerializable as values
Map<String, String> attributes = new HashMap<>();
attributes.put("a", "2");
attributes.put("b", "b");
Map<EndpointQualifier, Address> addressMap = new HashMap<EndpointQualifier, Address>();
addressMap.put(MEMBER, memberAddress);
addressMap.put(CLIENT, clientAddress);
addressMap.put(REST, restAddress);
MemberInfo memberInfo = new MemberInfo(memberAddress, UUID.randomUUID(), attributes, false, MemberVersion.of(BuildInfoProvider.getBuildInfo().getVersion()), addressMap);
Data serialized = SERIALIZATION_SERVICE.toData(memberInfo);
MemberInfo deserialized = SERIALIZATION_SERVICE.toObject(serialized);
assertEquals(deserialized.getAddress(), memberInfo.getAddress());
assertEquals(deserialized.getVersion(), memberInfo.getVersion());
assertEquals(deserialized.getUuid(), memberInfo.getUuid());
assertEquals(deserialized.getAttributes().get("a"), memberInfo.getAttributes().get("a"));
assertEquals(deserialized.getAttributes().get("b"), memberInfo.getAttributes().get("b"));
assertEquals(3, deserialized.getAddressMap().size());
assertEquals(memberAddress, deserialized.getAddressMap().get(MEMBER));
assertEquals(clientAddress, deserialized.getAddressMap().get(CLIENT));
assertEquals(restAddress, deserialized.getAddressMap().get(REST));
}
use of com.hazelcast.instance.EndpointQualifier in project hazelcast by hazelcast.
the class MemberStateImplTest method testSerialization.
@Test
public void testSerialization() throws UnknownHostException {
HazelcastInstance hazelcastInstance = createHazelcastInstance();
LocalReplicatedMapStatsImpl replicatedMapStats = new LocalReplicatedMapStatsImpl();
replicatedMapStats.incrementPutsNanos(30);
CacheStatisticsImpl cacheStatistics = new CacheStatisticsImpl(Clock.currentTimeMillis());
cacheStatistics.increaseCacheHits(5);
UUID clientUuid = UUID.randomUUID();
Collection<ClientEndPointDTO> clients = new ArrayList<>();
ClientEndPointDTO client = new ClientEndPointDTO();
client.uuid = clientUuid;
client.address = "localhost";
client.clientType = "undefined";
client.name = "aClient";
client.labels = new HashSet<>(Collections.singletonList("label"));
client.ipAddress = "10.176.167.34";
client.canonicalHostName = "ip-10-176-167-34.ec2.internal";
clients.add(client);
ClusterState clusterState = ClusterState.ACTIVE;
com.hazelcast.instance.impl.NodeState nodeState = com.hazelcast.instance.impl.NodeState.PASSIVE;
Version clusterVersion = Version.of("3.9.0");
MemberVersion memberVersion = MemberVersion.of("3.8.0");
NodeState state = new NodeStateImpl(clusterState, nodeState, clusterVersion, memberVersion);
final BackupTaskStatus backupTaskStatus = new BackupTaskStatus(BackupTaskState.IN_PROGRESS, 5, 10);
final String backupDirectory = "/hot/backup/dir";
final HotRestartStateImpl hotRestartState = new HotRestartStateImpl(backupTaskStatus, true, backupDirectory);
Map<UUID, String> clientStats = new HashMap<>();
clientStats.put(clientUuid, "someStats");
Map<EndpointQualifier, Address> endpoints = new HashMap<>();
endpoints.put(EndpointQualifier.MEMBER, new Address("127.0.0.1", 5701));
endpoints.put(EndpointQualifier.resolve(ProtocolType.WAN, "MyWAN"), new Address("127.0.0.1", 5901));
TimedMemberStateFactory factory = new TimedMemberStateFactory(getHazelcastInstanceImpl(hazelcastInstance));
TimedMemberState timedMemberState = factory.createTimedMemberState();
MemberStateImpl memberState = timedMemberState.getMemberState();
memberState.setAddress("memberStateAddress:Port");
UUID uuid = UUID.randomUUID();
memberState.setUuid(uuid);
UUID cpMemberUuid = UUID.randomUUID();
memberState.setCpMemberUuid(cpMemberUuid);
memberState.setEndpoints(endpoints);
memberState.setMapsWithStats(singleton("map-1"));
memberState.setMultiMapsWithStats(singleton("multiMap-1"));
memberState.setReplicatedMapsWithStats(singleton("replicatedMap-1"));
memberState.setQueuesWithStats(singleton("queue-1"));
memberState.setTopicsWithStats(singleton("topic-1"));
memberState.setReliableTopicsWithStats(singleton("reliableTopic-1"));
memberState.setPNCountersWithStats(singleton("pnCounter-1"));
memberState.setExecutorsWithStats(singleton("executor-1"));
memberState.setCachesWithStats(singleton("cache-1"));
memberState.setFlakeIdGeneratorsWithStats(singleton("flakeIdGenerator-1"));
memberState.setOperationStats(new LocalOperationStatsImpl());
memberState.setClients(clients);
memberState.setNodeState(state);
memberState.setHotRestartState(hotRestartState);
memberState.setClientStats(clientStats);
MemberStateImpl deserialized = new MemberStateImpl();
deserialized.fromJson(memberState.toJson());
assertEquals("memberStateAddress:Port", deserialized.getAddress());
assertEquals(uuid, deserialized.getUuid());
assertEquals(cpMemberUuid, deserialized.getCpMemberUuid());
assertEquals(endpoints, deserialized.getEndpoints());
assertNotNull(deserialized.getName());
assertEquals(deserialized.getName(), memberState.getName());
assertEquals(singleton("map-1"), deserialized.getMapsWithStats());
assertEquals(singleton("multiMap-1"), deserialized.getMultiMapsWithStats());
assertEquals(singleton("replicatedMap-1"), deserialized.getReplicatedMapsWithStats());
assertEquals(singleton("queue-1"), deserialized.getQueuesWithStats());
assertEquals(singleton("topic-1"), deserialized.getTopicsWithStats());
assertEquals(singleton("reliableTopic-1"), deserialized.getReliableTopicsWithStats());
assertEquals(singleton("pnCounter-1"), deserialized.getPNCountersWithStats());
assertEquals(singleton("executor-1"), deserialized.getExecutorsWithStats());
assertEquals(singleton("cache-1"), deserialized.getCachesWithStats());
assertEquals(singleton("flakeIdGenerator-1"), deserialized.getFlakeIdGeneratorsWithStats());
assertNotNull(deserialized.getOperationStats());
client = deserialized.getClients().iterator().next();
assertEquals(clientUuid, client.uuid);
assertEquals("localhost", client.address);
assertEquals("undefined", client.clientType);
assertEquals("aClient", client.name);
assertContains(client.labels, "label");
assertEquals("10.176.167.34", client.ipAddress);
assertEquals("ip-10-176-167-34.ec2.internal", client.canonicalHostName);
NodeState deserializedState = deserialized.getNodeState();
assertEquals(clusterState, deserializedState.getClusterState());
assertEquals(nodeState, deserializedState.getNodeState());
assertEquals(clusterVersion, deserializedState.getClusterVersion());
assertEquals(memberVersion, deserializedState.getMemberVersion());
final HotRestartState deserializedHotRestartState = deserialized.getHotRestartState();
assertTrue(deserializedHotRestartState.isHotBackupEnabled());
assertEquals(backupTaskStatus, deserializedHotRestartState.getBackupTaskStatus());
assertEquals(backupDirectory, deserializedHotRestartState.getBackupDirectory());
ClusterHotRestartStatusDTO clusterHotRestartStatus = deserialized.getClusterHotRestartStatus();
assertEquals(FULL_RECOVERY_ONLY, clusterHotRestartStatus.getDataRecoveryPolicy());
assertEquals(ClusterHotRestartStatusDTO.ClusterHotRestartStatus.UNKNOWN, clusterHotRestartStatus.getHotRestartStatus());
assertEquals(-1, clusterHotRestartStatus.getRemainingValidationTimeMillis());
assertEquals(-1, clusterHotRestartStatus.getRemainingDataLoadTimeMillis());
assertTrue(clusterHotRestartStatus.getMemberHotRestartStatusMap().isEmpty());
Map<UUID, String> deserializedClientStats = deserialized.getClientStats();
assertEquals("someStats", deserializedClientStats.get(clientUuid));
}
use of com.hazelcast.instance.EndpointQualifier in project hazelcast by hazelcast.
the class AdvancedNetworkConfig method setEndpointConfigs.
public AdvancedNetworkConfig setEndpointConfigs(Map<EndpointQualifier, EndpointConfig> endpointConfigs) {
// sanitize input
for (Map.Entry<EndpointQualifier, EndpointConfig> entry : endpointConfigs.entrySet()) {
entry.getValue().setProtocolType(entry.getKey().getType());
}
// validate
for (ProtocolType protocolType : ProtocolType.values()) {
int count = countEndpointConfigs(endpointConfigs, protocolType);
if (count > protocolType.getServerSocketCardinality()) {
throw new InvalidConfigurationException("Protocol type " + protocolType + " does not allow more than " + protocolType.getServerSocketCardinality() + " server sockets but " + count + " were defined");
}
}
this.endpointConfigs.clear();
this.endpointConfigs.putAll(endpointConfigs);
return this;
}
use of com.hazelcast.instance.EndpointQualifier in project hazelcast by hazelcast.
the class MemberStateImpl method toJson.
@Override
public JsonObject toJson() {
final JsonObject root = new JsonObject();
root.add("address", address);
String uuidString = uuid != null ? uuid.toString() : null;
root.add("uuid", uuidString);
String cpMemberUuidString = cpMemberUuid != null ? cpMemberUuid.toString() : null;
root.add("cpMemberUuid", cpMemberUuidString);
root.add("name", name);
final JsonArray endpoints = new JsonArray();
for (Entry<EndpointQualifier, Address> entry : this.endpoints.entrySet()) {
JsonObject address = new JsonObject();
address.set("host", entry.getValue().getHost());
address.set("port", entry.getValue().getPort());
JsonObject endpoint = new JsonObject();
endpoint.set("protocol", entry.getKey().getType().name());
endpoint.set("address", address);
if (entry.getKey().getIdentifier() != null) {
endpoint.set("id", entry.getKey().getIdentifier());
}
endpoints.add(endpoint);
}
root.add("endpoints", endpoints);
serializeAsMap(root, "mapStats", mapsWithStats);
serializeAsMap(root, "multiMapStats", multiMapsWithStats);
serializeAsMap(root, "replicatedMapStats", replicatedMapsWithStats);
serializeAsMap(root, "queueStats", queuesWithStats);
serializeAsMap(root, "topicStats", topicsWithStats);
serializeAsMap(root, "reliableTopicStats", reliableTopicsWithStats);
serializeAsMap(root, "pnCounterStats", pnCountersWithStats);
serializeAsMap(root, "executorStats", executorsWithStats);
serializeAsMap(root, "scheduledExecutorStats", scheduledExecutorsWithStats);
serializeAsMap(root, "durableExecutorStats", durableExecutorsWithStats);
serializeAsMap(root, "cacheStats", cachesWithStats);
serializeAsMap(root, "flakeIdStats", flakeIdGeneratorsWithStats);
serializeMap(root, "wanStats", wanStats);
final JsonArray clientsArray = new JsonArray();
for (ClientEndPointDTO client : clients) {
clientsArray.add(client.toJson());
}
root.add("clients", clientsArray);
addJsonIfSerializable(root, "operationStats", operationStats);
root.add("memberPartitionState", memberPartitionState.toJson());
root.add("nodeState", nodeState.toJson());
root.add("hotRestartState", hotRestartState.toJson());
root.add("clusterHotRestartStatus", clusterHotRestartStatus.toJson());
JsonObject clientStatsObject = new JsonObject();
for (Map.Entry<UUID, String> entry : clientStats.entrySet()) {
clientStatsObject.add(entry.getKey().toString(), entry.getValue());
}
root.add("clientStats", clientStatsObject);
return root;
}
use of com.hazelcast.instance.EndpointQualifier in project hazelcast by hazelcast.
the class LocalAddressRegistry method registerLocalAddresses.
private void registerLocalAddresses(UUID thisUuid, AddressPicker addressPicker) {
LinkedAddresses addresses = LinkedAddresses.getResolvedAddresses(addressPicker.getPublicAddress(EndpointQualifier.MEMBER));
for (Map.Entry<EndpointQualifier, Address> addressEntry : addressPicker.getBindAddressMap().entrySet()) {
addresses.addAllResolvedAddresses(addressPicker.getPublicAddress(addressEntry.getKey()));
addresses.addAllResolvedAddresses(addressEntry.getValue());
ServerSocketChannel serverSocketChannel = addressPicker.getServerSocketChannel(addressEntry.getKey());
if (serverSocketChannel != null && serverSocketChannel.socket().getInetAddress().isAnyLocalAddress()) {
int port = addressEntry.getValue().getPort();
try {
Collections.list(NetworkInterface.getNetworkInterfaces()).forEach(networkInterface -> Collections.list(networkInterface.getInetAddresses()).forEach(inetAddress -> addresses.addAllResolvedAddresses(new Address(inetAddress, port))));
} catch (SocketException e) {
ignore(e);
}
}
localUuid = thisUuid;
localAddresses = addresses;
}
if (logger.isFineEnabled()) {
logger.fine(localAddresses + " are registered for the local member with local uuid=" + localUuid);
}
}
Aggregations