Documentation
¶
Overview ¶
Package model holds the retention module's entity values: package and build cleanup policies and their runs, and the cold-storage tier's archive policies, executions and restore requests.
Role ¶
retention module, core layer, entity values. The module's store ports take and return them, and the cleanup, archive and restore services of P11 and P16 will build on them. A run's status is the retention api's RunStatus, which federation's full-sync runs report too. The package imports the standard library and retention/api.
Inputs ¶
- For RestoreRequest.Validate, a restore request as the cold-storage API receives it.
Outputs ¶
- CleanupPolicy with CleanupCriteria and CleanupItemType (package, build and release bundle), and CleanupRun.
- ArchivePolicy with ArchiveFamily (retention v1 and smart archiving v2), ArchiveExecution with ExecutionKind, ExecutionState and Progress, and RestoreRequest with RestoreType and Validate.
- MaxRestoreItems and the sentinel ErrInvalidRestore.
Invariants ¶
- A cleanup policy's criteria keep the legacy month fields, so a policy written by an old client reads back as it was written.
- An archive policy's criteria are kept in its family's wire shape, because the two families select differently (decision 0024).
- One restore takes at most MaxRestoreItems items, as JFrog's does.
References ¶
- Decision 0010: docs/research/decisions/0010-retention-trash-and-gc.md (cleanup policies).
- Decision 0024: docs/research/decisions/0024-cold-storage-tier.md (archive policies, executions and restores).
- Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md ("Persistence").
- Research 07: docs/research/07-webhooks-retention-projects.md. Research 16: docs/research/16-enterprise-products.md (cold storage). Research 15: docs/research/15-data-model.md, lines 687 and 688 (the cleanup tables) and lines 715 and 716 (the archive tables).
- Target layout: docs/research/architecture-options/5-modular-monolith.md, lines 100 to 103 (a storage skeleton ahead of its phase), lines 325 to 329 (the retention module), lines 577 and 578 (each module owns its store ports) and line 1058 (the shared types split into each module's core/model).
- Plan: docs/implementation/plan.md#p2-stores, task 0, #p11-projects-webhooks-retention-replication, #p16-cold-storage-archive-and-retention and #p9d-modular-monolith-migration, epic STO (https://github.com/weaveplatform/artifactweave/issues/939).
- https://github.com/weaveplatform/artifactweave/issues/1053
Status ¶
Implemented P2: the cleanup and archive values among the shared domain types (pull request 3). Moved here in P9d. The behaviour that uses them arrives with P11 (cleanup policies) and P16 (the cold-storage tier).
Testing ¶
- model_test.go: TestUnitRunStatusTerminal (which run statuses are final) and TestUnitArchive (Progress, including an execution with no total; restore requests that validate, and an unknown type, nothing to restore, too many items and no destination failing with ErrInvalidRestore).
The metadata store's CleanupPolicies, CleanupRuns, ArchivePolicies and ArchiveExecutions contract subtests store and read these values on its in-memory, SQLite and PostgreSQL stores.
Index ¶
Constants ¶
const MaxRestoreItems = 30000
MaxRestoreItems caps one restore job, as JFrog does.
Variables ¶
var ErrInvalidRestore = errors.New("invalid restore request")
ErrInvalidRestore reports a restore request that cannot be executed.
Functions ¶
This section is empty.
Types ¶
type ArchiveExecution ¶
type ArchiveExecution struct {
ID int64
PolicyKey string
Kind ExecutionKind
State ExecutionState
Started time.Time
Finished time.Time
Total int64
Completed int64
Failed int64
TotalBytes int64
SuccessBytes int64
FailureBytes int64
TriggeredBy string
Destination []byte
}
ArchiveExecution is one run of an archive policy, a restore job or a purge.
func (ArchiveExecution) Progress ¶
func (e ArchiveExecution) Progress() int
Progress is the completed share in percent, as progressPercentage reports.
type ArchiveFamily ¶
type ArchiveFamily string
ArchiveFamily is which of JFrog's two archive policy APIs a policy belongs to (decision 0024): cold-storage retention v1 or smart archiving v2.
const ( ArchiveRetentionV1 ArchiveFamily = "retention_v1" ArchiveSmartV2 ArchiveFamily = "smart_v2" )
Archive families.
type ArchivePolicy ¶
type ArchivePolicy struct {
Key string
Family ArchiveFamily
Description string
Enabled bool
CronExp string
ProjectKey string
DurationMinutes int
ExpirationMonths int
SkipTrashcan bool
Criteria []byte
Created time.Time
Updated time.Time
}
ArchivePolicy moves selected items to the cold blob store. Criteria is the family's selection document, kept in that family's wire shape because the two families select differently.
type CleanupCriteria ¶
type CleanupCriteria struct {
PackageTypes []string `json:"package_types,omitempty"`
Repos []string `json:"repos,omitempty"`
ExcludedRepos []string `json:"excluded_repos,omitempty"`
IncludedPackages []string `json:"included_packages,omitempty"`
ExcludedPackages []string `json:"excluded_packages,omitempty"`
IncludeAllProjects bool `json:"include_all_projects,omitempty"`
IncludedProjects []string `json:"included_projects,omitempty"`
CreatedBeforeInDays int `json:"created_before_in_days,omitempty"`
CreatedBeforeInMonths int `json:"created_before_in_months,omitempty"`
LastDownloadedBeforeInDays int `json:"last_downloaded_before_in_days,omitempty"`
LastDownloadedBeforeInMonths int `json:"last_downloaded_before_in_months,omitempty"`
KeepLastNVersions int `json:"keep_last_n_versions,omitempty"`
IncludedProperties map[string][]string `json:"included_properties,omitempty"`
ExcludedProperties map[string][]string `json:"excluded_properties,omitempty"`
IncludedPackageVersions []string `json:"included_package_versions,omitempty"`
ExcludedPackageVersions []string `json:"excluded_package_versions,omitempty"`
}
CleanupCriteria select what a package cleanup policy removes. Stored as the policy's document; the legacy month fields are kept so a policy written by an old client round-trips.
type CleanupItemType ¶
type CleanupItemType string
CleanupItemType is what a cleanup policy deletes.
const ( CleanupPackage CleanupItemType = "package" CleanupBuild CleanupItemType = "build" CleanupReleaseBundle CleanupItemType = "releaseBundle" )
Cleanup item types.
type CleanupPolicy ¶
type CleanupPolicy struct {
Key string
Description string
CronExp string
ProjectKey string
ItemType CleanupItemType
DurationMinutes int
Enabled bool
SkipTrashcan bool
Criteria CleanupCriteria
Created time.Time
CreatedBy string
Updated time.Time
UpdatedBy string
}
CleanupPolicy is a scheduled retention rule (decision 0010).
type CleanupRun ¶
type CleanupRun struct {
ID int64
PolicyKey string
TriggerID int64
ItemType CleanupItemType
Status api.RunStatus
DryRun bool
Manual bool
TriggeredBy string
Started time.Time
Ended time.Time
TotalItems int64
CleanedItems int64
CleanedSize int64
Report []byte
}
CleanupRun is one execution of a cleanup policy.
type ExecutionKind ¶
type ExecutionKind string
ExecutionKind is what an archive execution does.
const ( ExecutionArchive ExecutionKind = "archive" ExecutionRestore ExecutionKind = "restore" ExecutionPurge ExecutionKind = "purge" )
Execution kinds.
type ExecutionState ¶
type ExecutionState string
ExecutionState is the state of an archive, restore or purge execution.
const ( ExecutionPending ExecutionState = "PENDING" ExecutionInProgress ExecutionState = "IN_PROGRESS" ExecutionInProgressWithErrors ExecutionState = "IN_PROGRESS_WITH_ERRORS" ExecutionComplete ExecutionState = "COMPLETE" ExecutionCompleteWithErrors ExecutionState = "COMPLETE_WITH_ERRORS" ExecutionFailed ExecutionState = "FAILED" )
Execution states as the cold-storage API reports them.
type RestoreRequest ¶
type RestoreRequest struct {
Type RestoreType
Items []string
ToOriginal bool
FallbackPath string
CentralPath string
NewPath string
AddNamespace bool
ManifestPaths []string
}
RestoreRequest asks for archived content back. Items are archived paths or package references; when ToOriginal is false or the original path is taken, the fallback, central or new destination applies.
func (RestoreRequest) Validate ¶
func (r RestoreRequest) Validate() error
Validate checks the request is executable: a known type, at least one and at most MaxRestoreItems items, and somewhere to put them.
type RestoreType ¶
type RestoreType string
RestoreType is what a restore request names.
const ( RestorePackage RestoreType = "PACKAGE_RESTORE" RestoreArtifact RestoreType = "ARTIFACT_RESTORE" )
Restore types.