db

package
v0.0.0-...-7f11b89 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2017 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoVerionsSatisfiedPassedConstraints string = "no versions satisfy passed constraints"
	NoVersionsAvailable                 string = "no versions available"
	PinnedVersionUnavailable            string = "pinned version %s is not available"
)

Variables

View Source
var ErrBuildEventStreamClosed = errors.New("build event stream closed")
View Source
var ErrConfigComparisonFailed = errors.New("comparison with existing config failed during save")
View Source
var ErrEndOfBuildEventStream = errors.New("end of build event stream")
View Source
var ErrMultipleContainersFound = errors.New("multiple containers found for given identifier")

Functions

func NewNotificationsBus

func NewNotificationsBus(listener *pq.Listener, conn Conn) *notificationsBus

func NewPipelineDBFactory

func NewPipelineDBFactory(
	sqldbConnection Conn,
	bus *notificationsBus,
	lockFactory lock.LockFactory,
) *pipelineDBFactory

Types

type BasicAuth

type BasicAuth struct {
	BasicAuthUsername string `json:"basic_auth_username"`
	BasicAuthPassword string `json:"basic_auth_password"`
}

func (*BasicAuth) EncryptedJSON

func (auth *BasicAuth) EncryptedJSON() (string, error)

type Build

type Build interface {
	ID() int
	Name() string
	JobID() int
	JobName() string
	PipelineID() int
	PipelineName() string
	TeamID() int
	TeamName() string
	Engine() string
	EngineMetadata() string
	Status() Status
	StartTime() time.Time
	EndTime() time.Time
	ReapTime() time.Time
	IsOneOff() bool
	IsScheduled() bool
	IsRunning() bool
	IsManuallyTriggered() bool

	Reload() (bool, error)

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

	GetVersionedResources() (SavedVersionedResources, error)
	GetResources() ([]BuildInput, []BuildOutput, error)

	Start(string, string) (bool, error)
	Finish(status Status) error
	MarkAsFailed(cause error) error
	Abort() error
	AbortNotifier() (Notifier, error)

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

	GetPreparation() (BuildPreparation, bool, error)

	SaveEngineMetadata(engineMetadata string) error

	SaveInput(input BuildInput) (SavedVersionedResource, error)
	SaveOutput(vr VersionedResource, explicit bool) (SavedVersionedResource, error)

	SaveImageResourceVersion(planID atc.PlanID, identifier ResourceCacheIdentifier) error
	GetImageResourceCacheIdentifiers() ([]ResourceCacheIdentifier, error)

	GetConfig() (atc.Config, ConfigVersion, error)

	GetPipeline() (SavedPipeline, error)
}

type BuildInput

type BuildInput struct {
	Name string

	VersionedResource

	FirstOccurrence bool
}

type BuildOutput

type BuildOutput struct {
	VersionedResource
}

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 (
	BuildPreparationStatusUnknown     BuildPreparationStatus = "unknown"
	BuildPreparationStatusBlocking    BuildPreparationStatus = "blocking"
	BuildPreparationStatusNotBlocking BuildPreparationStatus = "not_blocking"
)

type ConfigVersion

type ConfigVersion int

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

type Conn

