Class AgentPoolManagerImpl
- java.lang.Object
 - 
- jetbrains.buildServer.serverSide.agentPools.AgentPoolManagerImpl
 
 
- 
- All Implemented Interfaces:
 AgentPoolManager,AfterBuildsCleanupExtension,ServerExtension,TeamCityExtension
public class AgentPoolManagerImpl extends Object implements AgentPoolManager, AfterBuildsCleanupExtension
 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected ProjectManagerExmyProjectManagerstatic StringPROJECT_POOLS_CLEANUP_DELAY_PROPstatic StringPROJECT_POOLS_CLEANUP_ENABLED_PROP 
- 
Constructor Summary
Constructors Constructor Description AgentPoolManagerImpl(SQLRunnerEx sqlRunner, NumericIdSequences idSequences, AgentTypeStorage agentTypeStorage, EventDispatcher<AgentPoolListener> agentPoolEventDispatcher, EventDispatcher<BuildServerListener> eventDispatcher, BuildAgentManagerEx agentManager, ServerResponsibility serverResponsibility, MultiNodesEvents multiNodesEvents, ExecutorServices executorServices) 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(AgentPoolListener listener)Adds listener for agent pool events.voidafterCleanup(CleanupProcessState cleanupState)Invoked upon finishing of the main cleanup process.booleanagentPoolContainsProject(int poolId, String projectId)Returns true if agent pool with specified id exists and contains project with specified internal id.voidassociateProjectsWithPool(int agentPoolId, Set<String> projectIds)Associates specified projects with the specified pool.booleancanAddAgent(int poolId)Returns true if this pool can add least one more agentbooleancanAddAgents(int poolId, int addCount)Returns true if this pool can add desired # of agentsStringcheckAgentPoolCanBeUsedByCloudProfile(String cloudProfileId, AgentPool agentPool)Checks if agent from the given cloud profile can be used with a specified pool.voidcopyPoolAssociations(String sourceProjectId, String targetProjectId)Copies set of pools associations from one project to the other.AgentPoolcreateNewAgentPool(String agentPoolName)Creates new agent pool with the specified name and no limits.AgentPoolcreateNewAgentPool(String agentPoolName, AgentPoolLimits poolLimits)Creates new agent pool with the specified name and specific limitsAgentPoolcreateUnknownPool(int agentPoolId)Creates an instance of "unknown" pool without writing anything to DB.AgentPooldeleteAgentPool(int agentPoolId)Deletes agent pool with the specified identifier.voiddissociateProjectsFromOtherPools(int agentPoolId, Set<String> projectIds)Dissociates specified projects from all the pools except the specified one.voiddissociateProjectsFromPool(int agentPoolId, Set<String> projectIds)Dissociates specified projects from the specified pool.voidensureAgentTypeIsAssignedToPool(int agentTypeId)This method ensures that agent type with specified id belongs at least to the default agent pool.AgentPoolfindAgentPoolById(int agentPoolId)Returns agent pool with the specified identifier.AgentPoolfindAgentPoolByTypeId(int agentTypeId)Searches for agent pool by agent type id.intfindAgentPoolIdByTypeId(int agentTypeId)Returns agent pool id for the specified agent type id or -1 if there is no such pool or agent type.Map<Integer,AgentPool>findAgentPoolsByIds(Collection<Integer> agentPoolIds)Returns a map of agent pools corresponding to the specified agent pool idsAgentPoolfindProjectPoolByProjectId(String projectId)Creates pool for project in memory, without persisting it to DBSet<Integer>getAgentPoolsWithProject(String projectId)Returns all associated pools for the specified project.Collection<Integer>getAgentTypeIdsByPool(int agentPoolId)Returns agent type ids associated with the specified poolList<AgentPool>getAllAgentPools()Returns all agent pools.List<AgentPool>getAllAgentPoolsEx(boolean includeProjectPools)returns list of agent pools (see options)Collection<Pair<Integer,String>>getAllPoolProjectRelations()Returns all pool--project relations.intgetNumberOfAgentPools()Returns number of agent pools.AgentPoolgetOrCreateProjectPool(String projectId)Creates pool for project in memory, without persisting it to DBSet<String>getPoolProjects(int poolId)Returns projects that are associated with the specified pool.Set<Integer>getProjectAgentTypes(String projectId)Returns all agents from pools the given projects associated with.Collection<AgentPool>getProjectOwnedAgentPools(String projectExternalId)Returns agent pools that include only projects that are under this project's tree (including the project itself).booleanhasSeveralPools()Returns true if number of agent pools is greater than one.voidmoveAgentToPool(int agentPoolId, BuildAgentEx agent)Moves specified agent to the specified pool.voidmoveAgentTypesToPool(int agentPoolId, Set<Integer> agentTypeIds)Moves specified agent types to the specified pool.voidmoveAgentTypesToProjectPool(String projectId, Set<Integer> agentTypeIds)Moves the specified agent types to the project agents pool corresponding to the specified project id (pool will be created if it does not exist)voidresetPoolsCache()voidsetAgentTypeProviderRegistry(AgentTypeProviderRegistry agentTypeProviderRegistry)voidsetAuditLogFactory(AuditLogFactory auditLogFactory)voidsetCloudManagerBase(CloudManagerBase cloudManagerBase)voidsetProjectManager(ProjectManagerEx projectManager)AgentPoolupdateAgentPool(int agentPoolId, String newAgentPoolName, AgentPoolLimits newPoolLimits)Renames agent pool with the specified identifier. 
 - 
 
