Class ServerCleanupState
- java.lang.Object
-
- jetbrains.buildServer.serverSide.impl.cleanup.ServerCleanupState
-
- All Implemented Interfaces:
CleanupProcessState
,CleanupProcessStateEx
@ThreadSafe public class ServerCleanupState extends Object implements CleanupProcessStateEx
-
-
Constructor Summary
Constructors Constructor Description ServerCleanupState(TimeService timeService, CleanupHistoryManager cleanupHistoryManager, CustomDataStorageManager customDataStorage)
ServerCleanupState(TimeService timeService, CleanupHistoryManager cleanupHistoryManager, CustomDataStorageManager customDataStorage, boolean isMainCleanupProcess)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
collectMetrics()
Returns true if cleanup process is expected to collect metrics.int
getBuildsToProcess()
int
getCleanedByExtensionsBuildsCount()
Returns the total number of builds processed by all extensions withBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)
methods.long
getCleanedFilesSize()
Returns the amount of bytes cleaned byBuildArtifactsCleaner
.CleanupDecisionListener
getCleanupDecisionListener()
Returns a listener for build-related clean-up reports.String
getCurrentStage()
Returns text description of the current cleanup stage.Set<String>
getDryRunBuildTypesIds()
long
getElapsedTime()
NavigableMap<ExtensionError,Map<String,Pair<List<Long>,List<Long>>>>
getExtensionErrorsMap()
Returns an information about all exceptions that happened during cleanup extension call and about affected builds:
Error data -> affected build type id -> (ids of partly cleaned builds, ids of removed from history builds).
InterruptReason
getInterruptReason()
SUser
getInterruptUser()
Map<BuildsCleanupExtension,Long>
getPerExtensionCleanupBuildsDataTime()
Returns the total time that was taken by all extensionsBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)
methods.int
getProcessedBuilds()
Collection<Long>
getProcessedBuilds(CleanupLevel... cleanupLevels)
Returns ids of all builds processed on specified cleanup levels.Set<String>
getRecentlyRemovedBuildTypesIds()
Set<String>
getRemovedBuildTypesIds()
Set<String>
getRemovedProjectsIds()
long
getStartTime()
Returns cleanup start time in millis.boolean
hasExtensionErrors()
Returnstrue
if there is an error happened during cleanup extensions call.boolean
isAnyProcessedBuildForLevel(CleanupLevel cleanupLevel)
Returnstrue
if there is at least one processed build at specified level,false
otherwise.boolean
isInProgress()
boolean
isInterrupted()
Returnstrue
if the cleanup process was interrupted.
Note for extensions: the usage ofCleanupProcessState.throwIfInterrupted()
is preferred because allows to stop the cleanup process faster.boolean
isMainCleanupProcess()
Returns true if cleanup process is running as a part of the main cleanup process - which can be used by extensions to optimise cleanup behaviour.void
onCleanedFilesSize(long cleanedSize)
Adds the amount of bytes of cleaned files.void
onExtensionCleanupBuildsDataFinish(BuildsCleanupExtension extension, long cleanupTime)
Adds the time in milliseconds that was taken by theBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)
method of this extension.void
onExtensionError(String extensionName, Collection<? extends SBuild> builds, String errorMessage, CleanupLevel level)
Stores an information about an error happened during the cleanup extension call and about affected builds.void
onExtensionPrepareBuildsDataFinish(BuildsCleanupExtension extension, long cleanupTime)
Adds the time in milliseconds that was taken by theBuildsCleanupExtension.prepareBuildsData(BuildCleanupContext)
method of this extension.void
onExtensionsCleanupBuildsDataFinish(int buildsCount)
Adds the number of builds processed by all enabled cleanup extensionsBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)
method calls.void
reportBuildsProcessed(List<Long> buildIds, CleanupLevel cleanupLevel)
Sets ids of builds already processed by cleanupvoid
reportBuildsToProcess(int buildsCount)
Adds count of the builds scheduled for cleanup operationvoid
setCurrentStage(String stageDescription)
Sets description of current cleanup stagevoid
setDryRunBuildTypesIds(Collection<String> recentlyRemovedBuildTypesIds)
void
setInterrupted(InterruptReason reason)
Marks cleanup process is interrupted with specified reason.
ForInterruptReason.STOPPED_BY_USER
use methodCleanupProcessStateEx.setInterruptedByUser(SUser)
!void
setInterruptedByUser(SUser user)
Marks cleanup process as interrupted by specified uservoid
setRecentlyRemovedBuildTypesIds(Collection<String> recentlyRemovedBuildTypesIds)
void
setRemovedBuildTypesIds(Collection<String> removedBuildTypesIds)
void
setRemovedProjectsIds(Collection<String> removedProjectsIds)
void
throwIfInterrupted()
ThrowsCleanupInterruptedException
if the cleanup process was interrupted.boolean
useArtifactPatternsCache()
Returns true if cleanup process is expected to use cache of applied keep artifact patterns for particular builds.
-
-
-
Constructor Detail
-
ServerCleanupState
public ServerCleanupState(@NotNull TimeService timeService, @NotNull CleanupHistoryManager cleanupHistoryManager, @NotNull CustomDataStorageManager customDataStorage, boolean isMainCleanupProcess)
-
ServerCleanupState
public ServerCleanupState(@NotNull TimeService timeService, @NotNull CleanupHistoryManager cleanupHistoryManager, @NotNull CustomDataStorageManager customDataStorage)
-
-
Method Detail
-
isInProgress
public boolean isInProgress()
- Specified by:
isInProgress
in interfaceCleanupProcessState
- Returns:
true
if cleanup is in progress (even if it was interrupted)
-
isAnyProcessedBuildForLevel
public boolean isAnyProcessedBuildForLevel(@NotNull CleanupLevel cleanupLevel)
Description copied from interface:CleanupProcessStateEx
Returnstrue
if there is at least one processed build at specified level,false
otherwise.- Specified by:
isAnyProcessedBuildForLevel
in interfaceCleanupProcessStateEx
-
getProcessedBuilds
@NotNull public Collection<Long> getProcessedBuilds(@NotNull CleanupLevel... cleanupLevels)
Description copied from interface:CleanupProcessState
Returns ids of all builds processed on specified cleanup levels.- Specified by:
getProcessedBuilds
in interfaceCleanupProcessState
- Parameters:
cleanupLevels
- cleanup levels- Returns:
- ids of processed builds
-
setRemovedProjectsIds
public void setRemovedProjectsIds(@NotNull Collection<String> removedProjectsIds)
-
getRemovedProjectsIds
@NotNull public Set<String> getRemovedProjectsIds()
- Specified by:
getRemovedProjectsIds
in interfaceCleanupProcessState
- Returns:
- a collection of internal project ids for the removed projects whose data should be cleaned up
-
setRemovedBuildTypesIds
public void setRemovedBuildTypesIds(@NotNull Collection<String> removedBuildTypesIds)
-
getRemovedBuildTypesIds
@NotNull public Set<String> getRemovedBuildTypesIds()
- Specified by:
getRemovedBuildTypesIds
in interfaceCleanupProcessState
- Returns:
- a collection of internal build type ids of the removed build configurations
-
setRecentlyRemovedBuildTypesIds
public void setRecentlyRemovedBuildTypesIds(@NotNull Collection<String> recentlyRemovedBuildTypesIds)
-
reportBuildsToProcess
public void reportBuildsToProcess(int buildsCount)
Description copied from interface:CleanupProcessStateEx
Adds count of the builds scheduled for cleanup operation- Specified by:
reportBuildsToProcess
in interfaceCleanupProcessStateEx
- Parameters:
buildsCount
- count of the builds scheduled for cleanup operation
-
reportBuildsProcessed
public void reportBuildsProcessed(@NotNull List<Long> buildIds, @NotNull CleanupLevel cleanupLevel)
Description copied from interface:CleanupProcessStateEx
Sets ids of builds already processed by cleanup- Specified by:
reportBuildsProcessed
in interfaceCleanupProcessStateEx
- Parameters:
buildIds
- ids of builds already processed by cleanup
-
setCurrentStage
public void setCurrentStage(@NotNull String stageDescription)
Description copied from interface:CleanupProcessStateEx
Sets description of current cleanup stage- Specified by:
setCurrentStage
in interfaceCleanupProcessStateEx
- Parameters:
stageDescription
- cleanup stage description
-
getCurrentStage
@NotNull public String getCurrentStage()
Description copied from interface:CleanupProcessState
Returns text description of the current cleanup stage.- Specified by:
getCurrentStage
in interfaceCleanupProcessState
- Returns:
- returns text description of current cleanup stage
-
getProcessedBuilds
public int getProcessedBuilds()
- Specified by:
getProcessedBuilds
in interfaceCleanupProcessState
- Returns:
- number of processed builds or
-1
it there is none of them
-
getBuildsToProcess
public int getBuildsToProcess()
- Specified by:
getBuildsToProcess
in interfaceCleanupProcessState
- Returns:
- number of builds scheduled to cleanup but not yet processed
-
getStartTime
public long getStartTime()
Description copied from interface:CleanupProcessStateEx
Returns cleanup start time in millis.- Specified by:
getStartTime
in interfaceCleanupProcessStateEx
-
getElapsedTime
public long getElapsedTime()
- Specified by:
getElapsedTime
in interfaceCleanupProcessState
- Returns:
- returns cleanup process elapsed time in milliseconds
-
isInterrupted
public boolean isInterrupted()
Description copied from interface:CleanupProcessState
Returnstrue
if the cleanup process was interrupted.
Note for extensions: the usage ofCleanupProcessState.throwIfInterrupted()
is preferred because allows to stop the cleanup process faster.- Specified by:
isInterrupted
in interfaceCleanupProcessState
- Returns:
true
if the cleanup process was interrupted- See Also:
CleanupProcessState.throwIfInterrupted()
-
throwIfInterrupted
public void throwIfInterrupted() throws CleanupInterruptedException
Description copied from interface:CleanupProcessState
ThrowsCleanupInterruptedException
if the cleanup process was interrupted.- Specified by:
throwIfInterrupted
in interfaceCleanupProcessState
- Throws:
CleanupInterruptedException
- if the cleanup process was interrupted.
-
getInterruptReason
@Nullable public InterruptReason getInterruptReason()
- Specified by:
getInterruptReason
in interfaceCleanupProcessState
- Returns:
- if cleanup interrupted, returns reason of interruption
-
getInterruptUser
@Nullable public SUser getInterruptUser()
- Specified by:
getInterruptUser
in interfaceCleanupProcessState
- Returns:
- if cleanup interrupted, returns user who interrupted it
-
setInterrupted
public void setInterrupted(@NotNull InterruptReason reason)
Description copied from interface:CleanupProcessStateEx
Marks cleanup process is interrupted with specified reason.
ForInterruptReason.STOPPED_BY_USER
use methodCleanupProcessStateEx.setInterruptedByUser(SUser)
!- Specified by:
setInterrupted
in interfaceCleanupProcessStateEx
- Parameters:
reason
- reason
-
setInterruptedByUser
public void setInterruptedByUser(@NotNull SUser user)
Description copied from interface:CleanupProcessStateEx
Marks cleanup process as interrupted by specified user- Specified by:
setInterruptedByUser
in interfaceCleanupProcessStateEx
- Parameters:
user
- user who interrupted cleanup
-
isMainCleanupProcess
public boolean isMainCleanupProcess()
Description copied from interface:CleanupProcessStateEx
Returns true if cleanup process is running as a part of the main cleanup process - which can be used by extensions to optimise cleanup behaviour.- Specified by:
isMainCleanupProcess
in interfaceCleanupProcessStateEx
-
useArtifactPatternsCache
public boolean useArtifactPatternsCache()
Description copied from interface:CleanupProcessStateEx
Returns true if cleanup process is expected to use cache of applied keep artifact patterns for particular builds.- Specified by:
useArtifactPatternsCache
in interfaceCleanupProcessStateEx
-
collectMetrics
public boolean collectMetrics()
Description copied from interface:CleanupProcessStateEx
Returns true if cleanup process is expected to collect metrics.- Specified by:
collectMetrics
in interfaceCleanupProcessStateEx
-
onExtensionError
public void onExtensionError(@NotNull String extensionName, @NotNull Collection<? extends SBuild> builds, @NotNull String errorMessage, @NotNull CleanupLevel level)
Description copied from interface:CleanupProcessStateEx
Stores an information about an error happened during the cleanup extension call and about affected builds.- Specified by:
onExtensionError
in interfaceCleanupProcessStateEx
-
hasExtensionErrors
public boolean hasExtensionErrors()
Description copied from interface:CleanupProcessStateEx
Returnstrue
if there is an error happened during cleanup extensions call.- Specified by:
hasExtensionErrors
in interfaceCleanupProcessStateEx
- See Also:
CleanupProcessStateEx.getExtensionErrorsMap()
-
getExtensionErrorsMap
@NotNull public NavigableMap<ExtensionError,Map<String,Pair<List<Long>,List<Long>>>> getExtensionErrorsMap()
Description copied from interface:CleanupProcessStateEx
Returns an information about all exceptions that happened during cleanup extension call and about affected builds:
Error data -> affected build type id -> (ids of partly cleaned builds, ids of removed from history builds).
- Specified by:
getExtensionErrorsMap
in interfaceCleanupProcessStateEx
-
onCleanedFilesSize
public void onCleanedFilesSize(long cleanedSize)
Description copied from interface:CleanupProcessStateEx
Adds the amount of bytes of cleaned files.- Specified by:
onCleanedFilesSize
in interfaceCleanupProcessStateEx
-
getCleanedFilesSize
public long getCleanedFilesSize()
Description copied from interface:CleanupProcessStateEx
Returns the amount of bytes cleaned byBuildArtifactsCleaner
. Artifacts cleaned in external repositories (like S3, Docker) are not taken into account.- Specified by:
getCleanedFilesSize
in interfaceCleanupProcessStateEx
-
onExtensionPrepareBuildsDataFinish
public void onExtensionPrepareBuildsDataFinish(@NotNull BuildsCleanupExtension extension, long cleanupTime)
Description copied from interface:CleanupProcessStateEx
Adds the time in milliseconds that was taken by theBuildsCleanupExtension.prepareBuildsData(BuildCleanupContext)
method of this extension.- Specified by:
onExtensionPrepareBuildsDataFinish
in interfaceCleanupProcessStateEx
-
onExtensionCleanupBuildsDataFinish
public void onExtensionCleanupBuildsDataFinish(@NotNull BuildsCleanupExtension extension, long cleanupTime)
Description copied from interface:CleanupProcessStateEx
Adds the time in milliseconds that was taken by theBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)
method of this extension.- Specified by:
onExtensionCleanupBuildsDataFinish
in interfaceCleanupProcessStateEx
-
getPerExtensionCleanupBuildsDataTime
@NotNull public Map<BuildsCleanupExtension,Long> getPerExtensionCleanupBuildsDataTime()
Description copied from interface:CleanupProcessStateEx
Returns the total time that was taken by all extensionsBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)
methods.- Specified by:
getPerExtensionCleanupBuildsDataTime
in interfaceCleanupProcessStateEx
-
onExtensionsCleanupBuildsDataFinish
public void onExtensionsCleanupBuildsDataFinish(int buildsCount)
Description copied from interface:CleanupProcessStateEx
Adds the number of builds processed by all enabled cleanup extensionsBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)
method calls. Expected to be "pack size" or lesser when we skip some builds that were processed during previous clean-up processes.- Specified by:
onExtensionsCleanupBuildsDataFinish
in interfaceCleanupProcessStateEx
-
getCleanedByExtensionsBuildsCount
public int getCleanedByExtensionsBuildsCount()
Description copied from interface:CleanupProcessStateEx
Returns the total number of builds processed by all extensions withBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)
methods.- Specified by:
getCleanedByExtensionsBuildsCount
in interfaceCleanupProcessStateEx
-
getCleanupDecisionListener
@NotNull public CleanupDecisionListener getCleanupDecisionListener()
Description copied from interface:CleanupProcessStateEx
Returns a listener for build-related clean-up reports.- Specified by:
getCleanupDecisionListener
in interfaceCleanupProcessStateEx
-
setDryRunBuildTypesIds
public void setDryRunBuildTypesIds(@NotNull Collection<String> recentlyRemovedBuildTypesIds)
-
getDryRunBuildTypesIds
@NotNull public Set<String> getDryRunBuildTypesIds()
- Specified by:
getDryRunBuildTypesIds
in interfaceCleanupProcessStateEx
- Returns:
- a collection of internal build type ids marke for dry-run cleanup.
-
-