entitystore

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FilterVerbIn tests containment
	FilterVerbIn Verb = "in"

	// FilterVerbEqual tests equality
	FilterVerbEqual Verb = "equal"

	// FilterVerbBefore tests two time.Time
	FilterVerbBefore Verb = "before"

	// FilterVerbAfter tests two time.Time
	FilterVerbAfter Verb = "after"

	// FilterScopeField defines that the subject is a BaseEntity field
	FilterScopeField Scope = "field"

	// FilterScopeTag defines that the subject is a BaseEntity Tag
	FilterScopeTag Scope = "tag"

	// FilterScopeExtra defines that the subject is a extra field extended from BaseEntity
	FilterScopeExtra Scope = "extra"
)

Variables

This section is empty.

Functions

func GetDataType

func GetDataType(entity Entity) string

GetDataType returns the data type of the given entity

func IsUniqueViolation added in v0.1.13

func IsUniqueViolation(err error) bool

IsUniqueViolation is a helper function to safely return UniqueViolation if available

Types

type BackendConfig added in v0.1.13

type BackendConfig struct {
	Backend  string
	Address  string
	Username string
	Password string
	Bucket   string
}

BackendConfig list a set of configuration values for backend DB

type BaseEntity

type BaseEntity struct {
	ID             string          `json:"id"`
	Name           string          `json:"name"`
	OrganizationID string          `json:"organizationId"`
	CreatedTime    time.Time       `json:"createdTime,omitempty"`
	ModifiedTime   time.Time       `json:"modifiedTime,omitempty"`
	Revision       uint64          `json:"revision"`
	Version        uint64          `json:"version"`
	Spec           Spec            `json:"state"`
	Status         Status          `json:"status"`
	Reason         Reason          `json:"reason"`
	Tags           Tags            `json:"tags"`
	Delete         bool            `json:"delete"`
	Context        context.Context `json:"-"`
}

BaseEntity is the base struct for all stored objects

func (*BaseEntity) GetCreateTime added in v0.1.13

func (e *BaseEntity) GetCreateTime() time.Time

GetCreateTime gets the entity creation time

func (*BaseEntity) GetDelete added in v0.1.13

func (e *BaseEntity) GetDelete() bool

GetDelete gets the entity delete status

func (*BaseEntity) GetID added in v0.1.13

func (e *BaseEntity) GetID() string

GetID gets the entity ID

func (*BaseEntity) GetModifiedTime

func (e *BaseEntity) GetModifiedTime() time.Time

GetModifiedTime gets the entity modification time

func (*BaseEntity) GetName

func (e *BaseEntity) GetName() string

GetName retreives the entity name

func (*BaseEntity) GetOrganizationID added in v0.1.13

func (e *BaseEntity) GetOrganizationID() string

GetOrganizationID gets the entity organizationID

func (*BaseEntity) GetReason added in v0.1.13

func (e *BaseEntity) GetReason() Reason

GetReason gets the entity reason

func (*BaseEntity) GetRevision

func (e *BaseEntity) GetRevision() uint64

GetRevision gets the entity revision

func (*BaseEntity) GetSpec added in v0.1.13

func (e *BaseEntity) GetSpec() Spec

GetSpec gets the entity spec

func (*BaseEntity) GetStatus

func (e *BaseEntity) GetStatus() Status

GetStatus gets the entity status

func (*BaseEntity) GetTags

func (e *BaseEntity) GetTags() Tags

GetTags retreives the entity tags

func (*BaseEntity) GetVersion added in v0.1.13

func (e *BaseEntity) GetVersion() uint64

GetVersion gets the entity version

func (*BaseEntity) SetDelete added in v0.1.13

func (e *BaseEntity) SetDelete(delete bool)

SetDelete sets the entity delete status

func (*BaseEntity) SetReason added in v0.1.13

func (e *BaseEntity) SetReason(reason Reason)

SetReason sets the entity reason

func (*BaseEntity) SetSpec added in v0.1.13

func (e *BaseEntity) SetSpec(spec Spec)

SetSpec sets the entity spec

func (*BaseEntity) SetStatus added in v0.1.13

func (e *BaseEntity) SetStatus(status Status)

SetStatus sets the entity status

func (*BaseEntity) SetTags added in v0.1.13

func (e *BaseEntity) SetTags(tags Tags)

SetTags sets the entity tags

type Entity

type Entity interface {
	SetSpec(Spec)
	SetStatus(Status)
	SetReason(Reason)
	SetTags(Tags)
	SetDelete(bool)

	GetID() string
	GetName() string
	GetOrganizationID() string
	GetCreateTime() time.Time
	GetModifiedTime() time.Time
	GetRevision() uint64
	GetVersion() uint64
	GetSpec() Spec
	GetStatus() Status
	GetReason() Reason
	GetTags() Tags
	GetDelete() bool
	// contains filtered or unexported methods
}

Entity is the base interface for all stored objects

type EntityStore

