server

package
Version: v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2017 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OpenEBS can be used as a persistence mechanism for
	// any type of compute instance
	AnyInstance = "any-compute"

	// TODO We shall see how to construct an Availability Zone
	AnyZone = "any-zone"
)
View Source
const (
	// ErrInvalidMethod is used if the HTTP method is not supported
	ErrInvalidMethod = "Invalid method"
)

Variables

This section is empty.

Functions

func LevelFilter

func LevelFilter() *logutils.LevelFilter

LevelFilter returns a LevelFilter that is configured with the log levels that we use.

func ValidateLevelFilter

func ValidateLevelFilter(minLevel logutils.LogLevel, filter *logutils.LevelFilter) bool

ValidateLevelFilter verifies that the log levels within the filter are valid.

Types

type Addresses

type Addresses struct {
	HTTP string `mapstructure:"http"`
}

Addresses encapsulates all of the addresses we bind to for various network services. Everything is optional and defaults to BindAddr.

func (*Addresses) Merge

func (a *Addresses) Merge(b *Addresses) *Addresses

Merge is used to merge two address configs together.

type AdvertiseAddrs

type AdvertiseAddrs struct {
	HTTP string `mapstructure:"http"`
}

AdvertiseAddrs is used to control the addresses we advertise out for different network services. All are optional and default to BindAddr and their default Port.

func (*AdvertiseAddrs) Merge

Merge merges two advertise addrs configs together.

type HTTPCodedError

type HTTPCodedError interface {
	error
	Code() int
}

HTTPCodedError is used to provide the HTTP error code

func CodedError

func CodedError(c int, s string) HTTPCodedError

type HTTPServer

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

HTTPServer is used to wrap Maya server and expose it over an HTTP interface

func NewHTTPServer

func NewHTTPServer(maya *MayaServer, config *MayaConfig, logOutput io.Writer) (*HTTPServer, error)

NewHTTPServer starts new HTTP server over Maya server

func (*HTTPServer) GetVolumePlugin

func (s *HTTPServer) GetVolumePlugin(name string) (volume.VolumeInterface, error)

GetVolumePlugin is a pass through function that provides a particular volume plugin

func (*HTTPServer) MetaSpecificRequest

func (s *HTTPServer) MetaSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) Shutdown

func (s *HTTPServer) Shutdown()

Shutdown is used to shutdown the HTTP server

func (*HTTPServer) VolumeSpecificRequest

func (s *HTTPServer) VolumeSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

VolumeSpecificRequest is a http handler implementation. The URL path is parsed to match specific implementations. TODO

Should it return specific types ?

type LogHandler

type LogHandler interface {
	HandleLog(string)
}

LogHandler interface is used for clients that want to subscribe to logs, for example to stream them over an IPC mechanism

type LogWriter

type LogWriter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

LogWriter implements io.Writer so it can be used as a log sink. It maintains a circular buffer of logs, and a set of handlers to which it can stream the logs to.

func NewLogWriter

func NewLogWriter(buf int) *LogWriter

NewLogWriter creates a logWriter with the given buffer capacity

func (*LogWriter) DeregisterHandler

func (l *LogWriter) DeregisterHandler(lh LogHandler)

DeregisterHandler removes a LogHandler and prevents more invocations

func (*LogWriter) RegisterHandler

func (l *LogWriter) RegisterHandler(lh LogHandler)

RegisterHandler adds a log handler to receive logs, and sends the last buffered logs to the handler

func (*LogWriter) Write

func (l *LogWriter) Write(p []byte) (n int, err error)

Write is used to accumulate new logs

type MayaConfig

