datastore

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound        = errors.New("not found")
	ErrInvalidArgument = errors.New("invalid argument")
	ErrAlreadyExists   = errors.New("already exists")
	ErrInvalidCursor   = errors.New("invalid cursor")
	ErrIteratorDone    = errors.New("iterator is done")
	ErrInternal        = errors.New("internal")
	ErrUnimplemented   = errors.New("unimplemented")
)
View Source
var (
	DeploymentToPlannedUpdater = func(summary, statusReason, runningCommitHash, version string, stages []*model.PipelineStage) func(*model.Deployment) error {
		return func(d *model.Deployment) error {
			d.Status = model.DeploymentStatus_DEPLOYMENT_PLANNED
			d.Summary = summary
			d.StatusReason = statusReason
			d.RunningCommitHash = runningCommitHash
			d.Version = version
			d.Stages = stages
			return nil
		}
	}

	DeploymentStatusUpdater = func(status model.DeploymentStatus, statusReason string) func(*model.Deployment) error {
		return func(d *model.Deployment) error {
			d.Status = status
			d.StatusReason = statusReason
			return nil
		}
	}

	DeploymentToCompletedUpdater = func(status model.DeploymentStatus, statuses map[string]model.StageStatus, statusReason string, completedAt int64) func(*model.Deployment) error {
		return func(d *model.Deployment) error {
			if !model.IsCompletedDeployment(status) {
				return fmt.Errorf("deployment status %s is not completed value: %w", status, ErrInvalidArgument)
			}

			d.Status = status
			d.StatusReason = statusReason
			d.CompletedAt = completedAt
			for i := range d.Stages {
				stageID := d.Stages[i].Id
				if status, ok := statuses[stageID]; ok {
					d.Stages[i].Status = status
				}
			}
			return nil
		}
	}

	StageStatusChangedUpdater = func(stageID string, status model.StageStatus, statusReason string, requires []string, visible bool, retriedCount int32, completedAt int64) func(*model.Deployment) error {
		return func(d *model.Deployment) error {
			for _, s := range d.Stages {
				if s.Id == stageID {
					s.Status = status
					s.StatusReason = statusReason
					if len(requires) > 0 {
						s.Requires = requires
					}
					s.Visible = visible
					s.RetriedCount = retriedCount
					s.CompletedAt = completedAt
					return nil
				}
			}
			return fmt.Errorf("stage id %s not found: %w", stageID, ErrInvalidArgument)
		}
	}
)
View Source
var (
	CommandHandledUpdater = func(status model.CommandStatus, metadata map[string]string, handledAt int64) func(*model.Command) error {
		return func(cmd *model.Command) error {
			cmd.Status = status
			cmd.Metadata = metadata
			cmd.HandledAt = handledAt
			return nil
		}
	}
)
View Source
var (
	PipedMetadataUpdater = func(cloudProviders []*model.Piped_CloudProvider, repoIDs []string, version string, startedAt int64) func(piped *model.Piped) error {
		return func(piped *model.Piped) error {
			piped.CloudProviders = cloudProviders
			piped.RepositoryIds = repoIDs
			piped.Version = version
			piped.StartedAt = startedAt
			return nil
		}
	}
)

Functions

This section is empty.

Types

type ApplicationStore

type ApplicationStore interface {
	AddApplication(ctx context.Context, app *model.Application) error
	EnableApplication(ctx context.Context, id string) error
	DisableApplication(ctx context.Context, id string) error
	GetApplication(ctx context.Context, id string) (*model.Application, error)
	ListApplications(ctx context.Context, opts ListOptions) ([]*model.Application, error)
	UpdateApplication(ctx context.Context, id string, updater func(*model.Application) error) error
	PutApplicationSyncState(ctx context.Context, id string, syncState *model.ApplicationSyncState) error
	PutApplicationMostRecentDeployment(ctx context.Context, id string, status model.DeploymentStatus, deployment *model.ApplicationDeploymentReference) error
}

func NewApplicationStore

func NewApplicationStore(ds DataStore) ApplicationStore

type CommandStore

type CommandStore interface {
	AddCommand(ctx context.Context, cmd *model.Command) error
	UpdateCommand(ctx context.Context, id string, updater func(piped *model.Command) error) error
	ListCommands(ctx context.Context, opts ListOptions) ([]*model.Command, error)
	GetCommand(ctx context.Context, id string) (*model.Command, error)
}

