db

package
v1.6.1-0...-a0f72b6 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoVersionsSatisfiedPassedConstraints string = "no versions satisfy passed constraints"
	NoVersionsAvailable                  string = "no versions available"
	NoResourceCheckFinished              string = "checking for latest available versions"
	PinnedVersionUnavailable             string = "pinned version %s is not available"
)
View Source
const (
	WorkerStateRunning  = WorkerState("running")
	WorkerStateStalled  = WorkerState("stalled")
	WorkerStateLanding  = WorkerState("landing")
	WorkerStateLanded   = WorkerState("landed")
	WorkerStateRetiring = WorkerState("retiring")
)
View Source
const CheckBuildName = "check"
View Source
const DefaultBuildBeingWatchedMarkDuration = 2 * time.Hour
View Source
const MissingBuildInput string = "input is not included in resolved candidates"

Variables

View Source
var (
	ErrTooManyBuilds           = errors.New("too many builds")
	ErrTooManyResourceVersions = errors.New("too many resoruce versions")
	ErrPinnedThroughConfig     = errors.New("resource is pinned through config")
)
View Source
var (
	ErrVolumeCannotBeDestroyedWithChildrenPresent = errors.New("volume cannot be destroyed as children are present")
	ErrVolumeStateTransitionFailed                = errors.New("could not transition volume state")
	ErrVolumeMissing                              = errors.New("volume no longer in db")
	ErrInvalidResourceCache                       = errors.New("invalid resource cache")
)
View Source
var (
	ErrWorkerNotPresent         = errors.New("worker not present in db")
	ErrTooManyActiveTasks       = errors.New("worker has too many active tasks")
	ErrCannotPruneRunningWorker = errors.New("worker not stalled for pruning")
)
View Source
var CheckDeleteBatchSize = 500
View Source
var ErrAdoptRerunBuildHasNoInputs = errors.New("inputs not ready for build to rerun")
View Source
var ErrBuildArtifactNotFound = errors.New("build artifact not found")
View Source
var ErrBuildDisappeared = errors.New("build disappeared from db")
View Source
var ErrBuildEventStreamClosed = errors.New("build event stream closed")
View Source
var ErrBuildHasNoPipeline = errors.New("build has no pipeline")
View Source
var ErrConfigComparisonFailed = errors.New("comparison with existing config failed during save")
View Source
var ErrContainerDisappeared = errors.New("container disappeared from db")
View Source
var ErrEndOfBuildEventStream = errors.New("end of build event stream")
View Source
var ErrResourceCacheAlreadyExists = errors.New("resource-cache-already-exists")
View Source
var ErrResourceCacheDisappeared = errors.New("resource-cache-disappeared")
View Source
var ErrResourceConfigAlreadyExists = errors.New("resource config already exists")
View Source
var ErrResourceConfigDisappeared = errors.New("resource config disappeared")
View Source
var ErrResourceConfigHasNoType = errors.New("resource config has no type")
View Source
var ErrResourceConfigParentDisappeared = errors.New("resource config parent disappeared")
View Source
var ErrSetByNewerBuild = errors.New("pipeline set by a newer build")
View Source
var ErrWorkerBaseResourceTypeDisappeared = errors.New("worker base resource type disappeared")

Functions

func CacheWarmUp

func CacheWarmUp(runner sq.Runner) error

func CleanupBaseResourceTypesCache

func CleanupBaseResourceTypesCache()

CleanupBaseResourceTypesCache should only be used in unit tests' BeforeEach.

func Close

func Close(c io.Closer)

Close ignores errors, and should used with defer. makes errcheck happy that those errs are captured

func InitConnectionTracker

func InitConnectionTracker(on bool)

func MarkBuildAsBeingWatched

func MarkBuildAsBeingWatched(db Conn, buildEventChannel string) error

MarkBuildAsBeingWatched marks a build as BeingWatched by sending a db notification to channel beingWatchedNotifyChannelName with payload of the build's event channel name. This is because a build may be watched from any ATCs, while the build may be running in a separate ATC.

func NewArtifactLifecycle

func NewArtifactLifecycle(conn Conn) *artifactLifecycle

func NewBeingWatchedBuildEventChannelMap

func NewBeingWatchedBuildEventChannelMap() *beingWatchedBuildEventChannelMap

NewBeingWatchedBuildEventChannelMap returns a singleton instance of beingWatchedBuildEventChannelMap.

func NewClock

func NewClock() realClock

func NewIntPtr

func NewIntPtr(i int) *int

func NewNotificationsBus

func NewNotificationsBus(listener Listener, executor Executor) *notificationsBus

func Rollback

func Rollback(tx Tx)

Rollback ignores errors, and should be used with defer. makes errcheck happy that those errs are captured

func SetNotificationBusQueueSize

func SetNotificationBusQueueSize(size int) error

func SetupConnectionRetryingDriver

func SetupConnectionRetryingDriver(
	delegateDriverName string,
	sqlDataSource string,
	newDriverName string,
)

Types

type AccessToken

type AccessToken struct {
	Token  string
	Claims Claims
}

type AccessTokenFactory

type AccessTokenFactory interface {
	CreateAccessToken(token string, claims Claims) error
	GetAccessToken(token string) (AccessToken, bool, error)
}

func NewAccessTokenFactory

func NewAccessTokenFactory(conn Conn) AccessTokenFactory

type AccessTokenLifecycle

type AccessTokenLifecycle interface {
	RemoveExpiredAccessTokens(leeway time.Duration) (int, error)
}

func NewAccessTokenLifecycle

func NewAccessTokenLifecycle(conn Conn) AccessTokenLifecycle

type AlgorithmInput

type AlgorithmInput struct {
	AlgorithmVersion
	FirstOccurrence bool
}

type AlgorithmOutput

type AlgorithmOutput struct {
	AlgorithmVersion
	InputName string
}

type AlgorithmVersion

type AlgorithmVersion struct {
	ResourceID int
	Version    ResourceVersion
}

type BaseResourceType

type BaseResourceType struct {
	Name string // The name of the type, e.g. 'git'.
}

BaseResourceType represents a resource type provided by workers.

It is created via worker registration. All creates are upserts.

It is removed by gc.BaseResourceTypeCollector, once there are no references to it from worker_base_resource_types.

func (BaseResourceType) Find

func (brt BaseResourceType) Find(runner sq.Runner) (*UsedBaseResourceType, bool, error)

func (BaseResourceType) FindOrCreate

func (brt BaseResourceType) FindOrCreate(tx Tx, unique bool) (*UsedBaseResourceType, error)

FindOrCreate looks for an existing BaseResourceType and creates it if it doesn't exist. It returns a UsedBaseResourceType.

type BaseResourceTypeNotFoundError

type BaseResourceTypeNotFoundError struct {
	Name string
}

func (BaseResourceTypeNotFoundError) Error

type Build

type Build interface {
	PipelineRef

	ID() int
	Name() string

	RunStateID() string

	TeamID() int
	TeamName() string

	Job() (Job, bool, error)

	// AllAssociatedTeamNames is only meaningful for check build. For a global
	// resource's check build, it may associate to resources across multiple
	// teams.
	AllAssociatedTeamNames() []string

	JobID() int
	JobName() string

	ResourceID() int
	ResourceName() string

	ResourceTypeID() int

	Schema() string
	PrivatePlan() atc.Plan
	PublicPlan() *json.RawMessage
	HasPlan() bool
	Comment() string
	Status() BuildStatus
	CreateTime() time.Time
	StartTime() time.Time
	EndTime() time.Time
	ReapTime() time.Time
	IsManuallyTriggered() bool
	IsScheduled() bool
	IsRunning() bool
	IsCompleted() bool
	InputsReady() bool
	RerunOf() int
	RerunOfName() string
	RerunNumber() int
	CreatedBy() *string

	LagerData() lager.Data
	TracingAttrs() tracing.Attrs

	SyslogTag(event.OriginID) string

	Reload() (bool, error)

	ResourcesChecked() (bool, error)

	AcquireTrackingLock(logger lager.Logger, interval time.Duration) (lock.Lock, bool, error)

	Interceptible() (bool, error)
	Preparation() (BuildPreparation, bool, error)

	Start(atc.Plan) (bool, error)
	Finish(BuildStatus) error

	Variables(lager.Logger, creds.Secrets, creds.VarSourcePool) (vars.Variables, error)

	SetComment(string) error
	SetInterceptible(bool) error

	Events(uint) (EventSource, error)
	SaveEvent(event atc.Event) error

	Artifacts() ([]WorkerArtifact, error)
	Artifact(artifactID int) (WorkerArtifact, error)

	SaveOutput(string, ResourceCache, atc.Source, atc.Version, ResourceConfigMetadataFields, string, string) error
	AdoptInputsAndPipes() ([]BuildInput, bool, error)
	AdoptRerunInputsAndPipes() ([]BuildInput, bool, error)

	Resources() ([]BuildInput, []BuildOutput, error)
	SaveImageResourceVersion(ResourceCache) error

	Delete() (bool, error)
	MarkAsAborted() error
	IsAborted() bool
	AbortNotifier() (Notifier, error)

	IsDrained() bool
	SetDrained(bool) error

	SpanContext() propagation.TextMapCarrier

	SavePipeline(
		pipelineRef atc.PipelineRef,
		teamId int,
		config atc.Config,
		from ConfigVersion,
		initiallyPaused bool,
	) (Pipeline, bool, error)

	ResourceCacheUser() ResourceCacheUser
	ContainerOwner(atc.PlanID) ContainerOwner

	OnCheckBuildStart() error
}

