com.atlassian.bamboo.buildqueue.manager
Class AgentManagerImpl

java.lang.Object
  extended by com.atlassian.bamboo.buildqueue.manager.AgentManagerImpl
All Implemented Interfaces:
AgentManager, LocalAgentManager

public class AgentManagerImpl
extends java.lang.Object
implements AgentManager, LocalAgentManager


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.atlassian.bamboo.buildqueue.manager.AgentManager
AgentManager.DisabledAgentsInclusion, AgentManager.OfflineAgentsInclusion
 
Field Summary
static java.lang.String DEFAULT_AGENT_NAME
           
 
Constructor Summary
AgentManagerImpl()
           
 
Method Summary
 void abandonBuild(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 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 numOfAgentsToCreate)
          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 exists
 void createLocalAgent(LocalAgentDefinition definition)
          Create a new local agent.
 void disableAllAgents()
          Disable all pipelines
 void enableAllAgents()
          Enable all pipelines
<T> T
executeIfIdle(java.util.concurrent.Callable<T> callable)
          Executes a given Callable only if no builds are in progress.
 java.util.Map<java.lang.Long,PipelineDefinition> findAllAgentsForAgentIds(java.util.Collection<java.lang.Long> agentIds)
          Returns a Map of PipelineDefinitions keyed by their id
 java.util.Collection<BuildAgent> getActiveAndEnabledAgents()
          Returns agents that are enabled and online
 BuildAgent getAgent(long agentId)
           
 long getAgentCount(java.lang.Class<ElasticAgentDefinition> agentDefinitionClass)
          Retrieves the amount of agents of given type stored in the database
 PipelineDefinition getAgentDefinition(java.lang.Long agentId)
           
 PipelineDefinition getAgentDefinitionByName(java.lang.String name)
          Retrieve a pipelineDefinition by name.
 java.util.List<PipelineDefinition> getAgentDefinitionsWithNameLike(java.lang.String likeName)
          Retrun a list of agents whose name is like the provided string.
 java.util.List<BuildAgent> getAllAgents()
           
 java.util.List<ElasticAgentDefinition> getAllElasticAgentDefinitions()
          Retrieve all elastic agent definitions from db.
 java.util.List<ElasticAgentDefinition> getAllElasticAgentDefinitions(java.util.Collection<java.lang.String> instanceIds)
          Retrieve elastic agent definitions from db.
 java.util.List<ElasticAgentDefinition> getAllElasticAgentDefinitions(int firstResult, int maxResults)
          Retrieve most recently terminated elastic agent definitions from db, ordered by termination time, descending.
 java.util.List<LocalBuildAgent> getAllLocalAgents()
          Returns all LocalBuildAgent objects
 java.util.List<BuildAgent> getAllNonElasticAgents()
           
 java.util.List<PipelineDefinition> getAllPersistedAgentDefinitions()
          Retrieves a list of all agent definitions stored in the database.
 java.util.List<BuildAgent> getAllRemoteAgents()
          Gets all remote agents in the system.
 java.util.List<BuildAgent> getAllRemoteAgents(boolean onlineOnly)
          Get remote agents.
 java.util.Collection<BuildAgent> getBusyBuildAgents()
          Gets a collection agents that are currently building or cancelling a build
 java.util.Collection<BuildAgent> getExecutableAgents(RequirementSet requirementSet, AgentManager.DisabledAgentsInclusion includeDisabled, AgentManager.OfflineAgentsInclusion includeOffline)
          Gets all agents which can run a given RequirementSet
 java.util.Collection<BuildAgent> getExecutableAgents(RequirementSet requirementSet, boolean includeDisabled)
          Gets all agents which can run a given RequirementSet
 ExecutableAgentsMatrix getExecutableAgentsMatrix(RequirementSet requirementSet, AgentManager.DisabledAgentsInclusion includeDisabled, AgentManager.OfflineAgentsInclusion includeOffline)
          Returns a matrix of how many agents match each requirement in the set.
 ExecutableAgentsMatrix getExecutableAgentsMatrix(RequirementSet requirementSet, boolean includeDisabled)
          Returns a matrix of how many agents match each requirement in the set.
 java.util.Collection<ElasticImageConfiguration> getExecutableImages(RequirementSet requirementSet)
          Retrieves a list of all images which satisfy the given requirements set.
 java.util.Collection<ElasticImageConfiguration> getExecutableImages(RequirementSet requirementSet, boolean includeDisabled)
          Retrieves a list of all images which satisfy the given requirements set.
 LocalBuildAgent getLocalAgent(long pipelineId)
          Returns the pipeline that matches the passed id
 java.util.List<BuildAgent> getOnlineElasticAgents()
          Retrieve all online elastic build agents.
 void initAgents()
          Inits the local agents Must be ran before any other methods.
 void removeAgent(long agentId)
          Removes the passed agent
 void saveAnyPipeline(PipelineDefinition pipelineDefinition)
          Stores a pipeline PipelineDefinition of any type (elastic, local, remote)
 void saveElasticPipeline(ElasticAgentDefinition elasticDefinition)
          Stores the elastic PipelineDefinition
 void savePipeline(PipelineDefinition pipelineDefinition)
          Stores the PipelineDefinition.
 void setAgentDao(AgentDao agentDao)
           
 void setBambooLicenseManager(BambooLicenseManager bambooLicenseManager)
           
 void setBuildAgentController(BuildAgentController buildAgentController)
           
 void setBuildExecutionManager(BuildExecutionManager buildExecutionManager)
           
 void setBuildLoggerManager(BuildLoggerManager buildLoggerManager)
           
 void setCapabilityRequirementsMatcher(CapabilityRequirementsMatcher capabilityRequirementsMatcher)
           
 void setCapabilitySetManager(CapabilitySetManager capabilitySetManager)
           
 void setElasticAgentManager(ElasticInstanceManager elasticInstanceManager)
           
 void setElasticImageConfigurationAccessor(ElasticImageConfigurationAccessor elasticImageConfigurationAccessor)
           
 void setErrorUpdateHander(ErrorUpdateHandler errorUpdateHandler)
           
 void setEventPublisher(com.atlassian.event.api.EventPublisher eventPublisher)
           
 void startLocalAgents()
          Starts all current LocalBuildAgent objects
 void stopAgent(BuildAgent agent)
          Performs any other operations required when an agent goes offline, such as updating the status and shutdown time.
 void stopLocalAgents()
          Stops all LocalBuildAgent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_AGENT_NAME

