core

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2021 License: BSD-3-Clause Imports: 29 Imported by: 26

Documentation

Index

Constants

View Source
const (
	DDDEBUG  = types.LLDDDEBUG
	DDEBUG   = types.LLDDEBUG
	DEBUG    = types.LLDEBUG
	INFO     = types.LLINFO
	NOTICE   = types.LLNOTICE
	WARNING  = types.LLWARNING
	ERROR    = types.LLERROR
	CRITICAL = types.LLCRITICAL
	FATAL    = types.LLFATAL
	PANIC    = types.LLPANIC
)

create shortcut aliases for log levels

View Source
const AddrURL = "type.googleapis.com/IPv4.IPv4OverEthernet/Ifaces/kraken/Ip/Ip"

Variables

View Source
var MutationEventString = map[pb.MutationControl_Type]string{
	MutationEvent_MUTATE:    "MUTATE",
	MutationEvent_INTERRUPT: "INTERRUPT",
}
View Source
var Registry = NewKrakenRegistry()

Registry is where we register modules & extensions It provides various internal functions We need this prior to init(), so it must be a global

View Source
var StateChangeTypeString = map[pb.StateChangeControl_Type]string{
	StateChange_CREATE:     "CREATE",
	StateChange_READ:       "READ",
	StateChange_UPDATE:     "UPDATE",
	StateChange_DELETE:     "DELETE",
	StateChange_CFG_READ:   "CFG_READ",
	StateChange_CFG_UPDATE: "CFG_UPDATE",
}

Functions

func BuildInfo

func BuildInfo() (r string)

func ChanSender

func ChanSender(ev types.Event, c chan<- types.Event) error

ChanSender is for the simple case were we just retransmit on a chan

func CreateDiscovers added in v0.2.0

func CreateDiscovers(url string) (map[string]reflect.Value, error)

func CreateMutation added in v0.2.0

func CreateMutation(si types.ServiceInstance, m *Mutation) (types.StateMutation, error)

createMutation turns a string mutation definition into a StateMutation

func DefaultRootSpec

func DefaultRootSpec() types.StateSpec

DefaultRootSpec provides a sensible root StateSpec to build the mutation graph off of

func FilterRegexp

func FilterRegexp(ev types.Event, re *regexp.Regexp) (r bool)

FilterRegexp matches URL to a compiled Regexp

func FilterRegexpStr

func FilterRegexpStr(ev types.Event, re string) (r bool)

FilterRegexpStr matches URL to a regexp (string) FilterRegexp is probably more efficient for repeated filtering

func FilterSimple

func FilterSimple(ev types.Event, match []string) (r bool)

FilterSimple is mostly for an example; it's not very useful

func LookupEnum added in v0.2.0

func LookupEnum(url string) (enumName string, enumType reflect.Type, valueMap map[string]int32, err error)

LookupEnum finds an enum and its value map based on URL

func LookupEnumValue added in v0.2.0

func LookupEnumValue(url string, value string) (interface{}, error)

LookupEnumValue maps an enum value to a reflect.Value based on URL and value string

func ModuleExecute

func ModuleExecute(id, module, sock string)

moduleExecute does all of the necessary steps to start the service instance this is the actual entry point for a new module process

func MustLookupEnum added in v0.2.0

func MustLookupEnum(url string) (enumName string, enumType reflect.Type, valueMap map[string]int32)

MustLookupEnum performs LookupEnum, but panics if enum lookup fails

func MustLookupEnumValue added in v0.2.0

func MustLookupEnumValue(url string, value string) interface{}

MustLookupEnumValue performs LookupEnumValue, but panics if lookup fails

func MustValueFromString added in v0.2.0

func MustValueFromString(url, value string) reflect.Value

MustValueFromString wraps ValueFromString, but panics on error

func NewEvent

func NewEvent(t types.EventType, url string, data interface{}) types.Event

NewEvent creates an initialized, fully specified Event

func NewStateChangeEvent

func NewStateChangeEvent(t pb.StateChangeControl_Type, u string, v reflect.Value) types.Event

NewStateChangeEvent creates a new event of this time, fully specified

func ServiceLoggerListener

func ServiceLoggerListener(l types.Logger, c <-chan LoggerEvent)

ServiceLoggerListener receives log events through a channel and passes them to a secondary logger interface This can be run as a goroutine

func ValueFromString added in v0.2.0

func ValueFromString(url, value string) (v reflect.Value, err error)

ValueFromString tries to convert a string to a reflect.Value based on URL

Types

type Context

type Context struct {
	Logger  ServiceLogger
	Query   QueryEngine
	SubChan chan<- types.EventListener
	Self    types.NodeID
	Parents []string
	SDE     ContextSDE
	SSE     ContextSSE
	SME     ContextSME
	RPC     ContextRPC
	Sm      types.ServiceManager // API needs this
	// contains filtered or unexported fields
}

Context contains information about the current running context such as who we are, and to whom we belong.

type ContextRPC

type ContextRPC struct {
	Network      string
	Addr         string
	Port         int
	Path         string // path for UNIX socket
	NetListner   net.Listener
	UNIXListener net.Listener
}

type ContextSDE

type ContextSDE struct {
	InitialCfg []types.Node
	InitialDsc []types.Node
}

type ContextSME

type ContextSME struct {
	RootSpec types.StateSpec
}

type ContextSSE

type ContextSSE struct {
	Network   string
	Addr      string
	Port      int
	AddrURL   string
	HelloTime time.Duration
	DeadTime  time.Duration
}

type DiscoveryEvent

type DiscoveryEvent struct {
	ID      string // ID of a service instance
	URL     string // fully qualified, with node
	ValueID string
}

A DiscoveryEvent announce a discovery This should probably live elsewhere This maps directly to a pb.DiscoveryControl

func (*DiscoveryEvent) String

func (de *DiscoveryEvent) String() string

type Event

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

An Event is a generic container for internal events, like state changes

func (*Event) Data

func (v *Event) Data() interface{}

func (*Event) Type

func (v *Event) Type() types.EventType

func (*Event) URL

func (v *Event) URL() string

type EventDispatchEngine

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

EventDispatchEngine redistributes event to (possibly filtered) listeners.

func NewEventDispatchEngine

func NewEventDispatchEngine(ctx Context) (v *EventDispatchEngine)

NewEventDispatchEngine creates an initialized EventDispatchEngine

func (*EventDispatchEngine) AddListener

func (v *EventDispatchEngine) AddListener(el types.EventListener) (e error)

AddListener gets called to add a Listener; Listeners are filtered subscribers

func (*EventDispatchEngine) EventChan

func (v *EventDispatchEngine) EventChan() chan<- []types.Event

EventChan is the channel emitters should send new events on

func (*EventDispatchEngine) GetLoggerLevel

func (v *EventDispatchEngine) GetLoggerLevel() types.LoggerLevel

func (*EventDispatchEngine) GetModule

func (v *EventDispatchEngine) GetModule() string

func (*EventDispatchEngine) IsEnabledFor

func (v *EventDispatchEngine) IsEnabledFor(level types.LoggerLevel) bool

func (*EventDispatchEngine) Log

func (v *EventDispatchEngine) Log(level types.LoggerLevel, m string)

func (*EventDispatchEngine) Logf

func (v *EventDispatchEngine) Logf(level types.LoggerLevel, fmt string, va ...interface{})

func (*EventDispatchEngine) Run

func (v *EventDispatchEngine) Run(ready chan<- interface{})

Run is a goroutine than handles event dispatch and subscriptions There's currently no way to stop this once it's started.

func (*EventDispatchEngine) SetLoggerLevel

func (v *EventDispatchEngine) SetLoggerLevel(level types.LoggerLevel)

func (*EventDispatchEngine) SetModule

func (v *EventDispatchEngine) SetModule(name string)

func (*EventDispatchEngine) SubscriptionChan

func (v *EventDispatchEngine) SubscriptionChan() chan<- types.EventListener

SubscriptionChan gets the channel we can subscribe new EventListeners with

type EventEmitter

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

