cluster

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BackendStateInit           = "init"
	BackendStateReady          = "ready"
	BackendStateError          = "error"
	BackendStateStopped        = "stopped"
	BackendStateDecommissioned = "decommissioned"
)

BackendStates: The state of the cluster backend node.

View Source
const (
	// Backend
	CmdUpdateNodeState     = "update_node_state"
	CmdDecommissionBackend = "decommission_backend"

	// Meetings
	CmdUpdateMeetingState = "update_meeting_state"
	CmdEndAllMeetings     = "end_all_meetings"

	// Maintenance
	CmdCollectGarbage = "collect_garbage"
)

Commands that can be handled by the controller

View Source
const (
	// MeetingSyncInterval is the amount of time after a
	// meeting state is considered stale and should be refreshed.
	MeetingSyncInterval = 15 * time.Second

	// NodeSyncInterval is the amount of time after a backend
	// node is considered stale and should be refreshed.
	NodeSyncInterval = 20 * time.Second
)

Variables

View Source
var (
	// ErrNoBackendInContext will be returned when no backends
	// could be associated with the request.
	ErrNoBackendInContext = errors.New("no backend in context")

	// ErrNoFrontendInContext will be returned when no frontend
	// is associated with the request.
	ErrNoFrontendInContext = errors.New("no fontend in context")

	// ErrBackendNotReady will only occure when the routing
	// selected a backend that can not accept any requests
	ErrBackendNotReady = errors.New("backend not ready")
)

Errors

View Source
var (
	// ErrNoBackendForMeeting indicates, that there is a backend
	// expected to be associated with a meeting, yet the meeting
	// is unknown to the cluster.
	ErrNoBackendForMeeting = errors.New("no backends associated with meeting")

	// ErrNoBackendAvailable indicates that there is no backend
	// available for creating a meeting.
	ErrNoBackendAvailable = errors.New("no free backend availble for meeting")

	// ErrMeetingIDMissing indicates that there is a meetingID
	// expected to be in the requests params, but it is missing.
	ErrMeetingIDMissing = errors.New("meetingID missing from request")
)

Routing errors

View Source
var (
	// ErrRecordingNotFound indicates, that the recording
	// state could not retrieved.
	ErrRecordingNotFound = errors.New("recording could not be found")
)
View Source
var (
	// ErrUnknownCommand indicates, that the command was not
	// understood by the controller.
	ErrUnknownCommand = errors.New("command unknown")
)

Functions

func CollectGarbage

func CollectGarbage() *store.Command

CollectGarbage requests removing stale states.

func ContextWithBackend

func ContextWithBackend(
	ctx context.Context, backend *Backend,
) context.Context

ContextWithBackend create a new context with a backend

func ContextWithBackends

func ContextWithBackends(
	ctx context.Context, backends []*Backend,
) context.Context

ContextWithBackends creates a new context from the parent context with a copy of the backends.

func ContextWithFrontend

func ContextWithFrontend(
	ctx context.Context, frontend *Frontend,
) context.Context

ContextWithFrontend creates a context with a frontend

func DecommissionBackend

func DecommissionBackend(req *DecommissionBackendRequest) *store.Command

DecommissionBackend will remove a given cluster backend from the state.

func EndAllMeetings

func EndAllMeetings(req *EndAllMeetingsRequest) *store.Command

EndAllMeetings will send end meeting api requests to all running meetings on a backend. This can be usefull to force decommissioning.

func NewRequestContext

func NewRequestContext() context.Context

NewRequestContext create a new context

func UpdateMeetingState

func UpdateMeetingState(
	req *UpdateMeetingStateRequest,
) *store.Command

UpdateMeetingState makes a new meeting refresh command

func UpdateNodeState

func UpdateNodeState(req *UpdateNodeStateRequest) *store.Command

UpdateNodeState creates a update status command

Types

type Backend

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

A Backend is a BigBlueButton instance in the cluster.

It has a bbb.backend secret for request authentication, stored in the backend state. The state is shared across all instances.

func BackendFromContext

func BackendFromContext(ctx context.Context) *Backend

BackendFromContext retrievs a backend from a context

func BackendsFromContext

func BackendsFromContext(ctx context.Context) []*Backend

BackendsFromContext retrieves backends from a context

func GetBackend

func GetBackend(
	ctx context.Context,
	q sq.SelectBuilder,
) (*Backend, error)

GetBackend retrievs a single backend by query criteria

func GetBackends

func GetBackends(
	ctx context.Context,
	q sq.SelectBuilder,
) ([]*Backend, error)

