Class MachineStateControl


@Service public class MachineStateControl extends DatabaseAwareBean
How to manage the state of a machine and boards in it.
Author:
Donal Fellows
  • Constructor Details

    • MachineStateControl

      public MachineStateControl()
  • Method Details

    • findId

      public Optional<MachineStateControl.BoardState> findId(int id)
      Look up a board for management.
      Parameters:
      id - The unique ID of the board. Because this is fully unique, the machine name is not needed.
      Returns:
      Board state manager
    • findTriad

      public Optional<MachineStateControl.BoardState> findTriad(@NotBlank @NotBlank String machine, @Valid @NonNull @Valid TriadCoords coords)
      Look up a board for management.
      Parameters:
      machine - The name of the machine.
      coords - Triad coordinates
      Returns:
      Board state manager
    • findPhysical

      public Optional<MachineStateControl.BoardState> findPhysical(@NotBlank @NotBlank String machine, @Valid @NotNull @Valid @NotNull PhysicalCoords coords)
      Look up a board for management.
      Parameters:
      machine - The name of the machine.
      coords - Physical coordinates
      Returns:
      Board state manager
    • findIP

      public Optional<MachineStateControl.BoardState> findIP(@NotBlank @NotBlank String machine, @IPAddress @IPAddress String address)
      Look up a board for management.
      Parameters:
      machine - The name of the machine.
      address - Board IP address
      Returns:
      Board state manager
    • getMachineTagging

      public List<MachineTagging> getMachineTagging()
      Returns:
      The mapping from machine names+IDs to tags.
    • getMachineReports

      public Map<String,List<BoardIssueReport>> getMachineReports()
      Returns:
      The unacknowledged reports about boards with potential problems in existing machines, categorised by machine.
    • updateTags

      public void updateTags(@NotBlank @NotBlank String machineName, Set<@NotBlank String> tags)
      Replace the tags on a machine with a given set.
      Parameters:
      machineName - The name of the machine to update the tags of.
      tags - The tags to apply. Existing tags will be removed.
      Throws:
      IllegalArgumentException - If the machine with that name doesn't exist.
    • setMachineState

      public void setMachineState(@NotBlank @NotBlank String machineName, boolean inService)
      Sets whether a machine is in service.
      Parameters:
      machineName - The name of the machine to control
      inService - Whether to put the machine in or out of service.
    • pullBlacklist

      public Optional<Blacklist> pullBlacklist(int boardId, int bmpId)
      Retrieve the blacklist for the given board from the board and store it in the database.
      Parameters:
      boardId - The board to get the blacklist of.
      bmpId - The BMP of the board.
      Returns:
      The blacklist that was transferred, if any.
    • pushBlacklist

      public Optional<Blacklist> pushBlacklist(MachineStateControl.BoardState board)
      Take the blacklist for the given board in the database and write it to the board.
      Parameters:
      board - The board to set the blacklist of.
      Returns:
      The blacklist that was transferred, if any.
    • readAllBoardSerialNumbers

      public void readAllBoardSerialNumbers(@NotBlank @NotBlank String machineName)
      Ensure that the database has the actual serial numbers of all boards in a machine.
      Parameters:
      machineName - Which machine to read the serial numbers of.
    • updateAllBlacklists

      public void updateAllBlacklists(@NotBlank @NotBlank String machineName)
      Retrieve all blacklists, parse them, and store them in the DB's model.
      Parameters:
      machineName - Which machine to get the blacklists of.
    • readBlacklistFromDB

      public Optional<Blacklist> readBlacklistFromDB(MachineStateControl.BoardState board)
      Given a board, read its blacklist from the database.
      Parameters:
      board - Which board to read the blacklist of.
      Returns:
      The board's blacklist.
      Throws:
      DataAccessException - If access to the DB fails.
    • writeBlacklistToDB

      public void writeBlacklistToDB(int boardId, @Valid @Valid Blacklist blacklist)
      Given a board, write a blacklist for it to the database. Does not push the blacklist to the board.
      Parameters:
      boardId - The ID of the board to write.
      blacklist - The blacklist to write.
      Throws:
      DataAccessException - If access to the DB fails.
    • readBlacklistFromMachine

      public Optional<Blacklist> readBlacklistFromMachine(int boardId, int bmpId) throws InterruptedException
      Given a board, read its blacklist off the machine.
      Parameters:
      boardId - Which board to read the blacklist of.
      bmpId - The BMP of the board.
      Returns:
      The board's blacklist.
      Throws:
      DataAccessException - If access to the DB fails.
      MachineStateControl.MachineStateException - If the read fails.
      InterruptedException - If interrupted.
    • writeBlacklistToMachine

      public void writeBlacklistToMachine(int boardId, int bmpId, @Valid @Valid Blacklist blacklist) throws InterruptedException
      Write a blacklist to a board on the machine.
      Parameters:
      boardId - Which board to write the blacklist of.
      bmpId - Which BMP the board belongs to.
      blacklist - The blacklist to write.
      Throws:
      DataAccessException - If access to the DB fails.
      MachineStateControl.MachineStateException - If the write fails.
      InterruptedException - If interrupted. Note that interrupting the thread does not necessarily halt the write of the blacklist.
    • getSerialNumber

      public String getSerialNumber(MachineStateControl.BoardState board) throws InterruptedException
      Read the serial number off a board.
      Parameters:
      board - Which board to get the serial number of.
      Returns:
      The serial number.
      Throws:
      DataAccessException - If access to the DB fails.
      MachineStateControl.MachineStateException - If the write fails.
      InterruptedException - If interrupted.
    • readTemperatureFromMachine

      public Optional<ADCInfo> readTemperatureFromMachine(int boardId, int bmpId) throws InterruptedException
      Given a board, read its temperature data off the machine.
      Parameters:
      boardId - Which board to read the temperature data of.
      bmpId - The BMP that controls the board.
      Returns:
      The board's temperature data.
      Throws:
      DataAccessException - If access to the DB fails.
      MachineStateControl.MachineStateException - If the read fails.
      InterruptedException - If interrupted.
    • isBlacklistSynched

      public boolean isBlacklistSynched(MachineStateControl.BoardState board)
      Test whether a board's blacklist is believed to be synchronised to the hardware.
      Parameters:
      board - Which board?
      Returns:
      True if the synch has happened, i.e., the time the blacklist data was changed is no later than the last time the synch happened.