EventEmitter is really just a helper object, and not a core type. It simplifies making an engine that Emits events to event dispatch.

func NewEventEmitter

func NewEventEmitter(t types.EventType) *EventEmitter

NewEventEmitter creates a new initialized EventEmitter. It must be Subscribed to do anything interesting.

func (*EventEmitter) Emit

func (m *EventEmitter) Emit(v []types.Event)

Emit emits (non-blocking) a slice of Events NOT a goroutine; handles that internally

func (*EventEmitter) EmitOne

func (m *EventEmitter) EmitOne(v types.Event)

EmitOne is a helper for when we have a single event

func (*EventEmitter) EventType

func (m *EventEmitter) EventType() types.EventType

EventType returns the event type that this Emitter sends

func (*EventEmitter) Subscribe

func (m *EventEmitter) Subscribe(id string, c chan<- []types.Event) (e error)

Subscribe links the Emitter to an Event chan, allowing it to actually send events.

func (*EventEmitter) Unsubscribe

func (m *EventEmitter) Unsubscribe(id string) (e error)

Unsubscribe removes an event chan from the subscriber list

type EventListener

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

An EventListener implementation that leaves filter/send as arbitrary function pointers.

func NewEventListener

func NewEventListener(name string, t types.EventType, filter func(types.Event) bool, send func(types.Event) error) *EventListener

NewEventListener creates a new initialized, full specified EventListener

func (*EventListener) Filter

func (v *EventListener) Filter(ev types.Event) (r bool)

Filter processes a filter callback, returns whether this event would be filtered. Send uses this automatically.

func (*EventListener) Name

func (v *EventListener) Name() string

Name returns the name of this listener; names are used to make unique keys, must be unique

func (*EventListener) Send

func (v *EventListener) Send(ev types.Event) (e error)

Send processes the callback to send the event to the object listening.

func (*EventListener) SetState

func (v *EventListener) SetState(s types.EventListenerState)

SetState sets the listener runstate

func (*EventListener) State

State is the current state of the listener; listeners can be temporarily muted, for instance

func (*EventListener) Type

func (v *EventListener) Type() types.EventType

Type returns the type of event we're listening for. This is another kind of filter.

type Kraken

type Kraken struct {
	Ctx Context
	Ede *EventDispatchEngine
	Sde *StateDifferenceEngine
	Sse *StateSyncEngine
	Sme *StateMutationEngine
	Api *ModuleAPIServer
	Sm  *ServiceManager
	// contains filtered or unexported fields
}

A Kraken is a mythical giant squid-beast.

func NewKraken

func NewKraken(self types.Node, parents []string, logger types.Logger) *Kraken

NewKraken creates a new Kraken object with proper intialization

func (*Kraken) Bootstrap

func (k *Kraken) Bootstrap()

Bootstrap creates all service instances in the correct order with all of the correct plumbing

func (*Kraken) Cmd

func (*Kraken) Cmd() *exec.Cmd

func (*Kraken) Config

func (*Kraken) Config() *any.Any

func (*Kraken) Emit

func (k *Kraken) Emit(v []types.Event)

func (*Kraken) EmitOne

func (k *Kraken) EmitOne(v types.Event)

func (*Kraken) EventType

func (k *Kraken) EventType() types.EventType

func (*Kraken) Exe

func (*Kraken) Exe() string

func (*Kraken) GetLoggerLevel

func (k *Kraken) GetLoggerLevel() types.LoggerLevel

func (*Kraken) GetModule

func (k *Kraken) GetModule() string

func (*Kraken) GetState

func (*Kraken) GetState() types.ServiceState

func (*Kraken) ID

func (sse *Kraken) ID() string

implement types.ServiceInstance this is a little artificial, but it's a special case many of these would never becaused because it's not actually managed by ServiceManager

func (*Kraken) IsEnabledFor

func (k *Kraken) IsEnabledFor(level types.LoggerLevel) bool

func (*Kraken) Log

func (k *Kraken) Log(level types.LoggerLevel, m string)

func (*Kraken) Logf

func (k *Kraken) Logf(level types.LoggerLevel, fmt string, v ...interface{})

func (*Kraken) Message

func (*Kraken) Message() *pb.ServiceInstance

func (*Kraken) Module

func (sse *Kraken) Module() string

func (*Kraken) Name

func (k *Kraken) Name() string

func (*Kraken) Release

func (k *Kraken) Release()

Release the Kraken... the Kraken process itself has the core task of managing services

func (*Kraken) Run

func (k *Kraken) Run()

Run starts all services as goroutines

func (*Kraken) SetCmd

func (*Kraken) SetCmd(*exec.Cmd)

func (*Kraken) SetCtl

func (*Kraken) SetCtl(chan<- types.ServiceControl)

func (*Kraken) SetLoggerLevel

func (k *Kraken) SetLoggerLevel(level types.LoggerLevel)

func (*Kraken) SetModule

func (k *Kraken) SetModule(name string)

func (*Kraken) SetState

func (*Kraken) SetState(types.ServiceState)

func (*Kraken) State

func (*Kraken) State() types.ServiceState

func (*Kraken) Stop

func (*Kraken) Stop()

func (*Kraken) Subscribe

func (k *Kraken) Subscribe(id string, c chan<- []types.Event) error

func (*Kraken) Unsubscribe

func (k *Kraken) Unsubscribe(id string) error

func (*Kraken) UpdateConfig

func (*Kraken) UpdateConfig(*any.Any)

type KrakenRegistry

type KrakenRegistry struct {
	Modules          map[string]types.Module
	Extensions       map[string]types.Extension
	Discoverables    map[string]map[string]map[string]reflect.Value // d["instance_id"]["property_url"]["value_id"]
	Mutations        map[string]map[string]types.StateMutation      // m["instance_id"]["mutation_id"]
	ServiceInstances map[string]map[string]types.ServiceInstance    // s["module"]["instance_id"]
}

func NewKrakenRegistry

func NewKrakenRegistry() *KrakenRegistry

func (*KrakenRegistry) RegisterDiscoverable

func (r *KrakenRegistry) RegisterDiscoverable(si types.ServiceInstance, d map[string]map[string]reflect.Value)

RegisterDiscoverable adds a map of discoverables the module can emit

func (*KrakenRegistry) RegisterExtension

func (r *KrakenRegistry) RegisterExtension(e types.Extension)

RegisterExtension adds an extension to the map if it hasn't been already It's probably a good idea for this to be done in init()

func (*KrakenRegistry) RegisterModule

func (r *KrakenRegistry) RegisterModule(m types.Module)

RegisterModule adds an module to the map if it hasn't been already It's probably a good idea for this to be done in init()

func (*KrakenRegistry) RegisterMutations

func (r *KrakenRegistry) RegisterMutations(si types.ServiceInstance, d map[string]types.StateMutation)

RegisterMutations declares mutations a module can perform

func (*KrakenRegistry) RegisterServiceInstance

func (r *KrakenRegistry) RegisterServiceInstance(m types.Module, d map[string]types.ServiceInstance)

RegisterServiceInstance creates a service instance with a particular module.RegisterServiceInstance Note: This can be done after the fact, but serviceinstances that are added after runtime cannot (currently) be used as part of mutation chains.

func (*KrakenRegistry) Resolve

func (r *KrakenRegistry) Resolve(url string) (proto.Message, error)

type LoggerEvent

type LoggerEvent struct {
	Level   types.LoggerLevel
	Module  string
	Message string
}

LoggerEvent is used by ServiceLogger to send log events over channels

type ModuleAPIClient

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

func NewModuleAPIClient

func NewModuleAPIClient(sock string) *ModuleAPIClient

func (*ModuleAPIClient) DiscoveryInit

func (a *ModuleAPIClient) DiscoveryInit(id string) (c chan<- types.Event, e error)

func (*ModuleAPIClient) EventInit

func (a *ModuleAPIClient) EventInit(id string, module string) (c <-chan types.Event, e error)

func (*ModuleAPIClient) GetLoggerLevel

func (a *ModuleAPIClient) GetLoggerLevel() types.LoggerLevel

