registry

package
v2.2.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Package registry provides the main glue between services

It wraps micro registry (running services declared to the discovery server) into a more generic registry where all actual plugins are self-declared.

Package registry provides the main glue between services

It wraps micro registry (running services declared to the discovery server) into a more generic registry where all actual plugins are self-declared.

Package registry provides the main glue between services

It wraps micro registry (running services declared to the discovery server) into a more generic registry where all actual plugins are self-declared.

  • Copyright (c) 2019. Abstrium SAS <team (at) pydio.com>
  • This file is part of Pydio Cells. *
  • Pydio Cells is free software: you can redistribute it and/or modify
  • it under the terms of the GNU Affero General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • Pydio Cells is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU Affero General Public License for more details. *
  • You should have received a copy of the GNU Affero General Public License
  • along with Pydio Cells. If not, see <http://www.gnu.org/licenses/>. *
  • The latest code can be found at <https://pydio.com>.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Default registry
	Default = NewRegistry()
)
View Source
var (
	ProcessStartTags []string
)

Functions

func BuildServiceMeta added in v1.4.0

func BuildServiceMeta() map[string]string

func FixedInstanceSelector

func FixedInstanceSelector(srvName string, targetAddress string) selector.SelectOption

PeerClientSelector creates a Selector Filter to restrict call to a given PeerAddress

func GetClient

func GetClient(name string) (string, client.Client)

GetClient returns the default client for the service name

func GetPeers added in v1.2.2

func GetPeers() map[string]*Peer

func GetProcesses added in v1.4.0

func GetProcesses() map[string]*Process

func Init

func Init(opts ...Option)

Init the default registry

func NewMockFromMicroService

func NewMockFromMicroService(rs *registry.Service) *mockService

func PeerClientSelector added in v1.4.1

func PeerClientSelector(srvName string, targetPeer string) selector.SelectOption

PeerClientSelector creates a Selector Filter to restrict call to a given PeerAddress

func ShortRequestTimeout

func ShortRequestTimeout() client.CallOption

GetShortRequestTime returns a 1s RequestTimeout option

Types

type Cluster

type Cluster interface {
	Join(nodeId string) error
	Leave() error
	Close() error

	LeadershipAcquired() chan bool
}

func GetCluster

func GetCluster(ctx context.Context, serviceName string, fsm raft.FSM) Cluster

type Nodes

type Nodes []*registry.Node

Nodes wraps an array of registry nodes

func (Nodes) StringArray

func (n Nodes) StringArray() []string

StringArray representation of the registry nodes

type NullFSM

type NullFSM struct{}

func (*NullFSM) Apply

func (n *NullFSM) Apply(*raft.Log) interface{}

func (*NullFSM) Restore

func (n *NullFSM) Restore(rc io.ReadCloser) error

func (*NullFSM) Snapshot

func (n *NullFSM) Snapshot() (raft.FSMSnapshot, error)

type NullSnapshot

type NullSnapshot struct{}

func (*NullSnapshot) Persist

func (n *NullSnapshot) Persist(sink raft.SnapshotSink) error

func (*NullSnapshot) Release

func (n *NullSnapshot) Release()

type Option

type Option func(*Options)

Option is a gateway to setting Options to the Registry

func Name

func Name(n string) Option

Name links a name as a registry option

func PollInterval

func PollInterval(interval time.Duration) Option

PollInterval defines an interval option to a watcher

type Options