type BuildBeingWatchedMarker

type BuildBeingWatchedMarker struct {
	// contains filtered or unexported fields
}

BuildBeingWatchedMarker listens to channel beingWatchedNotifyChannelName and mark builds as BeingWatched accordingly in a singleton map. And it periodically cleans up the map.

func NewBuildBeingWatchedMarker

func NewBuildBeingWatchedMarker(logger lager.Logger, conn Conn, dataRetainDuration time.Duration, clock clock.Clock) (*BuildBeingWatchedMarker, error)

func (*BuildBeingWatchedMarker) Drain

func (bt *BuildBeingWatchedMarker) Drain(ctx context.Context)

func (*BuildBeingWatchedMarker) Run

Run is periodically invoked to clean the internal map. We have no way to know if a build is no longer watched by any client, so cleanup strategy is, after a build is added to the map, we keep it in the map for 2 hours. After 2 hours, we will query its status. If it's completed, then we delete it from the map. If we cannot find the build, mostly like that's a check build, as a check build should never last 2 hours, so we just delete it from the map.

type BuildCursor

type BuildCursor struct {
	ID      int
	RerunOf sql.NullInt64
}

func (BuildCursor) NewerBuilds

func (cursor BuildCursor) NewerBuilds(idCol string) sq.Sqlizer

func (BuildCursor) OlderBuilds

func (cursor BuildCursor) OlderBuilds(idCol string) sq.Sqlizer

type BuildFactory

type BuildFactory interface {
	BuildForAPI(int) (BuildForAPI, bool, error)
	VisibleBuilds([]string, Page) ([]BuildForAPI, Pagination, error)
	AllBuilds(Page) ([]BuildForAPI, Pagination, error)
	PublicBuilds(Page) ([]BuildForAPI, Pagination, error)

	Build(int) (Build, bool, error)
	GetAllStartedBuilds() ([]Build, error)
	GetDrainableBuilds() ([]Build, error)

	// TODO: move to BuildLifecycle, new interface (see WorkerLifecycle)
	MarkNonInterceptibleBuilds() error
}

func NewBuildFactory

func NewBuildFactory(conn Conn, lockFactory lock.LockFactory, oneOffGracePeriod time.Duration, failedGracePeriod time.Duration) BuildFactory

type BuildForAPI

type BuildForAPI interface {
	PipelineRef

	ID() int
	Name() string

	TeamID() int
	TeamName() string

	JobID() int
	JobName() string

	Job() (Job, bool, error)

	// AllAssociatedTeamNames is only meaningful for check build. For a global
	// resource's check build, it may associate to resources across multiple
	// teams.
	AllAssociatedTeamNames() []string

	ResourceID() int
	ResourceName() string

	LagerData() lager.Data
	Schema() string
	PublicPlan() *json.RawMessage
	HasPlan() bool

	Comment() string
	StartTime() time.Time
	EndTime() time.Time
	ReapTime() time.Time
	Status() BuildStatus
	RerunOf() int
	RerunOfName() string
	RerunNumber() int
	CreatedBy() *string

	IsDrained() bool
	IsRunning() bool

	Artifacts() ([]WorkerArtifact, error)
	Events(uint) (EventSource, error)
	Resources() ([]BuildInput, []BuildOutput, error)
	Preparation() (BuildPreparation, bool, error)

	MarkAsAborted() error
	SetComment(string) error
}

BuildForAPI is a smaller interface of db.Build that should only be used within API packages.

type BuildInput

type BuildInput struct {
	Name       string
	Version    atc.Version
	ResourceID int

	FirstOccurrence bool
	ResolveError    string

	Context SpanContext
}

func (BuildInput) SpanContext

func (bi BuildInput) SpanContext() propagation.TextMapCarrier

type BuildOutput

type BuildOutput struct {
	Name    string
	Version atc.Version
}

type BuildPreparation

type BuildPreparation struct {
	BuildID             int
	PausedPipeline      BuildPreparationStatus
	PausedJob           BuildPreparationStatus
	MaxRunningBuilds    BuildPreparationStatus
	Inputs              map[string]BuildPreparationStatus
	InputsSatisfied     BuildPreparationStatus
	MissingInputReasons MissingInputReasons
}

type BuildPreparationStatus

type BuildPreparationStatus string
const (
	BuildPreparationStatusBlocking    BuildPreparationStatus = "blocking"
	BuildPreparationStatusNotBlocking BuildPreparationStatus = "not_blocking"
)

type BuildStatus

type BuildStatus string
const (
	BuildStatusPending   BuildStatus = "pending"
	BuildStatusStarted   BuildStatus = "started"
	BuildStatusAborted   BuildStatus = "aborted"
	BuildStatusSucceeded BuildStatus = "succeeded"
	BuildStatusFailed    BuildStatus = "failed"
	BuildStatusErrored   BuildStatus = "errored"
)

func (BuildStatus) String

func (status BuildStatus) String() string

type CausalityDirection

type CausalityDirection string
const (
	CausalityDownstream CausalityDirection = "downstream"
	CausalityUpstream   CausalityDirection = "upstream"
)

type Cause

type Cause struct {
	ResourceVersionID int `json:"resource_version_id"`
	BuildID           int `json:"build_id"`
}

type CheckFactory

type CheckFactory interface {
	TryCreateCheck(context.Context, Checkable, ResourceTypes, atc.Version, bool, bool, bool) (Build, bool, error)
	Resources() ([]Resource, error)
	ResourceTypesByPipeline() (map[int]ResourceTypes, error)
	Drain()
}

func NewCheckFactory

func NewCheckFactory(
	conn Conn,
	lockFactory lock.LockFactory,
	secrets creds.Secrets,
	varSourcePool creds.VarSourcePool,
	checkBuildChan chan<- Build,
	sequenceGenerator util.SequenceGenerator,
) CheckFactory

type CheckLifecycle

type CheckLifecycle interface {
	DeleteCompletedChecks(logger lager.Logger) error
}

func NewCheckLifecycle

func NewCheckLifecycle(conn Conn) CheckLifecycle

type Checkable

type Checkable interface {
	PipelineRef

	Name() string
	TeamID() int
	ResourceConfigScopeID() int
	TeamName() string
	Type() string
	Source() atc.Source
	Tags() atc.Tags
	CheckEvery() *atc.CheckEvery
	CheckTimeout() string
	LastCheckEndTime() time.Time
	CurrentPinnedVersion() atc.Version

	HasWebhook() bool

	CheckPlan(planFactory atc.PlanFactory, imagePlanner atc.ImagePlanner, from atc.Version, interval atc.CheckEvery, sourceDefaults atc.Source, skipInterval bool, skipIntervalRecursively bool) atc.Plan
	CreateBuild(context.Context, bool, atc.Plan) (Build, bool, error)
	CreateInMemoryBuild(context.Context, atc.Plan, util.SequenceGenerator) (Build, error)
}

type Claims

type Claims struct {
	jwt.Claims
	FederatedClaims   `json:"federated_claims"`
	RawClaims         map[string]interface{} `json:"-"`
	Username          string                 `json:"name"`
	PreferredUsername string                 `json:"preferred_username"`
	Email             string                 `json:"email"`
}

func (Claims) MarshalJSON

func (c Claims) MarshalJSON() ([]byte, error)

func (*Claims) Scan

func (c *Claims) Scan(value interface{}) error

func (*Claims) UnmarshalJSON

func (c *Claims) UnmarshalJSON(data []byte) error

func (Claims) Value

func (c Claims) Value() (driver.Value, error)

type Clock

type Clock interface {
	Now() time.Time
	Until(time.Time) time.Duration
}

type Component

type Component interface {
	ID() int
	Name() string
	Interval() time.Duration
	LastRan() time.Time
	Paused() bool

	Reload() (bool, error)
	IntervalElapsed() bool
	UpdateLastRan() error
}

type ComponentFactory

type ComponentFactory interface {
	CreateOrUpdate(atc.Component) (Component, error)
	Find(string) (Component, bool, error)
}

func NewComponentFactory

func NewComponentFactory(conn Conn, numGoroutineThreshold int, rander ComponentRand, clock clock.Clock, goRoutineCounter GoroutineCounter) ComponentFactory

type ComponentRand

