Class FakeAgentTypeManager
- java.lang.Object
-
- jetbrains.buildServer.serverSide.fakes.FakeAgentTypeManager
-
- All Implemented Interfaces:
AgentTypeFinder
,AgentTypeManager
,AgentTypeStorage
public class FakeAgentTypeManager extends Object implements AgentTypeManager, AgentTypeStorage, AgentTypeFinder
Fake agent type manager. For testing purpose.- Author:
- Leonid Bushuev from JetBrains
-
-
Constructor Summary
Constructors Constructor Description FakeAgentTypeManager(FakeAgentPoolManager poolManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
assignAgentType(BuildAgentEx agent)
Creates agent type for specified agent if agent does not have one and assigns it to the agent.void
copyAgentTypeRestrictions(String originalBuildTypeId, String newBuildTypeId)
void
copyAgentTypeRestrictions(BuildTypeDescriptor originalBuildType, BuildTypeDescriptor newBuildType)
SAgentType
createAgentTypeFromKey(AgentTypeKey key, int poolId)
SAgentType
createCloudAgentType(String name, String osName)
SAgentType
createNormalAgentType(String name, String osName)
void
deleteAgentType(int agentTypeId)
void
excludeBuildTypesFromAllowed(int agentTypeId, Set<String> buildTypeIds)
Removes the given build configurations from the list of allowed ones.void
excludeRunConfigurationsFromAllowed(int agentTypeId, String[] buildTypeIds)
SAgentType
findAgentType(int agentTypeId)
AgentType
findAgentTypeById(int agentTypeId)
Finds agent type in agent type id.AgentType
findAgentTypeByKey(AgentTypeKey agentTypeKey)
Finds agent type in database by specified key.Map<Integer,AgentType>
findAgentTypesByIds(Collection<Integer> agentTypeIds)
Returns map of agent types corresponding to the specified agent type idsCollection<SAgentType>
getActiveAgentTypes()
Collection<SAgentType>
getActiveCloudAgentTypes()
List<AgentCompatibility>
getAgentTypeCompatibilities(SAgentType agentType)
Set<Integer>
getAgentTypeIds()
Returns all known agent type identifiers.Collection<Integer>
getAgentTypeIdsByPool(int agentPoolId)
Map<Integer,AgentTypeKey>
getAgentTypePairs()
Collection<SAgentType>
getAgentTypesByPool(int agentPoolId)
Set<String>
getCanRunConfigurations(int agentTypeId)
int
getNumberOfCompatibleConfigurations(SAgentType agentType)
int
getNumberOfIncompatibleConfigurations(SAgentType agentType)
int
getOrCreateAgentTypeId(AgentTypeKey key)
similar toAgentTypeManager.getOrCreateAgentTypeId(jetbrains.buildServer.serverSide.agentTypes.AgentTypeKey, int)
, puts agentType to the "Default" pool, if it doesn't existint
getOrCreateAgentTypeId(AgentTypeKey key, int defaultRawPoolId)
Maps created agent type key into agentTypeId.AgentTypePolicy
getPolicy(int agentTypeId)
Loades the policy from database (if not loaded yet) and returns it.BuildAgentManager.RunConfigurationPolicy
getRunConfigurationPolicy(int agentTypeId)
void
includeBuildTypesToAllowed(int agentTypeId, Set<String> buildTypeIds)
Adds the given build configurations to the list of allowed ones.void
includeRunConfigurationsToAllowed(int agentTypeId, String[] buildTypeIds)
void
invalidateCacheForAgentTypesFromPools(Set<Integer> agentPoolIds, CacheClearPolicy policy)
void
invalidateCacheForAllAgentTypes()
void
invalidateCacheForOneAgentType(int agentTypeId, CacheClearPolicy policy)
boolean
isAllowedToRun(int agentTypeId, String projectId, String buildTypeId)
Checks whether the given build configuration (buildTypeId) is allowed to run on the specified agent type (agentTypeId).boolean
isCanRunConfiguration(int agentTypeId, BuildTypeDescriptor buildType)
void
migrateAgentTypeKey(AgentTypeKey currentKey, AgentTypeKey newKey)
void
removeBuildTypeFromAllLists(String buildTypeId)
Removes the specified build configuration from all allowed configurations lists, and invalidates internal cache.void
setPolicyKind(int agentTypeId, int newPolicyKind)
Changes policy kind for the specified agent.void
setRunConfigurationPolicy(int agentTypeId, BuildAgentManager.RunConfigurationPolicy policy)
void
updateAgentType(int agentTypeId, AgentDescription agentDescription, boolean allowDeleteParams)
updates agent type parameters from the agent's parametersvoid
updateAgentType(BuildAgentEx agent, boolean allowDeleteParams)
updates agent type parameters from the agent's parametersvoid
updateAgentTypeFromDB(int agentTypeId)
-
-
-
Constructor Detail
-
FakeAgentTypeManager
public FakeAgentTypeManager(@NotNull FakeAgentPoolManager poolManager)
-
-
Method Detail
-
createNormalAgentType
public SAgentType createNormalAgentType(String name, String osName)
-
createCloudAgentType
public SAgentType createCloudAgentType(String name, String osName)
-
createAgentTypeFromKey
public SAgentType createAgentTypeFromKey(@NotNull AgentTypeKey key, int poolId)
-
getActiveAgentTypes
@NotNull public Collection<SAgentType> getActiveAgentTypes()
- Specified by:
getActiveAgentTypes
in interfaceAgentTypeFinder
-
getActiveCloudAgentTypes
@NotNull public Collection<SAgentType> getActiveCloudAgentTypes()
- Specified by:
getActiveCloudAgentTypes
in interfaceAgentTypeFinder
-
getAgentTypesByPool
@NotNull public Collection<SAgentType> getAgentTypesByPool(int agentPoolId)
- Specified by:
getAgentTypesByPool
in interfaceAgentTypeFinder
-
findAgentType
public SAgentType findAgentType(int agentTypeId)
- Specified by:
findAgentType
in interfaceAgentTypeFinder
-
setRunConfigurationPolicy
public void setRunConfigurationPolicy(int agentTypeId, @NotNull BuildAgentManager.RunConfigurationPolicy policy)
- Specified by:
setRunConfigurationPolicy
in interfaceAgentTypeManager
-
getRunConfigurationPolicy
@NotNull public BuildAgentManager.RunConfigurationPolicy getRunConfigurationPolicy(int agentTypeId)
- Specified by:
getRunConfigurationPolicy
in interfaceAgentTypeManager
-
findAgentTypeById
public AgentType findAgentTypeById(int agentTypeId)
Description copied from interface:AgentTypeStorage
Finds agent type in agent type id.- Specified by:
findAgentTypeById
in interfaceAgentTypeStorage
- Parameters:
agentTypeId
- agent type id.- Returns:
- loaded
AgentType
or null if agent type not found.
-
findAgentTypesByIds
@NotNull public Map<Integer,AgentType> findAgentTypesByIds(@NotNull Collection<Integer> agentTypeIds)
Description copied from interface:AgentTypeStorage
Returns map of agent types corresponding to the specified agent type ids- Specified by:
findAgentTypesByIds
in interfaceAgentTypeStorage
- Parameters:
agentTypeIds
- ids of agent types- Returns:
- see above
-
findAgentTypeByKey
@Nullable public AgentType findAgentTypeByKey(@NotNull AgentTypeKey agentTypeKey)
Description copied from interface:AgentTypeStorage
Finds agent type in database by specified key.- Specified by:
findAgentTypeByKey
in interfaceAgentTypeStorage
- Parameters:
agentTypeKey
- agent type key.- Returns:
- loaded
AgentType
or null if agent type not found.
-
getAgentTypeIds
@NotNull public Set<Integer> getAgentTypeIds()
Description copied from interface:AgentTypeStorage
Returns all known agent type identifiers.- Specified by:
getAgentTypeIds
in interfaceAgentTypeStorage
- Returns:
- set of agent type identifiers.
-
getAgentTypePairs
public Map<Integer,AgentTypeKey> getAgentTypePairs()
- Specified by:
getAgentTypePairs
in interfaceAgentTypeStorage
-
getAgentTypeIdsByPool
@NotNull public Collection<Integer> getAgentTypeIdsByPool(int agentPoolId)
- Specified by:
getAgentTypeIdsByPool
in interfaceAgentTypeStorage
-
getPolicy
@NotNull public AgentTypePolicy getPolicy(int agentTypeId)
Description copied from interface:AgentTypeStorage
Loades the policy from database (if not loaded yet) and returns it.- Specified by:
getPolicy
in interfaceAgentTypeStorage
- Parameters:
agentTypeId
- agent type.- Returns:
- policy.
-
setPolicyKind
public void setPolicyKind(int agentTypeId, int newPolicyKind)
Description copied from interface:AgentTypeStorage
Changes policy kind for the specified agent.- Specified by:
setPolicyKind
in interfaceAgentTypeStorage
- Parameters:
agentTypeId
- agent which policy to change.newPolicyKind
- new policy kind.
-
includeBuildTypesToAllowed
public void includeBuildTypesToAllowed(int agentTypeId, @NotNull Set<String> buildTypeIds)
Description copied from interface:AgentTypeStorage
Adds the given build configurations to the list of allowed ones.- Specified by:
includeBuildTypesToAllowed
in interfaceAgentTypeStorage
- Parameters:
agentTypeId
- agent type.buildTypeIds
- build configurations to add to the list of allowed.
-
excludeBuildTypesFromAllowed
public void excludeBuildTypesFromAllowed(int agentTypeId, @NotNull Set<String> buildTypeIds)
Description copied from interface:AgentTypeStorage
Removes the given build configurations from the list of allowed ones.- Specified by:
excludeBuildTypesFromAllowed
in interfaceAgentTypeStorage
- Parameters:
agentTypeId
- agent type.buildTypeIds
- build configurations to remove from the list of allowed.
-
isAllowedToRun
public boolean isAllowedToRun(int agentTypeId, @NotNull String projectId, @NotNull String buildTypeId)
Description copied from interface:AgentTypeStorage
Checks whether the given build configuration (buildTypeId) is allowed to run on the specified agent type (agentTypeId).- Specified by:
isAllowedToRun
in interfaceAgentTypeStorage
- Parameters:
agentTypeId
- agent type.buildTypeId
- build configuration. @return true if allowed.
-
removeBuildTypeFromAllLists
public void removeBuildTypeFromAllLists(@NotNull String buildTypeId)
Description copied from interface:AgentTypeStorage
Removes the specified build configuration from all allowed configurations lists, and invalidates internal cache. This method is designed to call it when a build configuration is being deleted.- Specified by:
removeBuildTypeFromAllLists
in interfaceAgentTypeStorage
- Parameters:
buildTypeId
- build configuration identifier.
-
copyAgentTypeRestrictions
public void copyAgentTypeRestrictions(@NotNull String originalBuildTypeId, @NotNull String newBuildTypeId)
- Specified by:
copyAgentTypeRestrictions
in interfaceAgentTypeStorage
-
invalidateCacheForAllAgentTypes
public void invalidateCacheForAllAgentTypes()
- Specified by:
invalidateCacheForAllAgentTypes
in interfaceAgentTypeStorage
-
invalidateCacheForAgentTypesFromPools
public void invalidateCacheForAgentTypesFromPools(@NotNull Set<Integer> agentPoolIds, @NotNull CacheClearPolicy policy)
- Specified by:
invalidateCacheForAgentTypesFromPools
in interfaceAgentTypeStorage
-
invalidateCacheForOneAgentType
public void invalidateCacheForOneAgentType(int agentTypeId, @NotNull CacheClearPolicy policy)
- Specified by:
invalidateCacheForOneAgentType
in interfaceAgentTypeStorage
-
updateAgentTypeFromDB
public void updateAgentTypeFromDB(int agentTypeId)
- Specified by:
updateAgentTypeFromDB
in interfaceAgentTypeStorage
-
deleteAgentType
public void deleteAgentType(int agentTypeId)
- Specified by:
deleteAgentType
in interfaceAgentTypeStorage
-
updateAgentType
public void updateAgentType(@NotNull BuildAgentEx agent, boolean allowDeleteParams)
Description copied from interface:AgentTypeManager
updates agent type parameters from the agent's parameters- Specified by:
updateAgentType
in interfaceAgentTypeManager
- Parameters:
agent
- the agentallowDeleteParams
- if then this is the update of agent type parameters when the agent is first registered, if false then this is a periodical update which happens while the agent is already registered and runs some builds
-
updateAgentType
public void updateAgentType(int agentTypeId, @NotNull AgentDescription agentDescription, boolean allowDeleteParams)
Description copied from interface:AgentTypeManager
updates agent type parameters from the agent's parameters- Specified by:
updateAgentType
in interfaceAgentTypeManager
- Parameters:
agentTypeId
- agent type idagentDescription
- agent description
-
assignAgentType
public int assignAgentType(@NotNull BuildAgentEx agent)
Description copied from interface:AgentTypeManager
Creates agent type for specified agent if agent does not have one and assigns it to the agent.- Specified by:
assignAgentType
in interfaceAgentTypeManager
- Returns:
- id of new agent type
-
getOrCreateAgentTypeId
public int getOrCreateAgentTypeId(@NotNull AgentTypeKey key)
Description copied from interface:AgentTypeManager
similar toAgentTypeManager.getOrCreateAgentTypeId(jetbrains.buildServer.serverSide.agentTypes.AgentTypeKey, int)
, puts agentType to the "Default" pool, if it doesn't exist- Specified by:
getOrCreateAgentTypeId
in interfaceAgentTypeManager
- Specified by:
getOrCreateAgentTypeId
in interfaceAgentTypeStorage
- Parameters:
key
- agent type key which identifier is requested.- Returns:
- agent type identifier.
-
getOrCreateAgentTypeId
public int getOrCreateAgentTypeId(@NotNull AgentTypeKey key, int defaultRawPoolId)
Description copied from interface:AgentTypeManager
Maps created agent type key into agentTypeId. This method should lookup to the storage or allocate new item.- Specified by:
getOrCreateAgentTypeId
in interfaceAgentTypeManager
- Specified by:
getOrCreateAgentTypeId
in interfaceAgentTypeStorage
- Parameters:
key
- agent type key received from plugindefaultRawPoolId
- raw pool id to assign agent type to, if one doesn't exist.- Returns:
- agent type id
-
includeRunConfigurationsToAllowed
public void includeRunConfigurationsToAllowed(int agentTypeId, @NotNull String[] buildTypeIds)
- Specified by:
includeRunConfigurationsToAllowed
in interfaceAgentTypeManager
-
excludeRunConfigurationsFromAllowed
public void excludeRunConfigurationsFromAllowed(int agentTypeId, @NotNull String[] buildTypeIds)
- Specified by:
excludeRunConfigurationsFromAllowed
in interfaceAgentTypeManager
-
getCanRunConfigurations
@NotNull public Set<String> getCanRunConfigurations(int agentTypeId)
- Specified by:
getCanRunConfigurations
in interfaceAgentTypeManager
-
isCanRunConfiguration
public boolean isCanRunConfiguration(int agentTypeId, @NotNull BuildTypeDescriptor buildType)
- Specified by:
isCanRunConfiguration
in interfaceAgentTypeManager
-
getNumberOfCompatibleConfigurations
public int getNumberOfCompatibleConfigurations(@NotNull SAgentType agentType)
- Specified by:
getNumberOfCompatibleConfigurations
in interfaceAgentTypeManager
-
getNumberOfIncompatibleConfigurations
public int getNumberOfIncompatibleConfigurations(@NotNull SAgentType agentType)
- Specified by:
getNumberOfIncompatibleConfigurations
in interfaceAgentTypeManager
-
getAgentTypeCompatibilities
@NotNull public List<AgentCompatibility> getAgentTypeCompatibilities(@NotNull SAgentType agentType)
- Specified by:
getAgentTypeCompatibilities
in interfaceAgentTypeManager
-
copyAgentTypeRestrictions
public void copyAgentTypeRestrictions(@NotNull BuildTypeDescriptor originalBuildType, @NotNull BuildTypeDescriptor newBuildType)
- Specified by:
copyAgentTypeRestrictions
in interfaceAgentTypeManager
-
migrateAgentTypeKey
public void migrateAgentTypeKey(@NotNull AgentTypeKey currentKey, @NotNull AgentTypeKey newKey)
- Specified by:
migrateAgentTypeKey
in interfaceAgentTypeManager
-
-