func NewCommandStore

func NewCommandStore(ds DataStore) CommandStore

type DataStore

type DataStore interface {
	// Find finds the documents matched given criteria.
	Find(ctx context.Context, kind string, opts ListOptions) (Iterator, error)
	// Get gets one document specified with ID, and unmarshal it to typed struct.
	// If the document can not be found in datastore, ErrNotFound will be returned.
	Get(ctx context.Context, kind, id string, entity interface{}) error
	// Create saves a new entity to the datastore.
	// If an entity with the same ID is already existing, ErrAlreadyExists will be returned.
	Create(ctx context.Context, kind, id string, entity interface{}) error
	// Put saves the entity into the datastore with a given id and kind.
	// Put does not check the existence of the entity with same ID.
	Put(ctx context.Context, kind, id string, entity interface{}) error
	// Update updates an existing entity in the datastore.
	// If updating entity was not found in the datastore, ErrNotFound will be returned.
	Update(ctx context.Context, kind, id string, factory Factory, updater Updater) error
	// Close closes datastore resources held by the client.
	Close() error
}

type DeploymentStore

type DeploymentStore interface {
	AddDeployment(ctx context.Context, d *model.Deployment) error
	UpdateDeployment(ctx context.Context, id string, updater func(*model.Deployment) error) error
	PutDeploymentMetadata(ctx context.Context, id string, metadata map[string]string) error
	PutDeploymentStageMetadata(ctx context.Context, deploymentID, stageID string, metadata map[string]string) error
	ListDeployments(ctx context.Context, opts ListOptions) ([]*model.Deployment, error)
	GetDeployment(ctx context.Context, id string) (*model.Deployment, error)
}

func NewDeploymentStore

func NewDeploymentStore(ds DataStore) DeploymentStore

type EnvironmentStore

type EnvironmentStore interface {
	AddEnvironment(ctx context.Context, env *model.Environment) error
	GetEnvironment(ctx context.Context, id string) (*model.Environment, error)
	ListEnvironments(ctx context.Context, opts ListOptions) ([]*model.Environment, error)
}

func NewEnvironmentStore

func NewEnvironmentStore(ds DataStore) EnvironmentStore

type Factory

type Factory func() interface{}

type Iterator

type Iterator interface {
	Next(dst interface{}) error
	Cursor() (string, error)
}

type ListFilter

type ListFilter struct {
	Field    string
	Operator string
	Value    interface{}
}

type ListOptions

type ListOptions struct {
	Page     int
	PageSize int
	Filters  []ListFilter
	Orders   []Order
	Cursor   string
}

type Order

type Order struct {
	Field     string
	Direction OrderDirection
}

type OrderDirection

type OrderDirection int
const (
	// Asc sorts results from smallest to largest.
	Asc OrderDirection = iota + 1
	// Desc sorts results from largest to smallest.
	Desc
)

type PipedStatsStore

type PipedStatsStore interface {
	AddPipedStats(ctx context.Context, ps *model.PipedStats) error
	ListPipedStatss(ctx context.Context, opts ListOptions) ([]model.PipedStats, error)
}

func NewPipedStatsStore

func NewPipedStatsStore(ds DataStore) PipedStatsStore

type PipedStore

type PipedStore interface {
	AddPiped(ctx context.Context, piped *model.Piped) error
	GetPiped(ctx context.Context, id string) (*model.Piped, error)
	ListPipeds(ctx context.Context, opts ListOptions) ([]*model.Piped, error)
	UpdatePiped(ctx context.Context, id string, updater func(piped *model.Piped) error) error
	EnablePiped(ctx context.Context, id string) error
	DisablePiped(ctx context.Context, id string) error
	UpdateKeyHash(ctx context.Context, id, keyhash string) error
}

func NewPipedStore

func NewPipedStore(ds DataStore) PipedStore

type ProjectStore

type ProjectStore interface {
	AddProject(ctx context.Context, proj *model.Project) error
	GetProject(ctx context.Context, id string) (*model.Project, error)
	ListProjects(ctx context.Context, opts ListOptions) ([]model.Project, error)
}

func NewProjectStore

func NewProjectStore(ds DataStore) ProjectStore

type Updater

type Updater func(interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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