agent

package
v0.0.0-...-dbbe6ce Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2016 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GetInfo api.ServiceMethod = iota
	HealthCheck
)

Variables

View Source
var (
	ErrBadSchedulerConfig             = errors.New("bad-scheduler-config")
	ErrCannotDetermineContainerImage  = errors.New("cannot-determine-image")
	ErrUnknownService                 = errors.New("unknown-service")
	ErrHeapEmpty                      = errors.New("heap-empty")
	ErrNoImage                        = errors.New("no-image-at-path")
	ErrNoImageRegistryAuth            = errors.New("no-image-registry-auth")
	ErrNoHost                         = errors.New("no-host")
	ErrNoName                         = errors.New("no-name")
	ErrNotConnectedToRegistry         = errors.New("not-connected-to-registry")
	ErrNoContainerInformation         = errors.New("no-container-information")
	ErrNoDomain                       = errors.New("no-domain")
	ErrNoConfig                       = errors.New("no-config")
	ErrNoDockerName                   = errors.New("docker-name-env-not-set")
	ErrMoreThanOneAgent               = errors.New("more-than-one-agent")
	ErrNoDockerTlsCert                = errors.New("no-docker-tls-cert")
	ErrNoDockerTlsKey                 = errors.New("no-docker-tls-key")
	ErrBadDockerTlsCert               = errors.New("cannot-add-docker-tls-cert")
	ErrWatchReleaseMissingRegistryKey = errors.New("watch-release-missing-registry-key")
	ErrNoSchedulerReleasePath         = errors.New("no-scheduler-release-path")
	ErrMaxAttemptsExceeded            = errors.New("max-attempts-exceeded")
	ErrBadSchedulerSpec               = errors.New("bad-scheduler-spec")
	ErrBadVacuumConfig                = errors.New("bad-vacuum-config")
	ErrDebug                          = errors.New("REMOVE_ME")
)
View Source
var (
	ContainerFsm = containerFsm{
		Created:  []State{Starting, Running, Failed, Stopped, Removed},
		Starting: []State{Running, Failed, Stopping},
		Running:  []State{Running, Failed, Stopping, Stopped},
		Stopping: []State{Failed, Stopped},
		Stopped:  []State{Removed},
		Failed:   []State{Removed},
	}
)
View Source
var Methods = api.ServiceMethods{

	GetInfo: api.MethodSpec{
		Doc: `
Returns information about the server.
`,
		UrlRoute:     "/v1/info",
		HttpMethod:   "GET",
		ContentTypes: []string{"application/json"},
		ResponseBody: Types.Info,
	},

	HealthCheck: api.MethodSpec{
		Doc: `
Health check
`,
		UrlRoute:     "/health",
		HttpMethod:   "GET",
		ContentTypes: []string{"application/json"},
		ResponseBody: Types.Health,
	},
}
View Source
var ServiceId = "agent"
View Source
var Types = struct {
	Info   func(*http.Request) interface{}
	Health func(*http.Request) interface{}
}{
	Info:   func(*http.Request) interface{} { return &Info{} },
	Health: func(*http.Request) interface{} { return &Health{} },
}

Functions

func BuildRegistryEntry

func BuildRegistryEntry(container *docker.Container, match_port int) (*RegistryContainerEntry, error)

func CompareImages

func CompareImages(imageA, imageB string) bool

func ExceptionEvent

func ExceptionEvent(err error, context interface{}, a ...interface{})

func ImageMatch

func ImageMatch(image string, spec *docker.Image) bool

Types

type Agent

type Agent struct {
	QualifyByTags

	ZkSettings
	DockerSettings

	RegistryContainerEntry

	ListenPort   int `json:"listen_port"`
	DockerUIPort int `json:"dockerui_port"`

	UiDocRoot string `json:"ui_doc_root,omitempty"`
	EnableUI  bool   `json:"enable_ui,omitempty"`

	Initializer *ConfigLoader `json:"config_loader"`

	StatusPubsubTopic string `json:"status_topic,omitempty"`
	// contains filtered or unexported fields
}

