org.apache.mesos
Class MesosSchedulerDriver

java.lang.Object
  extended by org.apache.mesos.MesosSchedulerDriver
All Implemented Interfaces:
SchedulerDriver

public class MesosSchedulerDriver
extends Object
implements SchedulerDriver

Concrete implementation of a SchedulerDriver that connects a Scheduler with a Mesos master. The MesosSchedulerDriver is thread-safe. Note that scheduler failover is supported in Mesos. After a scheduler is registered with Mesos it may failover (to a new process on the same machine or across multiple machines) by creating a new driver with the ID given to it in Scheduler.registered(org.apache.mesos.SchedulerDriver, org.apache.mesos.Protos.FrameworkID, org.apache.mesos.Protos.MasterInfo). The driver is responsible for invoking the Scheduler callbacks as it communicates with the Mesos master. Note that blocking on the MesosSchedulerDriver (e.g., via join()) doesn't affect the scheduler callbacks in anyway because they are handled by a different thread. See src/examples/java/TestFramework.java for an example of using the MesosSchedulerDriver.


Constructor Summary
MesosSchedulerDriver(Scheduler scheduler, org.apache.mesos.Protos.FrameworkInfo framework, String master)
          Creates a new driver for the specified scheduler.
MesosSchedulerDriver(Scheduler scheduler, org.apache.mesos.Protos.FrameworkInfo framework, String master, org.apache.mesos.Protos.Credential credential)
          Same as the above constructor, except that it accepts 'credential' as a parameter.
 
Method Summary
 org.apache.mesos.Protos.Status abort()
          Aborts the driver so that no more callbacks can be made to the scheduler.
 org.apache.mesos.Protos.Status declineOffer(org.apache.mesos.Protos.OfferID offerId)
          Declines an offer in its entirety.
 org.apache.mesos.Protos.Status declineOffer(org.apache.mesos.Protos.OfferID offerId, org.apache.mesos.Protos.Filters filters)
          Declines an offer in its entirety and applies the specified filters on the resources (see mesos.proto for a description of Filters).
protected  void finalize()
           
protected  void initialize()
           
 org.apache.mesos.Protos.Status join()
          Waits for the driver to be stopped or aborted, possibly _blocking_ the current thread indefinitely.
 org.apache.mesos.Protos.Status killTask(org.apache.mesos.Protos.TaskID taskId)
          Kills the specified task.
 org.apache.mesos.Protos.Status launchTasks(Collection<org.apache.mesos.Protos.OfferID> offerIds, Collection<org.apache.mesos.Protos.TaskInfo> tasks)
          Launches the given set of tasks.
 org.apache.mesos.Protos.Status launchTasks(Collection<org.apache.mesos.Protos.OfferID> offerIds, Collection<org.apache.mesos.Protos.TaskInfo> tasks, org.apache.mesos.Protos.Filters filters)
          Launches the given set of tasks on a set of offers.
 org.apache.mesos.Protos.Status launchTasks(org.apache.mesos.Protos.OfferID offerId, Collection<org.apache.mesos.Protos.TaskInfo> tasks)
          Deprecated. Replaced by launchTasks using offer list.
 org.apache.mesos.Protos.Status launchTasks(org.apache.mesos.Protos.OfferID offerId, Collection<org.apache.mesos.Protos.TaskInfo> tasks, org.apache.mesos.Protos.Filters filters)
          Deprecated. Replaced by launchTasks using offer list.
 org.apache.mesos.Protos.Status reconcileTasks(Collection<org.apache.mesos.Protos.TaskStatus> statuses)
          Reconciliation of tasks causes the master to send status updates for tasks whose status differs from the status sent here.
 org.apache.mesos.Protos.Status requestResources(Collection<org.apache.mesos.Protos.Request> requests)
          Requests resources from Mesos (see mesos.proto for a description of Request and how, for example, to request resources from specific slaves).
 org.apache.mesos.Protos.Status reviveOffers()
          Removes all filters, previously set by the framework (via SchedulerDriver.launchTasks(java.util.Collection, java.util.Collection, org.apache.mesos.Protos.Filters)).
 org.apache.mesos.Protos.Status run()
          Starts and immediately joins (i.e., blocks on) the driver.
 org.apache.mesos.Protos.Status sendFrameworkMessage(org.apache.mesos.Protos.ExecutorID executorId, org.apache.mesos.Protos.SlaveID slaveId, byte[] data)
          Sends a message from the framework to one of its executors.
 org.apache.mesos.Protos.Status start()
          See SchedulerDriver for descriptions of these.
 org.apache.mesos.Protos.Status stop()
          Stops the scheduler driver assuming no failover.
 org.apache.mesos.Protos.Status stop(boolean failover)
          Stops the scheduler driver.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MesosSchedulerDriver

