Search in sources :

Example 1 with ClusterState

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

the class ClusterJoinManager method checkClusterStateBeforeJoin.

private boolean checkClusterStateBeforeJoin(Address target, String uuid) {
    ClusterState state = clusterStateManager.getState();
    if (state == ClusterState.IN_TRANSITION) {
        logger.warning("Cluster state is in transition process. Join is not allowed until " + "transaction is completed -> " + clusterStateManager.stateToString());
        return true;
    }
    if (state == ClusterState.ACTIVE) {
        return false;
    }
    if (clusterService.isMemberRemovedWhileClusterIsNotActive(target)) {
        MemberImpl memberRemovedWhileClusterIsNotActive = clusterService.getMemberRemovedWhileClusterIsNotActive(uuid);
        if (memberRemovedWhileClusterIsNotActive != null && !target.equals(memberRemovedWhileClusterIsNotActive.getAddress())) {
            logger.warning("Uuid " + uuid + " was being used by " + memberRemovedWhileClusterIsNotActive + " before. " + target + " is not allowed to join with a uuid which belongs to" + " a known passive member.");
            return true;
        }
        return false;
    }
    if (clusterService.isMemberRemovedWhileClusterIsNotActive(uuid)) {
        return false;
    }
    if (node.getNodeExtension().isStartCompleted()) {
        String message = "Cluster state either is locked or doesn't allow new members to join -> " + clusterStateManager.stateToString();
        logger.warning(message);
        OperationService operationService = nodeEngine.getOperationService();
        BeforeJoinCheckFailureOperation op = new BeforeJoinCheckFailureOperation(message);
        operationService.send(op, target);
    } else {
        String message = "Cluster state either is locked or doesn't allow new members to join -> " + clusterStateManager.stateToString() + ". Silently ignored join request of " + target + " because start not completed.";
        logger.warning(message);
    }
    return true;
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) MemberImpl(com.hazelcast.instance.MemberImpl) OperationService(com.hazelcast.spi.OperationService) BeforeJoinCheckFailureOperation(com.hazelcast.internal.cluster.impl.operations.BeforeJoinCheckFailureOperation)

Example 2 with ClusterState

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

the class Node method changeNodeStateToPassive.

public void changeNodeStateToPassive() {
    final ClusterState clusterState = clusterService.getClusterState();
    if (clusterState != ClusterState.PASSIVE) {
        throw new IllegalStateException("This method can be called only when cluster-state is " + clusterState);
    }
    state = NodeState.PASSIVE;
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState)

Example 3 with ClusterState

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

the class Node method changeNodeStateToActive.

public void changeNodeStateToActive() {
    final ClusterState clusterState = clusterService.getClusterState();
    if (clusterState == ClusterState.PASSIVE) {
        throw new IllegalStateException("This method can be called only when cluster-state is not " + clusterState);
    }
    state = NodeState.ACTIVE;
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState)

Example 4 with ClusterState

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

the class HttpPostCommandProcessor method handleChangeClusterState.

private void handleChangeClusterState(HttpPostCommand command) throws UnsupportedEncodingException {
    byte[] data = command.getData();
    String[] strList = bytesToString(data).split("&");
    String groupName = URLDecoder.decode(strList[0], "UTF-8");
    String groupPass = URLDecoder.decode(strList[1], "UTF-8");
    String stateParam = URLDecoder.decode(strList[2], "UTF-8");
    String res;
    try {
        Node node = textCommandService.getNode();
        ClusterService clusterService = node.getClusterService();
        GroupConfig groupConfig = node.getConfig().getGroupConfig();
        if (!(groupConfig.getName().equals(groupName) && groupConfig.getPassword().equals(groupPass))) {
            res = response(ResponseType.FORBIDDEN);
        } else {
            ClusterState state = clusterService.getClusterState();
            if (stateParam.equals("frozen")) {
                state = ClusterState.FROZEN;
            }
            if (stateParam.equals("active")) {
                state = ClusterState.ACTIVE;
            }
            if (stateParam.equals("passive")) {
                state = ClusterState.PASSIVE;
            }
            if (!state.equals(clusterService.getClusterState())) {
                clusterService.changeClusterState(state);
                res = response(ResponseType.SUCCESS, "state", state.toString().toLowerCase());
            } else {
                res = response(ResponseType.FAIL, "state", state.toString().toLowerCase());
            }
        }
    } catch (Throwable throwable) {
        logger.warning("Error occurred while changing cluster state", throwable);
        res = exceptionResponse(throwable);
    }
    command.setResponse(HttpCommand.CONTENT_TYPE_JSON, stringToBytes(res));
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) ClusterService(com.hazelcast.internal.cluster.ClusterService) GroupConfig(com.hazelcast.config.GroupConfig) Node(com.hazelcast.instance.Node) StringUtil.bytesToString(com.hazelcast.util.StringUtil.bytesToString)

Example 5 with ClusterState

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

the class ShutdownNodeOperation method run.

@Override
public void run() {
    final ClusterServiceImpl clusterService = getService();
    final ILogger logger = getLogger();
    final ClusterState clusterState = clusterService.getClusterState();
    if (clusterState == ClusterState.PASSIVE) {
        final NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
        if (nodeEngine.isRunning()) {
            logger.info("Shutting down node in cluster passive state. Requested by: " + getCallerAddress());
            new Thread(new Runnable() {

                @Override
                public void run() {
                    final Node node = nodeEngine.getNode();
                    node.hazelcastInstance.getLifecycleService().shutdown();
                }
            }, nodeEngine.getHazelcastThreadGroup().getThreadNamePrefix(".clusterShutdown")).start();
        } else {
            logger.info("Node is already shutting down. NodeState: " + nodeEngine.getNode().getState());
        }
    } else {
        logger.severe("Can not shut down node because cluster is in " + clusterState + " state. Requested by: " + getCallerAddress());
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ClusterState(com.hazelcast.cluster.ClusterState) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) ILogger(com.hazelcast.logging.ILogger)

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