registry

package
v3.0.9+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2022 License: AGPL-3.0 Imports: 17 Imported by: 349

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-2021. 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

FixedInstanceSelector 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

ShortRequestTimeout returns a 1s RequestTimeout option

func Watch

func Watch() (registry.Watcher, error)

Watch triggers a watch of the default registry

Types

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 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 GetPeer

func GetPeer(node *registry.Node) *Peer

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

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 GetProcess

func GetProcess(node *registry.Node) *Process

func NewProcess added in v1.4.0

func NewProcess(node *registry.Node) *Process

func (*Process) Add

func (p *Process) Add(serviceName string)

func (*Process) Delete

func (p *Process) Delete(serviceName string)

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
	GetPeer(*registry.Node) *Peer
	GetCurrentProcess() *Process
	GetCurrentChildrenProcesses() []*Process
	GetProcesses() map[string]*Process
	GetProcess(*registry.Node) *Process
	ListServices(withExcluded ...bool) ([]Service, error)
	ListServicesWithFilter(func(Service) bool) ([]Service, error)
	GetRunningService(string) ([]Service, error)
	ListRunningServices() ([]Service, error)
	ListServicesWithMicroMeta(string, ...string) ([]Service, error)
	Filter(func(Service) bool) error
	Watch() (registry.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 Service

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

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

	Name() string
	ID() 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 GetRunningService

func GetRunningService(name string) ([]Service, error)

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

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

Jump to

Keyboard shortcuts

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