type ComponentRand interface {
	Int() int
}

type ConfigVersion

type ConfigVersion int

ConfigVersion is a sequence identifier used for compare-and-swap.

type Conn

type Conn interface {
	Bus() NotificationsBus
	EncryptionStrategy() encryption.Strategy

	Ping() error
	Driver() driver.Driver

	Begin() (Tx, error)
	Exec(string, ...interface{}) (sql.Result, error)
	Prepare(string) (*sql.Stmt, error)
	Query(string, ...interface{}) (*sql.Rows, error)
	QueryRow(string, ...interface{}) squirrel.RowScanner

	BeginTx(context.Context, *sql.TxOptions) (Tx, error)
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) squirrel.RowScanner

	SetMaxIdleConns(int)
	SetMaxOpenConns(int)
	Stats() sql.DBStats

	Close() error
	Name() string
}

func Log

func Log(logger lager.Logger, conn Conn) Conn

Log returns a wrapper of DB connection which contains a wraper of DB transactions so all queries could be logged by givin logger

func NewConn

func NewConn(name string, sqlDB *sql.DB, dsn string, oldKey, newKey *encryption.Key) Conn

func Open

func Open(logger lager.Logger, driver, dsn string, newKey, oldKey *encryption.Key, name string, lockFactory lock.LockFactory) (Conn, error)

type ConnectionSession

type ConnectionSession interface {
	Release()
}

type ConnectionTracker

type ConnectionTracker interface {
	Track() ConnectionSession
	Current() []string
}
var GlobalConnectionTracker ConnectionTracker

type Container

type Container interface {
	ID() int
	State() string
	Handle() string
	WorkerName() string
	Metadata() ContainerMetadata
}

type ContainerMetadata

type ContainerMetadata struct {
	Type ContainerType

	StepName string
	Attempt  string

	WorkingDirectory string
	User             string

	PipelineID int
	JobID      int
	BuildID    int

	PipelineName         string
	PipelineInstanceVars string
	JobName              string
	BuildName            string
}

func (ContainerMetadata) SQLMap

func (metadata ContainerMetadata) SQLMap() map[string]interface{}

func (*ContainerMetadata) ScanTargets

func (metadata *ContainerMetadata) ScanTargets() []interface{}

type ContainerOwner

type ContainerOwner interface {
	Find(conn Conn) (sq.Eq, bool, error)
	Create(tx Tx, workerName string) (map[string]interface{}, error)
}

ContainerOwner designates the data the container should reference that identifies its lifecycle. When the owner goes away, the container should be garbage collected.

func NewBuildStepContainerOwner

func NewBuildStepContainerOwner(
	buildID int,
	planID atc.PlanID,
	teamID int,
) ContainerOwner

NewBuildStepContainerOwner references a step within a build. When the build becomes non-interceptible or disappears, the container can be removed.

func NewFixedHandleContainerOwner

func NewFixedHandleContainerOwner(handle string) ContainerOwner

NewFixedHandleContainerOwner is used in testing to represent a container with a fixed handle, rather than using the randomly generated UUID as a handle.

func NewInMemoryCheckBuildContainerOwner

func NewInMemoryCheckBuildContainerOwner(
	buildID int,
	createTime time.Time,
	planID atc.PlanID,
	teamID int,
) ContainerOwner

NewInMemoryCheckBuildContainerOwner references a in-memory check build. To reduce burden to db, this will use in-memory build's pre-id. And to ensure pre-id is unique, in-memory's create time is also used.

func NewResourceConfigCheckSessionContainerOwner

func NewResourceConfigCheckSessionContainerOwner(
	resourceConfigID int,
	baseResourceTypeID int,
	expiries ContainerOwnerExpiries,
) ContainerOwner

NewResourceConfigCheckSessionContainerOwner references a resource config and worker base resource type, with an expiry. When the resource config or worker base resource type disappear, or the expiry is reached, the container can be removed.

type ContainerOwnerDisappearedError

type ContainerOwnerDisappearedError struct {
	// contains filtered or unexported fields
}

func (ContainerOwnerDisappearedError) Error

type ContainerOwnerExpiries

type ContainerOwnerExpiries struct {
	Min time.Duration
	Max time.Duration
}

type ContainerRepository

type ContainerRepository interface {
	FindOrphanedContainers() ([]CreatingContainer, []CreatedContainer, []DestroyingContainer, error)
	DestroyFailedContainers() (int, error)
	FindDestroyingContainers(workerName string) ([]string, error)
	RemoveDestroyingContainers(workerName string, currentHandles []string) (int, error)
	UpdateContainersMissingSince(workerName string, handles []string) error
	RemoveMissingContainers(time.Duration) (int, error)
	DestroyUnknownContainers(workerName string, reportedHandles []string) (int, error)
	DestroyDirtyInMemoryBuildContainers() (int, error)
}

func NewContainerRepository

func NewContainerRepository(conn Conn) ContainerRepository

type ContainerState

type ContainerState string

type ContainerType

type ContainerType string
const (
	ContainerTypeCheck ContainerType = "check"
	ContainerTypeGet   ContainerType = "get"
	ContainerTypePut   ContainerType = "put"
	ContainerTypeTask  ContainerType = "task"
	ContainerTypeRun   ContainerType = "run"
)

func ContainerTypeFromString

func ContainerTypeFromString(containerType string) (ContainerType, error)

type CreatedContainer

type CreatedContainer interface {
	Container

	Destroying() (DestroyingContainer, error)
	LastHijack() time.Time
	UpdateLastHijack() error
}

type CreatedVolume

type CreatedVolume interface {
	Handle() string
	Path() string
	Type() VolumeType
	TeamID() int
	WorkerArtifactID() int
	WorkerResourceCacheID() int
	CreateChildForContainer(CreatingContainer, string) (CreatingVolume, error)
	Destroying() (DestroyingVolume, error)
	WorkerName() string

	InitializeResourceCache(ResourceCache) (*UsedWorkerResourceCache, error)
	InitializeStreamedResourceCache(ResourceCache, int) (*UsedWorkerResourceCache, error)
	GetResourceCacheID() int
	InitializeArtifact(name string, buildID int) (WorkerArtifact, error)
	InitializeTaskCache(jobID int, stepName string, path string) error

	ContainerHandle() string
	ParentHandle() string
	ResourceType() (*VolumeResourceType, error)
	BaseResourceType() (*UsedWorkerBaseResourceType, error)
	TaskIdentifier() (int, atc.PipelineRef, string, string, error)
}

TODO-Later Consider separating CORE & Runtime concerns by breaking this abstraction up.

type CreatingContainer

type CreatingContainer interface {
	Container

	Created() (CreatedContainer, error)
	Failed() (FailedContainer, error)
}

type CreatingVolume

type CreatingVolume interface {
	Handle() string
	ID() int
	Created() (CreatedVolume, error)
	Failed() (FailedVolume, error)

	InitializeArtifact() (WorkerArtifact, error)
}

type DestroyingContainer

type DestroyingContainer interface {
	Container

	Destroy() (bool, error)
}

type DestroyingVolume

type DestroyingVolume interface {
	Handle() string
	Destroy() (bool, error)
	WorkerName() string
}

type ErrCustomResourceTypeVersionNotFound

type ErrCustomResourceTypeVersionNotFound struct {
	Name string
}

func (ErrCustomResourceTypeVersionNotFound) Error

type ErrPipelineNotFound

type ErrPipelineNotFound atc.PipelineRef

func (ErrPipelineNotFound) Error

func (e ErrPipelineNotFound) Error() string

type ErrResourceNotFound

type ErrResourceNotFound struct {
	Name string
}

func (ErrResourceNotFound) Error

func (e ErrResourceNotFound) Error() string

type ErrVolumeMarkCreatedFailed

type ErrVolumeMarkCreatedFailed struct {
	Handle string
}

func (ErrVolumeMarkCreatedFailed) Error

type ErrVolumeMarkStateFailed

type ErrVolumeMarkStateFailed struct {
	State VolumeState
}

func (ErrVolumeMarkStateFailed) Error

func (e ErrVolumeMarkStateFailed) Error() string

type EventSource

type EventSource interface {
	Next() (event.Envelope, error)
	Close() error
}

type Executor

type Executor interface {
	Exec(statement string, args ...interface{}) (sql.Result, error)
}

type FailedContainer

type FailedContainer interface {
	Container

	Destroy() (bool, error)
}

type FailedVolume

type FailedVolume interface {
	Handle() string
	Destroy() (bool, error)
	WorkerName() string
}

type FederatedClaims

type FederatedClaims struct {
	UserID    string `json:"user_id"`
	Connector string `json:"connector_id"`
}

type FirstLoggedBuildIDDecreasedError

type FirstLoggedBuildIDDecreasedError struct {
	Job   string
	OldID int
	NewID int
}

func (FirstLoggedBuildIDDecreasedError) Error

type GoroutineCounter

