db

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2017 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// None is for workers who haven't been assigned a role yet.
	None Role = ""

	// Worker minions run application containers.
	Worker = "Worker"

	// Master containers provide services for the Worker containers.
	Master = "Master"
)
View Source
const (
	// Amazon implements amazon EC2.
	Amazon Provider = "Amazon"

	// Google implements Google Cloud Engine.
	Google = "Google"

	// DigitalOcean implements Digital Ocean Droplets.
	DigitalOcean = "DigitalOcean"

	// Vagrant implements local virtual machines.
	Vagrant = "Vagrant"
)

Variables

View Source
var ACLTable = TableType(reflect.TypeOf(ACL{}).String())

ACLTable is the type of the ACL table.

AllTables is a slice of all the db TableTypes. It is used primarily for tests, where there is no reason to put lots of thought into which tables a Transaction should use.

View Source
var ClusterTable = TableType(reflect.TypeOf(Cluster{}).String())

ClusterTable is the type of the cluster table.

View Source
var ConnectionTable = TableType(reflect.TypeOf(Connection{}).String())

ConnectionTable is the type of the connection table.

View Source
var ContainerTable = TableType(reflect.TypeOf(Container{}).String())

ContainerTable is the type of the container table.

View Source
var EtcdTable = TableType(reflect.TypeOf(Etcd{}).String())

EtcdTable is the type of the etcd table.

View Source
var HostnameTable = TableType(reflect.TypeOf(Hostname{}).String())

HostnameTable is the type of the Hostname table.

View Source
var ImageTable = TableType(reflect.TypeOf(Image{}).String())

ImageTable is the type of the image table.

View Source
var LabelTable = TableType(reflect.TypeOf(Label{}).String())

LabelTable is the type of the label table.

View Source
var MachineTable = TableType(reflect.TypeOf(Machine{}).String())

MachineTable is the type of the machine table.

View Source
var MinionTable = TableType(reflect.TypeOf(Minion{}).String())

MinionTable is the type of the minion table.

View Source
var PlacementTable = TableType(reflect.TypeOf(Placement{}).String())

PlacementTable is the type of the placement table.

Functions

func RoleToPB

func RoleToPB(r Role) pb.MinionConfig_Role

RoleToPB converts db.Role to a protobuf role.

Types

type ACL

type ACL struct {
	ID int

	Admin            []string
	ApplicationPorts []PortRange
}

ACL defines access control for Quilt-managed machines.

func (ACL) String

func (acl ACL) String() string

type Cluster

type Cluster struct {
	ID int

	Namespace string // Cloud Provider Namespace
	Spec      string `rowStringer:"omit"`
}

A Cluster is a group of Machines which can operate containers.

func (Cluster) String

func (c Cluster) String() string

type Conn

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

A Conn is a database handle on which Transactions may be created.

func New

func New() Conn

New creates a connection to a brand new database.

func (Conn) EtcdLeader

func (conn Conn) EtcdLeader() bool

EtcdLeader returns true if the minion is the lead master for the cluster.

func (Conn) GetClusterNamespace

func (conn Conn) GetClusterNamespace() (namespace string, err error)

GetClusterNamespace returns the namespace of the single cluster object in the cluster table. Otherwise it returns an error.

func (Conn) MinionSelf

func (conn Conn) MinionSelf() Minion

MinionSelf returns the Minion Row corresponding to the currently running minion. If there is no Minion Row, it panics

func (Conn) SelectFromCluster

func (conn Conn) SelectFromCluster(check func(Cluster) bool) []Cluster

SelectFromCluster gets all clusters in the database that satisfy 'check'.

func (Conn) SelectFromConnection

func (conn Conn) SelectFromConnection(check func(Connection) bool) []Connection

SelectFromConnection gets all connections in the database connection that satisfy the 'check'.

func (Conn) SelectFromContainer

func (conn Conn) SelectFromContainer(check func(Container) bool) []Container

SelectFromContainer gets all containers in the database that satisfy the 'check'.

func (Conn) SelectFromEtcd

