daemon

package
v0.0.0-...-d2438c5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEventHook

func NewEventHook(broadcaster EventBroadcaster, logger log.Logger) func(int64, interface{})

NewEventHook forwards to the local events dispatcher an event received from another node.

Types

type APIMetrics

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

func NewAPIMetrics

func NewAPIMetrics(apiDuration HistogramVec, connectedClients GaugeVec) APIMetrics

NewAPIMetrics creates a new APIMetrics with sane defaults

func (APIMetrics) APIDuration

func (a APIMetrics) APIDuration() HistogramVec

APIDuration returns the HistogramVec for collecting api duration metrics

func (APIMetrics) ConnectedClients

func (a APIMetrics) ConnectedClients() GaugeVec

ConnectedClients returns the GaugeVec for collecting the number of connected client metrics

type Actor

type Actor interface {

	// ID returns the unique ID for the actor
	ID() string

	// Types returns the underlying types the actor subscribes to
	Types() []string

	// Write pushes information to the actor
	Write([]byte) error

	// Close the actor
	Close()

	// NoForward decides if messages should be forwarded to the actor
	NoForward() bool

	// Done returns if the actor is done messaging.
	Done() bool
}

Actor defines an broker between event messages and nodes

type ActorGroup

type ActorGroup interface {

	// Add an actor to a group
	Add(a Actor)

	// Prune removes any done actors
	Prune() bool

	// Walk over the actors with in the group one by one (order is not
	// guaranteed).
	Walk(func(Actor) error) error
}

ActorGroup holds a group of actors

type Cluster

type Cluster interface {
	database.DBAccessor
	db.ClusterOpener
	db.ClusterTransactioner
	db.ClusterExclusiveLocker

	// NodeID sets the the node NodeID associated with this cluster instance. It's used for
	// backward-compatibility of all db-related APIs that were written before
	// clustering and don't accept a node NodeID, so in those cases we automatically
	// use this value as implicit node NodeID.
	NodeID(int64)

	// SchemaVersion returns the underlying schema version for the cluster
	SchemaVersion() int

	// Close the database facade.
	Close() error
}

Cluster mediates access to data stored in the cluster dqlite database.

type Daemon

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

Daemon can respond to requests from a shared client.

func New

func New(
	clientCerts []x509.Certificate,
	version string,
	networkAddress, debugAddress string,
	clusterConfigSchema, nodeConfigSchema config.Schema,
	apiExtensions []string,
	apiMetrics APIMetrics,
	apiServices, apiInternalServices []api.Service,
	actorGroup ActorGroup,
	eventBroadcaster EventBroadcaster,
	options ...Option,
) *Daemon

New creates a Daemon with sane defaults

func (*Daemon) APIExtensions

func (d *Daemon) APIExtensions() []string

APIExtensions returns the extensions available to the current daemon

func (*Daemon) APIMetrics

func (d *Daemon) APIMetrics() APIMetrics

APIMetrics returns the metrics for recording metric changes

func (*Daemon) ActorGroup

func (d *Daemon) ActorGroup() ActorGroup

ActorGroup returns a group of actors for event processing

func (*Daemon) ClientCerts

func (d *Daemon) ClientCerts() []x509.Certificate

ClientCerts returns the certificates used locally

func (*Daemon) Cluster

func (d *Daemon) Cluster() Cluster

Cluster returns the underlying Cluster

func (*Daemon) ClusterCerts

func (d *Daemon) ClusterCerts() []x509.Certificate

ClusterCerts returns the network certificates used for the cluster.

func (*Daemon) ClusterConfigSchema

func (d *Daemon) ClusterConfigSchema() config.Schema

ClusterConfigSchema returns the daemon schema for the Cluster

func (*Daemon) Endpoints

func (d *Daemon) Endpoints() Endpoints

Endpoints returns the underlying endpoints that the daemon controls.

func (*Daemon) EventBroadcaster

func (d *Daemon) EventBroadcaster() EventBroadcaster

EventBroadcaster returns a event broadcaster for event processing

func (*Daemon) Gateway

