Search in sources :

Example 16 with EndpointQualifier

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));
}
Also used : Address(com.hazelcast.cluster.Address) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) HashMap(java.util.HashMap) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) Data(com.hazelcast.internal.serialization.Data) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with EndpointQualifier

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));
}
Also used : NodeState(com.hazelcast.internal.monitor.NodeState) Address(com.hazelcast.cluster.Address) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) MemberVersion(com.hazelcast.version.MemberVersion) Version(com.hazelcast.version.Version) MemberVersion(com.hazelcast.version.MemberVersion) UUID(java.util.UUID) ClusterHotRestartStatusDTO(com.hazelcast.internal.management.dto.ClusterHotRestartStatusDTO) TimedMemberState(com.hazelcast.internal.management.TimedMemberState) ClusterState(com.hazelcast.cluster.ClusterState) TimedMemberStateFactory(com.hazelcast.internal.management.TimedMemberStateFactory) ClientEndPointDTO(com.hazelcast.internal.management.dto.ClientEndPointDTO) CacheStatisticsImpl(com.hazelcast.cache.impl.CacheStatisticsImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) BackupTaskStatus(com.hazelcast.persistence.BackupTaskStatus) HotRestartState(com.hazelcast.internal.monitor.HotRestartState) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with EndpointQualifier

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;
}
Also used : ProtocolType(com.hazelcast.instance.ProtocolType) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 19 with EndpointQualifier

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;
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) Address(com.hazelcast.cluster.Address) ClientEndPointDTO(com.hazelcast.internal.management.dto.ClientEndPointDTO) JsonObject(com.hazelcast.internal.json.JsonObject) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) JsonUtil.getString(com.hazelcast.internal.util.JsonUtil.getString) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap)

Example 20 with EndpointQualifier

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);
    }
}
Also used : Address(com.hazelcast.cluster.Address) Iterator(java.util.Iterator) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) AddressPicker(com.hazelcast.instance.AddressPicker) NetworkInterface(java.net.NetworkInterface) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UUID(java.util.UUID) Node(com.hazelcast.instance.impl.Node) ServerSocketChannel(java.nio.channels.ServerSocketChannel) ConcurrentMap(java.util.concurrent.ConcurrentMap) SocketException(java.net.SocketException) ILogger(com.hazelcast.logging.ILogger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmptyStatement.ignore(com.hazelcast.internal.util.EmptyStatement.ignore) Map(java.util.Map) Nonnull(javax.annotation.Nonnull) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) SocketException(java.net.SocketException) Address(com.hazelcast.cluster.Address) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ServerSocketChannel(java.nio.channels.ServerSocketChannel)

Aggregations

EndpointQualifier (com.hazelcast.instance.EndpointQualifier)22 Address (com.hazelcast.cluster.Address)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 EndpointConfig (com.hazelcast.config.EndpointConfig)5 HashMap (java.util.HashMap)5 UUID (java.util.UUID)5 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)3 ProtocolType (com.hazelcast.instance.ProtocolType)3 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)3 ClientEndPointDTO (com.hazelcast.internal.management.dto.ClientEndPointDTO)3 Map (java.util.Map)3 AdvancedNetworkConfig (com.hazelcast.config.AdvancedNetworkConfig)2 ServerSocketEndpointConfig (com.hazelcast.config.ServerSocketEndpointConfig)2 ClusterHotRestartStatusDTO (com.hazelcast.internal.management.dto.ClusterHotRestartStatusDTO)2 MemberVersion (com.hazelcast.version.MemberVersion)2 Version (com.hazelcast.version.Version)2 InetSocketAddress (java.net.InetSocketAddress)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2