Hi Jason,
It is my understanding that what you want is to execute all the tasks in each job on the same machine.There are multiple ways to do this, and they all involve the node filtering ability provided by
an execution policy, which can be
set onto a job SLA.
The simplest approach is to filter the nodes by their IP address or host name. For this, you need to collect the addresses of the available nodes, which can be done using the
management APIs as follows:
public static List<String> getAllNodesHosts(JPPFClient client) throws Exception {
// get a JMX connection to the driver
JMXDriverConnectionWrapper jmx = getJMXConnection(client);
// request information on all the nodes
Collection<JPPFManagementInfo> nodes = jmx.nodesInformation();
Set<String> result = new HashSet<>();
// collect all the nodes host names / ip addresses
for (JPPFManagementInfo nodeInfo: nodes) {
String host = nodeInfo.getHost();
if (!result.contains(host)) result.add(host);
}
return new ArrayList<>(result);
}
public static JMXDriverConnectionWrapper getJMXConnection(JPPFClient client) throws Exception {
JPPFConnectionPool pool = null;
// wait until there is a connection pool available
while ((pool = client.getConnectionPool()) == null) Thread.sleep(10L);
JMXDriverConnectionWrapper jmx = null;
// wait until the pool has an established JMX connection
while ((jmx = pool.getJmxConnection(true)) == null) Thread.sleep(10L);
return jmx;
}
Once you have the list of node hosts, you can use them in a round-robin fashion for all your jobs, for example:
try (JPPFClient client = new JPPFClient()) {
List<JPPFJob> jobs = ...;
List<String> nodeHosts = getAllNodesHosts(client);
int hostIndex = 0;
for (JPPFJob job: jobs) {
// modulo operation to implement round-robin rotation
hostIndex = hostIndex % nodeHosts.size();
String host = nodeHosts.get(hostIndex);
// execute only on the machine which has 'host' as IPv4 or IPv6 address or host name
ExecutionPolicy policy = new Contains("ipv4.addresses", true, host).or(new Contains("ipv6.addresses", true, host));
job.getSLA().setExecutionPolicy(policy);
client.submitJob(job);
}
} catch (Exception e) {
e.printStackTrace();
}
With this approach, you effectively implement a partitioning of the grid without the need to have multiple servers, which makes life a lot simpler. This also allows you to use node provisioning without further concern, since each slave node will have the same ip address as its master node.
I don't think that's how slave nodes work in JPPF ...
That is totally correct, slave nodes are pretty much standard nodes, independent from the master from a task distribution persipective, with the difference that the master node controls the JVM processes of all its slaves: if the master dies, all slaves are terminated.
I hope this answers your questions.
Sincerely,
-Laurent