serviceregistry

package
v2.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package serviceregistry provides the service registry.

Index

Constants

View Source
const (
	// Category is the category of ServiceRegistry.
	Category = supervisor.CategorySystemController

	// Kind is the kind of ServiceRegistry.
	Kind = "ServiceRegistry"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Registry

type Registry interface {
	Name() string

	// Operation from the registry.
	Notify() <-chan *RegistryEvent

	// Operations to the registry.
	// The key of maps is key of service instance.
	ApplyServiceInstances(serviceInstances map[string]*ServiceInstanceSpec) error
	DeleteServiceInstances(serviceInstances map[string]*ServiceInstanceSpec) error
	// GetServiceInstance must return error if not found.
	GetServiceInstance(serviceName, instanceID string) (*ServiceInstanceSpec, error)
	// ListServiceInstances could return zero elements of instances with nil error.
	ListServiceInstances(serviceName string) (map[string]*ServiceInstanceSpec, error)
	// ListServiceInstances could return zero elements of instances with nil error.
	ListAllServiceInstances() (map[string]*ServiceInstanceSpec, error)
}

Registry stands for the specific service registry.

type RegistryEvent

type RegistryEvent struct {
	// SourceRegistryName is the registry which caused the event,
	// the RegistryName of specs may not be the same with it.
	SourceRegistryName string
	UseReplace         bool

	// Replace replaces all service instances of the registry.
	Replace map[string]*ServiceInstanceSpec

	// Apply creates or updates service instances of the registry.
	Apply map[string]*ServiceInstanceSpec

	// Delete deletes service instances of the registry.
	Delete map[string]*ServiceInstanceSpec
}

RegistryEvent is the event of service registry. If UseReplace is true, the event handler should use Replace field even it is empty. NOTE: Changing inner fields needs to adapt to its methods Empty, DeepCopy, Validate, etc.

func NewRegistryEventFromDiff

func NewRegistryEventFromDiff(registryName string, oldSpecs, newSpecs map[string]*ServiceInstanceSpec) *RegistryEvent

NewRegistryEventFromDiff creates a registry event from diff old and new specs. It only uses Apply and Delete excluding Replace. External drivers should use event.Replace in first time, then use this utility to generate next events. registryName is only assigned to the event, the registry name of service instance spec won't change.

func (*RegistryEvent) DeepCopy

func (e *RegistryEvent) DeepCopy() *RegistryEvent

DeepCopy deep copies RegistryEvent.

func (*RegistryEvent) Empty

func (e *RegistryEvent) Empty() bool

Empty returns if the event contains nothing to handle.

func (*RegistryEvent) Validate

func (e *RegistryEvent) Validate() error

Validate validates RegistryEvent.

type RegistryWatcher

type RegistryWatcher interface {
	ID() string

	RegistryName() string

	// Exists returns if the registry exists.
	Exists() bool

	// The channel will be closed if the registry is closed.
	Watch() <-chan *RegistryEvent

	Stop()
}

RegistryWatcher is the watcher of service registry.

type ServiceEvent

type ServiceEvent struct {
	// SourceRegistryName is the registry which caused the event,
	// the RegistryName of specs may not be the same with it.
	SourceRegistryName string
	Instances          map[string]*ServiceInstanceSpec
}

ServiceEvent is the event of service. It concludes complete instances of the service. NOTE: Changing inner fields needs to adapt to its methods DeepCopy, etc.

func (*ServiceEvent) DeepCopy

func (e *ServiceEvent) DeepCopy() *ServiceEvent

DeepCopy deep copies ServiceEvent.

type ServiceInstanceSpec

type ServiceInstanceSpec struct {
	// RegistryName is required.
	RegistryName string `json:"registryName"`
	// ServiceName is required.
	ServiceName string `json:"serviceName"`
	// InstanceID is required.
	InstanceID string `json:"instanceID"`

	// Address is required.
	Address string `json:"address"`
	// Port is required.
	Port uint16 `json:"port"`

	// Scheme is optional.
	Scheme string `json:"scheme"`
	// Tags is optional.
	Tags []string `json:"tags"`
	// Weight is optional.
	Weight int `json:"weight"`
}

ServiceInstanceSpec is the service instance spec in Easegress.

func (*ServiceInstanceSpec) DeepCopy

DeepCopy deep copies ServiceInstanceSpec.

func (*ServiceInstanceSpec) Key

func (s *ServiceInstanceSpec) Key() string

Key returns the unique key for the service instance.

func (*ServiceInstanceSpec) URL

func (s *ServiceInstanceSpec) URL() string

URL returns the url of the server.

func (*ServiceInstanceSpec) Validate

func (s *ServiceInstanceSpec) Validate() error

Validate validates itself.

type ServiceRegistry

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

ServiceRegistry is a system controller to be center registry between external registries and internal handlers and watchers. To be specific: it dispatches event from every registry to every watcher, and wraps the operations from handlers to every registry.

func (*ServiceRegistry) ApplyServiceInstances

func (sr *ServiceRegistry) ApplyServiceInstances(registryName string, serviceInstances map[string]*ServiceInstanceSpec) error

ApplyServiceInstances applies the services to the registry with change RegistryName of all specs.

func (*ServiceRegistry) Category

func (sr *ServiceRegistry) Category() supervisor.ObjectCategory

Category returns the category of ServiceRegistry.

func (*ServiceRegistry) Close

func (sr *ServiceRegistry) Close()

Close closes ServiceRegistry.

func (*ServiceRegistry) DefaultSpec

func (sr *ServiceRegistry) DefaultSpec() interface{}

DefaultSpec returns the default spec of ServiceRegistry.

func (*ServiceRegistry) DeleteServiceInstances

func (sr *ServiceRegistry) DeleteServiceInstances(registryName string, serviceInstances map[string]*ServiceInstanceSpec) error

DeleteServiceInstances service instances of one service.

func (*ServiceRegistry) DeregisterRegistry

func (sr *ServiceRegistry) DeregisterRegistry(registryName string) error

DeregisterRegistry remove the registry.

func (*ServiceRegistry) GetServiceInstance

func (sr *ServiceRegistry) GetServiceInstance(registryName, serviceName, instanceID string) (*ServiceInstanceSpec, error)

GetServiceInstance get service instance.

func (*ServiceRegistry) Inherit

func (sr *ServiceRegistry) Inherit(superSpec *supervisor.Spec, previousGeneration supervisor.Object)

Inherit inherits previous generation of ServiceRegistry.

func (*ServiceRegistry) Init

func (sr *ServiceRegistry) Init(superSpec *supervisor.Spec)

Init initializes ServiceRegistry.

func (*ServiceRegistry) Kind

func (sr *ServiceRegistry) Kind() string

Kind returns the kind of ServiceRegistry.

func (*ServiceRegistry) ListAllServiceInstances

func (sr *ServiceRegistry) ListAllServiceInstances(registryName string) (map[string]*ServiceInstanceSpec, error)

ListAllServiceInstances service instances of all services.

func (*ServiceRegistry) ListServiceInstances

func (sr *ServiceRegistry) ListServiceInstances(registryName, serviceName string) (map[string]*ServiceInstanceSpec, error)

ListServiceInstances service instances of one service.

func (*ServiceRegistry) NewRegistryWatcher

func (sr *ServiceRegistry) NewRegistryWatcher(registryName string) RegistryWatcher

NewRegistryWatcher creates a registry watcher.

func (*ServiceRegistry) NewServiceWatcher

func (sr *ServiceRegistry) NewServiceWatcher(registryName, serviceName string) ServiceWatcher

NewServiceWatcher creates a service watcher.

func (*ServiceRegistry) RegisterRegistry

func (sr *ServiceRegistry) RegisterRegistry(registry Registry) error

RegisterRegistry registers the registry and watch it.

func (*ServiceRegistry) Status

func (sr *ServiceRegistry) Status() *supervisor.Status

Status returns status of ServiceRegistry.

type ServiceWatcher

type ServiceWatcher interface {
	ID() string

	RegistryName() string
	ServiceName() string

	Watch() <-chan *ServiceEvent

	Stop()
}

ServiceWatcher is the watcher of service.

type Spec

type Spec struct {
	SyncInterval string `json:"syncInterval" jsonschema:"required,format=duration"`
}

Spec describes ServiceRegistry.

type Status

type Status struct{}

Status is the status of ServiceRegistry.

Jump to

Keyboard shortcuts

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