func (conn Conn) SelectFromEtcd(check func(Etcd) bool) []Etcd

SelectFromEtcd gets all Etcd rows in the database connection that satisfy the 'check'.

func (Conn) SelectFromHostname

func (conn Conn) SelectFromHostname(check func(Hostname) bool) []Hostname

SelectFromHostname gets all hostnames in the database that satisfy the 'check'.

func (Conn) SelectFromLabel

func (conn Conn) SelectFromLabel(check func(Label) bool) []Label

SelectFromLabel gets all labels in the database connection that satisfy 'check'.

func (Conn) SelectFromMachine

func (cn Conn) SelectFromMachine(check func(Machine) bool) []Machine

SelectFromMachine gets all machines in the database that satisfy 'check'.

func (Conn) SelectFromMinion

func (conn Conn) SelectFromMinion(check func(Minion) bool) []Minion

SelectFromMinion gets all minions in the database that satisfy the 'check'.

func (Conn) SelectFromPlacement

func (conn Conn) SelectFromPlacement(check func(Placement) bool) []Placement

SelectFromPlacement gets all placements in the database that satisfy the 'check'.

func (Conn) Trigger

func (cn Conn) Trigger(tt ...TableType) Trigger

Trigger registers a new database trigger that watches changes to 'tableName'. Any change to the table, including row insertions, deletions, and modifications, will cause a notification on 'Trigger.C'.

func (Conn) TriggerTick

func (cn Conn) TriggerTick(seconds int, tt ...TableType) Trigger

TriggerTick creates a trigger, similar to Trigger(), that additionally ticks once every N 'seconds'. So that clients properly initialize, TriggerTick() sends an initialization tick at startup.

func (Conn) Txn

func (cn Conn) Txn(tables ...TableType) Transaction

Txn creates a new Transaction object connected to the same database, but with restricted access to only the given tables.

type Connection

type Connection struct {
	ID int `json:"-"`

	From    string
	To      string
	MinPort int
	MaxPort int
}

A Connection allows the members of two labels to speak to each other on the port range [MinPort, MaxPort] inclusive.

func (Connection) String

func (c Connection) String() string

type ConnectionSlice

type ConnectionSlice []Connection

ConnectionSlice is an alias for []Connection to allow for joins

func (ConnectionSlice) Get

func (cs ConnectionSlice) Get(i int) interface{}

Get returns the value contained at the given index

func (ConnectionSlice) Len

func (cs ConnectionSlice) Len() int

Len returns the number of items in the slice.

func (ConnectionSlice) Less

func (cs ConnectionSlice) Less(i, j int) bool

Less implements less than for sort.Interface.

func (ConnectionSlice) Swap

func (cs ConnectionSlice) Swap(i, j int)

Swap implements swapping for sort.Interface.

type Container

type Container struct {
	ID int `json:"-"`

	IP                string            `json:",omitempty"`
	Minion            string            `json:",omitempty"`
	EndpointID        string            `json:",omitempty"`
	StitchID          string            `json:",omitempty"`
	DockerID          string            `json:",omitempty"`
	Status            string            `json:",omitempty"`
	Command           []string          `json:",omitempty"`
	Labels            []string          `json:",omitempty"`
	Env               map[string]string `json:",omitempty"`
	FilepathToContent map[string]string `json:",omitempty"`
	Hostname          string            `json:"-"`
	Created           time.Time         `json:","`

	Image      string `json:",omitempty"`
	ImageID    string `json:",omitempty"`
	Dockerfile string `json:"-"`
}

A Container row is created for each container specified by the policy. Each row will eventually be instantiated within its corresponding cluster. Used only by the minion.

func (Container) String

func (c Container) String() string

type ContainerSlice

type ContainerSlice []Container

ContainerSlice is an alias for []Container to allow for joins

func (ContainerSlice) Get

func (cs ContainerSlice) Get(ii int) interface{}

Get returns the value contained at the given index

func (ContainerSlice) Len

func (cs ContainerSlice) Len() int

Len returns the number of items in the slice

func (ContainerSlice) Less

func (cs ContainerSlice) Less(i, j int) bool

