Class V1CompatTask
java.lang.Object
uk.ac.manchester.spinnaker.alloc.compat.V1CompatTask
The core of tasks that handle connections by clients.
- Author:
- Donal Fellows
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
V1CompatTask
(V1CompatService srv, Reader in, Writer out) Constructor for testing.protected
V1CompatTask
(V1CompatService srv, Socket sock) Make an instance that wraps a socket. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
Stop any current running notifiers.final boolean
Read a message from the client and send a response.protected abstract int
createJobNumBoards
(@jakarta.validation.constraints.Positive int numBoards, Map<@NotBlank String, @NotNull Object> kwargs, byte[] cmd) Create a job asking for a number of boards.protected abstract int
createJobRectangle
(@uk.ac.manchester.spinnaker.machine.board.ValidTriadWidth int width, @uk.ac.manchester.spinnaker.machine.board.ValidTriadHeight int height, Map<@NotBlank String, @NotNull Object> kwargs, byte[] cmd) Create a job asking for a rectangle of boards.protected abstract int
createJobSpecificBoard
(@Valid TriadCoords coords, Map<@NotBlank String, @NotNull Object> kwargs, byte[] cmd) Create a job asking for a specific board.protected abstract void
destroyJob
(int jobId, String reason) Destroy a job.protected abstract BoardPhysicalCoordinates
getBoardAtLogicalPosition
(@NotBlank String machineName, @uk.ac.manchester.spinnaker.machine.board.ValidTriadX int x, @uk.ac.manchester.spinnaker.machine.board.ValidTriadY int y, @uk.ac.manchester.spinnaker.machine.board.ValidTriadZ int z) Get the physical location of a board at given coordinates.protected abstract BoardCoordinates
getBoardAtPhysicalPosition
(@NotBlank String machineName, @uk.ac.manchester.spinnaker.machine.board.ValidCabinetNumber int cabinet, @uk.ac.manchester.spinnaker.machine.board.ValidFrameNumber int frame, @uk.ac.manchester.spinnaker.machine.board.ValidBoardNumber int board) Get the coordinates of a board at a physical location.protected final ExecutorService
protected abstract JobMachineInfo
getJobMachineInfo
(int jobId) Get information about the machine allocated to a job.protected abstract JobState
getJobState
(int jobId) Get the state of a job.protected final ObjectMapper
protected final SpallocProperties.CompatibilityProperties
final String
host()
What host is connected to this service instance?protected abstract void
jobKeepalive
(int jobId) Mark a job as still being kept alive.protected abstract JobDescription[]
listJobs()
List the jobs.protected abstract Machine[]
List the machines.protected abstract void
Request notification of job status changes.protected abstract void
notifyMachine
(String machineName, boolean wantNotify) Request notification of machine status changes.protected Command
parseCommand
(byte[] msg) Parse a command that was saved in the DB.protected Command
parseCommand
(String msg) Parse a command from a message.protected abstract void
powerJobBoards
(int jobId, PowerState switchOn) Switch on or off a job's boards.protected abstract void
reportProblem
(@IPAddress String address, @ValidX Integer x, @ValidY Integer y, @ValidP Integer p, String description) Report a problem with a board, chip or core.protected abstract String
version()
Get the service version.protected abstract WhereIs
whereIsJobChip
(int jobId, @uk.ac.manchester.spinnaker.machine.ValidX int x, @uk.ac.manchester.spinnaker.machine.ValidY int y) Describe where a chip is within a job.protected abstract WhereIs
whereIsMachineChip
(@NotBlank String machineName, @uk.ac.manchester.spinnaker.machine.ValidX int x, @uk.ac.manchester.spinnaker.machine.ValidY int y) Describe where a chip is within a machine.protected abstract WhereIs
whereIsMachineLogicalBoard
(@NotBlank String machineName, @uk.ac.manchester.spinnaker.machine.board.ValidTriadX int x, @uk.ac.manchester.spinnaker.machine.board.ValidTriadY int y, @uk.ac.manchester.spinnaker.machine.board.ValidTriadZ int z) Describe where a board is within a machine.protected abstract WhereIs
whereIsMachinePhysicalBoard
(String machineName, @uk.ac.manchester.spinnaker.machine.board.ValidCabinetNumber int cabinet, @uk.ac.manchester.spinnaker.machine.board.ValidFrameNumber int frame, @uk.ac.manchester.spinnaker.machine.board.ValidBoardNumber int board) Describe where a board is within a machine.protected final void
writeException
(Throwable exn) Send an exception message.protected final void
writeJobNotification
(List<Integer> jobIds) Send a notification about a collection of jobs changing.protected final void
writeMachineNotification
(List<String> machineNames) Send a notification about a collection of machines changing.protected final void
writeResponse
(Object response) Send a response message.
-
Constructor Details
-
V1CompatTask
Make an instance that wraps a socket.- Parameters:
srv
- The overall service, used for looking up shared resources that are uncomfortable as beans.sock
- The socket that talks to the client.- Throws:
IOException
- If access to the socket fails.
-
V1CompatTask
Constructor for testing. Makes a task that isn't connected to a socket.- Parameters:
srv
- The overall service, used for looking up shared resources that are uncomfortable as beans.in
- Input to the task.out
- Output to the task.
-
-
Method Details
-
closeNotifiers
protected abstract void closeNotifiers()Stop any current running notifiers. -
host
What host is connected to this service instance?- Returns:
- The remote host that this task is serving.
-
parseCommand
Parse a command from a message.- Parameters:
msg
- The message to parse.- Returns:
- The command.
- Throws:
IOException
- If the message doesn't contain a valid command.
-
parseCommand
Parse a command that was saved in the DB.- Parameters:
msg
- The saved command to parse.- Returns:
- The command, or
null
if the message can't be parsed.
-
writeResponse
Send a response message.- Parameters:
response
- The body object of the response.- Throws:
IOException
- If network access fails, or the object isn't serializable as JSON or a suitable primitive.
-
writeException
Send an exception message.- Parameters:
exn
- A description of the exception.- Throws:
IOException
- If network access fails.
-
writeJobNotification
Send a notification about a collection of jobs changing.- Parameters:
jobIds
- The jobs that have changed. (Usually all jobs.)- Throws:
IOException
- If network access fails.
-
writeMachineNotification
Send a notification about a collection of machines changing.- Parameters:
machineNames
- The machines that have changed. (Usually all machines.)- Throws:
IOException
- If network access fails.
-
communicate
Read a message from the client and send a response.- Returns:
true
if further messages should be processed,false
if the connection should be closed.- Throws:
IOException
- If network access fails.InterruptedException
- If interrupted (happens on service shutdown).
-
createJobNumBoards
protected abstract int createJobNumBoards(@Positive @jakarta.validation.constraints.Positive int numBoards, Map<@NotBlank String, @NotNull Object> kwargs, byte[] cmd) throws TaskExceptionCreate a job asking for a number of boards.- Parameters:
numBoards
- Number of boards.kwargs
- Keyword argument map.cmd
- The actual command, as serialised JSON.- Returns:
- Job identifier.
- Throws:
TaskException
- If anything goes wrong.
-
createJobRectangle
protected abstract int createJobRectangle(@ValidTriadWidth @uk.ac.manchester.spinnaker.machine.board.ValidTriadWidth int width, @ValidTriadHeight @uk.ac.manchester.spinnaker.machine.board.ValidTriadHeight int height, Map<@NotBlank String, @NotNull Object> kwargs, byte[] cmd) throws TaskExceptionCreate a job asking for a rectangle of boards.- Parameters:
width
- Width of rectangle in triads.height
- Height of rectangle in triads.kwargs
- Keyword argument map.cmd
- The actual command, as serialised JSON.- Returns:
- Job identifier.
- Throws:
TaskException
- If anything goes wrong.
-
createJobSpecificBoard
protected abstract int createJobSpecificBoard(@Valid @Valid TriadCoords coords, Map<@NotBlank String, @NotNull Object> kwargs, byte[] cmd) throws TaskExceptionCreate a job asking for a specific board.- Parameters:
coords
- Which board, by its logical coordinates.kwargs
- Keyword argument map.cmd
- The actual command, as serialised JSON.- Returns:
- Job identifier. Never
null
. - Throws:
TaskException
- If anything goes wrong.
-
destroyJob
Destroy a job.- Parameters:
jobId
- Job identifier.reason
- Why the machine is being destroyed.- Throws:
TaskException
- If anything goes wrong.
-
getBoardAtPhysicalPosition
protected abstract BoardCoordinates getBoardAtPhysicalPosition(@NotBlank @NotBlank String machineName, @ValidCabinetNumber @uk.ac.manchester.spinnaker.machine.board.ValidCabinetNumber int cabinet, @ValidFrameNumber @uk.ac.manchester.spinnaker.machine.board.ValidFrameNumber int frame, @ValidBoardNumber @uk.ac.manchester.spinnaker.machine.board.ValidBoardNumber int board) throws TaskException Get the coordinates of a board at a physical location.- Parameters:
machineName
- Name of the machine.cabinet
- Cabinet number.frame
- Frame number.board
- Board number.- Returns:
- Logical location. Never
null
. - Throws:
TaskException
- If anything goes wrong.
-
getBoardAtLogicalPosition
protected abstract BoardPhysicalCoordinates getBoardAtLogicalPosition(@NotBlank @NotBlank String machineName, @ValidTriadX @uk.ac.manchester.spinnaker.machine.board.ValidTriadX int x, @ValidTriadY @uk.ac.manchester.spinnaker.machine.board.ValidTriadY int y, @ValidTriadZ @uk.ac.manchester.spinnaker.machine.board.ValidTriadZ int z) throws TaskException Get the physical location of a board at given coordinates.- Parameters:
machineName
- Name of the machine.x
- Triad X coordinate.y
- Triad Y coordinate.z
- Triad Z coordinate.- Returns:
- Physical location. Never
null
. - Throws:
TaskException
- If anything goes wrong.
-
getJobMachineInfo
Get information about the machine allocated to a job.- Parameters:
jobId
- Job identifier.- Returns:
- Description of job's (sub)machine. Never
null
. - Throws:
TaskException
- If anything goes wrong.
-
getJobState
Get the state of a job.- Parameters:
jobId
- Job identifier.- Returns:
- State description. Never
null
. - Throws:
TaskException
- If anything goes wrong.
-
jobKeepalive
Mark a job as still being kept alive.- Parameters:
jobId
- Job identifier.- Throws:
TaskException
- If anything goes wrong.
-
listJobs
List the jobs.- Returns:
- Descriptions of jobs on all machines. Never
null
. - Throws:
TaskException
- If anything goes wrong.
-
listMachines
List the machines.- Returns:
- Descriptions of all machines. Never
null
. - Throws:
TaskException
- If anything goes wrong.
-
notifyJob
Request notification of job status changes. Best effort only.- Parameters:
jobId
- Job identifier. May benull
to talk about any job.wantNotify
- Whether to enable or disable these notifications.- Throws:
TaskException
- If anything goes wrong.
-
notifyMachine
Request notification of machine status changes. Best effort only.- Parameters:
machineName
- Name of the machine. May benull
to talk about any machine.wantNotify
- Whether to enable or disable these notifications.- Throws:
TaskException
- If anything goes wrong.
-
powerJobBoards
Switch on or off a job's boards.- Parameters:
jobId
- Job identifier.switchOn
- Whether to switch on.- Throws:
TaskException
- If anything goes wrong.
-
reportProblem
protected abstract void reportProblem(@IPAddress @IPAddress String address, @ValidX @ValidX Integer x, @ValidY @ValidY Integer y, @ValidP @ValidP Integer p, String description) Report a problem with a board, chip or core. If a whole chip has a problem,p
will benull
. If a whole board has a problem,x,y
will benull,null
.- Parameters:
address
- The board's IP address.x
- The chip's X coordinate.y
- The chip's Y coordinate.p
- The core's P coordinate.description
- Optional descriptive text about the problem.
-
version
Get the service version.- Returns:
- The service version. Never
null
. - Throws:
TaskException
- If anything goes wrong.
-
whereIsJobChip
protected abstract WhereIs whereIsJobChip(int jobId, @ValidX @uk.ac.manchester.spinnaker.machine.ValidX int x, @ValidY @uk.ac.manchester.spinnaker.machine.ValidY int y) throws TaskException Describe where a chip is within a job.- Parameters:
jobId
- Job identifier.x
- Chip X coordinate.y
- Chip Y coordinate.- Returns:
- Descriptor. Never
null
. - Throws:
TaskException
- If anything goes wrong.
-
whereIsMachineChip
protected abstract WhereIs whereIsMachineChip(@NotBlank @NotBlank String machineName, @ValidX @uk.ac.manchester.spinnaker.machine.ValidX int x, @ValidY @uk.ac.manchester.spinnaker.machine.ValidY int y) throws TaskException Describe where a chip is within a machine.- Parameters:
machineName
- Name of the machine.x
- Chip X coordinate.y
- Chip Y coordinate.- Returns:
- Descriptor. Never
null
. - Throws:
TaskException
- If anything goes wrong.
-
whereIsMachineLogicalBoard
protected abstract WhereIs whereIsMachineLogicalBoard(@NotBlank @NotBlank String machineName, @ValidTriadX @uk.ac.manchester.spinnaker.machine.board.ValidTriadX int x, @ValidTriadY @uk.ac.manchester.spinnaker.machine.board.ValidTriadY int y, @ValidTriadZ @uk.ac.manchester.spinnaker.machine.board.ValidTriadZ int z) throws TaskException Describe where a board is within a machine.- Parameters:
machineName
- Name of the machine.x
- Triad X coordinate.y
- Triad Y coordinate.z
- Triad Z coordinate.- Returns:
- Descriptor. Never
null
. - Throws:
TaskException
- If anything goes wrong.
-
whereIsMachinePhysicalBoard
protected abstract WhereIs whereIsMachinePhysicalBoard(String machineName, @ValidCabinetNumber @uk.ac.manchester.spinnaker.machine.board.ValidCabinetNumber int cabinet, @ValidFrameNumber @uk.ac.manchester.spinnaker.machine.board.ValidFrameNumber int frame, @ValidBoardNumber @uk.ac.manchester.spinnaker.machine.board.ValidBoardNumber int board) throws TaskException Describe where a board is within a machine.- Parameters:
machineName
- Name of the machine.cabinet
- Cabinet number.frame
- Frame number.board
- Board number.- Returns:
- Descriptor. Never
null
. - Throws:
TaskException
- If anything goes wrong.
-
getExecutor
- Returns:
- The executor to use.
-
getJsonMapper
- Returns:
- The JSON mapper to use if necessary.
-
getProperties
- Returns:
- The relevant properties.
-