func (*Agent) BindFlags

func (this *Agent) BindFlags()

func (*Agent) ConfigureDomain

func (this *Agent) ConfigureDomain(config *DomainConfig) (*Domain, error)

func (*Agent) ConnectServices

func (this *Agent) ConnectServices() error

func (*Agent) DiscoverRunningContainers

func (this *Agent) DiscoverRunningContainers(check CheckContainer, do OnMatch) error

func (*Agent) DiscoverSelfInDocker

func (this *Agent) DiscoverSelfInDocker() error

func (*Agent) GetIdentity

func (this *Agent) GetIdentity() string

func (*Agent) GetInfo

func (this *Agent) GetInfo() interface{}

func (*Agent) ListContainers

func (this *Agent) ListContainers(domain, service string) ([]*docker.Container, error)

Containers in this domain

func (*Agent) LoadConfig

func (this *Agent) LoadConfig(config *ConfigLoader) error

func (*Agent) Register

func (this *Agent) Register() error

func (*Agent) Run

func (this *Agent) Run()

Block until SIGTERM

func (*Agent) StartDockerUI

func (this *Agent) StartDockerUI() <-chan error

func (*Agent) WatchContainer

func (this *Agent) WatchContainer(domain, service string, spec *MatchContainerRule) error

type AssignContainerImage

type AssignContainerImage func(step int, opts *docker.ContainerControl) (*docker.Image, error)

func AssignContainerImageFromRegistry

func AssignContainerImageFromRegistry(global GlobalServiceState, local HostContainerStates,
	domain string, service ServiceKey) AssignContainerImage

type AssignContainerName

type AssignContainerName func(step int, template string, opts *docker.ContainerControl) string

func AssignContainerNameFromRegistry

func AssignContainerNameFromRegistry(global GlobalServiceState, local HostContainerStates,
	domain string, service ServiceKey) AssignContainerName

type CheckContainer

type CheckContainer func(*docker.Container) map[ServiceKey]*ContainerMatchRule

type Constraint

type Constraint struct {
	MinInstancesPerHost *int `json:"min_instances_per_host,omitempty"`
	MaxInstancesPerHost *int `json:"max_instances_per_host,omitempty"`
	MinInstancesGlobal  *int `json:"min_instances_global,omitempty"`
	MaxInstancesGlobal  *int `json:"max_instances_global,omitempty"`
}

Static / manual scheduler where the instances counts are specified statically per host

func (*Constraint) Schedule

func (this *Constraint) Schedule(localRunning, globalRunning int) (int, error)

type ContainerAction

type ContainerAction struct {
	// Template for naming the container. Variables:  Group, Sequence, Domain, Service, Image
	// If not provided, docker naming will be used.
	ContainerNameTemplate *string `json:"container_name_template,omitempty" dash:"template"`

	docker.ContainerControl
}

type ContainerActionType

type ContainerActionType int
const (
	Start ContainerActionType = iota
	Stop
	Remove
)

type ContainerGroup

type ContainerGroup struct {
	Image   string
	FsmById map[string]*Fsm
}

For all instances of a same container image version.

func NewContainerGroup

func NewContainerGroup(image string) *ContainerGroup

func (*ContainerGroup) Empty

func (cg *ContainerGroup) Empty() bool

func (*ContainerGroup) GetFsm

func (cg *ContainerGroup) GetFsm(c *docker.Container) *Fsm

func (ContainerGroup) Instances

func (c ContainerGroup) Instances() []*Fsm

func (*ContainerGroup) RemoveFsm

func (cg *ContainerGroup) RemoveFsm(c *docker.Container)

func (ContainerGroup) String

func (c ContainerGroup) String() string

type ContainerMatchRule

type ContainerMatchRule struct {
	MatchContainerRule

	Domain      string
	Service     ServiceKey
	PortMatched bool
}

