clusters

package
v1.2.21 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: Apache-2.0 Imports: 37 Imported by: 2

Documentation

Index

Constants

View Source
const (
	Add    = NodeEventKind(1)
	Remove = NodeEventKind(2)
)

Variables

View Source
var (
	ErrTooEarly               = errors.TooEarly("fns: service is not ready, try later again")
	ErrUnavailable            = errors.Unavailable("fns: service is closed")
	ErrDeviceId               = errors.Warning("fns: device id was required")
	ErrInvalidPath            = errors.Warning("fns: invalid path")
	ErrInvalidBody            = errors.Warning("fns: invalid body")
	ErrInvalidRequestVersions = errors.Warning("fns: invalid request versions")
	ErrTooMayRequest          = errors.TooMayRequest("fns: too may request, try again later")
	ErrSignatureLost          = errors.New(488, "***SIGNATURE LOST***", "X-Fns-Signature was required")
	ErrSignatureUnverified    = errors.New(458, "***SIGNATURE INVALID***", "X-Fns-Signature was invalid")
)

Functions

func New

func New(options Options) (manager services.EndpointsManager, shared shareds.Shared, barrier barriers.Barrier, handlers []transports.MuxHandler, err error)

func NewBarrier

func NewBarrier(config BarrierConfig, shared shareds.Shared) (b barriers.Barrier)

func NewInternalHandler

func NewInternalHandler(local services.Endpoints, signature signatures.Signature) transports.MuxHandler

func NewSignature

func NewSignature(secret string) signatures.Signature

func RegisterCluster

func RegisterCluster(name string, cluster Cluster)

func RegisterHostRetriever

func RegisterHostRetriever(name string, fn HostRetriever)

Types

type Barrier

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

func (*Barrier) Do

func (b *Barrier) Do(ctx context.Context, key []byte, fn func() (result interface{}, err error)) (result barriers.Result, err error)

func (*Barrier) Forget

func (b *Barrier) Forget(ctx context.Context, key []byte)

type BarrierConfig

type BarrierConfig struct {
	TTL        time.Duration `json:"ttl"`
	Interval   time.Duration `json:"interval"`
	Standalone bool          `json:"standalone"`
}

type BarrierValue

type BarrierValue []byte

func NewBarrierValue

func NewBarrierValue() BarrierValue

func (BarrierValue) Exist

func (bv BarrierValue) Exist() bool

func (BarrierValue) Failed

func (bv BarrierValue) Failed(v error) (n BarrierValue)

func (BarrierValue) Forget

func (bv BarrierValue) Forget() BarrierValue

func (BarrierValue) Forgot

func (bv BarrierValue) Forgot() bool

func (BarrierValue) Succeed

func (bv BarrierValue) Succeed(v interface{}) (n BarrierValue, err error)

func (BarrierValue) Value

func (bv BarrierValue) Value() (data []byte, err error)

type Cluster

type Cluster interface {
	Construct(options ClusterOptions) (err error)
	AddService(service Service)
	Join(ctx context.Context) (err error)
	Leave(ctx context.Context) (err error)
	NodeEvents() (events <-chan NodeEvent)
	Shared() (shared shareds.Shared)
	Barrier() (barrier barriers.Barrier)
}

func NewDevelopment

func NewDevelopment(dialer transports.Dialer, signature signatures.Signature) Cluster

type ClusterBuilderOptions

type ClusterBuilderOptions struct {
	Config configures.Config
	Log    logs.Logger
}

type ClusterEndpointsManager

type ClusterEndpointsManager interface {
	services.EndpointsManager
	FnAddress(ctx context.Context, endpoint []byte, fnName []byte, options ...services.EndpointGetOption) (address string, internal bool, has bool)
}

func NewManager

func NewManager(id string, version versions.Version, address string, cluster Cluster, local services.EndpointsManager, worker workers.Workers, log logs.Logger, dialer transports.Dialer, signature signatures.Signature) ClusterEndpointsManager

