spec

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ComponentTSMeta    = "ts-meta"
	ComponentTSSql     = "ts-sql"
	ComponentTSStore   = "ts-store"
	ComponentTSServer  = "ts-server"
	ComponentTSMonitor = "ts-monitor"
	ComponentGrafana   = "grafana"
)

Components names

View Source
const (
	OpenGeminiPackageCacheDir = "packages"
	OpenGeminiClusterDir      = "clusters"
)

the subdirectory names

View Source
const (

	// BackupDirName is the directory to save backup files.
	BackupDirName = "backup"
)
View Source
const (
	ComponentOpenGemini = "openGemini"
)

Components sources

View Source
const (
	// TempConfigPath is the sub path where generated temporary configs are stored
	TempConfigPath = "config-cache"
)

Variables

View Source
var (

	// ErrTopologyReadFailed is ErrTopologyReadFailed
	ErrTopologyReadFailed = errNSTopolohy.NewType("read_failed", utils.ErrTraitPreCheck)
	// ErrTopologyParseFailed is ErrTopologyParseFailed
	ErrTopologyParseFailed = errNSTopolohy.NewType("parse_failed", utils.ErrTraitPreCheck)
)
View Source
var (

	// ErrCreateDirFailed is ErrCreateDirFailed
	ErrCreateDirFailed = errNS.NewType("create_dir_failed")
	// ErrSaveMetaFailed is ErrSaveMetaFailed
	ErrSaveMetaFailed = errNS.NewType("save_meta_failed")
	// ErrSaveScaleOutFileFailed is ErrSaveMetaFailed
	ErrSaveScaleOutFileFailed = errNS.NewType("save_scale-out_lock_failed")
)
View Source
var (
	ErrUserOrGroupInvalid = errors.New(`linux username and groupname must start with a lower case letter or an underscore, ` +
		`followed by lower case letters, digits, underscores, or dashes. ` +
		`Usernames may only be up to 32 characters long. ` +
		`Groupnames may only be up to 16 characters long.`)
)

pre defined error types

View Source
var ErrorCheckConfig = errors.New("check config failed")

ErrorCheckConfig represent error occurred in config check stage

View Source
var (
	RoleMonitor = "monitor"
)

Functions

func Abs

func Abs(user, path string) string

Abs returns the absolute path

func AllComponentNames

func AllComponentNames() (roles []string)

AllComponentNames contains the names of all components. should include all components in ComponentsByStartOrder

func CheckClusterDirConflict

func CheckClusterDirConflict(clusterList map[string]Metadata, clusterName string, topo Topology) error

CheckClusterDirConflict checks cluster dir conflict or overlap

func CheckClusterDirOverlap

func CheckClusterDirOverlap(entries []DirEntry) error

CheckClusterDirOverlap checks cluster dir overlaps with data or log. this should only be used across clusters. we don't allow to deploy log under data, and vise versa.

func CheckClusterPortConflict

func CheckClusterPortConflict(clusterList map[string]Metadata, clusterName string, topo Topology) error

CheckClusterPortConflict checks cluster port conflict

func ClusterPath

func ClusterPath(cluster string, subpath ...string) string

ClusterPath returns the full path to a subpath (file or directory) of a cluster, it is a subdir in the profile dir of the user, with the cluster name as its name. It is not guaranteed the path already exist.

func ExpandRelativeDir

func ExpandRelativeDir(topo Topology)

ExpandRelativeDir fill DeployDir, DataDir and LogDir to absolute path

func FillHostArchOrOS

func FillHostArchOrOS(s *Specification, hostArchOrOS map[string]string, fullType FullHostType) error

FillHostArchOrOS fills the topology with the given host->arch

func FlattenMap

func FlattenMap(ms map[string]any) map[string]any

FlattenMap convert mutil-layer map to single layer

func FoldMap

func FoldMap(ms map[string]any) map[string]any

FoldMap convert single layer map to multi-layer

func GetValueFromPath

func GetValueFromPath(m map[string]any, p string) any

GetValueFromPath try to find the value by path recursively

func Initialize

func Initialize(base string) error

Initialize initializes the global variables of meta package. If the environment variable GEMIX_COMPONENT_DATA_DIR is set, it is used as root of the profile directory, otherwise the `$HOME/.gemix` of current user is used. The directory will be created before return if it does not already exist.

func IterHost

func IterHost(topo Topology, fn func(instance Instance))

IterHost iterates one instance for each host

func Merge2Toml

func Merge2Toml(comp string, global, overwrite map[string]any) ([]byte, error)

Merge2Toml merge the config of global.

func MergeConfig

func MergeConfig(orig map[string]any, overwrites ...map[string]any) map[string]any

MergeConfig merge two or more config into one and unflat them config1:

a.b.a: 1
a.b.b: 2

config2:

a.b.a: 3
a.b.c: 4

config3:

b.c = 5

After MergeConfig(config1, config2, config3):

a:
  b:
    a: 3
    b: 2
    c: 4
b:
  c: 5

func MergeResourceControl