type GoroutineCounter interface {
	NumGoroutine() int
}

type InputConfig

type InputConfig struct {
	Name            string
	Trigger         bool
	Passed          JobSet
	UseEveryVersion bool
	PinnedVersion   atc.Version
	ResourceID      int
	JobID           int
}

type InputConfigs

type InputConfigs []InputConfig

func (InputConfigs) String

func (cfgs InputConfigs) String() string

type InputMapping

type InputMapping map[string]InputResult

type InputResult

type InputResult struct {
	Input          *AlgorithmInput
	PassedBuildIDs []int
	ResolveError   ResolutionFailure
}

type InputVersionEmptyError

type InputVersionEmptyError struct {
	InputName string
}

func (InputVersionEmptyError) Error

func (e InputVersionEmptyError) Error() string

type Job

type Job interface {
	PipelineRef

	ID() int
	Name() string
	FirstLoggedBuildID() int
	TeamID() int
	TeamName() string
	Tags() []string
	Public() bool
	ScheduleRequestedTime() time.Time
	MaxInFlight() int
	DisableManualTrigger() bool

	Config() (atc.JobConfig, error)
	Inputs() ([]atc.JobInput, error)
	Outputs() ([]atc.JobOutput, error)
	AlgorithmInputs() (InputConfigs, error)

	Reload() (bool, error)

	Paused() bool
	PausedBy() string
	PausedAt() time.Time
	Pause(pausedBy string) error
	Unpause() error

	ScheduleBuild(Build) (bool, error)
	CreateBuild(createdBy string) (Build, error)
	RerunBuild(build Build, createdBy string) (Build, error)

	RequestSchedule() error
	UpdateLastScheduled(time.Time) error

	ChronoBuilds(page Page) ([]BuildForAPI, Pagination, error)
	Builds(page Page) ([]BuildForAPI, Pagination, error)
	BuildsWithTime(page Page) ([]BuildForAPI, Pagination, error)
	Build(name string) (Build, bool, error)
	FinishedAndNextBuild() (Build, Build, error)
	UpdateFirstLoggedBuildID(newFirstLoggedBuildID int) error
	EnsurePendingBuildExists(context.Context) error
	GetPendingBuilds() ([]Build, error)
	LatestCompletedBuildId() (int, error)

	GetNextBuildInputs() ([]BuildInput, error)
	GetFullNextBuildInputs() ([]BuildInput, bool, error)
	SaveNextInputMapping(inputMapping InputMapping, inputsDetermined bool) error

	ClearTaskCache(string, string) (int64, error)

	AcquireSchedulingLock(lager.Logger) (lock.Lock, bool, error)

	SetHasNewInputs(bool) error
	HasNewInputs() bool
}

type JobFactory

type JobFactory interface {
	VisibleJobs([]string) ([]atc.JobSummary, error)
	AllActiveJobs() ([]atc.JobSummary, error)
	JobsToSchedule() (SchedulerJobs, error)
}

XXX: This job factory object is not really a job factory anymore. It is holding the responsibility for two very different things: constructing a dashboard object and also a scheduler job object. Figure out what this is trying to encapsulate or considering splitting this out!

func NewJobFactory

func NewJobFactory(conn Conn, lockFactory lock.LockFactory) JobFactory

type JobSet

type JobSet map[int]bool

type Jobs

type Jobs []Job

func (Jobs) Configs

func (jobs Jobs) Configs() (atc.JobConfigs, error)

type LastCheck

type LastCheck struct {
	StartTime time.Time
	EndTime   time.Time
	Succeeded bool
}

type Listener

type Listener interface {
	Close() error
	Listen(channel string) error
	Unlisten(channel string) error
	NotificationChannel() <-chan *pq.Notification
}

type MissingInputReasons

type MissingInputReasons map[string]string

func (MissingInputReasons) RegisterMissingInput

func (m MissingInputReasons) RegisterMissingInput(inputName string)

func (MissingInputReasons) RegisterNoResourceCheckFinished

func (m MissingInputReasons) RegisterNoResourceCheckFinished(inputName string)

func (MissingInputReasons) RegisterResolveError

func (m MissingInputReasons) RegisterResolveError(inputName string, resolveErr string)

type NonOneRowAffectedError

type NonOneRowAffectedError struct {
	RowsAffected int64
}

func (NonOneRowAffectedError) Error

func (err NonOneRowAffectedError) Error() string

type Notification

type Notification struct {
	Payload string
	Healthy bool
}

type NotificationsBus

type NotificationsBus interface {
	Notify(channel string) error
	Listen(channel string, queueSize int) (chan Notification, error)
	Unlisten(channel string, notify chan Notification) error
	Close() error
}

type Notifier

type Notifier interface {
	Notify() <-chan struct{}
	Close() error
}

type Page

type Page struct {
	From *int // inclusive
	To   *int // inclusive

	Limit   int
	UseDate bool
}

type PaginatedBuilds

type PaginatedBuilds struct {
	// contains filtered or unexported fields
}

func (*PaginatedBuilds) HasNext

func (bs *PaginatedBuilds) HasNext() bool

func (*PaginatedBuilds) Next

func (bs *PaginatedBuilds) Next(ctx context.Context) (int, bool, error)

type Pagination

type Pagination struct {
	Newer *Page
	Older *Page
}

type PinnedVersionNotFound

type PinnedVersionNotFound struct {
	PinnedVersion atc.Version
}

func (PinnedVersionNotFound) String

type Pipe

type Pipe struct {
	ID       string
	URL      string
	TeamName string
}

type Pipeline

type Pipeline interface {
	ID() int
	Name() string
	TeamID() int
	TeamName() string
	InstanceVars() atc.InstanceVars
	ParentJobID() int
	ParentBuildID() int
	Groups() atc.GroupConfigs
	VarSources() atc.VarSourceConfigs
	Display() *atc.DisplayConfig
	ConfigVersion() ConfigVersion
	Config() (atc.Config, error)
	Public() bool
	Archived() bool
	LastUpdated() time.Time

	CheckPaused() (bool, error)
	Reload() (bool, error)

	ResourceVersion(resourceConfigVersionID int) (atc.ResourceVersion, bool, error)

	GetBuildsWithVersionAsInput(int, int) ([]Build, error)
	GetBuildsWithVersionAsOutput(int, int) ([]Build, error)

	CreateOneOffBuild() (Build, error)
	CreateStartedBuild(plan atc.Plan) (Build, error)

	Builds(page Page) ([]BuildForAPI, Pagination, error)
	BuildsWithTime(page Page) ([]BuildForAPI, Pagination, error)

	DeleteBuildEventsByBuildIDs(buildIDs []int) error

	LoadDebugVersionsDB() (*atc.DebugVersionsDB, error)

	Resource(name string) (Resource, bool, error)
	ResourceID(name string) (int, bool, error)
	ResourceByID(id int) (Resource, bool, error)
	Resources() (Resources, error)

	ResourceTypes() (ResourceTypes, error)
	ResourceType(name string) (ResourceType, bool, error)

	Prototypes() (Prototypes, error)
	Prototype(name string) (Prototype, bool, error)

	SetResourceConfigScopeForResource(name string, scope ResourceConfigScope) error
	SetResourceConfigScopeForResourceType(name string, scope ResourceConfigScope) error
	SetResourceConfigScopeForPrototype(name string, scope ResourceConfigScope) error

	Job(name string) (Job, bool, error)
	Jobs() (Jobs, error)
	Dashboard() ([]atc.JobSummary, error)

	Expose() error
	Hide() error

	Paused() bool
	PausedBy() string
	PausedAt() time.Time
	Pause(pausedBy string) error
	Unpause() error

	Archive() error

	Destroy() error

	Variables(lager.Logger, creds.Secrets, creds.VarSourcePool) (vars.Variables, error)

	SetParentIDs(jobID, buildID int) error
}

type PipelineFactory

type PipelineFactory interface {
	VisiblePipelines([]string) ([]Pipeline, error)
	AllPipelines() ([]Pipeline, error)
	PipelinesToSchedule() ([]Pipeline, error)
}

func NewPipelineFactory

func NewPipelineFactory(conn Conn, lockFactory lock.LockFactory) PipelineFactory

type PipelineLifecycle

type PipelineLifecycle interface {
	ArchiveAbandonedPipelines() error
	RemoveBuildEventsForDeletedPipelines() error
}

func NewPipelineLifecycle

func NewPipelineLifecycle(conn Conn, lockFactory lock.LockFactory) PipelineLifecycle

type PipelinePauser

type PipelinePauser interface {
	PausePipelines(ctx context.Context, daysSinceLastBuild int) error
}

func NewPipelinePauser

func NewPipelinePauser(conn Conn, lockFactory lock.LockFactory) PipelinePauser

type PipelineRef

type PipelineRef interface {
	PipelineID() int
	PipelineName() string
	PipelineInstanceVars() atc.InstanceVars
	PipelineRef() atc.PipelineRef
	Pipeline() (Pipeline, bool, error)
}