func (*ModuleAPIClient) GetModule

func (a *ModuleAPIClient) GetModule() string

func (*ModuleAPIClient) IsEnabledFor

func (a *ModuleAPIClient) IsEnabledFor(level types.LoggerLevel) bool

func (*ModuleAPIClient) Log

func (a *ModuleAPIClient) Log(level types.LoggerLevel, m string)

func (*ModuleAPIClient) Logf

func (a *ModuleAPIClient) Logf(level types.LoggerLevel, fmt string, v ...interface{})

func (*ModuleAPIClient) LoggerInit

func (a *ModuleAPIClient) LoggerInit(si string) (e error)

func (*ModuleAPIClient) MutationInit

func (a *ModuleAPIClient) MutationInit(id string, module string) (c <-chan types.Event, e error)

func (*ModuleAPIClient) QueryCreate

func (a *ModuleAPIClient) QueryCreate(n types.Node) (r types.Node, e error)

func (*ModuleAPIClient) QueryDelete

func (a *ModuleAPIClient) QueryDelete(id string) (r types.Node, e error)

QueryDelete deletes a node by id

func (*ModuleAPIClient) QueryDeleteAll

func (a *ModuleAPIClient) QueryDeleteAll() (r []types.Node, e error)

func (*ModuleAPIClient) QueryFreeze

func (a *ModuleAPIClient) QueryFreeze() (e error)

func (*ModuleAPIClient) QueryFrozen

func (a *ModuleAPIClient) QueryFrozen() (r bool, e error)

func (*ModuleAPIClient) QueryGetValue

func (a *ModuleAPIClient) QueryGetValue(id string, url string) (value interface{}, err error)

QueryGetValue returns the configuration value `url` for `id`

func (*ModuleAPIClient) QueryGetValueDsc

func (a *ModuleAPIClient) QueryGetValueDsc(id string, url string) (value interface{}, err error)

QueryGetValueDsc returns the configuration value `url` for `id`

func (*ModuleAPIClient) QueryGetValues

func (a *ModuleAPIClient) QueryGetValues(id string, urls []string) (values map[string]interface{}, err error)

QueryGetValues returns the configuration values `urls` for `id`

func (*ModuleAPIClient) QueryGetValuesDsc

func (a *ModuleAPIClient) QueryGetValuesDsc(id string, urls []string) (values map[string]interface{}, err error)

QueryGetValuesDsc returns the discoverable values `urls` for `id`

func (*ModuleAPIClient) QueryMutationEdges

func (a *ModuleAPIClient) QueryMutationEdges() (r pb.MutationEdgeList, e error)

func (*ModuleAPIClient) QueryMutationNodes

func (a *ModuleAPIClient) QueryMutationNodes() (r pb.MutationNodeList, e error)

func (*ModuleAPIClient) QueryNodeMutationEdges

func (a *ModuleAPIClient) QueryNodeMutationEdges(id string) (r pb.MutationEdgeList, e error)

func (*ModuleAPIClient) QueryNodeMutationNodes

func (a *ModuleAPIClient) QueryNodeMutationNodes(id string) (r pb.MutationNodeList, e error)

func (*ModuleAPIClient) QueryNodeMutationPath

func (a *ModuleAPIClient) QueryNodeMutationPath(id string) (r pb.MutationPath, e error)

func (*ModuleAPIClient) QueryRead

func (a *ModuleAPIClient) QueryRead(id string) (r types.Node, e error)

func (*ModuleAPIClient) QueryReadAll

func (a *ModuleAPIClient) QueryReadAll() (r []types.Node, e error)

func (*ModuleAPIClient) QueryReadAllDsc

func (a *ModuleAPIClient) QueryReadAllDsc() (r []types.Node, e error)

func (*ModuleAPIClient) QueryReadDsc

func (a *ModuleAPIClient) QueryReadDsc(id string) (r types.Node, e error)

func (*ModuleAPIClient) QuerySetValue

func (a *ModuleAPIClient) QuerySetValue(id string, url string, value interface{}) (err error)

QuerySetValue sets a single configurate state value on node ID

func (*ModuleAPIClient) QuerySetValueDsc

func (a *ModuleAPIClient) QuerySetValueDsc(id string, url string, value interface{}) (err error)

QuerySetValueDsc sets a single discoverable state value on node ID

func (*ModuleAPIClient) QuerySetValues

func (a *ModuleAPIClient) QuerySetValues(id string, values map[string]interface{}) (ret map[string]interface{}, err error)

QuerySetValues sets a specified list of configuration state values on node ID

func (*ModuleAPIClient) QuerySetValuesDsc

func (a *ModuleAPIClient) QuerySetValuesDsc(id string, values map[string]interface{}) (ret map[string]interface{}, err error)

QuerySetValuesDsc sets a specified list of discoverable state values on node ID

func (*ModuleAPIClient) QueryThaw

func (a *ModuleAPIClient) QueryThaw() (e error)

func (*ModuleAPIClient) QueryUpdate

func (a *ModuleAPIClient) QueryUpdate(n types.Node) (r types.Node, e error)

func (*ModuleAPIClient) QueryUpdateDsc

func (a *ModuleAPIClient) QueryUpdateDsc(n types.Node) (r types.Node, e error)

func (*ModuleAPIClient) Self

func (a *ModuleAPIClient) Self() types.NodeID

func (*ModuleAPIClient) ServiceInit

func (a *ModuleAPIClient) ServiceInit(id string, module string) (c <-chan types.ServiceControl, e error)

func (*ModuleAPIClient) SetLoggerLevel

func (a *ModuleAPIClient) SetLoggerLevel(level types.LoggerLevel)

func (*ModuleAPIClient) SetModule

func (a *ModuleAPIClient) SetModule(name string)

func (*ModuleAPIClient) SetSelf

func (a *ModuleAPIClient) SetSelf(s types.NodeID)

type ModuleAPIServer

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

ModuleAPIServer is the gateway for gRPC calls into Kraken (i.e. the Module interface)

func NewModuleAPIServer

func NewModuleAPIServer(ctx Context) *ModuleAPIServer

NewModuleAPIServer creates a new, initialized API

func (*ModuleAPIServer) DiscoveryInit

func (s *ModuleAPIServer) DiscoveryInit(stream pb.ModuleAPI_DiscoveryInitServer) (e error)

DiscoveryInit handles discoveries from nodes This dispatches nodes

func (*ModuleAPIServer) Emit

func (s *ModuleAPIServer) Emit(v []types.Event)

func (*ModuleAPIServer) EmitOne

func (s *ModuleAPIServer) EmitOne(v types.Event)

func (*ModuleAPIServer) EventInit

func (s *ModuleAPIServer) EventInit(sir *pb.ServiceInitRequest, stream pb.ModuleAPI_EventInitServer) (e error)

EventInit handles establishing the event stream This just caputures all events and sends them over the stream

func (*ModuleAPIServer) EventType

func (s *ModuleAPIServer) EventType() types.EventType

func (*ModuleAPIServer) GetLoggerLevel

func (s *ModuleAPIServer) GetLoggerLevel() types.LoggerLevel

func (*ModuleAPIServer) GetModule

func (s *ModuleAPIServer) GetModule() string

func (*ModuleAPIServer) IsEnabledFor

func (s *ModuleAPIServer) IsEnabledFor(level types.LoggerLevel) bool

func (*ModuleAPIServer) Log

func (s *ModuleAPIServer) Log(level types.LoggerLevel, m string)

func (*ModuleAPIServer) Logf

func (s *ModuleAPIServer) Logf(level types.LoggerLevel, fmt string, v ...interface{})

func (*ModuleAPIServer) LoggerInit

func (s *ModuleAPIServer) LoggerInit(stream pb.ModuleAPI_LoggerInitServer) (e error)

LoggerInit initializes and RPC logger stream

func (*ModuleAPIServer) MutationInit

func (s *ModuleAPIServer) MutationInit(sir *pb.ServiceInitRequest, stream pb.ModuleAPI_MutationInitServer) (e error)

MutationInit handles establishing the mutation stream This just caputures (filtered) mutation events and sends them over the stream

