cluster

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: BSD-2-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultEtcdTimeout = 3 * time.Second
)

Variables

View Source
var ConfigEnvPaths = [][]string{}/* 162 elements not displayed */
View Source
var TarantoolSchema = []SchemaPath{}/* 162 elements not displayed */

Functions

func ConnectEtcd added in v1.3.0

func ConnectEtcd(opts EtcdOpts) (*clientv3.Client, error)

ConnectEtcd creates a new client object for a etcd from the specified options.

func HasInstance

func HasInstance(cluster ClusterConfig, name string) bool

HasInstance returns true if an instance with the name exists in the config.

func Instances

func Instances(cluster ClusterConfig) []string

Instances returns a list of instance names from the cluster config.

func Validate added in v1.3.0

func Validate(config *Config, schema []SchemaPath) error

Validate validates a configuration with the schema.

Types

type AllowedValidator added in v1.3.0

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

AllowedValidator allows a set of values.

func MakeAllowedValidator added in v1.3.0

func MakeAllowedValidator(validator Validator, allowed []any) AllowedValidator

MakeAllowedValidator creates a new AllowedValidator object.

func (AllowedValidator) Validate added in v1.3.0

func (validator AllowedValidator) Validate(value any) (any, error)

Validate returns a validated value or an error.

type AnyValidator added in v1.3.0

type AnyValidator struct {
}

AnyValidator allows any values, but not nil.

func (AnyValidator) Validate added in v1.3.0

func (validator AnyValidator) Validate(value any) (any, error)

Validate returns the value if it is not nil or an error.

type ArrayValidator added in v1.3.0

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

ArrayValidator allows an array of values.

func MakeArrayValidator added in v1.3.0

func MakeArrayValidator(itemValidator Validator) ArrayValidator

MakeArrayValidator create a new ArrayValidator object with a validator for values.

func (ArrayValidator) Validate added in v1.3.0

func (validator ArrayValidator) Validate(value any) (any, error)

Validate returns a validated array or an error.

type BooleanValidator added in v1.3.0

type BooleanValidator struct {
}

BooleanValidator allows only boolean-compatible values.

func (BooleanValidator) Validate added in v1.3.0

func (validator BooleanValidator) Validate(value any) (any, error)

Validate returns a boolean value or an error.

type ClusterConfig

type ClusterConfig struct {
	Config struct {
		Etcd struct {
			Endpoints []string `yaml:"endpoints"`
			Username  string   `yaml:"username"`
			Password  string   `yaml:"password"`
			Prefix    string   `yaml:"prefix"`
			Ssl       struct {
				KeyFile    string `yaml:"ssl_key"`
				CertFile   string `yaml:"cert_file"`
				CaPath     string `yaml:"ca_path"`
				CaFile     string `yaml:"ca_file"`
				VerifyPeer bool   `yaml:"verify_peer"`
				VerifyHost bool   `yaml:"verify_host"`
			} `yaml:"ssl"`
			Http struct {
				Request struct {
					Timeout float64 `yaml:"timeout"`
				} `yaml:"request"`
			} `yaml:"http"`
		} `yaml:"etcd"`
	} `yaml:"config"`
	// RawConfig is a configuration of the global scope.
	RawConfig *Config `yaml:"-"`
	// Groups are parsed configurations per a group.
	Groups map[string]GroupConfig
}

ClusterConfig describes a cluster configuration.

func GetClusterConfig

func GetClusterConfig(path string) (ClusterConfig, error)

GetClusterConfig returns a cluster configuration loaded from a path to a config file. It uses a a config file, etcd and default environment variables as sources. The function returns a cluster config as is, without merging of settings from scopes: global, group, replicaset, instance.

func MakeClusterConfig

func MakeClusterConfig(config *Config) (ClusterConfig, error)

MakeClusterConfig creates a ClusterConfig object from a configuration.

func ReplaceInstanceConfig added in v1.3.0

