store

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFoundOrDirty = errors.New("failed to find requested document. It is possible that this operation was a Dirty Write. Consider fetching the latest version of the requested document to repeat the read-write cycle")

ErrNotFoundOrDirty is returned when the requested document couldn't be found inside the database or a Dirty Write occurred.

Functions

func ConvertToGRPC

func ConvertToGRPC(cfg *Config) (*spec.Config, error)

ConvertToGRPC converts from database representation to GRPC representation. For clusters, it mimics the GRPC unmarshalling style where if a field was not set within a message it will be nil instead of a zero value for that type.

func ConvertToGRPCEvents

func ConvertToGRPCEvents(w Events) (*spec.Events, error)

ConvertToGRPCEvents converts the database representation of events to GRPC.

func ConvertToGRPCTaskEvent

func ConvertToGRPCTaskEvent(te TaskEvent) (*spec.TaskEvent, error)

func ConvertToGRPCWorkflow

func ConvertToGRPCWorkflow(w Workflow) *spec.Workflow

ConvertToGRPCWorkflow converts the database representation of the workflow state to GRPC.

Types

type ClusterState

type ClusterState struct {
	Current Clusters `bson:"current"`
	Desired Clusters `bson:"desired"`
	Events  Events   `bson:"events"`
	State   Workflow `bson:"state"`
}

type Clusters

type Clusters struct {
	K8s           []byte `bson:"k8s"`
	LoadBalancers []byte `bson:"loadBalancers"`
}

type Config

type Config struct {
	Version  uint64                   `bson:"version"`
	Name     string                   `bson:"name"`
	K8SCtx   KubernetesContext        `bson:"kubernetesContext"`
	Manifest Manifest                 `bson:"manifest"`
	Clusters map[string]*ClusterState `bson:"clusters"`
}

func ConvertFromGRPC

func ConvertFromGRPC(cfg *spec.Config) (*Config, error)

ConvertFromGRPC converts the grpc representation to the database representation.

type Events

type Events struct {
	TaskEvents []TaskEvent `bson:"taskEvents"`
	TTL        int32       `bson:"ttl"`
	Autoscaled bool        `bson:"autoscaled"`
}

func ConvertFromGRPCEvents

func ConvertFromGRPCEvents(w *spec.Events) (Events, error)

ConvertFromGRPCEvents converts the events data from GRPC to the database representation.

type InMemoryStore

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

func NewInMemoryStore

func NewInMemoryStore() *InMemoryStore

func (*InMemoryStore) Close

func (i *InMemoryStore) Close() error

func (*InMemoryStore) CreateConfig

func (i *InMemoryStore) CreateConfig(_ context.Context, config *Config) error

func (*InMemoryStore) DeleteConfig

func (i *InMemoryStore) DeleteConfig(_ context.Context, name string, version uint64) error

func (*InMemoryStore) GetConfig

func (i *InMemoryStore) GetConfig(_ context.Context, name string) (*Config, error)

func (*InMemoryStore) HealthCheck

func (i *InMemoryStore) HealthCheck() error

func (*InMemoryStore) ListConfigs

func (i *InMemoryStore) ListConfigs(_ context.Context, filter *ListFilter) ([]*Config, error)

func (*InMemoryStore) MarkForDeletion

func (i *InMemoryStore) MarkForDeletion(_ context.Context, name string, version uint64) error

func (*InMemoryStore) UpdateConfig

func (i *InMemoryStore) UpdateConfig(_ context.Context, config *Config) error

type KubernetesContext

type KubernetesContext struct {
	Name      string `bson:"name"`
	Namespace string `bson:"namespace"`
}

type ListFilter

type ListFilter struct {
	ManifestState []string
}

ListFilter wraps supported filters for listing configs.

type Manifest

type Manifest struct {
	Raw                 string `bson:"raw"`
	Checksum            []byte `bson:"checksum"`
	LastAppliedChecksum []byte `bson:"lastAppliedChecksum"`
	State               string `bson:"state"`
}

