Interface AgentManager
-
- All Known Subinterfaces:
LocalAgentManager
- All Known Implementing Classes:
AgentManagerImpl
public interface AgentManager
Manages theLocalBuildAgent
andPipelineDefinition
funnily enough. The class is fully synchronized.
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_AGENT_NAME
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
abandonBuild(@NotNull BuildAgent remoteAgent, boolean agentStartingUp)
boolean
allowNewElasticAgent()
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
allowNewEphemeralAgent()
Allow an ephemeral agent to register and come online? Based on licensing restrictions.boolean
allowNewLocalAgent()
Allow a local agent to come online? Based on licensing restrictions.boolean
allowNewRemoteAgent()
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
checkPipelinesAreDisabled()
void
createDefaultAgent()
sets up a default local agent if no local agent existsvoid
createLocalAgent(LocalAgentDefinition pipelineDefinition)
Create a new local agent.void
disableAllAgents()
Disable all pipelinesvoid
enableAllAgents()
Enable all pipelines<T> T
executeIfIdle(Callable<T> callable)
Executes a givenCallable
only if no builds are in progress.Map<Long,PipelineDefinition>
findAllAgentsForAgentIds(@NotNull Collection<Long> agentIds)
Returns a Map ofPipelineDefinition
s keyed by their id@NotNull Collection<BuildAgent>
getActiveAndEnabledAgents()
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)
Retrieve a pipelineDefinition by name.@NotNull List<PipelineDefinition>
getAgentDefinitionsWithNameLike(@NotNull String likeName)
Return a list of agents whose name is like the provided string.@NotNull List<BuildAgent>
getAllAgents()
@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>
getAllLocalAgents()
Returns allLocalBuildAgent
objects@NotNull List<BuildAgent>
getAllNonElasticAgents()
List<PipelineDefinition>
getAllPersistedAgentDefinitions()
Retrieves a list of all agent definitions stored in the database.@NotNull List<BuildAgent>
getAllRemoteAgents()
Gets all remote agents in the system.@NotNull List<BuildAgent>
getAllRemoteAgents(boolean onlineOnly)
Get remote agents.@NotNull List<BuildAgent>
getAllStandardAgents()
@NotNull Collection<BuildAgent>
getBusyBuildAgents()
Gets a collection agents that are currently building or cancelling a build@NotNull Collection<BuildAgent>
getElasticActiveAndEnabledAgents()
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>
getEphemeralAgentPods()
Returns a list of ephemeral agents related pods in any phase present in the connected cluster at the moment of request.@NotNull List<EphemeralAgentPod>
getEventuallyConsistentEphemeralAgentPods()
Returns a list of ephemeral agents related pods in any phase present in the connected cluster.@NotNull Collection<LocalBuildAgent>
getLocalActiveAndEnabledAgents()
Returns local agents that are enabled and onlineLocalBuildAgent
getLocalAgent(long pipelineId)
Returns the pipeline that matches the passed id@NotNull List<BuildAgent>
getOnlineElasticAgents()
Retrieve all online elastic build agents.int
getPendingEphemeralAgentsEstimatedCount()
Get estimated number of pending ephemeral agents.@NotNull Collection<BuildAgent>
getRemoteActiveAndEnabledAgents()
Returns remote agents that are enabled and onlinevoid
initAgents()
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.Optional<BuildAgent>
setAgentEnabled(long agentId, boolean enable)
void
startLocalAgents()
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
stopLocalAgents()
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 Detail
-
DEFAULT_AGENT_NAME
static final String DEFAULT_AGENT_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
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
void stopLocalAgents() throws InterruptedException
Stops allLocalBuildAgent
- Throws:
InterruptedException
-
getAllLocalAgents
@NotNull @NotNull List<LocalBuildAgent> getAllLocalAgents()
Returns allLocalBuildAgent
objects- Returns:
- A copied collection of
LocalBuildAgent
objects, or an empty collection if none exists.
-
getAllRemoteAgents
@NotNull @NotNull List<BuildAgent> getAllRemoteAgents()
Gets all remote agents in the system. They can be offline.- Returns:
- all remote agents.
-
getAllRemoteAgents
@NotNull @NotNull List<BuildAgent> getAllRemoteAgents(boolean onlineOnly)
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
long getAgentCount(Class<? extends PipelineDefinition> agentDefinitionClass)
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
@NotNull @NotNull List<BuildAgent> getOnlineElasticAgents()
Retrieve all online elastic build agents.- Returns:
-
getAllAgents
@NotNull @NotNull List<BuildAgent> getAllAgents()
-
getAllNonElasticAgents
@NotNull @NotNull List<BuildAgent> getAllNonElasticAgents()
-
getAllStandardAgents
@NotNull @NotNull List<BuildAgent> getAllStandardAgents()
- Returns:
- all standard agents, i.e. not ephemeral and not elastic
- Since:
- 9.3
-
getBusyBuildAgents
@NotNull @NotNull Collection<BuildAgent> getBusyBuildAgents()
Gets a collection agents that are currently building or cancelling a build- Returns:
- Collection of
BuildAgent
-
getActiveAndEnabledAgents
@NotNull @NotNull Collection<BuildAgent> getActiveAndEnabledAgents()
Returns agents that are enabled and online- Returns:
- Collection of
BuildAgent
-
getRemoteActiveAndEnabledAgents
@NotNull @NotNull Collection<BuildAgent> getRemoteActiveAndEnabledAgents()
Returns remote agents that are enabled and online- Returns:
- Collection of
BuildAgent
-
getElasticActiveAndEnabledAgents
@NotNull @NotNull Collection<BuildAgent> getElasticActiveAndEnabledAgents()
Returns elastic agents that are enabled and online- Returns:
- Collection of
BuildAgent
-
getLocalActiveAndEnabledAgents
@NotNull @NotNull Collection<LocalBuildAgent> getLocalActiveAndEnabledAgents()
Returns local agents that are enabled and online- Returns:
- Collection of
LocalBuildAgent
-
savePipeline
void savePipeline(PipelineDefinition pipelineDefinition)
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
void saveElasticPipeline(@NotNull @NotNull ElasticAgentDefinition pipelineDefinition)
Stores the elasticPipelineDefinition
- Parameters:
pipelineDefinition
- - Must not be null
-
saveEphemeralPipeline
void saveEphemeralPipeline(@NotNull @NotNull EphemeralAgentDefinition pipelineDefinition)
Stores the ephemeralPipelineDefinition
- Parameters:
pipelineDefinition
- - Must not be null
-
saveReturningElasticPipeline
void saveReturningElasticPipeline(@NotNull @NotNull ElasticAgentDefinition elasticDefinition)
Stores the elasticPipelineDefinition
of a returning elastic agent.- Parameters:
elasticDefinition
- returning elastic agent definition
-
getLocalAgent
LocalBuildAgent getLocalAgent(long pipelineId)
Returns the pipeline that matches the passed id- Parameters:
pipelineId
-- Returns:
- Matching
LocalBuildAgent
object. Null if pipeline does not exist
-
getAgent
@Nullable @Nullable BuildAgent getAgent(long agentId)
-
getAgentDefinition
@Nullable @Nullable PipelineDefinition getAgentDefinition(@NotNull @NotNull Long agentId)
-
getEphemeralAgentPods
@NotNull @NotNull List<EphemeralAgentPod> 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
@NotNull @NotNull List<EphemeralAgentPod> 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
@NotNull @NotNull Optional<BuildAgent> getEphemeralAgentByPodName(@NotNull @NotNull String podName)
Returns aBuildAgent
by given pod name (if exists).- Since:
- 9.3
-
stopEphemeralAgentByPodName
void stopEphemeralAgentByPodName(@NotNull @NotNull String podName)
Stops the ephemeral agent with requested pod name.- Parameters:
podName
- name of the pod the ephemeral agent is running on- Since:
- 9.3
-
findAllAgentsForAgentIds
Map<Long,PipelineDefinition> findAllAgentsForAgentIds(@NotNull @NotNull Collection<Long> agentIds)
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
<T> T executeIfIdle(Callable<T> callable) throws Exception
Executes 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
void createLocalAgent(LocalAgentDefinition pipelineDefinition) throws BambooLicenseException
Create a new local agent.- Parameters:
pipelineDefinition
-- Throws:
BambooLicenseException
-
removeAgent
void removeAgent(long agentId) throws TimeoutException
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
-
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
-
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
-
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
void stopAgent(@NotNull @NotNull BuildAgent agent)
Performs any other operations required when an agent goes offline, such as updating the status and shutdown time.- Parameters:
agent
- to be stopped
-
onAgentReturning
void onAgentReturning(@NotNull @NotNull BuildAgent agent)
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
void abandonBuild(@NotNull @NotNull BuildAgent remoteAgent, boolean agentStartingUp)
-
getAgentDefinitionByName
@Nullable @Nullable PipelineDefinition getAgentDefinitionByName(@NotNull @NotNull String name)
Retrieve a pipelineDefinition by name. Names should be unique.- Parameters:
name
- of the agent to find- Returns:
- the agent that has the given name.
-
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
void saveAnyPipeline(@NotNull @NotNull PipelineDefinition pipelineDefinition)
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
Optional<BuildAgent> setAgentEnabled(long agentId, boolean enable)
-
-