- 
- 
Field Detail
- 
PROJECT_POOLS_CLEANUP_DELAY_PROP
public static final String PROJECT_POOLS_CLEANUP_DELAY_PROP
- See Also:
 - Constant Field Values
 
 
- 
PROJECT_POOLS_CLEANUP_ENABLED_PROP
public static final String PROJECT_POOLS_CLEANUP_ENABLED_PROP
- See Also:
 - Constant Field Values
 
 
- 
myProjectManager
@NotNull protected ProjectManagerEx myProjectManager
 
 - 
 
- 
Constructor Detail
- 
AgentPoolManagerImpl
public AgentPoolManagerImpl(@NotNull SQLRunnerEx sqlRunner, @NotNull NumericIdSequences idSequences, @NotNull AgentTypeStorage agentTypeStorage, @NotNull EventDispatcher<AgentPoolListener> agentPoolEventDispatcher, @NotNull EventDispatcher<BuildServerListener> eventDispatcher, @NotNull BuildAgentManagerEx agentManager, @NotNull ServerResponsibility serverResponsibility, @NotNull MultiNodesEvents multiNodesEvents, @NotNull ExecutorServices executorServices) 
 - 
 
- 
Method Detail
- 
setProjectManager
public void setProjectManager(@NotNull ProjectManagerEx projectManager) 
- 
setAuditLogFactory
public void setAuditLogFactory(AuditLogFactory auditLogFactory)
 
- 
setAgentTypeProviderRegistry
public void setAgentTypeProviderRegistry(@NotNull AgentTypeProviderRegistry agentTypeProviderRegistry) 
- 
setCloudManagerBase
public void setCloudManagerBase(@NotNull CloudManagerBase cloudManagerBase) 
- 
addListener
public void addListener(@NotNull AgentPoolListener listener)Description copied from interface:AgentPoolManagerAdds listener for agent pool events.- Specified by:
 addListenerin interfaceAgentPoolManager- Parameters:
 listener- listener
 
- 
getAllPoolProjectRelations
@NotNull public Collection<Pair<Integer,String>> getAllPoolProjectRelations()
Description copied from interface:AgentPoolManagerReturns all pool--project relations.- Specified by:
 getAllPoolProjectRelationsin interfaceAgentPoolManager- Returns:
 - pool--project relations as an unsorted collection of pairs where first element is a pool id and second element is a project id.
 
 
- 
getAgentPoolsWithProject
@NotNull public Set<Integer> getAgentPoolsWithProject(@NotNull String projectId)
Description copied from interface:AgentPoolManagerReturns all associated pools for the specified project.- Specified by:
 getAgentPoolsWithProjectin interfaceAgentPoolManager- Parameters:
 projectId- project id- Returns:
 - set of agent pool ids
 
 
- 
getProjectOwnedAgentPools
@NotNull public Collection<AgentPool> getProjectOwnedAgentPools(@NotNull String projectExternalId)
Description copied from interface:AgentPoolManagerReturns agent pools that include only projects that are under this project's tree (including the project itself).- Specified by:
 getProjectOwnedAgentPoolsin interfaceAgentPoolManager- Returns:
 
 
- 
getProjectAgentTypes
@NotNull public Set<Integer> getProjectAgentTypes(@NotNull String projectId)
Description copied from interface:AgentPoolManagerReturns all agents from pools the given projects associated with.- Specified by:
 getProjectAgentTypesin interfaceAgentPoolManager- Parameters:
 projectId- project id- Returns:
 - set of agent tyeps ids
 
 
