engine, lang: core: world: Split out the scheduler interface
This commit is contained in:
@@ -44,8 +44,6 @@ type World interface { // TODO: is there a better name for this interface?
|
|||||||
|
|
||||||
ResWorld
|
ResWorld
|
||||||
|
|
||||||
Scheduler(namespace string, opts ...scheduler.Option) (*scheduler.Result, error)
|
|
||||||
|
|
||||||
// URI returns the current FS URI.
|
// URI returns the current FS URI.
|
||||||
// TODO: Can we improve this API or deprecate it entirely?
|
// TODO: Can we improve this API or deprecate it entirely?
|
||||||
URI() string
|
URI() string
|
||||||
@@ -84,6 +82,13 @@ type ResWorld interface {
|
|||||||
ResCollect(ctx context.Context, hostnameFilter, kindFilter []string) ([]Res, error)
|
ResCollect(ctx context.Context, hostnameFilter, kindFilter []string) ([]Res, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SchedulerWorld is an interface that has to do with distributed scheduling.
|
||||||
|
// XXX: This should be abstracted to remove the etcd specific types if possible.
|
||||||
|
type SchedulerWorld interface {
|
||||||
|
// Scheduler runs a distributed scheduler.
|
||||||
|
Scheduler(namespace string, opts ...scheduler.Option) (*scheduler.Result, error)
|
||||||
|
}
|
||||||
|
|
||||||
// EtcdWorld is a world interface that should be implemented if the world
|
// EtcdWorld is a world interface that should be implemented if the world
|
||||||
// backend is implementing etcd, and if it supports dynamically resizing things.
|
// backend is implementing etcd, and if it supports dynamically resizing things.
|
||||||
// TODO: In theory we could generalize this to support other backends, but lets
|
// TODO: In theory we could generalize this to support other backends, but lets
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/purpleidea/mgmt/etcd/scheduler" // TODO: is it okay to import this without abstraction?
|
"github.com/purpleidea/mgmt/engine"
|
||||||
|
"github.com/purpleidea/mgmt/etcd/scheduler" // XXX: abstract this if possible
|
||||||
"github.com/purpleidea/mgmt/lang/funcs"
|
"github.com/purpleidea/mgmt/lang/funcs"
|
||||||
"github.com/purpleidea/mgmt/lang/interfaces"
|
"github.com/purpleidea/mgmt/lang/interfaces"
|
||||||
"github.com/purpleidea/mgmt/lang/types"
|
"github.com/purpleidea/mgmt/lang/types"
|
||||||
@@ -90,6 +91,8 @@ type ScheduleFunc struct {
|
|||||||
|
|
||||||
args []types.Value
|
args []types.Value
|
||||||
|
|
||||||
|
world engine.SchedulerWorld
|
||||||
|
|
||||||
namespace string
|
namespace string
|
||||||
scheduler *scheduler.Result
|
scheduler *scheduler.Result
|
||||||
|
|
||||||
@@ -278,6 +281,13 @@ func (obj *ScheduleFunc) Info() *interfaces.Info {
|
|||||||
// Init runs some startup code for this function.
|
// Init runs some startup code for this function.
|
||||||
func (obj *ScheduleFunc) Init(init *interfaces.Init) error {
|
func (obj *ScheduleFunc) Init(init *interfaces.Init) error {
|
||||||
obj.init = init
|
obj.init = init
|
||||||
|
|
||||||
|
world, ok := obj.init.World.(engine.SchedulerWorld)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("world backend does not support the SchedulerWorld interface")
|
||||||
|
}
|
||||||
|
obj.world = world
|
||||||
|
|
||||||
obj.watchChan = make(chan *schedulerResult)
|
obj.watchChan = make(chan *schedulerResult)
|
||||||
//obj.init.Debug = true // use this for local debugging
|
//obj.init.Debug = true // use this for local debugging
|
||||||
return nil
|
return nil
|
||||||
@@ -378,7 +388,7 @@ func (obj *ScheduleFunc) Stream(ctx context.Context) error {
|
|||||||
obj.init.Logf("starting scheduler...")
|
obj.init.Logf("starting scheduler...")
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
obj.scheduler, err = obj.init.World.Scheduler(obj.namespace, schedulerOpts...)
|
obj.scheduler, err = obj.world.Scheduler(obj.namespace, schedulerOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errwrap.Wrapf(err, "can't create scheduler")
|
return errwrap.Wrapf(err, "can't create scheduler")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user