func (*ModuleAPIServer) QueryCreate

func (s *ModuleAPIServer) QueryCreate(ctx context.Context, in *pb.Query) (out *pb.Query, e error)

func (*ModuleAPIServer) QueryDelete

func (s *ModuleAPIServer) QueryDelete(ctx context.Context, in *pb.Query) (out *pb.Query, e error)

func (*ModuleAPIServer) QueryDeleteAll

func (s *ModuleAPIServer) QueryDeleteAll(ctx context.Context, in *ptypes.Empty) (out *pb.QueryMulti, e error)

func (*ModuleAPIServer) QueryFreeze

func (s *ModuleAPIServer) QueryFreeze(ctx context.Context, in *ptypes.Empty) (out *pb.Query, e error)

func (*ModuleAPIServer) QueryFrozen

func (s *ModuleAPIServer) QueryFrozen(ctx context.Context, in *ptypes.Empty) (out *pb.Query, e error)

func (*ModuleAPIServer) QueryMutationEdges

func (s *ModuleAPIServer) QueryMutationEdges(ctx context.Context, in *ptypes.Empty) (out *pb.Query, e error)

func (*ModuleAPIServer) QueryMutationNodes

func (s *ModuleAPIServer) QueryMutationNodes(ctx context.Context, in *ptypes.Empty) (out *pb.Query, e error)

func (*ModuleAPIServer) QueryNodeMutationEdges

func (s *ModuleAPIServer) QueryNodeMutationEdges(ctx context.Context, in *pb.Query) (out *pb.Query, e error)

func (*ModuleAPIServer) QueryNodeMutationNodes

func (s *ModuleAPIServer) QueryNodeMutationNodes(ctx context.Context, in *pb.Query) (out *pb.Query, e error)

func (*ModuleAPIServer) QueryNodeMutationPath

func (s *ModuleAPIServer) QueryNodeMutationPath(ctx context.Context, in *pb.Query) (out *pb.Query, e error)

func (*ModuleAPIServer) QueryRead

func (s *ModuleAPIServer) QueryRead(ctx context.Context, in *pb.Query) (out *pb.Query, e error)

func (*ModuleAPIServer) QueryReadAll

func (s *ModuleAPIServer) QueryReadAll(ctx context.Context, in *ptypes.Empty) (out *pb.QueryMulti, e error)

func (*ModuleAPIServer) QueryReadAllDsc

func (s *ModuleAPIServer) QueryReadAllDsc(ctx context.Context, in *ptypes.Empty) (out *pb.QueryMulti, e error)

func (*ModuleAPIServer) QueryReadDsc

func (s *ModuleAPIServer) QueryReadDsc(ctx context.Context, in *pb.Query) (out *pb.Query, e error)

func (*ModuleAPIServer) QueryThaw

func (s *ModuleAPIServer) QueryThaw(ctx context.Context, in *ptypes.Empty) (out *pb.Query, e error)

func (*ModuleAPIServer) QueryUpdate

func (s *ModuleAPIServer) QueryUpdate(ctx context.Context, in *pb.Query) (out *pb.Query, e error)

func (*ModuleAPIServer) QueryUpdateDsc

func (s *ModuleAPIServer) QueryUpdateDsc(ctx context.Context, in *pb.Query) (out *pb.Query, e error)

func (*ModuleAPIServer) Run

func (s *ModuleAPIServer) Run(ready chan<- interface{})

Run starts the API service listener

func (*ModuleAPIServer) ServiceInit

func (s *ModuleAPIServer) ServiceInit(sir *pb.ServiceInitRequest, stream pb.ModuleAPI_ServiceInitServer) (e error)

func (*ModuleAPIServer) SetLoggerLevel

func (s *ModuleAPIServer) SetLoggerLevel(level types.LoggerLevel)

func (*ModuleAPIServer) SetModule

func (s *ModuleAPIServer) SetModule(name string)

func (*ModuleAPIServer) Subscribe

func (s *ModuleAPIServer) Subscribe(id string, c chan<- []types.Event) error

func (*ModuleAPIServer) Unsubscribe

func (s *ModuleAPIServer) Unsubscribe(id string) error

type Mutation added in v0.2.0

type Mutation struct {
	Mutates  map[string][2]string
	Requires map[string]string
	Excludes map[string]string
	Context  string
	Timeout  string
	FailTo   [2]string
	Handler  func(mut string, cfg, dsc types.Node)
}

a mutation object records mutations as strings we have to lookup types & values at runtime (with CreateMutation) This helps generate more generic module objects, as we can perform lookups after The node object with its various extensions is created.

type MutationEvent

type MutationEvent struct {
	Type pb.MutationControl_Type
	// strictly speaking, we may only need the Cfg
	// but we generally have this info on hand anyway
	NodeCfg  types.Node
	NodeDsc  types.Node
	Mutation [2]string // [0] = module, [1] = mutid
}

func (*MutationEvent) String

func (me *MutationEvent) String() string

type Node

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

A Node object is the basic data store of the state engine. It is also a wrapper for a protobuf object.

func NewNodeFromBinary

func NewNodeFromBinary(b []byte) *Node

NewNodeFromBinary creates a new node from Binary (proto)

func NewNodeFromJSON

func NewNodeFromJSON(j []byte) *Node

NewNodeFromJSON creates a new node from JSON bytes

func NewNodeFromMessage

func NewNodeFromMessage(m *pb.Node) *Node

NewNodeFromMessage creats a new node based on a proto message

func NewNodeWithID

func NewNodeWithID(id string) *Node

NewNodeWithID creates a new node with an ID pre-set

func (*Node) AddExtension

func (n *Node) AddExtension(m proto.Message) (e error)

AddExtension adds a new extension to the node. It will fail if marshal fails, or if it's a dupe.

func (*Node) AddService

func (n *Node) AddService(si *pb.ServiceInstance) (e error)

AddService adds a ServiceInstance to the node, updates the index

func (*Node) Binary

func (n *Node) Binary() []byte

Binary returns a Binary representation of the node

func (*Node) DelExtension

func (n *Node) DelExtension(url string)

DelExtension removes an extension from the node. Has no return value, even if extension isn't there.

func (*Node) DelService

func (n *Node) DelService(id string)

DelService removes a ServiceInstance from a node This does not error if the instance does not exist

func (*Node) Diff

func (n *Node) Diff(node types.Node, prefix string) (r []string, e error)

Diff finds URLs that are different between this Node and another prefix allows a string prefix to be prepended to diffs note: we have to be especially careful about locking in this function

func (*Node) GetExtensionURLs

func (n *Node) GetExtensionURLs() (r []string)

GetExtensionURLs returns a slice of currently added extensions

func (*Node) GetExtensions

func (n *Node) GetExtensions() (r map[string]proto.Message)

GetExtensions returns the exts map

func (*Node) GetService

func (n *Node) GetService(id string) (r *pb.ServiceInstance)

GetService returns the ServiceInstance by ID

func (*Node) GetServiceIDs

func (n *Node) GetServiceIDs() (r []string)

GetServiceIDs returns a slice of service ID strings

func (*Node) GetServices

func (n *Node) GetServices() (r []*pb.ServiceInstance)

GetServices returns a slice of pb.ServiceInstance objects

func (*Node) GetValue

func (n *Node) GetValue(url string) (v reflect.Value, e error)

GetValue returns a specific value (reflect.Value) by URL note: we can't just wrap everything in a lock because n.GetService will lock too

func (*Node) GetValues

func (n *Node) GetValues(urls []string) (v map[string]reflect.Value, e error)

GetValues gets multiple values in one call

func (*Node) HasExtension

func (n *Node) HasExtension(url string) bool

HasExtension determines if the node has an extension by URL

func (*Node) HasService

func (n *Node) HasService(id string) bool

HasService returns a bool stating if a service exists

func (*Node) ID

func (n *Node) ID() types.NodeID

ID returns the NodeID object for the node Note: we don't lock on this under the assumption that ID's don't typically change

func (*Node) JSON

func (n *Node) JSON() []byte