type Mongo

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

func NewMongoClient

func NewMongoClient(ctx context.Context, uri string) (*Mongo, error)

func (*Mongo) Close

func (m *Mongo) Close() error

func (*Mongo) CreateConfig

func (m *Mongo) CreateConfig(ctx context.Context, config *Config) error

func (*Mongo) DeleteConfig

func (m *Mongo) DeleteConfig(ctx context.Context, name string, version uint64) error

func (*Mongo) GetConfig

func (m *Mongo) GetConfig(ctx context.Context, name string) (*Config, error)

func (*Mongo) HealthCheck

func (m *Mongo) HealthCheck() error

func (*Mongo) Init

func (m *Mongo) Init() error

func (*Mongo) ListConfigs

func (m *Mongo) ListConfigs(ctx context.Context, filter *ListFilter) ([]*Config, error)

func (*Mongo) MarkForDeletion

func (m *Mongo) MarkForDeletion(ctx context.Context, name string, version uint64) error

func (*Mongo) UpdateConfig

func (m *Mongo) UpdateConfig(ctx context.Context, config *Config) error

type Store

type Store interface {
	io.Closer
	healthcheck.HealthChecker

	// CreateConfig creates a new config. It is up to the application logic to determine if the
	// config already exists or not. On conflict, the creation will error out. The Version field
	// of the config will always be overwritten to 0 as new configs always start with a version of 0.
	CreateConfig(ctx context.Context, config *Config) error

	// UpdateConfig updates an existing config in the database with the new supplied data. If there is no document
	// that matches the Config.Name and Config.Version the ErrNotFoundOrDirty err is returned. It is up to the application
	// code to determine, if the write was Dirty (i.e. outdated Document version used) or there is no such document with the
	// requested Config.Name and Config.Version combination. Before updating the document, a higher document version
	// number by 1 will replace the supplied number in Config.Version (i.e. Config.Version += 1).
	UpdateConfig(ctx context.Context, config *Config) error

	// GetConfig queries the document with the Config.Name. If no such document is found the ErrNotFoundOrDirty err
	// is returned. In this case it always will be the case that the document is absent. This can be used by the application
	// code to determine an absent document or Dirty Write.
	GetConfig(ctx context.Context, name string) (*Config, error)

	// ListConfigs queries all documents stored that satisfy the passed in ListFilter.
	ListConfigs(ctx context.Context, filter *ListFilter) ([]*Config, error)

	// DeleteConfig will delete the document with the requested Config.Name and Config.Version combination.
	// If No documents with the given combination were deleted the ErrNotFoundOrDirty err is returned. It is up
	// to the application code to handle the case in which a Dirty Write occurred or the document does not exist.
	DeleteConfig(ctx context.Context, name string, version uint64) error

	// MarkForDeletion will mark the infrastructure in the document with the requested Config.Name and Config.Version for
	// deletion. If No documents with the given combination were marked for deletion the ErrNotFoundOrDirty err is returned. It is up
	// to the application code to handle the case in which a Dirty Write occurred or the document does not exist.
	MarkForDeletion(ctx context.Context, name string, version uint64) error
}

type TaskEvent

type TaskEvent struct {
	Id          string `bson:"id"`
	Timestamp   string `bson:"timestamp"`
	Event       string `bson:"event"`
	Task        []byte `bson:"task"`
	Description string `bson:"description"`
	OnError     []byte `bson:"onError"`
}

type Workflow

type Workflow struct {
	Status      string `bson:"status"`
	Stage       string `bson:"stage"`
	Description string `bson:"description"`
	Timestamp   string `bson:"timestamp"`
}

func ConvertFromGRPCWorkflow

func ConvertFromGRPCWorkflow(w *spec.Workflow) Workflow

ConvertFromGRPCWorkflow converts the workflow state data from GRPC to the database representation.

Jump to

Keyboard shortcuts

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