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;
}
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;
}
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;
}
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));
}
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());
}
}
Aggregations