supervisor

package
v2.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package supervisor implements the supervisor of all objects.

Index

Constants

View Source
const (
	// CategoryAll is just for filter of search.
	CategoryAll ObjectCategory = ""
	// CategorySystemController is the category of system controller.
	CategorySystemController = "SystemController"
	// CategoryBusinessController is the category of business controller.
	CategoryBusinessController = "BusinessController"
	// CategoryPipeline is the category of pipeline.
	CategoryPipeline = "Pipeline"
	// CategoryTrafficGate is the category of traffic gate.
	CategoryTrafficGate = "TrafficGate"
)
View Source
const DefaultSpecVersion = "easegress.megaease.com/v2"

DefaultSpecVersion is the default value of the Version field in MetaSpec.

Variables

View Source
var TrafficObjectKinds = make(map[string]struct{})

TrafficObjectKinds is a map that contains all kinds of TrafficObject.

Functions

func ObjectKinds

func ObjectKinds() []string

ObjectKinds returns all object kinds.

func Register

func Register(o Object)

Register registers object.

Types

type Controller

type Controller interface {
	Object

	// Init initializes the Object.
	Init(superSpec *Spec)

	// Inherit also initializes the Object.
	// But it needs to handle the lifecycle of the previous generation.
	// So it's own responsibility for the object to inherit and clean the previous generation stuff.
	// The supervisor won't call Close for the previous generation.
	Inherit(superSpec *Spec, previousGeneration Object)
}

Controller is the object in category of Controller.

type MetaSpec

type MetaSpec struct {
	Name    string `json:"name" jsonschema:"required,format=urlname"`
	Kind    string `json:"kind" jsonschema:"required"`
	Version string `json:"version,omitempty"`

	// RFC3339 format
	CreatedAt string `json:"createdAt,omitempty"`
}

MetaSpec is metadata for all specs.

func NewMeta

func NewMeta(kind, name string) *MetaSpec

type Object

type Object interface {
	// Category returns the object category of itself.
	Category() ObjectCategory

	// Kind returns the unique kind name to represent itself.
	Kind() string

	// DefaultSpec returns the default spec.
	// It must return a pointer to point a struct.
	DefaultSpec() interface{}

	// Status returns its runtime status.
	Status() *Status

	// Close closes itself. It is called by deleting.
	// Supervisor won't call Close for previous generation in Update.
	Close()
}

Object is the common interface for all objects whose lifecycle supervisor handles.

func GetObject

func GetObject(kind string) Object

GetObject returns object by kind.

type ObjectCategory

type ObjectCategory string

ObjectCategory is the type to classify all objects.

type ObjectEntity

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

ObjectEntity is the object entity.

func (*ObjectEntity) CloseWithRecovery

func (e *ObjectEntity) CloseWithRecovery()

CloseWithRecovery closes the object with built-in recovery.

func (*ObjectEntity) Generation

func (e *ObjectEntity) Generation() uint64

Generation returns the generation of the object entity.

func (*ObjectEntity) InheritWithRecovery

func (e *ObjectEntity) InheritWithRecovery(previousEntity *ObjectEntity, muxMapper context.MuxMapper)

InheritWithRecovery inherits the object with built-in recovery.

func (*ObjectEntity) InitWithRecovery

func (e *ObjectEntity) InitWithRecovery(muxMapper context.MuxMapper)

InitWithRecovery initializes the object with built-in recovery. muxMapper could be nil if the object is not TrafficGate and Pipeline.

func (*ObjectEntity) Instance

func (e *ObjectEntity) Instance() Object

Instance returns the instance of the object entity.

func (*ObjectEntity) Spec

func (e *ObjectEntity) Spec() *Spec

Spec returns the spec of the object entity.

type ObjectEntityWatcher

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

ObjectEntityWatcher is the watcher for object entity

func (*ObjectEntityWatcher) Entities

func (w *ObjectEntityWatcher) Entities() map[string]*ObjectEntity

Entities returns the snapshot of the object entities of the watcher.

func (*ObjectEntityWatcher) Watch

func (w *ObjectEntityWatcher) Watch() <-chan *ObjectEntityWatcherEvent

Watch returns then channel to notify the event.

type ObjectEntityWatcherEvent

type ObjectEntityWatcherEvent struct {
	Delete map[string]*ObjectEntity
	Create map[string]*ObjectEntity
	Update map[string]*ObjectEntity
}

ObjectEntityWatcherEvent is the event for watcher

type ObjectEntityWatcherFilter

type ObjectEntityWatcherFilter func(entity *ObjectEntity) bool

ObjectEntityWatcherFilter is the filter type, it returns true when it wants to get the notification about the entity's creation/update/deletion.

func FilterCategory

func FilterCategory(categories ...ObjectCategory) ObjectEntityWatcherFilter

FilterCategory returns a bool function to check if the object entity is filtered by category or not

type ObjectRegistry

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

ObjectRegistry records every object entity according to config from storage without manage their lifecycle.

func (*ObjectRegistry) CloseWatcher

func (or *ObjectRegistry) CloseWatcher(name string)

CloseWatcher closes and releases a watcher.

func (*ObjectRegistry) NewWatcher

NewWatcher creates a watcher

type Pipeline

type Pipeline interface {
	TrafficObject
}

Pipeline is the object in category of Pipeline.

type Spec

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

Spec is the universal spec for all objects.

func NewSpec

func NewSpec(config string) (*Spec, error)