GetBackends retrievs all backends from the store, filterable with a query.

func NewBackend

func NewBackend(state *store.BackendState) *Backend

NewBackend creates a new backend instance with a fresh bbb client.

func (*Backend) Create

func (b *Backend) Create(
	ctx context.Context,
	req *bbb.Request,
) (*bbb.CreateResponse, error)

Create a new Meeting

func (*Backend) End

func (b *Backend) End(
	ctx context.Context,
	req *bbb.Request,
) (*bbb.EndResponse, error)

End a meeting

func (*Backend) GetDefaultConfigXML

func (b *Backend) GetDefaultConfigXML(
	ctx context.Context,
	req *bbb.Request,
) (*bbb.GetDefaultConfigXMLResponse, error)

GetDefaultConfigXML retrieves the default config xml

func (*Backend) GetMeetingInfo

func (b *Backend) GetMeetingInfo(
	ctx context.Context,
	req *bbb.Request,
) (*bbb.GetMeetingInfoResponse, error)

GetMeetingInfo gets the meeting details

func (*Backend) GetMeetings

func (b *Backend) GetMeetings(
	ctx context.Context,
	req *bbb.Request,
) (*bbb.GetMeetingsResponse, error)

GetMeetings retrieves a list of meetings

func (*Backend) GetRecordingTextTracks

func (b *Backend) GetRecordingTextTracks(
	ctx context.Context,
	req *bbb.Request,
) (*bbb.GetRecordingTextTracksResponse, error)

GetRecordingTextTracks retrieves the text tracks from a recording

func (*Backend) HasTag

func (b *Backend) HasTag(tag string) bool

HasTag checks for the presence of a tag

func (*Backend) HasTags

func (b *Backend) HasTags(tags []string) bool

HasTags checks for the presence of all tags

func (*Backend) Host

func (b *Backend) Host() string

Host retrievs the backend host

func (*Backend) ID

func (b *Backend) ID() string

ID retrievs the backend id

func (*Backend) IsMeetingRunning

func (b *Backend) IsMeetingRunning(
	ctx context.Context,
	req *bbb.Request,
) (*bbb.IsMeetingRunningResponse, error)

IsMeetingRunning returns the is meeting running state

func (*Backend) Join

func (b *Backend) Join(
	ctx context.Context,
	req *bbb.Request,
) (*bbb.JoinResponse, error)

Join via redirect: The client will receive a redirect to the BBB backend and will join there directly.

func (*Backend) JoinProxy

func (b *Backend) JoinProxy(
	ctx context.Context,
	req *bbb.Request,
) (*bbb.JoinResponse, error)

JoinProxy makes a request on behalf of the client. A reverse proxy needs to pass all subsequent requests to the BBB backend.

func (*Backend) PutRecordingTextTrack

func (b *Backend) PutRecordingTextTrack(
	ctx context.Context,
	req *bbb.Request,
) (*bbb.PutRecordingTextTrackResponse, error)

PutRecordingTextTrack adds a text track

func (*Backend) SetConfigXML

func (b *Backend) SetConfigXML(
	ctx context.Context,
	req *bbb.Request,
) (*bbb.SetConfigXMLResponse, error)

SetConfigXML sets the? config xml

func (*Backend) Stress

func (b *Backend) Stress() float64

Stress calculates the current node load

func (*Backend) String

func (b *Backend) String() string

String stringifies the Backend

func (*Backend) Tags

func (b *Backend) Tags() []string

Tags retrievs the backend's tags from it's state

type Controller

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

The Controller interfaces with the state of the cluster providing methods for retrieving cluster backends and frontends.

The controller subscribes to commands.

func NewController

func NewController() *Controller

NewController will initialize the cluster controller with a database connection. A BBB client will be created which will be used by the backend instances.

func (*Controller) Start

func (c *Controller) Start()

Start the controller

func (*Controller) StartBackground

func (c *Controller) StartBackground()

StartBackground will be run periodically triggered by requests and should only add tasks to the command queue. These tasks will take care of syncing the backends with our state by refreshing nodes and meetings.

type DecommissionBackendRequest

type DecommissionBackendRequest struct {
	ID string `json:"id"`
}

DecommissionBackendRequest declares the removal of a backend node from the cluster state.

type EndAllMeetingsRequest

type EndAllMeetingsRequest struct {
	BackendID string
}

EndAllMeetingsRequest contains parameters for the end all meetings command.

type Frontend

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

A Frontend is a consumer like greenlight. Each frontend has it's own secret for authentication.

