db

package
v0.0.0-...-3fa228a Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2016 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"

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

	// Azure implements the Azure cloud provider.
	Azure = "Azure"
)

Variables

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 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 Cluster

type Cluster struct {
	ID int

	Namespace string // Cloud Provider Namespace
	Spec      string

	/* XXX: These belong in a separate administration table of some sort. */
	ACLs []string
}

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 executed.

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) MinionSelf

func (conn Conn) MinionSelf() (Minion, error)

MinionSelf returns the Minion Row corresponding to the currently running minion, or an error if no such row exists.

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) SelectFromLabel

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

SelectFromLabel gets all labels in the database connection 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) Transact

func (cn Conn) Transact(do func(db Database) error) error

Transact executes database transactions. It takes a closure, 'do', which is operates on its 'db' argument. Transactions are not concurrent, instead each runs sequentially on it's database without conflicting with other transactions.

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.

type Connection

type Connection struct {
	ID int

	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(ii 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.

type Container

type Container struct {
	ID int

	Pid      int
	IP       string
	Mac      string
	Minion   string
	DockerID string
	StitchID int
	Image    string
	Command  []string
	Labels   []string
	Env      map[string]string
}

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

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) GetCluster

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

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

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) 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, error)

MinionSelf returns the Minion Row corresponding to the currently running minion, or an error if no such row exists.

func (Database) Remove

func (db Database) Remove(r row)

Remove deletes row from the database.

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) 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 Label

type Label struct {
	ID int

	Label     string
	IP        string
	MultiHost bool
}

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(ii 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

type Machine

type Machine struct {
	ID int //Database ID

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

	/* 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:"-"`

	// Below fields are included in the JSON encoding.
	Role      Role
	PrivateIP string
	Provider  string
	Size      string
	Region    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
}

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 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 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