type MayaConfig struct {
	// Region is the region this Maya server is supposed to deal in.
	// Defaults to global.
	Region string `mapstructure:"region"`

	// Datacenter is the datacenter this Maya server is supposed to deal in.
	// Defaults to dc1
	Datacenter string `mapstructure:"datacenter"`

	// NodeName is the name we register as. Defaults to hostname.
	NodeName string `mapstructure:"name"`

	// DataDir is the directory to store Maya server's state in
	DataDir string `mapstructure:"data_dir"`

	// LogLevel is the level of the logs to putout
	LogLevel string `mapstructure:"log_level"`

	// BindAddr is the address on which maya's services will
	// be bound. If not specified, this defaults to 127.0.0.1.
	BindAddr string `mapstructure:"bind_addr"`

	// EnableDebug is used to enable debugging HTTP endpoints
	EnableDebug bool `mapstructure:"enable_debug"`

	// Mayaserver can make use of various providers e.g. Nomad,
	// k8s etc
	ServiceProvider string `mapstructure:"service_provider"`

	// Ports is used to control the network ports we bind to.
	Ports *Ports `mapstructure:"ports"`

	// Addresses is used to override the network addresses we bind to.
	//
	// Use normalizedAddrs if you need the host+port to bind to.
	Addresses *Addresses `mapstructure:"addresses"`

	// AdvertiseAddrs is used to control the addresses we advertise.
	AdvertiseAddrs *AdvertiseAddrs `mapstructure:"advertise"`

	// LeaveOnInt is used to gracefully leave on the interrupt signal
	LeaveOnInt bool `mapstructure:"leave_on_interrupt"`

	// LeaveOnTerm is used to gracefully leave on the terminate signal
	LeaveOnTerm bool `mapstructure:"leave_on_terminate"`

	// EnableSyslog is used to enable sending logs to syslog
	EnableSyslog bool `mapstructure:"enable_syslog"`

	// SyslogFacility is used to control the syslog facility used.
	SyslogFacility string `mapstructure:"syslog_facility"`

	// Version information is set at compilation time
	Revision          string
	Version           string
	VersionPrerelease string

	// List of config files that have been loaded (in order)
	Files []string `mapstructure:"-"`

	// HTTPAPIResponseHeaders allows users to configure the Nomad http agent to
	// set arbritrary headers on API responses
	HTTPAPIResponseHeaders map[string]string `mapstructure:"http_api_response_headers"`
	// contains filtered or unexported fields
}

MayaConfig is the configuration for Maya server.

func DefaultMayaConfig

func DefaultMayaConfig() *MayaConfig

DefaultMayaConfig is a the baseline configuration for Maya server

func LoadMayaConfig

func LoadMayaConfig(path string) (*MayaConfig, error)

LoadMayaConfig loads the configuration at the given path, regardless if its a file or directory.

func LoadMayaConfigDir

func LoadMayaConfigDir(dir string) (*MayaConfig, error)

LoadMayaConfigDir loads all the configurations in the given directory in alphabetical order.

func ParseMayaConfig

func ParseMayaConfig(r io.Reader) (*MayaConfig, error)

ParseMayaConfig parses the config from the given io.Reader.

Due to current internal limitations, the entire contents of the io.Reader will be copied into memory first before parsing.

func ParseMayaConfigFile

func ParseMayaConfigFile(path string) (*MayaConfig, error)

ParseMayaConfigFile parses the given path as a config file.

func (*MayaConfig) Listener

func (mc *MayaConfig) Listener(proto, addr string, port int) (net.Listener, error)

Listener can be used to get a new listener using a custom bind address. If the bind provided address is empty, the BindAddr is used instead.

func (*MayaConfig) Merge

func (mc *MayaConfig) Merge(b *MayaConfig) *MayaConfig

Merge merges two configurations & returns a new one.

func (*MayaConfig) NormalizeAddrs

func (mc *MayaConfig) NormalizeAddrs() error

NormalizeAddrs normalizes Addresses and AdvertiseAddrs to always be initialized and have sane defaults.

type MayaServer

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

MayaServer is a long running stateless daemon that runs at openebs maya master(s)

func NewMayaServer

func NewMayaServer(config *MayaConfig, logOutput io.Writer) (*MayaServer, error)

NewMayaServer is used to create a new maya server with the given configuration

func (*MayaServer) BootstrapPlugins

func (ms *MayaServer) BootstrapPlugins() error

TODO Create a Bootstrap interface that facilitates initialization Create another Bootstraped interface that provides the initialized instances Perhaps at lib/bootstrap MayaServer struct will make use of above interfaces & hence specialized structs that cater to bootstraping & bootstraped features.

NOTE:

The current implementation is tightly coupled & cannot be unit tested.

func (*MayaServer) GetVolumePlugin

func (ms *MayaServer) GetVolumePlugin(name string) (volume.VolumeInterface, error)

GetVolumePlugin is an accessor that fetches a volume.VolumeInterface instance The volume.VolumeInterface should have been initialized earlier.

func (*MayaServer) Leave

func (ms *MayaServer) Leave() error

Leave is used gracefully exit.

func (*MayaServer) Shutdown

func (ms *MayaServer) Shutdown() error

Shutdown is used to terminate MayaServer.

type Ports

type Ports struct {
	HTTP int `mapstructure:"http"`
}

Ports encapsulates the various ports we bind to for network services. If any are not specified then the defaults are used instead.

func (*Ports) Merge

func (a *Ports) Merge(b *Ports) *Ports

Merge is used to merge two port configurations.

type SyslogWrapper

type SyslogWrapper struct {
	L    gsyslog.Syslogger
	Filt *logutils.LevelFilter
}

SyslogWrapper is used to cleaup log messages before writing them to a Syslogger. Implements the io.Writer interface.

func (*SyslogWrapper) Write

func (s *SyslogWrapper) Write(p []byte) (int, error)

Write is used to implement io.Writer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL