Search in sources :

Example 1 with ProtocolType

use of com.hazelcast.instance.ProtocolType in project hazelcast by hazelcast.

the class MemberHandshake method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    schemaVersion = in.readByte();
    targetAddress = in.readObject();
    reply = in.readBoolean();
    uuid = readUUID(in);
    int size = in.readInt();
    if (size == 0) {
        localAddresses = Collections.emptyMap();
    } else {
        Map<ProtocolType, Collection<Address>> addressesPerProtocolType = new EnumMap<>(ProtocolType.class);
        for (int i = 0; i < size; i++) {
            ProtocolType protocolType = ProtocolType.valueOf(in.readInt());
            Collection<Address> addresses = readCollection(in);
            addressesPerProtocolType.put(protocolType, addresses);
        }
        this.localAddresses = addressesPerProtocolType;
    }
    if (schemaVersion > SCHEMA_VERSION_1) {
        int optionsSize = in.readInt();
        for (int k = 0; k < optionsSize; k++) {
            options.put(in.readString(), in.readString());
        }
    }
}
Also used : Address(com.hazelcast.cluster.Address) ProtocolType(com.hazelcast.instance.ProtocolType) SerializationUtil.readCollection(com.hazelcast.internal.serialization.impl.SerializationUtil.readCollection) Collection(java.util.Collection) SerializationUtil.writeCollection(com.hazelcast.internal.serialization.impl.SerializationUtil.writeCollection) EnumMap(java.util.EnumMap)

Example 2 with ProtocolType

use of com.hazelcast.instance.ProtocolType in project hazelcast by hazelcast.

the class MemberStateImpl method fromJson.

@Override
@SuppressWarnings({ "checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity", "checkstyle:methodlength" })
public void fromJson(JsonObject json) {
    address = getString(json, "address");
    String uuidString = getString(json, "uuid", null);
    uuid = uuidString != null ? UUID.fromString(uuidString) : null;
    String cpMemberUuidString = getString(json, "cpMemberUuid", null);
    cpMemberUuid = cpMemberUuidString != null ? UUID.fromString(cpMemberUuidString) : null;
    name = getString(json, "name", null);
    JsonArray jsonEndpoints = getArray(json, "endpoints");
    endpoints = new HashMap<>();
    for (JsonValue obj : jsonEndpoints) {
        JsonObject endpoint = obj.asObject();
        String id = endpoint.getString("id", null);
        ProtocolType type = ProtocolType.valueOf(endpoint.getString("protocol", "MEMBER"));
        JsonValue addr = endpoint.get("address");
        String host = addr.asObject().getString("host", "");
        int port = addr.asObject().getInt("port", 0);
        EndpointQualifier qualifier = EndpointQualifier.resolve(type, id);
        Address address = null;
        try {
            address = new Address(host, port);
        } catch (UnknownHostException e) {
            // ignore
            ignore(e);
        }
        endpoints.put(qualifier, address);
    }
    mapsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "mapStats")) {
        mapsWithStats.add(next.getName());
    }
    multiMapsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "multiMapStats")) {
        multiMapsWithStats.add(next.getName());
    }
    replicatedMapsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "replicatedMapStats")) {
        replicatedMapsWithStats.add(next.getName());
    }
    queuesWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "queueStats")) {
        queuesWithStats.add(next.getName());
    }
    topicsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "topicStats")) {
        topicsWithStats.add(next.getName());
    }
    reliableTopicsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "reliableTopicStats")) {
        reliableTopicsWithStats.add(next.getName());
    }
    pnCountersWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "pnCounterStats")) {
        pnCountersWithStats.add(next.getName());
    }
    executorsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "executorStats")) {
        executorsWithStats.add(next.getName());
    }
    scheduledExecutorsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "scheduledExecutorStats")) {
        scheduledExecutorsWithStats.add(next.getName());
    }
    durableExecutorsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "durableExecutorStats")) {
        durableExecutorsWithStats.add(next.getName());
    }
    cachesWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "cacheStats")) {
        cachesWithStats.add(next.getName());
    }
    flakeIdGeneratorsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "flakeIdStats")) {
        flakeIdGeneratorsWithStats.add(next.getName());
    }
    for (JsonObject.Member next : getObject(json, "wanStats", new JsonObject())) {
        putDeserializedIfSerializable(wanStats, next.getName(), next.getValue().asObject(), new LocalWanStatsImpl());
    }
    JsonArray jsonClients = getArray(json, "clients");
    clients = new ArrayList<>();
    for (JsonValue jsonClient : jsonClients) {
        final ClientEndPointDTO client = new ClientEndPointDTO();
        client.fromJson(jsonClient.asObject());
        clients.add(client);
    }
    JsonObject jsonOperationStats = getObject(json, "operationStats", null);
    if (jsonOperationStats != null) {
        operationStats = readJsonIfDeserializable(jsonOperationStats, operationStats);
    }
    JsonObject jsonMemberPartitionState = getObject(json, "memberPartitionState", null);
    if (jsonMemberPartitionState != null) {
        memberPartitionState = new MemberPartitionStateImpl();
        memberPartitionState.fromJson(jsonMemberPartitionState);
    }
    JsonObject jsonNodeState = getObject(json, "nodeState", null);
    if (jsonNodeState != null) {
        nodeState = new NodeStateImpl();
        nodeState.fromJson(jsonNodeState);
    }
    JsonObject jsonHotRestartState = getObject(json, "hotRestartState", null);
    if (jsonHotRestartState != null) {
        hotRestartState = new HotRestartStateImpl();
        hotRestartState.fromJson(jsonHotRestartState);
    }
    JsonObject jsonClusterHotRestartStatus = getObject(json, "clusterHotRestartStatus", null);
    if (jsonClusterHotRestartStatus != null) {
        clusterHotRestartStatus = new ClusterHotRestartStatusDTO();
        clusterHotRestartStatus.fromJson(jsonClusterHotRestartStatus);
    }
    clientStats = new HashMap<>();
    for (JsonObject.Member next : getObject(json, "clientStats")) {
        clientStats.put(UUID.fromString(next.getName()), next.getValue().asString());
    }
}
Also used : Address(com.hazelcast.cluster.Address) UnknownHostException(java.net.UnknownHostException) ClientEndPointDTO(com.hazelcast.internal.management.dto.ClientEndPointDTO) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) JsonUtil.getString(com.hazelcast.internal.util.JsonUtil.getString) JsonArray(com.hazelcast.internal.json.JsonArray) ProtocolType(com.hazelcast.instance.ProtocolType) ClusterHotRestartStatusDTO(com.hazelcast.internal.management.dto.ClusterHotRestartStatusDTO)

Example 3 with ProtocolType

use of com.hazelcast.instance.ProtocolType in project hazelcast by hazelcast.

the class TcpServerControl method process.

private synchronized void process(TcpServerConnection connection, MemberHandshake handshake) {
    if (logger.isFinestEnabled()) {
        logger.finest("Handshake " + connection + ", complete message is " + handshake);
    }
    Map<ProtocolType, Collection<Address>> remoteAddressesPerProtocolType = handshake.getLocalAddresses();
    List<Address> allAliases = new ArrayList<>();
    // public address in address registration phase
    if (supportedProtocolTypes.contains(ProtocolType.MEMBER) && remoteAddressesPerProtocolType.containsKey(ProtocolType.MEMBER)) {
        allAliases.addAll(remoteAddressesPerProtocolType.remove(ProtocolType.MEMBER));
    }
    for (Map.Entry<ProtocolType, Collection<Address>> remoteAddresses : remoteAddressesPerProtocolType.entrySet()) {
        if (supportedProtocolTypes.contains(remoteAddresses.getKey())) {
            allAliases.addAll(remoteAddresses.getValue());
        }
    }
    // key 192.168.1.1:5701.
    assert (connectionManager.getEndpointQualifier() != EndpointQualifier.MEMBER || connection.getConnectionType().equals(ConnectionType.MEMBER)) : "When handling MEMBER connections, connection type" + " must be already set";
    boolean isMemberConnection = (connection.getConnectionType().equals(ConnectionType.MEMBER) && (connectionManager.getEndpointQualifier() == EndpointQualifier.MEMBER || unifiedEndpointManager));
    boolean mustRegisterRemoteSocketAddress = !handshake.isReply();
    Address remoteEndpoint = null;
    if (isMemberConnection) {
        // address of the target member will be set correctly in TcpIpConnection.setEndpoint.
        if (mustRegisterRemoteSocketAddress) {
            allAliases.add(new Address(connection.getRemoteSocketAddress()));
        }
    } else {
        // when not a member connection, register the remote socket address
        remoteEndpoint = new Address(connection.getRemoteSocketAddress());
    }
    process0(connection, remoteEndpoint, allAliases, handshake);
}
Also used : Address(com.hazelcast.cluster.Address) ProtocolType(com.hazelcast.instance.ProtocolType) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Map(java.util.Map)

Example 4 with ProtocolType

use of com.hazelcast.instance.ProtocolType in project hazelcast by hazelcast.