func (*ContainerMatchRule) GetMatchContainerPort

func (this *ContainerMatchRule) GetMatchContainerPort() int

type ContainerMatchRulesUnion

type ContainerMatchRulesUnion struct {
	ByContainerName        *string           `json:"container_name,omitempty"`
	ByContainerEnvironment []string          `json:"container_envs,omitempty"`
	ByContainerLabels      map[string]string `json:"container_labels,omitempty"`
}

func (*ContainerMatchRulesUnion) Match

type ContainerState

type ContainerState int
const (
	Created ContainerState = iota
	Starting
	Running  // ready running
	Stopping // initiated stop
	Stopped  // stopped
	Failed   // uninitiated / unexpected stop
	Removed  // removed
)

func (ContainerState) Equals

func (this ContainerState) Equals(that State) bool

func (ContainerState) String

func (this ContainerState) String() string

type ContainerTracker

type ContainerTracker struct {
	Domain string
	// contains filtered or unexported fields
}

func NewContainerTracker

func NewContainerTracker(domain string) *ContainerTracker

func (*ContainerTracker) AddStatesListener

func (this *ContainerTracker) AddStatesListener(service ServiceKey) HostContainerStatesChanged

func (*ContainerTracker) AddTrackStartTime

func (this *ContainerTracker) AddTrackStartTime(service ServiceKey, c *docker.Container)

func (*ContainerTracker) CountVersions

func (this *ContainerTracker) CountVersions(service ServiceKey) int

/ Returns the number of versions of a service

func (*ContainerTracker) Died

func (this *ContainerTracker) Died(service ServiceKey, c *docker.Container)

func (*ContainerTracker) GetFsm

func (this *ContainerTracker) GetFsm(service ServiceKey, c *docker.Container) *Fsm

func (*ContainerTracker) Instances

func (this *ContainerTracker) Instances(service ServiceKey, image string) []*Fsm

/ Returns the number of versions of a service

func (*ContainerTracker) OldestVersion

func (this *ContainerTracker) OldestVersion(service ServiceKey) (image string, instances []*Fsm)

Returns all containers running on the oldest version of a service

func (*ContainerTracker) PeekOldest

func (this *ContainerTracker) PeekOldest(service ServiceKey) (*ContainerGroup, error)

func (*ContainerTracker) PopOldest

func (this *ContainerTracker) PopOldest(service ServiceKey) (*ContainerGroup, error)

func (*ContainerTracker) RemoveFsm

func (this *ContainerTracker) RemoveFsm(service ServiceKey, c *docker.Container)

func (*ContainerTracker) RemoveTrackStartTime

func (this *ContainerTracker) RemoveTrackStartTime(service ServiceKey, c *docker.Container)

func (*ContainerTracker) Removed

func (this *ContainerTracker) Removed(service ServiceKey, c *docker.Container)

func (*ContainerTracker) Reset

func (this *ContainerTracker) Reset()

func (*ContainerTracker) Running

func (this *ContainerTracker) Running(service ServiceKey, c *docker.Container)

func (*ContainerTracker) Starting

func (this *ContainerTracker) Starting(service ServiceKey, c *docker.Container)

func (*ContainerTracker) Stopped

func (this *ContainerTracker) Stopped(service ServiceKey, c *docker.Container)

func (*ContainerTracker) Stopping

func (this *ContainerTracker) Stopping(service ServiceKey, c *docker.Container)

func (*ContainerTracker) VisitStartTimes

func (this *ContainerTracker) VisitStartTimes(visit func(service ServiceKey, c *docker.Container))

func (*ContainerTracker) VisitVersions

func (this *ContainerTracker) VisitVersions(visit func(service ServiceKey, cg *ContainerGroup))

type DiscoveryContainerMatcher

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

func (*DiscoveryContainerMatcher) C

func (this *DiscoveryContainerMatcher) C(domain string, service ServiceKey, spec *MatchContainerRule) *DiscoveryContainerMatcher