public static final java.lang.String DEFAULT_AGENT_NAME
See Also:
Constant Field Values
Constructor Detail

AgentManagerImpl

public AgentManagerImpl()
Method Detail

createDefaultAgent

public void createDefaultAgent()
Description copied from interface: AgentManager
sets up a default local agent if no local agent exists

Specified by:
createDefaultAgent in interface AgentManager

initAgents

public void initAgents()
Description copied from interface: AgentManager
Inits the local agents Must be ran before any other methods.

Specified by:
initAgents in interface AgentManager

startLocalAgents

public void startLocalAgents()
Description copied from interface: AgentManager
Starts all current LocalBuildAgent objects

Specified by:
startLocalAgents in interface AgentManager

stopLocalAgents

public void stopLocalAgents()
                     throws java.lang.InterruptedException
Description copied from interface: AgentManager
Stops all LocalBuildAgent

Specified by:
stopLocalAgents in interface AgentManager
Throws:
java.lang.InterruptedException

getAllLocalAgents

@NotNull
public java.util.List<LocalBuildAgent> getAllLocalAgents()
Description copied from interface: AgentManager
Returns all LocalBuildAgent objects

Specified by:
getAllLocalAgents in interface AgentManager
Returns:
A copied collection of LocalBuildAgent objects, or an empty collection if none exists.

getOnlineElasticAgents

@NotNull
public java.util.List<BuildAgent> getOnlineElasticAgents()
Description copied from interface: AgentManager
Retrieve all online elastic build agents.

Specified by:
getOnlineElasticAgents in interface AgentManager
Returns:

