kontrol

package
v0.0.0-...-17e712e Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2014 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package kontrol provides an implementation for the name service kite. It can be queried to get the list of running kites.

Index

Constants

View Source
const (
	KontrolVersion    = "0.0.4"
	HeartbeatInterval = 10 * time.Second
	HeartbeatDelay    = 20 * time.Second
	KitesPrefix       = "/kites"
	TokenLeeway       = 1 * time.Minute
)

Variables

View Source
var (
	TokenTTL    = 48 * time.Hour
	DefaultPort = 4000
)

Functions

func GetQueryKey

func GetQueryKey(q *protocol.KontrolQuery) (string, error)

getQueryKey returns the etcd key for the query.

Types

type Etcd

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

Etcd implements the Storage interface

func NewEtcd

func NewEtcd(machines []string, log kite.Logger) *Etcd

func (*Etcd) Add

func (e *Etcd) Add(k *protocol.Kite, value *kontrolprotocol.RegisterValue) error

func (*Etcd) Clear

func (e *Etcd) Clear() error

func (*Etcd) Delete

func (e *Etcd) Delete(k *protocol.Kite) error

func (*Etcd) Get

func (e *Etcd) Get(query *protocol.KontrolQuery) (Kites, error)

func (*Etcd) Update

func (e *Etcd) Update(k *protocol.Kite, value *kontrolprotocol.RegisterValue) error

func (*Etcd) Upsert

func (e *Etcd) Upsert(k *protocol.Kite, value *kontrolprotocol.RegisterValue) error

type Kites

type Kites []*protocol.KiteWithToken

Kites is a helpe type to work with a set of kites

func (Kites) Attach

func (k Kites) Attach(token string)

Attach attaches the given token to each kite. It replaces any previous token.

func (Kites) Filter

func (k Kites) Filter(constraint version.Constraints, keyRest string)

Filter filters out kites with the given constraints

func (Kites) Shuffle

func (k Kites) Shuffle()

Shuffle shuffles the order of the kites. This is usefull if you want send back a randomized list of kites.

type Kontrol

type Kontrol struct {
	Kite *kite.Kite

	// MachineAuthenticate is used to authenticate the request in the
	// "handleMachine" method.  The reason for a separate auth function is, the
	// request must not be authenticated because clients do not have a kite.key
	// before they register to this machine.
	MachineAuthenticate func(r *kite.Request) error

	// RegisterURL defines the URL that is used to self register when adding
	// itself to the storage backend
	RegisterURL string
	// contains filtered or unexported fields
}

func New

func New(conf *config.Config, version, publicKey, privateKey string) *Kontrol

New creates a new kontrol instance with the given verson and config instance. Publickey is used for validating tokens and privateKey is used for signing tokens.

peers can be given nil if not running on cluster.

Public and private keys are RSA pem blocks that can be generated with the following command:

openssl genrsa -out testkey.pem 2048
openssl rsa -in testkey.pem -pubout > testkey_pub.pem

func (*Kontrol) AddAuthenticator

func (k *Kontrol) AddAuthenticator(keyType string, fn func(*kite.Request) error)

func (*Kontrol) Close

func (k *Kontrol) Close()

Close stops kontrol and closes all connections

func (*Kontrol) InitializeSelf

func (k *Kontrol) InitializeSelf() error

InitializeSelf registers his host by writing a key to ~/.kite/kite.key

func (*Kontrol) Run

func (k *Kontrol) Run()

func (*Kontrol) SetStorage

func (k *Kontrol) SetStorage(storage Storage)

SetStorage sets the backend storage that kontrol is going to use to store kites

type Node

type Node struct {
	Node *etcd.Node
}

Node is a wrapper around an etcd node to provide additional functionality around kites.

func NewNode

func NewNode(node *etcd.Node) *Node

New returns a new initialized node with the given etcd node.

func (*Node) Flatten

func (n *Node) Flatten() []*Node

Flatten converts the recursive etcd directory structure to a flat one that contains all kontrolNodes

func (*Node) HasValue

func (n *Node) HasValue() bool

HasValue returns true if the give node has a non-empty value

func (*Node) Kite

func (n *Node) Kite() (*protocol.KiteWithToken, error)

Kite returns a single kite gathered from the key and the value for the current node.

func (*Node) KiteFromKey

func (n *Node) KiteFromKey() (*protocol.Kite, error)

KiteFromKey returns a *protocol.Kite from an etcd key. etcd key is like: "/kites/devrim/env/mathworker/1/localhost/tardis.local/id"

func (*Node) Kites

func (n *Node) Kites() (Kites, error)

Kites returns a list of kites that are gathered by collecting recursively all nodes under the current node.

func (*Node) Value

func (n *Node) Value() (string, error)

Value returns the value associated with the current node.

type Postgres

type Postgres struct {
	DB  *sql.DB
	Log kite.Logger
}

func NewPostgres

func NewPostgres(conf *PostgresConfig, log kite.Logger) *Postgres

func (*Postgres) Add

func (p *Postgres) Add(kiteProt *protocol.Kite, value *kontrolprotocol.RegisterValue) error

func (*Postgres) CleanExpiredRows

func (p *Postgres) CleanExpiredRows(expire time.Duration) (int64, error)

CleanExpiredRows deletes rows that are at least "expire" duration old. So if say an expire duration of 10 second is given, it will delete all rows that were updated 10 seconds ago

func (*Postgres) Delete

func (p *Postgres) Delete(kiteProt *protocol.Kite) error

func (*Postgres) Get

func (p *Postgres) Get(query *protocol.KontrolQuery) (Kites, error)

func (*Postgres) RunCleaner

func (p *Postgres) RunCleaner(interval, expire time.Duration)

RunCleaner delets every "interval" duration rows which are older than "expire" duration based on the "updated_at" field. For more info check CleanExpireRows which is used to delete old rows.

func (*Postgres) Update

func (p *Postgres) Update(kiteProt *protocol.Kite, value *kontrolprotocol.RegisterValue) error

func (*Postgres) Upsert

func (p *Postgres) Upsert(kiteProt *protocol.Kite, value *kontrolprotocol.RegisterValue) (err error)

type PostgresConfig

type PostgresConfig struct {
	Host     string
	Port     int
	Username string
	Password string
	DBName   string
}

Postgres holds Postgresql database related configuration

type RegisterValue

type RegisterValue struct {
	URL string `json:"url"`
}

RegisterValue is the type of the value that is saved to etcd.

type Storage

type Storage interface {
	// Get retrieves the Kites with the given query
	Get(query *protocol.KontrolQuery) (Kites, error)

	// Add inserts the given kite with the given value
	Add(kite *protocol.Kite, value *kontrolprotocol.RegisterValue) error

	// Update updates the value for the given kite
	Update(kite *protocol.Kite, value *kontrolprotocol.RegisterValue) error

	// Delete deletes the given kite from the storage
	Delete(kite *protocol.Kite) error

	// Upsert inserts or updates the value for the given kite
	Upsert(kite *protocol.Kite, value *kontrolprotocol.RegisterValue) error
}

Storage is an interface to a kite storage. A storage should be safe to concurrent access.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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