type Options struct {
	Name         string
	PollInterval time.Duration

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

Options defines options to the Registry itself

type Peer added in v1.2.2

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

func NewPeer added in v1.2.2

func NewPeer(address string, nodeMeta ...map[string]string) *Peer

func (*Peer) Add added in v1.2.2

func (p *Peer) Add(c *registry.Service, id string) bool

Add returns if the service was already registered

func (*Peer) Delete added in v1.2.2

func (p *Peer) Delete(c *registry.Service, id string) bool

Delete returns if the services existed before or not

func (*Peer) GetAddress added in v1.4.1

func (p *Peer) GetAddress() string

func (*Peer) GetHostname added in v1.4.1

func (p *Peer) GetHostname() string

func (*Peer) GetServices added in v1.2.2

func (p *Peer) GetServices(name ...string) []*registry.Service

func (*Peer) IsInitial added in v1.4.1

func (p *Peer) IsInitial() bool

type Process added in v1.4.0

type Process struct {
	Id          string
	ParentId    string
	MetricsPort int
	PeerId      string
	PeerAddress string
	StartTag    string

	Services map[string]string
	// contains filtered or unexported fields
}

func GetCurrentProcess

func GetCurrentProcess() *Process

func NewProcess added in v1.4.0

func NewProcess(pid string) *Process

type RegisterOption

type RegisterOption func(*RegisterOptions)

RegisterOption is a gateway to setting RegisterOptions to a Registry Entry

func RegisterDependencies

func RegisterDependencies(d ...string) RegisterOption

RegisterDependencies adds dependencies between services to the registry entry

func RegisterFlags

func RegisterFlags(f ...*pflag.Flag) RegisterOption

RegisterFlags adds flags to the registry entry service

type RegisterOptions

type RegisterOptions struct {
	Dependencies []string
	Flags        []*pflag.Flag

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

RegisterOptions defines different options for the Register entry

type Registry

type Registry interface {
	Init(...Option)
	Register(Service, ...RegisterOption) error
	Deregister(Service) error
	GetServiceByName(string) Service
	GetServicesByName(string) []Service
	GetPeers() map[string]*Peer
	GetCurrentProcess() *Process
	GetCurrentChildrenProcesses() []*Process
	GetProcesses() map[string]*Process
	ListServices(withExcluded ...bool) ([]Service, error)
	ListServicesWithFilter(func(Service) bool) ([]Service, error)
	ListRunningServices() ([]Service, error)
	ListServicesWithMicroMeta(string, ...string) ([]Service, error)
	SetServiceStopped(string) error
	Filter(func(Service) bool) error
	Watch() (Watcher, error)
	String() string
	Options() Options

	BeforeInit() error
	AfterInit() error
}

Registry provides an interface for service discovery and an abstraction over varying implementations {consul, etcd, zookeeper, ...}

func NewRegistry

func NewRegistry(opts ...Option) Registry

NewRegistry provides a new registry object

type Result

type Result struct {
	Action  string
	Service Service
}

Result of a Watch Message

type Service

type Service interface {
	Start(context.Context)
	Stop()

	IsRunning() bool
	IsExcluded() bool
	SetExcluded(ex bool)
	Check(context.Context) error

	Name() string
	Address() string
	Regexp() *regexp.Regexp
	Version() string
	Description() string
	Tags() []string
	GetDependencies() []Service
	AddDependency(string)
	SetRunningNodes([]*registry.Node)
	RunningNodes() []*registry.Node
	DAO() interface{}

	IsGeneric() bool
	IsGRPC() bool
	IsREST() bool

	RequiresFork() bool
	ForkStart(ctx context.Context, retries ...int)
	MustBeUnique() bool
	AutoStart() bool

	MatchesRegexp(string) bool

	BeforeInit() error
	AfterInit() error
}

Service defines the primary functions a service must be able to answer to for the registry

func ListRunningServices

func ListRunningServices() ([]Service, error)

ListRunningServices returns the list of services that are started in the system

func ListServices

func ListServices(withExcluded ...bool) ([]Service, error)

ListServices returns the list of services that are started in the system

func ListServicesWithFilter added in v1.5.0

func ListServicesWithFilter(fn func(Service) bool) ([]Service, error)

ListServicesWithFilter returns the list of services that are started in the system

func ListServicesWithMicroMeta

func ListServicesWithMicroMeta(metaName string, metaValue ...string) ([]Service, error)

ListServicesWithMicroMeta lists the services that have a specific meta name and value associated

type Watcher

type Watcher interface {
	Next() (*Result, error)
	Stop()
}

Watcher defines the functions used to watch the registry

func Watch

func Watch() (Watcher, error)

Watch triggers a watch of the default registry

Jump to

Keyboard shortcuts

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