func FrontendFromContext

func FrontendFromContext(ctx context.Context) *Frontend

FrontendFromContext retrieves a frontend from a context

func GetFrontend

func GetFrontend(
	ctx context.Context,
	q sq.SelectBuilder,
) (*Frontend, error)

GetFrontend fetches a frontend with a state from the store

func GetFrontends

func GetFrontends(
	ctx context.Context,
	q sq.SelectBuilder,
) ([]*Frontend, error)

GetFrontends retrieves all frontends from the store matchig a query

func NewFrontend

func NewFrontend(state *store.FrontendState) *Frontend

NewFrontend initializes a frontend with the provided config and assigns the ID.

func (*Frontend) Frontend

func (f *Frontend) Frontend() *bbb.Frontend

Frontend gets the states BBB frontend

func (*Frontend) ID

func (f *Frontend) ID() string

ID retrievs the frontend id

func (*Frontend) Key

func (f *Frontend) Key() string

Key retrieves the frontend key

func (*Frontend) Settings

func (f *Frontend) Settings() *store.FrontendSettings

Settings gets the state settings

func (*Frontend) String

func (f *Frontend) String() string

String stringifies the frontend

type Gateway

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

The Gateway accepts bbb cluster requests and dispatches it to the cluster nodes.

func NewGateway

func NewGateway(ctrl *Controller, opts *GatewayOptions) *Gateway

NewGateway sets up a new cluster router instance.

func (*Gateway) Dispatch

func (gw *Gateway) Dispatch(
	ctx context.Context,
	conn *pgxpool.Conn,
	req *bbb.Request,
) bbb.Response

Dispatch taks a cluster request and starts the middleware chain. We will always return a bbb response. Any error occoring during routing or dispatching will be encoded as an BBB XML Response.

func (*Gateway) Use

func (gw *Gateway) Use(middleware RequestMiddleware)

Use registers a middleware function

type GatewayOptions

type GatewayOptions struct {
}

GatewayOptions have flags for customizing the gateway behaviour.

type RequestHandler

type RequestHandler func(context.Context, *bbb.Request) (bbb.Response, error)

RequestHandler accepts a bbb request and state. It produces a bbb response or an error.

type RequestMiddleware

type RequestMiddleware func(next RequestHandler) RequestHandler

RequestMiddleware is a plain middleware without a state

type Router

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

The Router provides a requets middleware for routing requests to backends. The routing middleware stack selects backends.

func NewRouter

func NewRouter(ctrl *Controller) *Router

NewRouter creates a new router middleware selecting a list of backends from the cluster state.

The request will be initialized with a list of all backends available in the the cluster state

The middleware chain should only subtract backends.

func (*Router) LookupBackend

func (r *Router) LookupBackend(
	ctx context.Context,
	req *bbb.Request,
) (*Backend, error)

LookupBackend will retrieve a backend or will fail if the backend could not be found. Primary identifier is the MeetingID of the request. When no backend is found, this will not fail, however the backend will be nil and this case needs to be handled.

func (*Router) LookupBackendForRecordID

func (r *Router) LookupBackendForRecordID(
	ctx context.Context,
	recordID string,
) (*Backend, error)

LookupBackendForRecordID uses the recordID to identify a backend via the recordings state table.

func (*Router) SelectBackend

func (r *Router) SelectBackend(
	ctx context.Context, req *bbb.Request,
) (*Backend, error)

SelectBackend will apply the routing middleware chain to a given request with all ready nodes in the cluster where the admin state is also ready. Selecting a backend will fail if no backends are available as routing targets.

func (*Router) Use

func (r *Router) Use(middleware RouterMiddleware)

Use will insert a middleware into the chain

type RouterHandler

type RouterHandler func(context.Context, []*Backend, *bbb.Request) ([]*Backend, error)

RouterHandler accepts a bbb request and a list of backends and returns a filtered or sorted list of backends.

type RouterMiddleware

type RouterMiddleware func(next RouterHandler) RouterHandler

A RouterMiddleware accepts a handler function and returns a decorated handler function.

type Schema

type Schema map[string]string

Schema is a mapping of variable names and decode hints

type UpdateMeetingStateRequest

type UpdateMeetingStateRequest struct {
	ID string // the meeting ID
}

UpdateMeetingStateRequest requests the refresh of a meeting

type UpdateNodeStateRequest

type UpdateNodeStateRequest struct {
	ID string // the backend state id
}

UpdateNodeStateRequest requests a status update from a backend identified by ID

Jump to

Keyboard shortcuts

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