getAllElasticAgentDefinitions

@NotNull
public java.util.List<ElasticAgentDefinition> getAllElasticAgentDefinitions()
Description copied from interface: AgentManager
Retrieve all elastic agent definitions from db.

Specified by:
getAllElasticAgentDefinitions in interface AgentManager
Returns:
list of ElasticAgents

getAllElasticAgentDefinitions

@NotNull
public java.util.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 interface AgentManager
Returns:
list of ElasticAgents

getAgentCount

public long getAgentCount(java.lang.Class<ElasticAgentDefinition> agentDefinitionClass)
Description copied from interface: AgentManager
Retrieves the amount of agents of given type stored in the database

Specified by:
getAgentCount in interface AgentManager
Parameters:
agentDefinitionClass - agent type
Returns:
amount of agents

getAllElasticAgentDefinitions

@NotNull
public java.util.List<ElasticAgentDefinition> getAllElasticAgentDefinitions(@NotNull
                                                                                    java.util.Collection<java.lang.String> instanceIds)
Description copied from interface: AgentManager
Retrieve elastic agent definitions from db.

Specified by:
getAllElasticAgentDefinitions in interface AgentManager
Parameters:
instanceIds - the instances ids on which the agents were running
Returns:
list of ElasticAgents

getAllRemoteAgents

@NotNull
public java.util.List<BuildAgent> getAllRemoteAgents(boolean onlineOnly)
Description copied from interface: AgentManager
Get remote agents.

Specified by:
getAllRemoteAgents in interface AgentManager
Parameters:
onlineOnly - - only return those agents which are online currently.
Returns:

getAllRemoteAgents

@NotNull
public java.util.List<BuildAgent> getAllRemoteAgents()
Description copied from interface: AgentManager
Gets all remote agents in the system. They can be offline.

Specified by:
getAllRemoteAgents in interface AgentManager
Returns:
all remote agents.

getAllAgents

@NotNull
public java.util.List<BuildAgent> getAllAgents()
Specified by:
getAllAgents in interface AgentManager

getAllNonElasticAgents

@NotNull
public java.util.List<BuildAgent> getAllNonElasticAgents()
Specified by:
getAllNonElasticAgents in interface AgentManager

getBusyBuildAgents

@NotNull
public java.util.Collection<BuildAgent> getBusyBuildAgents()
Description copied from interface: AgentManager
Gets a collection agents that are currently building or cancelling a build

Specified by:
getBusyBuildAgents in interface AgentManager
Returns:
Collection of BuildAgent

getActiveAndEnabledAgents

@NotNull
public java.util.Collection<BuildAgent> getActiveAndEnabledAgents()
Description copied from interface: AgentManager
Returns agents that are enabled and online

Specified by:
getActiveAndEnabledAgents in interface AgentManager
Returns:
Collection of BuildAgent

getExecutableAgents

@NotNull
public java.util.Collection<BuildAgent> getExecutableAgents(RequirementSet requirementSet,
                                                                    boolean includeDisabled)
Description copied from interface: AgentManager
Gets all agents which can run a given RequirementSet

Specified by:
getExecutableAgents in interface AgentManager
Returns:

getExecutableAgents

@NotNull
public java.util.Collection<BuildAgent> getExecutableAgents(RequirementSet requirementSet,
                                                                    AgentManager.DisabledAgentsInclusion includeDisabled,
                                                                    AgentManager.OfflineAgentsInclusion includeOffline)
Description copied from interface: AgentManager
Gets all agents which can run a given RequirementSet

Specified by:
getExecutableAgents in interface AgentManager
Returns:

getExecutableAgentsMatrix

@NotNull
public ExecutableAgentsMatrix getExecutableAgentsMatrix(@NotNull
                                                                RequirementSet requirementSet,
                                                                boolean includeDisabled)
Description copied from interface: AgentManager
Returns a matrix of how many agents match each requirement in the set. Also adds the total number of agents that matches the set

Specified by:
getExecutableAgentsMatrix in interface AgentManager
Returns:

getExecutableAgentsMatrix

