Search in sources :

Example 21 with ClusterState

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

the class HttpGetCommandProcessor method handleHealthcheck.

private void handleHealthcheck(HttpGetCommand command) {
    Node node = textCommandService.getNode();
    NodeState nodeState = node.getState();
    ClusterServiceImpl clusterService = node.getClusterService();
    ClusterState clusterState = clusterService.getClusterState();
    int clusterSize = clusterService.getMembers().size();
    InternalPartitionService partitionService = node.getPartitionService();
    boolean memberStateSafe = partitionService.isMemberStateSafe();
    boolean clusterSafe = memberStateSafe && !partitionService.hasOnGoingMigration();
    long migrationQueueSize = partitionService.getMigrationQueueSize();
    StringBuilder res = new StringBuilder();
    res.append("Hazelcast::NodeState=").append(nodeState).append("\n");
    res.append("Hazelcast::ClusterState=").append(clusterState).append("\n");
    res.append("Hazelcast::ClusterSafe=").append(Boolean.toString(clusterSafe).toUpperCase()).append("\n");
    res.append("Hazelcast::MigrationQueueSize=").append(migrationQueueSize).append("\n");
    res.append("Hazelcast::ClusterSize=").append(clusterSize).append("\n");
    command.setResponse(MIME_TEXT_PLAIN, stringToBytes(res.toString()));
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) NodeState(com.hazelcast.instance.NodeState) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl)

Example 22 with ClusterState

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

the class AdvancedClusterStateTest method test_eitherClusterStateChange_orPartitionInitialization_shouldBeSuccessful.

@Test
public void test_eitherClusterStateChange_orPartitionInitialization_shouldBeSuccessful() throws Exception {
    Config config = new Config();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance[] instances = factory.newInstances(config);
    HazelcastInstance hz1 = instances[0];
    final HazelcastInstance hz2 = instances[1];
    HazelcastInstance hz3 = instances[2];
    final InternalPartitionService partitionService = getNode(hz1).getPartitionService();
    final int initialPartitionStateVersion = partitionService.getPartitionStateVersion();
    final ClusterState newState = ClusterState.PASSIVE;
    final Future future = spawn(new Runnable() {

        public void run() {
            try {
                changeClusterState(hz2, newState, initialPartitionStateVersion);
            } catch (Exception ignored) {
            }
        }
    });
    partitionService.firstArrangement();
    future.get(2, TimeUnit.MINUTES);
    final ClusterState currentState = hz2.getCluster().getClusterState();
    if (currentState == newState) {
        // if cluster state changed then partition state version should be equal to initial version
        assertEquals(initialPartitionStateVersion, partitionService.getPartitionStateVersion());
    } else {
        assertEquals(ClusterState.ACTIVE, currentState);
        final InternalPartition partition = partitionService.getPartition(0, false);
        if (partition.getOwnerOrNull() == null) {
            // if partition assignment failed then partition state version should be equal to initial version
            assertEquals(initialPartitionStateVersion, partitionService.getPartitionStateVersion());
        } else {
            // if cluster state change failed and partition assignment is done
            // then partition state version should be some positive number
            final int partitionStateVersion = partitionService.getPartitionStateVersion();
            assertTrue("Version should be positive: " + partitionService, partitionStateVersion > 0);
        }
    }
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Config(com.hazelcast.config.Config) Future(java.util.concurrent.Future) InternalPartition(com.hazelcast.internal.partition.InternalPartition) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) TransactionException(com.hazelcast.transaction.TransactionException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 23 with ClusterState

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

the class GetClusterStateRequest method writeResponse.

@Override
public void writeResponse(ManagementCenterService mcs, JsonObject out) throws Exception {
    ClusterState clusterState = mcs.getHazelcastInstance().getCluster().getClusterState();
    JsonObject result = new JsonObject();
    result.add("result", clusterState.toString());
    out.add("result", result);
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) JsonObject(com.eclipsesource.json.JsonObject)

Example 24 with ClusterState

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

the class GetClusterStateRequestTest method testGetClusterState.

@Test
public void testGetClusterState() throws Exception {
    GetClusterStateRequest request = new GetClusterStateRequest();
    ClusterState clusterState = cluster.getClusterState();
    JsonObject jsonObject = new JsonObject();
    request.writeResponse(managementCenterService, jsonObject);
    JsonObject result = (JsonObject) jsonObject.get("result");
    assertEquals(clusterState.name(), request.readResponse(result));
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) GetClusterStateRequest(com.hazelcast.internal.management.request.GetClusterStateRequest) JsonObject(com.eclipsesource.json.JsonObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 25 with ClusterState

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

the class PartitionReplicaStateChecker method hasMissingReplicaOwners.

private boolean hasMissingReplicaOwners() {
    if (!needsReplicaStateCheck()) {
        return false;
    }
    int memberGroupsSize = partitionStateManager.getMemberGroupsSize();
    int replicaCount = Math.min(InternalPartition.MAX_REPLICA_COUNT, memberGroupsSize);
    ClusterServiceImpl clusterService = node.getClusterService();
    ClusterState clusterState = clusterService.getClusterState();
    boolean isClusterNotActive = (clusterState == ClusterState.FROZEN || clusterState == ClusterState.PASSIVE);
    for (InternalPartition partition : partitionStateManager.getPartitions()) {
        for (int index = 0; index < replicaCount; index++) {
            Address address = partition.getReplicaAddress(index);
            if (address == null) {
                if (logger.isFinestEnabled()) {
                    logger.finest("Missing replica=" + index + " for partitionId=" + partition.getPartitionId());
                }
                return true;
            }
            if (clusterService.getMember(address) == null && (!isClusterNotActive || !clusterService.isMemberRemovedWhileClusterIsNotActive(address))) {
                if (logger.isFinestEnabled()) {
                    logger.finest("Unknown replica owner= " + address + ", partitionId=" + partition.getPartitionId() + ", replica=" + index);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) Address(com.hazelcast.nio.Address) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Aggregations

ClusterState (com.hazelcast.cluster.ClusterState)26 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)6 Address (com.hazelcast.nio.Address)6 Node (com.hazelcast.instance.Node)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 InternalPartition (com.hazelcast.internal.partition.InternalPartition)3 Version (com.hazelcast.version.Version)3 JsonObject (com.eclipsesource.json.JsonObject)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)2 ILogger (com.hazelcast.logging.ILogger)2 NodeState (com.hazelcast.monitor.NodeState)2 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 TransactionException (com.hazelcast.transaction.TransactionException)2 MemberVersion (com.hazelcast.version.MemberVersion)2 ExecutionException (java.util.concurrent.ExecutionException)2