123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- package api
- import (
- "context"
- )
- type SourceTuple interface {
- Message() map[string]interface{}
- Meta() map[string]interface{}
- }
- type DefaultSourceTuple struct {
- message map[string]interface{}
- meta map[string]interface{}
- }
- func NewDefaultSourceTuple(message map[string]interface{}, meta map[string]interface{}) *DefaultSourceTuple {
- return &DefaultSourceTuple{
- message: message,
- meta: meta,
- }
- }
- func (t *DefaultSourceTuple) Message() map[string]interface{} {
- return t.message
- }
- func (t *DefaultSourceTuple) Meta() map[string]interface{} {
- return t.meta
- }
- type Logger interface {
- Debug(args ...interface{})
- Info(args ...interface{})
- Warn(args ...interface{})
- Error(args ...interface{})
- Debugln(args ...interface{})
- Infoln(args ...interface{})
- Warnln(args ...interface{})
- Errorln(args ...interface{})
- Debugf(format string, args ...interface{})
- Infof(format string, args ...interface{})
- Warnf(format string, args ...interface{})
- Errorf(format string, args ...interface{})
- }
- type Closable interface {
- Close(ctx StreamContext) error
- }
- type Source interface {
- //Should be sync function for normal case. The container will run it in go func
- Open(ctx StreamContext, consumer chan<- SourceTuple, errCh chan<- error)
- //Called during initialization. Configure the source with the data source(e.g. topic for mqtt) and the properties
- //read from the yaml
- Configure(datasource string, props map[string]interface{}) error
- Closable
- }
- type Sink interface {
- //Should be sync function for normal case. The container will run it in go func
- Open(ctx StreamContext) error
- //Called during initialization. Configure the sink with the properties from rule action definition
- Configure(props map[string]interface{}) error
- //Called when each row of data has transferred to this sink
- Collect(ctx StreamContext, data interface{}) error
- Closable
- }
- type Emitter interface {
- AddOutput(chan<- interface{}, string) error
- }
- type Collector interface {
- GetInput() (chan<- interface{}, string)
- }
- type TopNode interface {
- GetName() string
- }
- type Rule struct {
- Id string `json:"id"`
- Sql string `json:"sql"`
- Actions []map[string]interface{} `json:"actions"`
- Options map[string]interface{} `json:"options"`
- }
- type StreamContext interface {
- context.Context
- GetLogger() Logger
- GetRuleId() string
- GetOpId() string
- GetInstanceId() int
- WithMeta(ruleId string, opId string) StreamContext
- WithInstance(instanceId int) StreamContext
- WithCancel() (StreamContext, context.CancelFunc)
- SetError(e error)
- //State handling
- IncrCounter(key string, amount int) error
- GetCounter(key string) (int, error)
- PutState(key string, value interface{}) error
- GetState(key string) (interface{}, error)
- DeleteState(key string) error
- }
- type Operator interface {
- Emitter
- Collector
- Exec(StreamContext, chan<- error)
- GetName() string
- GetMetrics() [][]interface{}
- }
- type FunctionContext interface {
- StreamContext
- GetFuncId() int
- }
- type Function interface {
- //The argument is a list of xsql.Expr
- Validate(args []interface{}) error
- //Execute the function, return the result and if execution is successful.
- //If execution fails, return the error and false.
- Exec(args []interface{}, ctx FunctionContext) (interface{}, bool)
- //If this function is an aggregate function. Each parameter of an aggregate function will be a slice
- IsAggregate() bool
- }
|