@NotNull
public ExecutableAgentsMatrix getExecutableAgentsMatrix(@NotNull
                                                                RequirementSet requirementSet,
                                                                AgentManager.DisabledAgentsInclusion includeDisabled,
                                                                AgentManager.OfflineAgentsInclusion includeOffline)
Description copied from interface: AgentManager
Returns a matrix of how many agents match each requirement in the set. Also adds the total number of agents that matches the set

Specified by:
getExecutableAgentsMatrix in interface AgentManager
Returns:

getExecutableImages

@NotNull
public java.util.Collection<ElasticImageConfiguration> getExecutableImages(@NotNull
                                                                                   RequirementSet requirementSet,
                                                                                   boolean includeDisabled)
Description copied from interface: AgentManager
Retrieves a list of all images which satisfy the given requirements set.

Specified by:
getExecutableImages in interface AgentManager
Parameters:
requirementSet - to check
includeDisabled - whether to include images configurations which are currently disabled
Returns:
Any configured ElasticImageConfiguration which can build the requirement set (currently this can be 1 or none)

getExecutableImages

@NotNull
public java.util.Collection<ElasticImageConfiguration> getExecutableImages(@NotNull
                                                                                   RequirementSet requirementSet)
Description copied from interface: AgentManager
Retrieves a list of all images which satisfy the given requirements set.

Specified by:
getExecutableImages in interface AgentManager
Parameters:
requirementSet - to check
Returns:
Any configured ElasticImageConfiguration which can build the requirement set (currently this can be 1 or none)

createLocalAgent

public void createLocalAgent(LocalAgentDefinition definition)
                      throws BambooLicenseException
Description copied from interface: AgentManager
Create a new local agent.

Specified by:
createLocalAgent in interface AgentManager
Throws:
BambooLicenseException

savePipeline

public void savePipeline(@NotNull
                         PipelineDefinition pipelineDefinition)
Description copied from interface: AgentManager
Stores the PipelineDefinition. Updates any caches so calls to AgentManager.getLocalAgent(long) will return the LocalBuildAgent returns with the new definition

Specified by:
savePipeline in interface AgentManager
Parameters:
pipelineDefinition - - Must not be null

saveElasticPipeline

public void saveElasticPipeline(@NotNull
                                ElasticAgentDefinition elasticDefinition)
Description copied from interface: AgentManager
Stores the elastic PipelineDefinition

Specified by:
saveElasticPipeline in interface AgentManager
Parameters:
elasticDefinition - - Must not be null

getAllPersistedAgentDefinitions

public java.util.List<PipelineDefinition> getAllPersistedAgentDefinitions()
Description copied from interface: AgentManager
Retrieves a list of all agent definitions stored in the database.

Specified by:
getAllPersistedAgentDefinitions in interface AgentManager
Returns:
List

abandonBuild

public void abandonBuild(@NotNull
                         BuildAgent remoteAgent,
                         boolean agentStartingUp)
Specified by:
abandonBuild in interface AgentManager

stopAgent

public void stopAgent(@NotNull
                      BuildAgent agent)
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 interface AgentManager
Parameters:
agent - to be stopped

getLocalAgent

public LocalBuildAgent getLocalAgent(long pipelineId)
Description copied from interface: AgentManager
Returns the pipeline that matches the passed id

Specified by:
getLocalAgent in interface AgentManager
Returns:
Matching LocalBuildAgent object. Null if pipeline does not exist

getAgent

@Nullable
public BuildAgent getAgent(long agentId)
Specified by:
getAgent in interface AgentManager

getAgentDefinition

@Nullable
public PipelineDefinition getAgentDefinition(@NotNull
                                                      java.lang.Long agentId)
Specified by:
getAgentDefinition in interface AgentManager

findAllAgentsForAgentIds

public java.util.Map<java.lang.Long,PipelineDefinition> findAllAgentsForAgentIds(@NotNull
                                                                                 java.util.Collection<java.lang.Long> agentIds)
Description copied from interface: AgentManager
Returns a Map of PipelineDefinitions keyed by their id