func ReplaceInstanceConfig(cconfig ClusterConfig,
	instance string, iconfig *Config) (ClusterConfig, error)

ReplaceInstanceConfig replaces an instance configuration.

func (*ClusterConfig) UnmarshalYAML

func (config *ClusterConfig) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML helps to unmarshal a ClusterConfig object from YAML.

type Collector

type Collector interface {
	// Collect collects a configuration or returns an error.
	Collect() (*Config, error)
}

Collector interface must be implemented by a configuration source collector.

type Config

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

Config is a container for deserialized configuration.

func Instantiate

func Instantiate(cluster ClusterConfig, name string) *Config

Instantiate returns a fetched instance config from the cluster config. If the cluster config has the instance then it returns a merged config of the instance from scopes: global, group, replicaset, instance. If the cluster config has not the instance then it returns a global scope of the cluster config.

func NewConfig

func NewConfig() *Config

NewConfig creates a new empty configuration.

func (*Config) Elems

func (config *Config) Elems(path []string) ([]string, error)

Elems returns a list of an elements for a path.

func (*Config) ForEach

func (config *Config) ForEach(path []string, fun func(path []string, value any))

ForEach iterates over each value in the configuration.

func (*Config) Get

func (config *Config) Get(path []string) (any, error)

Get returns a value from a configuration path.

func (*Config) Merge

func (config *Config) Merge(low *Config)

Merge merges a configuration to the current. The outside configuration has a low priority.

func (*Config) Set

func (config *Config) Set(path []string, value any) error

Set sets a value to a configuration path.

func (*Config) String

func (config *Config) String() string

String returns a string representation of the configuration. Actually it is a valid YAML.

func (*Config) UnmarshalYAML

func (config *Config) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML helps to unmarshal the configuration from a YAML document.

type ConfigPublisher added in v1.3.0

type ConfigPublisher interface {
	// Publish publisher the configuration or returns an error.
	Publish(config *Config) error
}

ConfigPublisher interface must be implemented by a config publisher.

type DataPublisher added in v1.3.0

type DataPublisher interface {
	// Publish publishes the data or returns an error.
	Publish(data []byte) error
}

DataPublisher interface must be implemented by a raw data publisher.

type EnvCollector

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

EnvCollector collects a configuration from environment variables.

func NewEnvCollector

func NewEnvCollector(formatter func(path []string) string) EnvCollector

NewEnvCollector creates a new EnvCollector. A path to an environment variable format function must be specified.

func (EnvCollector) Collect

func (collector EnvCollector) Collect() (*Config, error)

Collect collects a configuration from environment variables.

type EtcdCollector added in v1.3.0

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

EtcdCollector collects data from a etcd connection.

func NewEtcdCollector added in v1.3.0

func NewEtcdCollector(getter EtcdGetter, prefix string, timeout time.Duration) EtcdCollector

NewEtcdCollector creates a new collector for etcd from the path.

func (EtcdCollector) Collect added in v1.3.0

func (collector EtcdCollector) Collect() (*Config, error)

Collect collects a configuration from the specified path with the specified timeout.

type EtcdDataPublisher added in v1.3.0

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

EtcdDataPublisher publishes a data into etcd.

func NewEtcdDataPublisher added in v1.3.0

func NewEtcdDataPublisher(getter EtcdTxnGetter,
	prefix string, timeout time.Duration) EtcdDataPublisher

NewEtcdDataPublisher creates a new EtcdDataPublisher object to publish a data to etcd with the prefix during the timeout.

func (EtcdDataPublisher) Publish added in v1.3.0

func (publisher EtcdDataPublisher) Publish(data []byte) error

Publish publishes the configuration into etcd to the given prefix.

type EtcdGetter added in v1.3.0

type EtcdGetter interface {
	// Get retrieves key-value pairs for a key.
	Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error)
}

EtcdGetter is the interface that wraps get from etcd method.

type EtcdOpts added in v1.3.0

type EtcdOpts struct {
	// Endpoints a slice of endpoints to connect.
	Endpoints []string
	// Prefix is a configuration prefix.
	Prefix string
	// Username is a user name for authorization
	Username string
	// Password is a password for authorization
	Password string
	// KeyFile is a path to a private SSL key file.
	KeyFile string
	// CertFile is a path to an SSL certificate file.
	CertFile string
	// CaPath is a path to a trusted certificate authorities (CA) directory.
	CaPath string
	// CaFile is a path to a trusted certificate authorities (CA) file.
	CaFile string
	// SkipHostVerify controls whether a client verifies the server's
	// certificate chain and host name. This is dangerous option so by
	// default it is false.
	SkipHostVerify bool
	// Timeout is a timeout for actions.
	Timeout time.Duration
}

EtcdOpts is a way to configure a etcd client.

func MakeEtcdOptsFromUrl added in v1.3.0

func MakeEtcdOptsFromUrl(uri *url.URL) (EtcdOpts, error)

MakeEtcdOptsFromUrl creates etcd options from a URL.

type EtcdTxnGetter added in v1.3.0

type EtcdTxnGetter interface {
	EtcdGetter
	// Txn creates a transaction.
	Txn(ctx context.Context) clientv3.Txn
}

EtcdUpdater is the interface that adds Txn method to EtcdGetter.

type FileCollector

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

FileCollector collects data from a YAML file.

func NewFileCollector

func NewFileCollector(path string) FileCollector

NewFileCollector create a new file collector for a path.

func (FileCollector) Collect

func (collector FileCollector) Collect() (*Config, error)

Collect collects a configuration from a file located at a specified path.

type FileDataPublisher added in v1.3.0

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

FileDataPublisher publishes a data into a file as is.

func NewFileDataPublisher added in v1.3.0

func NewFileDataPublisher(path string) FileDataPublisher

NewFileDataPublisher creates a new FileDataPublisher object to publish a data into a file for the given path.

func (FileDataPublisher) Publish added in v1.3.0

func (publisher FileDataPublisher) Publish(data []byte) error

Publish publishes the data to a file for the given path.

type GroupConfig

type GroupConfig struct {
	// RawConfig is a raw configuration of the group scope.
	RawConfig *Config `yaml:"-"`
	// Replicasets are parsed configurations per a replicaset.
	Replicasets map[string]ReplicasetConfig
}

GroupConfig describes a group configuration.

func (*GroupConfig) UnmarshalYAML

func (config *GroupConfig) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML helps to unmarshal a GroupConfig object from YAML.

type InstanceConfig

type InstanceConfig struct {
	// RawConfig is a raw configuration of the instance scope.
	RawConfig *Config `yaml:"-"`
}

InstanceConfig describes an instance configuration.

func GetInstanceConfig

func GetInstanceConfig(cluster ClusterConfig, instance string) (InstanceConfig, error)

GetInstanceConfig returns a full configuration for an instance with the name from a cluster config. It merges the configuration from all configured sources and scopes: environment, global, group, replicaset, instance.

func MakeInstanceConfig

func MakeInstanceConfig(config *Config) (InstanceConfig, error)

MakeInstanceConfig creates an InstanceConfig object from a configuration.

func (*InstanceConfig) UnmarshalYAML

func (config *InstanceConfig) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML helps to unmarshal an InstanceConfig object from YAML.

type IntegerValidator added in v1.3.0

type IntegerValidator struct {
}

IntegerValidator allows only integer-compatible values.

func (IntegerValidator) Validate added in v1.3.0

func (validator IntegerValidator) Validate(value any) (any, error)

Validate returns an integer value or an error.

type MapValidator added in v1.3.0

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

MapValidator allows only a map.

func MakeMapValidator added in v1.3.0

func MakeMapValidator(key Validator, value Validator) MapValidator

MakeMapValidator create a new MapValidator object with specified a key and a value validator.