type ClusterOptions

type ClusterOptions struct {
	Log     logs.Logger
	Config  configures.Config
	Id      string
	Version versions.Version
	Address string
}

type Config

type Config struct {
	Secret        string          `json:"secret"`
	HostRetriever string          `json:"hostRetriever"`
	Name          string          `json:"name"`
	Proxy         bool            `json:"proxy"`
	Option        json.RawMessage `json:"option"`
}

type Development

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

func (*Development) AddService

func (cluster *Development) AddService(_ Service)

func (*Development) Barrier added in v1.2.0

func (cluster *Development) Barrier() (barrier barriers.Barrier)

func (*Development) Construct

func (cluster *Development) Construct(options ClusterOptions) (err error)

func (*Development) Join

func (cluster *Development) Join(ctx context.Context) (err error)

func (*Development) Leave

func (cluster *Development) Leave(_ context.Context) (err error)

func (*Development) NodeEvents

func (cluster *Development) NodeEvents() (events <-chan NodeEvent)

func (*Development) Shared

func (cluster *Development) Shared() (shared shareds.Shared)

type DevelopmentConfig

type DevelopmentConfig struct {
	ProxyAddr string `json:"proxyAddr"`
}

type Endpoint

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

func NewEndpoint

func NewEndpoint(address string, id string, version versions.Version, name string, internal bool, document documents.Endpoint, client transports.Client, signature signatures.Signature) (endpoint *Endpoint)

func (*Endpoint) AddFn

func (endpoint *Endpoint) AddFn(name string, internal bool, readonly bool)

func (*Endpoint) Address

func (endpoint *Endpoint) Address() string

func (*Endpoint) Document

func (endpoint *Endpoint) Document() documents.Endpoint

func (*Endpoint) Functions

func (endpoint *Endpoint) Functions() services.Fns

func (*Endpoint) Info

func (endpoint *Endpoint) Info() services.EndpointInfo

func (*Endpoint) Internal

func (endpoint *Endpoint) Internal() bool

func (*Endpoint) IsHealth added in v1.2.0

func (endpoint *Endpoint) IsHealth() bool

func (*Endpoint) Name

func (endpoint *Endpoint) Name() string

func (*Endpoint) Running

func (endpoint *Endpoint) Running() bool

func (*Endpoint) Shutdown

func (endpoint *Endpoint) Shutdown(_ context.Context)

type Endpoints

type Endpoints []*Endpoint

func (Endpoints) Len

func (list Endpoints) Len() int

func (Endpoints) Less

func (list Endpoints) Less(i, j int) bool

func (Endpoints) Swap

func (list Endpoints) Swap(i, j int)

type Entry

type Entry struct {
	Key   []byte `json:"key" avro:"key"`
	Value []byte `json:"value" avro:"value"`
}

type Fn

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

func (*Fn) Enable

func (fn *Fn) Enable() bool

func (*Fn) Handle

func (fn *Fn) Handle(ctx services.Request) (v interface{}, err error)

func (*Fn) Internal

func (fn *Fn) Internal() bool

func (*Fn) Name

func (fn *Fn) Name() string

func (*Fn) Readonly

func (fn *Fn) Readonly() bool

type HostRetriever

type HostRetriever func() (host string, err error)

type InternalHandler

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

func (*InternalHandler) Construct

func (handler *InternalHandler) Construct(_ transports.MuxHandlerOptions) error

func (*InternalHandler) Handle

func (*InternalHandler) Match

func (handler *InternalHandler) Match(_ context.Context, method []byte, path []byte, header transports.Header) bool

func (*InternalHandler) Name

func (handler *InternalHandler) Name() string

type Manager

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

func (*Manager) Add

func (manager *Manager) Add(service services.Service) (err error)

func (*Manager) FnAddress added in v1.2.21