Less implements less than for sort.Interface.

func (ContainerSlice) Swap

func (cs ContainerSlice) Swap(i, j int)

Swap implements swapping for sort.Interface.

type Database

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

The Database is the central storage location for all state in the system. The policy engine populates the database with a preferred state of the world, while various modules flesh out that policy with actual implementation details.

func (Database) Commit

func (db Database) Commit(r row)

Commit updates the database with the data contained in row.

func (Database) EtcdLeader

func (db Database) EtcdLeader() bool

EtcdLeader returns true if the minion is the lead master for the cluster.

func (Database) GetACL

func (db Database) GetACL() (ACL, error)

GetACL gets the ACL row from the database. There should only ever be a single ACL row.

func (Database) GetCluster

func (db Database) GetCluster() (Cluster, error)

GetCluster gets the cluster from the database. There should only ever be a single cluster.

func (Database) GetClusterNamespace

func (db Database) GetClusterNamespace() (string, error)

GetClusterNamespace returns the namespace of the single cluster object in the cluster table. Otherwise it returns an error.

func (Database) GetEtcd

func (db Database) GetEtcd() (Etcd, error)

GetEtcd gets the Etcd row from the database. There should only ever be a single Etcd row.

func (Database) InsertACL

func (db Database) InsertACL() ACL

InsertACL creates a new ACL row and inserts it into 'db'.

func (Database) InsertCluster

func (db Database) InsertCluster() Cluster

InsertCluster creates a new Cluster and interts it into 'db'.

func (Database) InsertConnection

func (db Database) InsertConnection() Connection

InsertConnection creates a new connection row and inserts it into the database.

func (Database) InsertContainer

func (db Database) InsertContainer() Container

InsertContainer creates a new container row and inserts it into the database.

func (Database) InsertEtcd

func (db Database) InsertEtcd() Etcd

InsertEtcd creates a new etcd row and inserts it into the database.

func (Database) InsertHostname

func (db Database) InsertHostname() Hostname

InsertHostname creates a new Hostname row and inserts it into 'db'.

func (Database) InsertImage

func (db Database) InsertImage() Image

InsertImage creates a new image row and inserts it into the database.

func (Database) InsertLabel

func (db Database) InsertLabel() Label

InsertLabel creates a new label row and inserts it into the database.

func (Database) InsertMachine

func (db Database) InsertMachine() Machine

InsertMachine creates a new Machine and inserts it into 'db'.

func (Database) InsertMinion

func (db Database) InsertMinion() Minion

InsertMinion creates a new Minion and inserts it into 'db'.

func (Database) InsertPlacement

func (db Database) InsertPlacement() Placement

InsertPlacement creates a new placement row and inserts it into the database.

func (Database) MinionSelf

func (db Database) MinionSelf() Minion

MinionSelf returns the Minion Row corresponding to the currently running minion. If there is no Minion Row, it panics

func (Database) Remove

func (db Database) Remove(r row)

Remove deletes row from the database.

func (Database) SelectFromACL

func (db Database) SelectFromACL(check func(ACL) bool) []ACL

SelectFromACL gets all acls in the database that satisfy 'check'.

func (Database) SelectFromCluster

func (db Database) SelectFromCluster(check func(Cluster) bool) []Cluster

SelectFromCluster gets all clusters in the database that satisfy 'check'.

func (Database) SelectFromConnection

func (db Database) SelectFromConnection(check func(Connection) bool) []Connection

SelectFromConnection gets all connections in the database that satisfy 'check'.

func (Database) SelectFromContainer

func (db Database) SelectFromContainer(check func(Container) bool) []Container

SelectFromContainer gets all containers in the database that satisfy 'check'.

func (Database) SelectFromEtcd

func (db Database) SelectFromEtcd(check func(Etcd) bool) []Etcd

SelectFromEtcd gets all Etcd rows in the database that satisfy the 'check'.

func (Database) SelectFromHostname

func (db Database) SelectFromHostname(check func(Hostname) bool) []Hostname

SelectFromHostname gets all hostnames in the database that satisfy 'check'.

