原文:http://mesos.apache.org/documentation/latest/app-framework-development-guide/
---文档指导我们在mesos管理框架内添加应用
从MESOS_HOME/src/examples/
目录中去获取你选择语言的例子,它可以给你如何实现mesos框架调度和执行器一些提示。
创建自己的框架调度器(
Create your Framework Scheduler
)你能用C, C++, Java/Scala, or Python来实现一个调度器,你的调度器需要继承Scheduler
这个类(请查看下面的API)。调度器需要创建SchedulerDriver类(用于调度器和mesos master之间的交流)并且调度器后面调用SchedulerDriver.run()
。
MESOS_HOME/include/mesos/scheduler.hpp
文件内
/**
* Empty virtual destructor (necessary to instantiate subclasses).
*/
virtual ~Scheduler() {}
/**
* Invoked when the scheduler successfully registers with a Mesos
* master. A unique ID (generated by the master) used for
* distinguishing this framework from others and MasterInfo
* with the ip and port of the current master are provided as arguments.
*/
virtual void registered(SchedulerDriver* driver,
const FrameworkID& frameworkId,
const MasterInfo& masterInfo) = 0;
/**
* Invoked when the scheduler re-registers with a newly elected Mesos master.
* This is only called when the scheduler has previously been registered.
* MasterInfo containing the updated information about the elected master
* is provided as an argument.
*/
virtual void reregistered(SchedulerDriver* driver,
const MasterInfo& masterInfo) = 0;
/**
* Invoked when the scheduler becomes "disconnected" from the master
* (e.g., the master fails and another is taking over).
*/
virtual void disconnected(SchedulerDriver* driver) = 0;
/**
* Invoked when resources have been offered to this framework. A
* single offer will only contain resources from a single slave.
* Resources associated with an offer will not be re-offered to
* _this_ framework until either (a) this framework has rejected
* those resources (see SchedulerDriver::launchTasks) or (b) those
* resources have been rescinded (see Scheduler::offerRescinded).
* Note that resources may be concurrently offered to more than one
* framework at a time (depending on the allocator being used). In
* that case, the first framework to launch tasks using those
* resources will be able to use them while the other frameworks
* will have those resources rescinded (or if a framework has
* already launched tasks with those resources then those tasks will
* fail with a TASK_LOST status and a message saying as much).
*/
virtual void resourceOffers(SchedulerDriver* driver,
const std::vector& offers) = 0;
/**
* Invoked when an offer is no longer valid (e.g., the slave was
* lost or another framework used resources in the offer). If for
* whatever reason an offer is never rescinded (e.g., dropped
* message, failing over framework, etc.), a framwork that attempts
* to launch tasks using an invalid offer will receive TASK_LOST
* status updats for those tasks (see Scheduler::resourceOffers).
*/
virtual void offerRescinded(SchedulerDriver* driver,
const OfferID& offerId) = 0;
/**
* Invoked when the status of a task has changed (e.g., a slave is
* lost and so the task is lost, a task finishes and an executor
* sends a status update saying so, etc). Note that returning from
* this callback _acknowledges_ receipt of this status update! If
* for whatever reason the scheduler aborts during this callback (or
* the process exits) another status update will be delivered (note,
* however, that this is currently not true if the slave sending the
* status update is lost/fails during that time).
*/
virtual void statusUpdate(SchedulerDriver* driver,
const TaskStatus& status) = 0;
/**
* Invoked when an executor sends a message. These messages are best
* effort; do not expect a framework message to be retransmitted in
* any reliable fashion.
*/
virtual void frameworkMessage(SchedulerDriver* driver,
const ExecutorID& executorId,
const SlaveID& slaveId,
const std::string& data) = 0;
/**
* Invoked when a slave has been determined unreachable (e.g.,
* machine failure, network partition). Most frameworks will need to
* reschedule any tasks launched on this slave on a new slave.
*/
virtual void slaveLost(SchedulerDriver* driver,
const SlaveID& slaveId) = 0;
/**
* Invoked when an executor has exited/terminated. Note that any
* tasks running will have TASK_LOST status updates automagically
* generated.
*/
virtual void executorLost(SchedulerDriver* driver,
const ExecutorID& executorId,
const SlaveID& slaveId,
int status) = 0;
/**
* Invoked when there is an unrecoverable error in the scheduler or
* scheduler driver. The driver will be aborted BEFORE invoking this
* callback.
*/
virtual void error(SchedulerDriver* driver, const std::string& message) = 0;
声明定义在 MESOS_HOME/include/mesos/executor.hpp
/**
* Invoked once the executor driver has been able to successfully
* connect with Mesos. In particular, a scheduler can pass some
* data to it's executors through the FrameworkInfo.ExecutorInfo's
* data field.
*/
virtual void registered(ExecutorDriver* driver,
const ExecutorInfo& executorInfo,
const FrameworkInfo& frameworkInfo,
const SlaveInfo& slaveInfo) = 0;
/**
* Invoked when the executor re-registers with a restarted slave.
*/
virtual void reregistered(ExecutorDriver* driver,
const SlaveInfo& slaveInfo) = 0;
/**
* Invoked when the executor becomes "disconnected" from the slave
* (e.g., the slave is being restarted due to an upgrade).
*/
virtual void disconnected(ExecutorDriver* driver) = 0;
/**
* Invoked when a task has been launched on this executor (initiated
* via Scheduler::launchTasks). Note that this task can be realized
* with a thread, a process, or some simple computation, however, no
* other callbacks will be invoked on this executor until this
* callback has returned.
*/
virtual void launchTask(ExecutorDriver* driver,
const TaskInfo& task) = 0;
/**
* Invoked when a task running within this executor has been killed
* (via SchedulerDriver::killTask). Note that no status update will
* be sent on behalf of the executor, the executor is responsible
* for creating a new TaskStatus (i.e., with TASK_KILLED) and
* invoking ExecutorDriver::sendStatusUpdate.
*/
virtual void killTask(ExecutorDriver* driver, const TaskID& taskId) = 0;
/**
* Invoked when a framework message has arrived for this
* executor. These messages are best effort; do not expect a
* framework message to be retransmitted in any reliable fashion.
*/
virtual void frameworkMessage(ExecutorDriver* driver,
const std::string& data) = 0;
/**
* Invoked when the executor should terminate all of it's currently
* running tasks. Note that after a Mesos has determined that an
* executor has terminated any tasks that the executor did not send
* terminal status updates for (e.g., TASK_KILLED, TASK_FINISHED,
* TASK_FAILED, etc) a TASK_LOST status update will be created.
*/
virtual void shutdown(ExecutorDriver* driver) = 0;
/**
* Invoked when a fatal error has occurred with the executor and/or
* executor driver. The driver will be aborted BEFORE invoking this
* callback.
*/
virtual void error(ExecutorDriver* driver, const std::string& message) = 0;
MesosSchedulerDriver
的构建参数
ExecutorInfo
(src/examples/java/TestFramework.java就是这样的一个例子)。ExecutorInfo是一个Protocol Buffer Message类(在
include/mesos/mesos.proto
里面定义),我们也可以设置这样的HDFS://path/to/executor/这样的uri。如果你有特殊的执行器储存地方,也可以更改
frameworks_home
配置项(默认是
MESOS_HOME/frameworks
)为
你的mesos-slave
进程,然后设置
ExecutorInfo
在一个相关的路径下,而去从机器也会通过提高的相关路径预测frameworks_home的值。
一旦你的确定执行器可以在mesos-slaves运行,那你可以运用在mesos master注册的调度器,然后接受资源请求。