type Conn interface {
	Begin() (Tx, error)
	Close() error
	Driver() driver.Driver
	Exec(query string, args ...interface{}) (sql.Result, error)
	Ping() error
	Prepare(query string) (*sql.Stmt, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	SetMaxIdleConns(n int)
	SetMaxOpenConns(n int)
}

func Log

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

func Wrap

func Wrap(sqlDB *sql.DB) Conn

func WrapWithError

func WrapWithError(sqlDB *sql.DB, err error) (Conn, error)

type DB

type DB interface {
	GetTeams() ([]SavedTeam, error)
	CreateTeam(team Team) (SavedTeam, error)
	CreateDefaultTeamIfNotExists() error
	DeleteTeamByName(teamName string) error

	GetAllStartedBuilds() ([]Build, error)
	GetPublicBuilds(page Page) ([]Build, Pagination, error)

	FindJobIDForBuild(buildID int) (int, bool, error)

	CreatePipe(pipeGUID string, url string, teamName string) error
	GetPipe(pipeGUID string) (Pipe, error)

	GetTaskLock(logger lager.Logger, taskName string) (lock.Lock, bool, error)

	DeleteBuildEventsByBuildIDs(buildIDs []int) error
}

type Dashboard

type Dashboard []DashboardJob

type DashboardJob

type DashboardJob struct {
	Job SavedJob

	FinishedBuild Build
	NextBuild     Build
}

type EventSource

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

type FirstLoggedBuildIDDecreasedError

type FirstLoggedBuildIDDecreasedError struct {
	Job   string
	OldID int
	NewID int
}

func (FirstLoggedBuildIDDecreasedError) Error

type GenericOAuth

type GenericOAuth struct {
	AuthURL       string            `json:"auth_url"`
	AuthURLParams map[string]string `json:"auth_url_params"`
	TokenURL      string            `json:"token_url"`
	ClientID      string            `json:"client_id"`
	ClientSecret  string            `json:"client_secret"`
	DisplayName   string            `json:"display_name"`
	Scope         string            `json:"scope"`
}

type GitHubAuth

type GitHubAuth struct {
	ClientID      string       `json:"client_id"`
	ClientSecret  string       `json:"client_secret"`
	Organizations []string     `json:"organizations"`
	Teams         []GitHubTeam `json:"teams"`
	Users         []string     `json:"users"`
	AuthURL       string       `json:"auth_url"`
	TokenURL      string       `json:"token_url"`
	APIURL        string       `json:"api_url"`
}

type GitHubTeam

type GitHubTeam struct {
	OrganizationName string `json:"organization_name"`
	TeamName         string `json:"team_name"`
}

type Job

type Job struct {
	Name string
}

type MetadataField

type MetadataField struct {
	Name  string
	Value string
}

type MissingInputReasons

type MissingInputReasons map[string]string

func (MissingInputReasons) RegisterNoVersions

func (mir MissingInputReasons) RegisterNoVersions(inputName string)

func (MissingInputReasons) RegisterPassedConstraint

func (mir MissingInputReasons) RegisterPassedConstraint(inputName string)

func (MissingInputReasons) RegisterPinnedVersionUnavailable

func (mir MissingInputReasons) RegisterPinnedVersionUnavailable(inputName string, version string)

type NotificationsBus

type NotificationsBus interface {
	Listen(channel string) (chan bool, error)
	Notify(channel string) error
	Unlisten(channel string, notify chan bool) error
}

type Notifier

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

type Page

type Page struct {
	Since int // exclusive
	Until int // exclusive

	From int // inclusive
	To   int // inclusive

	Limit int
}

type Pagination

type Pagination struct {
	Previous *Page
	Next     *Page
}

type Pipe

type Pipe struct {
	ID       string
	URL      string
	TeamName string
}

type Pipeline

type Pipeline struct {
	Name    string
	Config  atc.Config
	Version ConfigVersion
}

type PipelineDB

type PipelineDB interface {
	Pipeline() SavedPipeline
	GetPipelineName() string
	GetPipelineID() int
	ScopedName(string) string
	TeamID() int
	Config() atc.Config
	ConfigVersion() ConfigVersion

	Reload() (bool, error)

	Pause() error
	Unpause() error
	IsPaused() (bool, error)
	IsPublic() bool
	UpdateName(string) error
	Destroy() error

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

	GetResource(resourceName string) (SavedResource, bool, error)
	GetResources() ([]SavedResource, bool, error)
	GetResourceType(resourceTypeName string) (SavedResourceType, bool, error)
	GetResourceVersions(resourceName string, page Page) ([]SavedVersionedResource, Pagination, bool, error)

	PauseResource(resourceName string) error
	UnpauseResource(resourceName string) error

	SaveResourceVersions(atc.ResourceConfig, []atc.Version) error
	SaveResourceTypeVersion(atc.ResourceType, atc.Version) error
	GetLatestVersionedResource(resourceName string) (SavedVersionedResource, bool, error)
	GetLatestEnabledVersionedResource(resourceName string) (SavedVersionedResource, bool, error)
	EnableVersionedResource(versionedResourceID int) error
	DisableVersionedResource(versionedResourceID int) error
	SetResourceCheckError(resource SavedResource, err error) error
	AcquireResourceTypeCheckingLock(logger lager.Logger, resourceType SavedResourceType, length time.Duration, immediate bool) (lock.Lock, bool, error)

	GetJobs() ([]SavedJob, error)
	GetJob(job string) (SavedJob, bool, error)
	PauseJob(job string) error
	UnpauseJob(job string) error
	SetMaxInFlightReached(string, bool) error
	UpdateFirstLoggedBuildID(job string, newFirstLoggedBuildID int) error

	GetJobFinishedAndNextBuild(job string) (Build, Build, error)

	GetJobBuilds(job string, page Page) ([]Build, Pagination, error)
	GetAllJobBuilds(job string) ([]Build, error)

	GetJobBuild(job string, build string) (Build, bool, error)
	CreateJobBuild(job string) (Build, error)
	EnsurePendingBuildExists(jobName string) error
	GetPendingBuildsForJob(jobName string) ([]Build, error)
	GetAllPendingBuilds() (map[string][]Build, error)
	UseInputsForBuild(buildID int, inputs []BuildInput) error

	LoadVersionsDB() (*algorithm.VersionsDB, error)
	GetVersionedResourceByVersion(atcVersion atc.Version, resourceName string) (SavedVersionedResource, bool, error)
	SaveIndependentInputMapping(inputMapping algorithm.InputMapping, jobName string) error
	GetIndependentBuildInputs(jobName string) ([]BuildInput, error)
	SaveNextInputMapping(inputMapping algorithm.InputMapping, jobName string) error
	GetNextBuildInputs(jobName string) ([]BuildInput, bool, error)
	DeleteNextInputMapping(jobName string) error

	GetRunningBuildsBySerialGroup(jobName string, serialGroups []string) ([]Build, error)
	GetNextPendingBuildBySerialGroup(jobName string, serialGroups []string) (Build, bool, error)

	UpdateBuildToScheduled(buildID int) (bool, error)
	SaveInput(buildID int, input BuildInput) (SavedVersionedResource, error)
	SaveOutput(buildID int, vr VersionedResource, explicit bool) (SavedVersionedResource, error)
	GetBuildsWithVersionAsInput(versionedResourceID int) ([]Build, error)
	GetBuildsWithVersionAsOutput(versionedResourceID int) ([]Build, error)

	GetDashboard() (Dashboard, atc.GroupConfigs, error)

	Expose() error
	Hide() error
}

type PipelineDBFactory

type PipelineDBFactory interface {
	Build(pipeline SavedPipeline) PipelineDB
}

type PipelinePausedState

type PipelinePausedState string
const (
	PipelinePaused   PipelinePausedState = "paused"
	PipelineUnpaused PipelinePausedState = "unpaused"
	PipelineNoChange PipelinePausedState = "nochange"
)

func (PipelinePausedState) Bool

func (state PipelinePausedState) Bool() *bool

type PipelinesDB

type PipelinesDB interface {
	GetAllPublicPipelines() ([]SavedPipeline, error)
}

type Resource

type Resource struct {
	Name string
}

type ResourceCacheIdentifier

type ResourceCacheIdentifier struct {
	ResourceVersion atc.Version
	ResourceHash    string
}

type ResourceNotFoundError

type ResourceNotFoundError struct {
	Name string
}

func (ResourceNotFoundError) Error

func (e ResourceNotFoundError) Error() string

type ResourceTypeNotFoundError

type ResourceTypeNotFoundError struct {
	Name string
}

func (ResourceTypeNotFoundError) Error

type SQLDB

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

func NewSQL

func NewSQL(
	sqldbConnection Conn,
	bus *notificationsBus,
	lockFactory lock.LockFactory,
) *SQLDB

func (*SQLDB) AcquireContainerCreatingLock

func (db *SQLDB) AcquireContainerCreatingLock(logger lager.Logger, containerID int) (lock.Lock, bool, error)

func (*SQLDB) AcquireVolumeCreatingLock

func (db *SQLDB) AcquireVolumeCreatingLock(logger lager.Logger, volumeID int) (lock.Lock, bool, error)

func (*SQLDB) CreateDefaultTeamIfNotExists

func (db *SQLDB) CreateDefaultTeamIfNotExists() error

func (*SQLDB) CreatePipe

func (db *SQLDB) CreatePipe(pipeGUID string, url string, teamName string) error

func (*SQLDB) CreateTeam

func (db *SQLDB) CreateTeam(team Team) (SavedTeam, error)

func (*SQLDB) DeleteBuildEventsByBuildIDs

func (db *SQLDB) DeleteBuildEventsByBuildIDs(buildIDs []int) error

func (*SQLDB) DeleteTeamByName

func (db *SQLDB) DeleteTeamByName(teamName string) error

func (*SQLDB) FindJobIDForBuild

func (db *SQLDB) FindJobIDForBuild(buildID int) (int, bool, error)

func (*SQLDB) GetAllPipelines

func (db *SQLDB) GetAllPipelines() ([]SavedPipeline, error)

func (*SQLDB) GetAllPublicPipelines

func (db *SQLDB) GetAllPublicPipelines() ([]SavedPipeline, error)

func (*SQLDB) GetAllStartedBuilds

func (db *SQLDB) GetAllStartedBuilds() ([]Build, error)

func (*SQLDB) GetBuildByID

func (db *SQLDB) GetBuildByID(buildID int) (Build, bool, error)

func (*SQLDB) GetPipe

func (db *SQLDB) GetPipe(pipeGUID string) (Pipe, error)

func (*SQLDB) GetPipelineByID

func (db *SQLDB) GetPipelineByID(pipelineID int) (SavedPipeline, error)

func (*SQLDB) GetPublicBuilds

func (db *SQLDB) GetPublicBuilds(page Page) ([]Build, Pagination, error)

func (*SQLDB) GetTaskLock

func (db *SQLDB) GetTaskLock(logger lager.Logger, taskName string) (lock.Lock, bool, error)

func (*SQLDB) GetTeams

func (db *SQLDB) GetTeams() ([]SavedTeam, error)

type SavedJob

type SavedJob struct {
	ID                 int
	Paused             bool
	PipelineName       string
	FirstLoggedBuildID int
	TeamID             int
	Config             atc.JobConfig
	Job
}

type SavedPipeline

type SavedPipeline struct {
	ID       int
	Paused   bool
	Public   bool
	TeamID   int
	TeamName string

	Pipeline
}

type SavedResource

type SavedResource struct {
	ID           int
	CheckError   error
	Paused       bool
	PipelineName string
	Config       atc.ResourceConfig
	Resource
}

func (SavedResource) FailingToCheck

func (r SavedResource) FailingToCheck() bool

type SavedResourceType

type SavedResourceType struct {
	ID      int
	Name    string
	Type    string
	Version Version
	Config  atc.ResourceType
}

type SavedTeam

type SavedTeam struct {
	ID int
	Team
}

type SavedVersionedResource

type SavedVersionedResource struct {
	ID int

	Enabled bool

	ModifiedTime time.Time

	VersionedResource

	CheckOrder int
}

type SavedVersionedResources

type SavedVersionedResources []SavedVersionedResource

type Status

type Status string
const (
	StatusPending   Status = "pending"
	StatusStarted   Status = "started"
	StatusAborted   Status = "aborted"
	StatusSucceeded Status = "succeeded"
	StatusFailed    Status = "failed"
	StatusErrored   Status = "errored"
)

type Team

type Team struct {
	Name  string
	Admin bool

	BasicAuth    *BasicAuth    `json:"basic_auth"`
	GitHubAuth   *GitHubAuth   `json:"github_auth"`
	UAAAuth      *UAAAuth      `json:"uaa_auth"`
	GenericOAuth *GenericOAuth `json:"genericoauth_auth"`
}

type TeamDB

type TeamDB interface {
	GetPipelines() ([]SavedPipeline, error)
	GetPublicPipelines() ([]SavedPipeline, error)
	GetPrivateAndAllPublicPipelines() ([]SavedPipeline, error)

	GetPipelineByName(pipelineName string) (SavedPipeline, bool, error)

	OrderPipelines([]string) error

	GetTeam() (SavedTeam, bool, error)
	UpdateBasicAuth(basicAuth *BasicAuth) (SavedTeam, error)
	UpdateGitHubAuth(gitHubAuth *GitHubAuth) (SavedTeam, error)
	UpdateUAAAuth(uaaAuth *UAAAuth) (SavedTeam, error)
	UpdateGenericOAuth(genericOAuth *GenericOAuth) (SavedTeam, error)

	GetConfig(pipelineName string) (atc.Config, atc.RawConfig, ConfigVersion, error)
	SaveConfigToBeDeprecated(string, atc.Config, ConfigVersion, PipelinePausedState) (SavedPipeline, bool, error)

	CreateOneOffBuild() (Build, error)
	GetPrivateAndPublicBuilds(page Page) ([]Build, Pagination, error)
}

type TeamDBFactory

type TeamDBFactory interface {
	GetTeamDB(string) TeamDB
}

func NewTeamDBFactory

func NewTeamDBFactory(conn Conn, bus *notificationsBus, lockFactory lock.LockFactory) TeamDBFactory

type Tx

type Tx interface {
	Commit() error
	Exec(query string, args ...interface{}) (sql.Result, error)
	Prepare(query string) (*sql.Stmt, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	Rollback() error
	Stmt(stmt *sql.Stmt) *sql.Stmt
}

type UAAAuth

type UAAAuth struct {
	ClientID     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret"`
	AuthURL      string   `json:"auth_url"`
	TokenURL     string   `json:"token_url"`
	CFSpaces     []string `json:"cf_spaces"`
	CFURL        string   `json:"cf_url"`
	CFCACert     string   `json:"cf_ca_cert"`
}

type Version

type Version map[string]string

type VersionedResource

type VersionedResource struct {
	Resource   string
	Type       string
	Version    Version
	Metadata   []MetadataField
	PipelineID int
}

Directories

Path Synopsis
This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter
This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter
lockfakes
This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter
This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter
migrationsfakes
This file was generated by counterfeiter
This file was generated by counterfeiter

Jump to

Keyboard shortcuts

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