func (*DiscoveryContainerMatcher) Init

func (*DiscoveryContainerMatcher) Match

func (this *DiscoveryContainerMatcher) Match(c *docker.Container) map[ServiceKey]*ContainerMatchRule

func (*DiscoveryContainerMatcher) MatcherForDomain

func (this *DiscoveryContainerMatcher) MatcherForDomain(domain string, service ServiceKey) func(docker.Action, *docker.Container) bool

type Domain

type Domain struct {
	Domain string `json:"domain"`

	RegistryContainerEntry

	Config *DomainConfig

	Identity string `json:"id"`
	// contains filtered or unexported fields
}

func (*Domain) AddScheduler

func (this *Domain) AddScheduler(service ServiceKey, scheduler *Scheduler) (chan bool, error)

func (*Domain) GetContainerWatcherSpecs

func (this *Domain) GetContainerWatcherSpecs() (map[ServiceKey]*MatchContainerRule, error)

Based on the scheduler information, derive the rules for discovery and monitoring of containers

func (*Domain) ListContainers

func (this *Domain) ListContainers(service ServiceKey) ([]*docker.Container, error)

Containers in this domain

func (*Domain) Register

func (this *Domain) Register() error

func (*Domain) StartScheduleExecutor

func (this *Domain) StartScheduleExecutor() (*ScheduleExecutor, error)

func (*Domain) StartServices

func (this *Domain) StartServices(tags QualifyByTags) (*Domain, error)

func (*Domain) SynchronizeSchedule

func (this *Domain) SynchronizeSchedule() error

func (*Domain) WatchContainer

func (this *Domain) WatchContainer(service ServiceKey, spec *MatchContainerRule) error

type DomainConfig

type DomainConfig struct {
	RegistryContainerEntry

	Services map[ServiceKey]*Scheduler `json:"services,omitempty"`

	Vacuums map[ServiceKey]*VacuumConfig `json:"vacuums,omitempty"`
}

Configuration for the domain Note this is effectively a deployment workflow with state transitions. TODO - implement state machine to track this for each service.

func (*DomainConfig) JSON

func (d *DomainConfig) JSON() string

type EndPoint

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

func NewApiEndPoint

func NewApiEndPoint(agent *Agent) (ep *EndPoint, err error)

func (*EndPoint) GetInfo

func (this *EndPoint) GetInfo(resp http.ResponseWriter, req *http.Request)

func (*EndPoint) HealthCheck

func (this *EndPoint) HealthCheck(resp http.ResponseWriter, req *http.Request)

func (*EndPoint) ServeHTTP

func (this *EndPoint) ServeHTTP(resp http.ResponseWriter, request *http.Request)

func (*EndPoint) Stop

func (this *EndPoint) Stop() error

type GlobalServiceState

type GlobalServiceState interface {
	Image() (path, version, image string, err error)
	Instances() (count int, err error)
}

type Health

type Health struct {
	Status        string  `json:"status"`
	UptimeSeconds float64 `json:uptime_seconds,omitempty`
}

type HostContainerStates

type HostContainerStates interface {
	Instances(service ServiceKey, image string) []*Fsm
	CountVersions(service ServiceKey) int
	OldestVersion(service ServiceKey) (image string, instances []*Fsm)
	VisitVersions(func(service ServiceKey, cg *ContainerGroup))
	VisitStartTimes(func(service ServiceKey, c *docker.Container))
}

type HostContainerStatesChanged

type HostContainerStatesChanged <-chan HostContainerStates

type Info

type Info struct {
	Version     version.Build `json:"version"`
	Now         time.Time     `json:"now"`
	Uptime      time.Duration `json:"uptime,omitempty"`
	Api         string        `json:"api,omitempty"`
	DockerApi   string        `json:"dockerapi,omitempty"`
	DockerUi    string        `json:"dockerui,omitempty"`
	StatusTopic string        `json:"status_topic,omitempty"`
	Environ     []string      `json:"environ,omitempty"`
	Agent       *Agent        `json:"agent"`
}