func MergeResourceControl(lhs, rhs meta.ResourceControl) meta.ResourceControl

MergeResourceControl merge the rhs into lhs and overwrite rhs if lhs has value for same field

func PackageGrafanaPath

func PackageGrafanaPath(comp string, version string, os string, arch string) string

PackageGrafanaPath return the grafana component tar.gz path

func PackagePath

func PackagePath(comp string, version string, os string, arch string) string

PackagePath return the openGemini component tar.gz path

func ParseTopologyYaml

func ParseTopologyYaml(file string, out Topology, ignoreGlobal ...bool) error

ParseTopologyYaml read yaml content from `file` and unmarshal it to `out` ignoreGlobal ignore global variables in file, only ignoreGlobal with a index of 0 is effective

func PortStarted

func PortStarted(ctx context.Context, e ctxt.Executor, port int, timeout uint64) error

PortStarted wait until a port is being listened

func PortStopped

func PortStopped(ctx context.Context, e ctxt.Executor, port int, timeout uint64) error

PortStopped wait until a port is being released

func ProfileDir

func ProfileDir() string

ProfileDir returns the full profile directory path of gemix.

func ProfilePath

func ProfilePath(subpath ...string) string

ProfilePath joins a path under the profile dir

func ReadYamlFile

func ReadYamlFile(file string) ([]byte, error)

ReadYamlFile read yaml content from file

func RelativePathDetect

func RelativePathDetect(topo any, isSkipField func(reflect.Value) bool) error

RelativePathDetect detect if some specific path is relative path and report error

func SetValueFromGlobal

func SetValueFromGlobal(topo *Specification)

SetValueFromGlobal set the default value from global

func UptimeByHost

func UptimeByHost(host string, port int, timeout time.Duration, tlsCfg *tls.Config) time.Duration

UptimeByHost queries current uptime of the instance by http Prometheus metric api.

Types

type BaseInstance

