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 booleancollectMetrics()Returns true if cleanup process is expected to collect metrics.intgetBuildsToProcess()intgetCleanedByExtensionsBuildsCount()Returns the total number of builds processed by all extensions withBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)methods.longgetCleanedFilesSize()Returns the amount of bytes cleaned byBuildArtifactsCleaner.CleanupDecisionListenergetCleanupDecisionListener()Returns a listener for build-related clean-up reports.StringgetCurrentStage()Returns text description of the current cleanup stage.Set<String>getDryRunBuildTypesIds()longgetElapsedTime()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).InterruptReasongetInterruptReason()SUsergetInterruptUser()Map<BuildsCleanupExtension,Long>getPerExtensionCleanupBuildsDataTime()Returns the total time that was taken by all extensionsBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)methods.intgetProcessedBuilds()Collection<Long>getProcessedBuilds(CleanupLevel... cleanupLevels)Returns ids of all builds processed on specified cleanup levels.Set<String>getRecentlyRemovedBuildTypesIds()Set<String>getRemovedBuildTypesIds()Set<String>getRemovedProjectsIds()longgetStartTime()Returns cleanup start time in millis.booleanhasExtensionErrors()Returnstrueif there is an error happened during cleanup extensions call.booleanisAnyProcessedBuildForLevel(CleanupLevel cleanupLevel)Returnstrueif there is at least one processed build at specified level,falseotherwise.booleanisInProgress()booleanisInterrupted()Returnstrueif the cleanup process was interrupted.
Note for extensions: the usage ofCleanupProcessState.throwIfInterrupted()is preferred because allows to stop the cleanup process faster.booleanisMainCleanupProcess()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.voidonCleanedFilesSize(long cleanedSize)Adds the amount of bytes of cleaned files.voidonExtensionCleanupBuildsDataFinish(BuildsCleanupExtension extension, long cleanupTime)Adds the time in milliseconds that was taken by theBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)method of this extension.voidonExtensionError(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.voidonExtensionPrepareBuildsDataFinish(BuildsCleanupExtension extension, long cleanupTime)Adds the time in milliseconds that was taken by theBuildsCleanupExtension.prepareBuildsData(BuildCleanupContext)method of this extension.voidonExtensionsCleanupBuildsDataFinish(int buildsCount)Adds the number of builds processed by all enabled cleanup extensionsBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)method calls.voidreportBuildsProcessed(List<Long> buildIds, CleanupLevel cleanupLevel)Sets ids of builds already processed by cleanupvoidreportBuildsToProcess(int buildsCount)Adds count of the builds scheduled for cleanup operationvoidsetCurrentStage(String stageDescription)Sets description of current cleanup stagevoidsetDryRunBuildTypesIds(Collection<String> recentlyRemovedBuildTypesIds)voidsetInterrupted(InterruptReason reason)Marks cleanup process is interrupted with specified reason.
ForInterruptReason.STOPPED_BY_USERuse methodCleanupProcessStateEx.setInterruptedByUser(SUser)!voidsetInterruptedByUser(SUser user)Marks cleanup process as interrupted by specified uservoidsetRecentlyRemovedBuildTypesIds(Collection<String> recentlyRemovedBuildTypesIds)voidsetRemovedBuildTypesIds(Collection<String> removedBuildTypesIds)voidsetRemovedProjectsIds(Collection<String> removedProjectsIds)voidthrowIfInterrupted()ThrowsCleanupInterruptedExceptionif the cleanup process was interrupted.booleanuseArtifactPatternsCache()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:
isInProgressin interfaceCleanupProcessState- Returns:
trueif cleanup is in progress (even if it was interrupted)
-
isAnyProcessedBuildForLevel
public boolean isAnyProcessedBuildForLevel(@NotNull CleanupLevel cleanupLevel)Description copied from interface:CleanupProcessStateExReturnstrueif there is at least one processed build at specified level,falseotherwise.- Specified by:
isAnyProcessedBuildForLevelin interfaceCleanupProcessStateEx
-
getProcessedBuilds
@NotNull public Collection<Long> getProcessedBuilds(@NotNull CleanupLevel... cleanupLevels)
Description copied from interface:CleanupProcessStateReturns ids of all builds processed on specified cleanup levels.- Specified by:
getProcessedBuildsin 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:
getRemovedProjectsIdsin 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:
getRemovedBuildTypesIdsin 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:CleanupProcessStateExAdds count of the builds scheduled for cleanup operation- Specified by:
reportBuildsToProcessin 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:CleanupProcessStateExSets ids of builds already processed by cleanup- Specified by:
reportBuildsProcessedin interfaceCleanupProcessStateEx- Parameters:
buildIds- ids of builds already processed by cleanup
-
setCurrentStage
public void setCurrentStage(@NotNull String stageDescription)Description copied from interface:CleanupProcessStateExSets description of current cleanup stage- Specified by:
setCurrentStagein interfaceCleanupProcessStateEx- Parameters:
stageDescription- cleanup stage description
-
getCurrentStage
@NotNull public String getCurrentStage()
Description copied from interface:CleanupProcessStateReturns text description of the current cleanup stage.- Specified by:
getCurrentStagein interfaceCleanupProcessState- Returns:
- returns text description of current cleanup stage
-
getProcessedBuilds
public int getProcessedBuilds()
- Specified by:
getProcessedBuildsin interfaceCleanupProcessState- Returns:
- number of processed builds or
-1it there is none of them
-
getBuildsToProcess
public int getBuildsToProcess()
- Specified by:
getBuildsToProcessin interfaceCleanupProcessState- Returns:
- number of builds scheduled to cleanup but not yet processed
-
getStartTime
public long getStartTime()
Description copied from interface:CleanupProcessStateExReturns cleanup start time in millis.- Specified by:
getStartTimein interfaceCleanupProcessStateEx
-
getElapsedTime
public long getElapsedTime()
- Specified by:
getElapsedTimein interfaceCleanupProcessState- Returns:
- returns cleanup process elapsed time in milliseconds
-
isInterrupted
public boolean isInterrupted()
Description copied from interface:CleanupProcessStateReturnstrueif the cleanup process was interrupted.
Note for extensions: the usage ofCleanupProcessState.throwIfInterrupted()is preferred because allows to stop the cleanup process faster.- Specified by:
isInterruptedin interfaceCleanupProcessState- Returns:
trueif the cleanup process was interrupted- See Also:
CleanupProcessState.throwIfInterrupted()
-
throwIfInterrupted
public void throwIfInterrupted() throws CleanupInterruptedExceptionDescription copied from interface:CleanupProcessStateThrowsCleanupInterruptedExceptionif the cleanup process was interrupted.- Specified by:
throwIfInterruptedin interfaceCleanupProcessState- Throws:
CleanupInterruptedException- if the cleanup process was interrupted.
-
getInterruptReason
@Nullable public InterruptReason getInterruptReason()
- Specified by:
getInterruptReasonin interfaceCleanupProcessState- Returns:
- if cleanup interrupted, returns reason of interruption
-
getInterruptUser
@Nullable public SUser getInterruptUser()
- Specified by:
getInterruptUserin interfaceCleanupProcessState- Returns:
- if cleanup interrupted, returns user who interrupted it
-
setInterrupted
public void setInterrupted(@NotNull InterruptReason reason)Description copied from interface:CleanupProcessStateExMarks cleanup process is interrupted with specified reason.
ForInterruptReason.STOPPED_BY_USERuse methodCleanupProcessStateEx.setInterruptedByUser(SUser)!- Specified by:
setInterruptedin interfaceCleanupProcessStateEx- Parameters:
reason- reason
-
setInterruptedByUser
public void setInterruptedByUser(@NotNull SUser user)Description copied from interface:CleanupProcessStateExMarks cleanup process as interrupted by specified user- Specified by:
setInterruptedByUserin interfaceCleanupProcessStateEx- Parameters:
user- user who interrupted cleanup
-
isMainCleanupProcess
public boolean isMainCleanupProcess()
Description copied from interface:CleanupProcessStateExReturns 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:
isMainCleanupProcessin interfaceCleanupProcessStateEx
-
useArtifactPatternsCache
public boolean useArtifactPatternsCache()
Description copied from interface:CleanupProcessStateExReturns true if cleanup process is expected to use cache of applied keep artifact patterns for particular builds.- Specified by:
useArtifactPatternsCachein interfaceCleanupProcessStateEx
-
collectMetrics
public boolean collectMetrics()
Description copied from interface:CleanupProcessStateExReturns true if cleanup process is expected to collect metrics.- Specified by:
collectMetricsin interfaceCleanupProcessStateEx
-
onExtensionError
public void onExtensionError(@NotNull String extensionName, @NotNull Collection<? extends SBuild> builds, @NotNull String errorMessage, @NotNull CleanupLevel level)Description copied from interface:CleanupProcessStateExStores an information about an error happened during the cleanup extension call and about affected builds.- Specified by:
onExtensionErrorin interfaceCleanupProcessStateEx
-
hasExtensionErrors
public boolean hasExtensionErrors()
Description copied from interface:CleanupProcessStateExReturnstrueif there is an error happened during cleanup extensions call.- Specified by:
hasExtensionErrorsin interfaceCleanupProcessStateEx- See Also:
CleanupProcessStateEx.getExtensionErrorsMap()
-
getExtensionErrorsMap
@NotNull public NavigableMap<ExtensionError,Map<String,Pair<List<Long>,List<Long>>>> getExtensionErrorsMap()
Description copied from interface:CleanupProcessStateExReturns 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:
getExtensionErrorsMapin interfaceCleanupProcessStateEx
-
onCleanedFilesSize
public void onCleanedFilesSize(long cleanedSize)
Description copied from interface:CleanupProcessStateExAdds the amount of bytes of cleaned files.- Specified by:
onCleanedFilesSizein interfaceCleanupProcessStateEx
-
getCleanedFilesSize
public long getCleanedFilesSize()
Description copied from interface:CleanupProcessStateExReturns the amount of bytes cleaned byBuildArtifactsCleaner. Artifacts cleaned in external repositories (like S3, Docker) are not taken into account.- Specified by:
getCleanedFilesSizein interfaceCleanupProcessStateEx
-
onExtensionPrepareBuildsDataFinish
public void onExtensionPrepareBuildsDataFinish(@NotNull BuildsCleanupExtension extension, long cleanupTime)Description copied from interface:CleanupProcessStateExAdds the time in milliseconds that was taken by theBuildsCleanupExtension.prepareBuildsData(BuildCleanupContext)method of this extension.- Specified by:
onExtensionPrepareBuildsDataFinishin interfaceCleanupProcessStateEx
-
onExtensionCleanupBuildsDataFinish
public void onExtensionCleanupBuildsDataFinish(@NotNull BuildsCleanupExtension extension, long cleanupTime)Description copied from interface:CleanupProcessStateExAdds the time in milliseconds that was taken by theBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)method of this extension.- Specified by:
onExtensionCleanupBuildsDataFinishin interfaceCleanupProcessStateEx
-
getPerExtensionCleanupBuildsDataTime
@NotNull public Map<BuildsCleanupExtension,Long> getPerExtensionCleanupBuildsDataTime()
Description copied from interface:CleanupProcessStateExReturns the total time that was taken by all extensionsBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)methods.- Specified by:
getPerExtensionCleanupBuildsDataTimein interfaceCleanupProcessStateEx
-
onExtensionsCleanupBuildsDataFinish
public void onExtensionsCleanupBuildsDataFinish(int buildsCount)
Description copied from interface:CleanupProcessStateExAdds 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:
onExtensionsCleanupBuildsDataFinishin interfaceCleanupProcessStateEx
-
getCleanedByExtensionsBuildsCount
public int getCleanedByExtensionsBuildsCount()
Description copied from interface:CleanupProcessStateExReturns the total number of builds processed by all extensions withBuildsCleanupExtension.cleanupBuildsData(jetbrains.buildServer.serverSide.cleanup.BuildCleanupContext)methods.- Specified by:
getCleanedByExtensionsBuildsCountin interfaceCleanupProcessStateEx
-
getCleanupDecisionListener
@NotNull public CleanupDecisionListener getCleanupDecisionListener()
Description copied from interface:CleanupProcessStateExReturns a listener for build-related clean-up reports.- Specified by:
getCleanupDecisionListenerin interfaceCleanupProcessStateEx
-
setDryRunBuildTypesIds
public void setDryRunBuildTypesIds(@NotNull Collection<String> recentlyRemovedBuildTypesIds)
-
getDryRunBuildTypesIds
@NotNull public Set<String> getDryRunBuildTypesIds()
- Specified by:
getDryRunBuildTypesIdsin interfaceCleanupProcessStateEx- Returns:
- a collection of internal build type ids marke for dry-run cleanup.
-
-