Class DiskUsage
- java.lang.Object
-
- jetbrains.buildServer.serverSide.statistics.diskusage.DiskUsage
-
- All Implemented Interfaces:
DiskUsagePersister
,DiskUsageViewer
public class DiskUsage extends Object implements DiskUsagePersister, DiskUsageViewer
User: Andrey Titov Date: 1/17/13Provides disk usage data. Collects usage data over artifacts and logs scanning artifact directories recursively.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DiskUsage.BuildData
-
Field Summary
Fields Modifier and Type Field Description static String
FREE_SPACE_CALCULATOR_INCLUDE_EXTERNAL_STORAGES_PROPERTY
static String
TC_PROPERTY_HUGE_LOG_SIZE_ALERT_LEVEL
-
Constructor Summary
Constructors Constructor Description DiskUsage(ProjectManager projectManager, ServerSettings serverSettings, DiskUsageStoreProvider diskUsageStoreProvider, FileSystemFacade fileSystemFacade, InMemoryProjectDiskUsage inMemoryProjectDiskUsage, ArtifactStorageDiskUsageInfoProvider artifactStorageDiskUsageInfoProvider, BuildHistoryEx buildHistory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beforeBuildsDeletedFromHistory(List<SFinishedBuild> builds)
This method should be called for builds deleted from history before their cleanup.void
buildArtifactsCleaned(SBuildType buildType, long buildId, boolean wasPinned, boolean noArtifactsLeft, boolean allRemoved, long removedArtifacts, long removedInternalArtifacts, long removedLogs)
Updates data over a build type after partial or full build cleanup.void
buildArtifactsCleaned(SBuildType buildType, long buildId, boolean wasPinned, boolean noArtifactsLeft, boolean allRemoved, long removedArtifacts, long removedInternalArtifacts, long removedLogs, String storageId)
Map<SProject,Map<String,CompositeDiskUsageData>>
getAllData()
long
getArtifactsDirectoryFreeSpace()
The return value is usable disk spaceCompositeDiskUsageData
getData(SBuildType bt)
Disk usage data is stored in cache so it could be outdated.List<CompositeDiskUsageData>
getData(SProject project)
Disk usage data is stored in cache so it could be outdated.List<CompositeDiskUsageData>
getDataWithSubprojects(SProject project)
The method calculates disk usage data for all subproject of a given SProject including itself.long
getLastUpdateDate(SBuildType buildType)
long
getLastUpdateDuration()
Date
getLastUpdateTime()
long
getLogsDirectoryFreeSpace()
The return value is usable disk spacelong
getPinnedArtifactsSize()
long
getPinnedBuildsArtifactsSize(SBuildType buildType)
long
getPinnedBuildsLogsSize(SBuildType buildType)
long
getPinnedBuildsNumber()
long
getPinnedBuildsNumber(SBuildType buildType)
long
getPinnedBuildsSize(SBuildType buildType)
long
getPinnedLogsSize()
static long
getSizeThreshold()
long
getTotalArtifactsSize()
long
getTotalLogsSize()
long
getVersion(SBuildType buildType)
Disk usage data is stored versioned.boolean
hasData(SBuildType bt)
static boolean
isBuildLogSizeHuge(long estimateSize)
static boolean
isDiskUsageEnabled()
static boolean
isProjectDiskUsageUsed()
void
junkDeleted(SBuildType buildType, long totalDeleted, String storageId)
Decreases 'non-builds data' for buildTypeCompositeDiskUsageData
peekData(SBuildType bt)
Disk usage data is stored in cache so it could be outdated.List<CompositeDiskUsageData>
peekData(SProject project)
Disk usage data is stored in cache so it could be outdated.DiskUsageProjectRow
peekHierarchy(SProject rootProject)
Peeks collected data for all projects.DiskUsageProjectRow
peekHierarchySingleProject(SProject rootProject)
DiskUsageRow
peekRow(SBuildType bt)
This method peeks collected data for a build type wrapping data objects to DiskUsageRow instances.Map<SProject,DiskUsageProjectRow>
peekRows(Collection<SProject> project)
This method peeks collected data for a number of projects wrapping data objects to DiskUsageProjectRow instances.List<DiskUsageRow>
peekRows(SProject project)
This method peeks collected data for a project wrapping data objects to DiskUsageRow instances.void
recalculateAllData(UpdateAllProgress progress)
Recalculates all data recursively going to each artifact directoryvoid
recalculateBuild(SBuild build)
Recalculates a single buildCompositeDiskUsageData
recalculateData(SBuildType bt)
Recalculates a single build typevoid
recalculateProject(SProject project)
void
setLastUpdateDuration(long lastUpdateDurationMs)
Sets the duration of last full scanvoid
setLastUpdateTime(Date lastUpdateTime)
Sets the date of last full scanstatic OptionalLong
tryParseLong(String s)
void
updateBuildPinned(SBuild build)
Save disk usage data over the pinned buildvoid
updateBuildUnpinned(SBuild build)
Save disk usage data over the unpinned build
-
-
-
Field Detail
-
TC_PROPERTY_HUGE_LOG_SIZE_ALERT_LEVEL
public static final String TC_PROPERTY_HUGE_LOG_SIZE_ALERT_LEVEL
- See Also:
- Constant Field Values
-
FREE_SPACE_CALCULATOR_INCLUDE_EXTERNAL_STORAGES_PROPERTY
public static final String FREE_SPACE_CALCULATOR_INCLUDE_EXTERNAL_STORAGES_PROPERTY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DiskUsage
public DiskUsage(@NotNull ProjectManager projectManager, @NotNull ServerSettings serverSettings, @NotNull DiskUsageStoreProvider diskUsageStoreProvider, @NotNull FileSystemFacade fileSystemFacade, @NotNull InMemoryProjectDiskUsage inMemoryProjectDiskUsage, @NotNull ArtifactStorageDiskUsageInfoProvider artifactStorageDiskUsageInfoProvider, @NotNull BuildHistoryEx buildHistory)
-
-
Method Detail
-
isBuildLogSizeHuge
public static boolean isBuildLogSizeHuge(long estimateSize)
-
getSizeThreshold
public static long getSizeThreshold()
-
isDiskUsageEnabled
public static boolean isDiskUsageEnabled()
-
getAllData
@NotNull public Map<SProject,Map<String,CompositeDiskUsageData>> getAllData()
- Returns:
- All collected data. Can run for quite long time at the first run.
-
peekRows
@NotNull public Map<SProject,DiskUsageProjectRow> peekRows(@NotNull Collection<SProject> project)
Description copied from interface:DiskUsageViewer
This method peeks collected data for a number of projects wrapping data objects to DiskUsageProjectRow instances. As peek method it doesn't recalculate missing data.
- Specified by:
peekRows
in interfaceDiskUsageViewer
- Parameters:
project
- projects to collect rows- Returns:
- map of packed rows.
-
peekHierarchy
@NotNull public DiskUsageProjectRow peekHierarchy(@NotNull SProject rootProject)
Description copied from interface:DiskUsageViewer
Peeks collected data for all projects. Doesn't recalculate missing data
- Specified by:
peekHierarchy
in interfaceDiskUsageViewer
- Returns:
-
peekHierarchySingleProject
@NotNull public DiskUsageProjectRow peekHierarchySingleProject(@NotNull SProject rootProject)
- Specified by:
peekHierarchySingleProject
in interfaceDiskUsageViewer
-
isProjectDiskUsageUsed
public static boolean isProjectDiskUsageUsed()
-
recalculateAllData
public void recalculateAllData(@NotNull UpdateAllProgress progress)
Recalculates all data recursively going to each artifact directory
- Specified by:
recalculateAllData
in interfaceDiskUsagePersister
- Parameters:
progress
- UpdateAllProgress instance that can be used to watch the progress.
-
getData
@NotNull public CompositeDiskUsageData getData(@NotNull SBuildType bt)
Disk usage data is stored in cache so it could be outdated. Use
recalculateData
orDiskUsageTaskExecutor
to update values. Disk usage data will be calculated in this method if data was not collected yet. UsepeekData
to avoid blocking.- Parameters:
bt
- Build type to collect disk usage data for- Returns:
- disk usage data over one BuildType
-
getData
@NotNull public List<CompositeDiskUsageData> getData(@NotNull SProject project)
Disk usage data is stored in cache so it could be outdated. Use
recalculateData
orDiskUsageTaskExecutor
to update values. Disk usage data will be calculated in this method if data was not collected yet. UsepeekData
to avoid blocking.- Parameters:
project
- Project to collect usage data in- Returns:
- disk usage data over all configurations in specified project
-
peekData
@NotNull public CompositeDiskUsageData peekData(@NotNull SBuildType bt)
Description copied from interface:DiskUsageViewer
Disk usage data is stored in cache so it could be outdated. Use
recalculateData
orDiskUsageTaskExecutor
to update values.This method doesn't calculate data when it's not available
- Specified by:
peekData
in interfaceDiskUsageViewer
- Parameters:
bt
- Build type to collect disk usage data for- Returns:
- disk usage data over one BuildType
-
hasData
public boolean hasData(@NotNull SBuildType bt)
- Specified by:
hasData
in interfaceDiskUsagePersister
- Returns:
- true if there is any saved data over provided buildType
-
peekData
@NotNull public List<CompositeDiskUsageData> peekData(@NotNull SProject project)
Description copied from interface:DiskUsageViewer
Disk usage data is stored in cache so it could be outdated. Use
recalculateData
orDiskUsageTaskExecutor
to update values.This method doesn't calculate data when it's not available
- Specified by:
peekData
in interfaceDiskUsageViewer
- Parameters:
project
- Project to collect usage data in- Returns:
- disk usage data over all configurations in specified project
-
peekRows
@NotNull public List<DiskUsageRow> peekRows(@NotNull SProject project)
Description copied from interface:DiskUsageViewer
This method peeks collected data for a project wrapping data objects to DiskUsageRow instances. As peek method it doesn't recalculate missing data.
- Specified by:
peekRows
in interfaceDiskUsageViewer
- Parameters:
project
- project to collect rows- Returns:
- list of packed rows.
-
peekRow
@Nullable public DiskUsageRow peekRow(@NotNull SBuildType bt)
Description copied from interface:DiskUsageViewer
This method peeks collected data for a build type wrapping data objects to DiskUsageRow instances. As peek method it doesn't recalculate missing data.
- Specified by:
peekRow
in interfaceDiskUsageViewer
- Parameters:
bt
- build configuration to collect rows- Returns:
- packed row
-
getDataWithSubprojects
@NotNull public List<CompositeDiskUsageData> getDataWithSubprojects(@Nullable SProject project)
The method calculates disk usage data for all subproject of a given SProject including itself.
Disk usage data is stored in cache so it could be outdated. Use
recalculateData
orDiskUsageTaskExecutor
to update values.- Parameters:
project
- Project to collect disk usage data from. Root project will be used if null.- Returns:
- CompositeDiskUsageData instances including the ones for
project
and for all in't ancestors
-
recalculateData
@NotNull public CompositeDiskUsageData recalculateData(@NotNull SBuildType bt)
Description copied from interface:DiskUsagePersister
Recalculates a single build type
- Specified by:
recalculateData
in interfaceDiskUsagePersister
- Returns:
-
buildArtifactsCleaned
public void buildArtifactsCleaned(@NotNull SBuildType buildType, long buildId, boolean wasPinned, boolean noArtifactsLeft, boolean allRemoved, long removedArtifacts, long removedInternalArtifacts, long removedLogs)
Description copied from interface:DiskUsagePersister
Updates data over a build type after partial or full build cleanup. If allRemoved is true (build is completely removed)CompositeDiskUsageData#getBuildsNumber()
will be decreased. If at the same time removedArtifacts is 0 (no own artifacts removed) -CompositeDiskUsageData#getCleanedBuildsNumber()
will be decreased as well. If allRemoved is false while noArtifactsLeft is true and removedArtifacts is positive (any own artifacts removed) -CompositeDiskUsageData#getCleanedBuildsNumber()
will be increased. If wasPinned is true - pinned sizes will be decreased. If allRemoved is true at the same time - the build will be removed from pinned builds list.- Specified by:
buildArtifactsCleaned
in interfaceDiskUsagePersister
noArtifactsLeft
- should be true if build is removed completely (the whole build artifacts directory is removed)allRemoved
- should be true if no artifacts left (internal artifacts don't matter)
-
buildArtifactsCleaned
public void buildArtifactsCleaned(@NotNull SBuildType buildType, long buildId, boolean wasPinned, boolean noArtifactsLeft, boolean allRemoved, long removedArtifacts, long removedInternalArtifacts, long removedLogs, @NotNull String storageId)
- Specified by:
buildArtifactsCleaned
in interfaceDiskUsagePersister
-
beforeBuildsDeletedFromHistory
public void beforeBuildsDeletedFromHistory(List<SFinishedBuild> builds)
Description copied from interface:DiskUsagePersister
This method should be called for builds deleted from history before their cleanup. Pinned builds will be marked as unpinned, builds will be removed from top builds list, total log size and artifacts size would be moved to 'non-builds data'.
- Specified by:
beforeBuildsDeletedFromHistory
in interfaceDiskUsagePersister
- Parameters:
builds
- Cleaned builds
-
junkDeleted
public void junkDeleted(@NotNull SBuildType buildType, long totalDeleted, @NotNull String storageId)
Description copied from interface:DiskUsagePersister
Decreases 'non-builds data' for buildType
- Specified by:
junkDeleted
in interfaceDiskUsagePersister
- Parameters:
buildType
- Build type where junk was cleanedtotalDeleted
- Size of cleaned junk
-
recalculateBuild
public void recalculateBuild(@NotNull SBuild build)
Description copied from interface:DiskUsagePersister
Recalculates a single build
- Specified by:
recalculateBuild
in interfaceDiskUsagePersister
-
getVersion
public long getVersion(@Nullable SBuildType buildType)
Description copied from interface:DiskUsagePersister
Disk usage data is stored versioned. 0 means data was not collected yet.
- Specified by:
getVersion
in interfaceDiskUsagePersister
- Specified by:
getVersion
in interfaceDiskUsageViewer
- Returns:
- version
-
getLastUpdateDate
public long getLastUpdateDate(@Nullable SBuildType buildType)
- Specified by:
getLastUpdateDate
in interfaceDiskUsageViewer
-
getArtifactsDirectoryFreeSpace
public long getArtifactsDirectoryFreeSpace()
Description copied from interface:DiskUsageViewer
The return value is usable disk space
- Specified by:
getArtifactsDirectoryFreeSpace
in interfaceDiskUsageViewer
- Returns:
- free disk space in artifacts directory or
ArtifactStorageDiskUsageCalculator.UNLIMITED_SPACE
if the space is not limited
-
getLogsDirectoryFreeSpace
public long getLogsDirectoryFreeSpace()
Description copied from interface:DiskUsageViewer
The return value is usable disk space
- Specified by:
getLogsDirectoryFreeSpace
in interfaceDiskUsageViewer
- Returns:
- free disk space in logs directory or
ArtifactStorageDiskUsageCalculator.UNLIMITED_SPACE
if the space is not limited
-
getPinnedBuildsNumber
public long getPinnedBuildsNumber()
- Specified by:
getPinnedBuildsNumber
in interfaceDiskUsageViewer
- Returns:
- number of found pinned builds
-
getPinnedArtifactsSize
public long getPinnedArtifactsSize()
- Specified by:
getPinnedArtifactsSize
in interfaceDiskUsageViewer
- Returns:
- size of all artifacts in found pinned builds
-
getPinnedLogsSize
public long getPinnedLogsSize()
- Specified by:
getPinnedLogsSize
in interfaceDiskUsageViewer
- Returns:
- size of all logs in found pinned builds
-
getPinnedBuildsNumber
public long getPinnedBuildsNumber(@NotNull SBuildType buildType)
- Specified by:
getPinnedBuildsNumber
in interfaceDiskUsageViewer
- Returns:
- number of found pinned builds in specified BuildType
-
getPinnedBuildsSize
public long getPinnedBuildsSize(@NotNull SBuildType buildType)
- Specified by:
getPinnedBuildsSize
in interfaceDiskUsageViewer
- Returns:
- total size of artifacts and logs in found pinned builds of specified BuildType
-
getPinnedBuildsArtifactsSize
public long getPinnedBuildsArtifactsSize(@NotNull SBuildType buildType)
- Specified by:
getPinnedBuildsArtifactsSize
in interfaceDiskUsageViewer
- Returns:
- total size of artifacts in found pinned builds of specified BuildType
-
getPinnedBuildsLogsSize
public long getPinnedBuildsLogsSize(@NotNull SBuildType buildType)
- Specified by:
getPinnedBuildsLogsSize
in interfaceDiskUsageViewer
- Returns:
- total size of logs in found pinned builds of specified BuildType
-
getTotalArtifactsSize
public long getTotalArtifactsSize()
- Specified by:
getTotalArtifactsSize
in interfaceDiskUsageViewer
- Returns:
- size of all found artifacts
-
getTotalLogsSize
public long getTotalLogsSize()
- Specified by:
getTotalLogsSize
in interfaceDiskUsageViewer
- Returns:
- size of all found logs
-
getLastUpdateTime
@Nullable public Date getLastUpdateTime()
- Specified by:
getLastUpdateTime
in interfaceDiskUsageViewer
- Returns:
- last full scan date
-
setLastUpdateTime
public void setLastUpdateTime(@Nullable Date lastUpdateTime)
Description copied from interface:DiskUsagePersister
Sets the date of last full scan
- Specified by:
setLastUpdateTime
in interfaceDiskUsagePersister
-
getLastUpdateDuration
public long getLastUpdateDuration()
- Specified by:
getLastUpdateDuration
in interfaceDiskUsageViewer
- Returns:
- last full scan duration
-
setLastUpdateDuration
public void setLastUpdateDuration(long lastUpdateDurationMs)
Description copied from interface:DiskUsagePersister
Sets the duration of last full scan
- Specified by:
setLastUpdateDuration
in interfaceDiskUsagePersister
-
updateBuildPinned
public void updateBuildPinned(@NotNull SBuild build)
Description copied from interface:DiskUsagePersister
Save disk usage data over the pinned build
- Specified by:
updateBuildPinned
in interfaceDiskUsagePersister
-
updateBuildUnpinned
public void updateBuildUnpinned(@NotNull SBuild build)
Description copied from interface:DiskUsagePersister
Save disk usage data over the unpinned build
- Specified by:
updateBuildUnpinned
in interfaceDiskUsagePersister
-
recalculateProject
public void recalculateProject(@NotNull SProject project)
- Specified by:
recalculateProject
in interfaceDiskUsagePersister
-
tryParseLong
public static OptionalLong tryParseLong(@NotNull String s)
-
-