Class JobAgent

All Implemented Interfaces:
AccessControlled, Identifiable, Nameable, Ownable, Removable, Shareable

public class JobAgent extends CommonItem
This class represents a job agent, which is a program running in another virtual machine on the same or a different server. The job agent is regularly checking the database for jobs that are waiting to be executed. It is not neccessary for a job agent to be registered in the database but if it is the core can provide services that are otherwise inaccesible.
  • Keep track of which plugins are installed on the agent's server
  • Provide information to other clients about what the agent is doing, ie. memory/cpu usage, which plugins that are executing, etc.
  • Priority boosting for plugins that should bypass the queing system.
Version:
2.0
Author:
nicklas
Last modified
$Date: 2017-05-22 14:35:27 +0200 (må, 22 maj 2017) $
  • Field Details

    • log

      private static final Logger log
      Log events.
    • TYPE

      public static final Item TYPE
      The type of item represented by this class.
      See Also:
    • DEFAULT_PORT

      public static final int DEFAULT_PORT
      The default port (47822) where job agents are listening for connections. If 47822 is converted to a hexadecimal number it becomes BACE!
      See Also:
    • MAX_EXTERNAL_ID_LENGTH

      public static final int MAX_EXTERNAL_ID_LENGTH
      The maximum length of the external ID that can be stored in the database.
      See Also:
    • MAX_SERVER_LENGTH

      public static final int MAX_SERVER_LENGTH
      The maximum length of the server name that can be stored in the database.
      See Also:
    • agentInfo

      private static final Map<Integer,JobAgentInfo> agentInfo
  • Constructor Details

  • Method Details

    • getNew

      public static JobAgent getNew(DbControl dc, String externalId) throws BaseException
      Create a new JobAgent item.
      Parameters:
      dc - The DbControl which will be used for permission checking and database access
      externalId - The external ID, which must be unique, for the job agent
      Returns:
      The new JobAgent item
      Throws:
      BaseException - If there is an error
    • getById

      public static JobAgent getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException
      Get a JobAgent object when you know the ID.
      Parameters:
      dc - The DbControl which will be used for permission checking and database access.
      id - The ID of the item to load
      Returns:
      The JobAgent item
      Throws:
      ItemNotFoundException - If an item with the specified ID is not found
      PermissionDeniedException - If the logged in user doesn't have read permission to the item
      BaseException - If there is another error
    • getByExternalId

      public static JobAgent getByExternalId(DbControl dc, String externalId) throws ItemNotFoundException, PermissionDeniedException, BaseException
      Get a JobAgent item when you know the external ID.
      Parameters:
      dc - The DbControl which will be used for permission checking and database access.
      externalId - The external ID of the item to load
      Returns:
      The JobAgent item
      Throws:
      ItemNotFoundException - If an item with the specified ID is not found
      PermissionDeniedException - If the logged in user doesn't have read permission for the item
      BaseException - If there is another error
    • getQuery

      public static ItemQuery<JobAgent> getQuery()
      Get an ItemQuery that returns job agents.
      Returns:
      An ItemQuery object
    • getData

      JobAgentData getData()
      Description copied from class: BasicItem
      Get the BasicData object that holds all data for this item.
      Overrides:
      getData in class CommonItem
    • getType

      public Item getType()
      Description copied from interface: Identifiable
      Get the type of item represented by the object. The returned value is one of the values defined in the Item enumeration.
      Returns:
      A value indicating the type of item
    • getExternalId

      public String getExternalId()
      Get the external id for the job agent. The external id is used to identify each job agent and must be unique.
    • setExternalId

      public void setExternalId(String externalId) throws PermissionDeniedException, InvalidDataException, BaseException
      Set the external id for the job agent.
      Parameters:
      externalId - External id to be set.
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      InvalidDataException - If the new value is longer than MAX_EXTERNAL_ID_LENGTH
      BaseException - If there is another error
    • getServer

      public String getServer()
      Get the name or IP-adress of the server were the job agent is running.
      Returns:
      The name or IP, or null if not known
    • setServer

      public void setServer(String server) throws InvalidDataException, PermissionDeniedException
      Set the name/IP of the server where the job agent is running.
      Parameters:
      server - The name/IP or null if not known
      Throws:
      InvalidDataException - If the new value is longer than MAX_SERVER_LENGTH
      PermissionDeniedException - If the logged in user doesn't have write permission
    • getPort

      public Integer getPort()
      Get the port the job agent is listening on.
      Returns:
      The port number or null if the job agent isn't listening
    • setPort

      public void setPort(Integer port)
      Set the port the job agent is listening on.
      Parameters:
      port - The new port number or null if the job agent isn't listening
    • getInfo

      public JobAgentInfo getInfo()
      Get info about the running job agent. For performance reasons the information is cached and only updated if older than specified by the agent.maxage configuration setting.
      Returns:
      A JobAgentInfo object
    • getConnection

      public JobAgentConnection getConnection(Integer timeout) throws PermissionDeniedException
      Get a connection object for connecting to the job agent. It is only possible to connect to job agents which has specified a server and port.
      Parameters:
      timeout - The timeout for the connection, null will use the default timeout as configued by the agent.connection.timeout setting in the base.config file
      Returns:
      The connection object or null if none could be created
      Throws:
      PermissionDeniedException - If the logged in user doesn't have WRITE permission on the job agent
    • getCpuUsage

      public Integer getCpuUsage()
      Get the current CPU usage in percent of the server where the job agent is running. The CPU usage is not available unless a server name/IP and port has been specified. For performance reasons the CPU usage is cached and only updated if older than specified by the agent.maxage configuration setting.
      Returns:
      The CPU usage of the job agent's server in percent, or null if not known
    • getUsedMemory

      public Long getUsedMemory()
      Get the current memory usage in bytes of the server where the job agent is running. The memory usage is not available unless a server name/IP and port has been specified. For performance reasons the memory usage is cached and only updated if older than specified by the agent.maxage configuration setting.
      Returns:
      The memory usage on the job agent's server, or null if not known
    • getTotalMemory

      public Long getTotalMemory()
      Get the total memory in bytes of the server where the job agent is running. The memory is not available unless a server name/IP and port has been specified. For performance reasons the memory is cached and only updated if older than specified by the agent.maxage configuration setting.
      Returns:
      The memory on the job agent's server, or null if not known
    • getSettings

      public JobAgentSettings getSettings(PluginDefinition plugin, boolean create)
      Get the settings for the specified plugin. If no settings exists a new JobAgentSettings item is created if the create parameter is true. You must call DbControl.saveItem(BasicItem) to save the new settings to the database.
      Parameters:
      plugin - The plugin to the settings for, or null if none exists and the create parameter is false
      create - TRUE if new settings should be created if no one was found, FALSE otherwise.
      Returns:
      A JobAgentSettings object for the specified plugin
    • getSettings

      public JobAgentSettings getSettings(Job job)
      Get the settings for the plugin that is used for the specified job.
      Parameters:
      job - The job to get the settings for
      Returns:
      A JobAgentSettings object or null if not settings exist for the job
    • getSettings

      public ItemQuery<JobAgentSettings> getSettings()
      Get a query that returns all plugin-specific settings for this job agent.
      Returns:
      An ItemQuery object
    • getWaitingJobs

      public ItemQuery<Job> getWaitingJobs()
      Get a query that returns all jobs that are waiting to be executed sorted by their priority taking the priority boost into account.
      Returns:
      An ItemQuery object
    • getAgentInfo

      private static JobAgentInfo getAgentInfo(JobAgent agent)
      Get a JobAgentInfo for a job agent. If the job agent hasn't specified a server and port or if there is an error while connecting to the job agent an empty info object is returned.
      Parameters:
      agent - The job agent to get the info for
      Returns:
      A JobAgentInfo object