type MatchContainerRule

type MatchContainerRule struct {
	QualifyByTags
	docker.Image
	MatchContainerPort *int                       `json:"match_container_port,omitempty"`
	MatchFirst         []ContainerMatchRulesUnion `json:"match_first,omitempty"`
	MatchAll           []ContainerMatchRulesUnion `json:"mathc_all,omitempty"`
	// contains filtered or unexported fields
}

func (*MatchContainerRule) GetMatchContainerPort

func (this *MatchContainerRule) GetMatchContainerPort() int

type MinStartTimeHeap

type MinStartTimeHeap []*docker.Container

Min-heap of container prioritized by the start time of the container

func (*MinStartTimeHeap) Add

func (ch *MinStartTimeHeap) Add(c *docker.Container)

func (*MinStartTimeHeap) Init

func (ch *MinStartTimeHeap) Init()

func (MinStartTimeHeap) Len

func (h MinStartTimeHeap) Len() int

func (MinStartTimeHeap) Less

func (h MinStartTimeHeap) Less(i, j int) bool

func (*MinStartTimeHeap) Pop

func (h *MinStartTimeHeap) Pop() interface{}

func (*MinStartTimeHeap) Push

func (h *MinStartTimeHeap) Push(x interface{})

func (*MinStartTimeHeap) Remove

func (ch *MinStartTimeHeap) Remove(c *docker.Container) bool

func (MinStartTimeHeap) Swap

func (h MinStartTimeHeap) Swap(i, j int)

func (*MinStartTimeHeap) Visit

func (ch *MinStartTimeHeap) Visit(visit func(*docker.Container))

type MinVersionHeap

type MinVersionHeap []*ContainerGroup

Min-heap of container groups prioritized by the version

func (*MinVersionHeap) GetFsm

func (ch *MinVersionHeap) GetFsm(c *docker.Container) *dash.Fsm

func (*MinVersionHeap) Instances

func (ch *MinVersionHeap) Instances(image string) []*dash.Fsm

func (MinVersionHeap) Len

func (h MinVersionHeap) Len() int

func (MinVersionHeap) Less

func (h MinVersionHeap) Less(i, j int) bool

func (*MinVersionHeap) Pop

func (h *MinVersionHeap) Pop() interface{}

func (*MinVersionHeap) Push

func (h *MinVersionHeap) Push(x interface{})

func (*MinVersionHeap) RemoveFsm

func (ch *MinVersionHeap) RemoveFsm(c *docker.Container)

func (MinVersionHeap) Swap

func (h MinVersionHeap) Swap(i, j int)

func (*MinVersionHeap) Visit

func (ch *MinVersionHeap) Visit(visit func(*ContainerGroup))

type OnMatch

type OnMatch func(*docker.Container, *ContainerMatchRule)

type RunOnceSchedule

type RunOnceSchedule struct {
	Trigger string `json:"trigger"`
}

type ScheduleExecutor

type ScheduleExecutor struct {
	Inbox chan<- []Task
	Stop  chan<- bool
	// contains filtered or unexported fields
}

func NewScheduleExecutor

func NewScheduleExecutor(zk zk.ZK, docker *docker.Docker) *ScheduleExecutor

func (*ScheduleExecutor) Run

func (this *ScheduleExecutor) Run() error

type Scheduler

type Scheduler struct {
	QualifyByTags

	Task

	Register    *MatchContainerRule `json:"register,omitempty"`
	TriggerPath *Trigger            `json:"trigger_path,omitempty"`

	Constraint *Constraint      `json:"constraint,omitempty"`
	RunOnce    *RunOnceSchedule `json:"run_once,omitemtpy"`
	// contains filtered or unexported fields
}

func (*Scheduler) GetMatchContainerRule

func (this *Scheduler) GetMatchContainerRule() *MatchContainerRule