type BaseInstance struct {
	InstanceSpec

	Name       string
	Host       string
	ManageHost string
	ListenHost string
	Port       int
	SSHP       int
	Source     string

	Ports    []int
	Dirs     []string
	StatusFn func(ctx context.Context, timeout time.Duration, tlsCfg *tls.Config, tsMetaHosts ...string) string
	UptimeFn func(ctx context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration
}

BaseInstance implements some method of Instance interface..

func (*BaseInstance) Arch

func (i *BaseInstance) Arch() string

Arch implements Instance interface

func (*BaseInstance) ComponentName

func (i *BaseInstance) ComponentName() string

ComponentName implements Instance interface

func (*BaseInstance) ComponentSource

func (i *BaseInstance) ComponentSource() string

ComponentSource implements Instance interface

func (*BaseInstance) DataDir

func (i *BaseInstance) DataDir() string

DataDir implements Instance interface

func (*BaseInstance) DeployDir

func (i *BaseInstance) DeployDir() string

DeployDir implements Instance interface

func (*BaseInstance) GetHost

func (i *BaseInstance) GetHost() string

GetHost implements Instance interface

func (*BaseInstance) GetListenHost

func (i *BaseInstance) GetListenHost() string

GetListenHost implements Instance interface

func (*BaseInstance) GetManageHost

func (i *BaseInstance) GetManageHost() string

GetManageHost implements Instance interface

func (*BaseInstance) GetPort

func (i *BaseInstance) GetPort() int

GetPort implements Instance interface

func (*BaseInstance) GetSSHPort

func (i *BaseInstance) GetSSHPort() int

GetSSHPort implements Instance interface

func (*BaseInstance) ID

func (i *BaseInstance) ID() string

ID returns the identifier of this instance, the ID is constructed by host:port

func (*BaseInstance) InitConfig

func (i *BaseInstance) InitConfig(ctx context.Context, e ctxt.Executor, opt GlobalOptions, user string, paths meta.DirPaths) (err error)

InitConfig init the service configuration.

func (*BaseInstance) InstanceName

func (i *BaseInstance) InstanceName() string

InstanceName implements Instance interface

func (*BaseInstance) IsPatched

func (i *BaseInstance) IsPatched() bool

IsPatched implements Instance interface

func (*BaseInstance) IteratorLocalConfigDir

func (i *BaseInstance) IteratorLocalConfigDir(ctx context.Context, local string, filter func(string) bool, f func(string) error) error

IteratorLocalConfigDir iterators the local dir with filter, then invoke f for each found fileName

func (*BaseInstance) LogDir

func (i *BaseInstance) LogDir() string

LogDir implements Instance interface

func (*BaseInstance) MergeServerConfig

func (i *BaseInstance) MergeServerConfig(ctx context.Context, e ctxt.Executor, globalConf, instanceConf map[string]any, paths meta.DirPaths) error

MergeServerConfig merges the server configuration and overwrite the global configuration

func (*BaseInstance) OS

func (i *BaseInstance) OS() string

OS implements Instance interface

func (*BaseInstance) PrepareStart

func (i *BaseInstance) PrepareStart(ctx context.Context, tlsCfg *tls.Config) error

PrepareStart checks instance requirements before starting

func (*BaseInstance) Ready

func (i *BaseInstance) Ready(ctx context.Context, e ctxt.Executor, timeout uint64, _ *tls.Config) error

Ready implements Instance interface

func (*BaseInstance) ResourceControl

func (i *BaseInstance) ResourceControl() meta.ResourceControl

ResourceControl return cgroups config of instance

func (*BaseInstance) ServiceName

func (i *BaseInstance) ServiceName() string

ServiceName implements Instance interface

func (*BaseInstance) SetPatched

func (i *BaseInstance) SetPatched(p bool)

SetPatched implements the Instance interface

func (*BaseInstance) Status

func (i *BaseInstance) Status(ctx context.Context, timeout time.Duration, tlsCfg *tls.Config, tsMetaList ...string) string

Status implements Instance interface

func (*BaseInstance) TLSDir

func (i *BaseInstance) TLSDir() string

TLSDir implements Instance interface

func (*BaseInstance) TransferLocalConfigDir

func (i *BaseInstance) TransferLocalConfigDir(ctx context.Context, e ctxt.Executor, local, remote string, filter func(string) bool) error

TransferLocalConfigDir scp local config directory to remote Precondition: the user on remote have right to access & mkdir of dest files

func (*BaseInstance) TransferLocalConfigFile

func (i *BaseInstance) TransferLocalConfigFile(ctx context.Context, e ctxt.Executor, local, remote string) error

TransferLocalConfigFile scp local config file to remote Precondition: the user on remote have permission to access & mkdir of dest files

func (*BaseInstance) Uptime

func (i *BaseInstance) Uptime(ctx context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration

Uptime implements Instance interface

func (*BaseInstance) UsedDirs

func (i *BaseInstance) UsedDirs() []string

UsedDirs implements Instance interface

func (*BaseInstance) UsedPorts

func (i *BaseInstance) UsedPorts() []int

UsedPorts implements Instance interface

type BaseMeta

type BaseMeta struct {
	User    string
	Group   string
	Version string
}

BaseMeta is the base info of metadata.

type BaseTopo

type BaseTopo struct {
	GlobalOptions    *GlobalOptions
	MonitoredOptions *TSMonitoredOptions
	MasterList       []string

	GrafanaVersion *string
	Monitors       []*TSServerSpec
	Grafanas       []*GrafanaSpec
}

type BindVersion

type BindVersion func(comp string, version string) (bindVersion string)

BindVersion map the cluster version to the third components binding version.

type ClusterMeta

type ClusterMeta struct {
	User     string         `yaml:"user"`               // the user to run and manage cluster on remote
	Version  string         `yaml:"openGemini_version"` // the version of openGemini cluster
	Topology *Specification `yaml:"topology"`
}

ClusterMeta is the specification of generic cluster metadata

func (*ClusterMeta) GetBaseMeta

func (m *ClusterMeta) GetBaseMeta() *BaseMeta

GetBaseMeta implements Metadata interface.

func (*ClusterMeta) GetTopology

func (m *ClusterMeta) GetTopology() Topology

GetTopology implement Metadata interface.

func (*ClusterMeta) SetTopology

func (m *ClusterMeta) SetTopology(topo Topology)

SetTopology implement Metadata interface.

func (*ClusterMeta) SetUser

func (m *ClusterMeta) SetUser(s string)

SetUser implement UpgradableMetadata interface.

func (*ClusterMeta) SetVersion

func (m *ClusterMeta) SetVersion(s string)

SetVersion implement UpgradableMetadata interface.

type Component

type Component interface {
	Name() string
	Role() string
	Instances() []Instance
}

Component represents a component of the cluster.

type DirAccessor

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

DirAccessor stands for a directory accessor for an instance

type DirEntry

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

DirEntry stands for a directory with attributes and instance

type FullHostType

type FullHostType string

FullHostType is the type of fullhost operations

const (
	// FullArchType cpu-arch type
	FullArchType FullHostType = "Arch"
	// FullOSType kernel-name
	FullOSType FullHostType = "OS"
)

type GlobalOptions

type GlobalOptions struct {
	User            string               `yaml:"user,omitempty" default:"gemini"`
	Group           string               `yaml:"group,omitempty"`
	SSHPort         int                  `yaml:"ssh_port,omitempty" default:"22" validate:"ssh_port:editable"`
	TLSEnabled      bool                 `yaml:"enable_tls,omitempty"`
	ListenHost      string               `yaml:"listen_host,omitempty" validate:"listen_host:editable"`
	DeployDir       string               `yaml:"deploy_dir,omitempty" default:"deploy"`
	LogDir          string               `yaml:"log_dir,omitempty" default:"logs"`
	DataDir         string               `yaml:"data_dir,omitempty" default:"data"`
	ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control:editable"`
	OS              string               `yaml:"os,omitempty" default:"linux"`
	Arch            string               `yaml:"arch,omitempty" default:"amd64"`
}

GlobalOptions represents the global options for all groups in topology specification in topology.yaml

type GrafanaComponent

type GrafanaComponent struct{ Topology }

GrafanaComponent represents Grafana component.

func (*GrafanaComponent) Instances

func (c *GrafanaComponent) Instances() []Instance

Instances implements Component interface.

func (*GrafanaComponent) Name

func (c *GrafanaComponent) Name() string

Name implements Component interface.

func (*GrafanaComponent) Role

func (c *GrafanaComponent) Role() string

Role implements Component interface.

type GrafanaInstance

type GrafanaInstance struct {
	BaseInstance
	// contains filtered or unexported fields
}

GrafanaInstance represent the grafana instance

func (*GrafanaInstance) InitConfig

func (i *GrafanaInstance) InitConfig(
	ctx context.Context,
	e ctxt.Executor,
	clusterName,
	clusterVersion,
	deployUser string,
	paths meta.DirPaths,
) error

InitConfig implement Instance interface

func (*GrafanaInstance) ScaleConfig

func (i *GrafanaInstance) ScaleConfig(
	ctx context.Context,
	e ctxt.Executor,
	topo Topology,
	clusterName string,
	clusterVersion string,
	deployUser string,
	paths meta.DirPaths,
) error

ScaleConfig deploy temporary config on scaling

type GrafanaSpec

type GrafanaSpec struct {
	Host            string               `yaml:"host"`
	ManageHost      string               `yaml:"manage_host,omitempty" validate:"manage_host:editable"`
	SSHPort         int                  `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"`
	Port            int                  `yaml:"port" default:"3000"`
	DeployDir       string               `yaml:"deploy_dir,omitempty"`
	Config          map[string]string    `yaml:"config,omitempty" validate:"config:ignore"`
	ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control:editable"`
	Arch            string               `yaml:"arch,omitempty"`
	OS              string               `yaml:"os,omitempty"`
	DashboardDir    string               `yaml:"dashboard_dir,omitempty" validate:"dashboard_dir:editable"`
	Username        string               `yaml:"username,omitempty" default:"admin" validate:"username:editable"`
	Password        string               `yaml:"password,omitempty" default:"admin" validate:"password:editable"`
	AnonymousEnable bool                 `yaml:"anonymous_enable" default:"false" validate:"anonymous_enable:editable"`
	RootURL         string               `yaml:"root_url" validate:"root_url:editable"`
	Domain          string               `yaml:"domain" validate:"domain:editable"`
	DefaultTheme    string               `yaml:"default_theme,omitempty" validate:"default_theme:editable"`
	OrgName         string               `yaml:"org_name,omitempty" validate:"org_name:editable"`
	OrgRole         string               `yaml:"org_role,omitempty" validate:"org_role:editable"`
}

GrafanaSpec represents the Grafana topology specification in topology.yaml

func (*GrafanaSpec) GetMainPort

func (s *GrafanaSpec) GetMainPort() int

GetMainPort returns the main port of the instance

func (*GrafanaSpec) GetManageHost

func (s *GrafanaSpec) GetManageHost() string

GetManageHost returns the manage host of the instance

func (*GrafanaSpec) Role

func (s *GrafanaSpec) Role() string

Role returns the component role of the instance

func (*GrafanaSpec) SSH

func (s *GrafanaSpec) SSH() (string, int)

SSH returns the host and SSH port of the instance

type Instance

type Instance interface {
	InstanceSpec
	ID() string
	Ready(context.Context, ctxt.Executor, uint64, *tls.Config) error
	InitConfig(ctx context.Context, e ctxt.Executor, clusterName string, clusterVersion string, deployUser string, paths meta.DirPaths) error
	//ScaleConfig(ctx context.Context, e ctxt.Executor, topo Topology, clusterName string, clusterVersion string, deployUser string, paths meta.DirPaths) error
	PrepareStart(ctx context.Context, tlsCfg *tls.Config) error
	ComponentName() string
	ComponentSource() string
	InstanceName() string
	ServiceName() string
	GetHost() string
	GetManageHost() string
	GetPort() int
	GetSSHPort() int
	DeployDir() string
	UsedPorts() []int
	UsedDirs() []string
	Status(ctx context.Context, timeout time.Duration, tlsCfg *tls.Config, tsMetaList ...string) string
	Uptime(ctx context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration
	DataDir() string
	LogDir() string
	OS() string // only linux supported now
	Arch() string
}

Instance represents the instance.

type InstanceSpec

type InstanceSpec interface {
	Role() string
	SSH() (string, int)
}

InstanceSpec represent a instance specification

type Metadata

type Metadata interface {
	GetTopology() Topology
	SetTopology(topo Topology)
	GetBaseMeta() *BaseMeta
}

Metadata of a cluster.

type MonitorHostInfo

type MonitorHostInfo struct {
	Ssh          int    // ssh port of host
	Os           string // operating system
	Arch         string // cpu architecture
	MetricPath   string
	ErrorLogPath string
	DataPath     string
	WALPath      string
	ProcessName  set.StringSet
	MonitorAddr  string
}

type ServerConfigs

type ServerConfigs struct {
	TsMeta    map[string]any    `yaml:"ts-meta"`
	TsSql     map[string]any    `yaml:"ts-sql"`
	TsStore   map[string]any    `yaml:"ts-store"`
	TsMonitor map[string]any    `yaml:"ts-monitor"`
	Grafana   map[string]string `yaml:"grafana"`
}

ServerConfigs represents the server runtime configuration

type SpecManager

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

SpecManager control management of spec meta data.

func GetSpecManager

func GetSpecManager() *SpecManager

GetSpecManager return the spec manager of openGemini cluster.

func NewSpec

func NewSpec(base string, newMeta func() *ClusterMeta) *SpecManager

NewSpec create a spec instance.

func (*SpecManager) Exist

func (s *SpecManager) Exist(clusterName string) (exist bool, err error)

Exist checks if the cluster exist by checking the meta file.

func (*SpecManager) GetAllClusters

func (s *SpecManager) GetAllClusters() (map[string]Metadata, error)

GetAllClusters get a metadata list of all clusters deployed by current user

func (*SpecManager) List

func (s *SpecManager) List() (clusterNames []string, err error)

List return the cluster names.

func (*SpecManager) Metadata

func (s *SpecManager) Metadata(clusterName string, meta any) error

Metadata tries to read the metadata of a cluster from file

func (*SpecManager) NewMetadata

func (s *SpecManager) NewMetadata() *ClusterMeta

NewMetadata alloc a Metadata according the type.

func (*SpecManager) Path

func (s *SpecManager) Path(cluster string, subpath ...string) string

Path returns the full path to a sub path (file or directory) of a cluster, it is a sub dir in the profile dir of the user, with the cluster name as its name.

func (*SpecManager) Remove

func (s *SpecManager) Remove(clusterName string) error

Remove removes the data with specified cluster name.

func (*SpecManager) SaveMeta

func (s *SpecManager) SaveMeta(clusterName string, meta *ClusterMeta) error

SaveMeta save the meta with specified cluster name.

type Specification

type Specification struct {
	GlobalOptions    GlobalOptions      `yaml:"global,omitempty" validate:"global:editable"`
	MonitoredOptions TSMonitoredOptions `yaml:"monitored,omitempty" validate:"monitored:editable"`
	ServerConfigs    ServerConfigs      `yaml:"server_configs,omitempty" validate:"server_configs:ignore"`
	TSMetaServers    []*TSMetaSpec      `yaml:"ts_meta_servers"`
	TSSqlServers     []*TSSqlSpec       `yaml:"ts_sql_servers"`
	TSStoreServers   []*TSStoreSpec     `yaml:"ts_store_servers"`
	Monitors         []*TSServerSpec    `yaml:"monitoring_servers"`
	Grafanas         []*GrafanaSpec     `yaml:"grafana_servers,omitempty"`
}

Specification represents the specification of topology.yaml

func ReadFromYaml

func ReadFromYaml(file string) (*Specification, error)

func (*Specification) BaseTopo

func (s *Specification) BaseTopo() *BaseTopo

BaseTopo implements Specification interface.

func (*Specification) ComponentsByStartOrder

func (s *Specification) ComponentsByStartOrder() (comps []Component)

ComponentsByStartOrder return component in the order need to start.

func (*Specification) ComponentsByStopOrder

func (s *Specification) ComponentsByStopOrder() (comps []Component)

ComponentsByStopOrder return component in the order need to stop.

func (*Specification) CountDir

func (s *Specification) CountDir(targetHost, dirPrefix string) int

CountDir counts for dir paths used by any instance in the cluster with the same prefix, useful to find potential path conflicts

func (*Specification) FillHostArchOrOS

func (s *Specification) FillHostArchOrOS(hostArchOrOS map[string]string, fullType FullHostType) error

FillHostArchOrOS fills the topology with the given host->arch

func (*Specification) GetGrafanaConfig

func (s *Specification) GetGrafanaConfig() map[string]string

GetGrafanaConfig returns global grafana configurations

func (*Specification) GetMonitoredOptions

func (s *Specification) GetMonitoredOptions() *TSMonitoredOptions

GetMonitoredOptions implements Topology interface.

func (*Specification) GetTSMetaListWithManageHost

func (s *Specification) GetTSMetaListWithManageHost() []string

GetTSMetaListWithManageHost returns a list of ts-meta API hosts of the current cluster

func (*Specification) GetTsMetaList

func (s *Specification) GetTsMetaList() []string

GetTsMetaList returns a list of ts-meta API hosts of the current cluster

func (*Specification) IterComponent

func (s *Specification) IterComponent(fn func(comp Component))

IterComponent iterates all components in component starting order

func (*Specification) IterInstance

func (s *Specification) IterInstance(fn func(instance Instance), concurrency ...int)

IterInstance iterates all instances in component starting order

func (*Specification) UnmarshalYAML

func (s *Specification) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface, it sets the default values when unmarshaling the topology file

func (*Specification) Validate

func (s *Specification) Validate() error

Validate validates the topology specification and produce error if the specification invalid (e.g: port conflicts or directory conflicts)

type TSMetaComponent

type TSMetaComponent struct{ Topology *Specification }

TSMetaComponent represents ts-meta component.

func (*TSMetaComponent) Instances

func (c *TSMetaComponent) Instances() []Instance

Instances implements Component interface.

func (*TSMetaComponent) Name

func (c *TSMetaComponent) Name() string

Name implements Component interface.

func (*TSMetaComponent) Role

func (c *TSMetaComponent) Role() string

Role implements Component interface.

type TSMetaInstance

type TSMetaInstance struct {
	Name string
	BaseInstance
	// contains filtered or unexported fields
}

TSMetaInstance represent the ts-meta instance

func (*TSMetaInstance) InitConfig

func (i *TSMetaInstance) InitConfig(ctx context.Context, e ctxt.Executor, clusterName string, clusterVersion string, deployUser string, paths meta.DirPaths) error

func (*TSMetaInstance) SetDefaultConfig

func (i *TSMetaInstance) SetDefaultConfig(instanceConf map[string]any) map[string]any

type TSMetaSpec

type TSMetaSpec struct {
	Arch string `yaml:"arch,omitempty"`
	OS   string `yaml:"os,omitempty"`

	Source string `yaml:"source,omitempty" validate:"source:editable"`

	// Use Name to get the name with a default value if it's empty.
	Name string `yaml:"name"`

	Host       string `yaml:"host"`
	ManageHost string `yaml:"manage_host,omitempty" validate:"manage_host:editable"`
	ListenHost string `yaml:"listen_host,omitempty"`
	SSHPort    int    `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"`

	LogDir    string `yaml:"log_dir,omitempty"`
	DeployDir string `yaml:"deploy_dir,omitempty"`
	DataDir   string `yaml:"data_dir,omitempty"`

	// port specification
	ClientPort int `yaml:"client_port" default:"8091"`
	PeerPort   int `yaml:"peer_port" default:"8092"`
	RaftPort   int `yaml:"raft_port"  default:"8088"`
	GossipPort int `yaml:"gossip_port"  default:"8010"`

	Config map[string]any `yaml:"config,omitempty" validate:"config:ignore"`
}

TSMetaSpec represents the ts-meta topology specification in topology.yaml

func (*TSMetaSpec) GetManageHost

func (s *TSMetaSpec) GetManageHost() string

GetManageHost returns the manage host of the instance

func (*TSMetaSpec) GetSource

func (s *TSMetaSpec) GetSource() string

GetSource returns source to download the component

func (*TSMetaSpec) Role

func (s *TSMetaSpec) Role() string

Role returns the component role of the instance

func (*TSMetaSpec) SSH

func (s *TSMetaSpec) SSH() (string, int)

func (*TSMetaSpec) Status

func (s *TSMetaSpec) Status(ctx context.Context, timeout time.Duration, tlsCfg *tls.Config, _ ...string) string

Status queries current status of the instance

type TSMonitorComponent

type TSMonitorComponent struct{ Topology *Specification }

TSMonitorComponent represents ts-meta component.

func (*TSMonitorComponent) Instances

func (c *TSMonitorComponent) Instances() []Instance

Instances implements Component interface.

func (*TSMonitorComponent) Name

func (c *TSMonitorComponent) Name() string

Name implements Component interface.

func (*TSMonitorComponent) Role

func (c *TSMonitorComponent) Role() string

Role implements Component interface.

type TSMonitorInstance

type TSMonitorInstance struct {
	Name string
	BaseInstance
	// contains filtered or unexported fields
}

TSMonitorInstance represent the ts-meta instance

func (*TSMonitorInstance) InitConfig

func (i *TSMonitorInstance) InitConfig(ctx context.Context, e ctxt.Executor, clusterName string, clusterVersion string, deployUser string, paths meta.DirPaths) error

func (*TSMonitorInstance) Ready

func (i *TSMonitorInstance) Ready(ctx context.Context, e ctxt.Executor, timeout uint64, _ *tls.Config) error

Ready implements Instance interface

func (*TSMonitorInstance) SetDefaultConfig

func (i *TSMonitorInstance) SetDefaultConfig(instanceConf map[string]any, clusterName string) map[string]any

type TSMonitorSpec

type TSMonitorSpec struct {
	Arch string `yaml:"arch,omitempty"`
	OS   string `yaml:"os,omitempty"`

	Source string `yaml:"source,omitempty" validate:"source:editable"`

	// Use Name to get the name with a default value if it's empty.
	Name string `yaml:"name"`

	Host       string `yaml:"host"`
	ManageHost string `yaml:"manage_host,omitempty" validate:"manage_host:editable"`
	ListenHost string `yaml:"listen_host,omitempty"`
	SSHPort    int    `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"`

	LogDir    string `yaml:"log_dir,omitempty"`
	DeployDir string `yaml:"deploy_dir,omitempty"`

	MonitorProcess map[string]struct{}
	Config         map[string]any `yaml:"config,omitempty" validate:"config:ignore"`
}

TSMonitorSpec represents the ts_monitor_enabled topology specification in topology.yaml

func (*TSMonitorSpec) GetManageHost

func (s *TSMonitorSpec) GetManageHost() string

GetManageHost returns the manage host of the instance

func (*TSMonitorSpec) GetSource

func (s *TSMonitorSpec) GetSource() string

GetSource returns source to download the component

func (*TSMonitorSpec) Role

func (s *TSMonitorSpec) Role() string

Role returns the component role of the instance

func (*TSMonitorSpec) SSH

func (s *TSMonitorSpec) SSH() (string, int)

type TSMonitoredOptions

type TSMonitoredOptions struct {
	TSMonitorEnabled bool   `yaml:"ts_monitor_enabled,omitempty" default:"false"`
	DeployDir        string `yaml:"deploy_dir,omitempty"`
	LogDir           string `yaml:"log_dir,omitempty"`
}

TSMonitoredOptions represents the monitored configuration

type TSServerComponent

type TSServerComponent struct{ Topology }

TSServerComponent represents ts-meta component.

func (*TSServerComponent) Instances

func (c *TSServerComponent) Instances() []Instance

Instances implements Component interface.

func (*TSServerComponent) Name

func (c *TSServerComponent) Name() string

Name implements Component interface.

func (*TSServerComponent) Role

func (c *TSServerComponent) Role() string

Role implements Component interface.

type TSServerInstance

type TSServerInstance struct {
	BaseInstance
	// contains filtered or unexported fields
}

TSServerInstance represent the ts-meta instance

func (*TSServerInstance) InitConfig

func (i *TSServerInstance) InitConfig(ctx context.Context, e ctxt.Executor, clusterName string, clusterVersion string, deployUser string, paths meta.DirPaths) error

func (*TSServerInstance) SetDefaultConfig

func (i *TSServerInstance) SetDefaultConfig(instanceConf map[string]any) map[string]any

type TSServerSpec

type TSServerSpec struct {
	Arch string `yaml:"arch,omitempty"`
	OS   string `yaml:"os,omitempty"`

	Source string `yaml:"source,omitempty" validate:"source:editable"`

	// Use Name to get the name with a default value if it's empty.
	Name string `yaml:"name"`

	Host       string `yaml:"host"`
	ManageHost string `yaml:"manage_host,omitempty" validate:"manage_host:editable"`
	ListenHost string `yaml:"listen_host,omitempty"`
	SSHPort    int    `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"`

	LogDir    string `yaml:"log_dir,omitempty"`
	DeployDir string `yaml:"deploy_dir,omitempty"`
	DataDir   string `yaml:"data_dir,omitempty"`

	// port specification
	Port       int `yaml:"port" default:"8186"`
	RaftPort   int `yaml:"raft_port"  default:"8188"`
	ClientPort int `yaml:"client_port" default:"8191"`
	PeerPort   int `yaml:"peer_port" default:"8192"`
	IngestPort int `yaml:"ingest_port" default:"8410"`
	SelectPort int `yaml:"select_port" default:"8411"`

	Config map[string]any `yaml:"config,omitempty" validate:"config:ignore"`
}

TSServerSpec represents the ts-server topology specification in topology.yaml

func (*TSServerSpec) GetManageHost

func (s *TSServerSpec) GetManageHost() string

GetManageHost returns the manage host of the instance

func (*TSServerSpec) GetSource

func (s *TSServerSpec) GetSource() string

GetSource returns source to download the component

func (*TSServerSpec) Role

func (s *TSServerSpec) Role() string

Role returns the component role of the instance

func (*TSServerSpec) SSH

func (s *TSServerSpec) SSH() (string, int)

type TSSqlComponent

type TSSqlComponent struct{ Topology *Specification }

TSSqlComponent represents ts-meta component.

func (*TSSqlComponent) Instances

func (c *TSSqlComponent) Instances() []Instance

Instances implements Component interface.

func (*TSSqlComponent) Name

func (c *TSSqlComponent) Name() string

Name implements Component interface.

func (*TSSqlComponent) Role

func (c *TSSqlComponent) Role() string

Role implements Component interface.

type TSSqlInstance

type TSSqlInstance struct {
	Name string
	BaseInstance
	// contains filtered or unexported fields
}

TSSqlInstance represent the ts-meta instance

func (*TSSqlInstance) InitConfig

func (i *TSSqlInstance) InitConfig(ctx context.Context, e ctxt.Executor, clusterName string, clusterVersion string, deployUser string, paths meta.DirPaths) error

func (*TSSqlInstance) SetDefaultConfig

func (i *TSSqlInstance) SetDefaultConfig(instanceConf map[string]any) map[string]any

type TSSqlSpec

type TSSqlSpec struct {
	Arch string `yaml:"arch,omitempty"`
	OS   string `yaml:"os,omitempty"`

	Source string `yaml:"source,omitempty" validate:"source:editable"`

	// Use Name to get the name with a default value if it's empty.
	Name           string `yaml:"name"`
	IgnoreExporter bool   `yaml:"ignore_exporter,omitempty"`

	Host       string `yaml:"host"`
	ManageHost string `yaml:"manage_host,omitempty" validate:"manage_host:editable"`
	ListenHost string `yaml:"listen_host,omitempty"`
	SSHPort    int    `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"`

	LogDir    string `yaml:"log_dir,omitempty"`
	DeployDir string `yaml:"deploy_dir,omitempty"`

	// port specification
	Port int `yaml:"port" default:"8086"`

	Config map[string]any `yaml:"config,omitempty" validate:"config:ignore"`
}

TSSqlSpec represents the ts-sql topology specification in topology.yaml

func (*TSSqlSpec) GetManageHost

func (s *TSSqlSpec) GetManageHost() string

GetManageHost returns the manage host of the instance

func (*TSSqlSpec) GetSource

func (s *TSSqlSpec) GetSource() string

GetSource returns source to download the component

func (*TSSqlSpec) IgnoreMonitorAgent

func (s *TSSqlSpec) IgnoreMonitorAgent() bool

IgnoreMonitorAgent returns if the node does not have monitor agents available

func (*TSSqlSpec) Role

func (s *TSSqlSpec) Role() string

Role returns the component role of the instance

func (*TSSqlSpec) SSH

func (s *TSSqlSpec) SSH() (string, int)

type TSStoreComponent

type TSStoreComponent struct{ Topology *Specification }

TSStoreComponent represents ts-meta component.

func (*TSStoreComponent) Instances

func (c *TSStoreComponent) Instances() []Instance

Instances implements Component interface.

func (*TSStoreComponent) Name

func (c *TSStoreComponent) Name() string

Name implements Component interface.

func (*TSStoreComponent) Role

func (c *TSStoreComponent) Role() string

Role implements Component interface.

type TSStoreInstance

type TSStoreInstance struct {
	Name string
	BaseInstance
	// contains filtered or unexported fields
}

TSStoreInstance represent the ts-meta instance

func (*TSStoreInstance) InitConfig

func (i *TSStoreInstance) InitConfig(ctx context.Context, e ctxt.Executor, clusterName string, clusterVersion string, deployUser string, paths meta.DirPaths) error

func (*TSStoreInstance) SetDefaultConfig

func (i *TSStoreInstance) SetDefaultConfig(instanceConf map[string]any) map[string]any

type TSStoreSpec

type TSStoreSpec struct {
	Arch string `yaml:"arch,omitempty"`
	OS   string `yaml:"os,omitempty"`

	Source string `yaml:"source,omitempty" validate:"source:editable"`

	// Use Name to get the name with a default value if it's empty.
	Name string `yaml:"name"`

	Host       string `yaml:"host"`
	ManageHost string `yaml:"manage_host,omitempty" validate:"manage_host:editable"`
	ListenHost string `yaml:"listen_host,omitempty"`
	SSHPort    int    `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"`

	LogDir    string `yaml:"log_dir,omitempty"`
	DeployDir string `yaml:"deploy_dir,omitempty"`
	DataDir   string `yaml:"data_dir,omitempty"`

	// port specification
	IngestPort int `yaml:"ingest_port" default:"8400"`
	SelectPort int `yaml:"select_port" default:"8401"`
	GossipPort int `yaml:"gossip_port" default:"8011"`

	Config map[string]any `yaml:"config,omitempty" validate:"config:ignore"`
}

TSStoreSpec represents the ts-store topology specification in topology.yaml

func (*TSStoreSpec) GetManageHost

func (s *TSStoreSpec) GetManageHost() string

GetManageHost returns the manage host of the instance

func (*TSStoreSpec) GetSource

func (s *TSStoreSpec) GetSource() string

GetSource returns source to download the component

func (*TSStoreSpec) Role

func (s *TSStoreSpec) Role() string

Role returns the component role of the instance

func (*TSStoreSpec) SSH

func (s *TSStoreSpec) SSH() (string, int)

type Topology

type Topology interface {
	BaseTopo() *BaseTopo
	// Validate validates the topology specification and produce error if the
	// specification invalid (e.g: port conflicts or directory conflicts)
	Validate() error

	ComponentsByStartOrder() []Component
	ComponentsByStopOrder() []Component
	//ComponentsByUpdateOrder(curVer string) []Component
	IterInstance(fn func(instance Instance), concurrency ...int)
	GetMonitoredOptions() *TSMonitoredOptions
	CountDir(host string, dir string) int // count how many time a path is used by instances in cluster
	//TLSConfig(dir string) (*tls.Config, error)
	//Merge(that Topology) Topology // TODO: for update
	FillHostArchOrOS(hostArchmap map[string]string, fullType FullHostType) error
	GetGrafanaConfig() map[string]string
}

Topology represents specification of the cluster.

Jump to

Keyboard shortcuts

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