public MesosSchedulerDriver(Scheduler scheduler,
                            org.apache.mesos.Protos.FrameworkInfo framework,
                            String master)
Creates a new driver for the specified scheduler. The master should be one of: host:port zk://host1:port1,host2:port2,.../path zk://username:password@host1:port1,host2:port2,.../path file:///path/to/file (where file contains one of the above) The driver will attempt to "failover" if the specified FrameworkInfo includes a valid FrameworkID. Any Mesos configuration options are read from environment variables, as well as any configuration files found through the environment variables. TODO(vinod): Deprecate this in favor the constructor that takes 'credential' as parameter.


MesosSchedulerDriver

public MesosSchedulerDriver(Scheduler scheduler,
                            org.apache.mesos.Protos.FrameworkInfo framework,
                            String master,
                            org.apache.mesos.Protos.Credential credential)
Same as the above constructor, except that it accepts 'credential' as a parameter.

Method Detail

start

public org.apache.mesos.Protos.Status start()
See SchedulerDriver for descriptions of these.

Specified by:
start in interface SchedulerDriver

stop

public org.apache.mesos.Protos.Status stop(boolean failover)
Description copied from interface: SchedulerDriver
Stops the scheduler driver. If the 'failover' flag is set to false then it is expected that this framework will never reconnect to Mesos and all of it's executors and tasks can be terminated. Otherwise, all executors and tasks will remain running (for some master specified failover timeout) allowing the scheduler to reconnect (possibly in the same process, or from a different process, for example, on a different machine).

Specified by:
stop in interface SchedulerDriver

stop

public org.apache.mesos.Protos.Status stop()
Description copied from interface: SchedulerDriver
Stops the scheduler driver assuming no failover.

Specified by:
stop in interface SchedulerDriver

abort

public org.apache.mesos.Protos.Status abort()
Description copied from interface: SchedulerDriver
Aborts the driver so that no more callbacks can be made to the scheduler. The semantics of abort and stop have deliberately been separated so that code can detect an aborted driver (i.e., via the return status of SchedulerDriver.join(), see below), and instantiate and start another driver if desired (from within the same process).

Specified by:
abort in interface SchedulerDriver

join

public org.apache.mesos.Protos.Status join()
Description copied from interface: SchedulerDriver
Waits for the driver to be stopped or aborted, possibly _blocking_ the current thread indefinitely. The return status of this function can be used to determine if the driver was aborted (see mesos.proto for a description of Status).

Specified by:
join in interface SchedulerDriver

run

public org.apache.mesos.Protos.Status run()
Description copied from interface: SchedulerDriver
Starts and immediately joins (i.e., blocks on) the driver.

Specified by:
run in interface SchedulerDriver

requestResources

public org.apache.mesos.Protos.Status requestResources(Collection<org.apache.mesos.Protos.Request> requests)
Description copied from interface: SchedulerDriver
Requests resources from Mesos (see mesos.proto for a description of Request and how, for example, to request resources from specific slaves). Any resources available are offered to the framework via Scheduler.resourceOffers(org.apache.mesos.SchedulerDriver, java.util.List) callback, asynchronously.

Specified by:
requestResources in interface SchedulerDriver

launchTasks

public org.apache.mesos.Protos.Status launchTasks(org.apache.mesos.Protos.OfferID offerId,
                                                  Collection<org.apache.mesos.Protos.TaskInfo> tasks)
Deprecated. Replaced by launchTasks using offer list.

Specified by:
launchTasks in interface SchedulerDriver

launchTasks

