com.atlassian.bamboo.buildqueue.manager
Class LocalAgentManagerImpl

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

public class LocalAgentManagerImpl
extends java.lang.Object
implements LocalAgentManager


Constructor Summary
LocalAgentManagerImpl()
           
 
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)
           
 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<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, boolean includeDisabled)
          Gets all agents which can run a given RequirementSet
 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.
 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 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 setCapabilityRequirementsMatcher(CapabilityRequirementsMatcher capabilityRequirementsMatcher)
           
 void setCapabilitySetManager(CapabilitySetManager capabilitySetManager)
           
 void setElasticAgentManager(ElasticInstanceManager elasticInstanceManager)
           
 void setElasticImageConfigurationAccessor(ElasticImageConfigurationAccessor elasticImageConfigurationAccessor)
           
 void setErrorUpdateHander(ErrorUpdateHandler errorUpdateHander)
           
 void setEventManager(com.atlassian.event.EventManager eventManager)
           
 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
 

Constructor Detail

LocalAgentManagerImpl

public LocalAgentManagerImpl()
Method Detail

createDefaultAgent

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

Specified by:
createDefaultAgent in interface LocalAgentManager

initAgents

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

Specified by:
initAgents in interface LocalAgentManager

startLocalAgents

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

Specified by:
startLocalAgents in interface LocalAgentManager

stopLocalAgents

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

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

getAllLocalAgents

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

Specified by:
getAllLocalAgents in interface LocalAgentManager
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: LocalAgentManager
Retrieve all online elastic build agents.

Specified by:
getOnlineElasticAgents in interface LocalAgentManager
Returns:

getAllElasticAgentDefinitions

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

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

getAllRemoteAgents

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

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

getAllRemoteAgents

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

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

getAllAgents

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

getAllNonElasticAgents

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

getBusyBuildAgents

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

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

getActiveAndEnabledAgents

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

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

getExecutableAgents

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

Specified by:
getExecutableAgents in interface LocalAgentManager
Returns:

getExecutableAgentsMatrix

@NotNull
public ExecutableAgentsMatrix getExecutableAgentsMatrix(@NotNull
                                                                RequirementSet requirementSet,
                                                                boolean includeDisabled)
Description copied from interface: LocalAgentManager
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 LocalAgentManager
Returns:

getExecutableImages

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

Specified by:
getExecutableImages in interface LocalAgentManager
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: LocalAgentManager
Create a new local agent.

Specified by:
createLocalAgent in interface LocalAgentManager
Throws:
BambooLicenseException

savePipeline

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

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

saveElasticPipeline

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

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

getAllPersistedAgentDefinitions

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

Specified by:
getAllPersistedAgentDefinitions in interface LocalAgentManager
Returns:
List

abandonBuild

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

stopAgent

public void stopAgent(@NotNull
                      BuildAgent agent)
Description copied from interface: LocalAgentManager
Performs any other operations required when an agent goes offline, such as updating the status and shutdown time.

Specified by:
stopAgent in interface LocalAgentManager
Parameters:
agent - to be stopped

getLocalAgent

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

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

getAgent

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

getAgentDefinition

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

findAllAgentsForAgentIds

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

Specified by:
findAllAgentsForAgentIds in interface LocalAgentManager
Returns:
agentMap

getAgentDefinitionByName

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

Specified by:
getAgentDefinitionByName in interface LocalAgentManager
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: LocalAgentManager
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 LocalAgentManager
Parameters:
likeName - the string to match
Returns:
List of Pipeline Definitions

disableAllAgents

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

Specified by:
disableAllAgents in interface LocalAgentManager

enableAllAgents

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

Specified by:
enableAllAgents in interface LocalAgentManager

checkPipelinesAreDisabled

public boolean checkPipelinesAreDisabled()
Specified by:
checkPipelinesAreDisabled in interface LocalAgentManager
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: LocalAgentManager

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 LocalAgentManager
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: LocalAgentManager
Removes the passed agent

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

allowNewRemoteAgent

public boolean allowNewRemoteAgent()
Description copied from interface: LocalAgentManager
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 LocalAgentManager
Returns:
true if a new agent is allowed, otherise false

allowNewRemoteAgents

public boolean allowNewRemoteAgents(int numOfAgentsToCreate)
Description copied from interface: LocalAgentManager
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 LocalAgentManager
Returns:
true if a specified number agents is allowed, otherise false

allowNewElasticAgent

public boolean allowNewElasticAgent()
Description copied from interface: LocalAgentManager
Allow an elastic agent to register and come online? Based on licensing restrictions.

Specified by:
allowNewElasticAgent in interface LocalAgentManager
Returns:
true if a new agent is allowed, otherise false

allowNewElasticAgents

public boolean allowNewElasticAgents(int numOfAgentsToCreate)
Description copied from interface: LocalAgentManager
Allow a specified number of elastic agents to register and come online? Based on licensing restrictions.

Specified by:
allowNewElasticAgents in interface LocalAgentManager
Returns:
true if a specified number agents is allowed, otherise false

allowNewLocalAgent

public boolean allowNewLocalAgent()
Description copied from interface: LocalAgentManager
Allow a local agent to come online? Based on licensing restrictions.

Specified by:
allowNewLocalAgent in interface LocalAgentManager
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)

setEventManager

public void setEventManager(com.atlassian.event.EventManager eventManager)

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 errorUpdateHander)


Copyright © 2010 Atlassian. All Rights Reserved.