JSON returns a JSON representation of the node

func (*Node) Merge

func (n *Node) Merge(node types.Node, pre string) (changes []string, e error)

Merge takes any non-nil values in m into n We don't use protobuf's merge because we generally want to know what values changed! It returns a slice of URLs to changes made

func (*Node) MergeDiff

func (n *Node) MergeDiff(node types.Node, diff []string) (changes []string, e error)

MergeDiff does a merge if of what is in diff (URLs) only it returns a slice of changes made

func (*Node) Message

func (n *Node) Message() proto.Message

Message returns the proto.Message interface for the node

func (*Node) ParentID

func (n *Node) ParentID() (pid types.NodeID)

ParentID returns the NodeID of the parent of this node

func (*Node) SetValue

func (n *Node) SetValue(url string, value reflect.Value) (v reflect.Value, e error)

SetValue sets a specific value (reflect.Value) by URL Returns the value, post-set (same if input if all went well) note: we can't just wrap everything in a lock because n.GetService will lock too

func (*Node) SetValues

func (n *Node) SetValues(valmap map[string]reflect.Value) (v map[string]reflect.Value)

SetValues sets multiple values. TODO: Need a way to dynamically added new sub-structs

func (*Node) String

func (n *Node) String() string

String is important, as we can make sure prints on a Node object obey locking

type Query

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

Query objects describe a state query

func NewQuery

func NewQuery(t types.QueryType, s types.QueryState, url string, v []reflect.Value) (*Query, chan types.QueryResponse)

NewQuery creates an initialized query; this is how all Queries should be created

func (*Query) ResponseChan

func (q *Query) ResponseChan() chan<- types.QueryResponse

ResponseChan returns the channel that a QueryResponse should be sent on

func (*Query) State

func (q *Query) State() types.QueryState

State returns the state (Dsc, Cfg, or Both) we are querying

func (*Query) Type

func (q *Query) Type() types.QueryType

Type returns the type of the query (e.g., Create, Update...)

func (*Query) URL

func (q *Query) URL() string

URL returns a string representing the object being queried

func (*Query) Value

func (q *Query) Value() []reflect.Value

Value returns an array of associated refelct.Value's with this query

type QueryEngine

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

QueryEngine provides a simple mechanism for state queries FIXME: QueryEngine should probably be abstracted

func NewQueryEngine

func NewQueryEngine(sd chan<- types.Query, sm chan<- types.Query) *QueryEngine

NewQueryEngine creates a specified QueryEngine; this is the only way to set it up

func (*QueryEngine) Create

func (q *QueryEngine) Create(n types.Node) (nc types.Node, e error)

Create can be used to create a new node in the Engine

func (*QueryEngine) Delete

func (q *QueryEngine) Delete(nid types.NodeID) (nc types.Node, e error)

Delete will delete a Node from the Engine

func (*QueryEngine) DeleteAll

func (q *QueryEngine) DeleteAll() (nc []types.Node, e error)

DeleteAll will delete all nodes from the Engine. !!!DANGEROUS!!!

func (*QueryEngine) Freeze

func (q *QueryEngine) Freeze() (e error)

func (*QueryEngine) Frozen

func (q *QueryEngine) Frozen() (b bool, e error)

func (*QueryEngine) GetValue

func (q *QueryEngine) GetValue(url string) (v reflect.Value, e error)

GetValue will get a value from the Cfg state via a URL

func (*QueryEngine) GetValueDsc

func (q *QueryEngine) GetValueDsc(url string) (v reflect.Value, e error)

GetValueDsc will get a value from the Dsc state via a URL

func (*QueryEngine) Read

func (q *QueryEngine) Read(n types.NodeID) (nc types.Node, e error)

Read will read a node from the Engine's Cfg store

func (*QueryEngine) ReadAll

func (q *QueryEngine) ReadAll() (nc []types.Node, e error)

ReadAll will get a slice of all nodes from the Cfg state

func (*QueryEngine) ReadAllDsc

func (q *QueryEngine) ReadAllDsc() (nc []types.Node, e error)

ReadAllDsc will get a slice of all nodes from the Dsc state

func (*QueryEngine) ReadDsc

func (q *QueryEngine) ReadDsc(n types.NodeID) (nc types.Node, e error)

ReadDsc will read a node from the Engine's Dsc store

func (*QueryEngine) ReadMutationEdges

func (q *QueryEngine) ReadMutationEdges(url string) (mc pb.MutationEdgeList, e error)

func (*QueryEngine) ReadMutationNodes

func (q *QueryEngine) ReadMutationNodes(url string) (mc pb.MutationNodeList, e error)

func (*QueryEngine) ReadNodeMutationEdges

func (q *QueryEngine) ReadNodeMutationEdges(url string) (mc pb.MutationEdgeList, e error)

func (*QueryEngine) ReadNodeMutationNodes

func (q *QueryEngine) ReadNodeMutationNodes(url string) (mc pb.MutationNodeList, e error)

func (*QueryEngine) ReadNodeMutationPath

func (q *QueryEngine) ReadNodeMutationPath(url string) (mc pb.MutationPath, e error)

func (*QueryEngine) SetValue

func (q *QueryEngine) SetValue(url string, v reflect.Value) (rv reflect.Value, e error)

SetValue will set a value in the Cfg state via a URL

func (*QueryEngine) SetValueDsc

func (q *QueryEngine) SetValueDsc(url string, v reflect.Value) (rv reflect.Value, e error)

SetValueDsc will set a value in the Dsc state via a URL

func (*QueryEngine) Thaw

func (q *QueryEngine) Thaw() (e error)

func (*QueryEngine) Update

func (q *QueryEngine) Update(n types.Node) (nc types.Node, e error)

Update will update a node in the Engine's Cfg store

func (*QueryEngine) UpdateDsc

func (q *QueryEngine) UpdateDsc(n types.Node) (nc types.Node, e error)

UpdateDsc will update a node in the Engine's Dsc store

type QueryResponse

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

A QueryResponse is sent by the Engine to the requester with results and possible errors

func NewQueryResponse

func NewQueryResponse(v []reflect.Value, e error) *QueryResponse

NewQueryResponse creates an initialized and fully specified QueryResponse

func (*QueryResponse) Error

func (q *QueryResponse) Error() error

Error returns the error value of the QueryResponse

func (*QueryResponse) Value

func (q *QueryResponse) Value() []reflect.Value

Value returns an array of []reflect.Value's that may have resulted from the query

type ServiceInstance

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

A ServiceInstance describes a service that will be built-in to the binary and exec'ed by forking note: state information is stored in the node proto object, this object manages a running context

func NewServiceInstance

func NewServiceInstance(id, module string, entry func()) *ServiceInstance

NewServiceInstance provides a new, initialized ServiceInstance object

func (*ServiceInstance) GetState

func (si *ServiceInstance) GetState() types.ServiceState

GetState returns the current run state of the service

func (*ServiceInstance) ID

func (si *ServiceInstance) ID() string

ID gets the ID string for the service

func (*ServiceInstance) Module

func (si *ServiceInstance) Module() string

Module returns the name of the module this is an instance of

func (*ServiceInstance) SetCtl

func (si *ServiceInstance) SetCtl(ctl chan<- types.ServiceControl)

SetCtl sets the channel to send control message to (to pass through the API)

func (*ServiceInstance) SetSock

func (si *ServiceInstance) SetSock(sock string)

SetSock sets the path to the API socket

func (*ServiceInstance) Start

func (si *ServiceInstance) Start()

Start will execute the process

func (*ServiceInstance) Stop

func (si *ServiceInstance) Stop()

Stop sends a signal to the running si to stop

func (*ServiceInstance) UpdateConfig

func (si *ServiceInstance) UpdateConfig()

UpdateConfig will send a signal to the running si to check for a config update

func (*ServiceInstance) Watch

func (si *ServiceInstance) Watch(wchan chan<- types.ServiceInstanceUpdate)

Watch provides a channel where process state changes will be reported

type ServiceLogger

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

A ServiceLogger is a channel interface for aggregating logs from services running as separate goroutines