A lot of struct refer to a pipeline. This is a helper interface that should embedded in those interfaces that need to refer to a pipeline. Accordingly, implementations of those interfaces should embed "pipelineRef".

func NewPipelineRef

func NewPipelineRef(id int, name string, instanceVars atc.InstanceVars, conn Conn, lockFactory lock.LockFactory) PipelineRef

type Prototype

type Prototype interface {
	PipelineRef

	ID() int
	TeamID() int
	TeamName() string
	Name() string
	Type() string
	Privileged() bool
	Source() atc.Source
	Defaults() atc.Source
	Params() atc.Params
	Tags() atc.Tags
	CheckEvery() *atc.CheckEvery
	CheckTimeout() string
	LastCheckStartTime() time.Time
	LastCheckEndTime() time.Time
	CurrentPinnedVersion() atc.Version
	ResourceConfigID() int
	ResourceConfigScopeID() int

	HasWebhook() bool

	SetResourceConfigScope(ResourceConfigScope) error

	CheckPlan(planFactory atc.PlanFactory, imagePlanner atc.ImagePlanner, from atc.Version, interval atc.CheckEvery, sourceDefaults atc.Source, skipInterval bool, skipIntervalRecursively bool) atc.Plan
	CreateBuild(context.Context, bool, atc.Plan) (Build, bool, error)

	CreateInMemoryBuild(context.Context, atc.Plan, util.SequenceGenerator) (Build, error)

	Version() atc.Version

	Reload() (bool, error)
}

type Prototypes

type Prototypes []Prototype

func (Prototypes) Configs

func (prototypes Prototypes) Configs() atc.Prototypes

type RealGoroutineCounter

type RealGoroutineCounter struct{}

func (RealGoroutineCounter) NumGoroutine

func (r RealGoroutineCounter) NumGoroutine() int

type ResolutionFailure

type ResolutionFailure string
const (
	LatestVersionNotFound ResolutionFailure = "latest version of resource not found"
	VersionNotFound       ResolutionFailure = "version of resource not found"
	NoSatisfiableBuilds   ResolutionFailure = "no satisfiable builds from passed jobs found for set of inputs"
)

type Resource

type Resource interface {
	PipelineRef

	ID() int
	Name() string
	Public() bool
	TeamID() int
	TeamName() string
	Type() string
	Source() atc.Source
	CheckEvery() *atc.CheckEvery
	CheckTimeout() string
	LastCheckStartTime() time.Time
	LastCheckEndTime() time.Time
	Tags() atc.Tags
	WebhookToken() string
	Config() atc.ResourceConfig
	ConfigPinnedVersion() atc.Version
	APIPinnedVersion() atc.Version
	PinComment() string
	SetPinComment(string) error
	ResourceConfigID() int
	ResourceConfigScopeID() int
	Icon() string

	HasWebhook() bool

	CurrentPinnedVersion() atc.Version

	BuildSummary() *atc.BuildSummary

	ClearVersions() (int64, error)
	Versions(page Page, versionFilter atc.Version) ([]atc.ResourceVersion, Pagination, bool, error)
	FindVersion(filter atc.Version) (ResourceConfigVersion, bool, error) // Only used in tests!!
	UpdateMetadata(atc.Version, ResourceConfigMetadataFields) (bool, error)

	EnableVersion(rcvID int) error
	DisableVersion(rcvID int) error

	PinVersion(rcvID int) (bool, error)
	UnpinVersion() error

	Causality(rcvID int, direction CausalityDirection) (atc.Causality, bool, error)

	SetResourceConfigScope(ResourceConfigScope) error

	CheckPlan(planFactory atc.PlanFactory, imagePlanner atc.ImagePlanner, from atc.Version, interval atc.CheckEvery, sourceDefaults atc.Source, skipInterval bool, skipIntervalRecursively bool) atc.Plan
	CreateBuild(context.Context, bool, atc.Plan) (Build, bool, error)
	CreateInMemoryBuild(context.Context, atc.Plan, util.SequenceGenerator) (Build, error)

	NotifyScan() error

	ClearResourceCache(atc.Version) (int64, error)

	SharedResourcesAndTypes() (atc.ResourcesAndTypes, error)

	Reload() (bool, error)
}

type ResourceCache

type ResourceCache interface {
	ID() int
	Version() atc.Version

	ResourceConfig() ResourceConfig

	Destroy(Tx) (bool, error)
	BaseResourceType() *UsedBaseResourceType
}

type ResourceCacheFactory

type ResourceCacheFactory interface {
	FindOrCreateResourceCache(
		resourceCacheUser ResourceCacheUser,
		resourceTypeName string,
		version atc.Version,
		source atc.Source,
		params atc.Params,
		customTypeResourceCache ResourceCache,
	) (ResourceCache, error)

	// changing resource cache to interface to allow updates on object is not feasible.
	// Since we need to pass it recursively in ResourceConfig.
	// Also, metadata will be available to us before we create resource cache so this
	// method can be removed at that point. See  https://github.com/concourse/concourse/issues/534
	UpdateResourceCacheMetadata(ResourceCache, []atc.MetadataField) error
	ResourceCacheMetadata(ResourceCache) (ResourceConfigMetadataFields, error)

	FindResourceCacheByID(id int) (ResourceCache, bool, error)
}

func NewResourceCacheFactory

func NewResourceCacheFactory(conn Conn, lockFactory lock.LockFactory) ResourceCacheFactory

type ResourceCacheLifecycle

type ResourceCacheLifecycle interface {
	CleanUsesForFinishedBuilds(lager.Logger) error
	CleanBuildImageResourceCaches(lager.Logger) error
	CleanUpInvalidCaches(lager.Logger) error
	CleanInvalidWorkerResourceCaches(lager.Logger, int) error
	CleanDirtyInMemoryBuildUses(lager.Logger) error
}

func NewResourceCacheLifecycle

func NewResourceCacheLifecycle(conn Conn) ResourceCacheLifecycle

type ResourceCacheUser

type ResourceCacheUser interface {
	SQLMap() map[string]interface{}
}

ResourceCacheUser designates the column to set in the resource_cache_users table.

func ForBuild

func ForBuild(id int) ResourceCacheUser

func ForInMemoryBuild

func ForInMemoryBuild(id int, createTime time.Time) ResourceCacheUser

type ResourceCheckRateLimiter

type ResourceCheckRateLimiter struct {
	// contains filtered or unexported fields
}

func NewResourceCheckRateLimiter

func NewResourceCheckRateLimiter(
	checksPerSecond rate.Limit,
	minChecksPerSecond rate.Limit,
	checkInterval time.Duration,
	refreshConn Conn,
	refreshInterval time.Duration,
	clock clock.Clock,
) *ResourceCheckRateLimiter

func (*ResourceCheckRateLimiter) Limit

func (limiter *ResourceCheckRateLimiter) Limit() rate.Limit

func (*ResourceCheckRateLimiter) Wait

func (limiter *ResourceCheckRateLimiter) Wait(ctx context.Context) error

type ResourceConfig

type ResourceConfig interface {
	ID() int
	LastReferenced() time.Time
	CreatedByResourceCache() ResourceCache
	CreatedByBaseResourceType() *UsedBaseResourceType

	OriginBaseResourceType() *UsedBaseResourceType

	FindOrCreateScope(resourceID *int) (ResourceConfigScope, error)
}

type ResourceConfigCheckSessionLifecycle

type ResourceConfigCheckSessionLifecycle interface {
	CleanInactiveResourceConfigCheckSessions() error
	CleanExpiredResourceConfigCheckSessions() error
}

func NewResourceConfigCheckSessionLifecycle

func NewResourceConfigCheckSessionLifecycle(conn Conn) ResourceConfigCheckSessionLifecycle

type ResourceConfigFactory

type ResourceConfigFactory interface {
	FindOrCreateResourceConfig(
		resourceType string,
		source atc.Source,
		customTypeResourceCache ResourceCache,
	) (ResourceConfig, error)

	FindResourceConfigByID(int) (ResourceConfig, bool, error)

	CleanUnreferencedConfigs(time.Duration) error
}

func NewResourceConfigFactory

func NewResourceConfigFactory(conn Conn, lockFactory lock.LockFactory) ResourceConfigFactory

type ResourceConfigMetadataField

type ResourceConfigMetadataField struct {
	Name  string
	Value string
}

type ResourceConfigMetadataFields

type ResourceConfigMetadataFields []ResourceConfigMetadataField

func NewResourceConfigMetadataFields

func NewResourceConfigMetadataFields(atcm []atc.MetadataField) ResourceConfigMetadataFields

func (ResourceConfigMetadataFields) ToATCMetadata

func (rmf ResourceConfigMetadataFields) ToATCMetadata() []atc.MetadataField

type ResourceConfigScope

