Class JobManager

java.lang.Object
uk.ac.manchester.spinnaker.nmpi.jobmanager.JobManager
All Implemented Interfaces:
JobManagerInterface, NMPIQueueListener

@Service("service") public class JobManager extends Object implements NMPIQueueListener, JobManagerInterface
The manager of jobs; synchronises and manages all the ongoing and future processes and machines.
  • Field Details

    • STATUS_UPDATE_PERIOD

      public static final int STATUS_UPDATE_PERIOD
      Seconds between status updates.
      See Also:
  • Constructor Details

    • JobManager

      public JobManager(URL baseUrl)
      Create a job manager.
      Parameters:
      baseUrl - The URL of the REST service of the manager.
  • Method Details

    • addJob

      public void addJob(Job job) throws IOException
      Description copied from interface: NMPIQueueListener
      Adds a job to the listener.
      Specified by:
      addJob in interface NMPIQueueListener
      Parameters:
      job - The job to add.
      Throws:
      IOException - If anything goes wrong.
    • getNextJob

      public Job getNextJob(String executerId)
      Description copied from interface: JobManagerInterface
      Get the job manager to find out what its next job will be.
      Specified by:
      getNextJob in interface JobManagerInterface
      Parameters:
      executerId - The executor to talk about.
      Returns:
      The job discovered.
    • getLargestJobMachine

      public SpinnakerMachine getLargestJobMachine(int id, double runTime)
      Description copied from interface: JobManagerInterface
      Get the largest machine that could run a job.
      Specified by:
      getLargestJobMachine in interface JobManagerInterface
      Parameters:
      id - The job ID.
      runTime - How much resource to allocate. Can be omitted, in which case it is set to -1.
      Returns:
      The machine descriptor.
    • getJobMachine

      public SpinnakerMachine getJobMachine(int id, int nCores, int nChips, int nBoards, double runTime)
      Description copied from interface: JobManagerInterface
      Get a machine for running a job. Typically, only one of nCores, nChips and nBoards will be specified.
      Specified by:
      getJobMachine in interface JobManagerInterface
      Parameters:
      id - The job ID.
      nCores - The number of cores wanted. Can be omitted, in which case it is set to -1.
      nChips - The number of chips wanted. Can be omitted, in which case it is set to -1.
      nBoards - The number of boards wanted. Can be omitted, in which case it is set to -1.
      runTime - How much resource to allocate. Can be omitted, in which case it is set to -1.
      Returns:
      The machine descriptor.
    • releaseMachine

      public void releaseMachine(int id, String machineName)
      Description copied from interface: JobManagerInterface
      Drop the allocation of a machine to a job.
      Specified by:
      releaseMachine in interface JobManagerInterface
      Parameters:
      id - The job ID
      machineName - The name of the machine to stop using.
    • setMachinePower

      public void setMachinePower(int id, String machineName, boolean powerOn)
      Description copied from interface: JobManagerInterface
      Set the power status of a job's machine.
      Specified by:
      setMachinePower in interface JobManagerInterface
      Parameters:
      id - The job ID
      machineName - The name of the machine to control the power of.
      powerOn - True of the machine is to be switched on; false to switch it off.
    • getChipCoordinates

      public ChipCoordinates getChipCoordinates(int id, String machineName, int chipX, int chipY)
      Description copied from interface: JobManagerInterface
      Get a description of where a chip actually is.
      Specified by:
      getChipCoordinates in interface JobManagerInterface
      Parameters:
      id - The job ID
      machineName - The name of the machine to control the power of.
      chipX - The virtual X coordinate of the chip.
      chipY - The virtual Y coordinate of the chip.
      Returns:
      The coordinates of the chip
    • extendJobMachineLease

      public void extendJobMachineLease(int id, double runTime)
      Description copied from interface: JobManagerInterface
      Extend the lease of the job.
      Specified by:
      extendJobMachineLease in interface JobManagerInterface
      Parameters:
      id - The job ID
      runTime - How long has the job actually run. Can be omitted, in which case it is set to -1.
    • checkMachineLease

      public JobMachineAllocated checkMachineLease(int id, int waitTime)
      Description copied from interface: JobManagerInterface
      Check if the job is still allocated to a machine.
      Specified by:
      checkMachineLease in interface JobManagerInterface
      Parameters:
      id - The job ID
      waitTime - How long should the lease time be. Can be omitted, in which case it is set to 1000.
      Returns:
      Whether the job is allocated.
    • appendLog

      public void appendLog(int id, String logToAppend)
      Description copied from interface: JobManagerInterface
      Add to the log of a job.
      Specified by:
      appendLog in interface JobManagerInterface
      Parameters:
      id - The job ID
      logToAppend - The string to append to the log.
    • addOutput

      public void addOutput(String projectId, int id, String output, InputStream input)
      Description copied from interface: JobManagerInterface
      Add to the output files of a job.
      Specified by:
      addOutput in interface JobManagerInterface
      Parameters:
      projectId - The ID of the project owning the job.
      id - The job ID
      output - The name of the file to write to.
      input - The contents of the file, streamed.
    • addProvenance

      public void addProvenance(int id, List<String> path, String value)
      Description copied from interface: JobManagerInterface
      Add to the provenance of a job.
      Specified by:
      addProvenance in interface JobManagerInterface
      Parameters:
      id - The job ID
      path - The path into the JSON provenance doc.
      value - The value to set at that point.
    • setJobFinished

      public void setJobFinished(String projectId, int id, String logToAppend, String baseDirectory, List<String> outputs)
      Description copied from interface: JobManagerInterface
      Mark the job as successfully finished.
      Specified by:
      setJobFinished in interface JobManagerInterface
      Parameters:
      projectId - The ID of the project owning the job.
      id - The id of the job.
      logToAppend - The job log data.
      baseDirectory - The base of filenames.
      outputs - The list of output files.
    • setJobError

      public void setJobError(String projectId, int id, String error, String logToAppend, String baseDirectory, List<String> outputs, RemoteStackTrace stackTrace)
      Description copied from interface: JobManagerInterface
      Mark the job as finished with an error.
      Specified by:
      setJobError in interface JobManagerInterface
      Parameters:
      projectId - The project owning the job.
      id - The id of the job.
      error - The error message.
      logToAppend - The job log data.
      baseDirectory - The base of filenames.
      outputs - The list of output files.
      stackTrace - The stack trace of the exception that caused the error.
    • setExecutorExited

      public void setExecutorExited(String executorId, String logToAppend)
      Mark the executor as having exited.
      Parameters:
      executorId - The ID of the executor in question
      logToAppend - The log messages
    • getJobProcessManager

      public jakarta.ws.rs.core.Response getJobProcessManager()
      Description copied from interface: JobManagerInterface
      Get the implementation code of the Job Process Manager.
      Specified by:
      getJobProcessManager in interface JobManagerInterface
      Returns:
      a response containing the ZIP file.
    • getSetupScript

      public jakarta.ws.rs.core.Response getSetupScript() throws IOException
      Description copied from interface: JobManagerInterface
      Get the setup script to be executed.
      Specified by:
      getSetupScript in interface JobManagerInterface
      Returns:
      a response containing the setup script
      Throws:
      IOException - if something goes wrong