Click or drag to resize

Get the state of the cluster

Problem

You want to get the list of agents connected to the cluster.

Solution

Call the getAgentInfo() method on the ClusterJobScheduler to retrieve the list of agents currently connected to the coordinator.

Java
package stkparallelcomputingserversdk.howto;

import java.util.List;

import agi.parallel.client.ClusterJobScheduler;
import agi.parallel.infrastructure.AgentSnapshot;

public class GetCoordinatorSnapshot {
    public static void main(String[] args) {
        try (ClusterJobScheduler scheduler = new ClusterJobScheduler("localhost")) {
            scheduler.connect();

            List<AgentSnapshot> agents = scheduler.getAgentInfo();
            for (int i = 0; i < agents.size(); ++i) {
                AgentSnapshot agent = agents.get(i);
                System.out.format("Agent #%s, MachineName=%s, HostCount=%s, Activity=%s%n",
                        i + 1,
                        agent.getMachineName(),
                        agent.getCapacity(),
                        agent.getActivity());
            }
        }

        /*
         * The output of the application should resemble:
         * Agent #1, MachineName=AgentComputerName1, HostCount=12, Activity=Idle
         * Agent #2, MachineName=AgentComputerName2, HostCount=8, Activity=Idle
         * Agent #3, MachineName=AgentComputerName3, HostCount=8, Activity=Idle
         * Agent #4, MachineName=AgentComputerName4, HostCount=8, Activity=Idle
         */
    }
}
Discussion

Getting the list of agents is useful when checking to make sure the coordinator is in a certain state before submitting tasks. Another use for getting the list of agents is to display the information for monitoring purposes.

See Also

STK Parallel Computing Server 2.9 API for Java