type ResourceConfigScope interface {
	ID() int
	ResourceID() *int
	ResourceConfig() ResourceConfig

	SaveVersions(SpanContext, []atc.Version) error
	FindVersion(atc.Version) (ResourceConfigVersion, bool, error)
	LatestVersion() (ResourceConfigVersion, bool, error)

	AcquireResourceCheckingLock(
		logger lager.Logger,
	) (lock.Lock, bool, error)

	LastCheck() (LastCheck, error)
	UpdateLastCheckStartTime(int, *json.RawMessage) (bool, error)
	UpdateLastCheckEndTime(bool) (bool, error)
}

ResourceConfigScope represents the relationship between a possible pipeline resource and a resource config. When a resource is specified to have a unique version history either through its base resource type or its custom resource type, it results in its generated resource config to be scoped to the resource. This relationship is translated into its row in the resource config scopes table to have both the resource id and resource config id populated. When a resource has a shared version history, its resource config is not scoped to the (or any) resource and its row in the resource config scopes table will have the resource config id populated but a NULL value for the resource id. Resource versions will therefore be directly dependent on a resource config scope.

type ResourceConfigVersion

type ResourceConfigVersion interface {
	ID() int
	Version() Version
	Metadata() ResourceConfigMetadataFields
	CheckOrder() int
	SpanContext() propagation.TextMapCarrier

	Reload() (bool, error)
}

type ResourceConfigVersions

type ResourceConfigVersions []ResourceConfigVersion

type ResourceFactory

type ResourceFactory interface {
	Resource(int) (Resource, bool, error)
	VisibleResources([]string) ([]Resource, error)
	AllResources() ([]Resource, error)
}

func NewResourceFactory

func NewResourceFactory(conn Conn, lockFactory lock.LockFactory) ResourceFactory

type ResourceHasNoScopeErr

type ResourceHasNoScopeErr struct {
	Name string
}

func (ResourceHasNoScopeErr) Error

func (e ResourceHasNoScopeErr) Error() string

type ResourceNotFoundError

type ResourceNotFoundError struct {
	ID int
}

func (ResourceNotFoundError) Error

func (e ResourceNotFoundError) Error() string

type ResourceNotFoundInPipeline

type ResourceNotFoundInPipeline struct {
	Resource string
	Pipeline string
}

func (ResourceNotFoundInPipeline) Error

type ResourceType

type ResourceType interface {
	PipelineRef

	ID() int
	TeamID() int
	TeamName() string
	Name() string
	Type() string
	Privileged() bool
	Source() atc.Source
	Defaults() atc.Source
	Params() atc.Params
	Tags() atc.Tags
	CheckEvery() *atc.CheckEvery
	CheckTimeout() string
	LastCheckStartTime() time.Time
	LastCheckEndTime() time.Time
	CurrentPinnedVersion() atc.Version
	ResourceConfigID() int
	ResourceConfigScopeID() int

	HasWebhook() bool

	SetResourceConfigScope(ResourceConfigScope) error
	SharedResourcesAndTypes() (atc.ResourcesAndTypes, error)

	CheckPlan(planFactory atc.PlanFactory, imagePlanner atc.ImagePlanner, from atc.Version, interval atc.CheckEvery, sourceDefaults atc.Source, skipInterval bool, skipIntervalRecursively bool) atc.Plan
	CreateBuild(context.Context, bool, atc.Plan) (Build, bool, error)
	CreateInMemoryBuild(context.Context, atc.Plan, util.SequenceGenerator) (Build, error)

	ClearVersions() (int64, error)

	Reload() (bool, error)
}

type ResourceTypeNotFoundError

type ResourceTypeNotFoundError struct {
	ID int
}

func (ResourceTypeNotFoundError) Error

type ResourceTypes

type ResourceTypes []ResourceType

func (ResourceTypes) Configs

func (resourceTypes ResourceTypes) Configs() atc.ResourceTypes

func (ResourceTypes) Deserialize

func (resourceTypes ResourceTypes) Deserialize() atc.ResourceTypes

func (ResourceTypes) Filter

func (resourceTypes ResourceTypes) Filter(checkable Checkable) ResourceTypes

func (ResourceTypes) Parent

func (resourceTypes ResourceTypes) Parent(checkable Checkable) (ResourceType, bool)

func (ResourceTypes) Without

func (resourceTypes ResourceTypes) Without(name string) ResourceTypes

type ResourceVersion

type ResourceVersion string

type Resources

type Resources []Resource

func (Resources) Configs

func (resources Resources) Configs() atc.ResourceConfigs

func (Resources) Lookup

func (resources Resources) Lookup(name string) (Resource, bool)

type SchedulerJob

type SchedulerJob struct {
	Job
	Resources     SchedulerResources
	ResourceTypes atc.ResourceTypes
	Prototypes    atc.Prototypes
}

type SchedulerJobs

type SchedulerJobs []SchedulerJob

type SchedulerResource

type SchedulerResource struct {
	Name                 string
	Type                 string
	Source               atc.Source
	ExposeBuildCreatedBy bool
}

func (*SchedulerResource) ApplySourceDefaults

func (r *SchedulerResource) ApplySourceDefaults(resourceTypes atc.ResourceTypes)

type SchedulerResources

type SchedulerResources []SchedulerResource

func (SchedulerResources) Lookup

func (resources SchedulerResources) Lookup(name string) (*SchedulerResource, bool)

type SpanContext

type SpanContext map[string]string

func NewSpanContext

func NewSpanContext(ctx context.Context) SpanContext

func (SpanContext) Get

func (sc SpanContext) Get(key string) string

func (SpanContext) Keys

func (sc SpanContext) Keys() []string

func (SpanContext) Set

func (sc SpanContext) Set(key, value string)

type TaskCacheFactory

type TaskCacheFactory interface {
	Find(jobID int, stepName string, path string) (UsedTaskCache, bool, error)
	FindOrCreate(jobID int, stepName string, path string) (UsedTaskCache, error)
}

func NewTaskCacheFactory

func NewTaskCacheFactory(conn Conn) TaskCacheFactory

type TaskCacheLifecycle

type TaskCacheLifecycle interface {
	CleanUpInvalidTaskCaches() ([]int, error)
}

func NewTaskCacheLifecycle

func NewTaskCacheLifecycle(conn Conn) TaskCacheLifecycle

type Team

type Team interface {
	ID() int
	Name() string
	Admin() bool

	Auth() atc.TeamAuth

	Delete() error
	Rename(string) error

	SavePipeline(
		pipelineRef atc.PipelineRef,
		config atc.Config,
		from ConfigVersion,
		initiallyPaused bool,
	) (Pipeline, bool, error)
	RenamePipeline(oldName string, newName string) (bool, error)

	Pipeline(pipelineRef atc.PipelineRef) (Pipeline, bool, error)
	Pipelines() ([]Pipeline, error)
	PublicPipelines() ([]Pipeline, error)
	OrderPipelines([]string) error
	OrderPipelinesWithinGroup(string, []atc.InstanceVars) error

	CreateOneOffBuild() (Build, error)
	CreateStartedBuild(plan atc.Plan) (Build, error)

	PrivateAndPublicBuilds(Page) ([]BuildForAPI, Pagination, error)
	Builds(page Page) ([]BuildForAPI, Pagination, error)
	BuildsWithTime(page Page) ([]BuildForAPI, Pagination, error)

	SaveWorker(atcWorker atc.Worker, ttl time.Duration) (Worker, error)
	Workers() ([]Worker, error)
	FindVolumeForWorkerArtifact(int) (CreatedVolume, bool, error)

	Containers() ([]Container, error)
	IsCheckContainer(string) (bool, error)
	IsContainerWithinTeam(string, bool) (bool, error)

	FindContainerByHandle(string) (Container, bool, error)
	FindCheckContainers(lager.Logger, atc.PipelineRef, string) ([]Container, map[int]time.Time, error)
	FindContainersByMetadata(ContainerMetadata) ([]Container, error)
	FindCreatedContainerByHandle(string) (CreatedContainer, bool, error)
	FindWorkerForContainer(handle string) (Worker, bool, error)
	FindWorkerForVolume(handle string) (Worker, bool, error)
	FindWorkersForResourceCache(rcId int, shouldBeValidBefore time.Time) ([]Worker, error)

	UpdateProviderAuth(auth atc.TeamAuth) error
}

type TeamFactory

type TeamFactory interface {
	CreateTeam(atc.Team) (Team, error)
	FindTeam(string) (Team, bool, error)
	GetTeams() ([]Team, error)
	GetByID(teamID int) Team
	CreateDefaultTeamIfNotExists() (Team, error)
	NotifyResourceScanner() error
	NotifyCacher() error
}

func NewTeamFactory

func NewTeamFactory(conn Conn, lockFactory lock.LockFactory) TeamFactory

type TriggerEvent

type TriggerEvent struct {
	Operation string             `json:"operation"`
	Data      map[string]*string `json:"data"`
}