- 
getPoolProjects
@NotNull public Set<String> getPoolProjects(int poolId)
Description copied from interface:AgentPoolManagerReturns projects that are associated with the specified pool.- Specified by:
 getPoolProjectsin interfaceAgentPoolManager- Parameters:
 poolId- pool identifier we want projects for.- Returns:
 - set of internal project ids.
 
 
- 
agentPoolContainsProject
public boolean agentPoolContainsProject(int poolId, @NotNull String projectId)Description copied from interface:AgentPoolManagerReturns true if agent pool with specified id exists and contains project with specified internal id.- Specified by:
 agentPoolContainsProjectin interfaceAgentPoolManager- Parameters:
 poolId- pool idprojectId- project id- Returns:
 - see above
 
 
- 
canAddAgent
public boolean canAddAgent(int poolId) throws NoSuchAgentPoolExceptionDescription copied from interface:AgentPoolManagerReturns true if this pool can add least one more agent- Specified by:
 canAddAgentin interfaceAgentPoolManager- Returns:
 - see above
 - Throws:
 NoSuchAgentPoolException
 
- 
canAddAgents
public boolean canAddAgents(int poolId, int addCount) throws NoSuchAgentPoolExceptionDescription copied from interface:AgentPoolManagerReturns true if this pool can add desired # of agents- Specified by:
 canAddAgentsin interfaceAgentPoolManageraddCount- number of agents to add- Returns:
 - Throws:
 NoSuchAgentPoolException
 
- 
getAgentTypeIdsByPool
@NotNull public Collection<Integer> getAgentTypeIdsByPool(int agentPoolId)
Description copied from interface:AgentPoolManagerReturns agent type ids associated with the specified pool- Specified by:
 getAgentTypeIdsByPoolin interfaceAgentPoolManager- Parameters:
 agentPoolId- - agent pool internal id
 
- 
findAgentPoolByTypeId
@Nullable public AgentPool findAgentPoolByTypeId(int agentTypeId)
Description copied from interface:AgentPoolManagerSearches for agent pool by agent type id.- Specified by:
 findAgentPoolByTypeIdin interfaceAgentPoolManager- Parameters:
 agentTypeId- agent type id- Returns:
 - found agent pool or null
 
 
- 
findAgentPoolIdByTypeId
public int findAgentPoolIdByTypeId(int agentTypeId)
Description copied from interface:AgentPoolManagerReturns agent pool id for the specified agent type id or -1 if there is no such pool or agent type.- Specified by:
 findAgentPoolIdByTypeIdin interfaceAgentPoolManager- Parameters:
 agentTypeId- agent type id- Returns:
 - found agent pool id or -1
 
 
- 
getAllAgentPoolsEx
@NotNull public List<AgentPool> getAllAgentPoolsEx(boolean includeProjectPools)
Description copied from interface:AgentPoolManagerreturns list of agent pools (see options)- Specified by:
 getAllAgentPoolsExin interfaceAgentPoolManager- Parameters:
 includeProjectPools- - true to include project pools- Returns:
 
 
- 
getAllAgentPools
@NotNull public List<AgentPool> getAllAgentPools()
Description copied from interface:AgentPoolManagerReturns all agent pools. Sorting is by name, but default pool is always the last.- Specified by:
 getAllAgentPoolsin interfaceAgentPoolManager- Returns:
 - see above
 
 
- 
getNumberOfAgentPools
public int getNumberOfAgentPools()
Description copied from interface:AgentPoolManagerReturns number of agent pools.- Specified by:
 getNumberOfAgentPoolsin interfaceAgentPoolManager- Returns:
 - see above
 
 
- 
hasSeveralPools
public boolean hasSeveralPools()
Description copied from interface:AgentPoolManagerReturns true if number of agent pools is greater than one.- Specified by:
 hasSeveralPoolsin interfaceAgentPoolManager- Returns:
 - see above
 
 
- 
findAgentPoolById
@Nullable public AgentPool findAgentPoolById(int agentPoolId)
Description copied from interface:AgentPoolManagerReturns agent pool with the specified identifier.- Specified by:
 findAgentPoolByIdin interfaceAgentPoolManager- Parameters:
 agentPoolId- agent pool id- Returns:
 - agent pool or null if it does not exist
 
 
- 
findAgentPoolsByIds
@NotNull public Map<Integer,AgentPool> findAgentPoolsByIds(@NotNull Collection<Integer> agentPoolIds)
Description copied from interface:AgentPoolManagerReturns a map of agent pools corresponding to the specified agent pool ids- Specified by:
 findAgentPoolsByIdsin interfaceAgentPoolManager- Returns:
 - see above
 
 
