cluster

package
v3.9.4 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package cluster defines an interface for clustering network components and provides a simple implementation.

Index

Constants

This section is empty.

Variables

View Source
var CustomNew func(ctx context.Context, config *Config, options ...Option) (Cluster, error)

CustomNew allows you to replace the clustering implementation. New will call CustomNew if not nil.

View Source
var HookName = "cluster-hook"

HookName is the name of the hook used to verify the identity of incoming calls within a cluster.

View Source
var PacketBrokerGatewayID = ttnpb.GatewayIdentifiers{GatewayID: "packetbroker"}

PacketBrokerGatewayID is the proxy gateway identifier of gateways connected through Packet Broker.

Functions

This section is empty.

Types

type Cluster

type Cluster interface {
	// Join the cluster.
	Join() error
	// Leave the cluster.
	Leave() error

	// GetPeers returns peers with the given role.
	GetPeers(ctx context.Context, role ttnpb.ClusterRole) ([]Peer, error)
	// GetPeer returns a peer with the given role, and a responsibility for the
	// given identifiers. If the identifiers are nil, this function returns a random
	// peer from the list that would be returned by GetPeers.
	GetPeer(ctx context.Context, role ttnpb.ClusterRole, ids ttnpb.Identifiers) (Peer, error)
	// GetPeerConn returns the gRPC client connection of a peer, if the peer is available as
	// as per GetPeer.
	GetPeerConn(ctx context.Context, role ttnpb.ClusterRole, ids ttnpb.Identifiers) (*grpc.ClientConn, error)

	// ClaimIDs can be used to indicate that the current peer takes
	// responsibility for entities identified by ids.
	// Claiming an already claimed ID will transfer the claim (without notifying
	// the previous holder). Releasing a non-claimed ID is a no-op. An error may
	// only be returned if the claim/unclaim couldn't be communicated with the cluster.
	ClaimIDs(ctx context.Context, ids ttnpb.Identifiers) error
	// UnclaimIDs can be used to indicate that the current peer
	// releases responsibility for entities identified by ids.
	// The specified context ctx may already be done before calling this function.
	UnclaimIDs(ctx context.Context, ids ttnpb.Identifiers) error

	// TLS returns whether the cluster uses TLS for cluster connections.
	TLS() bool
	// Auth returns a gRPC CallOption that can be used to identify the component within the cluster.
	Auth() grpc.CallOption
	// WithVerifiedSource verifies if the caller providing this context is a component from the cluster, and returns a
	// new context with that information.
	WithVerifiedSource(context.Context) context.Context
}

Cluster interface that is implemented by all different clustering implementations.

func New

func New(ctx context.Context, config *Config, options ...Option) (Cluster, error)

New instantiates a new clustering implementation. The basic clustering implementation allows for a cluster setup with a single-instance deployment of each component (GS/NS/AS/JS). Network operators can use their own clustering logic, which can be activated by setting the CustomNew variable.

type Config

type Config struct {
	Join              []string `name:"join" description:"Addresses of cluster peers to join"`
	Name              string   `name:"name" description:"Name of the current cluster peer (default: $HOSTNAME)"`
	Address           string   `name:"address" description:"Address to use for cluster communication"`
	IdentityServer    string   `name:"identity-server" description:"Address for the Identity Server"`
	GatewayServer     string   `name:"gateway-server" description:"Address for the Gateway Server"`
	NetworkServer     string   `name:"network-server" description:"Address for the Network Server"`
	ApplicationServer string   `name:"application-server" description:"Address for the Application Server"`
	JoinServer        string   `name:"join-server" description:"Address for the Join Server"`
	CryptoServer      string   `name:"crypto-server" description:"Address for the Crypto Server"`
	TLS               bool     `name:"tls" description:"Do cluster gRPC over TLS"`
	TLSServerName     string   `name:"tls-server-name" description:"Server name to use in TLS handshake to cluster peers"`
	Keys              []string `` /* 146-byte string literal not displayed */
}

Config represents clustering configuration.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option to apply at cluster initialization.

func WithConn

func WithConn(conn *grpc.ClientConn) Option

WithConn bypasses the standard mechanism for connecting to the "self" peer.

func WithServices

func WithServices(services ...rpcserver.Registerer) Option

WithServices registers the given services on the "self" peer.

func WithTLSConfig

func WithTLSConfig(tlsConfig *tls.Config) Option

WithTLSConfig sets the TLS config to use in cluster connections.

type Peer

type Peer interface {
	// Name of the peer
	Name() string
	// gRPC ClientConn to the peer (if available)
	Conn() (*grpc.ClientConn, error)
	// Roles announced by the peer
	Roles() []ttnpb.ClusterRole
	// HasRole returns true iff the peer has the given role
	HasRole(ttnpb.ClusterRole) bool
	// Tags announced by the peer
	Tags() map[string]string
}

Peer interface

Jump to

Keyboard shortcuts

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