type EntityStore interface {
	// Add adds new entities to the store
	Add(ctx context.Context, entity Entity) (id string, err error)
	// Update updates existing entities to the store
	Update(ctx context.Context, lastRevision uint64, entity Entity) (revision int64, err error)
	// GetById gets a single entity by key from the store
	Get(ctx context.Context, organizationID string, key string, opts Options, entity Entity) error
	// Find is like get, but returns a bool to indicate whether the entity exists (or was "found")
	Find(ctx context.Context, organizationID string, key string, opts Options, entity Entity) (bool, error)
	// List fetches a list of entities of a single data type satisfying the filter.
	// entities is a placeholder for results and must be a pointer to an empty slice of the desired entity type.
	List(ctx context.Context, organizationID string, opts Options, entities interface{}) error
	// Delete deletes a single entity from the store.
	Delete(ctx context.Context, organizationID string, id string, entity Entity) error
	// SoftDelete sets the deleted flag and status, but does not actually delete the entity from the store.
	SoftDelete(ctx context.Context, entity Entity) error
	// UpdateWithError is used by entity handlers to save changes and/or error status
	// e.g. `defer func() { h.store.UpdateWithError(e, err) }()`
	UpdateWithError(ctx context.Context, e Entity, err error)
	// ListOrgIds fetches a list of organization IDs
	ListOrgIDs(ctx context.Context) ([]string, error)
}

EntityStore is a wrapper around libkv and provides convenience methods to serializing and deserializing objects

func NewFromBackend added in v0.1.13

func NewFromBackend(config BackendConfig) (EntityStore, error)

NewFromBackend creates new entity store created from a backend DB

type Filter

type Filter interface {
	Add(...FilterStat) Filter
	FilterStats() []FilterStat
}

Filter defines a set of criteria to filter entities when listing

func FilterByApplication added in v0.1.13

func FilterByApplication(app string) Filter

FilterByApplication creates a filter, which will filter based on the supplied application name

func FilterEverything added in v0.1.13

func FilterEverything() Filter

FilterEverything creates a filter, which will matches all entities

func FilterExists added in v0.1.13

func FilterExists() Filter

FilterExists creates a filter, which will filter entities with Delete=true

type FilterStat added in v0.1.13

type FilterStat struct {
	Scope   Scope
	Subject string
	Verb    Verb
	Object  interface{}
}

FilterStat (Filter Statement) defines one filter criterion

func FilterStatByApplication added in v0.1.13

func FilterStatByApplication(name string) FilterStat

FilterStatByApplication defines one filter statement by application name

type Options added in v0.1.13

type Options struct {
	Filter Filter
}

Options defines a set of query options for list and get

type Reason added in v0.1.13

type Reason []string

Reason represents the reason of current status

func (*Reason) Scan added in v0.1.13

func (v *Reason) Scan(src interface{}) error

Scan implements interface sql.Scanner

func (Reason) Value added in v0.1.13

func (v Reason) Value() (driver.Value, error)

Value implements interface driver.Valuer

type Scope added in v0.1.13

type Scope string

Scope describes which scope this filter is applied on

type Spec

type Spec map[string]string

Spec represents the desired state/status

func (*Spec) Scan added in v0.1.13

func (v *Spec) Scan(src interface{}) error

Scan implements interface sql.Scanner

func (Spec) Value added in v0.1.13

func (v Spec) Value() (driver.Value, error)

Value implements interface driver.Valuer

type Status

type Status string

Status represents the current state

const (

	// StatusINITIALIZED object is INITIALIZED
	//	this status is used by image manager
	StatusINITIALIZED Status = "INITIALIZED"

	// StatusCREATING object is CREATING
	// it is not a guarantee that the object is also created and ready in the underlying driver
	// should wait until the READY state to use the object
	StatusCREATING Status = "CREATING"

	// StatusREADY object is READY to be used
	StatusREADY Status = "READY"

	// StatusUPDATING object is UPDATING
	// it is not a guarantee that changes will be reflected by the underlying driver
	// when updated, will transfer to READY state
	StatusUPDATING Status = "UPDATING"

	// StatusDELETING object is DELETING
	// it is not a guarantee that it has been deleted from the underlying driver
	// user should not reuse the object name until it is transfered to DELETED state
	StatusDELETING Status = "DELETING"

	// StatusDELETED object is DELETED
	// Note for dispatch team:
	// leave this here, reserved for when we use UUID instead of entity name
	StatusDELETED Status = "DELETED"

	// StatusERROR unexpected error state
	// you should not use the object until the state is tranfered to READY
	// or the object is deleted
	StatusERROR Status = "ERROR"

	// StatusMISSING temporary error state
	// Used when external resources cannot be found
	StatusMISSING Status = "MISSING"

	// StatusUNKNOWN is not an error, just that the current status is inderminate
	StatusUNKNOWN Status = "UNKNOWN"
)

type Tags

type Tags map[string]string

Tags are filterable metadata as key pairs

func (*Tags) Scan added in v0.1.13

func (v *Tags) Scan(src interface{}) error

Scan implements interface sql.Scanner

func (Tags) Value added in v0.1.13

func (v Tags) Value() (driver.Value, error)

Value implements interface driver.Valuer

type Verb added in v0.1.13

type Verb string

Verb describe the filter verb

Jump to

Keyboard shortcuts

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