- 
createNewAgentPool
@NotNull public AgentPool createNewAgentPool(@NotNull String agentPoolName) throws AgentPoolCannotBeRenamedException
Description copied from interface:AgentPoolManagerCreates new agent pool with the specified name and no limits.- Specified by:
 createNewAgentPoolin interfaceAgentPoolManager- Parameters:
 agentPoolName- agent pool name- Returns:
 - identifier of the created agent pool
 - Throws:
 AgentPoolCannotBeRenamedException- if the agent pool with such name already exists
 
- 
getOrCreateProjectPool
@NotNull public AgentPool getOrCreateProjectPool(@NotNull String projectId)
Description copied from interface:AgentPoolManagerCreates pool for project in memory, without persisting it to DB- Specified by:
 getOrCreateProjectPoolin interfaceAgentPoolManager
 
- 
createNewAgentPool
@NotNull public AgentPool createNewAgentPool(@NotNull String agentPoolName, @NotNull AgentPoolLimits poolLimits) throws AgentPoolCannotBeRenamedException
Description copied from interface:AgentPoolManagerCreates new agent pool with the specified name and specific limits- Specified by:
 createNewAgentPoolin interfaceAgentPoolManager- Parameters:
 agentPoolName- agent pool namepoolLimits- - agent pool limits- Returns:
 - identifier of the created agent pool
 - Throws:
 AgentPoolCannotBeRenamedException- if the agent pool with such name already exists
 
- 
createUnknownPool
@NotNull public AgentPool createUnknownPool(int agentPoolId)
Description copied from interface:AgentPoolManagerCreates an instance of "unknown" pool without writing anything to DB. Used in special cases- Specified by:
 createUnknownPoolin interfaceAgentPoolManager- Parameters:
 agentPoolId- agent pool id- Returns:
 - identifier of the created agent pool
 
 
- 
updateAgentPool
@NotNull public AgentPool updateAgentPool(int agentPoolId, @NotNull String newAgentPoolName, @NotNull AgentPoolLimits newPoolLimits) throws NoSuchAgentPoolException, AgentPoolCannotBeRenamedException
Description copied from interface:AgentPoolManagerRenames agent pool with the specified identifier.- Specified by:
 updateAgentPoolin interfaceAgentPoolManager- Parameters:
 agentPoolId- agent pool idnewAgentPoolName- new agent pool namenewPoolLimits- - agent pool limits- Returns:
 - previous state of the agent pool
 - Throws:
 NoSuchAgentPoolException- if the specified agent pool does not existAgentPoolCannotBeRenamedException- if it is an attempt to rename default agent pool or the agent pool with such name already exists
 
- 
deleteAgentPool
@NotNull public AgentPool deleteAgentPool(int agentPoolId) throws NoSuchAgentPoolException, AgentPoolCannotBeDeletedException
Description copied from interface:AgentPoolManagerDeletes agent pool with the specified identifier. If there are some agent types those belong to this pool, they will be moved to default pool.- Specified by:
 deleteAgentPoolin interfaceAgentPoolManager- Parameters:
 agentPoolId- agent pool id- Returns:
 - previous state of the agent pool
 - Throws:
 NoSuchAgentPoolException- if the specified agent pool does not existAgentPoolCannotBeDeletedException- if it is an attempt to delete default agent pool
 
- 
moveAgentTypesToPool
public void moveAgentTypesToPool(int agentPoolId, @NotNull Set<Integer> agentTypeIds) throws NoSuchAgentPoolException, PoolQuotaExceededException, AgentTypeCannotBeMovedExceptionDescription copied from interface:AgentPoolManagerMoves specified agent types to the specified pool.- Specified by:
 moveAgentTypesToPoolin interfaceAgentPoolManager- Parameters:
 agentPoolId- agent pool idagentTypeIds- agent type ids- Throws:
 NoSuchAgentPoolException- if the specified agent pool does not existPoolQuotaExceededException- if pool quota cannot accept desired # of agentsAgentTypeCannotBeMovedException
 
- 
moveAgentTypesToProjectPool
public void moveAgentTypesToProjectPool(@NotNull String projectId, @NotNull Set<Integer> agentTypeIds) throws PoolQuotaExceededException, AgentTypeCannotBeMovedExceptionDescription copied from interface:AgentPoolManagerMoves the specified agent types to the project agents pool corresponding to the specified project id (pool will be created if it does not exist)- Specified by:
 moveAgentTypesToProjectPoolin interfaceAgentPoolManager- Throws:
 PoolQuotaExceededExceptionAgentTypeCannotBeMovedException
 