type Tx

type Tx interface {
	Commit() error
	Exec(string, ...interface{}) (sql.Result, error)
	Prepare(string) (*sql.Stmt, error)
	Query(string, ...interface{}) (*sql.Rows, error)
	QueryRow(string, ...interface{}) squirrel.RowScanner
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) squirrel.RowScanner
	Rollback() error
	Stmt(*sql.Stmt) *sql.Stmt
	EncryptionStrategy() encryption.Strategy
}

type UpdateName

type UpdateName struct {
	OldName string
	NewName string
}

type UsedBaseResourceType

type UsedBaseResourceType struct {
	ID                   int    // The ID of the BaseResourceType.
	Name                 string // The name of the type, e.g. 'git'.
	UniqueVersionHistory bool   // If set to true, will create unique version histories for each of the resources using this base resource type
}

UsedBaseResourceType is created whenever a ResourceConfig is used, either for a build, a resource in the pipeline, or a resource type in the pipeline.

So long as the UsedBaseResourceType's ID is referenced by a ResourceConfig that is in use, this guarantees that the BaseResourceType will not be removed. That is to say that its "Use" is vicarious.

type UsedTaskCache

type UsedTaskCache interface {
	ID() int

	JobID() int
	StepName() string
	Path() string
}

type UsedWorkerBaseResourceType

type UsedWorkerBaseResourceType struct {
	ID      int
	Name    string
	Version string

	WorkerName string
}

type UsedWorkerResourceCache

type UsedWorkerResourceCache struct {
	ID                       int
	WorkerBaseResourceTypeID int
}

type UsedWorkerResourceCerts

type UsedWorkerResourceCerts struct {
	ID int
}

type UsedWorkerResourceType

type UsedWorkerResourceType struct {
	ID int

	Worker Worker

	UsedBaseResourceType *UsedBaseResourceType
}

type UsedWorkerTaskCache

type UsedWorkerTaskCache struct {
	ID         int
	WorkerName string
}

type User

type User interface {
	ID() int
	Sub() string
	Name() string
	Connector() string
	LastLogin() time.Time
}

type UserFactory

type UserFactory interface {
	CreateOrUpdateUser(username, connector, sub string) error
	GetAllUsers() ([]User, error)
	GetAllUsersByLoginDate(LastLogin time.Time) ([]User, error)
}

func NewUserFactory

func NewUserFactory(conn Conn) UserFactory

type Version

type Version map[string]string

type VersionsDB

type VersionsDB struct {
	// contains filtered or unexported fields
}

func NewVersionsDB

func NewVersionsDB(conn Conn, limitRows int, cache *gocache.Cache) VersionsDB

func (VersionsDB) FindVersionOfResource

func (versions VersionsDB) FindVersionOfResource(ctx context.Context, resourceID int, v atc.Version) (ResourceVersion, bool, error)

func (VersionsDB) IsFirstOccurrence

func (versions VersionsDB) IsFirstOccurrence(ctx context.Context, jobID int, inputName string, versionMD5 ResourceVersion, resourceId int) (bool, error)

func (VersionsDB) LatestBuildPipes

func (versions VersionsDB) LatestBuildPipes(ctx context.Context, buildID int) (map[int]BuildCursor, error)

func (VersionsDB) LatestBuildUsingLatestVersion

func (versions VersionsDB) LatestBuildUsingLatestVersion(ctx context.Context, jobID int, resourceID int) (int, bool, error)

func (VersionsDB) LatestVersionOfResource

func (versions VersionsDB) LatestVersionOfResource(ctx context.Context, resourceID int) (ResourceVersion, bool, error)

func (VersionsDB) NextEveryVersion

func (versions VersionsDB) NextEveryVersion(ctx context.Context, jobID int, resourceID int) (ResourceVersion, bool, bool, error)

func (VersionsDB) SuccessfulBuildOutputs

func (versions VersionsDB) SuccessfulBuildOutputs(ctx context.Context, buildID int) ([]AlgorithmVersion, error)

func (VersionsDB) SuccessfulBuilds

func (versions VersionsDB) SuccessfulBuilds(ctx context.Context, jobID int) PaginatedBuilds

func (VersionsDB) SuccessfulBuildsVersionConstrained

func (versions VersionsDB) SuccessfulBuildsVersionConstrained(
	ctx context.Context,
	jobID int,
	constrainingCandidates map[string][]string,
) (PaginatedBuilds, error)

func (VersionsDB) UnusedBuilds

func (versions VersionsDB) UnusedBuilds(ctx context.Context, jobID int, lastUsedBuild BuildCursor) (PaginatedBuilds, error)

func (VersionsDB) UnusedBuildsVersionConstrained

func (versions VersionsDB) UnusedBuildsVersionConstrained(ctx context.Context, jobID int, lastUsedBuild BuildCursor, constrainingCandidates map[string][]string) (PaginatedBuilds, error)

func (VersionsDB) VersionExists

func (versions VersionsDB) VersionExists(ctx context.Context, resourceID int, versionMD5 ResourceVersion) (bool, error)

func (VersionsDB) VersionIsDisabled

func (versions VersionsDB) VersionIsDisabled(ctx context.Context, resourceID int, versionMD5 ResourceVersion) (bool, error)

type VolumeRepository

type VolumeRepository interface {
	GetTeamVolumes(teamID int) ([]CreatedVolume, error)

	CreateContainerVolume(teamID int, workerName string, container CreatingContainer, mountPath string) (CreatingVolume, error)
	FindContainerVolume(teamID int, workerName string, container CreatingContainer, mountPath string) (CreatingVolume, CreatedVolume, error)

	FindBaseResourceTypeVolume(*UsedWorkerBaseResourceType) (CreatingVolume, CreatedVolume, error)
	CreateBaseResourceTypeVolume(*UsedWorkerBaseResourceType) (CreatingVolume, error)

	FindResourceCacheVolume(workerName string, resourceCache ResourceCache, volumeShouldBeValidBefore time.Time) (CreatedVolume, bool, error)

	FindTaskCacheVolume(teamID int, workerName string, taskCache UsedTaskCache) (CreatedVolume, bool, error)
	CreateTaskCacheVolume(teamID int, uwtc *UsedWorkerTaskCache) (CreatingVolume, error)

	FindResourceCertsVolume(workerName string, uwrc *UsedWorkerResourceCerts) (CreatingVolume, CreatedVolume, error)
	CreateResourceCertsVolume(workerName string, uwrc *UsedWorkerResourceCerts) (CreatingVolume, error)

	FindVolumesForContainer(container CreatedContainer) ([]CreatedVolume, error)
	GetOrphanedVolumes() ([]CreatedVolume, error)

	FindWorkersForResourceCache(resourceCache ResourceCache) ([]string, error)
	FindWorkersForTaskCache(taskCache UsedTaskCache) ([]string, error)

	DestroyFailedVolumes() (count int, err error)

	GetDestroyingVolumes(workerName string) ([]string, error)

	CreateVolume(teamID int, workerName string, volumeType VolumeType) (CreatingVolume, error)
	CreateVolumeWithHandle(handle string, teamID int, workerName string, volumeType VolumeType) (CreatingVolume, error)
	FindVolume(handle string) (CreatedVolume, bool, error)

	RemoveDestroyingVolumes(workerName string, handles []string) (int, error)

	UpdateVolumesMissingSince(workerName string, handles []string) error
	RemoveMissingVolumes(gracePeriod time.Duration) (removed int, err error)

	DestroyUnknownVolumes(workerName string, handles []string) (int, error)
}

func NewVolumeRepository

func NewVolumeRepository(conn Conn) VolumeRepository

type VolumeResourceType

type VolumeResourceType struct {
	WorkerBaseResourceType *UsedWorkerBaseResourceType
	ResourceType           *VolumeResourceType
	Version                atc.Version
}

type VolumeState

type VolumeState string
const (
	VolumeStateCreating   VolumeState = "creating"
	VolumeStateCreated    VolumeState = "created"
	VolumeStateDestroying VolumeState = "destroying"
	VolumeStateFailed     VolumeState = "failed"
)

type VolumeType

type VolumeType string
const (
	VolumeTypeContainer     VolumeType = "container"
	VolumeTypeResource      VolumeType = "resource"
	VolumeTypeResourceType  VolumeType = "resource-type"
	VolumeTypeResourceCerts VolumeType = "resource-certs"
	VolumeTypeTaskCache     VolumeType = "task-cache"
	VolumeTypeArtifact      VolumeType = "artifact"
	VolumeTypeUknown        VolumeType = "unknown" // for migration to life
)

type Wall

type Wall interface {
	SetWall(atc.Wall) error
	GetWall() (atc.Wall, error)
	Clear() error
}

func NewWall

func NewWall(conn Conn, clock Clock) Wall

type Worker

