com.atlassian.bamboo.buildqueue.manager
Interface AgentManager

All Known Subinterfaces:
LocalAgentManager
All Known Implementing Classes:
AgentManagerImpl

public interface AgentManager

Manages the LocalBuildAgent and PipelineDefinition funnily enough. The class is fully synchronized.


Nested Class Summary
static class AgentManager.DisabledAgentsInclusion
           
static class AgentManager.OfflineAgentsInclusion
           
 
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 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 exists
 void createLocalAgent(LocalAgentDefinition pipelineDefinition)
          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()
          Deprecated. since 3.2 This method can potentially pull thousands of agents definitions from the database and incapacitate the whole server, consider using getAllElasticAgentDefinitions(java.util.Collection) instead
 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 requirements, 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 pipelineDefinition)
          Stores the elastic PipelineDefinition
 void savePipeline(PipelineDefinition pipelineDefinition)
          Stores the PipelineDefinition.
 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
 

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 current LocalBuildAgent objects


stopLocalAgents

void stopLocalAgents()
                     throws java.lang.InterruptedException
Stops all LocalBuildAgent

Throws:
java.lang.InterruptedException

getAllLocalAgents

@NotNull
java.util.List<LocalBuildAgent> getAllLocalAgents()
Returns all LocalBuildAgent objects

Returns:
A copied collection of LocalBuildAgent objects, or an empty collection if none exists.

getAllRemoteAgents

@NotNull
java.util.List<BuildAgent> getAllRemoteAgents()
Gets all remote agents in the system. They can be offline.

Returns:
all remote agents.

getAllRemoteAgents

@NotNull
java.util.List<BuildAgent> getAllRemoteAgents(boolean onlineOnly)
Get remote agents.

Parameters:
onlineOnly - - only return those agents which are online currently.
Returns:

getAllElasticAgentDefinitions

@Deprecated
@NotNull
java.util.List<ElasticAgentDefinition> getAllElasticAgentDefinitions()
Deprecated. since 3.2 This method can potentially pull thousands of agents definitions from the database and incapacitate the whole server, consider using getAllElasticAgentDefinitions(java.util.Collection) instead

Retrieve all elastic agent definitions from db.

Returns:
list of ElasticAgents

getAllElasticAgentDefinitions

@NotNull
java.util.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(java.lang.Class<ElasticAgentDefinition> agentDefinitionClass)
Retrieves the amount of agents of given type stored in the database

Parameters:
agentDefinitionClass - agent type
Returns:
amount of agents

getAllElasticAgentDefinitions

@NotNull
java.util.List<ElasticAgentDefinition> getAllElasticAgentDefinitions(@NotNull
                                                                             java.util.Collection<java.lang.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
java.util.List<BuildAgent> getOnlineElasticAgents()
Retrieve all online elastic build agents.

Returns:

getAllAgents

@NotNull
java.util.List<BuildAgent> getAllAgents()

getAllNonElasticAgents

@NotNull
java.util.List<BuildAgent> getAllNonElasticAgents()

getBusyBuildAgents

@NotNull
java.util.Collection<BuildAgent> getBusyBuildAgents()
Gets a collection agents that are currently building or cancelling a build

Returns:
Collection of BuildAgent

getActiveAndEnabledAgents

@NotNull
java.util.Collection<BuildAgent> getActiveAndEnabledAgents()
Returns agents that are enabled and online

Returns:
Collection of BuildAgent

getExecutableAgents

@NotNull
java.util.Collection<BuildAgent> getExecutableAgents(RequirementSet requirementSet,
                                                             boolean includeDisabled)
Gets all agents which can run a given RequirementSet

Returns:

getExecutableAgents

@NotNull
java.util.Collection<BuildAgent> getExecutableAgents(RequirementSet requirements,
                                                             AgentManager.DisabledAgentsInclusion includeDisabled,
                                                             AgentManager.OfflineAgentsInclusion includeOffline)
Gets all agents which can run a given RequirementSet

Returns:

getExecutableImages

@NotNull
java.util.Collection<ElasticImageConfiguration> getExecutableImages(@NotNull
                                                                            RequirementSet requirementSet)
Retrieves a list of all images which satisfy the given requirements set.

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

getExecutableImages

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

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)

savePipeline

void savePipeline(PipelineDefinition pipelineDefinition)
Stores the PipelineDefinition. Updates any caches so calls to getLocalAgent(long) will return the LocalBuildAgent returns with the new definition

Parameters:
pipelineDefinition - - Must not be null

saveElasticPipeline

void saveElasticPipeline(@NotNull
                         ElasticAgentDefinition pipelineDefinition)
Stores the elastic PipelineDefinition

Parameters:
pipelineDefinition - - Must not be null

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
BuildAgent getAgent(long agentId)

getAgentDefinition

@Nullable
PipelineDefinition getAgentDefinition(@NotNull
                                               java.lang.Long agentId)

findAllAgentsForAgentIds

java.util.Map<java.lang.Long,PipelineDefinition> findAllAgentsForAgentIds(@NotNull
                                                                          java.util.Collection<java.lang.Long> agentIds)
Returns a Map of PipelineDefinitions 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(java.util.concurrent.Callable<T> callable)
                throws java.lang.Exception

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

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

createLocalAgent

void createLocalAgent(LocalAgentDefinition pipelineDefinition)
                      throws BambooLicenseException
Create a new local agent.

Parameters:
pipelineDefinition -
Throws:
BambooLicenseException

removeAgent

void removeAgent(long agentId)
                 throws java.util.concurrent.TimeoutException
Removes the passed agent

Parameters:
agentId -
Throws:
java.util.concurrent.TimeoutException

getExecutableAgentsMatrix

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

Parameters:
requirementSet -
includeDisabled -
Returns:

getExecutableAgentsMatrix

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

Parameters:
requirementSet -
includeDisabled -
includeOffline -
Returns:

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

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

getAllPersistedAgentDefinitions

java.util.List<PipelineDefinition> getAllPersistedAgentDefinitions()
Retrieves a list of all agent definitions stored in the database.

Returns:
List

abandonBuild

void abandonBuild(@NotNull
                  BuildAgent remoteAgent,
                  boolean agentStartingUp)

getAgentDefinitionByName

@Nullable
PipelineDefinition getAgentDefinitionByName(@NotNull
                                                     java.lang.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
java.util.List<PipelineDefinition> getAgentDefinitionsWithNameLike(@NotNull
                                                                           java.lang.String likeName)
Retrun 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
                     PipelineDefinition pipelineDefinition)
Stores a pipeline PipelineDefinition of any type (elastic, local, remote)

Parameters:
pipelineDefinition - - Must not be null


Copyright © 2012 Atlassian. All Rights Reserved.