func (manager *Manager) FnAddress(ctx context.Context, endpoint []byte, fnName []byte, options ...services.EndpointGetOption) (address string, internal bool, has bool)

func (*Manager) Get

func (manager *Manager) Get(ctx context.Context, name []byte, options ...services.EndpointGetOption) (endpoint services.Endpoint, has bool)

func (*Manager) Info

func (manager *Manager) Info() (infos services.EndpointInfos)

func (*Manager) Listen

func (manager *Manager) Listen(ctx context.Context) (err error)

func (*Manager) Request

func (manager *Manager) Request(ctx context.Context, name []byte, fn []byte, param interface{}, options ...services.RequestOption) (response services.Response, err error)

func (*Manager) Shutdown

func (manager *Manager) Shutdown(ctx context.Context)

type Node

type Node struct {
	Id       string           `json:"id"`
	Version  versions.Version `json:"version"`
	Address  string           `json:"address"`
	Services []Service        `json:"services"`
}

type NodeEvent

type NodeEvent struct {
	Kind NodeEventKind
	Node Node
}

type NodeEventKind

type NodeEventKind int

func (NodeEventKind) String added in v1.2.0

func (kind NodeEventKind) String() string

type Nodes

type Nodes []Node

func MapEndpointInfosToNodes

func MapEndpointInfosToNodes(infos services.EndpointInfos) (nodes Nodes)

func (Nodes) Add

func (nodes Nodes) Add(node Node) Nodes

func (Nodes) Difference

func (nodes Nodes) Difference(olds Nodes) (events []NodeEvent)

func (Nodes) Len

func (nodes Nodes) Len() int

func (Nodes) Less

func (nodes Nodes) Less(i, j int) bool

func (Nodes) Remove

func (nodes Nodes) Remove(node Node) Nodes

func (Nodes) Swap

func (nodes Nodes) Swap(i, j int)

type Options

type Options struct {
	Id      string
	Version versions.Version
	Port    int
	Log     logs.Logger
	Worker  workers.Workers
	Local   services.EndpointsManager
	Dialer  transports.Dialer
	Config  Config
}

type Registration

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

func (*Registration) Add

func (registration *Registration) Add(endpoint *Endpoint)

func (*Registration) Get

func (registration *Registration) Get(id []byte) (endpoint *Endpoint, has bool)

func (*Registration) MaxOne

func (registration *Registration) MaxOne() (endpoint *Endpoint, has bool)

func (*Registration) Range

func (registration *Registration) Range(interval versions.Interval) (endpoint *Endpoint, has bool)

func (*Registration) Remove

func (registration *Registration) Remove(id string)

type Registrations

type Registrations []*Registration

func (Registrations) Add

func (registrations Registrations) Add(endpoint *Endpoint) Registrations

func (Registrations) Get

func (registrations Registrations) Get(name []byte) (v *Registration, has bool)

func (Registrations) Remove

func (registrations Registrations) Remove(name string, id string) Registrations

type RequestBody

type RequestBody struct {
	ContextUserValues []Entry `json:"contextUserValues" avro:"contextUserValues"`
	Params            []byte  `json:"params" avro:"params"`
}

type ResponseBody

type ResponseBody struct {
	Succeed     bool    `json:"succeed" avro:"succeed"`
	Data        []byte  `json:"data" avro:"data"`
	Attachments []Entry `json:"attachments" avro:"attachments"`
}

func (ResponseBody) GetSpan added in v1.2.0

func (rsp ResponseBody) GetSpan() (v *tracings.Span, has bool)

type Service

type Service struct {
	Name        string           `json:"name"`
	Internal    bool             `json:"internal"`
	Functions   services.FnInfos `json:"functions"`
	DocumentRaw []byte           `json:"document"`
}

func NewService

func NewService(name string, internal bool, functions services.FnInfos, document documents.Endpoint) (service Service, err error)

func (Service) Document

func (service Service) Document() (document documents.Endpoint, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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