model

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package model holds the federation module's entity values: replications and their runs, paired peers and pairing nonces, the stream names and conflict stamps of the peer protocol, federated repository membership and full syncs, and the platform federation records (Access Federation targets, platform federations and topologies).

Role

federation module, core layer, entity values. The module's store ports take and return them, and the replication, peer, sync, federated repository, Access Federation and topology services of P11, P13 and P14 will build on them. The package imports the standard library, artifacts/api/repo (a repository's class and its federation members), platform/outbox (the clock a Stamp carries) and retention/api (the status a full-sync run reports), each another module's api or the platform, as decision 0044's dependency rules allow.

Inputs

  • For DirectionFor, a repository class; for ParseMemberURL and MembersOf, a federation member URL or a federated repository's configuration with this instance's base URL.
  • For the peer values, a time and a staleness threshold (DeriveStatus, Usable); for ParseStream, a stream name; for DeriveSyncStatus, a repository's settings, whether a full sync runs and its members' lag.

Outputs

  • Replication, ReplicationRun, ReplicationDirection with DirectionFor, and ReplicationStatus.
  • Peer with Has and DeriveStatus, PeerStatus, UseCase with KnownUseCase, PairingNonce with Usable, and PairingTokenTTL.
  • Stamp with After; StreamKind with RepositoryStream, AccessStream, DistributionStream and ParseStream, and the sentinel ErrInvalidStream.
  • FederationMember with ParseMemberURL, MembersOf and the sentinel ErrInvalidMemberURL; FederationSettings, FederationPriority, SyncStatus with DeriveSyncStatus, and FullSyncRun.
  • AccessFederationTarget with Streams, FederatedEntity and PatternFilter; PlatformFederation; Topology and TopologySite.

Invariants

  • Conflicts resolve last writer wins: the later clock time, and on a tie the greater origin instance id, so every member picks the same winner (decision 0021).
  • A pairing nonce completes at most one pairing, and only before it expires; pairing tokens last PairingTokenTTL, JFrog's default (decision 0021).
  • Use cases are JFrog's names where they mean the same thing and artifactweave's own otherwise; JFrog use cases with no counterpart are unknown, which the API answers with 404.
  • Stream names are part of the stored outbox, so their forms never change: repo:<key>, access and distribution:<tracker>:<peer>.

