Search in sources :

Example 46 with Address

use of com.hazelcast.cluster.Address 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 47 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class InvalidationMetaDataFetcher method fetchMembersMetadataFor.

private Map<Member, InternalCompletableFuture> fetchMembersMetadataFor(List<String> names) {
    Collection<Member> members = getDataMembers();
    if (members.isEmpty()) {
        return Collections.emptyMap();
    }
    Map<Member, InternalCompletableFuture> futureByMember = createHashMap(members.size());
    for (Member member : members) {
        Address address = member.getAddress();
        try {
            futureByMember.put(member, fetchMetadataOf(member, names));
        } catch (Exception e) {
            handleExceptionWhileProcessingMetadata(member, e);
        }
    }
    return futureByMember;
}
Also used : Address(com.hazelcast.cluster.Address) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Member(com.hazelcast.cluster.Member) ExecutionException(java.util.concurrent.ExecutionException)

Example 48 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class FetchPartitionStateOperation method beforeRun.

@Override
public void beforeRun() {
    Address caller = getCallerAddress();
    Address masterAddress = getNodeEngine().getMasterAddress();
    ILogger logger = getLogger();
    if (!caller.equals(masterAddress)) {
        String msg = caller + " requested our partition table but it's not our known master. " + "Master: " + masterAddress;
        logger.warning(msg);
        // Master address should be already updated after mastership claim.
        throw new IllegalStateException(msg);
    }
    InternalPartitionServiceImpl service = getService();
    if (!service.isMemberMaster(caller)) {
        String msg = caller + " requested our partition table but it's not the master known by migration system.";
        logger.warning(msg);
        // It will learn eventually.
        throw new RetryableHazelcastException(msg);
    }
}
Also used : Address(com.hazelcast.cluster.Address) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ILogger(com.hazelcast.logging.ILogger)

Example 49 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class PartitionReplicaSyncRequest method sendResponse.

/**
 * Send a synchronization response to the caller replica containing the replication operations to be executed
 */
private void sendResponse(Collection<Operation> operations, Collection<ChunkSupplier> chunkSuppliers, ServiceNamespace ns) {
    NodeEngine nodeEngine = getNodeEngine();
    PartitionReplicaSyncResponse syncResponse = createResponse(operations, chunkSuppliers, ns);
    Address target = getCallerAddress();
    ILogger logger = getLogger();
    if (logger.isFinestEnabled()) {
        logger.finest("Sending sync response to -> " + target + " for partitionId=" + partitionId() + ", replicaIndex=" + getReplicaIndex() + ", namespaces=" + ns);
    }
    // PartitionReplicaSyncResponse is TargetAware and sent directly without invocation system.
    syncResponse.setTarget(target);
    OperationService operationService = nodeEngine.getOperationService();
    operationService.send(syncResponse, target);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Address(com.hazelcast.cluster.Address) ILogger(com.hazelcast.logging.ILogger) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 50 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class TcpServerConnectionManagerBase method registerAddresses.

/**
 * Registers the given addresses to the address registry
 */
protected void registerAddresses(UUID remoteUuid, Address primaryAddress, Address targetAddress, Collection<Address> remoteAddressAliases) {
    LinkedAddresses addressesToRegister = LinkedAddresses.getResolvedAddresses(primaryAddress);
    if (targetAddress != null) {
        addressesToRegister.addAllResolvedAddresses(targetAddress);
    }
    if (remoteAddressAliases != null) {
        for (Address remoteAddressAlias : remoteAddressAliases) {
            addressesToRegister.addAllResolvedAddresses(remoteAddressAlias);
        }
    }
    addressRegistry.register(remoteUuid, addressesToRegister);
}
Also used : Address(com.hazelcast.cluster.Address)

Aggregations

Address (com.hazelcast.cluster.Address)540 Test (org.junit.Test)211 QuickTest (com.hazelcast.test.annotation.QuickTest)191 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)178 HazelcastInstance (com.hazelcast.core.HazelcastInstance)92 InetAddress (java.net.InetAddress)75 ArrayList (java.util.ArrayList)66 Member (com.hazelcast.cluster.Member)63 Accessors.getAddress (com.hazelcast.test.Accessors.getAddress)54 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)48 Config (com.hazelcast.config.Config)43 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)43 UUID (java.util.UUID)43 ILogger (com.hazelcast.logging.ILogger)37 HashMap (java.util.HashMap)36 Operation (com.hazelcast.spi.impl.operationservice.Operation)35 List (java.util.List)35 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)34 Map (java.util.Map)33 InetSocketAddress (java.net.InetSocketAddress)32