cluster

package
v0.4.0-beta.6 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashToken

func HashToken(token string) string

func ValidCapability

func ValidCapability(value Capability) bool

Types

type AggregatedResponse

type AggregatedResponse struct {
	Servers map[string]ServerResult `json:"servers"`
}

func AggregateFromPeers

func AggregateFromPeers(ctx context.Context, localData []byte, mgr *Manager, path string) *AggregatedResponse

type Capability

type Capability string
const (
	CapabilityFleetRead       Capability = "fleet.read"
	CapabilityDeploymentsRead Capability = "deployments.read"
	CapabilityDeploymentsRun  Capability = "deployments.run"
	CapabilityCapacityRead    Capability = "capacity.read"
	CapabilityCapacityOffer   Capability = "capacity.offer"
	CapabilityEventsPublish   Capability = "events.publish"
	CapabilityRoutingManage   Capability = "routing.manage"
)

type Client

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

func NewClient

func NewClient(baseURL, apiKey string, timeout time.Duration) *Client

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body io.Reader) (*http.Response, error)

func (*Client) Forward

func (c *Client) Forward(ctx context.Context, method, path string, body io.Reader) ([]byte, int, map[string]string, error)

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string) ([]byte, int, error)

func (*Client) Health

func (c *Client) Health(ctx context.Context) error

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body []byte) ([]byte, int, error)

type DB

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

func NewDB

func NewDB(deploymentsPath string) (*DB, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) ConsumeInvite

func (db *DB) ConsumeInvite(tokenHash string, peerName string) error

func (*DB) CreateInvite

func (db *DB) CreateInvite(invite *Invite) (int64, error)

func (*DB) CreatePeer

func (db *DB) CreatePeer(peer *Peer) (int64, error)

func (*DB) DeletePeer

func (db *DB) DeletePeer(name string) error

func (*DB) GetInviteByHash

func (db *DB) GetInviteByHash(tokenHash string) (*Invite, error)

func (*DB) GetPeer

func (db *DB) GetPeer(name string) (*Peer, error)

func (*DB) GetPeerPolicy

func (db *DB) GetPeerPolicy(name string) (*PeerPolicy, error)

func (*DB) ListPeers

func (db *DB) ListPeers() ([]Peer, error)

func (*DB) SetPeerPolicy

func (db *DB) SetPeerPolicy(policy PeerPolicy) error

func (*DB) UpdateLastSeen

func (db *DB) UpdateLastSeen(name string) error

type EventPublisher

type EventPublisher interface {
	Publish(events.Event) (events.IngestResult, error)
}

type Grant

type Grant struct {
	Capability  Capability `json:"capability"`
	Deployments []string   `json:"deployments,omitempty"`
	MaxCPU      float64    `json:"max_cpu,omitempty"`
	MaxMemory   uint64     `json:"max_memory,omitempty"`
	MaxReplicas int        `json:"max_replicas,omitempty"`
}

func DefaultPeerGrants

func DefaultPeerGrants() []Grant

type Invite

type Invite struct {
	ID           int64     `json:"id"`
	TokenHash    string    `json:"-"`
	Status       string    `json:"status"`
	CreatedBy    int64     `json:"created_by"`
	AcceptedPeer string    `json:"accepted_peer,omitempty"`
	ExpiresAt    time.Time `json:"expires_at"`
	CreatedAt    time.Time `json:"created_at"`
}

type Manager

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

func NewManager

func NewManager(db *DB, serverName string, healthInterval, requestTimeout time.Duration, jwtSecret string) *Manager

func (*Manager) AddPeer

func (m *Manager) AddPeer(name, url, apiKey string) error

func (*Manager) DB

func (m *Manager) DB() *DB

func (*Manager) ForEachPeer

func (m *Manager) ForEachPeer(ctx context.Context, fn func(ctx context.Context, name string, client *Client) ([]byte, error)) map[string]Result

func (*Manager) GetPeer

func (m *Manager) GetPeer(name string) (*Client, error)

func (*Manager) ListPeers

func (m *Manager) ListPeers() []PeerStatus

func (*Manager) RemovePeer

func (m *Manager) RemovePeer(name string) error

func (*Manager) ServerName

func (m *Manager) ServerName() string

func (*Manager) SetEventPublisher

func (m *Manager) SetEventPublisher(publisher EventPublisher)

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

func (*Manager) Stop

func (m *Manager) Stop()

type Peer

type Peer struct {
	ID              int64     `json:"id"`
	Name            string    `json:"name"`
	URL             string    `json:"url"`
	APIKeyHash      string    `json:"-"`
	APIKeyEncrypted string    `json:"-"`
	Status          string    `json:"status"`
	CreatedAt       time.Time `json:"created_at"`
	LastSeenAt      time.Time `json:"last_seen_at,omitempty"`
}

type PeerPolicy

type PeerPolicy struct {
	Peer   string  `json:"peer"`
	Grants []Grant `json:"grants"`
}

type PeerStatus

type PeerStatus struct {
	Name     string    `json:"name"`
	URL      string    `json:"url"`
	Online   bool      `json:"online"`
	LastSeen time.Time `json:"last_seen"`
	Error    string    `json:"error,omitempty"`
	Probed   bool      `json:"-"`
}

type Result

type Result struct {
	Data  []byte `json:"data,omitempty"`
	Error string `json:"error,omitempty"`
}

type ServerResult

type ServerResult struct {
	Name   string          `json:"name"`
	Online bool            `json:"online"`
	Data   json.RawMessage `json:"data,omitempty"`
	Error  string          `json:"error,omitempty"`
}

Jump to

Keyboard shortcuts

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