db

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: May 8, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The status of one table
	TableStatusCreating = "CREATING"
	TableStatusUpdating = "UPDATING"
	TableStatusDeleting = "DELETING"
	TableStatusActive   = "ACTIVE"

	ClusterName  = "ClusterName"
	DeviceName   = "DeviceName"
	ServiceName  = "ServiceName"
	ServiceUUID  = "ServiceUUID"
	Revision     = "Revision"
	LastModified = "LastModified"

	ServiceMeta = "ServiceMeta"
	ServiceSpec = "ServiceSpec"

	MemberName = "MemberName"
	MemberMeta = "MemberMeta"
	MemberSpec = "MemberSpec"

	ConfigFileID   = "ConfigFileID"
	ConfigFileMeta = "ConfigFileMeta"
	ConfigFileSpec = "ConfigFileSpec"

	StaticIP     = "StaticIP"
	StaticIPSpec = "StaticIPSpec"
)
View Source
const (
	StrErrDBInternal               = "DB Internal Error"
	StrErrDBLimitExceeded          = "DB LimitExceeded"
	StrErrDBTableInUse             = "DB TableInUse"
	StrErrDBResourceNotFound       = "DB ResourceNotFound"
	StrErrDBTableNotFound          = "DB TableNotFound"
	StrErrDBRecordNotFound         = "DB RecordNotFound"
	StrErrDBConditionalCheckFailed = "DB ConditionalCheckFailed"
	StrErrDBInvalidRequest         = "DB invalid request"
)
View Source
const (
	// Service members need to be created in advance. So TaskID, ContainerInstanceID
	// and ServerInstanceID would be empty at service member creation.
	// set them to default values, this will help the later conditional update.
	DefaultTaskID              = "defaultTaskID"
	DefaultContainerInstanceID = "defaultContainerInstanceID"
	DefaultServerInstanceID    = "defaultServerInstanceID"
)

Variables

View Source
var (
	ErrDBInternal      = errors.New(StrErrDBInternal)
	ErrDBLimitExceeded = errors.New(StrErrDBLimitExceeded)
	ErrDBTableInUse    = errors.New(StrErrDBTableInUse)
	ErrDBTableNotFound = errors.New(StrErrDBTableNotFound)
	// ResourceNotFound is for dynamodb table.
	// Table which is being requested does not exist, or is too early in the CREATING state.
	// https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.Errors.html
	ErrDBResourceNotFound = errors.New(StrErrDBResourceNotFound)
	// RecordNotFound is when the key does not exist in db.
	ErrDBRecordNotFound         = errors.New(StrErrDBRecordNotFound)
	ErrDBConditionalCheckFailed = errors.New(StrErrDBConditionalCheckFailed)
	ErrDBInvalidRequest         = errors.New(StrErrDBInvalidRequest)
)

Define the possible errors returned by DB interfaces

Functions

func CopyConfigFile added in v0.9.6

func CopyConfigFile(c *common.ConfigFile) *common.ConfigFile

func CopyConfigFileMeta added in v0.9.6

func CopyConfigFileMeta(c *common.ConfigFileMeta) *common.ConfigFileMeta

func CopyConfigFileSpec added in v0.9.6

func CopyConfigFileSpec(c *common.ConfigFileSpec) *common.ConfigFileSpec

func CopyConfigs added in v0.9.6

func CopyConfigs(c1 []common.ConfigID) []common.ConfigID

func CopyDevice added in v0.9.6

func CopyDevice(d *common.Device) *common.Device

func CopyMemberMeta added in v0.9.6

func CopyMemberMeta(m *common.MemberMeta) *common.MemberMeta

func CopyMemberSpec added in v0.9.6

func CopyMemberSpec(m *common.MemberSpec) *common.MemberSpec

func CopyMemberVolumes added in v0.9.6

func CopyMemberVolumes(v *common.MemberVolumes) *common.MemberVolumes

func CopyResources added in v0.9.6

func CopyResources(r *common.Resources) *common.Resources

func CopyService added in v0.9.6

func CopyService(s *common.Service) *common.Service

func CopyServiceAttr added in v0.9.6

func CopyServiceAttr(s *common.ServiceAttr) *common.ServiceAttr

func CopyServiceMember added in v0.9.6

func CopyServiceMember(m *common.ServiceMember) *common.ServiceMember

func CopyServiceMeta added in v0.9.6

func CopyServiceMeta(s *common.ServiceMeta) *common.ServiceMeta

func CopyServiceSpec added in v0.9.6

func CopyServiceSpec(s *common.ServiceSpec) *common.ServiceSpec

func CopyServiceStaticIP added in v0.9.6

func CopyServiceStaticIP(s *common.ServiceStaticIP) *common.ServiceStaticIP

func CopyServiceVolume added in v0.9.6

func CopyServiceVolume(v *common.ServiceVolume) *common.ServiceVolume

func CopyServiceVolumes added in v0.9.6

func CopyServiceVolumes(v *common.ServiceVolumes) *common.ServiceVolumes

func CopyStaticIPSpec added in v0.9.6

func CopyStaticIPSpec(s *common.StaticIPSpec) *common.StaticIPSpec

func CreateConfigFile

func CreateConfigFile(serviceUUID string, fileID string, revision int64, meta *common.ConfigFileMeta, spec *common.ConfigFileSpec) *common.ConfigFile

func CreateConfigFileMeta added in v0.9.6

func CreateConfigFileMeta(fileName string, mtime int64) *common.ConfigFileMeta

func CreateConfigFileSpec added in v0.9.6

func CreateConfigFileSpec(fileMode uint32, fileMD5 string, content string) *common.ConfigFileSpec

func CreateDevice

func CreateDevice(cluster string, device string, service string) *common.Device

func CreateInitialConfigFile

func CreateInitialConfigFile(serviceUUID string, fileID string, fileName string, fileMode uint32, content string) *common.ConfigFile

func CreateInitialMemberSpec added in v0.9.6

func CreateInitialMemberSpec(az string, vols *common.MemberVolumes, staticIP string, configs []common.ConfigID) *common.MemberSpec

func CreateMemberMeta added in v0.9.6

func CreateMemberMeta(mtime int64, status string) *common.MemberMeta

func CreateMemberSpec added in v0.9.6

func CreateMemberSpec(az string, taskID string, containerInstanceID string, serverInstanceID string,
	vols *common.MemberVolumes, staticIP string, configs []common.ConfigID) *common.MemberSpec

func CreateNewConfigFile added in v0.9.6

func CreateNewConfigFile(c *common.ConfigFile, newFileID string, newContent string) *common.ConfigFile

func CreateService

func CreateService(cluster string, service string, serviceUUID string) *common.Service

func CreateServiceAttr

func CreateServiceAttr(serviceUUID string, revision int64, meta *common.ServiceMeta, spec *common.ServiceSpec) *common.ServiceAttr

func CreateServiceMember

func CreateServiceMember(serviceUUID string, memberName string, revision int64, meta *common.MemberMeta, spec *common.MemberSpec) *common.ServiceMember

func CreateServiceMeta added in v0.9.6

func CreateServiceMeta(cluster string, service string, mtime int64, serviceType string, status string) *common.ServiceMeta

func CreateServiceSpec added in v0.9.6

func CreateServiceSpec(replicas int64, res *common.Resources, registerDNS bool, domain string,
	hostedZoneID string, requireStaticIP bool, serviceCfgs []common.ConfigID,
	catalogServiceType string, vols *common.ServiceVolumes) *common.ServiceSpec

func CreateServiceStaticIP added in v0.8.1

func CreateServiceStaticIP(staticIP string, revision int64, spec *common.StaticIPSpec) *common.ServiceStaticIP

func CreateStaticIPSpec added in v0.9.6

func CreateStaticIPSpec(serviceUUID string, az string, serverInstanceID string, netInterfaceID string) *common.StaticIPSpec

func EqualConfigFile

func EqualConfigFile(c1 *common.ConfigFile, c2 *common.ConfigFile, skipMtime bool, skipContent bool) bool

func EqualConfigs added in v0.9.6

func EqualConfigs(c1 []common.ConfigID, c2 []common.ConfigID) bool

func EqualDevice

func EqualDevice(t1 *common.Device, t2 *common.Device) bool

func EqualMemberMeta added in v0.9.6

func EqualMemberMeta(m1 *common.MemberMeta, m2 *common.MemberMeta, skipMtime bool) bool

func EqualMemberSpec added in v0.9.6

func EqualMemberSpec(m1 *common.MemberSpec, m2 *common.MemberSpec) bool

func EqualMemberVolumes added in v0.9.1

func EqualMemberVolumes(v1 *common.MemberVolumes, v2 *common.MemberVolumes) bool

func EqualResources added in v0.9.2

func EqualResources(r1 *common.Resources, r2 *common.Resources) bool

func EqualService

func EqualService(t1 *common.Service, t2 *common.Service) bool

func EqualServiceAttr

func EqualServiceAttr(s1 *common.ServiceAttr, s2 *common.ServiceAttr, skipMtime bool, skipRevision bool) bool

func EqualServiceAttrImmutableFields added in v0.9.6

func EqualServiceAttrImmutableFields(s1 *common.ServiceAttr, s2 *common.ServiceAttr) bool

func EqualServiceMember

func EqualServiceMember(t1 *common.ServiceMember, t2 *common.ServiceMember, skipMtime bool) bool

func EqualServiceMemberImmutableFields added in v0.9.6

func EqualServiceMemberImmutableFields(m1 *common.ServiceMember, m2 *common.ServiceMember) bool

func EqualServiceMeta added in v0.9.6

func EqualServiceMeta(s1 *common.ServiceMeta, s2 *common.ServiceMeta, skipMtime bool) bool

func EqualServiceSpec added in v0.9.6

func EqualServiceSpec(s1 *common.ServiceSpec, s2 *common.ServiceSpec) bool

func EqualServiceStaticIP added in v0.8.1

func EqualServiceStaticIP(t1 *common.ServiceStaticIP, t2 *common.ServiceStaticIP) bool

func EqualServiceStaticIPImmutableFields added in v0.9.6

func EqualServiceStaticIPImmutableFields(t1 *common.ServiceStaticIP, t2 *common.ServiceStaticIP) bool

func EqualServiceVolume added in v0.9.1

func EqualServiceVolume(v1 *common.ServiceVolume, v2 *common.ServiceVolume) bool

func EqualServiceVolumes added in v0.9.1

func EqualServiceVolumes(v1 *common.ServiceVolumes, v2 *common.ServiceVolumes) bool

func EqualStaticIPSpec added in v0.9.6

func EqualStaticIPSpec(t1 *common.StaticIPSpec, t2 *common.StaticIPSpec) bool

func PrintConfigFile

func PrintConfigFile(cfg *common.ConfigFile) string

func UpdateServiceConfig added in v0.9.6

func UpdateServiceConfig(s *common.ServiceAttr, cfgIndex int, newFileID string, fileMD5 string) *common.ServiceAttr

func UpdateServiceMemberConfigs

func UpdateServiceMemberConfigs(t1 *common.ServiceMember, c []common.ConfigID) *common.ServiceMember

func UpdateServiceMemberOwner

func UpdateServiceMemberOwner(t1 *common.ServiceMember, taskID string, containerInstanceID string, serverInstanceID string) *common.ServiceMember

func UpdateServiceReplicas added in v0.9.2

func UpdateServiceReplicas(s *common.ServiceAttr, replicas int64) *common.ServiceAttr

func UpdateServiceResources added in v0.9.6

func UpdateServiceResources(s *common.ServiceAttr, res *common.Resources) *common.ServiceAttr