func (Database) SelectFromImage

func (db Database) SelectFromImage(check func(Image) bool) []Image

SelectFromImage gets all images in the database that satisfy 'check'.

func (Database) SelectFromLabel

func (db Database) SelectFromLabel(check func(Label) bool) []Label

SelectFromLabel gets all labels in the database that satisfy 'check'.

func (Database) SelectFromMachine

func (db Database) SelectFromMachine(check func(Machine) bool) []Machine

SelectFromMachine gets all machines in the database that satisfy the 'check'.

func (Database) SelectFromMinion

func (db Database) SelectFromMinion(check func(Minion) bool) []Minion

SelectFromMinion gets all minions in the database that satisfy the 'check'.

func (Database) SelectFromPlacement

func (db Database) SelectFromPlacement(check func(Placement) bool) []Placement

SelectFromPlacement gets all placements in the database that satisfy 'check'.

type Etcd

type Etcd struct {
	ID int

	EtcdIPs []string // The set of members in the cluster.

	Leader   bool   // True if this Minion is the leader.
	LeaderIP string // IP address of the current leader, or ""
}

The Etcd table contains configuration pertaining to the minion etcd cluster including the members and leadership information.

func (Etcd) String

func (e Etcd) String() string

type Hostname

type Hostname struct {
	ID int `json:"-"`

	Hostname, IP string
}

A Hostname is a mapping from a name to an IP.

func (Hostname) String

func (r Hostname) String() string

type HostnameSlice

type HostnameSlice []Hostname

HostnameSlice is an alias for []Hostname to allow for joins

func (HostnameSlice) Get

func (hs HostnameSlice) Get(i int) interface{}

Get returns the value contained at the given index

func (HostnameSlice) Len

func (hs HostnameSlice) Len() int

Len returns the number of items in the slice

func (HostnameSlice) Less

func (hs HostnameSlice) Less(i, j int) bool

Less implements less than for sort.Interface.

func (HostnameSlice) Swap

func (hs HostnameSlice) Swap(i, j int)

Swap implements swapping for sort.Interface.

type Image

type Image struct {
	ID int

	// The desired name for the image.
	Name string

	// The Dockerfile with which to build the image.
	Dockerfile string

	// The ID of the built image.
	DockerID string
}

An Image row represents a Docker image that should be built by the Quilt masters.

func (Image) String

func (image Image) String() string

type ImageSlice

type ImageSlice []Image

ImageSlice is an alias for []Image to allow for joins

func (ImageSlice) Get

func (slc ImageSlice) Get(ii int) interface{}

Get returns the value contained at the given index

func (ImageSlice) Len

func (slc ImageSlice) Len() int

Len returns the number of items in the slice.

type Label

type Label struct {
	ID int

	Label        string
	IP           string
	ContainerIPs []string
}

A Label row is created for each label specified by the policy.

func (Label) String

func (r Label) String() string

type LabelSlice

type LabelSlice []Label

LabelSlice is an alias for []Label to allow for joins

func (LabelSlice) Get

func (ls LabelSlice) Get(i int) interface{}

Get returns the value contained at the given index

func (LabelSlice) Len

func (ls LabelSlice) Len() int

Len returns the number of items in the slice

func (LabelSlice) Less

func (ls LabelSlice) Less(i, j int) bool

Less implements less than for sort.Interface.

func (LabelSlice) Swap

func (ls LabelSlice) Swap(i, j int)

Swap implements swapping for sort.Interface.

type Machine

type Machine struct {
	ID int //Database ID

	/* Populated by the policy engine. */
	StitchID    string
	Role        Role
	Provider    Provider
	Region      string
	Size        string
	DiskSize    int
	SSHKeys     []string `rowStringer:"omit"`
	FloatingIP  string
	Preemptible bool

	/* Populated by the cloud provider. */
	CloudID   string //Cloud Provider ID
	PublicIP  string
	PrivateIP string

	/* Populated by the foreman. */
	Connected bool // Whether the minion on this machine has connected back.
}

Machine represents a physical or virtual machine operated by a cloud provider on which containers may be run.