func (*ServiceLogger) GetLoggerLevel

func (l *ServiceLogger) GetLoggerLevel() types.LoggerLevel

func (*ServiceLogger) GetModule

func (l *ServiceLogger) GetModule() string

func (*ServiceLogger) IsEnabledFor

func (l *ServiceLogger) IsEnabledFor(lv types.LoggerLevel) (r bool)

func (*ServiceLogger) Log

func (l *ServiceLogger) Log(lv types.LoggerLevel, m string)

func (*ServiceLogger) Logf

func (l *ServiceLogger) Logf(lv types.LoggerLevel, f string, v ...interface{})

func (*ServiceLogger) RegisterChannel

func (l *ServiceLogger) RegisterChannel(c chan<- LoggerEvent)

RegisterChannel sets the chan that the ServiceLogger will send events over

func (*ServiceLogger) SetLoggerLevel

func (l *ServiceLogger) SetLoggerLevel(lv types.LoggerLevel)

func (*ServiceLogger) SetModule

func (l *ServiceLogger) SetModule(m string)

type ServiceManager

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

func NewServiceManager

func NewServiceManager(ctx Context, sock string) *ServiceManager

func (*ServiceManager) AddService

func (sm *ServiceManager) AddService(si types.ServiceInstance)

func (*ServiceManager) DelService

func (sm *ServiceManager) DelService(si string)

func (*ServiceManager) GetService

func (sm *ServiceManager) GetService(si string) types.ServiceInstance

func (*ServiceManager) Run

func (sm *ServiceManager) Run(ready chan<- interface{})

type State

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

A State stores and manipulates a collection of Nodes

func NewState

func NewState() *State

NewState creates an initialized state

func (*State) BulkCreate

func (s *State) BulkCreate(ns []types.Node) (r []types.Node, e error)

BulkCreate creates multiple nodes

func (*State) BulkDelete

func (s *State) BulkDelete(ns []types.Node) (r []types.Node, e error)

BulkDelete removes multiple nodes

func (*State) BulkDeleteByID

func (s *State) BulkDeleteByID(nids []types.NodeID) (r []types.Node, e error)

BulkDeleteByID removes multiple nodes keyed by NodeID

func (*State) BulkRead

func (s *State) BulkRead(nids []types.NodeID) (r []types.Node, e error)

BulkRead reads multiple nodes

func (*State) BulkUpdate

func (s *State) BulkUpdate(ns []types.Node) (r []types.Node, e error)

BulkUpdate updates multiple nodes

func (*State) Create

func (s *State) Create(n types.Node) (r types.Node, e error)

Create creates a node in the state

func (*State) Delete

func (s *State) Delete(n types.Node) (r types.Node, e error)

Delete removes a node from the state

func (*State) DeleteAll

func (s *State) DeleteAll() (r []types.Node, e error)

DeleteAll will remove all nodes from the state

func (*State) DeleteByID

func (s *State) DeleteByID(nid types.NodeID) (r types.Node, e error)

DeleteByID deletes a node from the state keyed by NodeID

func (*State) GetValue

func (s *State) GetValue(url string) (r reflect.Value, e error)

GetValue will query a property with URL, where node is mapped by ID

func (*State) Read

func (s *State) Read(nid types.NodeID) (r types.Node, e error)

Read returns a node from the state

func (*State) ReadAll

func (s *State) ReadAll() (r []types.Node, e error)

ReadAll returns a slice of all nodes from the state

func (*State) SetValue

func (s *State) SetValue(url string, v reflect.Value) (r reflect.Value, e error)

SetValue will set a property with URL, where node is mapped by ID

func (*State) Update

func (s *State) Update(n types.Node) (r types.Node, e error)

Update updates a node in the state

type StateChangeEvent

type StateChangeEvent struct {
	Type  pb.StateChangeControl_Type
	URL   string
	Value reflect.Value
}

A StateChangeEvent is emitted when the StateDifferenceEngine detects a change to either Dsc or Cfg

func (*StateChangeEvent) String

func (sce *StateChangeEvent) String() string

type StateDifferenceEngine

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

An StateDifferenceEngine maintains two kinds of state: - "Discoverable" (Dsc) is the discovered state of the system - "Configuration" (Cfg) is the intended state of the system An StateDifferenceEngine provides a simple Query langage for accessing/updating state. An StateDifferenceEngine emits Events on state change

func NewStateDifferenceEngine

func NewStateDifferenceEngine(ctx Context, qc chan types.Query) *StateDifferenceEngine

NewStateDifferenceEngine initializes a new StateDifferenceEngine object given a Context

func (*StateDifferenceEngine) BulkCreate

func (n *StateDifferenceEngine) BulkCreate(ms []types.Node) (r []types.Node, e error)

BulkCreate creates multiple nodes

func (*StateDifferenceEngine) BulkDelete

func (n *StateDifferenceEngine) BulkDelete(ms []types.Node) (r []types.Node, e error)

BulkDelete deletes multiple nodes

func (*StateDifferenceEngine) BulkDeleteByID

func (n *StateDifferenceEngine) BulkDeleteByID(nids []types.NodeID) (r []types.Node, e error)

BulkDeleteByID deletes multiple nodes, keyed by their NodeID

func (*StateDifferenceEngine) BulkRead

func (n *StateDifferenceEngine) BulkRead(nids []types.NodeID) (r []types.Node, e error)

BulkRead reads multiple nodes from Cfg

func (*StateDifferenceEngine) BulkReadDsc

func (n *StateDifferenceEngine) BulkReadDsc(nids []types.NodeID) (r []types.Node, e error)

BulkReadDsc reads multiple nodes from Dsc

func (*StateDifferenceEngine) BulkUpdate

func (n *StateDifferenceEngine) BulkUpdate(ms []types.Node) (r []types.Node, e error)

BulkUpdate updates multiple nodes in Cfg

func (*StateDifferenceEngine) BulkUpdateDsc

func (n *StateDifferenceEngine) BulkUpdateDsc(ms []types.Node) (r []types.Node, e error)

BulkUpdateDsc updates multiple nodes in Dsc

func (*StateDifferenceEngine) Create

func (n *StateDifferenceEngine) Create(m types.Node) (r types.Node, e error)

Create a node in the state engine

func (*StateDifferenceEngine) Delete

func (n *StateDifferenceEngine) Delete(m types.Node) (r types.Node, e error)

Delete deletes a node

func (*StateDifferenceEngine) DeleteAll

func (n *StateDifferenceEngine) DeleteAll() (r []types.Node, e error)

DeleteAll deletes all nodes in the engine, careful!

func (*StateDifferenceEngine) DeleteByID

func (n *StateDifferenceEngine) DeleteByID(nid types.NodeID) (r types.Node, e error)

DeleteByID deletes a node by its NodeID

func (*StateDifferenceEngine) Emit

func (n *StateDifferenceEngine) Emit(v []types.Event)

func (*StateDifferenceEngine) EmitOne

func (n *StateDifferenceEngine) EmitOne(v types.Event)

func (*StateDifferenceEngine) EventType

func (n *StateDifferenceEngine) EventType() types.EventType

func (*StateDifferenceEngine) GetLoggerLevel

func (n *StateDifferenceEngine) GetLoggerLevel() types.LoggerLevel

func (*StateDifferenceEngine) GetModule

func (n *StateDifferenceEngine) GetModule() string

func (*StateDifferenceEngine) GetValue

func (n *StateDifferenceEngine) GetValue(url string) (r reflect.Value, e error)

GetValue gets a specific sub-value from Cfg

func (*StateDifferenceEngine) GetValueDsc

func (n *StateDifferenceEngine) GetValueDsc(url string) (r reflect.Value, e error)

GetValueDsc gets a specific sub-value from Dsc

func (*StateDifferenceEngine) IsEnabledFor

func (n *StateDifferenceEngine) IsEnabledFor(level types.LoggerLevel) bool

func (*StateDifferenceEngine) Log

func (n *StateDifferenceEngine) Log(level types.LoggerLevel, m string)

func (*StateDifferenceEngine) Logf

