Interface AgentManager
-
- All Known Subinterfaces:
LocalAgentManager
- All Known Implementing Classes:
AgentManagerImpl
public interface AgentManagerManages theLocalBuildAgentandPipelineDefinitionfunnily enough. The class is fully synchronized.
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_AGENT_NAME
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidabandonBuild(@NotNull BuildAgent remoteAgent, boolean agentStartingUp)booleanallowNewElasticAgent()Allow an elastic agent to register and come online? Based on licensing restrictions.booleanallowNewElasticAgents(int numOfAgentsToCreate)Allow a specified number of elastic agents to register and come online? Based on licensing restrictions.booleanallowNewEphemeralAgent()Allow an ephemeral agent to register and come online? Based on licensing restrictions.booleanallowNewLocalAgent()Allow a local agent to come online? Based on licensing restrictions.booleanallowNewRemoteAgent()Allow a remote agent to register and come online? Based on licensing restrictions.booleanallowNewRemoteAgents(int numAgentsToCreate)Allow a specified number of remote agents to register and come online? Based on licensing restrictions.booleancheckPipelinesAreDisabled()voidcreateDefaultAgent()sets up a default local agent if no local agent existsvoidcreateLocalAgent(LocalAgentDefinition pipelineDefinition)Create a new local agent.voiddisableAllAgents()Disable all pipelinesvoidenableAllAgents()Enable all pipelines<T> TexecuteIfIdle(Callable<T> callable)Executes a givenCallableonly if no builds are in progress.Map<Long,PipelineDefinition>findAllAgentsForAgentIds(@NotNull Collection<Long> agentIds)Returns a Map ofPipelineDefinitions keyed by their id@NotNull Collection<BuildAgent>getActiveAndEnabledAgents()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)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 allLocalBuildAgentobjects@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 aBuildAgentby 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 onlineLocalBuildAgentgetLocalAgent(long pipelineId)Returns the pipeline that matches the passed id@NotNull List<BuildAgent>getOnlineElasticAgents()Retrieve all online elastic build agents.intgetPendingEphemeralAgentsEstimatedCount()Get estimated number of pending ephemeral agents.@NotNull Collection<BuildAgent>getRemoteActiveAndEnabledAgents()Returns remote agents that are enabled and onlinevoidinitAgents()Inits 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 agentvoidremoveEphemeralAgent(long agentId)Removes the agent if the ephemeral one with requested ID is found.voidsaveAnyPipeline(@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.Optional<BuildAgent>setAgentEnabled(long agentId, boolean enable)voidstartLocalAgents()Starts 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.voidstopLocalAgents()Stops allLocalBuildAgentbooleanupdateAgentStatusIfResultReturnPossibleAfterServerRestart(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 currentLocalBuildAgentobjects
-
stopLocalAgents
void stopLocalAgents() throws InterruptedExceptionStops allLocalBuildAgent- Throws:
InterruptedException
-
getAllLocalAgents
@NotNull @NotNull List<LocalBuildAgent> getAllLocalAgents()
Returns allLocalBuildAgentobjects- Returns:
- A copied collection of
LocalBuildAgentobjects, 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 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
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 elasticPipelineDefinitionof 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
LocalBuildAgentobject. 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 aBuildAgentby 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 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
-
executeIfIdle
<T> T executeIfIdle(Callable<T> callable) throws Exception
Executes a given
Callableonly if no builds are in progress. Builds are prevented from starting while theCallableexecutes.- Parameters:
callable- theCallableto 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 TimeoutExceptionRemoves 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 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
Optional<BuildAgent> setAgentEnabled(long agentId, boolean enable)
-
-