func SortMachines

func SortMachines(machines []Machine) []Machine

SortMachines returns a slice of machines sorted according to the default database sort order.

func (Machine) String

func (m Machine) String() string

type MachineSlice

type MachineSlice []Machine

MachineSlice is an alias for []Machine to allow for joins

func (MachineSlice) Get

func (ms MachineSlice) Get(ii int) interface{}

Get returns the value contained at the given index

func (MachineSlice) Len

func (ms MachineSlice) Len() int

Len returns the number of items in the slice

type Minion

type Minion struct {
	ID int `json:"-"`

	Self           bool   `json:"-"`
	Spec           string `json:"-" rowStringer:"omit"`
	AuthorizedKeys string `json:"-" rowStringer:"omit"`

	// Below fields are included in the JSON encoding.
	Role       Role
	PrivateIP  string
	Provider   string
	Size       string
	Region     string
	FloatingIP string
}

The Minion table is instantiated on the minions with one row. That row contains the configuration that minion needs to operate, including its ID, Role, and IP address

func (Minion) String

func (m Minion) String() string

type MinionSlice

type MinionSlice []Minion

MinionSlice is an alias for []Minion to allow for joins

func (MinionSlice) Get

func (m MinionSlice) Get(ii int) interface{}

Get returns the value contained at the given index

func (MinionSlice) Len

func (m MinionSlice) Len() int

Len returns the number of items in the slice

type Placement

type Placement struct {
	ID int

	TargetLabel string

	Exclusive bool

	// Label Constraint
	OtherLabel string

	// Machine Constraints
	Provider   string
	Size       string
	Region     string
	FloatingIP string
}

Placement represents a declaration about how containers should be placed. These directives can be made either relative to labels of other containers, or Machines those containers run on.

func (Placement) String

func (p Placement) String() string

type PlacementSlice

type PlacementSlice []Placement

PlacementSlice is an alias for []Placement to allow for joins

func (PlacementSlice) Get

func (ps PlacementSlice) Get(ii int) interface{}

Get returns the value contained at the given index

func (PlacementSlice) Len

func (ps PlacementSlice) Len() int

Len returns the numebr of items in the slice

type PortRange

type PortRange struct {
	MinPort int
	MaxPort int
}

PortRange represents a range of ports for which to allow traffic.

func (PortRange) String

func (pr PortRange) String() string

type Provider

type Provider string

A Provider implements a cloud interface on which machines may be instantiated.

func ParseProvider

func ParseProvider(name string) (Provider, error)

ParseProvider returns the Provider represented by 'name' or an error.

type ProviderSlice

type ProviderSlice []Provider

ProviderSlice is an alias for []Provider to allow for joins

func (ProviderSlice) Get

func (ps ProviderSlice) Get(ii int) interface{}

Get returns the value contained at the given index

func (ProviderSlice) Len

func (ps ProviderSlice) Len() int

Len returns the number of items in the slice

type Role

type Role string

The Role a machine may take on within the cluster.

func PBToRole

func PBToRole(p pb.MinionConfig_Role) Role

PBToRole converts a protobuf role to a db.Role.

func ParseRole

func ParseRole(role string) (Role, error)

ParseRole returns the Role represented by the string 'role', or an error.

type TableType

type TableType string

TableType represents a table in the database.

type Transaction

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

A Transaction is a database handle on which transactions may be executed.

func (Transaction) Run

func (tr Transaction) Run(do func(db Database) error) error

Run executes database transactions. It takes a closure, 'do', which is operates on its 'db' argument. Transactions may be concurrent, but only if they operate on independent sets of tables. Otherwise, each transaction runs sequentially on it's database without conflicting with other transactions.

type Trigger

type Trigger struct {
	C chan struct{} // The channel on which notifications are delivered.
	// contains filtered or unexported fields
}

A Trigger sends notifications when anything in their corresponding table changes.

func (Trigger) Stop

func (t Trigger) Stop()

Stop a running trigger thus allowing resources to be deallocated.

Jump to

Keyboard shortcuts

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