mesosgot

package module
v0.0.0-...-6a469a2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2015 License: Apache-2.0 Imports: 20 Imported by: 0

README

mesosgot: Simple Go Task Scheduler on Mesos (prototype)

  1. very thin layer over mesos-go api (and example scheduler/executor); with simple API (http://godoc.org/github.com/yglcode/mesosgot).

  2. for launching cluster of relatively long running tasks running in its own goroutine at slave machines.

  3. each task is a Go function with following signature which will automatically run in a goroutine:

     func(in <-chan TaskMsg, out chan<-TaskMsg, args []string, env map[string]string) error
    
    • App tasks will use channel "in" to receive messages from schedulers.
    • App tasks will send messages to scheduler via channel "out".
    • Channel "in" will be closed to tell tasks to exit (such as when killed by scheduler, or system shuts down).
  4. application scheduler is also a go function automatically running in a goroutine:

     func(schedin <-chan TaskMsg, schedout chan<-TaskMsg, schedevent <-chan SchedEvent)
    
    • App scheduler will use channel "schedin" to receive messages from tasks.
    • App scheduler will send messages to tasks via "schedout" channel.
    • App scheduler will receive scheduling events from "schedevent" channel.
  5. scheduler & tasks communicate thru Go channels(in,out) overlaying on top of native framework communication api.

  6. simple/static resource allocation:

    • only accept resource offers when resources required by all tasks are offered
    • whenever any task fail, whole system shuts down
  7. programming:

    • build two separate executables:

      • app_scheduler: app scheduling logic to run at cluster master.
      • app_executor: containing all app tasks functions, their registration and dispatching logic to run at cluster slave machines.
    • app_scheduler: create GoTaskScheduler and plug into MesosSchedulerDriver

      • call GoTaskScheduler.SpawnTask() to launch named app tasks in cluster.
      • call GoTaskScheduler.RegisterSchedFunc() to register scheduler function.
    • app_executor: create GoTaskExecutor and plug into MesosExecutorDriver

      • call GoTaskExecutor.RegisterTask() to register app tasks to a name.
      • call GoTaskExecutor.RegisterTaskFunc() to register app task function to a name.
  8. implement an elevator control system on top of it as example.

Documentation

Overview

mesosgot: Simple Go Task Scheduler on Mesos (prototype)

1. very thin layer over mesos-go api (and example scheduler/executor).

2. for launching cluster of relatively long running tasks running in its own goroutine at slave machines.

  1. each task is a Go function with following signature which will automatically run in a goroutine: func(in <-chan TaskMsg, out chan<-TaskMsg, args []string, env map[string]string) error App tasks will use channel "in" to receive messages from schedulers. App tasks will send messages to scheduler via channel "out". Channel "in" will be closed to tell task exit (such as when killed by scheduler, or system shuts down).
  1. application scheduler is also a go function automatically running in a goroutine: func(schedin <-chan TaskMsg, schedout chan<-TaskMsg, schedevent <-chan SchedEvent) App scheduler will use channel "schedin" to receive messages from tasks. App scheduler will send messages to tasks via "schedout" channel. App scheduler will receive scheduling events from "schedevent" channel.

5. scheduler & tasks communicate thru Go channels(in,out) overlaying on top of native framework communication api.

6. simple/static resource allocation:

  • only accept resource offers when resources required by all tasks are offered
  • whenever any task fail, whole system shuts down

7. programming:

  • build two separate executables:

  • app_scheduler: app scheduling logic to run at cluster master.

  • app_executor: containing all app tasks functions, their registration and dispatching logic to run at cluster slave machines.

  • app_scheduler: create GoTaskScheduler and plug into MesosSchedulerDriver

  • call GoTaskScheduler.SpawnTask() to launch named tasks in cluster

  • call GoTaskScheduler.RegisterSchedFunc() to register scheduler function.

  • app_executor: create GoTaskExecutor and plug into MesosExecutorDriver

  • call GoTaskExecutor.RegisterTask() to register app task to a name.

  • call GoTaskExecutor.RegisterTaskFunc() to register app task function to a name.

Licensed under Apache 2.0

Index

Constants

View Source
const (
	//Default buffer size of channels for communication between scheduler and tasks.
	DefTaskChanLen = 256
)

Variables

This section is empty.

Functions

func EncodeMsg

func EncodeMsg(m GoTaskMsg) (s string, e error)

Encode GoTaskMsg to a string to be passed thru Mesos native FrameworkMessage.

Types

type AppSchedulerFunc

type AppSchedulerFunc func(schedin <-chan GoTaskMsg, schedout chan<- GoTaskMsg, schedevent <-chan SchedEvent)

SchedulerFunc for scheduling logic to run at cluster master. App scheduler will use channel "schedin" to receive messages from tasks. App scheduler will send messages to tasks via "schedout" channel. App scheduler will receive scheduling events from "schedevent" channel.

func (AppSchedulerFunc) Run

func (asf AppSchedulerFunc) Run(schedin <-chan GoTaskMsg, schedout chan<- GoTaskMsg, schedevent <-chan SchedEvent)

type AppSchedulerTask

type AppSchedulerTask interface {
	//App scheduler will use channel "schedin" to receive messages from tasks.
	//App scheduler will send messages to tasks via "schedout" channel.
	//App scheduler will receive scheduling events from "schedevent" channel.
	Run(schedin <-chan GoTaskMsg, schedout chan<- GoTaskMsg, schedevent <-chan SchedEvent)
}

SchedulerTask for scheduling logic to run at cluster master.

type AppTask

type AppTask interface {
	Run(in <-chan GoTaskMsg, out chan<- GoTaskMsg, args []string) error
}

The type of tasks. App tasks will use channel "in" to receive messages from schedulers. App tasks will send messages to scheduler via channel "out". channel "in" will be closed to notify task to exit.

type AppTaskExecutor

type AppTaskExecutor interface {
	//Start/dispatch app tasks based on task name.
	//App tasks will use channel "in" to receive messages from schedulers.
	//App tasks will send messages to scheduler via channel "out".
	RunTask(taskName string, in <-chan GoTaskMsg, out chan<- GoTaskMsg) error
	//register a task to a task name
	RegisterTask(name string, task AppTask)
	//register a task function to a task name
	RegisterTaskFunc(name string, task AppTaskFunc)
}

Common interface of app task executor.

type AppTaskFunc

type AppTaskFunc func(in <-chan GoTaskMsg, out chan<- GoTaskMsg, args []string) error

The type of task functions. App tasks will use channel "in" to receive messages from schedulers. App tasks will send messages to scheduler via channel "out". channel "in" will be closed to notify task to exit.

func (AppTaskFunc) Run

func (atf AppTaskFunc) Run(in <-chan GoTaskMsg, out chan<- GoTaskMsg, args []string) error

type AppTaskResourceInfo

type AppTaskResourceInfo struct {
	Name      string
	Count     int
	Resources map[string]float64 //map keys = Mesos resource names: "cpus", "mem"...
	Args      []string
	Env       map[string]string
}

AppTaskResourceInfo will allow app scheduler specify the resource requirements of app tasks.

type AppTaskScheduler

type AppTaskScheduler interface {
	//-- internal interface to mesos --
	//return resource requirements of all tasks
	TasksResourceInfo() []*AppTaskResourceInfo
	//start running app scheduler in a separate goroutine.
	//App scheduler will use channel "schedin" to receive messages from tasks.
	//App scheduler will send messages to tasks via "schedout" channel.
	//App scheduler will receive scheduling events from "schedevent" channel.
	RunScheduler(schedin <-chan GoTaskMsg, schedout chan<- GoTaskMsg, schedevent <-chan SchedEvent)

	//-- external interface to user code --
	//add one app task resource info
	SpawnTask(name string, count int, res map[string]float64)
	//add a set of app tasks
	SpawnTasks(tasks []*AppTaskResourceInfo)
	//register scheduler task
	RegisterSchedTask(sched AppSchedulerTask)
	//register scheduler func
	RegisterSchedFunc(sched AppSchedulerFunc)
}

Common interface implmented by all app/framework scheduler

type DefAppTaskExecutor

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

Default app task executor, used if no external appTaskExecutor specified when creating GoTaskExecutor

func NewDefAppTaskExecutor

func NewDefAppTaskExecutor() *DefAppTaskExecutor

func (*DefAppTaskExecutor) RegisterTask

func (exec *DefAppTaskExecutor) RegisterTask(name string, task AppTask)

Register a task to a task name in default app task executor

func (*DefAppTaskExecutor) RegisterTaskFunc

func (exec *DefAppTaskExecutor) RegisterTaskFunc(name string, taskFunc AppTaskFunc)

Register a task func to a task name in default app task executor

func (*DefAppTaskExecutor) RunTask

func (ee *DefAppTaskExecutor) RunTask(taskName string, chanin <-chan GoTaskMsg, chanout chan<- GoTaskMsg) error

Dispatch task based on task name, already run in its own goroutine

type DefAppTaskScheduler

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

when no external AppTaskScheduler is provided when GoTaskScheduler is created, a default DefAppTaskScheduler is used

func NewDefAppTaskScheduler

func NewDefAppTaskScheduler() *DefAppTaskScheduler

create a default AppTaskScheduler

func (*DefAppTaskScheduler) RegisterSchedFunc

func (ats *DefAppTaskScheduler) RegisterSchedFunc(sched AppSchedulerFunc)

register a app scheduler func to run in a goroutine

func (*DefAppTaskScheduler) RegisterSchedTask

func (ats *DefAppTaskScheduler) RegisterSchedTask(sched AppSchedulerTask)

register a app scheduler task to run in a goroutine

func (*DefAppTaskScheduler) RunScheduler

func (ats *DefAppTaskScheduler) RunScheduler(schedin <-chan GoTaskMsg, schedout chan<- GoTaskMsg, schedevent <-chan SchedEvent)

run registered app scheduler task/func in a goroutine

func (*DefAppTaskScheduler) SpawnTask

func (ats *DefAppTaskScheduler) SpawnTask(name string, count int, res map[string]float64)

launch a app task in cluster

func (*DefAppTaskScheduler) SpawnTasks

func (ats *DefAppTaskScheduler) SpawnTasks(tasks []*AppTaskResourceInfo)

launch a set of app tasks in cluster

func (*DefAppTaskScheduler) TasksResourceInfo

func (ats *DefAppTaskScheduler) TasksResourceInfo() []*AppTaskResourceInfo

return resource requests by app tasks

type GoTaskExecutor

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

Responsible for starting app tasks and forwarding messages between scheduler and tasks.

func NewGoTaskExecutor

func NewGoTaskExecutor(ae AppTaskExecutor) (exec *GoTaskExecutor)

Create a Go Task Executor to be used with Mesos Executor Driver. Use an AppTaskExecutor to do app specific dispatching to tasks.

func (*GoTaskExecutor) Disconnected

func (exec *GoTaskExecutor) Disconnected(driver exec.ExecutorDriver)

when disconnected from slave, oure communication thru Framework message should be broken, tell tasks to exit

func (*GoTaskExecutor) DriverConfig

func (exc *GoTaskExecutor) DriverConfig() exec.DriverConfig

Return Mesos driver config for this GoTask executor.

func (*GoTaskExecutor) Error

func (exec *GoTaskExecutor) Error(driver exec.ExecutorDriver, err string)

Unrecoverable error, tell all tasks exit

func (*GoTaskExecutor) FrameworkMessage

func (exec *GoTaskExecutor) FrameworkMessage(driver exec.ExecutorDriver, rawMsg string)

Forward messages from scheduler to tasks.

func (*GoTaskExecutor) KillTask

func (exec *GoTaskExecutor) KillTask(driver exec.ExecutorDriver, taskId *mesos.TaskID)

Scheduler kills a task, close it input chan.

func (*GoTaskExecutor) LaunchTask

func (exec *GoTaskExecutor) LaunchTask(driver exec.ExecutorDriver, taskInfo *mesos.TaskInfo)

Launch app task in a separate goroutine.

func (*GoTaskExecutor) RegisterTask

func (exec *GoTaskExecutor) RegisterTask(name string, task AppTask)

Register a task to a task name in go task executor

func (*GoTaskExecutor) RegisterTaskFunc

func (exec *GoTaskExecutor) RegisterTaskFunc(name string, taskFunc AppTaskFunc)

Register a task func to a task name in go task executor

func (*GoTaskExecutor) Registered

func (exec *GoTaskExecutor) Registered(driver exec.ExecutorDriver, execInfo *mesos.ExecutorInfo, fwinfo *mesos.FrameworkInfo, slaveInfo *mesos.SlaveInfo)

Mesos framework method.

func (*GoTaskExecutor) Reregistered

func (exec *GoTaskExecutor) Reregistered(driver exec.ExecutorDriver, slaveInfo *mesos.SlaveInfo)

Mesos framework method.

func (*GoTaskExecutor) Shutdown

func (exec *GoTaskExecutor) Shutdown(exec.ExecutorDriver)

Scheduler shuts down, all tasks have to exit

type GoTaskMsg

type GoTaskMsg struct {
	TaskName    string
	MessageData string
}

TaskMsg and encoder/decoder. GoTask_framework only has scheduler<->tasks communications, so simple rule: msg.TaskName always points to task's name, no matter which direction it goes, so it can be either msg source or msg destination.

func DecodeMsg

func DecodeMsg(s string) (m GoTaskMsg, e error)

Decode a string (from Mesos native FrameworkMessage) to GoTaskMsg to be passed to tasks and scheduler.

type GoTaskSchedConfig

type GoTaskSchedConfig struct {
	//Binding address for artifact server
	Address string
	//Binding port for artifact server
	ArtifactPort int
	//Authentication provider
	AuthProvider string
	//Master address, default 127.0.0.1:5050
	Master string
	//Path to app framework executor
	ExecutorPath string
	//Mesos authentication principal
	MesosAuthPrincipal string
	//Mesos authentication secret file
	MesosAuthSecretFile string
	TaskRefuseSeconds   float64
}

GoTask scheduler/framework config parameters

func LoadSchedulerConfig

func LoadSchedulerConfig() (config *GoTaskSchedConfig)

Load scheduler config parameters from default settings and command line flags.

type GoTaskScheduler

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

GoTask scheduler, responsible for starting tasks at slaves, forwarding msgs between scheduler and tasks.

func NewGoTaskScheduler

func NewGoTaskScheduler(userName string, conf *GoTaskSchedConfig, aps AppTaskScheduler) (sched *GoTaskScheduler)

Create a new Go Task Scheduler to be used with Mesos Scheduler Driver. If an instance of AppTaskScheduler is provided, it is used for tasks resource requirement and app scheduling; otherwise a default app task scheduler is used.

func (*GoTaskScheduler) Disconnected

func (sched *GoTaskScheduler) Disconnected(driver sched.SchedulerDriver)

Mesos framework method.

func (*GoTaskScheduler) DriverConfig

func (schd *GoTaskScheduler) DriverConfig() (drvConfig sched.DriverConfig)

Return a Mesos scheduler driver for this scheduler.

func (*GoTaskScheduler) Error

func (sched *GoTaskScheduler) Error(driver sched.SchedulerDriver, err string)

Mesos framework method.

func (*GoTaskScheduler) ExecutorLost

Mesos framework method.

func (*GoTaskScheduler) FrameworkMessage

func (sched *GoTaskScheduler) FrameworkMessage(driver sched.SchedulerDriver, execid *mesos.ExecutorID, slaveid *mesos.SlaveID, rawMsg string)

Forward messages from tasks at slave nodes to scheduler.

func (*GoTaskScheduler) OfferRescinded

func (sched *GoTaskScheduler) OfferRescinded(sched.SchedulerDriver, *mesos.OfferID)

Mesos framework method.

func (*GoTaskScheduler) RegisterSchedFunc

func (sched *GoTaskScheduler) RegisterSchedFunc(schedF AppSchedulerFunc)

register a app scheduler func to run in a goroutine

func (*GoTaskScheduler) RegisterSchedTask

func (sched *GoTaskScheduler) RegisterSchedTask(schedT AppSchedulerTask)

register a app scheduler task to run in a goroutine

func (*GoTaskScheduler) Registered

func (sched *GoTaskScheduler) Registered(driver sched.SchedulerDriver, frameworkId *mesos.FrameworkID, masterInfo *mesos.MasterInfo)

Mesos framework method.

func (*GoTaskScheduler) Reregistered

func (sched *GoTaskScheduler) Reregistered(driver sched.SchedulerDriver, masterInfo *mesos.MasterInfo)

Mesos framework method.

func (*GoTaskScheduler) ResourceOffers

func (sched *GoTaskScheduler) ResourceOffers(driver sched.SchedulerDriver, offers []*mesos.Offer)

Mesos framework method. Check resources available and start tasks at slave nodes.

func (*GoTaskScheduler) SlaveLost

func (sched *GoTaskScheduler) SlaveLost(driver sched.SchedulerDriver, slaveId *mesos.SlaveID)

Mesos framework method.

func (*GoTaskScheduler) SpawnTask

func (sched *GoTaskScheduler) SpawnTask(name string, count int, res map[string]float64)

launch a app task in cluster

func (*GoTaskScheduler) SpawnTasks

func (sched *GoTaskScheduler) SpawnTasks(tasks []*AppTaskResourceInfo)

launch a set of app tasks in cluster

func (*GoTaskScheduler) StatusUpdate

func (sched *GoTaskScheduler) StatusUpdate(driver sched.SchedulerDriver, status *mesos.TaskStatus)

Mesos framework method.

type SchedEvent

type SchedEvent struct {
	EventType SchedEventType
	EventData interface{} //the type of event data depend on event type
}

Scheduler events (such as task failure, disconnect, etc.) to be forwarded to App scheduler, and limited set of events to tasks (such as disconn, shutdown)

type SchedEventType

type SchedEventType int

Scheduler events types

const (
	Registered SchedEventType = iota
	Reregistered
	Disconnected
	TaskLaunched
	TaskRunning
	TaskFinished
	TaskFailed
	TaskKilled
	TaskLost
	OfferRescinded
	SlaveLost
	ExecutorLost
	Shutdown
	Error
	NumSchedEventTypes
)

func (SchedEventType) String

func (et SchedEventType) String() string

Directories

Path Synopsis
Elevator scheduling system emulation: two design considerations: 1.
Elevator scheduling system emulation: two design considerations: 1.

Jump to

Keyboard shortcuts

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