Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop and shutdown an entire hazelcast cluster?

Tags:

java

hazelcast

How do you stop and shutdown a hazelcast cluster? My observation from testing is that whenever a node ist stopped by HazelcastInstance#shutdown() the cluster tries to re-balance or backup the data. How can I first "stop" the cluster and then shut it down? (Or is my observation wrong?)

like image 421
Jan Avatar asked Feb 18 '14 23:02

Jan


People also ask

How do I check Hazelcast cluster status?

Now you retrieve information about your cluster's health status (member state, cluster state, cluster size, etc.) by launching http://<your member's host IP>:5701/hazelcast/health on your preferred browser.

How do I monitor a Hazelcast cluster?

Monitoring Hazelcast via REST API To monitor health of the cluster or member state via REST API, one has to enable REST API based communication to the members. This can be done by configuration and also programmatically. This displays that there is 1 member in our cluster and it is Active.


1 Answers

You can use isClusterSafe as in below example :

public class ShutdownCluster {

public static void main(String[] args) throws Exception {

    HazelcastInstance member1 = Hazelcast.newHazelcastInstance();
    HazelcastInstance member2 = Hazelcast.newHazelcastInstance();
    HazelcastInstance member3 = Hazelcast.newHazelcastInstance();

    if(member1.getPartitionService().isClusterSafe()) {
        IExecutorService executorService = member1.getExecutorService(ShutdownCluster.class.getName());
        executorService.executeOnAllMembers(new ShutdownMember());
    }
}

private static class ShutdownMember implements Runnable, HazelcastInstanceAware, Serializable {

    private HazelcastInstance node;

    @Override
    public void run() {
        node.getLifecycleService().shutdown();
    }

    @Override
    public void setHazelcastInstance(HazelcastInstance node) {
        this.node = node;
    }
}
}
like image 84
mrck Avatar answered Oct 29 '22 17:10

mrck