References

  • Decision 0021: docs/research/decisions/0021-peer-trust-and-sync-protocol.md (peers, pairing, streams and the conflict rule).
  • Decision 0022: docs/research/decisions/0022-federated-repositories.md (members, sync status and full syncs).
  • Decision 0025: docs/research/decisions/0025-platform-federation-and-topology.md (Access Federation targets, platform federations, topologies and peer statuses).
  • Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md ("Dependency rules").
  • Research 16: docs/research/16-enterprise-products.md. Research 15: docs/research/15-data-model.md, lines 689 and 690 (replications), lines 701 and 702 (peers and pairing nonces), lines 707 and 708 (members and full syncs), lines 719 to 721 (the platform federation tables) and line 762 (the peers table as built).
  • Target layout: docs/research/architecture-options/5-modular-monolith.md, lines 100 to 103 (a storage skeleton ahead of its phase), lines 331 to 346 (the federation 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, #p13-peer-trust-and-federated-repositories, #p14-platform-federation-and-topology 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 replication, peer, federation and platform values among the shared domain types (pull request 3). Moved here in P9d, where Stamp names the outbox's clock from its platform home. The behaviour that uses them arrives with P11 (replication), P13 (peer trust and federated repositories) and P14 (platform federation and topology).

Testing

  • model_test.go: TestUnitDirectionFor (locals push, remotes pull, virtuals do not replicate), TestUnitPeer (known and unknown use cases, Has, the four statuses and a never-seen peer, nonce expiry and single use), TestUnitStreams (stream names and their parse, and malformed names failing with ErrInvalidStream), TestUnitStamp (the conflict rule), TestUnitFederation (member URLs with and without a prefix, malformed ones failing with ErrInvalidMemberURL, MembersOf skipping this instance, and the four sync statuses) and TestUnitPlatformFederation (PatternFilter and Streams).

The metadata store's Replications, Peers, PairingNonces, FederationMembers, FullSyncs, AccessTargets, PlatformFederations and Topologies contract subtests store and read these values on its in-memory, SQLite and PostgreSQL stores.

Index

Constants

View Source
const AccessStream = string(StreamAccess)

AccessStream is the Access Federation stream.

View Source
const PairingTokenTTL = 300 * time.Second

PairingTokenTTL is how long a pairing token can be redeemed: 300 seconds, the JFrog pairing-token default (decision 0021).

Variables

View Source
var ErrInvalidMemberURL = errors.New("invalid federation member URL")

ErrInvalidMemberURL reports a federation member URL that does not name a repository on an instance.

View Source
var ErrInvalidStream = errors.New("invalid stream name")

ErrInvalidStream reports a stream name with an unknown form.

Functions

func DistributionStream

func DistributionStream(trackerID int64, peerInstanceID string) string

DistributionStream names one distribution job's stream.

func KnownUseCase

func KnownUseCase(u UseCase) bool

KnownUseCase reports whether u can be paired; JFrog use cases with no counterpart (mission-control, bridge, artifactory-cold) answer 404.

func ParseMemberURL

func ParseMemberURL(raw string) (baseURL, repoKey string, err error)

ParseMemberURL splits "<base URL>/artifactory/<repoKey>" into the instance base URL and the repository key.

func RepositoryStream

func RepositoryStream(repoKey string) string

RepositoryStream names a federated repository's stream.

Types

type AccessFederationTarget

type AccessFederationTarget struct {
	Name              string
	PeerInstanceID    string
	Active            bool
	Entities          []FederatedEntity
	PermissionFilters PatternFilter
	GroupFilters      PatternFilter
	Created           time.Time
}

AccessFederationTarget is a peer that receives this instance's identity changes on the access stream (decision 0025).

func (AccessFederationTarget) Streams

Streams reports whether the target receives entity e.

type FederatedEntity

type FederatedEntity string

FederatedEntity is an entity type Access Federation streams.

const (
	EntityUsers       FederatedEntity = "USERS"
	EntityGroups      FederatedEntity = "GROUPS"
	EntityPermissions FederatedEntity = "PERMISSIONS"
	EntityTokens      FederatedEntity = "TOKENS"
)

Federated entity types.

type FederationMember

type FederationMember struct {
	RepoKey        string
	PeerInstanceID string
	BaseURL        string
	RemoteRepoKey  string
	Enabled        bool
}

FederationMember is one member of a federated repository, normalised from the repository's members list. Members are peers paired for federation (decision 0022); RemoteRepoKey is the repository's key on that peer.

func MembersOf

func MembersOf(cfg *repo.Config, selfBaseURL string) ([]FederationMember, error)

MembersOf lists a federated repository's members from its configuration, skipping the entry for selfBaseURL (a member may list itself). The peer instance id is resolved later against the peer table.

type FederationPriority

type FederationPriority string

FederationPriority orders the dispatch of a repository's outbox batches.

const (
	PriorityHigh     FederationPriority = "HIGH"
	PriorityStandard FederationPriority = "STANDARD"
)

Federation priorities.

type FederationSettings

type FederationSettings struct {
	Priority             FederationPriority `json:"priority,omitempty"`
	PropagateCreatedTime bool               `json:"propagate_created_time,omitempty"`
	Disabled             bool               `json:"disabled,omitempty"`
}

FederationSettings are artifactweave's per-repository federation switches. They have no field in JFrog's repository JSON, so they are stored as their own document beside the repository configuration.

type FullSyncRun

type FullSyncRun struct {
	ID             int64
	RepoKey        string
	PeerInstanceID string
	Forced         bool
	SnapshotSeq    int64
	Started        time.Time
	Finished       time.Time
	Status         retentionapi.RunStatus
	ResultPaths    []string
}

FullSyncRun is one snapshot resynchronisation of a repository with a peer.

type PairingNonce

type PairingNonce struct {
	NonceHash  []byte
	UseCase    UseCase
	ExpiresAt  time.Time
	RedeemedAt time.Time
}

PairingNonce backs a single-use pairing token. Only the nonce hash is stored until the token is redeemed.

func (PairingNonce) Usable

func (n PairingNonce) Usable(now time.Time) bool

Usable reports whether the nonce can still complete a pairing.

type PatternFilter

type PatternFilter struct {
	Include []string `json:"include_patterns,omitempty"`
	Exclude []string `json:"exclude_patterns,omitempty"`
}

PatternFilter includes and excludes names by glob; an empty include list includes everything.

func (PatternFilter) Matches

func (f PatternFilter) Matches(name string) bool

Matches reports whether name passes the filter.

type Peer

type Peer struct {
	InstanceID      string
	BaseURL         string
	PublicKey       ed25519.PublicKey
	ProtocolVersion int
	UseCases        []UseCase
	Status          PeerStatus
	LastSeen        time.Time
	DisplayName     string
	CityName        string
	CountryCode     string
	EdgeRole        bool
}

Peer is another instance this one is paired with: a federation member, a distribution edge, an Access Federation target, a follower JPD or a topology site. Location fields are set by the administrator.

func (Peer) DeriveStatus

func (p Peer) DeriveStatus(
	now time.Time,
	stale time.Duration,
	rejected bool,
	failingUseCases int,
) PeerStatus

DeriveStatus computes the JPD status: UNAUTHORIZED when the last signed exchange was rejected, OFFLINE when nothing succeeded within the stale window, PARTIAL when some use cases are failing, ONLINE otherwise.

func (Peer) Has

func (p Peer) Has(u UseCase) bool

Has reports whether the peer is paired for u.

type PeerStatus

type PeerStatus string

PeerStatus is a peer's health as the JPD APIs report it (decision 0025).

const (
	PeerOnline       PeerStatus = "ONLINE"
	PeerOffline      PeerStatus = "OFFLINE"
	PeerPartial      PeerStatus = "PARTIAL"
	PeerUnauthorized PeerStatus = "UNAUTHORIZED"
)

Peer statuses.

type PlatformFederation

type PlatformFederation struct {
	ID               string
	Name             string
	Description      string
	ConnectionGroups map[string][]string
	Entities         []string
}

PlatformFederation is a named set of connection groups of follower JPDs. The entity types are Curation's and carry no data in artifactweave; they are stored so the federation round-trips.

type Replication

type Replication struct {
	RepoKey              string
	Key                  string
	URL                  string
	Username             string
	Password             string `json:"-"`
	Enabled              bool
	CronExp              string
	EventReplication     bool
	SyncDeletes          bool
	SyncProperties       bool
	SyncStatistics       bool
	IncludePathPrefix    string
	ExcludePathPrefix    string
	Proxy                string
	DisableProxy         bool
	CheckBinaryExistence bool
	SocketTimeout        time.Duration
}

Replication is one replication target of a repository. Key is the server-assigned replicationKey; Password is sealed.

type ReplicationDirection

type ReplicationDirection string

ReplicationDirection is derived from the repository class.

const (
	ReplicationPush ReplicationDirection = "push"
	ReplicationPull ReplicationDirection = "pull"
)

Replication directions.

func DirectionFor

func DirectionFor(c repo.Class) (ReplicationDirection, bool)

DirectionFor returns how a repository of class c replicates: locals push, remotes pull; other classes do not replicate.

type ReplicationRun

type ReplicationRun struct {
	ReplicationKey string
	Started        time.Time
	Completed      time.Time
	Status         ReplicationStatus
}

ReplicationRun records one execution of a replication, for the status endpoint. A zero Completed means the run is still going.

type ReplicationStatus

type ReplicationStatus string

ReplicationStatus is the reported state of a repository's replication.

const (
	ReplicationUnknown        ReplicationStatus = "unknown"
	ReplicationNeverRun       ReplicationStatus = "never_run"
	ReplicationIncomplete     ReplicationStatus = "incomplete"
	ReplicationError          ReplicationStatus = "error"
	ReplicationWarn           ReplicationStatus = "warn"
	ReplicationOK             ReplicationStatus = "ok"
	ReplicationInconsistent   ReplicationStatus = "inconsistent"
	ReplicationPartialFailure ReplicationStatus = "partial_failure"
)

Replication statuses.

type Stamp

type Stamp struct {
	Time   outbox.HLC
	Origin string
}

Stamp is an event's position for conflict resolution.

func (Stamp) After

func (s Stamp) After(o Stamp) bool

After reports whether s wins over o under last-writer-wins: later clock first, origin instance id as the tie-break so every member picks the same winner.

type StreamKind

type StreamKind string

StreamKind is the family of an outbox stream.

const (
	StreamRepository   StreamKind = "repo"
	StreamAccess       StreamKind = "access"
	StreamDistribution StreamKind = "distribution"
)

Stream kinds (decision 0021).

func ParseStream

func ParseStream(stream string) (StreamKind, string, error)

ParseStream splits a stream name into its kind and remainder.

type SyncStatus

type SyncStatus string

SyncStatus is a federated repository's reported state.

const (
	SyncSyncing         SyncStatus = "SYNCING"
	SyncFullSyncRunning SyncStatus = "FULL_SYNC_RUNNING"
	SyncDisabled        SyncStatus = "DISABLED"
	SyncOutOfSync       SyncStatus = "OUT_OF_SYNC"
)

Sync statuses.

func DeriveSyncStatus

func DeriveSyncStatus(
	s FederationSettings,
	fullSyncRunning bool,
	lags []time.Duration,
	threshold time.Duration,
) SyncStatus

DeriveSyncStatus applies decision 0022: disabled wins, then a running snapshot, then out of sync when any member lags beyond the threshold.

type Topology

type Topology struct {
	Key         string
	Name        string
	Description string
	Sites       []TopologySite
	Created     time.Time
	Modified    time.Time
}

Topology is a named arrangement of sites.

type TopologySite

type TopologySite struct {
	PeerInstanceID string
	SiteName       string
}

TopologySite is one site of a topology, backed by a peer.

type UseCase

type UseCase string

UseCase is a reason two instances are paired.

const (
	UseFederation         UseCase = "federation"
	UseDistribution       UseCase = "distribution"
	UseAccessFederation   UseCase = "access-federation"
	UsePlatformFederation UseCase = "platform-federation"
)

Use cases: JFrog's name where it means the same thing, artifactweave's own otherwise (decision 0021).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL