db

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2017 License: Apache-2.0 Imports: 10 Imported by: 28

Documentation

Index

Constants

View Source
const (
	// The status of one table
	TableStatusCreating = "CREATING"
	TableStatusUpdating = "UPDATING"
	TableStatusDeleting = "DELETING"
	TableStatusActive   = "ACTIVE"
)
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)
	ErrDBResourceNotFound       = errors.New(StrErrDBResourceNotFound)
	ErrDBRecordNotFound         = errors.New(StrErrDBRecordNotFound)
	ErrDBConditionalCheckFailed = errors.New(StrErrDBConditionalCheckFailed)
	ErrDBInvalidRequest         = errors.New(StrErrDBInvalidRequest)
)

Define the possible errors returned by DB interfaces

Functions

func CopyMemberConfigs

func CopyMemberConfigs(c1 []*common.MemberConfig) []*common.MemberConfig

func CreateConfigFile

func CreateConfigFile(serviceUUID string, fileID string, fileMD5 string,
	fileName string, fileMode uint32, mtime int64, content string) (*common.ConfigFile, error)

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 CreateInitialServiceAttr

func CreateInitialServiceAttr(serviceUUID string, replicas int64, cluster string,
	service string, vols common.ServiceVolumes, registerDNS bool, domain string,
	hostedZoneID string, requireStaticIP bool, userAttr *common.ServiceUserAttr) *common.ServiceAttr

func CreateInitialServiceMember

func CreateInitialServiceMember(serviceUUID string, memberIndex int64, memberName string, az string,
	vols common.MemberVolumes, staticIP string, configs []*common.MemberConfig) *common.ServiceMember

func CreateService

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

func CreateServiceAttr

func CreateServiceAttr(serviceUUID string, status string, mtime int64, replicas int64,
	cluster string, service string, vols common.ServiceVolumes, registerDNS bool, domain string,
	hostedZoneID string, requireStaticIP bool, userAttr *common.ServiceUserAttr) *common.ServiceAttr

func CreateServiceMember

func CreateServiceMember(serviceUUID string, memberIndex int64, memberName string,
	az string, taskID string, containerInstanceID string, ec2InstanceID string, mtime int64,
	vols common.MemberVolumes, staticIP string, configs []*common.MemberConfig) *common.ServiceMember

func CreateServiceStaticIP added in v0.8.1

func CreateServiceStaticIP(staticIP string, serviceUUID string,
	az string, serverInstanceID string, netInterfaceID string) *common.ServiceStaticIP

func EqualConfigFile

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

func EqualDevice

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

func EqualMemberVolumes added in v0.9.1

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

func EqualService

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

func EqualServiceAttr

func EqualServiceAttr(t1 *common.ServiceAttr, t2 *common.ServiceAttr, skipMtime bool) bool

func EqualServiceMember

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

func EqualServiceStaticIP added in v0.8.1

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

func EqualServiceUserAttr added in v0.9.1

func EqualServiceUserAttr(u1 *common.ServiceUserAttr, u2 *common.ServiceUserAttr) 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 PrintConfigFile

func PrintConfigFile(cfg *common.ConfigFile) string

func UpdateConfigFile

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

func UpdateServiceAttr

func UpdateServiceAttr(t1 *common.ServiceAttr, status string) *common.ServiceAttr

func UpdateServiceMemberConfigs

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

func UpdateServiceMemberOwner

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

func UpdateServiceStaticIP added in v0.8.1

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

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
	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, memberIndex int64) (member *common.ServiceMember, err error)
	ListServiceMembers(ctx context.Context, serviceUUID string) (members []*common.ServiceMember, err error)
	DeleteServiceMember(ctx context.Context, serviceUUID string, memberIndex int64) 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, memberIndex int64) 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, memberIndex int64) (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