- 
ensureAgentTypeIsAssignedToPool
public void ensureAgentTypeIsAssignedToPool(int agentTypeId)
Description copied from interface:AgentPoolManagerThis method ensures that agent type with specified id belongs at least to the default agent pool. A call of this method is required for every new agent type, because newly created agent types no longer belong to default pool by default.- Specified by:
 ensureAgentTypeIsAssignedToPoolin interfaceAgentPoolManager
 
- 
checkAgentPoolCanBeUsedByCloudProfile
@Nullable public String checkAgentPoolCanBeUsedByCloudProfile(@NotNull String cloudProfileId, @NotNull AgentPool agentPool)
Description copied from interface:AgentPoolManagerChecks if agent from the given cloud profile can be used with a specified pool.- Specified by:
 checkAgentPoolCanBeUsedByCloudProfilein interfaceAgentPoolManager- Parameters:
 cloudProfileId- - agent's cloud profile idagentPool- - destination pool- Returns:
 - - reason why agents from the given cloud profile cannot be used with specified pool or 'null' otherwise
 
 
- 
moveAgentToPool
public void moveAgentToPool(int agentPoolId, @NotNull BuildAgentEx agent) throws NoSuchAgentPoolException, PoolQuotaExceededException, AgentTypeCannotBeMovedExceptionDescription copied from interface:AgentPoolManagerMoves specified agent to the specified pool.- Specified by:
 moveAgentToPoolin interfaceAgentPoolManager- Parameters:
 agentPoolId- agent pool idagent- agent- Throws:
 NoSuchAgentPoolException- if the specified agent pool does not existPoolQuotaExceededException- if pool quota cannot accept desired # of agentsAgentTypeCannotBeMovedException
 
- 
associateProjectsWithPool
public void associateProjectsWithPool(int agentPoolId, @NotNull Set<String> projectIds) throws NoSuchAgentPoolExceptionDescription copied from interface:AgentPoolManagerAssociates specified projects with the specified pool. Does not affect projects which are not specified in parameters.- Specified by:
 associateProjectsWithPoolin interfaceAgentPoolManager- Parameters:
 agentPoolId- agent pool idprojectIds- project ids to associate with the specified pool- Throws:
 NoSuchAgentPoolException- if the specified agent pool does not exist
 
- 
resetPoolsCache
public void resetPoolsCache()
 
- 
dissociateProjectsFromPool
public void dissociateProjectsFromPool(int agentPoolId, @NotNull Set<String> projectIds) throws NoSuchAgentPoolExceptionDescription copied from interface:AgentPoolManagerDissociates specified projects from the specified pool. Does not affect projects which are not specified in parameters.- Specified by:
 dissociateProjectsFromPoolin interfaceAgentPoolManager- Parameters:
 agentPoolId- agent pool idprojectIds- project ids to dissociate from the specified pool- Throws:
 NoSuchAgentPoolException- if the specified agent pool does not exist
 
- 
dissociateProjectsFromOtherPools
public void dissociateProjectsFromOtherPools(int agentPoolId, @NotNull Set<String> projectIds)Description copied from interface:AgentPoolManagerDissociates specified projects from all the pools except the specified one. Does not affect projects which are not specified in parameters. Does not affect agent pool which is specified in parameters.- Specified by:
 dissociateProjectsFromOtherPoolsin interfaceAgentPoolManager- Parameters:
 agentPoolId- agent pool idprojectIds- project ids to dissociate from all the pools except the specified one
 
- 
copyPoolAssociations
public void copyPoolAssociations(@NotNull String sourceProjectId, @NotNull String targetProjectId)Description copied from interface:AgentPoolManagerCopies set of pools associations from one project to the other.- Specified by:
 copyPoolAssociationsin interfaceAgentPoolManager- Parameters:
 sourceProjectId- sourcetargetProjectId- target
 
- 
findProjectPoolByProjectId
@Nullable public AgentPool findProjectPoolByProjectId(@NotNull String projectId)
Description copied from interface:AgentPoolManagerCreates pool for project in memory, without persisting it to DB- Specified by:
 findProjectPoolByProjectIdin interfaceAgentPoolManager
 
- 
afterCleanup
public void afterCleanup(@NotNull CleanupProcessState cleanupState)Description copied from interface:AfterBuildsCleanupExtensionInvoked upon finishing of the main cleanup process. At this point all data for specific builds is deleted.
Note: This extension might not be called for every cleanup run as cleanup process can be interrupted earlier. Extension must check cleanup process state and if it is interrupted, complete its operations and return as quick as possible.- Specified by:
 afterCleanupin interfaceAfterBuildsCleanupExtension- Parameters:
 cleanupState- cleanup process state
 
 - 
 
 -