Search in sources :

Example 1 with NodeState

use of com.hazelcast.instance.impl.NodeState in project hazelcast by hazelcast.

the class Invocation method engineActive.

private boolean engineActive() {
    NodeState state = context.node.getState();
    if (state == NodeState.ACTIVE) {
        return true;
    }
    boolean allowed = true;
    if (state == NodeState.SHUT_DOWN) {
        notifyError(new HazelcastInstanceNotActiveException("State: " + state + " Operation: " + op.getClass()));
        allowed = false;
    } else if (!(op instanceof AllowedDuringPassiveState) && context.clusterService.getClusterState() == ClusterState.PASSIVE) {
        // Similar to OperationRunnerImpl.checkNodeState(op)
        notifyError(new IllegalStateException("Cluster is in " + ClusterState.PASSIVE + " state! Operation: " + op));
        allowed = false;
    }
    return allowed;
}
Also used : AllowedDuringPassiveState(com.hazelcast.spi.impl.AllowedDuringPassiveState) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) NodeState(com.hazelcast.instance.impl.NodeState)

Example 2 with NodeState

use of com.hazelcast.instance.impl.NodeState in project hazelcast by hazelcast.

the class HttpGetCommandProcessor method handleHealthcheck.

private void handleHealthcheck(HttpGetCommand command, String uri) {
    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();
    long migrationQueueSize = partitionService.getMigrationQueueSize();
    String healthParameter = uri.substring(URI_HEALTH_URL.length());
    if (healthParameter.equals(HEALTH_PATH_PARAM_NODE_STATE)) {
        if (NodeState.SHUT_DOWN.equals(nodeState)) {
            command.send503();
        } else {
            prepareResponse(command, Json.value(nodeState.toString()));
        }
    } else if (healthParameter.equals(HEALTH_PATH_PARAM_CLUSTER_STATE)) {
        prepareResponse(command, Json.value(clusterState.toString()));
    } else if (healthParameter.equals(HEALTH_PATH_PARAM_CLUSTER_SAFE)) {
        if (isClusterSafe()) {
            command.send200();
        } else {
            command.send503();
        }
    } else if (healthParameter.equals(HEALTH_PATH_PARAM_MIGRATION_QUEUE_SIZE)) {
        prepareResponse(command, Json.value(migrationQueueSize));
    } else if (healthParameter.equals(HEALTH_PATH_PARAM_CLUSTER_SIZE)) {
        prepareResponse(command, Json.value(clusterSize));
    } else if (healthParameter.isEmpty()) {
        JsonObject response = new JsonObject().add("nodeState", nodeState.toString()).add("clusterState", clusterState.toString()).add("clusterSafe", isClusterSafe()).add("migrationQueueSize", migrationQueueSize).add("clusterSize", clusterSize);
        prepareResponse(command, response);
    } else {
        command.send400();
    }
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) NodeState(com.hazelcast.instance.impl.NodeState) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.impl.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) JsonObject(com.hazelcast.internal.json.JsonObject)

Example 3 with NodeState

use of com.hazelcast.instance.impl.NodeState in project hazelcast by hazelcast.

the class OperationRunnerImpl method checkNodeState.

private void checkNodeState(Operation op) {
    NodeState state = node.getState();
    if (state == NodeState.ACTIVE) {
        return;
    }
    Address localAddress = node.getThisAddress();
    if (state == NodeState.SHUT_DOWN) {
        throw new HazelcastInstanceNotActiveException("Member " + localAddress + " is shut down! Operation: " + op);
    }
    if (op instanceof AllowedDuringPassiveState) {
        return;
    }
    // Cluster is in passive state. There is no need to retry.
    if (nodeEngine.getClusterService().getClusterState() == ClusterState.PASSIVE) {
        throw new IllegalStateException("Cluster is in " + ClusterState.PASSIVE + " state! Operation: " + op);
    }
}
Also used : AllowedDuringPassiveState(com.hazelcast.spi.impl.AllowedDuringPassiveState) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) NodeState(com.hazelcast.instance.impl.NodeState) Address(com.hazelcast.cluster.Address) OperationAccessor.setCallerAddress(com.hazelcast.spi.impl.operationservice.OperationAccessor.setCallerAddress)

Example 4 with NodeState

use of com.hazelcast.instance.impl.NodeState in project hazelcast by hazelcast.

the class HttpHeadCommandProcessor method handleHealthcheck.

private void handleHealthcheck(HttpHeadCommand 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();
    long migrationQueueSize = partitionService.getMigrationQueueSize();
    Map<String, Object> headervals = new LinkedHashMap<>();
    headervals.put("NodeState", nodeState);
    headervals.put("ClusterState", clusterState);
    headervals.put("MigrationQueueSize", migrationQueueSize);
    headervals.put("ClusterSize", clusterSize);
    command.setResponse(SC_200, headervals);
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) NodeState(com.hazelcast.instance.impl.NodeState) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.impl.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with NodeState

use of com.hazelcast.instance.impl.NodeState in project hazelcast by hazelcast.

the class MemberHazelcastInstanceInfoPlugin method run.

@Override
public void run(DiagnosticsLogWriter writer) {
    writer.startSection("HazelcastInstance");
    writer.writeKeyValueEntry("thisAddress", nodeEngine.getNode().getThisAddress().toString());
    writer.writeKeyValueEntry("isRunning", nodeEngine.getNode().isRunning());
    writer.writeKeyValueEntry("isLite", nodeEngine.getNode().isLiteMember());
    writer.writeKeyValueEntry("joined", nodeEngine.getNode().getClusterService().isJoined());
    NodeState state = nodeEngine.getNode().getState();
    writer.writeKeyValueEntry("nodeState", state == null ? "null" : state.toString());
    UUID clusterId = nodeEngine.getClusterService().getClusterId();
    writer.writeKeyValueEntry("clusterId", clusterId != null ? clusterId.toString() : "null");
    writer.writeKeyValueEntry("clusterSize", nodeEngine.getClusterService().getSize());
    writer.writeKeyValueEntry("isMaster", nodeEngine.getClusterService().isMaster());
    Address masterAddress = nodeEngine.getClusterService().getMasterAddress();
    writer.writeKeyValueEntry("masterAddress", masterAddress == null ? "null" : masterAddress.toString());
    writer.startSection("Members");
    for (Member member : nodeEngine.getClusterService().getMemberImpls()) {
        writer.writeEntry(member.getAddress().toString());
    }
    writer.endSection();
    writer.endSection();
}
Also used : NodeState(com.hazelcast.instance.impl.NodeState) Address(com.hazelcast.cluster.Address) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member)

Aggregations

NodeState (com.hazelcast.instance.impl.NodeState)5 Address (com.hazelcast.cluster.Address)2 ClusterState (com.hazelcast.cluster.ClusterState)2 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 Node (com.hazelcast.instance.impl.Node)2 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)2 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)2 AllowedDuringPassiveState (com.hazelcast.spi.impl.AllowedDuringPassiveState)2 Member (com.hazelcast.cluster.Member)1 JsonObject (com.hazelcast.internal.json.JsonObject)1 OperationAccessor.setCallerAddress (com.hazelcast.spi.impl.operationservice.OperationAccessor.setCallerAddress)1 LinkedHashMap (java.util.LinkedHashMap)1 UUID (java.util.UUID)1