Documentation ¶
Index ¶
- Constants
- 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 protocol.MuxMapper)
- func (e *ObjectEntity) InitWithRecovery(muxMapper protocol.MuxMapper)
- func (e *ObjectEntity) Instance() Object
- func (e *ObjectEntity) Spec() *Spec
- type ObjectEntityWatcher
- type ObjectEntityWatcherEvent
- type ObjectEntityWatcherFilter
- type ObjectRegistry
- type Pipeline
- type Spec
- type Status
- type Supervisor
- func (s *Supervisor) Close(wg *sync.WaitGroup)
- func (s *Supervisor) Cluster() cluster.Cluster
- 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(config string) (*ObjectEntity, error)
- func (s *Supervisor) NewObjectEntityFromSpec(spec *Spec) (*ObjectEntity, error)
- func (s *Supervisor) NewSpec(yamlConfig 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" )
Variables ¶
This section is empty.
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 `yaml:"name" jsonschema:"required,format=urlname"` Kind string `yaml:"kind" jsonschema:"required"` }
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 ¶ added in v1.0.1
type ObjectEntity struct {
// contains filtered or unexported fields
}
ObjectEntity is the object entity.
func (*ObjectEntity) CloseWithRecovery ¶ added in v1.0.1
func (e *ObjectEntity) CloseWithRecovery()
CloseWithRecovery closes the object with built-in recovery.
func (*ObjectEntity) Generation ¶ added in v1.0.1
func (e *ObjectEntity) Generation() uint64
Generation returns the generation of the object entity.
func (*ObjectEntity) InheritWithRecovery ¶ added in v1.0.1
func (e *ObjectEntity) InheritWithRecovery(previousEntity *ObjectEntity, muxMapper protocol.MuxMapper)
InheritWithRecovery inherits the object with built-in recovery.
func (*ObjectEntity) InitWithRecovery ¶ added in v1.0.1
func (e *ObjectEntity) InitWithRecovery(muxMapper protocol.MuxMapper)
InitWithRecovery initializes the object with built-in recovery. muxMapper could be nil if the object is not TrafficGate and Pipeline.
func (*ObjectEntity) Instance ¶ added in v1.0.1
func (e *ObjectEntity) Instance() Object
Instance returns the instance of the object entity.
func (*ObjectEntity) Spec ¶ added in v1.0.1
func (e *ObjectEntity) Spec() *Spec
Spec returns the spec of the object entity.
type ObjectEntityWatcher ¶ added in v1.0.1
type ObjectEntityWatcher struct {
// contains filtered or unexported fields
}
ObjectEntityWatcher is the watcher for object entity
func (*ObjectEntityWatcher) Entities ¶ added in v1.0.1
func (w *ObjectEntityWatcher) Entities() map[string]*ObjectEntity
Entities returns the snapshot of the object entities of the watcher.
func (*ObjectEntityWatcher) Watch ¶ added in v1.0.1
func (w *ObjectEntityWatcher) Watch() <-chan *ObjectEntityWatcherEvent
Watch returns then channel to notify the event.
type ObjectEntityWatcherEvent ¶ added in v1.0.1
type ObjectEntityWatcherEvent struct { Delete map[string]*ObjectEntity Create map[string]*ObjectEntity Update map[string]*ObjectEntity }
ObjectEntityWatcherEvent is the event for watcher
type ObjectEntityWatcherFilter ¶ added in v1.0.1
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 ¶ added in v1.0.1
func FilterCategory(categories ...ObjectCategory) ObjectEntityWatcherFilter
FilterCategory returns a bool function to check if the object entity is filtered by category or not
type ObjectRegistry ¶ added in v1.0.1
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 ¶ added in v1.0.1
func (or *ObjectRegistry) CloseWatcher(name string)
CloseWatcher closes and releases a watcher.
func (*ObjectRegistry) NewWatcher ¶ added in v1.0.1
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) ObjectSpec ¶
func (s *Spec) ObjectSpec() interface{}
ObjectSpec returns the object spec in its own type.
func (*Spec) RawSpec ¶ added in v1.0.1
RawSpec returns the final complete spec in type map[string]interface{}.
func (*Spec) YAMLConfig ¶
YAMLConfig returns the config in yaml format.
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 ¶ added in v1.4.0
func NewDefaultMock() *Supervisor
NewDefaultMock return a mock supervisor for testing purpose
func NewMock ¶ added in v1.4.0
func NewMock(options *option.Options, cls cluster.Cluster, businessControllers sync.Map, systemControllers sync.Map, 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) 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 ¶ added in v1.0.1
func (s *Supervisor) GetBusinessController(name string) (*ObjectEntity, bool)
GetBusinessController returns the business controller with the existing flag.
func (*Supervisor) GetSystemController ¶ added in v1.0.1
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 ¶ added in v1.3.0
func (s *Supervisor) MustGetSystemController(name string) *ObjectEntity
MustGetSystemController wraps GetSystemController with panic.
func (*Supervisor) NewObjectEntityFromConfig ¶ added in v1.0.1
func (s *Supervisor) NewObjectEntityFromConfig(config string) (*ObjectEntity, error)
NewObjectEntityFromConfig creates an object entity from configuration
func (*Supervisor) NewObjectEntityFromSpec ¶ added in v1.0.1
func (s *Supervisor) NewObjectEntityFromSpec(spec *Spec) (*ObjectEntity, error)
NewObjectEntityFromSpec creates an object entity from a spec
func (*Supervisor) NewSpec ¶ added in v1.1.0
func (s *Supervisor) NewSpec(yamlConfig string) (spec *Spec, err error)
NewSpec creates a spec and validates it.
func (*Supervisor) ObjectRegistry ¶ added in v1.0.1
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 ¶ added in v1.0.1
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 ¶ added in v1.0.1
type TrafficObject interface { Object // Init initializes the Object. Init(superSpec *Spec, muxMapper protocol.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 protocol.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.