func (d *Daemon) Gateway() Gateway

Gateway returns the underlying Daemon Gateway

func (*Daemon) Init

func (d *Daemon) Init() error

Init the Daemon, creating all the required dependencies.

func (*Daemon) Kill

func (d *Daemon) Kill()

Kill signals the daemon that we want to shutdown, and that any work initiated from this point (e.g. database queries over gRPC) should not be retried in case of failure.

func (*Daemon) Node

func (d *Daemon) Node() Node

Node returns the underlying node database

func (*Daemon) NodeConfigSchema

func (d *Daemon) NodeConfigSchema() config.Schema

NodeConfigSchema returns the daemon schema for the local Node

func (*Daemon) Nonce

func (d *Daemon) Nonce() string

Nonce returns the nonce for the daemon

func (*Daemon) Operations

func (d *Daemon) Operations() Operations

Operations return the underlying operational tasks associated with the current daemon

func (*Daemon) Register

func (d *Daemon) Register(tasks []SchedulerTask) error

Register tasks or system services for the daemon

func (*Daemon) RegisterChan

func (d *Daemon) RegisterChan() <-chan struct{}

RegisterChan returns a channel that blocks until all the registered tasks have happened for the Daemon

func (*Daemon) Schedules

func (d *Daemon) Schedules() Schedules

Schedules return the underlying schedule tasks associated with the current daemon

func (*Daemon) SetupChan

func (d *Daemon) SetupChan() <-chan struct{}

SetupChan returns a channel that blocks until setup has happened from the Daemon

func (*Daemon) ShutdownChan

func (d *Daemon) ShutdownChan() <-chan struct{}

ShutdownChan returns a channel that blocks until shutdown has happened from the Daemon.

func (*Daemon) State

func (d *Daemon) State() *state.State

State creates a new State instance liked to our internal db and os.

func (*Daemon) Stop

func (d *Daemon) Stop() error

Stop stops the shared daemon.

func (*Daemon) UnsafeSetCluster

func (d *Daemon) UnsafeSetCluster(cluster Cluster)

UnsafeSetCluster forces a cluster onto the daemon.

func (*Daemon) UnsafeShutdown

func (d *Daemon) UnsafeShutdown()

UnsafeShutdown forces an automatic shutdown of the Daemon

func (*Daemon) Version

func (d *Daemon) Version() string

Version returns the current version of the daemon

type Endpoints

type Endpoints interface {

	// Up brings up all configured endpoints and starts accepting HTTP requests.
	Up() error

	// Down brings down all endpoints and stops serving HTTP requests.
	Down() error

	// NetworkAddress returns the network address of the network endpoint, or an
	// empty string if there's no network endpoint
	NetworkAddress() string

	// NetworkPrivateKey returns the private key of the TLS certificate used by the
	// network endpoint.
	NetworkPrivateKey() []byte

	// NetworkCert returns the full TLS certificate information for this endpoint.
	NetworkCert() *cert.Info

	// NetworkPublicKey returns the public key of the TLS certificate used by the
	// network endpoint.
	NetworkPublicKey() []byte

	// NetworkUpdateAddress updates the address for the network endpoint,
	// shutting it down and restarting it.
	NetworkUpdateAddress(string) error

	// PprofUpdateAddress updates the address for the pprof endpoint, shutting
	// it down and restarting it.
	PprofUpdateAddress(string) error

	// NetworkUpdateCert updates the cert for the network endpoint,
	// shutting it down and restarting it.
	NetworkUpdateCert(*cert.Info) error
}

Endpoints are in charge of bringing up and down the HTTP endpoints for serving the RESTful API.

type EventBroadcaster

type EventBroadcaster interface {

	// Dispatch an event to other parts of the underlying system
	Dispatch(map[string]interface{}) error
}

EventBroadcaster defines a way to broadcast events to other internal parts of the system.

type Gateway