func UpdateServiceStaticIP added in v0.8.1

func UpdateServiceStaticIP(t1 *common.ServiceStaticIP, serverInstanceID string, netInterfaceID string) *common.ServiceStaticIP

func UpdateServiceStatus added in v0.9.2

func UpdateServiceStatus(s *common.ServiceAttr, status string) *common.ServiceAttr

Types

type DB

type DB interface {
	CreateSystemTables(ctx context.Context) error
	SystemTablesReady(ctx context.Context) (tableStatus string, ready bool, err error)
	DeleteSystemTables(ctx context.Context) error

	CreateDevice(ctx context.Context, dev *common.Device) error
	GetDevice(ctx context.Context, clusterName string, deviceName string) (dev *common.Device, err error)
	DeleteDevice(ctx context.Context, clusterName string, deviceName string) error
	ListDevices(ctx context.Context, clusterName string) (devs []*common.Device, err error)

	CreateService(ctx context.Context, svc *common.Service) error
	GetService(ctx context.Context, clusterName string, serviceName string) (svc *common.Service, err error)
	DeleteService(ctx context.Context, clusterName string, serviceName string) error
	ListServices(ctx context.Context, clusterName string) (svcs []*common.Service, err error)

	CreateServiceAttr(ctx context.Context, attr *common.ServiceAttr) error
	// Only support updating ServiceStatus, Replicas or UserAttr at v1, all other attributes are immutable.
	UpdateServiceAttr(ctx context.Context, oldAttr *common.ServiceAttr, newAttr *common.ServiceAttr) error
	GetServiceAttr(ctx context.Context, serviceUUID string) (attr *common.ServiceAttr, err error)
	DeleteServiceAttr(ctx context.Context, serviceUUID string) error

	CreateServiceMember(ctx context.Context, member *common.ServiceMember) error
	UpdateServiceMember(ctx context.Context, oldMember *common.ServiceMember, newMember *common.ServiceMember) error
	GetServiceMember(ctx context.Context, serviceUUID string, memberName string) (member *common.ServiceMember, err error)
	ListServiceMembers(ctx context.Context, serviceUUID string) (members []*common.ServiceMember, err error)
	DeleteServiceMember(ctx context.Context, serviceUUID string, memberName string) error

	CreateConfigFile(ctx context.Context, cfg *common.ConfigFile) error
	GetConfigFile(ctx context.Context, serviceUUID string, fileID string) (cfg *common.ConfigFile, err error)
	DeleteConfigFile(ctx context.Context, serviceUUID string, fileID string) error

	CreateServiceStaticIP(ctx context.Context, serviceip *common.ServiceStaticIP) error
	UpdateServiceStaticIP(ctx context.Context, oldip *common.ServiceStaticIP, newip *common.ServiceStaticIP) error
	GetServiceStaticIP(ctx context.Context, ip string) (serviceip *common.ServiceStaticIP, err error)
	DeleteServiceStaticIP(ctx context.Context, ip string) error
}

DB defines the DB interfaces

The design aims to provide the flexibility to support different type of key-value DBs. For example, could use the simple embedded controlDB, DynamoDB, etcd, zk, etc. There are 2 requirements: 1) conditional creation/update (create-if-not-exist and update-if-match). 2) strong consistency on get/list.

The device/service/serviceattr/servicemember/configfile creations are create-if-not-exist. If item exists in DB, the ErrDBConditionalCheckFailed error will be returned.

The serviceattr/servicemember updates are also update-if-match the old item. Return ErrDBConditionalCheckFailed as well if not match.

type MemDB

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

func NewMemDB

func NewMemDB() *MemDB

func (*MemDB) CreateConfigFile

func (d *MemDB) CreateConfigFile(ctx context.Context, cfg *common.ConfigFile) error

func (*MemDB) CreateDevice

func (d *MemDB) CreateDevice(ctx context.Context, dev *common.Device) error

func (*MemDB) CreateService