func (n *StateDifferenceEngine) Logf(level types.LoggerLevel, fmt string, v ...interface{})

func (*StateDifferenceEngine) QueryChan

func (n *StateDifferenceEngine) QueryChan() chan<- types.Query

QueryChan returns a chanel that Queries can be sent on

func (*StateDifferenceEngine) Read

func (n *StateDifferenceEngine) Read(nid types.NodeID) (r types.Node, e error)

Read reads a node from Cfg

func (*StateDifferenceEngine) ReadAll

func (n *StateDifferenceEngine) ReadAll() (r []types.Node, e error)

ReadAll returns a slice of all nodes in Cfg

func (*StateDifferenceEngine) ReadAllDsc

func (n *StateDifferenceEngine) ReadAllDsc() (r []types.Node, e error)

ReadAllDsc returns a slice of all nodes in Dsc

func (*StateDifferenceEngine) ReadDsc

func (n *StateDifferenceEngine) ReadDsc(nid types.NodeID) (r types.Node, e error)

ReadDsc reads a node from Dsc

func (*StateDifferenceEngine) Run

func (n *StateDifferenceEngine) Run(ready chan<- interface{})

Run is a goroutine that manages queries

func (*StateDifferenceEngine) SetLoggerLevel

func (n *StateDifferenceEngine) SetLoggerLevel(level types.LoggerLevel)

func (*StateDifferenceEngine) SetModule

func (n *StateDifferenceEngine) SetModule(name string)

func (*StateDifferenceEngine) SetValue

func (n *StateDifferenceEngine) SetValue(url string, v reflect.Value) (r reflect.Value, e error)

SetValue sets a specific sub-value in Cfg

func (*StateDifferenceEngine) SetValueDsc

func (n *StateDifferenceEngine) SetValueDsc(url string, v reflect.Value) (r reflect.Value, e error)

SetValueDsc sets a specific sub-value in Dsc

func (*StateDifferenceEngine) Subscribe

func (n *StateDifferenceEngine) Subscribe(id string, c chan<- []types.Event) error

func (*StateDifferenceEngine) Unsubscribe

func (n *StateDifferenceEngine) Unsubscribe(id string) error

func (*StateDifferenceEngine) Update

func (n *StateDifferenceEngine) Update(m types.Node) (r types.Node, e error)

Update updates a node in Cfg

func (*StateDifferenceEngine) UpdateDsc

func (n *StateDifferenceEngine) UpdateDsc(m types.Node) (r types.Node, e error)

UpdateDsc updates a node in Dsc

type StateMutation

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

A StateMutation describes a possible mutation of state These are declared by modules These are used to construct the state evolution graph

func NewStateMutation

func NewStateMutation(mut map[string][2]reflect.Value, req map[string]reflect.Value, exc map[string]reflect.Value, context types.StateMutationContext, timeout time.Duration, failto [3]string) *StateMutation

NewStateMutation creates an initialized, specified StateMutation object

func (*StateMutation) After

func (s *StateMutation) After() types.StateSpec

After returns a StatSpec representing the state of of a matching Node after the mutation

func (*StateMutation) Before

func (s *StateMutation) Before() types.StateSpec

Before returns a StatSpec representing the state of of a matching Node before the mutation

func (*StateMutation) Context

Context specifies in which context (Self/Child/All) this mutation applies to Note: this doesn't affect the graph; just who does the work.

func (*StateMutation) Excludes

func (s *StateMutation) Excludes() map[string]reflect.Value

Excludes returns the map of URLs/values that are mutally exclusive with this mutation

func (*StateMutation) FailTo

func (s *StateMutation) FailTo() [3]string

func (*StateMutation) Mutates

func (s *StateMutation) Mutates() map[string][2]reflect.Value

Mutates returns the map of URLs/values (before & after) that mutate in this mutation

func (*StateMutation) Requires

func (s *StateMutation) Requires() map[string]reflect.Value

Requires returns the map of URLs/values that are required for this mutation

func (*StateMutation) SetTimeout

func (s *StateMutation) SetTimeout(t time.Duration)

func (*StateMutation) SpecCompatIn

func (s *StateMutation) SpecCompatIn(sp types.StateSpec, muts map[string]uint32) bool

SpecCompatIn decides if this mutation can form an in arrow in the graph This is used for graph building.

func (*StateMutation) SpecCompatOut

func (s *StateMutation) SpecCompatOut(sp types.StateSpec, muts map[string]uint32) bool

SpecCompatOut decides if this mutaiton can form an out arrow in the graph This is used for graph building.

func (*StateMutation) Timeout

func (s *StateMutation) Timeout() time.Duration

type StateMutationEngine

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

A StateMutationEngine listens for state change events and manages mutations to evolve Dsc state into Cfg state

func NewStateMutationEngine

func NewStateMutationEngine(ctx Context, qc chan types.Query) *StateMutationEngine

NewStateMutationEngine creates an initialized StateMutationEngine

func (*StateMutationEngine) DumpGraph

func (sme *StateMutationEngine) DumpGraph()

DumpGraph FIXME: REMOVE -- for debugging LOCKS: graphMutex (R)

func (*StateMutationEngine) DumpJSONGraph

func (sme *StateMutationEngine) DumpJSONGraph(nodes []*mutationNode, edges []*mutationEdge)

DumpJSONGraph for debugging the graph !!!IMPORTANT!!! DumpJSONGraph assumes you already hold a lock

func (*StateMutationEngine) Emit

func (sme *StateMutationEngine) Emit(v []types.Event)

func (*StateMutationEngine) EmitOne

func (sme *StateMutationEngine) EmitOne(v types.Event)

func (*StateMutationEngine) EventType

func (sme *StateMutationEngine) EventType() types.EventType

func (*StateMutationEngine) Freeze

func (sme *StateMutationEngine) Freeze()

func (*StateMutationEngine) Frozen

func (sme *StateMutationEngine) Frozen() bool

func (*StateMutationEngine) GetLoggerLevel

func (sme *StateMutationEngine) GetLoggerLevel() types.LoggerLevel

func (*StateMutationEngine) GetModule

func (sme *StateMutationEngine) GetModule() string

func (*StateMutationEngine) IsEnabledFor

func (sme *StateMutationEngine) IsEnabledFor(level types.LoggerLevel) bool

func (*StateMutationEngine) Log

func (sme *StateMutationEngine) Log(level types.LoggerLevel, m string)

func (*StateMutationEngine) Logf

func (sme *StateMutationEngine) Logf(level types.LoggerLevel, fmt string, v ...interface{})

func (*StateMutationEngine) NodeMatch

func (sme *StateMutationEngine) NodeMatch(node types.Node) (i int)

NodeMatch determines how many compatable StateSpecs this node has in the graph

func (*StateMutationEngine) PathExists

func (sme *StateMutationEngine) PathExists(start types.Node, end types.Node) (r bool, e error)

PathExists returns a boolean indicating whether or not a path exists in the graph between two nodes. If the path doesn't exist, it also returns the error. LOCKS: graphMutex (R) via findPath

func (*StateMutationEngine) QueryChan

func (sme *StateMutationEngine) QueryChan() chan<- types.Query

QueryChan returns a chanel that Queries can be sent on

func (*StateMutationEngine) RegisterMutation

func (sme *StateMutationEngine) RegisterMutation(si, id string, mut types.StateMutation) (e error)

RegisterMutation injects new mutaitons into the SME. muts[i] should match callback[i] We take a list so that we only call onUpdate once LOCKS: graphMutex (RW)

func (*StateMutationEngine) Run

func (sme *StateMutationEngine) Run(ready chan<- interface{})

Run is a goroutine that listens for state changes and performs StateMutation magic LOCKS: all

func (*StateMutationEngine) SetLoggerLevel

func (sme *StateMutationEngine) SetLoggerLevel(level types.LoggerLevel)

func (*StateMutationEngine) SetModule

func (sme *StateMutationEngine) SetModule(name string)

func (*StateMutationEngine) Subscribe

func (sme *StateMutationEngine) Subscribe(id string, c chan<- []types.Event) error