type Gateway interface {

	// Init the gateway, creating a new raft factory and server (if this node is a
	// database node), and a dialer.
	Init(*cert.Info) error

	// RaftNodes returns information about the nodes that a currently part of
	// the raft cluster, as configured in the raft log. It returns an error if this
	// node is not the leader.
	RaftNodes() ([]db.RaftNode, error)

	// Raft returns the raft instance
	Raft() RaftInstance

	// DB returns the database node of the cluster
	DB() Node

	// IsDatabaseNode returns true if this gateway also run acts a raft database
	// node.
	IsDatabaseNode() bool

	// Cert returns the currently available cert in the gateway
	Cert() *cert.Info

	// LeaderAddress returns the address of the current raft leader.
	LeaderAddress() (string, error)

	// Reset the gateway, shutting it down and starting against from scratch
	// using the given certificate.
	//
	// This is used when disabling clustering on a node.
	Reset(cert *cert.Info) error

	// Clustered returns if the Gateway is a raft node or is not clustered
	Clustered() bool

	// WaitLeadership will wait for the raft node to become leader. Should only
	// be used by Bootstrap, since we know that we'll self elect.
	WaitLeadership() error

	// WaitUpgradeNotification waits for a notification from another node that all
	// nodes in the cluster should now have been upgraded and have matching schema
	// and API versions.
	WaitUpgradeNotification()

	// HandlerFuncs returns the HTTP handlers that should be added to the REST API
	// endpoint in order to handle database-related requests.
	//
	// There are two handlers, one for the /internal/raft endpoint and the other
	// for /internal/db, which handle respectively raft and gRPC-SQL requests.
	//
	// These handlers might return 404, either because this node is a
	// non-clustered node not available over the network or because it is not a
	// database node part of the dqlite cluster.
	HandlerFuncs() map[string]http.HandlerFunc

	// ServerStore returns a dqlite server store that can be used to lookup the
	// addresses of known database nodes.
	ServerStore() querycluster.ServerStore

	// DialFunc returns a dial function that can be used to connect to one of the
	// dqlite nodes.
	DialFunc() dqlite.DialFunc

	// Context returns a cancellation context to pass to dqlite.NewDriver as
	// option.
	//
	// This context gets cancelled by Gateway.Kill() and at that point any
	// connection failure won't be retried.
	Context() context.Context

	// Kill is an API that the daemon calls before it actually shuts down and calls
	// Shutdown(). It will abort any ongoing or new attempt to establish a SQL gRPC
	// connection with the dialer (typically for running some pre-shutdown
	// queries).
	Kill()

	// Shutdown this gateway, stopping the gRPC server and possibly the raft factory.
	Shutdown() error
}

