Class AgentManagerImpl
java.lang.Object
com.atlassian.bamboo.buildqueue.manager.AgentManagerImpl
- All Implemented Interfaces:
AgentManager
,LocalAgentManager
-
Field Summary
Fields inherited from interface com.atlassian.bamboo.buildqueue.manager.AgentManager
DEFAULT_AGENT_NAME
-
Constructor Summary
ConstructorDescriptionAgentManagerImpl
(AgentDao agentDao, CapabilitySetManager capabilitySetManager, CapabilityManager capabilityManager, com.atlassian.event.api.EventPublisher eventPublisher, BambooLicenseManager bambooLicenseManager, ElasticInstanceManager elasticInstanceManager, ErrorUpdateHandler errorUpdateHandler, BuildLoggerManager buildLoggerManager, FeatureManager featureManager, DeploymentsInProgressService deploymentsInProgressService, ElasticTunnelDefinitionDao elasticTunnelDefinitionDao, EphemeralAgentsService ephemeralAgentsService, EphemeralAgentExecutionService ephemeralAgentExecutionService, EphemeralAgentManagementLogger ephemeralAgentManagementLogger) -
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 numOfAgentsToCreate) 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 definition) Create a new local agent.void
Disable all pipelinesvoid
Enable all pipelinesfindAllAgentsForAgentIds
(@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) Retrieve aPipelineDefinition
by name.@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 agent (any type)void
removeEphemeralAgent
(long agentId) Removes the agent if the ephemeral one with requested ID is found.void
removeRemoteAgent
(long agentId) Removes a remote agentvoid
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 elasticDefinition) Stores the elasticPipelineDefinition
void
saveEphemeralPipeline
(@NotNull EphemeralAgentDefinition pipelineDefinition) Stores the ephemeralPipelineDefinition
void
savePipeline
(@NotNull PipelineDefinition pipelineDefinition) Stores thePipelineDefinition
.void
savePipeline
(@NotNull 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.
-
Constructor Details
-
AgentManagerImpl
public AgentManagerImpl(AgentDao agentDao, CapabilitySetManager capabilitySetManager, CapabilityManager capabilityManager, com.atlassian.event.api.EventPublisher eventPublisher, BambooLicenseManager bambooLicenseManager, ElasticInstanceManager elasticInstanceManager, ErrorUpdateHandler errorUpdateHandler, BuildLoggerManager buildLoggerManager, FeatureManager featureManager, DeploymentsInProgressService deploymentsInProgressService, ElasticTunnelDefinitionDao elasticTunnelDefinitionDao, EphemeralAgentsService ephemeralAgentsService, EphemeralAgentExecutionService ephemeralAgentExecutionService, EphemeralAgentManagementLogger ephemeralAgentManagementLogger)
-
-
Method Details
-
createDefaultAgent
public void createDefaultAgent()Description copied from interface:AgentManager
sets up a default local agent if no local agent exists- Specified by:
createDefaultAgent
in interfaceAgentManager
-
initAgents
public void initAgents()Description copied from interface:AgentManager
Inits the local agents Must be ran before any other methods.- Specified by:
initAgents
in interfaceAgentManager
-
startLocalAgents
public void startLocalAgents()Description copied from interface:AgentManager
Starts all currentLocalBuildAgent
objects- Specified by:
startLocalAgents
in interfaceAgentManager
-
stopLocalAgents
public void stopLocalAgents()Description copied from interface:AgentManager
Stops allLocalBuildAgent
- Specified by:
stopLocalAgents
in interfaceAgentManager
-
getAllLocalAgents
Description copied from interface:AgentManager
Returns allLocalBuildAgent
objects- Specified by:
getAllLocalAgents
in interfaceAgentManager
- Returns:
- A copied collection of
LocalBuildAgent
objects, or an empty collection if none exists.
-
getOnlineElasticAgents
Description copied from interface:AgentManager
Retrieve all online elastic build agents.- Specified by:
getOnlineElasticAgents
in interfaceAgentManager
- Returns:
-
getAllElasticAgentDefinitions
@NotNull public @NotNull List<ElasticAgentDefinition> getAllElasticAgentDefinitions(int firstResult, int maxResults) Description copied from interface:AgentManager
Retrieve most recently terminated elastic agent definitions from db, ordered by termination time, descending.- Specified by:
getAllElasticAgentDefinitions
in interfaceAgentManager
- Returns:
- list of ElasticAgents
-
getAgentCount
Description copied from interface:AgentManager
Retrieves the amount of agents of given type stored in the database- Specified by:
getAgentCount
in interfaceAgentManager
- Parameters:
agentDefinitionClass
- agent type- Returns:
- amount of agents
-
getAllElasticAgentDefinitions
@NotNull public @NotNull List<ElasticAgentDefinition> getAllElasticAgentDefinitions(@NotNull @NotNull Collection<String> instanceIds) Description copied from interface:AgentManager
Retrieve elastic agent definitions from db.- Specified by:
getAllElasticAgentDefinitions
in interfaceAgentManager
- Parameters:
instanceIds
- the instances ids on which the agents were running- Returns:
- list of ElasticAgents
-
getAllRemoteAgents
Description copied from interface:AgentManager
Get remote agents.- Specified by:
getAllRemoteAgents
in interfaceAgentManager
- Parameters:
onlineOnly
- - only return those agents which are online currently.- Returns:
-
getAllRemoteAgents
Description copied from interface:AgentManager
Gets all remote agents in the system. They can be offline.- Specified by:
getAllRemoteAgents
in interfaceAgentManager
- Returns:
- all remote agents.
-
getAllAgents
- Specified by:
getAllAgents
in interfaceAgentManager
-
getAllNonElasticAgents
- Specified by:
getAllNonElasticAgents
in interfaceAgentManager
-
getAllStandardAgents
- Specified by:
getAllStandardAgents
in interfaceAgentManager
- Returns:
- all standard agents, i.e. not ephemeral and not elastic
-
getBusyBuildAgents
Description copied from interface:AgentManager
Gets a collection agents that are currently building or cancelling a build- Specified by:
getBusyBuildAgents
in interfaceAgentManager
- Returns:
- Collection of
BuildAgent
-
getActiveAndEnabledAgents
Description copied from interface:AgentManager
Returns agents that are enabled and online- Specified by:
getActiveAndEnabledAgents
in interfaceAgentManager
- Returns:
- Collection of
BuildAgent
-
getRemoteActiveAndEnabledAgents
Description copied from interface:AgentManager
Returns remote agents that are enabled and online- Specified by:
getRemoteActiveAndEnabledAgents
in interfaceAgentManager
- Returns:
- Collection of
BuildAgent
-
getElasticActiveAndEnabledAgents
Description copied from interface:AgentManager
Returns elastic agents that are enabled and online- Specified by:
getElasticActiveAndEnabledAgents
in interfaceAgentManager
- Returns:
- Collection of
BuildAgent
-
getLocalActiveAndEnabledAgents
Description copied from interface:AgentManager
Returns local agents that are enabled and online- Specified by:
getLocalActiveAndEnabledAgents
in interfaceAgentManager
- Returns:
- Collection of
LocalBuildAgent
-
createLocalAgent
Description copied from interface:AgentManager
Create a new local agent.- Specified by:
createLocalAgent
in interfaceAgentManager
- Throws:
BambooLicenseException
-
savePipeline
Description copied from interface:AgentManager
Stores thePipelineDefinition
. Updates any caches so calls toAgentManager.getLocalAgent(long)
will return theLocalBuildAgent
returns with the new definition- Specified by:
savePipeline
in interfaceAgentManager
- Parameters:
pipelineDefinition
- - Must not be null
-
savePipeline
public void savePipeline(@NotNull @NotNull PipelineDefinition pipelineDefinition, @Nullable @Nullable AgentConfigurationUpdatedEventFactory eventFactory) Description copied from interface:AgentManager
Stores thePipelineDefinition
. Updates any caches so calls toAgentManager.getLocalAgent(long)
will return theLocalBuildAgent
returns with the new definition- Specified by:
savePipeline
in interfaceAgentManager
- Parameters:
pipelineDefinition
- - Must not be nulleventFactory
- event factory used to create event sent after the pipeline is saved
-
saveElasticPipeline
Description copied from interface:AgentManager
Stores the elasticPipelineDefinition
- Specified by:
saveElasticPipeline
in interfaceAgentManager
- Parameters:
elasticDefinition
- - Must not be null
-
saveEphemeralPipeline
Description copied from interface:AgentManager
Stores the ephemeralPipelineDefinition
- Specified by:
saveEphemeralPipeline
in interfaceAgentManager
- Parameters:
pipelineDefinition
- - Must not be null
-
saveReturningElasticPipeline
public void saveReturningElasticPipeline(@NotNull @NotNull ElasticAgentDefinition elasticDefinition) Description copied from interface:AgentManager
Stores the elasticPipelineDefinition
of a returning elastic agent.- Specified by:
saveReturningElasticPipeline
in interfaceAgentManager
- Parameters:
elasticDefinition
- returning elastic agent definition
-
getAllPersistedAgentDefinitions
Description copied from interface:AgentManager
Retrieves a list of all agent definitions stored in the database.- Specified by:
getAllPersistedAgentDefinitions
in interfaceAgentManager
-
abandonBuild
- Specified by:
abandonBuild
in interfaceAgentManager
-
onAgentReturning
Description copied from interface:AgentManager
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.- Specified by:
onAgentReturning
in interfaceAgentManager
- Parameters:
agent
- to be stopped
-
stopAgent
Description copied from interface:AgentManager
Performs any other operations required when an agent goes offline, such as updating the status and shutdown time.- Specified by:
stopAgent
in interfaceAgentManager
- Parameters:
agent
- to be stopped
-
getLocalAgent
Description copied from interface:AgentManager
Returns the pipeline that matches the passed id- Specified by:
getLocalAgent
in interfaceAgentManager
- Returns:
- Matching
LocalBuildAgent
object. Null if pipeline does not exist
-
getAgent
- Specified by:
getAgent
in interfaceAgentManager
-
getAgentDefinition
- Specified by:
getAgentDefinition
in interfaceAgentManager
-
getEphemeralAgentPods
Description copied from interface:AgentManager
Returns a list of ephemeral agents related pods in any phase present in the connected cluster at the moment of request.- Specified by:
getEphemeralAgentPods
in interfaceAgentManager
- Returns:
- a List of
EphemeralAgentPod
-
getEventuallyConsistentEphemeralAgentPods
Description copied from interface:AgentManager
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.- Specified by:
getEventuallyConsistentEphemeralAgentPods
in interfaceAgentManager
- Returns:
- a List of
EphemeralAgentPod
-
getPendingEphemeralAgentsEstimatedCount
public int getPendingEphemeralAgentsEstimatedCount()Description copied from interface:AgentManager
Get estimated number of pending ephemeral agents.- Specified by:
getPendingEphemeralAgentsEstimatedCount
in interfaceAgentManager
-
getEphemeralAgentByPodName
@NotNull public @NotNull Optional<BuildAgent> getEphemeralAgentByPodName(@NotNull @NotNull String podName) Description copied from interface:AgentManager
Returns aBuildAgent
by given pod name (if exists).- Specified by:
getEphemeralAgentByPodName
in interfaceAgentManager
-
stopEphemeralAgentByPodName
Description copied from interface:AgentManager
Stops the ephemeral agent with requested pod name.- Specified by:
stopEphemeralAgentByPodName
in interfaceAgentManager
- Parameters:
podName
- name of the pod the ephemeral agent is running on
-
findAllAgentsForAgentIds
public Map<Long,PipelineDefinition> findAllAgentsForAgentIds(@NotNull @NotNull Collection<Long> agentIds) Description copied from interface:AgentManager
Returns a Map ofPipelineDefinition
s keyed by their id- Specified by:
findAllAgentsForAgentIds
in interfaceAgentManager
- Returns:
- agentMap
-
getAgentDefinitionByName
@Nullable public @Nullable PipelineDefinition getAgentDefinitionByName(@NotNull @NotNull String name) Description copied from interface:AgentManager
Retrieve aPipelineDefinition
by name. Names should be unique.- Specified by:
getAgentDefinitionByName
in interfaceAgentManager
- Parameters:
name
- of the agent to find- Returns:
- the agent that has the given name.
-
getAgentDefinitionsByName
@NotNull public @NotNull List<PipelineDefinition> getAgentDefinitionsByName(@NotNull @NotNull String name) Description copied from interface:AgentManager
RetrievePipelineDefinition
s by name. Names should be unique. However, duplicates are possible due to not properly handled unsuccessful registration attempts.- Specified by:
getAgentDefinitionsByName
in interfaceAgentManager
- Parameters:
name
- of the agent to find- Returns:
- the agent that has the given name.
-
getAgentDefinitionsWithNameLike
@NotNull public @NotNull List<PipelineDefinition> getAgentDefinitionsWithNameLike(@NotNull @NotNull String likeName) Description copied from interface:AgentManager
Return a list of agents whose name is like the provided string. Uses hibernate's "like" so % to mark wild card.- Specified by:
getAgentDefinitionsWithNameLike
in interfaceAgentManager
- Parameters:
likeName
- the string to match- Returns:
- List of Pipeline Definitions
-
saveAnyPipeline
Description copied from interface:AgentManager
Stores a pipelinePipelineDefinition
of any type (elastic, local, remote) AgentConfigurationUpdateEvent is fired after the pipeline is saved- Specified by:
saveAnyPipeline
in interfaceAgentManager
- Parameters:
pipelineDefinition
- - Must not be null
-
saveAnyPipeline
public void saveAnyPipeline(@NotNull @NotNull PipelineDefinition pipelineDefinition, @Nullable @Nullable AgentConfigurationUpdatedEventFactory eventFactory) Description copied from interface:AgentManager
Stores a pipelinePipelineDefinition
of any type (elastic, local, remote)- Specified by:
saveAnyPipeline
in interfaceAgentManager
- Parameters:
pipelineDefinition
- Must not be nulleventFactory
- event factory used to create event sent after the pipeline is saved
-
disableAllAgents
public void disableAllAgents()Description copied from interface:AgentManager
Disable all pipelines- Specified by:
disableAllAgents
in interfaceAgentManager
-
enableAllAgents
public void enableAllAgents()Description copied from interface:AgentManager
Enable all pipelines- Specified by:
enableAllAgents
in interfaceAgentManager
-
checkPipelinesAreDisabled
public boolean checkPipelinesAreDisabled()- Specified by:
checkPipelinesAreDisabled
in interfaceAgentManager
- Returns:
- whether or not all pipelines are disabled
-
removeAgent
Description copied from interface:AgentManager
Removes the passed agent (any type)- Specified by:
removeAgent
in interfaceAgentManager
- Throws:
TimeoutException
-
removeRemoteAgent
public void removeRemoteAgent(long agentId) Description copied from interface:AgentManager
Removes a remote agent- Specified by:
removeRemoteAgent
in interfaceAgentManager
-
removeEphemeralAgent
public void removeEphemeralAgent(long agentId) Description copied from interface:AgentManager
Removes the agent if the ephemeral one with requested ID is found. If the agent is not ephemeral - nothing happens.- Specified by:
removeEphemeralAgent
in interfaceAgentManager
- Parameters:
agentId
- agent unique identifier
-
allowNewRemoteAgent
public boolean allowNewRemoteAgent()Description copied from interface:AgentManager
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.- Specified by:
allowNewRemoteAgent
in interfaceAgentManager
- Returns:
- true if a new agent is allowed, otherise false
-
allowNewRemoteAgentWithId
public boolean allowNewRemoteAgentWithId(long id) Description copied from interface:AgentManager
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.- Specified by:
allowNewRemoteAgentWithId
in interfaceAgentManager
- Parameters:
id
- agent id- Returns:
- true if a new agent is allowed, otherise false
-
allowNewRemoteAgents
public boolean allowNewRemoteAgents(int numOfAgentsToCreate) Description copied from interface:AgentManager
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.- Specified by:
allowNewRemoteAgents
in interfaceAgentManager
- Returns:
- true if a specified number agents is allowed, otherise false
-
allowNewElasticAgent
public boolean allowNewElasticAgent()Description copied from interface:AgentManager
Allow an elastic agent to register and come online? Based on licensing restrictions.- Specified by:
allowNewElasticAgent
in interfaceAgentManager
- Returns:
- true if a new agent is allowed, otherise false
-
allowNewElasticAgentWithId
public boolean allowNewElasticAgentWithId(long id) Description copied from interface:AgentManager
Allow an elastic agent with specific id to register and come online? Based on licensing restrictions.- Specified by:
allowNewElasticAgentWithId
in interfaceAgentManager
- Parameters:
id
- agent id- Returns:
- true if a new agent is allowed, otherise false
-
allowNewEphemeralAgent
public boolean allowNewEphemeralAgent()Description copied from interface:AgentManager
Allow an ephemeral agent to register and come online? Based on licensing restrictions.- Specified by:
allowNewEphemeralAgent
in interfaceAgentManager
- Returns:
- true if a new agent is allowed, otherise false
-
allowNewEphemeralAgentWithId
public boolean allowNewEphemeralAgentWithId(long id) Description copied from interface:AgentManager
Allow an ephemeral agent with specific id to register and come online? Based on licensing restrictions.- Specified by:
allowNewEphemeralAgentWithId
in interfaceAgentManager
- Parameters:
id
- agent id- Returns:
- true if a new agent is allowed, otherise false
-
allowNewElasticAgents
public boolean allowNewElasticAgents(int numOfAgentsToCreate) Description copied from interface:AgentManager
Allow a specified number of elastic agents to register and come online? Based on licensing restrictions.- Specified by:
allowNewElasticAgents
in interfaceAgentManager
- Returns:
- true if a specified number agents is allowed, otherise false
-
allowNewLocalAgent
public boolean allowNewLocalAgent()Description copied from interface:AgentManager
Allow a local agent to come online? Based on licensing restrictions.- Specified by:
allowNewLocalAgent
in interfaceAgentManager
- Returns:
- true if a new local agent is allowed, otherwise false
-
updateAgentStatusIfResultReturnPossibleAfterServerRestart
public boolean updateAgentStatusIfResultReturnPossibleAfterServerRestart(long agentId, ResultKey resultKey, String displayName, long deploymentResultId) Description copied from interface:AgentManager
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.- Specified by:
updateAgentStatusIfResultReturnPossibleAfterServerRestart
in interfaceAgentManager
- Returns:
- true iff agents is capable of surviving a server restart.
-
setAgentEnabled
- Specified by:
setAgentEnabled
in interfaceAgentManager
-