Package net.sf.basedb.core
Class JobAgent
java.lang.Object
net.sf.basedb.core.BasicItem
net.sf.basedb.core.OwnedItem
net.sf.basedb.core.SharedItem
net.sf.basedb.core.CommonItem
net.sf.basedb.core.JobAgent
- All Implemented Interfaces:
AccessControlled
,Identifiable
,Nameable
,Ownable
,Removable
,Shareable
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 Summary
Modifier and TypeFieldDescriptionprivate static final Map<Integer,
JobAgentInfo> static final int
The default port (47822) where job agents are listening for connections.private static final Logger
Log events.static final int
The maximum length of the external ID that can be stored in the database.static final int
The maximum length of the server name that can be stored in the database.static final Item
The type of item represented by this class.Fields inherited from interface net.sf.basedb.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate static JobAgentInfo
getAgentInfo
(JobAgent agent) Get aJobAgentInfo
for a job agent.static JobAgent
getByExternalId
(DbControl dc, String externalId) Get aJobAgent
item when you know the external ID.static JobAgent
Get aJobAgent
object when you know the ID.getConnection
(Integer timeout) Get a connection object for connecting to the job agent.Get the current CPU usage in percent of the server where the job agent is running.(package private) JobAgentData
getData()
Get theBasicData
object that holds all data for this item.Get the external id for the job agent.getInfo()
Get info about the running job agent.static JobAgent
Create a newJobAgent
item.getPort()
Get the port the job agent is listening on.getQuery()
Get anItemQuery
that returns job agents.Get the name or IP-adress of the server were the job agent is running.Get a query that returns all plugin-specific settings for this job agent.getSettings
(Job job) Get the settings for the plugin that is used for the specified job.getSettings
(PluginDefinition plugin, boolean create) Get the settings for the specified plugin.Get the total memory in bytes of the server where the job agent is running.getType()
Get the type of item represented by the object.Get the current memory usage in bytes of the server where the job agent is running.Get a query that returns all jobs that are waiting to be executed sorted by their priority taking the priority boost into account.void
setExternalId
(String externalId) Set the external id for the job agent.void
Set the port the job agent is listening on.void
Set the name/IP of the server where the job agent is running.Methods inherited from class net.sf.basedb.core.CommonItem
getDescription, getName, getRemovedBy, isRemoved, setDescription, setName, setRemoved
Methods inherited from class net.sf.basedb.core.SharedItem
getItemKey, getProjectKey, initPermissions, isShared, onBeforeCommit, setItemKey, setProjectKey
Methods inherited from class net.sf.basedb.core.OwnedItem
getOwner, isOwner, setOwner, takeOwnership
Methods inherited from class net.sf.basedb.core.BasicItem
addAnnotatableParents, addUsingItems, addUsingItems, breakCircularReferences, checkBatchAnnotatableUsage, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, onRollback, setDbControl, setProjectDefaults, toString, validate
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.sf.basedb.core.AccessControlled
checkPermission, getPermissions, hasPermission
Methods inherited from interface net.sf.basedb.core.Identifiable
getId, getVersion
Methods inherited from interface net.sf.basedb.core.Ownable
getOwner, isOwner, setOwner, takeOwnership
-
Field Details
-
log
Log events. -
TYPE
The type of item represented by this class.- See Also:
-
DEFAULT_PORT
public static final int DEFAULT_PORTThe 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_LENGTHThe maximum length of the external ID that can be stored in the database.- See Also:
-
MAX_SERVER_LENGTH
public static final int MAX_SERVER_LENGTHThe maximum length of the server name that can be stored in the database.- See Also:
-
agentInfo
-
-
Constructor Details
-
JobAgent
JobAgent(JobAgentData data)
-
-
Method Details
-
getNew
Create a newJobAgent
item.- Parameters:
dc
- TheDbControl
which will be used for permission checking and database accessexternalId
- 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 aJobAgent
object when you know the ID.- Parameters:
dc
- TheDbControl
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 foundPermissionDeniedException
- If the logged in user doesn't have read permission to the itemBaseException
- If there is another error
-
getByExternalId
public static JobAgent getByExternalId(DbControl dc, String externalId) throws ItemNotFoundException, PermissionDeniedException, BaseException Get aJobAgent
item when you know the external ID.- Parameters:
dc
- TheDbControl
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 foundPermissionDeniedException
- If the logged in user doesn't have read permission for the itemBaseException
- If there is another error
-
getQuery
Get anItemQuery
that returns job agents.- Returns:
- An
ItemQuery
object
-
getData
JobAgentData getData()Description copied from class:BasicItem
Get theBasicData
object that holds all data for this item.- Overrides:
getData
in classCommonItem
-
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 theItem
enumeration.- Returns:
- A value indicating the type of item
-
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 permissionInvalidDataException
- If the new value is longer thanMAX_EXTERNAL_ID_LENGTH
BaseException
- If there is another error
-
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
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 thanMAX_SERVER_LENGTH
PermissionDeniedException
- If the logged in user doesn't have write permission
-
getPort
Get the port the job agent is listening on.- Returns:
- The port number or null if the job agent isn't listening
-
setPort
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
Get info about the running job agent. For performance reasons the information is cached and only updated if older than specified by theagent.maxage
configuration setting.- Returns:
- A
JobAgentInfo
object
-
getConnection
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 theagent.connection.timeout
setting in thebase.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
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 theagent.maxage
configuration setting.- Returns:
- The CPU usage of the job agent's server in percent, or null if not known
-
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 theagent.maxage
configuration setting.- Returns:
- The memory usage on the job agent's server, or null if not known
-
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 theagent.maxage
configuration setting.- Returns:
- The memory on the job agent's server, or null if not known
-
getSettings
Get the settings for the specified plugin. If no settings exists a newJobAgentSettings
item is created if thecreate
parameter is true. You must callDbControl.saveItem(BasicItem)
to save the new settings to the database.- Parameters:
plugin
- The plugin to the settings for, or null if none exists and thecreate
parameter is falsecreate
- TRUE if new settings should be created if no one was found, FALSE otherwise.- Returns:
- A
JobAgentSettings
object for the specified plugin
-
getSettings
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
Get a query that returns all plugin-specific settings for this job agent.- Returns:
- An
ItemQuery
object
-
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
Get aJobAgentInfo
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
-