Documentation ¶
Overview ¶
Package serviced - agent implements a service that runs on a serviced node. It is responsible for ensuring that a particular node is running the correct services and reporting the state and health of those services back to the master serviced.
This file implements the LoadBalancer interface aspect of the host agent.
Serviced is a PaaS runtime based on docker. The serviced package exposes the interfaces for the key parts of this runtime.
Copyright 2016 The Serviced Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- func AddToEtcHosts(host, ip string) error
- func CreateDirectory(path, username string, perm os.FileMode) error
- func CreateVolumeDir(conn client.Connection, ...) error
- func ExecPath() (string, string, error)
- func GetDockerVersion() ([]int, error)
- func GetInterfaceIPAddress(_interface string) (string, error)
- func IsValidOwnerSpec(owner string) bool
- func NewReverseProxy(path string, targeturl *url.URL) *httputil.ReverseProxy
- type AgentClient
- type AgentOptions
- type ApplicationType
- type ContainerState
- type EvaluateServiceRequest
- type EvaluateServiceResponse
- type HealthCheckRequest
- type HostAgent
- func (a *HostAgent) AckProxySnapshotQuiece(snapshotId string, unused *interface{}) error
- func (a *HostAgent) AttachAndRun(dockerID string, command []string) ([]byte, error)
- func (a *HostAgent) AttachContainer(state *zkservice.ServiceState, serviceID string, instanceID int) (<-chan time.Time, error)
- func (a *HostAgent) BindIP(ipprefix, netmask, iface string) error
- func (a *HostAgent) GetEvaluatedService(request EvaluateServiceRequest, response *EvaluateServiceResponse) (err error)
- func (a *HostAgent) GetHostID(_ string, hostID *string) error
- func (a *HostAgent) GetISvcEndpoints(serviceId string, ...) (err error)
- func (a *HostAgent) GetProxySnapshotQuiece(serviceId string, snapshotId *string) error
- func (a *HostAgent) GetServiceBindMounts(serviceID string, bindmounts *map[string]string) error
- func (a *HostAgent) GetZkInfo(_ string, zkInfo *ZkInfo) error
- func (a *HostAgent) PauseContainer(serviceID string, instanceID int) error
- func (a *HostAgent) Ping(waitFor time.Duration, timestamp *time.Time) error
- func (a *HostAgent) ReleaseIP(ipprefix string) error
- func (a *HostAgent) ReportHealthStatus(req master.HealthStatusRequest, unused *int) error
- func (a *HostAgent) ReportInstanceDead(req master.ServiceInstanceRequest, unused *int) error
- func (a *HostAgent) RestartContainer(cancel <-chan interface{}, serviceID string, instanceID int) error
- func (a *HostAgent) ResumeContainer(serviceID string, instanceID int) error
- func (a *HostAgent) SendLogMessage(serviceLogInfo ServiceLogInfo, _ *struct{}) (err error)
- func (a *HostAgent) SetVIP(v VIP)
- func (a *HostAgent) Start(shutdown <-chan interface{})
- func (a *HostAgent) StartContainer(cancel <-chan interface{}, serviceID string, instanceID int) (*zkservice.ServiceState, <-chan time.Time, error)
- func (a *HostAgent) StopContainer(serviceID string, instanceID int) error
- type IP
- type LBClient
- func (a *LBClient) AckProxySnapshotQuiece(snapshotId string, unused *interface{}) error
- func (a *LBClient) Close() error
- func (a *LBClient) GetEvaluatedService(request EvaluateServiceRequest, response *EvaluateServiceResponse) error
- func (a *LBClient) GetHostID(hostID *string) error
- func (a *LBClient) GetISvcEndpoints(serviceId string, ...) error
- func (a *LBClient) GetProxySnapshotQuiece(serviceId string, snapshotId *string) error
- func (a *LBClient) GetServiceBindMounts(serviceID string, bindmounts *map[string]string) error
- func (a *LBClient) GetZkInfo(zkInfo *ZkInfo) error
- func (a *LBClient) Ping(waitFor time.Duration, timestamp *time.Time) error
- func (a *LBClient) ReportHealthStatus(req master.HealthStatusRequest, unused *int) error
- func (a *LBClient) ReportInstanceDead(req master.ServiceInstanceRequest, unused *int) error
- func (a *LBClient) SendLogMessage(serviceLogInfo ServiceLogInfo, _ *struct{}) error
- type LoadBalancer
- type ProtocolType
- type ServiceCache
- type ServiceInstanceRequest
- type ServiceLogInfo
- type VIP
- type VirtualIPManager
- type ZkInfo
Constants ¶
const ( SERVICED_UI_ENDPOINT = 5443 SERVICED_UI_ENDPOINT_PROXY = 443 )
Variables ¶
This section is empty.
Functions ¶
func CreateDirectory ¶
CreateDirectory creates a directory using the given username as the owner and the given perm as the directory permission.
func CreateVolumeDir ¶
func CreateVolumeDir(conn client.Connection, hostPath, containerSpec, imageSpec, userSpec, permissionSpec string) error
CreateVolumeDir() creates a directory on the running host using the user ids found within the specified image. For example, it can create a directory owned by the mysql user (as seen by the container) despite there being no mysql user on the host system. Assumes that the local docker image (imageSpec) exists and has been sync'd with the registry.
func GetDockerVersion ¶
GetDockerVersion returns docker version number.
func GetInterfaceIPAddress ¶
GetInterfaceIPAddress attempts to find the IP address based on interface name
func IsValidOwnerSpec ¶
IsValidOwnerSpec returns true if the owner is specified in owner:group format and the identifiers are valid POSIX.1-2008 username and group strings, respectively.
func NewReverseProxy ¶
func NewReverseProxy(path string, targeturl *url.URL) *httputil.ReverseProxy
NewReverseProxy differs from httputil.NewSingleHostReverseProxy in that it rewrites the path so that it does /not/ include the incoming path. e.g. request for "/mysvc/thing" when proxy is served from "/mysvc" means target is targeturl.Path + "/thing"; vs. httputil.NewSingleHostReverseProxy, in which it would be targeturl.Path + "/mysvc/thing".
Types ¶
type AgentClient ¶
type AgentClient struct {
// contains filtered or unexported fields
}
AgentClient is an interface that the serviced agent implements to provide information about the host it is running on.
func NewAgentClient ¶
func NewAgentClient(addr string) (s *AgentClient, err error)
Create a new AgentClient.
type AgentOptions ¶
type AgentOptions struct { IPAddress string PoolID string Master string UIPort string RPCPort string RPCDisableTLS bool // true if TLS should be disabled for RPC DockerDNS []string VolumesPath string Mount []string FSType volume.DriverType Zookeepers []string Mux *proxy.TCPMux MuxPort string UseTLS bool DockerRegistry string MaxContainerAge time.Duration // Maximum container age for a stopped container before being removed VirtualAddressSubnet string ControllerBinary string LogstashURL string DockerLogDriver string DockerLogConfig map[string]string ZKSessionTimeout int ZKConnectTimeout int ZKPerHostConnectDelay int ZKReconnectStartDelay int ZKReconnectMaxDelay int DelegateKeyFile string TokenFile string ConntrackFlush bool }
type ApplicationType ¶
type ApplicationType string
A user defined string that describes an exposed application endpoint.
type ContainerState ¶
type ContainerState struct { ID string Created time.Time Path string Args []string Config struct { Hostname string User string Memory uint64 MemorySwap uint64 CpuShares int AttachStdin bool AttachStdout bool AttachStderr bool PortSpecs []string Tty bool OpenStdin bool StdinOnce bool Env []string Cmd []string Dns []string Image string Volumes map[string]struct{} VolumesFrom string WorkingDir string Entrypoint []string NetworkDisabled bool Privileged bool OomKillDisable bool OomScoreAdj int } State struct { Running bool Pid int ExitCode int StartedAt string Ghost bool } Image string NetworkSettings struct { IPAddress string IPPrefixLen int Gateway string Bridge string PortMapping map[string]map[string]string Ports map[string][]domain.HostIPAndPort } SysInitPath string ResolvConfPath string Volumes map[string]string VolumesRW map[string]bool }
The state of a container as reported by Docker.
type EvaluateServiceRequest ¶
type EvaluateServiceResponse ¶
type HealthCheckRequest ¶
type HostAgent ¶
type HostAgent struct {
// contains filtered or unexported fields
}
HostAgent is an instance of the control center Agent.
func NewHostAgent ¶
func NewHostAgent(options AgentOptions, reg registry.Registry) (*HostAgent, error)
NewHostAgent creates a new HostAgent given a connection string
func (*HostAgent) AckProxySnapshotQuiece ¶
AckProxySnapshotQuiece is called by clients when the snapshot command has shown the service is quieced; the agent returns a response when the snapshot is complete
func (*HostAgent) AttachAndRun ¶
AttachAndRun implements zkdocker.ActionHandler; it attaches to a running container and performs a command as specified by the container's service definition
func (*HostAgent) AttachContainer ¶
func (a *HostAgent) AttachContainer(state *zkservice.ServiceState, serviceID string, instanceID int) (<-chan time.Time, error)
AttachContainer returns a channel that monitors the run state of a given container.
func (*HostAgent) GetEvaluatedService ¶
func (a *HostAgent) GetEvaluatedService(request EvaluateServiceRequest, response *EvaluateServiceResponse) (err error)
func (*HostAgent) GetISvcEndpoints ¶
func (a *HostAgent) GetISvcEndpoints(serviceId string, response *map[string][]applicationendpoint.ApplicationEndpoint) (err error)
func (*HostAgent) GetProxySnapshotQuiece ¶
GetProxySnapshotQuiece blocks until there is a snapshot request to the service
func (*HostAgent) GetServiceBindMounts ¶
GetServiceBindMounts returns the service bindmounts
func (*HostAgent) GetZkInfo ¶
GetZkInfo returns the agent's zookeeper connection string and its poolID
func (*HostAgent) PauseContainer ¶
PauseContainer pauses a running container
func (*HostAgent) ReportHealthStatus ¶
func (a *HostAgent) ReportHealthStatus(req master.HealthStatusRequest, unused *int) error
ReportHealthStatus proxies ReportHealthStatus to the master server.
func (*HostAgent) ReportInstanceDead ¶
func (a *HostAgent) ReportInstanceDead(req master.ServiceInstanceRequest, unused *int) error
ReportInstanceDead proxies ReportInstanceDead to the master server.
func (*HostAgent) RestartContainer ¶
func (a *HostAgent) RestartContainer(cancel <-chan interface{}, serviceID string, instanceID int) error
RestartContainer asynchronously pulls the latest image of a running container before stopping the service. After the service has stopped, the listener will be notified by the event monitor.
func (*HostAgent) ResumeContainer ¶
ResumeContainer resumes a paused container
func (*HostAgent) SendLogMessage ¶
func (a *HostAgent) SendLogMessage(serviceLogInfo ServiceLogInfo, _ *struct{}) (err error)
func (*HostAgent) Start ¶
func (a *HostAgent) Start(shutdown <-chan interface{})
main loop of the HostAgent
func (*HostAgent) StartContainer ¶
func (a *HostAgent) StartContainer(cancel <-chan interface{}, serviceID string, instanceID int) (*zkservice.ServiceState, <-chan time.Time, error)
StartContainer creates a new container and starts. It returns info about the container, and an event monitor to track the running state of the service.
type LBClient ¶
type LBClient struct {
// contains filtered or unexported fields
}
A LBClient implementation.
func (*LBClient) AckProxySnapshotQuiece ¶
AckProxySnapshotQuiece is called by clients when the snapshot command has shown the service is quieced; the agent returns a response when the snapshot is complete
func (*LBClient) GetEvaluatedService ¶
func (a *LBClient) GetEvaluatedService(request EvaluateServiceRequest, response *EvaluateServiceResponse) error
GetEvaluatedService returns a service where an evaluation has been executed against all templated properties.
func (*LBClient) GetISvcEndpoints ¶
func (a *LBClient) GetISvcEndpoints(serviceId string, endpoints *map[string][]applicationendpoint.ApplicationEndpoint) error
GetISvcEndpoints returns a list of controlplane endpoints for the given service endpoint request.
func (*LBClient) GetProxySnapshotQuiece ¶
GetProxySnapshotQuiece blocks until there is a snapshot request to the service
func (*LBClient) GetServiceBindMounts ¶
GetServiceBindMounts returns the service
func (*LBClient) ReportHealthStatus ¶
func (a *LBClient) ReportHealthStatus(req master.HealthStatusRequest, unused *int) error
ReportHealthStatus stores a health check result.
func (*LBClient) ReportInstanceDead ¶
func (a *LBClient) ReportInstanceDead(req master.ServiceInstanceRequest, unused *int) error
ReportInstanceDead removes health check results for an instance.
func (*LBClient) SendLogMessage ¶
func (a *LBClient) SendLogMessage(serviceLogInfo ServiceLogInfo, _ *struct{}) error
SendLogMessage simply outputs the ServiceLogInfo on the serviced master
type LoadBalancer ¶
type LoadBalancer interface { // SendLogMessage allows the proxy to send messages/logs to the master (to be displayed on the serviced master) SendLogMessage(serviceLogInfo ServiceLogInfo, _ *struct{}) error GetISvcEndpoints(serviceId string, endpoints *map[string][]applicationendpoint.ApplicationEndpoint) error // GetProxySnapshotQuiece blocks until there is a snapshot request GetProxySnapshotQuiece(serviceId string, snapshotId *string) error // AckProxySnapshotQuiece is called by clients when the snapshot command has // shown the service is quieced; the agent returns a response when the snapshot is complete AckProxySnapshotQuiece(snapshotId string, unused *interface{}) error // ReportHealthStatus writes the health check status to the cache ReportHealthStatus(req master.HealthStatusRequest, unused *int) error // ReportInstanceDead removes all health checks for the provided instance from the // cache. ReportInstanceDead(req master.ServiceInstanceRequest, unused *int) error // GetEvaluatedService returns a service where an evaluation has been executed against all templated properties. GetEvaluatedService(request EvaluateServiceRequest, response *EvaluateServiceResponse) error // Ping waits for the specified time then returns the server time Ping(waitFor time.Duration, timestamp *time.Time) error }
The API for a service proxy.
type ServiceCache ¶
type ServiceCache struct {
// contains filtered or unexported fields
}
func NewServiceCache ¶
func NewServiceCache(master string) *ServiceCache
func (*ServiceCache) GetEvaluatedService ¶
func (*ServiceCache) Invalidate ¶
func (sc *ServiceCache) Invalidate(serviceID string, instanceID int)
type ServiceInstanceRequest ¶
type ServiceLogInfo ¶
type VIP ¶
type VIP interface { GetAll() []IP Find(ipprefix string) *IP Release(ipaddr, device string) error Bind(ipaddr, device string) error }
VIP is the interface for managing virtual ips
type VirtualIPManager ¶
type VirtualIPManager struct {
// contains filtered or unexported fields
}
VirtualIPManager manages virtual ip bindings
func NewVirtualIPManager ¶
func NewVirtualIPManager(label string) *VirtualIPManager
NewVirtualIPManager instantiates an instance of the VirtualIPManager
func (*VirtualIPManager) Bind ¶
func (v *VirtualIPManager) Bind(ipaddr, device string) error
Bind binds a virtual ip to a device
func (*VirtualIPManager) Find ¶
func (v *VirtualIPManager) Find(ipprefix string) *IP
Find returns the matching binding for the given ip address
func (*VirtualIPManager) GetAll ¶
func (v *VirtualIPManager) GetAll() (ips []IP)
GetAll returns all the bound virtual ips
func (*VirtualIPManager) Release ¶
func (v *VirtualIPManager) Release(ipaddr, device string) error
Release releases the virtual ip binding