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 void
addListener(AgentPoolListener listener)
Adds listener for agent pool events.boolean
agentPoolContainsProject(int poolId, String projectId)
Returns true if agent pool with specified id exists and contains project with specified internal id.void
associateProjectsWithPool(int agentPoolId, Set<String> projectIds)
Associates specified projects with the specified pool.boolean
canAddAgent(int poolId)
Returns true if this pool can add least one more agentboolean
canAddAgents(int poolId, int count)
Returns true if this pool can add desired # of agentsString
checkAgentPoolCanBeUsedByCloudProfile(String cloudProfileId, AgentPool agentPool)
Checks if agent from the given cloud profile can be used with a specified pool.void
copyPoolAssociations(String sourceProjectId, String targetProjectId)
Copies set of pools associations from one project to the other.AgentPool
createNewAgentPool(int newId, String agentPoolName, AgentPoolLimits details)
AgentPool
createNewAgentPool(String agentPoolName)
Creates new agent pool with the specified name and no limits.AgentPool
createNewAgentPool(String agentPoolName, AgentPoolLimits poolLimits)
Creates new agent pool with the specified name and specific limitsAgentPool
createUnknownPool(int agentPoolId)
Creates an instance of "unknown" pool without writing anything to DB.AgentPool
deleteAgentPool(int agentPoolId)
Deletes agent pool with the specified identifier.void
dissociateProjectsFromOtherPools(int agentPoolId, Set<String> projectIds)
Dissociates specified projects from all the pools except the specified one.void
dissociateProjectsFromPool(int agentPoolId, Set<String> projectIds)
Dissociates specified projects from the specified pool.void
ensureAgentTypeIsAssignedToPool(int agentTypeId)
This method ensures that agent type with specified id belongs at least to the default agent pool.AgentPool
findAgentPoolById(int agentPoolId)
Returns agent pool with the specified identifier.AgentPool
findAgentPoolByTypeId(int agentTypeId)
Searches for agent pool by agent type id.int
findAgentPoolIdByTypeId(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 idsAgentPool
findProjectPoolByProjectId(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.int
getNumberOfAgentPools()
Returns number of agent pools.AgentPool
getOrCreateProjectPool(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).boolean
hasSeveralPools()
Returns true if number of agent pools is greater than one.void
moveAgentToPool(int agentPoolId, BuildAgentEx agent)
Moves specified agent to the specified pool.void
moveAgentTypesToPool(int agentPoolId, Set<Integer> agentTypeIds)
Moves specified agent types to the specified pool.void
moveAgentTypesToProjectPool(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)AgentPool
updateAgentPool(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:AgentPoolManager
Creates new agent pool with the specified name and no limits.- Specified by:
createNewAgentPool
in 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:AgentPoolManager
Creates pool for project in memory, without persisting it to DB- Specified by:
getOrCreateProjectPool
in interfaceAgentPoolManager
-
findProjectPoolByProjectId
@Nullable public AgentPool findProjectPoolByProjectId(@NotNull String projectId)
Description copied from interface:AgentPoolManager
Creates pool for project in memory, without persisting it to DB- Specified by:
findProjectPoolByProjectId
in interfaceAgentPoolManager
-
ensureAgentTypeIsAssignedToPool
public void ensureAgentTypeIsAssignedToPool(int agentTypeId)
Description copied from interface:AgentPoolManager
This 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:
ensureAgentTypeIsAssignedToPool
in interfaceAgentPoolManager
-
createNewAgentPool
@NotNull public AgentPool createNewAgentPool(@NotNull String agentPoolName, @NotNull AgentPoolLimits poolLimits)
Description copied from interface:AgentPoolManager
Creates new agent pool with the specified name and specific limits- Specified by:
createNewAgentPool
in 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:AgentPoolManager
Creates an instance of "unknown" pool without writing anything to DB. Used in special cases- Specified by:
createUnknownPool
in 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:AgentPoolManager
Returns all agent pools. Sorting is by name, but default pool is always the last.- Specified by:
getAllAgentPools
in interfaceAgentPoolManager
- Returns:
- see above
-
getAllAgentPoolsEx
@NotNull public List<AgentPool> getAllAgentPoolsEx(boolean includeProjectPools)
Description copied from interface:AgentPoolManager
returns list of agent pools (see options)- Specified by:
getAllAgentPoolsEx
in interfaceAgentPoolManager
- Parameters:
includeProjectPools
- - true to include project pools- Returns:
-
getNumberOfAgentPools
public int getNumberOfAgentPools()
Description copied from interface:AgentPoolManager
Returns number of agent pools.- Specified by:
getNumberOfAgentPools
in interfaceAgentPoolManager
- Returns:
- see above
-
hasSeveralPools
public boolean hasSeveralPools()
Description copied from interface:AgentPoolManager
Returns true if number of agent pools is greater than one.- Specified by:
hasSeveralPools
in interfaceAgentPoolManager
- Returns:
- see above
-
findAgentPoolById
@Nullable public AgentPool findAgentPoolById(int agentPoolId)
Description copied from interface:AgentPoolManager
Returns agent pool with the specified identifier.- Specified by:
findAgentPoolById
in 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:AgentPoolManager
Returns a map of agent pools corresponding to the specified agent pool ids- Specified by:
findAgentPoolsByIds
in interfaceAgentPoolManager
- Returns:
- see above
-
updateAgentPool
@NotNull public AgentPool updateAgentPool(int agentPoolId, @NotNull String newAgentPoolName, @NotNull AgentPoolLimits poolLimits) throws NoSuchAgentPoolException, AgentPoolCannotBeRenamedException
Description copied from interface:AgentPoolManager
Renames agent pool with the specified identifier.- Specified by:
updateAgentPool
in 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:AgentPoolManager
Deletes 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:
deleteAgentPool
in 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:AgentPoolManager
Adds listener for agent pool events.- Specified by:
addListener
in interfaceAgentPoolManager
- Parameters:
listener
- listener
-
moveAgentTypesToPool
public void moveAgentTypesToPool(int agentPoolId, @NotNull Set<Integer> agentTypeIds) throws NoSuchAgentPoolException
Description copied from interface:AgentPoolManager
Moves specified agent types to the specified pool.- Specified by:
moveAgentTypesToPool
in 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, AgentTypeCannotBeMovedException
Description copied from interface:AgentPoolManager
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)- Specified by:
moveAgentTypesToProjectPool
in interfaceAgentPoolManager
- Throws:
PoolQuotaExceededException
AgentTypeCannotBeMovedException
-
checkAgentPoolCanBeUsedByCloudProfile
@Nullable public String checkAgentPoolCanBeUsedByCloudProfile(@NotNull String cloudProfileId, @NotNull AgentPool agentPool)
Description copied from interface:AgentPoolManager
Checks if agent from the given cloud profile can be used with a specified pool.- Specified by:
checkAgentPoolCanBeUsedByCloudProfile
in 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
Description copied from interface:AgentPoolManager
Moves specified agent to the specified pool.- Specified by:
moveAgentToPool
in 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 NoSuchAgentPoolException
Description copied from interface:AgentPoolManager
Associates specified projects with the specified pool. Does not affect projects which are not specified in parameters.- Specified by:
associateProjectsWithPool
in 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 NoSuchAgentPoolException
Description copied from interface:AgentPoolManager
Dissociates specified projects from the specified pool. Does not affect projects which are not specified in parameters.- Specified by:
dissociateProjectsFromPool
in 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:AgentPoolManager
Dissociates 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:
dissociateProjectsFromOtherPools
in 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:AgentPoolManager
Copies set of pools associations from one project to the other.- Specified by:
copyPoolAssociations
in interfaceAgentPoolManager
- Parameters:
sourceProjectId
- sourcetargetProjectId
- target
-
getAllPoolProjectRelations
@NotNull public Collection<Pair<Integer,String>> getAllPoolProjectRelations()
Description copied from interface:AgentPoolManager
Returns all pool--project relations.- Specified by:
getAllPoolProjectRelations
in 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:AgentPoolManager
Returns all associated pools for the specified project.- Specified by:
getAgentPoolsWithProject
in interfaceAgentPoolManager
- Parameters:
projectId
- project id- Returns:
- set of agent pool ids
-
getProjectOwnedAgentPools
@NotNull public Collection<AgentPool> getProjectOwnedAgentPools(@NotNull String projectExternalId)
Description copied from interface:AgentPoolManager
Returns agent pools that include only projects that are under this project's tree (including the project itself).- Specified by:
getProjectOwnedAgentPools
in interfaceAgentPoolManager
- Returns:
-
getProjectAgentTypes
@NotNull public Set<Integer> getProjectAgentTypes(@NotNull String projectId)
Description copied from interface:AgentPoolManager
Returns all agents from pools the given projects associated with.- Specified by:
getProjectAgentTypes
in interfaceAgentPoolManager
- Parameters:
projectId
- project id- Returns:
- set of agent tyeps ids
-
getPoolProjects
@NotNull public Set<String> getPoolProjects(int poolId)
Description copied from interface:AgentPoolManager
Returns projects that are associated with the specified pool.- Specified by:
getPoolProjects
in 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:AgentPoolManager
Returns true if agent pool with specified id exists and contains project with specified internal id.- Specified by:
agentPoolContainsProject
in interfaceAgentPoolManager
- Parameters:
poolId
- pool idprojectId
- project id- Returns:
- see above
-
canAddAgent
public boolean canAddAgent(int poolId) throws NoSuchAgentPoolException
Description copied from interface:AgentPoolManager
Returns true if this pool can add least one more agent- Specified by:
canAddAgent
in interfaceAgentPoolManager
- Returns:
- see above
- Throws:
NoSuchAgentPoolException
-
canAddAgents
public boolean canAddAgents(int poolId, int count) throws NoSuchAgentPoolException
Description copied from interface:AgentPoolManager
Returns true if this pool can add desired # of agents- Specified by:
canAddAgents
in interfaceAgentPoolManager
count
- number of agents to add- Returns:
- Throws:
NoSuchAgentPoolException
-
getAgentTypeIdsByPool
@NotNull public Collection<Integer> getAgentTypeIdsByPool(int agentPoolId)
Description copied from interface:AgentPoolManager
Returns agent type ids associated with the specified pool- Specified by:
getAgentTypeIdsByPool
in interfaceAgentPoolManager
- Parameters:
agentPoolId
- - agent pool internal id
-
findAgentPoolByTypeId
@Nullable public AgentPool findAgentPoolByTypeId(int agentTypeId)
Description copied from interface:AgentPoolManager
Searches for agent pool by agent type id.- Specified by:
findAgentPoolByTypeId
in interfaceAgentPoolManager
- Parameters:
agentTypeId
- agent type id- Returns:
- found agent pool or null
-
findAgentPoolIdByTypeId
public int findAgentPoolIdByTypeId(int agentTypeId)
Description copied from interface:AgentPoolManager
Returns agent pool id for the specified agent type id or -1 if there is no such pool or agent type.- Specified by:
findAgentPoolIdByTypeId
in interfaceAgentPoolManager
- Parameters:
agentTypeId
- agent type id- Returns:
- found agent pool id or -1
-
-