Derive the watch container spec based on the scheduler data.

func (*Scheduler) IsValid

func (this *Scheduler) IsValid() bool

func (*Scheduler) RegisterOnly

func (this *Scheduler) RegisterOnly() bool

func (*Scheduler) Run

func (this *Scheduler) Run(domain string, service ServiceKey, global GlobalServiceState,
	channel HostContainerStatesChanged, stopper <-chan bool, inbox SchedulerExecutor) error

func (*Scheduler) StartOne

func (this *Scheduler) StartOne(domain string, service ServiceKey,
	global GlobalServiceState, local HostContainerStates) Task

func (*Scheduler) Synchronize

func (this *Scheduler) Synchronize(domain string, service ServiceKey,
	local HostContainerStates, global GlobalServiceState, control SchedulerExecutor) error

type SchedulerExecutor

type SchedulerExecutor chan<- []Task

type Task

type Task struct {

	// Registry path where the image to use is stored.
	ImagePath string `json:"image_path,omitempty"`

	// Max attempts at starting a container -- 0 means no bounds
	MaxAttempts int `json:"max_attempts,omitempty"`

	// Optional - Side effects if run multiple times?
	Idempotent bool `json:"idempotent,omitempty"`

	// Path where Docker auth info can be found in the registry.
	// The value at this path is expected to a json struct for AuthConfiguration
	// http://godoc.org/github.com/fsouza/go-dockerclient#AuthConfiguration
	DockerAuthInfoPath string               `json:"auth_info_path"`
	AuthIdentity       *docker.AuthIdentity `json:"auth"`
	Actions            []ContainerAction    `json:"actions,omitempty"`
	// contains filtered or unexported fields
}

func NoActions

func NoActions() []Task

func (*Task) Execute

func (this *Task) Execute(zkc zk.ZK, dockerc *docker.Docker) error

Defer assignment of container image and container name to external sources. This for example allow us to implement a pull base

func (*Task) Image

func (this *Task) Image() (string, string, string, error)

implements GlobalServiceState

func (*Task) Instances

func (this *Task) Instances() (int, error)

implements GlobalServiceState

type TlsHandler

type TlsHandler struct {
	Cert string
	Key  string
	Ca   string
	// contains filtered or unexported fields
}

func (*TlsHandler) ServeHTTP

func (h *TlsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Trigger

type Trigger string

type UnixHandler

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

func (*UnixHandler) ServeHTTP

func (h *UnixHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Vacuum

type Vacuum struct {
	Domain  string
	Service ServiceKey
	Config  VacuumConfig
	Stop    VacuumStop
	// contains filtered or unexported fields
}

func NewVacuum

func NewVacuum(domain string, service ServiceKey, config VacuumConfig,
	local HostContainerStates, docker *docker.Docker) *Vacuum

func (*Vacuum) Run

func (this *Vacuum) Run() error

func (*Vacuum) Validate

func (this *Vacuum) Validate() error

type VacuumByStartTime

type VacuumByStartTime struct {
}

type VacuumByVersions

type VacuumByVersions struct {
	VersionsToKeep int `json:"versions_to_keep"`
}

type VacuumConfig

type VacuumConfig struct {
	QualifyByTags

	RemoveImage        bool   `json:"remove_image,omitempty"`
	ExportContainer    bool   `json:"export_container,omitempty"`
	ExportDestination  string `json:"exoprt_destination,omitempty"`
	RunIntervalSeconds uint32 `json:"run_interval_seconds,omitempty"`

	// Option when by version
	ByVersion *VacuumByVersions `json:"by_version,omitempty"`

	// Option when by start time
	ByStartTime *VacuumByStartTime `json:"by_start_time,omitempty"`
	// contains filtered or unexported fields
}

type VacuumStop

type VacuumStop chan<- bool

type VersionComparator

type VersionComparator func(imageA, imageB string) bool

Jump to

Keyboard shortcuts

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