Gateway mediates access to the dqlite cluster using a gRPC SQL client, and possibly runs a dqlite replica on this node (if we're configured to do so).

type Gauge

type Gauge interface {
	// Inc increments the Gauge by 1. Use Add to increment it by arbitrary
	// values.
	Inc()
}

Gauge is a Metric that represents a single numerical value that can arbitrarily go up and down.

type GaugeVec

type GaugeVec interface {
	// WithLabelValues works as GetMetricWithLabelValues, but panics where
	// GetMetricWithLabelValues would have returned an error. By not returning an
	// error, WithLabelValues allows shortcuts like
	//     myVec.WithLabelValues("404", "GET").Add(42)
	WithLabelValues(lvs ...string) Gauge
}

GaugeVec is a Collector that bundles a set of Gauges that all share the same Desc, but have different values for their variable labels.

type Histogram

type Histogram interface {
	// Observe adds a single observation to the histogram.
	Observe(float64)
}

A Histogram counts individual observations from an event or sample stream in configurable buckets. Similar to a summary, it also provides a sum of observations and an observation count.

type HistogramVec

type HistogramVec interface {
	// WithLabelValues works as GetMetricWithLabelValues, but panics where
	// GetMetricWithLabelValues would have returned an error. By not returning an
	// error, WithLabelValues allows shortcuts like
	//     myVec.WithLabelValues("404", "GET").Observe(42.21)
	WithLabelValues(lvs ...string) Histogram
}

HistogramVec is a Collector that bundles a set of Histograms that all share the same Desc, but have different values for their variable labels.

type Node

type Node interface {
	database.DBAccessor
	db.NodeOpener
	db.NodeTransactioner

	// Dir returns the directory of the underlying database file.
	Dir() string

	// Close the database facade.
	Close() error
}

Node mediates access to the data stored in the node-local SQLite database.

type OS

type OS interface {

	// Init our internal data structures.
	Init(fsys.FileSystem) error

	// LocalDatabasePath returns the path of the local database file.
	LocalDatabasePath() string

	// GlobalDatabaseDir returns the path of the global database directory.
	GlobalDatabaseDir() string

	// GlobalDatabasePath returns the path of the global database SQLite file
	// managed by dqlite.
	GlobalDatabasePath() string

	// LocalNoncePath returns the path of the local nonce file.
	LocalNoncePath() string

	// VarDir represents the Data directory (e.g. /var/lib/therm/).
	VarDir() string

	// Hostname returns the host name reported by the kernel.
	Hostname() (string, error)

	// HostNames will generate a list of names for which the certificate will be
	// valid.
	// This will include the hostname and ip address
	HostNames() ([]string, error)

	// User returns the current user.
	User() (*user.User, error)
}

OS is a high-level facade for accessing all operating-system level functionality that therm uses.

type Operations

type Operations interface {

	// Add an operation to the collection
	Add(*operations.Operation) error

	// GetOpByPartialID retrieves an op of the operation from the collection by a
	// partial id. As long as the prefix matches an id then it will return that
	// operation. If the id matches multiple ids then it will return an ambiguous
	// error.
	GetOpByPartialID(string) (operations.Op, error)

	// DeleteOp attempts to kill an operation by the id
	DeleteOp(string) error

	// WaitOp for an operation to be completed
	WaitOp(string, time.Duration) (bool, error)

	// Walk over a collection of operations
	Walk(func(operations.Op) error) error
}

Operations defines an interface for interacting with a series of operations

type Option

type Option func(*options)

Option to be passed to Connect to customize the resulting instance.

func WithDiscoverable

func WithDiscoverable(flag bool) Option

WithDiscoverable sets if the deamon is discoverable for discovery service

func WithFileSystem

func WithFileSystem(fileSystem fsys.FileSystem) Option

WithFileSystem sets the fileSystem on the options

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets the logger on the option

func WithOS

func WithOS(os OS) Option

WithOS sets the os on the options

type RaftInstance

type RaftInstance interface {

	// MembershipChanger returns the underlying rafthttp.Layer, which can be
	// used to change the membership of this node in the cluster.
	MembershipChanger() raftmembership.Changer
}

RaftInstance is a specific wrapper around raft.Raft, which also holds a reference to its network transport and dqlite FSM.

type Response

type Response interface {

	// Render the response with a response writer.
	Render(http.ResponseWriter) error
}

Response defines a return value from a http request. The response then can be rendered.

type SchedulerTask

type SchedulerTask interface {

	// Run setups up the given schedule
	Run() (task.Func, task.Schedule)
}

SchedulerTask defines a task that can be run repeatedly

type Schedules

type Schedules interface {

	// Add an task to the schedule
	Add(*schedules.Task) error

	// Remove a scheduled task
	Remove(string) error

	// GetTsk returns a scheduled task
	GetTsk(string) (schedules.Tsk, error)

	// Walk over a set of scheduled tasks
	Walk(func(schedules.Tsk) error) error
}

Schedules defines an interface for interacting with a series of tasks

type Service

type Service interface {

	// Get handles GET requests
	Get(Daemon, *http.Request) Response

	// Put handles PUT requests
	Put(Daemon, *http.Request) Response

	// Post handles POST requests
	Post(Daemon, *http.Request) Response

	// Delete handles DELETE requests
	Delete(Daemon, *http.Request) Response

	// Patch handles PATCH requests
	Patch(Daemon, *http.Request) Response

	// Name returns the serialisable service name.
	// The name has to conform to RFC 3986
	Name() string
}

Service represents a endpoint that can perform http actions upon

Jump to

Keyboard shortcuts

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