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
ConstructorsModifierConstructorDescriptionprotectedV1CompatTask(V1CompatService srv, Reader in, Writer out) Constructor for testing.protectedV1CompatTask(V1CompatService srv, Socket sock) Make an instance that wraps a socket. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidStop any current running notifiers.final booleanRead a message from the client and send a response.protected abstract intcreateJobNumBoards(@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 intcreateJobRectangle(@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 intcreateJobSpecificBoard(@Valid TriadCoords coords, Map<@NotBlank String, @NotNull Object> kwargs, byte[] cmd) Create a job asking for a specific board.protected abstract voiddestroyJob(int jobId, String reason) Destroy a job.protected abstract BoardPhysicalCoordinatesgetBoardAtLogicalPosition(@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 BoardCoordinatesgetBoardAtPhysicalPosition(@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 ExecutorServiceprotected abstract JobMachineInfogetJobMachineInfo(int jobId) Get information about the machine allocated to a job.protected abstract JobStategetJobState(int jobId) Get the state of a job.protected final ObjectMapperprotected final SpallocProperties.CompatibilityPropertiesfinal Stringhost()What host is connected to this service instance?protected abstract voidjobKeepalive(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 voidRequest notification of job status changes.protected abstract voidnotifyMachine(String machineName, boolean wantNotify) Request notification of machine status changes.protected CommandparseCommand(byte[] msg) Parse a command that was saved in the DB.protected CommandparseCommand(String msg) Parse a command from a message.protected abstract voidpowerJobBoards(int jobId, PowerState switchOn) Switch on or off a job's boards.protected abstract voidreportProblem(@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 Stringversion()Get the service version.protected abstract WhereIswhereIsJobChip(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 WhereIswhereIsMachineChip(@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 WhereIswhereIsMachineLogicalBoard(@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 WhereIswhereIsMachinePhysicalBoard(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 voidwriteException(Throwable exn) Send an exception message.protected final voidwriteJobNotification(List<Integer> jobIds) Send a notification about a collection of jobs changing.protected final voidwriteMachineNotification(List<String> machineNames) Send a notification about a collection of machines changing.protected final voidwriteResponse(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
nullif 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:
trueif further messages should be processed,falseif 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 benullto 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 benullto 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,pwill benull. If a whole board has a problem,x,ywill 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.
-