NewSpec is the wrapper of NewSpec of global supervisor.

func (*Spec) Categroy added in v2.7.0

func (s *Spec) Categroy() ObjectCategory

func (*Spec) Equals

func (s *Spec) Equals(other *Spec) bool

Equals compares two Specs.

func (*Spec) JSONConfig

func (s *Spec) JSONConfig() string

JSONConfig returns the config in json format.

func (*Spec) Kind

func (s *Spec) Kind() string

Kind returns kind.

func (*Spec) MarshalJSON

func (s *Spec) MarshalJSON() ([]byte, error)

MarshalJSON marshals the spec to json.

func (*Spec) Name

func (s *Spec) Name() string

Name returns name.

func (*Spec) ObjectSpec

func (s *Spec) ObjectSpec() interface{}

ObjectSpec returns the object spec in its own type.

func (*Spec) RawSpec

func (s *Spec) RawSpec() map[string]interface{}

RawSpec returns the final complete spec in type map[string]interface{}.

func (*Spec) Super

func (s *Spec) Super() *Supervisor

Super returns supervisor

func (*Spec) Version

func (s *Spec) Version() string

Version returns version.

type Status

type Status struct {
	// ObjectStatus must be a map or struct (empty is allowed),
	// If the ObjectStatus contains field `timestamp`,
	// it will be covered by the top-level Timestamp here.
	ObjectStatus interface{}
	// Timestamp is the global unix timestamp, the object
	// needs not to set it on its own.
	Timestamp int64
}

Status is the universal status for all objects.

type Supervisor

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

Supervisor manages all objects.

func GetGlobalSuper added in v2.7.0

func GetGlobalSuper() *Supervisor

func MustNew

func MustNew(opt *option.Options, cls cluster.Cluster) *Supervisor

MustNew creates a Supervisor.

func NewDefaultMock

func NewDefaultMock() *Supervisor

NewDefaultMock return a mock supervisor for testing purpose

func NewMock

func NewMock(options *option.Options, cls cluster.Cluster, objectRegistry *ObjectRegistry, watcher *ObjectEntityWatcher,
	firstHandle bool, firstHandleDone chan struct{}, done chan struct{}) *Supervisor

NewMock return a mock supervisor for testing purpose

func (*Supervisor) Close

func (s *Supervisor) Close(wg *sync.WaitGroup)

Close closes Supervisor.

func (*Supervisor) Cluster

func (s *Supervisor) Cluster() cluster.Cluster

Cluster return the cluster applied to supervisor.

func (*Supervisor) CreateSpec

func (s *Supervisor) CreateSpec(config string) (spec *Spec, err error)

CreateSpec is like NewSpec, but it sets the CreatedAt field in MetaSpec. It should be used to create or update object spec.

func (*Supervisor) FirstHandleDone

func (s *Supervisor) FirstHandleDone() chan struct{}

FirstHandleDone returns the firstHandleDone channel, which will be closed after creating all objects at first time.

func (*Supervisor) GetBusinessController

func (s *Supervisor) GetBusinessController(name string) (*ObjectEntity, bool)

GetBusinessController returns the business controller with the existing flag.

func (*Supervisor) GetSystemController

func (s *Supervisor) GetSystemController(name string) (*ObjectEntity, bool)

GetSystemController returns the system controller with the existing flag. The name of system controller is its own kind.

func (*Supervisor) MustGetSystemController

func (s *Supervisor) MustGetSystemController(name string) *ObjectEntity

MustGetSystemController wraps GetSystemController with panic.

func (*Supervisor) NewObjectEntityFromConfig

func (s *Supervisor) NewObjectEntityFromConfig(jsonConfig string) (*ObjectEntity, error)

NewObjectEntityFromConfig creates an object entity from configuration

func (*Supervisor) NewObjectEntityFromSpec

func (s *Supervisor) NewObjectEntityFromSpec(spec *Spec) (*ObjectEntity, error)

NewObjectEntityFromSpec creates an object entity from a spec

func (*Supervisor) NewSpec

func (s *Supervisor) NewSpec(config string) (spec *Spec, err error)

NewSpec creates a spec and validates it from the config in json format. Config supports both json and yaml format.

func (*Supervisor) ObjectRegistry

func (s *Supervisor) ObjectRegistry() *ObjectRegistry

ObjectRegistry returns the registry of object

func (*Supervisor) Options

func (s *Supervisor) Options() *option.Options

Options returns the options applied to supervisor.

func (*Supervisor) WalkControllers

func (s *Supervisor) WalkControllers(walkFn WalkFunc)

WalkControllers walks every controllers until walkFn returns false.

type TrafficGate

type TrafficGate interface {
	TrafficObject
}

TrafficGate is the object in category of TrafficGate.

type TrafficObject

type TrafficObject interface {
	Object

	// Init initializes the Object.
	Init(superSpec *Spec, muxMapper context.MuxMapper)

	// Inherit also initializes the Object.
	// But it needs to handle the lifecycle of the previous generation.
	// So it's own responsibility for the object to inherit and clean the previous generation stuff.
	// The supervisor won't call Close for the previous generation.
	Inherit(superSpec *Spec, previousGeneration Object, muxMapper context.MuxMapper)
}

TrafficObject is the object of Traffic

type WalkFunc

type WalkFunc func(entity *ObjectEntity) bool

WalkFunc is the type of the function called for walking object entity.

Jump to

Keyboard shortcuts

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