Class FakeAgentPoolManager
- java.lang.Object
-
- jetbrains.buildServer.serverSide.fakes.FakeAgentPoolManager
-
- All Implemented Interfaces:
AgentPoolManager
public class FakeAgentPoolManager extends Object implements AgentPoolManager
Fake simple agent pool manager, for testing purposes. Not thread safe. Some of functions are not implemented.- Author:
- Leonid Bushuev from JetBrains
-
-
Constructor Summary
Constructors Constructor Description FakeAgentPoolManager(ProjectManager projectManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(AgentPoolListener listener)Adds listener for agent pool events.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 count)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(int newId, String agentPoolName, AgentPoolLimits details)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)AgentPoolupdateAgentPool(int agentPoolId, String newAgentPoolName, AgentPoolLimits poolLimits)Renames agent pool with the specified identifier.
-
-
-
Constructor Detail
-
FakeAgentPoolManager
public FakeAgentPoolManager(@NotNull ProjectManager projectManager)
-
-
Method Detail
-
createNewAgentPool
@NotNull public AgentPool createNewAgentPool(@NotNull String agentPoolName)
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
-
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
-
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
-
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
-
createNewAgentPool
@NotNull public AgentPool createNewAgentPool(@NotNull String agentPoolName, @NotNull AgentPoolLimits poolLimits)
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
-
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
-
createNewAgentPool
public AgentPool createNewAgentPool(int newId, @NotNull String agentPoolName, AgentPoolLimits details)
-
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
-
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:
-
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
-
updateAgentPool
@NotNull public AgentPool updateAgentPool(int agentPoolId, @NotNull String newAgentPoolName, @NotNull AgentPoolLimits poolLimits) 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 namepoolLimits- - 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
-
addListener
public void addListener(@NotNull AgentPoolListener listener)Description copied from interface:AgentPoolManagerAdds listener for agent pool events.- Specified by:
addListenerin interfaceAgentPoolManager- Parameters:
listener- listener
-
moveAgentTypesToPool
public void moveAgentTypesToPool(int agentPoolId, @NotNull Set<Integer> agentTypeIds) throws NoSuchAgentPoolExceptionDescription 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 exist
-
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
-
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, PoolQuotaExceededExceptionDescription 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 agents
-
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
-
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
-
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 count) throws NoSuchAgentPoolExceptionDescription copied from interface:AgentPoolManagerReturns true if this pool can add desired # of agents- Specified by:
canAddAgentsin interfaceAgentPoolManagercount- 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
-
-