func (MapValidator) Validate added in v1.3.0

func (validator MapValidator) Validate(value any) (any, error)

Validate returns a validated map or an error.

type NotExistError added in v1.3.0

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

NotExistError error type for non-existing path.

func (NotExistError) Error added in v1.3.0

func (e NotExistError) Error() string

Error - error interface implementation for NotExistError.

type NumberValidator added in v1.3.0

type NumberValidator struct {
}

NumberValidator allows only number-compatible values.

func (NumberValidator) Validate added in v1.3.0

func (validator NumberValidator) Validate(value any) (any, error)

Validate returns a number value or an error.

type RecordValidator added in v1.3.0

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

RecordValidator allows only a record values.

func MakeRecordValidator added in v1.3.0

func MakeRecordValidator(items map[string]Validator) RecordValidator

MakeRecordValidator create a new RecordValidator object with a specified record schema.

func (RecordValidator) Validate added in v1.3.0

func (validator RecordValidator) Validate(value any) (any, error)

Validate returns a validated record or an error.

type ReplicasetConfig

type ReplicasetConfig struct {
	// RawConfig is a raw configuration of the replicaset scope.
	RawConfig *Config `yaml:"-"`
	// Instances are configurations at an instance scope.
	Instances map[string]InstanceConfig
}

ReplicasetConfig describes a replicaset configuration.

func (*ReplicasetConfig) UnmarshalYAML

func (config *ReplicasetConfig) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML helps to unmarshal a ReplicasetConfig object from YAML.

type SchemaPath added in v1.3.0

type SchemaPath struct {
	// Path of a configuration value.
	Path []string
	// Validator to validate the configuration value.
	Validator Validator
}

SchemaPath describes a validation schema for a configuration.

type SequenceValidator added in v1.3.0

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

SequenceValidator allows to combine validators in a sequence.

func MakeSequenceValidator added in v1.3.0

func MakeSequenceValidator(validators ...Validator) SequenceValidator

MakeSequenceValidator creates a new SequenceValidator object.

func (SequenceValidator) Validate added in v1.3.0

func (validator SequenceValidator) Validate(value any) (any, error)

Validate returns a first validated value from the sequence or an error.

type StringValidator added in v1.3.0

type StringValidator struct {
}

StringValidator allows only string-compatible values.

func (StringValidator) Validate added in v1.3.0

func (validator StringValidator) Validate(value any) (any, error)

Validate returns a string value or an error.

type ValidateError added in v1.3.0

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

ValidateError describes a schema validation error.

func (ValidateError) Error added in v1.3.0

func (err ValidateError) Error() string

Error returns a string representation of the validation error.

func (ValidateError) Path added in v1.3.0

func (err ValidateError) Path() []string

Path returns a schema path to a configuration value.

func (ValidateError) Unwrap added in v1.3.0

func (err ValidateError) Unwrap() []error

Error returns a list of errors for the corresponding path.

type Validator added in v1.3.0

type Validator interface {
	// Validate validates the value and returns a validated one.
	Validate(value any) (any, error)
}

Validator validates a value.

type YamlCollector

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

YamlCollector collects a configuration from YAML data.

func NewYamlCollector

func NewYamlCollector(data []byte) YamlCollector

NewYamlCollector create a new YAML collector.

func (YamlCollector) Collect

func (collector YamlCollector) Collect() (*Config, error)

Collect collects a configuration from YAML data.

type YamlConfigPublisher added in v1.3.0

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

YamlConfigPublisher publishes a configuration as YAML via the base publisher.

func NewYamlConfigPublisher added in v1.3.0

func NewYamlConfigPublisher(publisher DataPublisher) YamlConfigPublisher

NewYamlConfigPublisher creates a new YamlConfigPublisher object to publish a configuration via the publisher.

func (YamlConfigPublisher) Publish added in v1.3.0

func (publisher YamlConfigPublisher) Publish(config *Config) error

Publish publishes the configuration as YAML data.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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