public org.apache.mesos.Protos.Status launchTasks(org.apache.mesos.Protos.OfferID offerId,
                                                  Collection<org.apache.mesos.Protos.TaskInfo> tasks,
                                                  org.apache.mesos.Protos.Filters filters)
Deprecated. Replaced by launchTasks using offer list.

Specified by:
launchTasks in interface SchedulerDriver

launchTasks

public org.apache.mesos.Protos.Status launchTasks(Collection<org.apache.mesos.Protos.OfferID> offerIds,
                                                  Collection<org.apache.mesos.Protos.TaskInfo> tasks)
Description copied from interface: SchedulerDriver
Launches the given set of tasks. See above for details.

Specified by:
launchTasks in interface SchedulerDriver

launchTasks

public org.apache.mesos.Protos.Status launchTasks(Collection<org.apache.mesos.Protos.OfferID> offerIds,
                                                  Collection<org.apache.mesos.Protos.TaskInfo> tasks,
                                                  org.apache.mesos.Protos.Filters filters)
Description copied from interface: SchedulerDriver
Launches the given set of tasks on a set of offers. Resources from offers are aggregated when more then one is provided. Note that all offers must belong to same slave. Any resources remaining (i.e., not used by the tasks or their executors) will be considered declined. The specified filters are applied on all unused resources (see mesos.proto for a description of Filters). Invoking this function with an empty collection of tasks declines offers in their entirety (see SchedulerDriver.declineOffer(org.apache.mesos.Protos.OfferID, org.apache.mesos.Protos.Filters).

Specified by:
launchTasks in interface SchedulerDriver

killTask

public org.apache.mesos.Protos.Status killTask(org.apache.mesos.Protos.TaskID taskId)
Description copied from interface: SchedulerDriver
Kills the specified task. Note that attempting to kill a task is currently not reliable. If, for example, a scheduler fails over while it was attempting to kill a task it will need to retry in the future Likewise, if unregistered / disconnected, the request will be dropped (these semantics may be changed in the future).

Specified by:
killTask in interface SchedulerDriver

declineOffer

public org.apache.mesos.Protos.Status declineOffer(org.apache.mesos.Protos.OfferID offerId)
Description copied from interface: SchedulerDriver
Declines an offer in its entirety. See above for details.

Specified by:
declineOffer in interface SchedulerDriver

declineOffer

public org.apache.mesos.Protos.Status declineOffer(org.apache.mesos.Protos.OfferID offerId,
                                                   org.apache.mesos.Protos.Filters filters)
Description copied from interface: SchedulerDriver
Declines an offer in its entirety and applies the specified filters on the resources (see mesos.proto for a description of Filters). Note that this can be done at any time, it is not necessary to do this within the Scheduler.resourceOffers(org.apache.mesos.SchedulerDriver, java.util.List) callback.

Specified by:
declineOffer in interface SchedulerDriver

reviveOffers

public org.apache.mesos.Protos.Status reviveOffers()
Description copied from interface: SchedulerDriver
Removes all filters, previously set by the framework (via SchedulerDriver.launchTasks(java.util.Collection, java.util.Collection, org.apache.mesos.Protos.Filters)). This enables the framework to receive offers from those filtered slaves.

Specified by:
reviveOffers in interface SchedulerDriver

sendFrameworkMessage

public org.apache.mesos.Protos.Status sendFrameworkMessage(org.apache.mesos.Protos.ExecutorID executorId,
                                                           org.apache.mesos.Protos.SlaveID slaveId,
                                                           byte[] data)
Description copied from interface: SchedulerDriver
Sends a message from the framework to one of its executors. These messages are best effort; do not expect a framework message to be retransmitted in any reliable fashion.

Specified by:
sendFrameworkMessage in interface SchedulerDriver

reconcileTasks

public org.apache.mesos.Protos.Status reconcileTasks(Collection<org.apache.mesos.Protos.TaskStatus> statuses)
Description copied from interface: SchedulerDriver
Reconciliation of tasks causes the master to send status updates for tasks whose status differs from the status sent here.

Specified by:
reconcileTasks in interface SchedulerDriver

initialize

protected void initialize()

finalize

protected void finalize()
Overrides:
finalize in class Object


Copyright © 2014 The Apache Software Foundation. All Rights Reserved.