Class V1CompatTask

java.lang.Object
uk.ac.manchester.spinnaker.alloc.compat.V1CompatTask

public abstract class V1CompatTask
extends Object
The core of tasks that handle connections by clients.
Author:
Donal Fellows
  • Constructor Details

    • V1CompatTask

      protected V1CompatTask​(V1CompatService srv, Socket sock) throws IOException
      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

      protected V1CompatTask​(V1CompatService srv, Reader in, Writer out)
      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

      public final String host()
      What host is connected to this service instance?
      Returns:
      The remote host that this task is serving.
    • parseCommand

      protected Command parseCommand​(String msg) throws IOException
      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

      protected Command parseCommand​(byte[] msg)
      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

      protected final void writeResponse​(Object response) throws IOException
      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

      protected final void writeException​(Throwable exn) throws IOException
      Send an exception message.
      Parameters:
      exn - A description of the exception.
      Throws:
      IOException - If network access fails.
    • writeJobNotification

      protected final void writeJobNotification​(List<Integer> jobIds) throws IOException
      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

      protected final void writeMachineNotification​(List<String> machineNames) throws IOException
      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

      public final boolean communicate() throws IOException, InterruptedException
      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 @javax.validation.constraints.Positive int numBoards, Map<@NotBlank String,​@NotNull Object> kwargs, byte[] cmd) throws TaskException
      Create 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 TaskException
      Create 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 TaskException
      Create 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

      protected abstract void destroyJob​(int jobId, String reason) throws TaskException
      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

      protected abstract JobMachineInfo getJobMachineInfo​(int jobId) throws TaskException
      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

      protected abstract JobState getJobState​(int jobId) throws TaskException
      Get the state of a job.
      Parameters:
      jobId - Job identifier.
      Returns:
      State description. Never null.
      Throws:
      TaskException - If anything goes wrong.
    • jobKeepalive

      protected abstract void jobKeepalive​(int jobId) throws TaskException
      Mark a job as still being kept alive.
      Parameters:
      jobId - Job identifier.
      Throws:
      TaskException - If anything goes wrong.
    • listJobs

      protected abstract JobDescription[] listJobs() throws TaskException
      List the jobs.
      Returns:
      Descriptions of jobs on all machines. Never null.
      Throws:
      TaskException - If anything goes wrong.
    • listMachines

      protected abstract Machine[] listMachines() throws TaskException
      List the machines.
      Returns:
      Descriptions of all machines. Never null.
      Throws:
      TaskException - If anything goes wrong.
    • notifyJob

      protected abstract void notifyJob​(Integer jobId, boolean wantNotify) throws TaskException
      Request notification of job status changes. Best effort only.
      Parameters:
      jobId - Job identifier. May be null to talk about any job.
      wantNotify - Whether to enable or disable these notifications.
      Throws:
      TaskException - If anything goes wrong.
    • notifyMachine

      protected abstract void notifyMachine​(String machineName, boolean wantNotify) throws TaskException
      Request notification of machine status changes. Best effort only.
      Parameters:
      machineName - Name of the machine. May be null to talk about any machine.
      wantNotify - Whether to enable or disable these notifications.
      Throws:
      TaskException - If anything goes wrong.
    • powerJobBoards

      protected abstract void powerJobBoards​(int jobId, PowerState switchOn) throws TaskException
      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 be null. If a whole board has a problem, x,y will be null,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

      protected abstract String version() throws TaskException
      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

      protected final ExecutorService getExecutor()
      Returns:
      The executor to use.
    • getJsonMapper

      protected final ObjectMapper getJsonMapper()
      Returns:
      The JSON mapper to use if necessary.
    • getProperties

      protected final SpallocProperties.CompatibilityProperties getProperties()
      Returns:
      The relevant properties.