the class ConfigValidator method checkAdvancedNetworkConfig.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity", "checkstyle:booleanexpressioncomplexity" })
public static void checkAdvancedNetworkConfig(Config config) {
    if (!config.getAdvancedNetworkConfig().isEnabled()) {
        return;
    }
    EnumMap<ProtocolType, MutableInteger> serverSocketsPerProtocolType = new EnumMap<>(ProtocolType.class);
    for (ProtocolType protocolType : ProtocolType.values()) {
        serverSocketsPerProtocolType.put(protocolType, new MutableInteger());
    }
    Map<EndpointQualifier, EndpointConfig> endpointConfigs = config.getAdvancedNetworkConfig().getEndpointConfigs();
    for (EndpointConfig endpointConfig : endpointConfigs.values()) {
        if (endpointConfig instanceof ServerSocketEndpointConfig) {
            serverSocketsPerProtocolType.get(endpointConfig.getProtocolType()).getAndInc();
        }
    }
    for (ProtocolType protocolType : ProtocolType.values()) {
        int serverSocketCount = serverSocketsPerProtocolType.get(protocolType).value;
        if (serverSocketCount > protocolType.getServerSocketCardinality()) {
            throw new InvalidConfigurationException(format("Protocol type %s allows definition " + "of up to %d server sockets but %d were configured", protocolType, protocolType.getServerSocketCardinality(), serverSocketCount));
        }
    }
    // ensure there is 1 MEMBER type server socket
    if (serverSocketsPerProtocolType.get(MEMBER).value != 1) {
        throw new InvalidConfigurationException("A member-server-socket-endpoint" + " configuration is required for the cluster to form.");
    }
    // endpoint qualifiers referenced by WAN publishers must exist
    for (WanReplicationConfig wanReplicationConfig : config.getWanReplicationConfigs().values()) {
        for (WanBatchPublisherConfig wanPublisherConfig : wanReplicationConfig.getBatchPublisherConfigs()) {
            if (wanPublisherConfig.getEndpoint() != null) {
                EndpointQualifier qualifier = EndpointQualifier.resolve(WAN, wanPublisherConfig.getEndpoint());
                if (endpointConfigs.get(qualifier) == null) {
                    throw new InvalidConfigurationException(format("WAN publisher config for cluster name '%s' requires an wan-endpoint " + "config with identifier '%s' but none was found", wanPublisherConfig.getClusterName(), wanPublisherConfig.getEndpoint()));
                }
            }
        }
    }
}
Also used : WanBatchPublisherConfig(com.hazelcast.config.WanBatchPublisherConfig) WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) ProtocolType(com.hazelcast.instance.ProtocolType) MutableInteger(com.hazelcast.internal.util.MutableInteger) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) ServerSocketEndpointConfig(com.hazelcast.config.ServerSocketEndpointConfig) EnumMap(java.util.EnumMap) EndpointConfig(com.hazelcast.config.EndpointConfig) ServerSocketEndpointConfig(com.hazelcast.config.ServerSocketEndpointConfig) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 5 with ProtocolType

use of com.hazelcast.instance.ProtocolType in project hazelcast by hazelcast.

the class MemberHandshakeTest method localAddresses.

Map<ProtocolType, Collection<Address>> localAddresses() throws Exception {
    Map<ProtocolType, Collection<Address>> map = new EnumMap<>(ProtocolType.class);
    Collection<Address> addresses = new ArrayList<>();
    addresses.add(new Address("127.0.0.1", 5701));
    addresses.add(new Address("127.0.0.1", 5702));
    addresses.add(new Address("127.0.0.1", 5703));
    map.put(ProtocolType.WAN, addresses);
    map.put(ProtocolType.MEMBER, singletonList(new Address("127.0.0.1", 5801)));
    map.put(ProtocolType.CLIENT, singletonList(new Address("127.0.0.1", 5802)));
    map.put(ProtocolType.REST, singletonList(new Address("127.0.0.1", 5803)));
    return map;
}
Also used : Address(com.hazelcast.cluster.Address) ProtocolType(com.hazelcast.instance.ProtocolType) ArrayList(java.util.ArrayList) Collection(java.util.Collection) EnumMap(java.util.EnumMap)

Aggregations

ProtocolType (com.hazelcast.instance.ProtocolType)10 Address (com.hazelcast.cluster.Address)5 Collection (java.util.Collection)4 EndpointQualifier (com.hazelcast.instance.EndpointQualifier)3 EnumMap (java.util.EnumMap)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 EndpointConfig (com.hazelcast.config.EndpointConfig)1 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)1 ServerSocketEndpointConfig (com.hazelcast.config.ServerSocketEndpointConfig)1 WanBatchPublisherConfig (com.hazelcast.config.WanBatchPublisherConfig)1 WanReplicationConfig (com.hazelcast.config.WanReplicationConfig)1 JsonArray (com.hazelcast.internal.json.JsonArray)1 JsonObject (com.hazelcast.internal.json.JsonObject)1 JsonValue (com.hazelcast.internal.json.JsonValue)1 ClientEndPointDTO (com.hazelcast.internal.management.dto.ClientEndPointDTO)1 ClusterHotRestartStatusDTO (com.hazelcast.internal.management.dto.ClusterHotRestartStatusDTO)1 MetricsRegistry (com.hazelcast.internal.metrics.MetricsRegistry)1 SerializationUtil.readCollection (com.hazelcast.internal.serialization.impl.SerializationUtil.readCollection)1