Search in sources :

Example 1 with PartitionServiceState

use of com.hazelcast.internal.partition.impl.PartitionServiceState in project hazelcast by hazelcast.

the class HazelcastStarterTest method assertSafePartitionServiceState.

private static void assertSafePartitionServiceState(HazelcastInstance realInstance) {
    PartitionServiceState partitionServiceState = TestPartitionUtils.getPartitionServiceState(realInstance);
    assertEquals(PartitionServiceState.SAFE, partitionServiceState);
}
Also used : PartitionServiceState(com.hazelcast.internal.partition.impl.PartitionServiceState)

Example 2 with PartitionServiceState

use of com.hazelcast.internal.partition.impl.PartitionServiceState in project hazelcast by hazelcast.

the class JobCoordinationService method shouldStartJobs.

boolean shouldStartJobs() {
    if (!isMaster() || !nodeEngine.isRunning()) {
        return false;
    }
    ClusterState clusterState = nodeEngine.getClusterService().getClusterState();
    if (isClusterEnteringPassiveState || clusterState == PASSIVE || clusterState == IN_TRANSITION) {
        logger.fine("Not starting jobs because cluster is in passive state or in transition.");
        return false;
    }
    // if there are any members in a shutdown process, don't start jobs
    if (!membersShuttingDown.isEmpty()) {
        LoggingUtil.logFine(logger, "Not starting jobs because members are shutting down: %s", membersShuttingDown.keySet());
        return false;
    }
    Version clusterVersion = nodeEngine.getClusterService().getClusterVersion();
    for (Member m : nodeEngine.getClusterService().getMembers()) {
        if (!clusterVersion.equals(m.getVersion().asVersion())) {
            logger.fine("Not starting non-light jobs because rolling upgrade is in progress");
            return false;
        }
    }
    PartitionServiceState state = getInternalPartitionService().getPartitionReplicaStateChecker().getPartitionServiceState();
    if (state != PartitionServiceState.SAFE) {
        logger.fine("Not starting jobs because partition replication is not in safe state, but in " + state);
        return false;
    }
    if (!getInternalPartitionService().getPartitionStateManager().isInitialized()) {
        logger.fine("Not starting jobs because partitions are not yet initialized.");
        return false;
    }
    return true;
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) Version(com.hazelcast.version.Version) Member(com.hazelcast.cluster.Member) PartitionServiceState(com.hazelcast.internal.partition.impl.PartitionServiceState)

Example 3 with PartitionServiceState

use of com.hazelcast.internal.partition.impl.PartitionServiceState in project hazelcast by hazelcast.

the class TestPartitionUtils method getPartitionServiceState.

public static PartitionServiceState getPartitionServiceState(HazelcastInstance instance) {
    try {
        Node node = getNode(instance);
        InternalPartitionService partitionService = node.getPartitionService();
        if (isProxyClass(instance.getClass())) {
            try {
                // this is very ugly, but because of a direct field access to Node.nodeEngine in the MigrationManager
                // constructor, we cannot properly mock or proxy the PartitionReplicaStateChecker class
                Object delegate = getDelegateFromMock(partitionService);
                Object partitionReplicaStateChecker = getFieldValueReflectively(delegate, "partitionReplicaStateChecker");
                Method method = partitionReplicaStateChecker.getClass().getMethod("getPartitionServiceState");
                Object result = method.invoke(partitionReplicaStateChecker);
                return (PartitionServiceState) proxyObjectForStarter(TestPartitionUtils.class.getClassLoader(), result);
            } catch (Exception e) {
                throw rethrowGuardianException(e);
            }
        } else {
            return partitionService.getPartitionReplicaStateChecker().getPartitionServiceState();
        }
    } catch (IllegalArgumentException e) {
        return PartitionServiceState.SAFE;
    }
}
Also used : TestUtil.getNode(com.hazelcast.instance.impl.TestUtil.getNode) Node(com.hazelcast.instance.impl.Node) Method(java.lang.reflect.Method) PartitionServiceState(com.hazelcast.internal.partition.impl.PartitionServiceState) HazelcastStarterUtils.rethrowGuardianException(com.hazelcast.test.starter.HazelcastStarterUtils.rethrowGuardianException)

Example 4 with PartitionServiceState

use of com.hazelcast.internal.partition.impl.PartitionServiceState in project hazelcast by hazelcast.

the class HazelcastTestSupport method assertAllInSafeState.

public static void assertAllInSafeState(Collection<HazelcastInstance> nodes) {
    Map<Address, PartitionServiceState> nonSafeStates = new HashMap<Address, PartitionServiceState>();
    for (HazelcastInstance node : nodes) {
        if (node == null) {
            continue;
        }
        final PartitionServiceState state = getPartitionServiceState(node);
        if (state != PartitionServiceState.SAFE) {
            nonSafeStates.put(Accessors.getAddress(node), state);
        }
    }
    assertTrue("Instances not in safe state! " + nonSafeStates, nonSafeStates.isEmpty());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) HashMap(java.util.HashMap) TestPartitionUtils.getPartitionServiceState(com.hazelcast.internal.partition.TestPartitionUtils.getPartitionServiceState) PartitionServiceState(com.hazelcast.internal.partition.impl.PartitionServiceState)

Aggregations

PartitionServiceState (com.hazelcast.internal.partition.impl.PartitionServiceState)4 Address (com.hazelcast.cluster.Address)1 ClusterState (com.hazelcast.cluster.ClusterState)1 Member (com.hazelcast.cluster.Member)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Node (com.hazelcast.instance.impl.Node)1 TestUtil.getNode (com.hazelcast.instance.impl.TestUtil.getNode)1 TestPartitionUtils.getPartitionServiceState (com.hazelcast.internal.partition.TestPartitionUtils.getPartitionServiceState)1 HazelcastStarterUtils.rethrowGuardianException (com.hazelcast.test.starter.HazelcastStarterUtils.rethrowGuardianException)1 Version (com.hazelcast.version.Version)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1