func (d *MemDB) CreateService(ctx context.Context, svc *common.Service) error

func (*MemDB) CreateServiceAttr

func (d *MemDB) CreateServiceAttr(ctx context.Context, attr *common.ServiceAttr) error

func (*MemDB) CreateServiceMember

func (d *MemDB) CreateServiceMember(ctx context.Context, member *common.ServiceMember) error

func (*MemDB) CreateServiceStaticIP added in v0.8.1

func (d *MemDB) CreateServiceStaticIP(ctx context.Context, serviceip *common.ServiceStaticIP) error

func (*MemDB) CreateSystemTables

func (d *MemDB) CreateSystemTables(ctx context.Context) error

func (*MemDB) DeleteConfigFile

func (d *MemDB) DeleteConfigFile(ctx context.Context, serviceUUID string, fileID string) error

func (*MemDB) DeleteDevice

func (d *MemDB) DeleteDevice(ctx context.Context, clusterName string, deviceName string) error

func (*MemDB) DeleteService

func (d *MemDB) DeleteService(ctx context.Context, clusterName string, serviceName string) error

func (*MemDB) DeleteServiceAttr

func (d *MemDB) DeleteServiceAttr(ctx context.Context, serviceUUID string) error

func (*MemDB) DeleteServiceMember

func (d *MemDB) DeleteServiceMember(ctx context.Context, serviceUUID string, memberName string) error

func (*MemDB) DeleteServiceStaticIP added in v0.8.1

func (d *MemDB) DeleteServiceStaticIP(ctx context.Context, ip string) error

func (*MemDB) DeleteSystemTables

func (d *MemDB) DeleteSystemTables(ctx context.Context) error

func (*MemDB) GetConfigFile

func (d *MemDB) GetConfigFile(ctx context.Context, serviceUUID string, fileID string) (cfg *common.ConfigFile, err error)

func (*MemDB) GetDevice

func (d *MemDB) GetDevice(ctx context.Context, clusterName string, deviceName string) (dev *common.Device, err error)

func (*MemDB) GetService

func (d *MemDB) GetService(ctx context.Context, clusterName string, serviceName string) (svc *common.Service, err error)

func (*MemDB) GetServiceAttr

func (d *MemDB) GetServiceAttr(ctx context.Context, serviceUUID string) (attr *common.ServiceAttr, err error)

func (*MemDB) GetServiceMember

func (d *MemDB) GetServiceMember(ctx context.Context, serviceUUID string, memberName string) (member *common.ServiceMember, err error)

func (*MemDB) GetServiceStaticIP added in v0.8.1

func (d *MemDB) GetServiceStaticIP(ctx context.Context, ip string) (serviceip *common.ServiceStaticIP, err error)

func (*MemDB) ListDevices

func (d *MemDB) ListDevices(ctx context.Context, clusterName string) (devs []*common.Device, err error)

func (*MemDB) ListServiceMembers

func (d *MemDB) ListServiceMembers(ctx context.Context, serviceUUID string) (members []*common.ServiceMember, err error)

func (*MemDB) ListServices

func (d *MemDB) ListServices(ctx context.Context, clusterName string) (svcs []*common.Service, err error)

func (*MemDB) SystemTablesReady

func (d *MemDB) SystemTablesReady(ctx context.Context) (tableStatus string, ready bool, err error)

func (*MemDB) UpdateServiceAttr

func (d *MemDB) UpdateServiceAttr(ctx context.Context, oldAttr *common.ServiceAttr, newAttr *common.ServiceAttr) error

func (*MemDB) UpdateServiceMember

func (d *MemDB) UpdateServiceMember(ctx context.Context, oldMember *common.ServiceMember, newMember *common.ServiceMember) error

func (*MemDB) UpdateServiceStaticIP added in v0.8.1

func (d *MemDB) UpdateServiceStaticIP(ctx context.Context, oldip *common.ServiceStaticIP, newip *common.ServiceStaticIP) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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