type Worker interface {
	Name() string
	Version() *string
	State() WorkerState
	GardenAddr() *string
	BaggageclaimURL() *string
	CertsPath() *string
	ResourceCerts() (*UsedWorkerResourceCerts, bool, error)
	HTTPProxyURL() string
	HTTPSProxyURL() string
	NoProxy() string
	ActiveContainers() int
	ActiveVolumes() int
	ResourceTypes() []atc.WorkerResourceType
	Platform() string
	Tags() []string
	TeamID() int
	TeamName() string
	StartTime() time.Time
	ExpiresAt() time.Time
	Ephemeral() bool

	Reload() (bool, error)

	Land() error
	Retire() error
	Prune() error
	Delete() error

	ActiveTasks() (int, error)
	IncreaseActiveTasks(int) (int, error)
	DecreaseActiveTasks() (int, error)

	FindContainer(owner ContainerOwner) (CreatingContainer, CreatedContainer, error)
	CreateContainer(owner ContainerOwner, meta ContainerMetadata) (CreatingContainer, error)
}

type WorkerArtifact

type WorkerArtifact interface {
	ID() int
	Name() string
	BuildID() int
	CreatedAt() time.Time
	Volume(teamID int) (CreatedVolume, bool, error)
}

TODO-L Can this be consolidated with atc/runtime/types.go -> Artifact OR Alternatively, there shouldn't be a volume reference here

type WorkerArtifactLifecycle

type WorkerArtifactLifecycle interface {
	RemoveExpiredArtifacts() error
}

type WorkerBaseResourceType

type WorkerBaseResourceType struct {
	Name       string
	WorkerName string
}

func (WorkerBaseResourceType) Find

func (workerBaseResourceType WorkerBaseResourceType) Find(runner sq.Runner) (*UsedWorkerBaseResourceType, bool, error)

func (WorkerBaseResourceType) FindById

func (workerBaseResourceType WorkerBaseResourceType) FindById(runner sq.Runner, id int) (*UsedWorkerBaseResourceType, bool, error)

type WorkerBaseResourceTypeFactory

type WorkerBaseResourceTypeFactory interface {
	Find(name string, worker Worker) (*UsedWorkerBaseResourceType, bool, error)
}

func NewWorkerBaseResourceTypeFactory

func NewWorkerBaseResourceTypeFactory(conn Conn) WorkerBaseResourceTypeFactory

type WorkerCache

type WorkerCache struct {
	// contains filtered or unexported fields
}

WorkerCache monitors changes to the workers and containers tables. It keeps a list of workers and the number of active build containers that belong to each worker in memory. The container count is from the perspective of the DB, rather than what the workers report.

In addition to responding to state changes, we also periodically re-sync the data by fetching fresh data from the database. Theoretically this shouldn't be necessary (since we try to respond to every change to the tables), but it's possible to miss events (e.g. the notification bus queue is full, network flakes, etc).

func NewStaticWorkerCache

func NewStaticWorkerCache(logger lager.Logger, conn Conn, refreshInterval time.Duration) *WorkerCache

NewStaticWorkerCache returns a WorkerCache that doesn't subscribe to changes to the workers/containers table, so it's data is likely to be stale until the next refresh.

func NewWorkerCache

func NewWorkerCache(logger lager.Logger, conn Conn, refreshInterval time.Duration) (*WorkerCache, error)

func (*WorkerCache) WorkerContainerCounts

func (cache *WorkerCache) WorkerContainerCounts() (map[string]int, error)

func (*WorkerCache) Workers

func (cache *WorkerCache) Workers() ([]Worker, error)

type WorkerFactory

type WorkerFactory interface {
	GetWorker(name string) (Worker, bool, error)
	SaveWorker(atcWorker atc.Worker, ttl time.Duration) (Worker, error)
	HeartbeatWorker(worker atc.Worker, ttl time.Duration) (Worker, error)
	Workers() ([]Worker, error)
	VisibleWorkers([]string) ([]Worker, error)

	FindWorkersForContainerByOwner(ContainerOwner) ([]Worker, error)
	BuildContainersCountPerWorker() (map[string]int, error)
}

func NewWorkerFactory

func NewWorkerFactory(conn Conn, cache *WorkerCache) WorkerFactory

type WorkerLifecycle

type WorkerLifecycle interface {
	DeleteUnresponsiveEphemeralWorkers() ([]string, error)
	StallUnresponsiveWorkers() ([]string, error)
	LandFinishedLandingWorkers() ([]string, error)
	DeleteFinishedRetiringWorkers() ([]string, error)
	GetWorkerStateByName() (map[string]WorkerState, error)
}

func NewWorkerLifecycle

func NewWorkerLifecycle(conn Conn) WorkerLifecycle

type WorkerResourceCache

type WorkerResourceCache struct {
	WorkerName    string
	ResourceCache ResourceCache
}

WorkerResourceCache stores resource caches on each worker. WorkerBaseResourceTypeID field records the original worker's base resource id when the cache is created. For example, when a resource cache is created on worker-1 and WorkerBaseResourceTypeID is 100. Then the resource cache is streamed to worker-2, a new worker resource cache will be created for worker-2, and WorkerBaseResourceTypeID will still be 100.

If worker-1 is pruned, the worker resource cache on worker-2 will be invalidated by setting WorkerBaseResourceTypeID to 0 and invalid_since to current time. Thus, a worker resource cache is called "valid" when its WorkerBaseResourceTypeID is not 0, and called "invalidated" when its WorkerBaseResourceTypeID is 0.

Builds started before invalid_since of an invalidated worker resource cache will still be able to use the cache. But if the cache is streamed to other workers, streamed volumes should no longer be marked as cache again.

When there is no running build started before invalid_since of an invalidated cache, the cache will be GC-ed.

func (WorkerResourceCache) Find

func (workerResourceCache WorkerResourceCache) Find(runner sq.Runner, volumeShouldBeValidBefore time.Time) (*UsedWorkerResourceCache, bool, error)

Find looks for a worker resource cache by resource cache id and worker name. If there is a valid cache, it will return it; otherwise an invalidated cache (worker_base_resource_type_id is 0) might be returned, but the invalidated cache's invalid_since must be later than volumeShouldBeValidBefore.

func (WorkerResourceCache) FindByID

func (workerResourceCache WorkerResourceCache) FindByID(runner sq.Runner, id int) (*UsedWorkerResourceCache, bool, error)

FindByID looks for a worker resource cache by resource cache id. To init a streamed volume as cache, it should check to see if the original cache is still valid.

func (WorkerResourceCache) FindOrCreate

func (workerResourceCache WorkerResourceCache) FindOrCreate(tx Tx, sourceWorkerBaseResourceTypeID int) (*UsedWorkerResourceCache, bool, error)

FindOrCreate finds or creates a worker_resource_cache initialized from a given sourceWorkerBaseResourceTypeID (which dictates the original worker that ran the get step for this resource cache). If there already exists a worker_resource_cache for the provided WorkerName and ResourceCache, but initialized from a different source worker, it will return `false` as its second return value.

This can happen if multiple volumes for the same resource cache are being streamed to a worker simultaneously from multiple other "source" workers - we only want a single worker_resource_cache in the end for the destination worker, so the "first write wins".

type WorkerResourceCerts

type WorkerResourceCerts struct {
	WorkerName string
	CertsPath  string
}

func (WorkerResourceCerts) Find

func (workerResourceCerts WorkerResourceCerts) Find(runner sq.BaseRunner) (*UsedWorkerResourceCerts, bool, error)

func (WorkerResourceCerts) FindOrCreate

func (workerResourceCerts WorkerResourceCerts) FindOrCreate(tx Tx) (*UsedWorkerResourceCerts, error)

type WorkerResourceType

type WorkerResourceType struct {
	Worker  Worker
	Image   string // The path to the image, e.g. '/opt/concourse/resources/git'.
	Version string // The version of the image, e.g. a SHA of the rootfs.

	BaseResourceType *BaseResourceType
}

func (WorkerResourceType) FindOrCreate

func (wrt WorkerResourceType) FindOrCreate(tx Tx, unique bool) (*UsedWorkerResourceType, error)

type WorkerState

type WorkerState string

func AllWorkerStates

func AllWorkerStates() []WorkerState

type WorkerTaskCache

type WorkerTaskCache struct {
	WorkerName string
	TaskCache  UsedTaskCache
}

type WorkerTaskCacheFactory

type WorkerTaskCacheFactory interface {
	FindOrCreate(WorkerTaskCache) (*UsedWorkerTaskCache, error)
	Find(WorkerTaskCache) (*UsedWorkerTaskCache, bool, error)
}

func NewWorkerTaskCacheFactory

func NewWorkerTaskCacheFactory(conn Conn) WorkerTaskCacheFactory

Source Files

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.
encryptionfakes
Code generated by counterfeiter.
Code generated by counterfeiter.
lockfakes
Code generated by counterfeiter.
Code generated by counterfeiter.
cli

Jump to

Keyboard shortcuts

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