store

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2017 License: Apache-2.0 Imports: 17 Imported by: 40

Documentation

Overview

Package store defines and implements a backend store for the registry

Index

Constants

View Source
const (
	// ServiceNameMaxLength is the maximum length of a service instance name, specified in bytes
	ServiceNameMaxLength int = 64

	// EndpointValueMaxLength is the maximum length of a service instance endpoint value, specified in bytes
	EndpointValueMaxLength int = 128

	// StatusMaxLength is the maximum length of a service instance status field, specified in bytes
	StatusMaxLength int = 32

	// MetadataMaxLength is the maximum length of a service instance metadata, specifie in bytes
	MetadataMaxLength int = 1024
)
View Source
const (
	Starting     = "STARTING"
	Up           = "UP"
	OutOfService = "OUT_OF_SERVICE"
	All          = "ALL" // ALL is only a valid status for the query string param and not for the register
)

Registered instance status related constants

View Source
const (
	REGISTER replicationType = iota
	DEREGISTER
	RENEW
	SETSTATUS
	READREPAIR
)

Enumeration implementation for the replication actions types

Variables

View Source
var DefaultConfig = NewConfig(defaultDefaultTTL, defaultMinimumTTL, defaultMaximumTTL, defaultNamespaceCapacity, nil, nil, defaultStore, defaultStoreAddr, defaultStorePassword, nil)

DefaultConfig is the default configuration parameters for the registry

Functions

This section is empty.

Types

type Catalog

type Catalog interface {
	Register(si *ServiceInstance) (*ServiceInstance, error)
	Deregister(instanceID string) (*ServiceInstance, error)
	Renew(instanceID string) (*ServiceInstance, error)
	SetStatus(instanceID, status string) (*ServiceInstance, error)

	Instance(instanceID string) (*ServiceInstance, error)
	List(serviceName string, predicate Predicate) ([]*ServiceInstance, error)
	ListServices(predicate Predicate) []*Service
}

Catalog for managing instances within a registry namespace

type CatalogFactory

type CatalogFactory interface {
	CreateCatalog(auth.Namespace) (Catalog, error)
}

CatalogFactory represents the interface of the Catalog Factory

func NewDiscoveryAdapter added in v1.0.0

func NewDiscoveryAdapter(factory DiscoveryFactory) CatalogFactory

NewDiscoveryAdapter creates a CatalogFactory from the given DiscoveryFactory

type CatalogMap

type CatalogMap interface {
	GetCatalog(auth.Namespace) (Catalog, error)
}

CatalogMap represents the interface of the Service store

func New

func New(conf *Config) CatalogMap

New creates a new CatalogMap instance, bounded with the specified configuration

type Config

type Config struct {
	DefaultTTL time.Duration
	MinimumTTL time.Duration
	MaximumTTL time.Duration

	NamespaceCapacity int

	SyncWaitTime time.Duration

	Extensions  []CatalogFactory
	Replication replication.Replication

	Store         string
	StoreAddr     string
	StorePassword string
	StoreDatabase database.Database
}

Config encapsulates the registry configuration parameters

func NewConfig

func NewConfig(defaultTTL, minimumTTL, maximumTTL time.Duration, namespaceCapacity int, extensions []CatalogFactory, rep replication.Replication, store string, storeAddr string, storePassword string, storeDatabase database.Database) *Config

NewConfig creates a new registry configuration according to the specified TTL values

type DBKey

type DBKey struct {
	Namespace  string
	InstanceID string
}

DBKey represents the service instance key

func (*DBKey) String

func (dbk *DBKey) String() string

Database key as JSON string

type DiscoveryFactory added in v1.0.0

type DiscoveryFactory func(namespace auth.Namespace) (api.ServiceDiscovery, error)

DiscoveryFactory is a function which accepts a namespace and returns a discovery object for that namespace

type Endpoint

type Endpoint struct {
	Type  string
	Value string
}

Endpoint represents a network endpoint. Immutable by convention.

func (*Endpoint) DeepClone

func (e *Endpoint) DeepClone() *Endpoint

DeepClone creates a deep copy of the receiver

func (*Endpoint) String

func (e *Endpoint) String() string

type Error

type Error struct {
	Code    ErrorCode
	Message string
	Cause   interface{}
}

Error is an error implementation that is associated with an ErrorCode

func NewError

func NewError(code ErrorCode, message string, cause interface{}) *Error

NewError creates a new registry.Error with the specified code, message and cause.

func (*Error) Error

func (e *Error) Error() string

type ErrorCode

type ErrorCode int

ErrorCode represents an error condition that might occur during a registry operation

const (
	ErrorBadRequest ErrorCode = iota
	ErrorNoSuchServiceName
	ErrorNoSuchServiceInstance
	ErrorNamespaceQuotaExceeded
	ErrorInternalServerError
	ErrorNoInstanceServiceName
	ErrorInstanceServiceNameTooLong
	ErrorInstanceEndpointValueTooLong
	ErrorInstanceStatusLengthTooLong
	ErrorInstanceMetaDataTooLong
)

ErrorCode predefined values

type ExternalRegistry

type ExternalRegistry interface {
	ReadKeys(namespace auth.Namespace) ([]string, error)
	ReadServiceInstanceByInstID(namespace auth.Namespace, instanceID string) (*ServiceInstance, error)
	ListServiceInstancesByName(namespace auth.Namespace, name string) (map[string]*ServiceInstance, error)
	ListAllServiceInstances(namespace auth.Namespace) (map[string]ServiceInstanceMap, error)
	InsertServiceInstance(namespace auth.Namespace, instance *ServiceInstance) error
	DeleteServiceInstance(namespace auth.Namespace, instanceID string) (int, error)
}

ExternalRegistry calls to manage the instances in an external store

func NewMockExternalRegistry

func NewMockExternalRegistry(mockServiceInstances map[string]*ServiceInstance) ExternalRegistry

NewMockExternalRegistry is a mock version of the external registry

func NewRedisRegistry

func NewRedisRegistry(db database.Database) ExternalRegistry

NewRedisRegistry is backed by a Redis db

type Predicate

type Predicate func(si *ServiceInstance) bool

Predicate for filtering returned instances

type Service

type Service struct {
	ServiceName string
}

Service represents a runtime service group.

func (*Service) String

func (s *Service) String() string

type ServiceInstance

type ServiceInstance struct {
	ID               string
	ServiceName      string
	Endpoint         *Endpoint
	Status           string
	Metadata         []byte
	RegistrationTime time.Time
	LastRenewal      time.Time
	TTL              time.Duration
	Tags             []string
	Extension        map[string]interface{}
}

ServiceInstance represents a runtime instance of a service.

func (*ServiceInstance) DeepClone

func (si *ServiceInstance) DeepClone() *ServiceInstance

DeepClone creates a deep copy of the receiver

func (*ServiceInstance) String

func (si *ServiceInstance) String() string

String output the structure

type ServiceInstanceMap

type ServiceInstanceMap map[DBKey]*ServiceInstance

ServiceInstanceMap is a map of ServiceInstances keyed by instance id and service name

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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