Specified by:
findAllAgentsForAgentIds in interface AgentManager
Returns:
agentMap

getAgentDefinitionByName

@Nullable
public PipelineDefinition getAgentDefinitionByName(@NotNull
                                                            java.lang.String name)
Description copied from interface: AgentManager
Retrieve a pipelineDefinition by name. Names should be unique.

Specified by:
getAgentDefinitionByName in interface AgentManager
Parameters:
name - of the agent to find
Returns:
the agent that has the given name.

getAgentDefinitionsWithNameLike

@NotNull
public java.util.List<PipelineDefinition> getAgentDefinitionsWithNameLike(@NotNull
                                                                                  java.lang.String likeName)
Description copied from interface: AgentManager
Retrun a list of agents whose name is like the provided string. Uses hibernate's "like" so % to mark wild card.

Specified by:
getAgentDefinitionsWithNameLike in interface AgentManager
Parameters:
likeName - the string to match
Returns:
List of Pipeline Definitions

saveAnyPipeline

public void saveAnyPipeline(@NotNull
                            PipelineDefinition pipelineDefinition)
Description copied from interface: AgentManager
Stores a pipeline PipelineDefinition of any type (elastic, local, remote)

Specified by:
saveAnyPipeline in interface AgentManager
Parameters:
pipelineDefinition - - Must not be null

disableAllAgents

public void disableAllAgents()
Description copied from interface: AgentManager
Disable all pipelines

Specified by:
disableAllAgents in interface AgentManager

enableAllAgents

public void enableAllAgents()
Description copied from interface: AgentManager
Enable all pipelines

Specified by:
enableAllAgents in interface AgentManager

checkPipelinesAreDisabled

public boolean checkPipelinesAreDisabled()
Specified by:
checkPipelinesAreDisabled in interface AgentManager
Returns:
whether or not all pipelines are disabled

executeIfIdle

public <T> T executeIfIdle(java.util.concurrent.Callable<T> callable)
                throws java.lang.Exception
Description copied from interface: AgentManager

Executes a given Callable only if no builds are in progress. Builds are prevented from starting while the Callable executes.

Specified by:
executeIfIdle in interface AgentManager
Parameters:
callable - the Callable to be executed
Returns:
the result of callable
Throws:
BambooBusyException - if builds are in progress
java.lang.Exception - if thrown by callable

removeAgent

public void removeAgent(long agentId)
                 throws java.util.concurrent.TimeoutException
Description copied from interface: AgentManager
Removes the passed agent

Specified by:
removeAgent in interface AgentManager
Throws:
java.util.concurrent.TimeoutException

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 interface AgentManager
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 interface AgentManager
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 interface AgentManager
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 interface AgentManager
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 interface AgentManager
Returns:
true if a new local agent is allowed, otherwise false

setBuildAgentController

public void setBuildAgentController(BuildAgentController buildAgentController)

setCapabilityRequirementsMatcher

public void setCapabilityRequirementsMatcher(CapabilityRequirementsMatcher capabilityRequirementsMatcher)

setCapabilitySetManager

public void setCapabilitySetManager(CapabilitySetManager capabilitySetManager)

setEventPublisher

public void setEventPublisher(com.atlassian.event.api.EventPublisher eventPublisher)

setBambooLicenseManager

public void setBambooLicenseManager(BambooLicenseManager bambooLicenseManager)

setElasticImageConfigurationAccessor

public void setElasticImageConfigurationAccessor(ElasticImageConfigurationAccessor elasticImageConfigurationAccessor)

setAgentDao

public void setAgentDao(AgentDao agentDao)

setElasticAgentManager

public void setElasticAgentManager(ElasticInstanceManager elasticInstanceManager)

setBuildExecutionManager

public void setBuildExecutionManager(BuildExecutionManager buildExecutionManager)

setErrorUpdateHander

public void setErrorUpdateHander(ErrorUpdateHandler errorUpdateHandler)

setBuildLoggerManager

public void setBuildLoggerManager(BuildLoggerManager buildLoggerManager)


Copyright © 2012 Atlassian. All Rights Reserved.