Documentation ¶
Overview ¶
Package supervisor implements the supervisor of all objects.
Index ¶
- Constants
- Variables
- func ObjectKinds() []string
- func Register(o Object)
- type Controller
- type MetaSpec
- type Object
- type ObjectCategory
- type ObjectEntity
- func (e *ObjectEntity) CloseWithRecovery()
- func (e *ObjectEntity) Generation() uint64
- func (e *ObjectEntity) InheritWithRecovery(previousEntity *ObjectEntity, muxMapper context.MuxMapper)
- func (e *ObjectEntity) InitWithRecovery(muxMapper context.MuxMapper)
- func (e *ObjectEntity) Instance() Object
- func (e *ObjectEntity) Spec() *Spec
- type ObjectEntityWatcher
- type ObjectEntityWatcherEvent
- type ObjectEntityWatcherFilter
- type ObjectRegistry
- type Pipeline
- type Spec
- func (s *Spec) Equals(other *Spec) bool
- func (s *Spec) JSONConfig() string
- func (s *Spec) Kind() string
- func (s *Spec) MarshalJSON() ([]byte, error)
- func (s *Spec) Name() string
- func (s *Spec) ObjectSpec() interface{}
- func (s *Spec) RawSpec() map[string]interface{}
- func (s *Spec) Super() *Supervisor
- func (s *Spec) Version() string
- type Status
- type Supervisor
- func (s *Supervisor) Close(wg *sync.WaitGroup)
- func (s *Supervisor) Cluster() cluster.Cluster
- func (s *Supervisor) CreateSpec(config string) (spec *Spec, err error)
- func (s *Supervisor) FirstHandleDone() chan struct{}
- func (s *Supervisor) GetBusinessController(name string) (*ObjectEntity, bool)
- func (s *Supervisor) GetSystemController(name string) (*ObjectEntity, bool)
- func (s *Supervisor) MustGetSystemController(name string) *ObjectEntity
- func (s *Supervisor) NewObjectEntityFromConfig(jsonConfig string) (*ObjectEntity, error)
- func (s *Supervisor) NewObjectEntityFromSpec(spec *Spec) (*ObjectEntity, error)
- func (s *Supervisor) NewSpec(config string) (spec *Spec, err error)
- func (s *Supervisor) ObjectRegistry() *ObjectRegistry
- func (s *Supervisor) Options() *option.Options
- func (s *Supervisor) WalkControllers(walkFn WalkFunc)
- type TrafficGate
- type TrafficObject
- type WalkFunc
Constants ¶
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" )
const DefaultSpecVersion = "easegress.megaease.com/v2"
DefaultSpecVersion is the default value of the Version field in MetaSpec.
Variables ¶
var TrafficObjectKinds = make(map[string]struct{})
TrafficObjectKinds is a map that contains all kinds of TrafficObject.
Functions ¶
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.
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.
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 ¶
func (or *ObjectRegistry) NewWatcher(name string, filter ObjectEntityWatcherFilter) *ObjectEntityWatcher
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 (*Spec) JSONConfig ¶
JSONConfig returns the config in json format.
func (*Spec) MarshalJSON ¶
MarshalJSON marshals the spec to json.
func (*Spec) ObjectSpec ¶
func (s *Spec) ObjectSpec() interface{}
ObjectSpec returns the object spec in its own type.
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 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) 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.