Search in sources :

Example 66 with Address

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

the class TcpClientConnectionTest method testWithLegalAndIllegalAddressTogether.

@Test
public void testWithLegalAndIllegalAddressTogether() {
    String illegalAddress = randomString();
    HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
    Address serverAddress = server.getCluster().getLocalMember().getAddress();
    ClientConfig config = new ClientConfig();
    config.setProperty(ClientProperty.SHUFFLE_MEMBER_LIST.getName(), "false");
    config.getNetworkConfig().addAddress(illegalAddress).addAddress(serverAddress.getHost() + ":" + serverAddress.getPort());
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
    Collection<Client> connectedClients = server.getClientService().getConnectedClients();
    assertEquals(connectedClients.size(), 1);
    Client serverSideClientInfo = connectedClients.iterator().next();
    assertEquals(serverSideClientInfo.getUuid(), client.getLocalEndpoint().getUuid());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 67 with Address

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

the class SystemLogPlugin method render.

private void render(DiagnosticsLogWriter writer, MembershipEvent event) {
    switch(event.getEventType()) {
        case MembershipEvent.MEMBER_ADDED:
            writer.startSection("MemberAdded");
            break;
        case MembershipEvent.MEMBER_REMOVED:
            writer.startSection("MemberRemoved");
            break;
        default:
            return;
    }
    writer.writeKeyValueEntry("member", event.getMember().getAddress().toString());
    // writing the members
    writer.startSection("Members");
    Set<Member> members = event.getMembers();
    if (members != null) {
        boolean first = true;
        for (Member member : members) {
            Address memberAddress = member.getAddress();
            String addressStr = String.valueOf(memberAddress);
            if (memberAddress.equals(thisAddress)) {
                if (first) {
                    writer.writeEntry(addressStr + ":this:master");
                } else {
                    writer.writeEntry(addressStr + ":this");
                }
            } else if (first) {
                writer.writeEntry(addressStr + ":master");
            } else {
                writer.writeEntry(addressStr);
            }
            first = false;
        }
    }
    writer.endSection();
    // ending the outer section
    writer.endSection();
}
Also used : Address(com.hazelcast.cluster.Address) Member(com.hazelcast.cluster.Member)

Example 68 with Address

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

the class OperationHeartbeatPlugin method run.

@Override
public void run(DiagnosticsLogWriter writer) {
    long nowMillis = System.currentTimeMillis();
    for (Map.Entry<Address, AtomicLong> entry : heartbeatPerMember.entrySet()) {
        Address member = entry.getKey();
        long lastHeartbeatMillis = entry.getValue().longValue();
        long noHeartbeatMillis = nowMillis - lastHeartbeatMillis;
        float deviation = HUNDRED * ((float) (noHeartbeatMillis - expectedIntervalMillis)) / expectedIntervalMillis;
        if (deviation >= maxDeviationPercentage) {
            startLazyMainSection(writer);
            writer.startSection("member" + member);
            writer.writeKeyValueEntry("deviation(%)", deviation);
            writer.writeKeyValueEntry("noHeartbeat(ms)", noHeartbeatMillis);
            writer.writeKeyValueEntry("lastHeartbeat(ms)", lastHeartbeatMillis);
            writer.writeKeyValueEntryAsDateTime("lastHeartbeat(date-time)", lastHeartbeatMillis);
            writer.writeKeyValueEntry("now(ms)", nowMillis);
            writer.writeKeyValueEntryAsDateTime("now(date-time)", nowMillis);
            writer.endSection();
        }
    }
    endLazyMainSection(writer);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Address(com.hazelcast.cluster.Address) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 69 with Address

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

the class TimedMemberStateFactory method createTimedMemberState.

@Nonnull
public TimedMemberState createTimedMemberState() {
    MemberStateImpl memberState = new MemberStateImpl();
    Collection<StatisticsAwareService> services = instance.node.nodeEngine.getServices(StatisticsAwareService.class);
    TimedMemberState timedMemberState = new TimedMemberState();
    createMemberState(memberState, services);
    timedMemberState.setMaster(instance.node.isMaster());
    timedMemberState.setMemberList(new ArrayList<>());
    Set<Member> memberSet = instance.getCluster().getMembers();
    for (Member member : memberSet) {
        MemberImpl memberImpl = (MemberImpl) member;
        Address address = memberImpl.getAddress();
        timedMemberState.getMemberList().add(address.getHost() + ":" + address.getPort());
    }
    timedMemberState.setMemberState(memberState);
    timedMemberState.setClusterName(instance.getConfig().getClusterName());
    SSLConfig sslConfig = getActiveMemberNetworkConfig(instance.getConfig()).getSSLConfig();
    timedMemberState.setSslEnabled(sslConfig != null && sslConfig.isEnabled());
    timedMemberState.setLite(instance.node.isLiteMember());
    SocketInterceptorConfig interceptorConfig = getActiveMemberNetworkConfig(instance.getConfig()).getSocketInterceptorConfig();
    timedMemberState.setSocketInterceptorEnabled(interceptorConfig != null && interceptorConfig.isEnabled());
    ManagementCenterConfig managementCenterConfig = instance.node.getConfig().getManagementCenterConfig();
    timedMemberState.setScriptingEnabled(managementCenterConfig.isScriptingEnabled());
    timedMemberState.setConsoleEnabled(managementCenterConfig.isConsoleEnabled());
    timedMemberState.setMcDataAccessEnabled(managementCenterConfig.isDataAccessEnabled());
    return timedMemberState;
}
Also used : SSLConfig(com.hazelcast.config.SSLConfig) StatisticsAwareService(com.hazelcast.internal.services.StatisticsAwareService) Address(com.hazelcast.cluster.Address) SocketInterceptorConfig(com.hazelcast.config.SocketInterceptorConfig) MemberStateImpl(com.hazelcast.internal.monitor.impl.MemberStateImpl) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ManagementCenterConfig(com.hazelcast.config.ManagementCenterConfig) Member(com.hazelcast.cluster.Member) CPMember(com.hazelcast.cp.CPMember) Nonnull(javax.annotation.Nonnull)

Example 70 with Address

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

the class InternalPartitionServiceImpl method triggerMasterToAssignPartitions.

/**
 * Sends a {@link AssignPartitions} to the master to assign partitions.
 */
private void triggerMasterToAssignPartitions() {
    if (!shouldTriggerMasterToAssignPartitions()) {
        return;
    }
    ClusterServiceImpl clusterService = node.getClusterService();
    ClusterState clusterState = clusterService.getClusterState();
    if (!clusterState.isMigrationAllowed()) {
        logger.warning("Partitions can't be assigned since cluster-state=" + clusterState);
        return;
    }
    final Address masterAddress = latestMaster;
    if (masterAddress == null || masterAddress.equals(node.getThisAddress())) {
        return;
    }
    if (masterTriggered.compareAndSet(false, true)) {
        OperationServiceImpl operationService = nodeEngine.getOperationService();
        InvocationFuture<PartitionRuntimeState> future = operationService.invokeOnTarget(SERVICE_NAME, new AssignPartitions(), masterAddress);
        future.whenCompleteAsync((partitionState, throwable) -> {
            if (throwable == null) {
                resetMasterTriggeredFlag();
                if (partitionState != null) {
                    partitionState.setMaster(masterAddress);
                    processPartitionRuntimeState(partitionState);
                }
            } else {
                resetMasterTriggeredFlag();
                logger.severe(throwable);
            }
        });
        masterTrigger.executeWithDelay();
    }
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) Address(com.hazelcast.cluster.Address) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) AssignPartitions(com.hazelcast.internal.partition.operation.AssignPartitions) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

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