Interface AgentManager
- All Known Subinterfaces:
LocalAgentManager
- All Known Implementing Classes:
AgentManagerImpl
public interface AgentManager
Manages the
LocalBuildAgent and PipelineDefinition funnily enough. The class is fully synchronized.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidabandonBuild(@NotNull BuildAgent remoteAgent, boolean agentStartingUp) booleanAllow an elastic agent to register and come online?booleanallowNewElasticAgents(int numOfAgentsToCreate) Allow a specified number of elastic agents to register and come online?booleanallowNewElasticAgentWithId(long id) Allow an elastic agent with specific id to register and come online?booleanAllow an ephemeral agent to register and come online?booleanallowNewEphemeralAgentWithId(long id) Allow an ephemeral agent with specific id to register and come online?booleanAllow a local agent to come online?booleanAllow a remote agent to register and come online?booleanallowNewRemoteAgents(int numAgentsToCreate) Allow a specified number of remote agents to register and come online?booleanallowNewRemoteAgentWithId(long id) Allow a remote agent with specific id to register and come online?booleanvoidsets up a default local agent if no local agent existsvoidcreateLocalAgent(LocalAgentDefinition pipelineDefinition) Create a new local agent.voidDisable all pipelinesvoidEnable all pipelinesfindAllAgentsForAgentIds(@NotNull Collection<Long> agentIds) Returns a Map ofPipelineDefinitions keyed by their id@NotNull Collection<BuildAgent>Returns agents that are enabled and online@Nullable BuildAgentgetAgent(long agentId) longgetAgentCount(Class<? extends PipelineDefinition> agentDefinitionClass) Retrieves the amount of agents of given type stored in the database@Nullable PipelineDefinitiongetAgentDefinition(@NotNull Long agentId) @Nullable PipelineDefinitiongetAgentDefinitionByName(@NotNull String name) Deprecated.@NotNull List<PipelineDefinition>getAgentDefinitionsByName(@NotNull String name) RetrievePipelineDefinitions by name.@NotNull List<PipelineDefinition>getAgentDefinitionsWithNameLike(@NotNull String likeName) Return a list of agents whose name is like the provided string.@NotNull List<BuildAgent>@NotNull List<ElasticAgentDefinition>getAllElasticAgentDefinitions(int firstResult, int maxResults) Retrieve most recently terminated elastic agent definitions from db, ordered by termination time, descending.@NotNull List<ElasticAgentDefinition>getAllElasticAgentDefinitions(@NotNull Collection<String> instanceIds) Retrieve elastic agent definitions from db.@NotNull List<LocalBuildAgent>Returns allLocalBuildAgentobjects@NotNull List<BuildAgent>Retrieves a list of all agent definitions stored in the database.@NotNull List<BuildAgent>Gets all remote agents in the system.@NotNull List<BuildAgent>getAllRemoteAgents(boolean onlineOnly) Get remote agents.@NotNull List<BuildAgent>@NotNull Collection<BuildAgent>Gets a collection agents that are currently building or cancelling a build@NotNull Collection<BuildAgent>Returns elastic agents that are enabled and online@NotNull Optional<BuildAgent>getEphemeralAgentByPodName(@NotNull String podName) Returns aBuildAgentby given pod name (if exists).@NotNull List<EphemeralAgentPod>Returns a list of ephemeral agents related pods in any phase present in the connected cluster at the moment of request.@NotNull List<EphemeralAgentPod>Returns a list of ephemeral agents related pods in any phase present in the connected cluster.@NotNull Collection<LocalBuildAgent>Returns local agents that are enabled and onlinegetLocalAgent(long pipelineId) Returns the pipeline that matches the passed idlonggetOfflineAgentCount(Class<? extends PipelineDefinition> agentDefinitionClass) Retrieves the amount of offline agents of given type stored in the database@NotNull List<ElasticAgentDefinition>getOfflineElasticAgentDefinitions(int firstResult, int maxResults) Retrieve offline elastic agents.Retrieves a list of offline elastic agents IDs.Retrieves a list of offline ephemeral agents IDs.Retrieves a list of offline remote agent IDs.@NotNull List<BuildAgent>Retrieve all online elastic build agents.intGet estimated number of pending ephemeral agents.@NotNull Collection<BuildAgent>Returns remote agents that are enabled and onlinevoidInits the local agents Must be ran before any other methods.voidonAgentReturning(@NotNull BuildAgent agent) Performs any other operations required when an agent goes offline, such as updating the status and shutdown time.voidremoveAgent(long agentId) Removes the passed agent (any type)voidremoveEphemeralAgent(long agentId) Removes the agent if the ephemeral one with requested ID is found.voidremoveRemoteAgent(long agentId) Removes a remote agentvoidsaveAnyPipeline(@NotNull PipelineDefinition pipelineDefinition) Stores a pipelinePipelineDefinitionof any type (elastic, local, remote) AgentConfigurationUpdateEvent is fired after the pipeline is savedvoidsaveAnyPipeline(@NotNull PipelineDefinition pipelineDefinition, @Nullable AgentConfigurationUpdatedEventFactory eventFactory) Stores a pipelinePipelineDefinitionof any type (elastic, local, remote)voidsaveElasticPipeline(@NotNull ElasticAgentDefinition pipelineDefinition) Stores the elasticPipelineDefinitionvoidsaveEphemeralPipeline(@NotNull EphemeralAgentDefinition pipelineDefinition) Stores the ephemeralPipelineDefinitionvoidsavePipeline(PipelineDefinition pipelineDefinition) Stores thePipelineDefinition.voidsavePipeline(PipelineDefinition pipelineDefinition, @Nullable AgentConfigurationUpdatedEventFactory eventFactory) Stores thePipelineDefinition.voidsaveReturningElasticPipeline(@NotNull ElasticAgentDefinition elasticDefinition) Stores the elasticPipelineDefinitionof a returning elastic agent.setAgentEnabled(long agentId, boolean enable) voidStarts all currentLocalBuildAgentobjectsvoidstopAgent(@NotNull BuildAgent agent) Performs any other operations required when an agent goes offline, such as updating the status and shutdown time.voidstopEphemeralAgentByPodName(@NotNull String podName) Stops the ephemeral agent with requested pod name.voidStops allLocalBuildAgentbooleanupdateAgentStatusIfResultReturnPossibleAfterServerRestart(long agentId, ResultKey resultKey, String displayName, long deploymentResultId) Checks if agent is capable of 'surviving' a server restart, i.e. if agent exists and is configured to reconnect after server restart, allowing it to return build result produced while the server was down.
-
Field Details
-
DEFAULT_AGENT_NAME
- See Also:
-
-
Method Details
-
createDefaultAgent
void createDefaultAgent()sets up a default local agent if no local agent exists -
initAgents
void initAgents()Inits the local agents Must be ran before any other methods. -
startLocalAgents
void startLocalAgents()Starts all currentLocalBuildAgentobjects -
stopLocalAgents
Stops allLocalBuildAgent- Throws:
InterruptedException
-
getAllLocalAgents
Returns allLocalBuildAgentobjects- Returns:
- A copied collection of
LocalBuildAgentobjects, or an empty collection if none exists.
-
getAllRemoteAgents
Gets all remote agents in the system. They can be offline.- Returns:
- all remote agents.
-
getAllRemoteAgents
Get remote agents.- Parameters:
onlineOnly- - only return those agents which are online currently.- Returns:
-
getAllElasticAgentDefinitions
@NotNull @NotNull List<ElasticAgentDefinition> getAllElasticAgentDefinitions(int firstResult, int maxResults) Retrieve most recently terminated elastic agent definitions from db, ordered by termination time, descending.- Returns:
- list of ElasticAgents
-
getOfflineElasticAgentDefinitions
@NotNull @NotNull List<ElasticAgentDefinition> getOfflineElasticAgentDefinitions(int firstResult, int maxResults) Retrieve offline elastic agents.- Returns:
- list of ElasticAgents
- Since:
- 11.0
-
getAgentCount
Retrieves the amount of agents of given type stored in the database- Parameters:
agentDefinitionClass- agent type- Returns:
- amount of agents
-
getOfflineAgentCount
Retrieves the amount of offline agents of given type stored in the database- Parameters:
agentDefinitionClass- agent type- Returns:
- amount of agents
- Since:
- 11.0
-
getAllElasticAgentDefinitions
@NotNull @NotNull List<ElasticAgentDefinition> getAllElasticAgentDefinitions(@NotNull @NotNull Collection<String> instanceIds) Retrieve elastic agent definitions from db.- Parameters:
instanceIds- the instances ids on which the agents were running- Returns:
- list of ElasticAgents
-
getOnlineElasticAgents
Retrieve all online elastic build agents.- Returns:
-
getAllAgents
-
getAllNonElasticAgents
-
getAllStandardAgents
- Returns:
- all standard agents, i.e. not ephemeral and not elastic
- Since:
- 9.3
-
getBusyBuildAgents
Gets a collection agents that are currently building or cancelling a build- Returns:
- Collection of
BuildAgent
-
getActiveAndEnabledAgents
Returns agents that are enabled and online- Returns:
- Collection of
BuildAgent
-
getRemoteActiveAndEnabledAgents
Returns remote agents that are enabled and online- Returns:
- Collection of
BuildAgent
-
getElasticActiveAndEnabledAgents
Returns elastic agents that are enabled and online- Returns:
- Collection of
BuildAgent
-
getLocalActiveAndEnabledAgents
Returns local agents that are enabled and online- Returns:
- Collection of
LocalBuildAgent
-
savePipeline
Stores thePipelineDefinition. Updates any caches so calls togetLocalAgent(long)will return theLocalBuildAgentreturns with the new definition- Parameters:
pipelineDefinition- - Must not be null
-
savePipeline
void savePipeline(PipelineDefinition pipelineDefinition, @Nullable @Nullable AgentConfigurationUpdatedEventFactory eventFactory) Stores thePipelineDefinition. Updates any caches so calls togetLocalAgent(long)will return theLocalBuildAgentreturns with the new definition- Parameters:
pipelineDefinition- - Must not be nulleventFactory- event factory used to create event sent after the pipeline is saved
-
saveElasticPipeline
Stores the elasticPipelineDefinition- Parameters:
pipelineDefinition- - Must not be null
-
saveEphemeralPipeline
Stores the ephemeralPipelineDefinition- Parameters:
pipelineDefinition- - Must not be null
-
saveReturningElasticPipeline
Stores the elasticPipelineDefinitionof a returning elastic agent.- Parameters:
elasticDefinition- returning elastic agent definition
-
getLocalAgent
Returns the pipeline that matches the passed id- Parameters:
pipelineId-- Returns:
- Matching
LocalBuildAgentobject. Null if pipeline does not exist
-
getAgent
-
getAgentDefinition
-
getEphemeralAgentPods
Returns a list of ephemeral agents related pods in any phase present in the connected cluster at the moment of request.- Returns:
- a List of
EphemeralAgentPod - Since:
- 9.3
-
getEventuallyConsistentEphemeralAgentPods
Returns a list of ephemeral agents related pods in any phase present in the connected cluster. The results may be stale. The desired order of magnitude of delay is seconds.- Returns:
- a List of
EphemeralAgentPod - Since:
- 9.3
-
getPendingEphemeralAgentsEstimatedCount
int getPendingEphemeralAgentsEstimatedCount()Get estimated number of pending ephemeral agents.- Since:
- 9.3
-
getEphemeralAgentByPodName
Returns aBuildAgentby given pod name (if exists).- Since:
- 9.3
-
stopEphemeralAgentByPodName
Stops the ephemeral agent with requested pod name.- Parameters:
podName- name of the pod the ephemeral agent is running on- Since:
- 9.3
-
findAllAgentsForAgentIds
Returns a Map ofPipelineDefinitions keyed by their id- Parameters:
agentIds-- Returns:
- agentMap
-
disableAllAgents
void disableAllAgents()Disable all pipelines -
enableAllAgents
void enableAllAgents()Enable all pipelines -
checkPipelinesAreDisabled
boolean checkPipelinesAreDisabled()- Returns:
- whether or not all pipelines are disabled
-
createLocalAgent
Create a new local agent.- Parameters:
pipelineDefinition-- Throws:
BambooLicenseException
-
removeAgent
Removes the passed agent (any type)- Parameters:
agentId-- Throws:
TimeoutException
-
removeRemoteAgent
void removeRemoteAgent(long agentId) Removes a remote agent- Since:
- 10.1
-
removeEphemeralAgent
void removeEphemeralAgent(long agentId) Removes the agent if the ephemeral one with requested ID is found. If the agent is not ephemeral - nothing happens.- Parameters:
agentId- agent unique identifier- Since:
- 9.3
-
allowNewRemoteAgent
boolean allowNewRemoteAgent()Allow a remote agent to register and come online? Based on licensing restrictions. The method takes into consideration the number of agents "reserved" for pending elastic instances.- Returns:
- true if a new agent is allowed, otherise false
-
allowNewRemoteAgentWithId
boolean allowNewRemoteAgentWithId(long id) Allow a remote agent with specific id to register and come online? Based on licensing restrictions. The method takes into consideration the number of agents "reserved" for pending elastic instances.- Parameters:
id- agent id- Returns:
- true if a new agent is allowed, otherise false
- Since:
- 9.6.0
-
allowNewRemoteAgents
boolean allowNewRemoteAgents(int numAgentsToCreate) Allow a specified number of remote agents to register and come online? Based on licensing restrictions. The method takes into consideration the number of agents "reserved" for pending elastic instances.- Returns:
- true if a specified number agents is allowed, otherise false
-
allowNewElasticAgent
boolean allowNewElasticAgent()Allow an elastic agent to register and come online? Based on licensing restrictions.- Returns:
- true if a new agent is allowed, otherise false
-
allowNewElasticAgentWithId
boolean allowNewElasticAgentWithId(long id) Allow an elastic agent with specific id to register and come online? Based on licensing restrictions.- Parameters:
id- agent id- Returns:
- true if a new agent is allowed, otherise false
- Since:
- 9.6.0
-
allowNewEphemeralAgent
boolean allowNewEphemeralAgent()Allow an ephemeral agent to register and come online? Based on licensing restrictions.- Returns:
- true if a new agent is allowed, otherise false
-
allowNewEphemeralAgentWithId
boolean allowNewEphemeralAgentWithId(long id) Allow an ephemeral agent with specific id to register and come online? Based on licensing restrictions.- Parameters:
id- agent id- Returns:
- true if a new agent is allowed, otherise false
- Since:
- 9.6.0
-
allowNewElasticAgents
boolean allowNewElasticAgents(int numOfAgentsToCreate) Allow a specified number of elastic agents to register and come online? Based on licensing restrictions.- Returns:
- true if a specified number agents is allowed, otherise false
-
allowNewLocalAgent
boolean allowNewLocalAgent()Allow a local agent to come online? Based on licensing restrictions.- Returns:
- true if a new local agent is allowed, otherwise false
-
stopAgent
Performs any other operations required when an agent goes offline, such as updating the status and shutdown time.- Parameters:
agent- to be stopped
-
onAgentReturning
Performs any other operations required when an agent goes offline, such as updating the status and shutdown time. Called when agent re-registered without being marked as offline.- Parameters:
agent- to be stopped
-
getAllPersistedAgentDefinitions
List<PipelineDefinition> getAllPersistedAgentDefinitions()Retrieves a list of all agent definitions stored in the database. -
abandonBuild
-
getAgentDefinitionByName
@Deprecated @Nullable @Nullable PipelineDefinition getAgentDefinitionByName(@NotNull @NotNull String name) Deprecated.since 9.2, usegetAgentDefinitionsByName(String)insteadRetrieve aPipelineDefinitionby name. Names should be unique.- Parameters:
name- of the agent to find- Returns:
- the agent that has the given name.
-
getAgentDefinitionsByName
RetrievePipelineDefinitions by name. Names should be unique. However, duplicates are possible due to not properly handled unsuccessful registration attempts.- Parameters:
name- of the agent to find- Returns:
- the agent that has the given name.
- Since:
- 9.2
-
getAgentDefinitionsWithNameLike
@NotNull @NotNull List<PipelineDefinition> getAgentDefinitionsWithNameLike(@NotNull @NotNull String likeName) Return a list of agents whose name is like the provided string. Uses hibernate's "like" so % to mark wild card.- Parameters:
likeName- the string to match- Returns:
- List of Pipeline Definitions
-
saveAnyPipeline
Stores a pipelinePipelineDefinitionof any type (elastic, local, remote) AgentConfigurationUpdateEvent is fired after the pipeline is saved- Parameters:
pipelineDefinition- - Must not be null
-
saveAnyPipeline
void saveAnyPipeline(@NotNull @NotNull PipelineDefinition pipelineDefinition, @Nullable @Nullable AgentConfigurationUpdatedEventFactory eventFactory) Stores a pipelinePipelineDefinitionof any type (elastic, local, remote)- Parameters:
pipelineDefinition- Must not be nulleventFactory- event factory used to create event sent after the pipeline is saved
-
updateAgentStatusIfResultReturnPossibleAfterServerRestart
boolean updateAgentStatusIfResultReturnPossibleAfterServerRestart(long agentId, ResultKey resultKey, String displayName, long deploymentResultId) Checks if agent is capable of 'surviving' a server restart, i.e. if agent exists and is configured to reconnect after server restart, allowing it to return build result produced while the server was down. Sets agent status to 'building' if it is so.- Returns:
- true iff agents is capable of surviving a server restart.
- Since:
- 5.8
-
setAgentEnabled
-
getOfflineRemoteAgentIds
Retrieves a list of offline remote agent IDs. Offline remote agents are those that are not currently connected to the server.- Returns:
- a list of offline remote agents IDs
- Since:
- 11.0
-
getOfflineElasticAgentIds
Retrieves a list of offline elastic agents IDs. Offline elastic agents are those that are not currently connected to the server.- Returns:
- a list of offline elastic agents IDs
- Since:
- 11.0
-
getOfflineEphemeralAgentIds
Retrieves a list of offline ephemeral agents IDs. Offline ephemeral agents are those that are not currently connected to the server. As ephemeral agents take care of the self-removal once they finish executing the executable they were launched for, this should return only a small portion of agents that couldn't be removed due to errors or temporary unavailability.- Returns:
- a list of offline ephemeral agents IDs
- Since:
- 11.0
-
getAgentDefinitionsByName(String)instead