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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
abandonBuild
(@NotNull BuildAgent remoteAgent, boolean agentStartingUp) boolean
Allow an elastic agent to register and come online? Based on licensing restrictions.boolean
allowNewElasticAgents
(int numOfAgentsToCreate) Allow a specified number of elastic agents to register and come online? Based on licensing restrictions.boolean
allowNewElasticAgentWithId
(long id) Allow an elastic agent with specific id to register and come online? Based on licensing restrictions.boolean
Allow an ephemeral agent to register and come online? Based on licensing restrictions.boolean
allowNewEphemeralAgentWithId
(long id) Allow an ephemeral agent with specific id to register and come online? Based on licensing restrictions.boolean
Allow a local agent to come online? Based on licensing restrictions.boolean
Allow a remote agent to register and come online? Based on licensing restrictions.boolean
allowNewRemoteAgents
(int numAgentsToCreate) Allow a specified number of remote agents to register and come online? Based on licensing restrictions.boolean
allowNewRemoteAgentWithId
(long id) Allow a remote agent with specific id to register and come online? Based on licensing restrictions.boolean
void
sets up a default local agent if no local agent existsvoid
createLocalAgent
(LocalAgentDefinition pipelineDefinition) Create a new local agent.void
Disable all pipelinesvoid
Enable all pipelines<T> T
executeIfIdle
(Callable<T> callable) Deprecated.since 9.2 without a replacementfindAllAgentsForAgentIds
(@NotNull Collection<Long> agentIds) Returns a Map ofPipelineDefinition
s keyed by their id@NotNull Collection<BuildAgent>
Returns agents that are enabled and online@Nullable BuildAgent
getAgent
(long agentId) long
getAgentCount
(Class<? extends PipelineDefinition> agentDefinitionClass) Retrieves the amount of agents of given type stored in the database@Nullable PipelineDefinition
getAgentDefinition
(@NotNull Long agentId) @Nullable PipelineDefinition
getAgentDefinitionByName
(@NotNull String name) Deprecated.since 9.2, usegetAgentDefinitionsByName(String)
instead@NotNull List<PipelineDefinition>
getAgentDefinitionsByName
(@NotNull String name) RetrievePipelineDefinition
s 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 allLocalBuildAgent
objects@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 aBuildAgent
by 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 id@NotNull List<BuildAgent>
Retrieve all online elastic build agents.int
Get estimated number of pending ephemeral agents.@NotNull Collection<BuildAgent>
Returns remote agents that are enabled and onlinevoid
Inits the local agents Must be ran before any other methods.void
onAgentReturning
(@NotNull BuildAgent agent) Performs any other operations required when an agent goes offline, such as updating the status and shutdown time.void
removeAgent
(long agentId) Removes the passed agentvoid
removeEphemeralAgent
(long agentId) Removes the agent if the ephemeral one with requested ID is found.void
saveAnyPipeline
(@NotNull PipelineDefinition pipelineDefinition) Stores a pipelinePipelineDefinition
of any type (elastic, local, remote) AgentConfigurationUpdateEvent is fired after the pipeline is savedvoid
saveAnyPipeline
(@NotNull PipelineDefinition pipelineDefinition, @Nullable AgentConfigurationUpdatedEventFactory eventFactory) Stores a pipelinePipelineDefinition
of any type (elastic, local, remote)void
saveElasticPipeline
(@NotNull ElasticAgentDefinition pipelineDefinition) Stores the elasticPipelineDefinition
void
saveEphemeralPipeline
(@NotNull EphemeralAgentDefinition pipelineDefinition) Stores the ephemeralPipelineDefinition
void
savePipeline
(PipelineDefinition pipelineDefinition) Stores thePipelineDefinition
.void
savePipeline
(PipelineDefinition pipelineDefinition, @Nullable AgentConfigurationUpdatedEventFactory eventFactory) Stores thePipelineDefinition
.void
saveReturningElasticPipeline
(@NotNull ElasticAgentDefinition elasticDefinition) Stores the elasticPipelineDefinition
of a returning elastic agent.setAgentEnabled
(long agentId, boolean enable) void
Starts all currentLocalBuildAgent
objectsvoid
stopAgent
(@NotNull BuildAgent agent) Performs any other operations required when an agent goes offline, such as updating the status and shutdown time.void
stopEphemeralAgentByPodName
(@NotNull String podName) Stops the ephemeral agent with requested pod name.void
Stops allLocalBuildAgent
boolean
updateAgentStatusIfResultReturnPossibleAfterServerRestart
(long agentId, ResultKey resultKey, String displayName, long deploymentResultId) Checks if agent is capable of 'surviving' a server restart, i.e.
-
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 currentLocalBuildAgent
objects -
stopLocalAgents
Stops allLocalBuildAgent
- Throws:
InterruptedException
-
getAllLocalAgents
Returns allLocalBuildAgent
objects- Returns:
- A copied collection of
LocalBuildAgent
objects, 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
-
getAgentCount
Retrieves the amount of agents of given type stored in the database- Parameters:
agentDefinitionClass
- agent type- Returns:
- amount of agents
-
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 theLocalBuildAgent
returns 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 theLocalBuildAgent
returns 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 elasticPipelineDefinition
of a returning elastic agent.- Parameters:
elasticDefinition
- returning elastic agent definition
-
getLocalAgent
Returns the pipeline that matches the passed id- Parameters:
pipelineId
-- Returns:
- Matching
LocalBuildAgent
object. 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 aBuildAgent
by 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 ofPipelineDefinition
s 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
-
executeIfIdle
Deprecated.since 9.2 without a replacementExecutes a given
Callable
only if no builds are in progress. Builds are prevented from starting while theCallable
executes.- Parameters:
callable
- theCallable
to be executed- Returns:
- the result of
callable
- Throws:
BambooBusyException
- if builds are in progressException
- if thrown bycallable
-
createLocalAgent
Create a new local agent.- Parameters:
pipelineDefinition
-- Throws:
BambooLicenseException
-
removeAgent
Removes the passed agent- Parameters:
agentId
-- Throws:
TimeoutException
-
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 aPipelineDefinition
by name. Names should be unique.- Parameters:
name
- of the agent to find- Returns:
- the agent that has the given name.
-
getAgentDefinitionsByName
RetrievePipelineDefinition
s 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 pipelinePipelineDefinition
of 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 pipelinePipelineDefinition
of 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
-