Class SpallocJob
java.lang.Object
uk.ac.manchester.spinnaker.spalloc.SpallocJob
- All Implemented Interfaces:
AutoCloseable
,SpallocJobAPI
public class SpallocJob extends Object implements AutoCloseable, SpallocJobAPI
A high-level interface for requesting and managing allocations of SpiNNaker
boards.
Constructing a SpallocJob
object connects to a spalloc-server
and requests a number of SpiNNaker boards. The job object may then be used to
monitor the state of the request, control the boards allocated and determine
their IP addresses.
In its simplest form, a SpallocJob
can be used as a context manager
like so:
try (var j = new SpallocJob(new CreateJob(6).owner(me))) { myApplication.boot(j.getHostname(), j.getDimensions()); myApplication.run(j.getHostname()); }In this example a six-board machine is requested and the
try
-with-resources context is entered once the allocation has been
made and the allocated boards are fully powered on. When control leaves the
block, the job is destroyed and the boards shut down by the server ready for
another job.
For more fine-grained control, the same functionality is available via various methods:
var j = new SpallocJob(new CreateJob(6).owner(me))); j.waitUntilReady(); myApplication.boot(j.getHostname(), j.getDimensions()); myApplication.run(j.getHostname()); j.destroy();Note:
More complex applications may wish to log the following properties of their job to support later debugging efforts:
ID
— May be used to query the state of the job and find out its fate if cancelled or destroyed. The spalloc-job command can be used to discover the state/fate of the job and spalloc-where-is may be used to find out what boards problem chips reside on.machineName
andboards
together give a complete record of the hardware used by the job. The spalloc-where-is command may be used to find out the physical locations of the boards used.
- See Also:
: How to describe the job to create.
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_CONFIGURATION_SOURCE
The name of the default file to load the configuration from. -
Constructor Summary
Constructors Constructor Description SpallocJob(int id)
Create a job client that resumes an existing job given its ID.SpallocJob(String hostname, int id)
Create a job client that resumes an existing job given its ID.SpallocJob(String hostname, int port, Integer timeout, int id)
Create a job client that resumes an existing job given its ID.SpallocJob(String hostname, Integer timeout, int id)
Create a job client that resumes an existing job given its ID.SpallocJob(String hostname, Integer port, Integer timeout, CreateJob builder)
Create a spalloc job that requests a SpiNNaker machine.SpallocJob(String hostname, Integer timeout, CreateJob builder)
Create a spalloc job that requests a SpiNNaker machine.SpallocJob(String hostname, CreateJob builder)
Create a spalloc job that requests a SpiNNaker machine.SpallocJob(CreateJob builder)
Create a spalloc job that requests a SpiNNaker machine.SpallocJob(SpallocClient client, Integer timeout, CreateJob builder)
Create a spalloc job that requests a SpiNNaker machine.SpallocJob(SpallocClient client, CreateJob builder)
Create a spalloc job that requests a SpiNNaker machine. -
Method Summary
Modifier and Type Method Description protected void
assertCompatibleVersion()
Assert that the server version is compatible.void
close()
void
destroy(String reason)
Destroy the job and disconnect from the server.List<BoardCoordinates>
getBoards()
SpallocClient
getClient()
List<Connection>
getConnections()
String
getDestroyReason()
MachineDimensions
getDimensions()
String
getHostname()
int
getID()
String
getMachineName()
Boolean
getPower()
State
getState()
static void
setConfigurationSource(String filename)
Set up where configuration settings come from.void
setPower(Boolean powerOn)
Turn the boards allocated to the job on or off.State
waitForStateChange(State oldState, Integer timeout)
Block until the job's state changes from the supplied state.void
waitUntilReady(Integer timeout)
Block until the job is allocated and ready.BoardPhysicalCoordinates
whereIs(HasChipLocation chip)
Locates and returns the physical coordinates containing a given chip in a machine allocated to this job.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface uk.ac.manchester.spinnaker.spalloc.SpallocJobAPI
destroy, getTransceiver, reset, waitForStateChange
-
Field Details
-
DEFAULT_CONFIGURATION_SOURCE
The name of the default file to load the configuration from.- See Also:
- Constant Field Values
-
-
Constructor Details
-
SpallocJob
@MustBeClosed public SpallocJob(String hostname, Integer timeout, CreateJob builder) throws IOException, SpallocServerException, InterruptedExceptionCreate a spalloc job that requests a SpiNNaker machine.- Parameters:
hostname
- The spalloc server hosttimeout
- The communications timeoutbuilder
- The job-creation request builder.- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
SpallocJob
@MustBeClosed public SpallocJob(String hostname, CreateJob builder) throws IOException, SpallocServerException, InterruptedExceptionCreate a spalloc job that requests a SpiNNaker machine.- Parameters:
hostname
- The spalloc server hostbuilder
- The job-creation request builder.- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
SpallocJob
@MustBeClosed public SpallocJob(CreateJob builder) throws IOException, SpallocServerException, InterruptedExceptionCreate a spalloc job that requests a SpiNNaker machine.- Parameters:
builder
- The job-creation request builder.- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
SpallocJob
public SpallocJob(SpallocClient client, CreateJob builder) throws IOException, SpallocServerException, InterruptedExceptionCreate a spalloc job that requests a SpiNNaker machine.- Parameters:
client
- The spalloc clientbuilder
- The job-creation request builder.- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.IllegalArgumentException
- If a bad builder is given.InterruptedException
- If interrupted while waiting.
-
SpallocJob
public SpallocJob(SpallocClient client, Integer timeout, CreateJob builder) throws IOException, SpallocServerException, InterruptedExceptionCreate a spalloc job that requests a SpiNNaker machine.- Parameters:
client
- The spalloc clienttimeout
- The communications timeoutbuilder
- The job-creation request builder.- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
SpallocJob
@MustBeClosed public SpallocJob(String hostname, Integer port, Integer timeout, CreateJob builder) throws IOException, SpallocServerException, InterruptedExceptionCreate a spalloc job that requests a SpiNNaker machine.- Parameters:
hostname
- The spalloc server hostport
- The spalloc server porttimeout
- The communications timeoutbuilder
- The job-creation request builder.- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.IllegalArgumentException
- If a bad builder is given.
-
SpallocJob
@MustBeClosed public SpallocJob(int id) throws IOException, SpallocServerException, JobDestroyedException, InterruptedExceptionCreate a job client that resumes an existing job given its ID.- Parameters:
id
- The job ID- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.JobDestroyedException
- If the job doesn't exist (any more).InterruptedException
- If interrupted while waiting.
-
SpallocJob
@MustBeClosed public SpallocJob(String hostname, int id) throws IOException, SpallocServerException, JobDestroyedException, InterruptedExceptionCreate a job client that resumes an existing job given its ID.- Parameters:
hostname
- The spalloc server hostid
- The job ID- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.JobDestroyedException
- If the job doesn't exist (any more).InterruptedException
- If interrupted while waiting.
-
SpallocJob
@MustBeClosed public SpallocJob(String hostname, Integer timeout, int id) throws IOException, SpallocServerException, JobDestroyedException, InterruptedExceptionCreate a job client that resumes an existing job given its ID.- Parameters:
hostname
- The spalloc server hosttimeout
- The communications timeoutid
- The job ID- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.JobDestroyedException
- If the job doesn't exist (any more).InterruptedException
- If interrupted while waiting.
-
SpallocJob
@MustBeClosed public SpallocJob(String hostname, int port, Integer timeout, int id) throws IOException, SpallocServerException, JobDestroyedException, InterruptedExceptionCreate a job client that resumes an existing job given its ID.- Parameters:
hostname
- The spalloc server hostport
- The TCP porttimeout
- The communications timeoutid
- The job ID- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.JobDestroyedException
- If the job doesn't exist (any more).InterruptedException
- If interrupted while waiting.
-
-
Method Details
-
setConfigurationSource
Set up where configuration settings come from. By default, this is from a file called "spalloc.ini"; this method allows you to override that (e.g., for testing).- Parameters:
filename
- the base filename (without a path) to load the configuration from. This is expected to be a.ini
file.- See Also:
Configuration
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
-
assertCompatibleVersion
protected void assertCompatibleVersion() throws IOException, SpallocServerException, InterruptedExceptionAssert that the server version is compatible. This client supports from 0.4.0 to 2.0.0 (but not including the latter).- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.IllegalStateException
- If the server is not compatible with this client.
-
destroy
public void destroy(String reason) throws IOException, SpallocServerException, InterruptedExceptionDescription copied from interface:SpallocJobAPI
Destroy the job and disconnect from the server.- Specified by:
destroy
in interfaceSpallocJobAPI
- Parameters:
reason
- Gives a human-readable explanation for the destruction of the job.- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
setPower
public void setPower(Boolean powerOn) throws IOException, SpallocServerException, InterruptedExceptionDescription copied from interface:SpallocJobAPI
Turn the boards allocated to the job on or off.Does nothing if the job has not yet been allocated any boards.
The
SpallocJobAPI.waitUntilReady(Integer)
method may be used to wait for the boards to fully turn on or off.- Specified by:
setPower
in interfaceSpallocJobAPI
- Parameters:
powerOn
- true to power on the boards, false to power off. If the boards are already turned on, setting power to true will reset them. Ifnull
, this method does nothing.- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
getID
public int getID()- Specified by:
getID
in interfaceSpallocJobAPI
- Returns:
- The ID of the job.
-
getState
- Specified by:
getState
in interfaceSpallocJobAPI
- Returns:
- The current state of the job.
- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
getPower
- Specified by:
getPower
in interfaceSpallocJobAPI
- Returns:
- The current power state of the job.
- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
getDestroyReason
- Specified by:
getDestroyReason
in interfaceSpallocJobAPI
- Returns:
- The reason for destruction of the job, or
null
if there is no reason (perhaps because the job isn't destroyed). Note that you should useSpallocJobAPI.getState()
to determine if the job is destroyed, not this method. - Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
getConnections
public List<Connection> getConnections() throws IOException, SpallocServerException, InterruptedException- Specified by:
getConnections
in interfaceSpallocJobAPI
- Returns:
- The list of connections, where each connection says what the hostname is to talk to a particular board's root chip.
- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
getHostname
- Specified by:
getHostname
in interfaceSpallocJobAPI
- Returns:
- The name of the host that is the root chip of the whole allocation.
- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
getDimensions
public MachineDimensions getDimensions() throws IOException, SpallocServerException, InterruptedException- Specified by:
getDimensions
in interfaceSpallocJobAPI
- Returns:
- The dimensions of the machine in chips, e.g., for booting.
- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
getMachineName
- Specified by:
getMachineName
in interfaceSpallocJobAPI
- Returns:
- The name of the machine the job is allocated on.
- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
getBoards
public List<BoardCoordinates> getBoards() throws IOException, SpallocServerException, IllegalStateException, InterruptedException- Specified by:
getBoards
in interfaceSpallocJobAPI
- Returns:
- All the boards allocated to the job.
- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.IllegalStateException
- If the spalloc job is not Ready.InterruptedException
- If interrupted while waiting.
-
waitForStateChange
public State waitForStateChange(State oldState, Integer timeout) throws SpallocServerException, InterruptedExceptionDescription copied from interface:SpallocJobAPI
Block until the job's state changes from the supplied state.- Specified by:
waitForStateChange
in interfaceSpallocJobAPI
- Parameters:
oldState
- The current state.timeout
- The number of seconds to wait for a change before timing out. If None, wait forever.- Returns:
- The new state, or old state if timed out.
- Throws:
SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
waitUntilReady
public void waitUntilReady(Integer timeout) throws JobDestroyedException, IOException, SpallocServerException, SpallocStateChangeTimeoutException, InterruptedExceptionDescription copied from interface:SpallocJobAPI
Block until the job is allocated and ready.- Specified by:
waitUntilReady
in interfaceSpallocJobAPI
- Parameters:
timeout
- The number of milliseconds to wait before timing out. If None, wait forever.- Throws:
JobDestroyedException
- If the job was destroyed before becoming ready.IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.SpallocStateChangeTimeoutException
- If the timeout expired before the ready state was entered.InterruptedException
- If interrupted while waiting.
-
whereIs
public BoardPhysicalCoordinates whereIs(HasChipLocation chip) throws IOException, SpallocServerException, InterruptedExceptionDescription copied from interface:SpallocJobAPI
Locates and returns the physical coordinates containing a given chip in a machine allocated to this job.- Specified by:
whereIs
in interfaceSpallocJobAPI
- Parameters:
chip
- The coordinates of the chip- Returns:
- the physical coordinates of the board
- Throws:
IOException
- If communications fail.SpallocServerException
- If the spalloc server rejects the operation request.InterruptedException
- If interrupted while waiting.
-
getClient
- Returns:
- The underlying client, allowing access to non-job-related operations.
-