func (*StateMutationEngine) Thaw

func (sme *StateMutationEngine) Thaw()

func (*StateMutationEngine) Unsubscribe

func (sme *StateMutationEngine) Unsubscribe(id string) error

type StateSpec

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

A StateSpec is essentially a filter that determines if a given state falls within the spec or not. It currently systems of required and excluded values for specific URLs.

func NewStateSpec

func NewStateSpec(req map[string]reflect.Value, exc map[string]reflect.Value) *StateSpec

NewStateSpec creates a new initialized and fully specified StateSpec

func (*StateSpec) Equal

func (s *StateSpec) Equal(b types.StateSpec) bool

Equal tests if two specs are identical. Note: DeepEqual doesn't work because it doesn't turn vals into interfaces.

func (*StateSpec) Excludes

func (s *StateSpec) Excludes() map[string]reflect.Value

Excludes returns the map of URLs/values that this spec cannot have

func (*StateSpec) ExcsEqual

func (s *StateSpec) ExcsEqual(b types.StateSpec) bool

ExcsEqual tests if two specs have the same excludes

func (*StateSpec) LeastCommon

func (s *StateSpec) LeastCommon(b types.StateSpec)

LeastCommon keeps only the values that are also in the supplied spec

func (*StateSpec) NodeCompatWithMutators

func (s *StateSpec) NodeCompatWithMutators(n types.Node, muts map[string]uint32) (r bool)

NodeCompatWithMutators is how we find endpoints for mutation paths 1) For each mutator that is in the node, the spec must be equal 2) For each requires in the spec that is not a mutator, node must be equal 3) For each excludes in the spec that is not a mutator, node must not be equal

func (*StateSpec) NodeMatch

func (s *StateSpec) NodeMatch(n types.Node) (r bool)

NodeMatch determines of a Node matches a spec

func (*StateSpec) NodeMatchWithMutators

func (s *StateSpec) NodeMatchWithMutators(n types.Node, muts map[string]uint32) bool

NodeMatchWithMutators is like NodeMatch, but requires any mutators be present and match if they are non-zero in the node

func (*StateSpec) ReqsEqual

func (s *StateSpec) ReqsEqual(b types.StateSpec) bool

ReqsEqual tests if two specs have the same requirements

func (*StateSpec) Requires

func (s *StateSpec) Requires() map[string]reflect.Value

Requires returns the map of URLs/values that this spec must have

func (*StateSpec) SpecCompat

func (a *StateSpec) SpecCompat(b types.StateSpec) (r bool)

SpecCompat determines if two specs are compatible. Note: this doesn't mean that a Node that matches one will match

the other; it's just possible that they would.

func (*StateSpec) SpecMerge

func (s *StateSpec) SpecMerge(b types.StateSpec) (ns types.StateSpec, e error)

SpecMerge is the same as SpecMergeMust, but don't assume compat, and return an error if not

func (*StateSpec) SpecMergeMust

func (s *StateSpec) SpecMergeMust(b types.StateSpec) (ns types.StateSpec)

SpecMergeMust makes the most specified version of two compbined StateSpecs

func (*StateSpec) StripZeros

func (s *StateSpec) StripZeros()

StripZeros removes any reqs/excs that are equal to zero value

type StateSyncEngine

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

StateSyncEngine manages tree-style, eventual consistency state synchronization

func NewStateSyncEngine

func NewStateSyncEngine(ctx Context) *StateSyncEngine

NewStateSyncEngine creates a new initialized StateSyncEngine

func (*StateSyncEngine) Emit

func (sse *StateSyncEngine) Emit(v []types.Event)

func (*StateSyncEngine) EmitOne

func (sse *StateSyncEngine) EmitOne(v types.Event)

func (*StateSyncEngine) EventType

func (sse *StateSyncEngine) EventType() types.EventType

func (*StateSyncEngine) GetLoggerLevel

func (sse *StateSyncEngine) GetLoggerLevel() types.LoggerLevel

func (*StateSyncEngine) GetModule

func (sse *StateSyncEngine) GetModule() string

func (*StateSyncEngine) GetState

func (sse *StateSyncEngine) GetState() types.ServiceState

func (*StateSyncEngine) ID

func (sse *StateSyncEngine) ID() string

implement types.ServiceInstance this is a bit of a hack

func (*StateSyncEngine) IsEnabledFor

func (sse *StateSyncEngine) IsEnabledFor(level types.LoggerLevel) bool

func (*StateSyncEngine) Log

func (sse *StateSyncEngine) Log(level types.LoggerLevel, m string)

func (*StateSyncEngine) Logf

func (sse *StateSyncEngine) Logf(level types.LoggerLevel, fmt string, v ...interface{})

func (*StateSyncEngine) Module

func (sse *StateSyncEngine) Module() string

func (*StateSyncEngine) Name

func (*StateSyncEngine) Name() string

implement types.Module

func (*StateSyncEngine) RPCPhoneHome

func (sse *StateSyncEngine) RPCPhoneHome(ctx context.Context, in *pb.PhoneHomeRequest) (out *pb.PhoneHomeReply, e error)

RPCPhoneHome is a gRPC call. It establishes state sync properties with a child.

func (*StateSyncEngine) Run

func (sse *StateSyncEngine) Run(ready chan<- interface{})

Run is a goroutine that makes StateSyncEngine active

func (*StateSyncEngine) SetCtl

func (sse *StateSyncEngine) SetCtl(chan<- types.ServiceControl)

func (*StateSyncEngine) SetLoggerLevel

func (sse *StateSyncEngine) SetLoggerLevel(level types.LoggerLevel)

func (*StateSyncEngine) SetModule

func (sse *StateSyncEngine) SetModule(name string)

func (*StateSyncEngine) SetSock

func (sse *StateSyncEngine) SetSock(string)

func (*StateSyncEngine) Start

func (sse *StateSyncEngine) Start()

func (*StateSyncEngine) Stop

func (sse *StateSyncEngine) Stop()

func (*StateSyncEngine) Subscribe

func (sse *StateSyncEngine) Subscribe(id string, c chan<- []types.Event) error

func (*StateSyncEngine) Unsubscribe

func (sse *StateSyncEngine) Unsubscribe(id string) error

func (*StateSyncEngine) UpdateConfig

func (sse *StateSyncEngine) UpdateConfig()

func (*StateSyncEngine) Watch

func (sse *StateSyncEngine) Watch(chan<- types.ServiceInstanceUpdate)

type WriterLogger

type WriterLogger struct {
	DisablePrefix bool
	// contains filtered or unexported fields
}

A WriterLogger writes to any io.Writer interface, e.g. stdout, stderr, or an open file NOTE: Does not close the interface

func (*WriterLogger) GetLoggerLevel

func (l *WriterLogger) GetLoggerLevel() types.LoggerLevel

GetLoggerLevel gets the log filtering level

func (*WriterLogger) GetModule

func (l *WriterLogger) GetModule() string

GetModule gets the current module string

func (*WriterLogger) IsEnabledFor

func (l *WriterLogger) IsEnabledFor(lv types.LoggerLevel) (r bool)

IsEnabledFor determines if this Logger would send a message at a particular level

func (*WriterLogger) Log

func (l *WriterLogger) Log(lv types.LoggerLevel, m string)

Log submits a Log message with a LoggerLevel

func (*WriterLogger) Logf

func (l *WriterLogger) Logf(lv types.LoggerLevel, f string, v ...interface{})

Logf is the same as Log but with sprintf formatting

func (*WriterLogger) RegisterWriter

func (l *WriterLogger) RegisterWriter(w io.Writer)

RegisterWriter sets the writer interface this logger will use

func (*WriterLogger) SetLoggerLevel

func (l *WriterLogger) SetLoggerLevel(lv types.LoggerLevel)

SetLoggerLevel sets the log filtering level

func (*WriterLogger) SetModule

func (l *WriterLogger) SetModule(m string)

SetModule sets an identifier string for the component that will use this Logger

Directories

Path Synopsis
tests

Jump to

Keyboard shortcuts

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