blob: 71615d7b56d20768769ef2feea993e3738c57277 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Apache Mesos - Scheduler HTTP API</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:locale" content="en_US"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="Apache Mesos"/>
<meta property="og:site_name" content="Apache Mesos"/>
<meta property="og:url" content="http://mesos.apache.org/"/>
<meta property="og:image" content="http://mesos.apache.org/assets/img/mesos_logo_fb_preview.png"/>
<meta property="og:description"
content="Apache Mesos abstracts resources away from machines,
enabling fault-tolerant and elastic distributed systems
to easily be built and run effectively."/>
<meta name="twitter:card" content="summary"/>
<meta name="twitter:site" content="@ApacheMesos"/>
<meta name="twitter:title" content="Apache Mesos"/>
<meta name="twitter:image" content="http://mesos.apache.org/assets/img/mesos_logo_fb_preview.png"/>
<meta name="twitter:description"
content="Apache Mesos abstracts resources away from machines,
enabling fault-tolerant and elastic distributed systems
to easily be built and run effectively."/>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<link rel="alternate" type="application/atom+xml" title="Apache Mesos Blog" href="/blog/feed.xml">
<link href="../../assets/css/main.css" media="screen" rel="stylesheet" type="text/css" />
<!-- Google Analytics Magic -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20226872-1']);
_gaq.push(['_setDomainName', 'apache.org']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<!-- magical breadcrumbs -->
<div class="topnav">
<div class="container">
<ul class="breadcrumb">
<li>
<div class="dropdown">
<a data-toggle="dropdown" href="#">Apache Software Foundation <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<li><a href="http://www.apache.org">Apache Homepage</a></li>
<li><a href="http://www.apache.org/licenses/">License</a></li>
<li><a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
<li><a href="http://www.apache.org/foundation/thanks.html">Thanks</a></li>
<li><a href="http://www.apache.org/security/">Security</a></li>
</ul>
</div>
</li>
<li><a href="http://mesos.apache.org">Apache Mesos</a></li>
<li><a href="/documentation
/">Documentation
</a></li>
</ul><!-- /.breadcrumb -->
</div><!-- /.container -->
</div><!-- /.topnav -->
<!-- navbar excitement -->
<div class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#mesos-menu" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/"><img src="/assets/img/mesos_logo.png" alt="Apache Mesos logo"/></a>
</div><!-- /.navbar-header -->
<div class="navbar-collapse collapse" id="mesos-menu">
<ul class="nav navbar-nav navbar-right">
<li><a href="/gettingstarted/">Getting Started</a></li>
<li><a href="/blog/">Blog</a></li>
<li><a href="/documentation/latest/">Documentation</a></li>
<li><a href="/downloads/">Downloads</a></li>
<li><a href="/community/">Community</a></li>
</ul>
</div><!-- /#mesos-menu -->
</div><!-- /.container -->
</div><!-- /.navbar -->
<div class="content">
<div class="container">
<div class="row-fluid">
<div class="col-md-4">
<h4>If you're new to Mesos</h4>
<p>See the <a href="/gettingstarted/">getting started</a> page for more
information about downloading, building, and deploying Mesos.</p>
<h4>If you'd like to get involved or you're looking for support</h4>
<p>See our <a href="/community/">community</a> page for more details.</p>
</div>
<div class="col-md-8">
<h1>Scheduler HTTP API</h1>
<p>A Mesos scheduler can be built in two different ways:</p>
<ol>
<li><p>By using the <code>SchedulerDriver</code> C++ interface. The <code>SchedulerDriver</code> handles
the details of communicating with the Mesos master. Scheduler developers
implement custom scheduling logic by registering callbacks with the
<code>SchedulerDriver</code> for significant events, such as receiving a new resource offer
or a status update on a task. Because the <code>SchedulerDriver</code> interface is written
in C++, this typically requires that scheduler developers either use C++ or use
a C++ binding to their language of choice (e.g., JNI when using JVM-based
languages).</p></li>
<li><p>By using the new HTTP API. This allows Mesos schedulers to be developed
without using C++ or a native client library; instead, a custom scheduler
interacts with the Mesos master via HTTP requests, as described below. Although
it is theoretically possible to use the HTTP scheduler API &ldquo;directly&rdquo; (e.g., by
using a generic HTTP library), most scheduler developers should use a library for
their language of choice that manages the details of the HTTP API; see the
document on <a href="/documentation/latest/./api-client-libraries/">HTTP API client libraries</a> for a list.</p></li>
</ol>
<p>The v1 Scheduler HTTP API was introduced in Mesos 0.24.0. As of Mesos 1.0, it is
considered stable and is the recommended way to develop new Mesos schedulers.</p>
<h2>Overview</h2>
<p>The scheduler interacts with Mesos via the <a href="/documentation/latest/./endpoints/master/api/v1/scheduler/">/api/v1/scheduler</a> master endpoint. We refer to this endpoint with its suffix &ldquo;/scheduler&rdquo; in the rest of this document. This endpoint accepts HTTP POST requests with data encoded as JSON (Content-Type: application/json) or binary Protobuf (Content-Type: application/x-protobuf). The first request that a scheduler sends to &ldquo;/scheduler&rdquo; endpoint is called SUBSCRIBE and results in a streaming response (&ldquo;200 OK&rdquo; status code with Transfer-Encoding: chunked).</p>
<p><strong>Schedulers are expected to keep the subscription connection open as long as possible (barring errors in network, software, hardware, etc.) and incrementally process the response.</strong> HTTP client libraries that can only parse the response after the connection is closed cannot be used. For the encoding used, please refer to <strong>Events</strong> section below.</p>
<p>All subsequent (non-<code>SUBSCRIBE</code>) requests to the &ldquo;/scheduler&rdquo; endpoint (see details below in <strong>Calls</strong> section) must be sent using a different connection than the one used for subscription. The master responds to these HTTP POST requests with &ldquo;202 Accepted&rdquo; status codes (or, for unsuccessful requests, with 4xx or 5xx status codes; details in later sections). The &ldquo;202 Accepted&rdquo; response means that a request has been accepted for processing, not that the processing of the request has been completed. The request might or might not be acted upon by Mesos (e.g., master fails during the processing of the request). Any asynchronous responses from these requests will be streamed on the long-lived subscription connection. Schedulers can submit requests using more than one different HTTP connection.</p>
<h2>Calls</h2>
<p>The following calls are currently accepted by the master. The canonical source of this information is <a href="https://github.com/apache/mesos/blob/master/include/mesos/v1/scheduler/scheduler.proto">scheduler.proto</a>. When sending JSON-encoded Calls, schedulers should encode raw bytes in Base64 and strings in UTF-8. All non-<code>SUBSCRIBE</code> calls should include the <code>Mesos-Stream-Id</code> header, explained in the <a href="#subscribe"><code>SUBSCRIBE</code></a> section. <code>SUBSCRIBE</code> calls should never include the <code>Mesos-Stream-Id</code> header.</p>
<p><a id="recordio-response-format"></a></p>
<h3>RecordIO response format</h3>
<p>The response returned from the <code>SUBSCRIBE</code> call (see <a href="#subscribe">below</a>) is encoded in RecordIO format, which essentially prepends to a single record (either JSON or serialized Protobuf) its length in bytes, followed by a newline and then the data:</p>
<p>The <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.1">BNF grammar</a> for a RecordIO-encoded streaming response is:</p>
<pre><code> records = *record
record = record-size LF record-data
record-size = 1*DIGIT
record-data = record-size(OCTET)
</code></pre>
<p><code>record-size</code> should be interpreted as an unsigned 64-bit integer (<code>uint64</code>).</p>
<p>For example, a stream may look like:</p>
<pre><code>128\n
{"type": "SUBSCRIBED","subscribed": {"framework_id": {"value":"12220-3440-12532-2345"},"heartbeat_interval_seconds":15.0}20\n
{"type":"HEARTBEAT"}675\n
...
</code></pre>
<p>In pseudo-code, this could be parsed with something like the following:</p>
<pre><code> while (true) {
do {
lengthBytes = readline()
} while (lengthBytes.length &lt; 1)
messageLength = parseInt(lengthBytes);
messageBytes = read(messageLength);
process(messageBytes);
}
</code></pre>
<p>Network intermediaries (e.g., proxies) are free to change the chunk boundaries; this should not have any effect on the recipient application (scheduler). We wanted a way to delimit/encode two events for JSON/Protobuf responses consistently and RecordIO format allowed us to do that.</p>
<p><a id="subscribe"></a></p>
<h3>SUBSCRIBE</h3>
<p>This is the first step in the communication process between the scheduler and the master. This is also to be considered as subscription to the &ldquo;/scheduler&rdquo; event stream.</p>
<p>To subscribe with the master, the scheduler sends an HTTP POST with a <code>SUBSCRIBE</code> message including the required FrameworkInfo. Note that if &ldquo;subscribe.framework_info.id&rdquo; is not set, master considers the scheduler as a new one and subscribes it by assigning it a FrameworkID. The HTTP response is a stream in RecordIO format; the event stream begins with a <code>SUBSCRIBED</code> event (see details in <strong>Events</strong> section). The response also includes the <code>Mesos-Stream-Id</code> header, which is used by the master to uniquely identify the subscribed scheduler instance. This stream ID header should be included in all subsequent non-<code>SUBSCRIBE</code> calls sent over this subscription connection to the master. The value of <code>Mesos-Stream-Id</code> is guaranteed to be at most 128 bytes in length.</p>
<pre><code>SUBSCRIBE Request (JSON):
POST /api/v1/scheduler HTTP/1.1
Host: masterhost:5050
Content-Type: application/json
Accept: application/json
Connection: close
{
"type" : "SUBSCRIBE",
"subscribe" : {
"framework_info" : {
"user" : "foo",
"name" : "Example HTTP Framework"
}
}
}
SUBSCRIBE Response Event (JSON):
HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked
Mesos-Stream-Id: 130ae4e3-6b13-4ef4-baa9-9f2e85c3e9af
&lt;event length&gt;
{
"type" : "SUBSCRIBED",
"subscribed" : {
"framework_id" : {"value":"12220-3440-12532-2345"},
"heartbeat_interval_seconds" : 15
}
}
&lt;more events&gt;
</code></pre>
<p>Alternatively, if &ldquo;subscribe.framework_info.id&rdquo; is set, master considers this a request from an already subscribed scheduler reconnecting after a disconnection (e.g., due to master/scheduler failover or network disconnection) and responds
with a <code>SUBSCRIBED</code> event. For further details, see the <strong>Disconnections</strong> section below.</p>
<p>NOTE: In the old version of the API, (re-)registered callbacks also included MasterInfo, which contained information about the master the driver currently connected to. With the new API, since schedulers explicitly subscribe with the leading master (see details below in <strong>Master Detection</strong> section), it&rsquo;s not relevant anymore.</p>
<p>If subscription fails for whatever reason (e.g., invalid request), an HTTP 4xx response is returned with the error message as part of the body and the connection is closed.</p>
<p>A scheduler can make additional HTTP requests to the &ldquo;/scheduler&rdquo; endpoint only after it has opened a persistent connection to it by sending a <code>SUBSCRIBE</code> request and received a <code>SUBSCRIBED</code> response. Calls made without subscription will result in &ldquo;403 Forbidden&rdquo; instead of a &ldquo;202 Accepted&rdquo; response. A scheduler might also receive a &ldquo;400 Bad Request&rdquo; response if the HTTP request is malformed (e.g., malformed HTTP headers).</p>
<p>Note that the <code>Mesos-Stream-Id</code> header should <strong>never</strong> be included with a <code>SUBSCRIBE</code> call; the master will always provide a new unique stream ID for each subscription.</p>
<h3>TEARDOWN</h3>
<p>Sent by the scheduler when it wants to tear itself down. When Mesos receives this request it will shut down all executors (and consequently kill tasks). It then removes the framework and closes all open connections from this scheduler to the Master.</p>
<pre><code>TEARDOWN Request (JSON):
POST /api/v1/scheduler HTTP/1.1
Host: masterhost:5050
Content-Type: application/json
Mesos-Stream-Id: 130ae4e3-6b13-4ef4-baa9-9f2e85c3e9af
{
"framework_id" : {"value" : "12220-3440-12532-2345"},
"type" : "TEARDOWN"
}
TEARDOWN Response:
HTTP/1.1 202 Accepted
</code></pre>
<h3>ACCEPT</h3>
<p>Sent by the scheduler when it accepts offer(s) sent by the master. The <code>ACCEPT</code> request includes the type of operations (e.g., launch task, launch task group, reserve resources, create volumes) that the scheduler wants to perform on the offers. Note that until the scheduler replies (accepts or declines) to an offer, the offer&rsquo;s resources are considered allocated to the framework. Also, any of the offer&rsquo;s resources not used in the <code>ACCEPT</code> call (e.g., to launch a task or task group) are considered declined and might be reoffered to other frameworks. In other words, the same <code>OfferID</code> cannot be used in more than one <code>ACCEPT</code> call. These semantics might change when we add new features to Mesos (e.g., persistence, reservations, optimistic offers, resizeTask, etc.).</p>
<pre><code>ACCEPT Request (JSON):
POST /api/v1/scheduler HTTP/1.1
Host: masterhost:5050
Content-Type: application/json
Mesos-Stream-Id: 130ae4e3-6b13-4ef4-baa9-9f2e85c3e9af
{
"framework_id" : {"value" : "12220-3440-12532-2345"},
"type" : "ACCEPT",
"accept" : {
"offer_ids" : [
{"value" : "12220-3440-12532-O12"}
],
"operations" : [
{
"type" : "LAUNCH",
"launch" : {
"task_infos" : [
{
"name" : "My Task",
"task_id" : {"value" : "12220-3440-12532-my-task"},
"agent_id" : {"value" : "12220-3440-12532-S1233"},
"executor" : {
"command" : {
"shell" : true,
"value" : "sleep 1000"
},
"executor_id" : {"value" : "12214-23523-my-executor"}
},
"resources" : [
{
"name" : "cpus",
"role" : "*",
"type" : "SCALAR",
"scalar": {"value": 1.0}
},
{
"name" : "mem",
"role" : "*",
"type" : "SCALAR",
"scalar": {"value": 128.0}
}
]
}
]
}
}
],
"filters" : {"refuse_seconds" : 5.0}
}
}
ACCEPT Response:
HTTP/1.1 202 Accepted
</code></pre>
<h3>DECLINE</h3>
<p>Sent by the scheduler to explicitly decline offer(s) received. Note that this is same as sending an <code>ACCEPT</code> call with no operations.</p>
<pre><code>DECLINE Request (JSON):
POST /api/v1/scheduler HTTP/1.1
Host: masterhost:5050
Content-Type: application/json
Mesos-Stream-Id: 130ae4e3-6b13-4ef4-baa9-9f2e85c3e9af
{
"framework_id" : {"value" : "12220-3440-12532-2345"},
"type" : "DECLINE",
"decline" : {
"offer_ids" : [
{"value" : "12220-3440-12532-O12"},
{"value" : "12220-3440-12532-O13"}
],
"filters" : {"refuse_seconds" : 5.0}
}
}
DECLINE Response:
HTTP/1.1 202 Accepted
</code></pre>
<h3>REVIVE</h3>
<p>Sent by the scheduler to remove any/all filters that it has previously set via <code>ACCEPT</code> or <code>DECLINE</code> calls.</p>
<pre><code>REVIVE Request (JSON):
POST /api/v1/scheduler HTTP/1.1
Host: masterhost:5050
Content-Type: application/json
Mesos-Stream-Id: 130ae4e3-6b13-4ef4-baa9-9f2e85c3e9af
{
"framework_id" : {"value" : "12220-3440-12532-2345"},
"type" : "REVIVE"
}
REVIVE Response:
HTTP/1.1 202 Accepted
</code></pre>
<h3>KILL</h3>
<p>Sent by the scheduler to kill a specific task. If the scheduler has a custom executor, the kill is forwarded to the executor; it is up to the executor to kill the task and send a <code>TASK_KILLED</code> (or <code>TASK_FAILED</code>) update. If the task hasn&rsquo;t yet been delivered to the executor when Mesos master or agent receives the kill request, a <code>TASK_KILLED</code> is generated and the task launch is not forwarded to the executor. Note that if the task belongs to a task group, killing of one task results in all tasks in the task group being killed. Mesos releases the resources for a task once it receives a terminal update for the task. If the task is unknown to the master, a <code>TASK_LOST</code> will be generated.</p>
<pre><code>KILL Request (JSON):
POST /api/v1/scheduler HTTP/1.1
Host: masterhost:5050
Content-Type: application/json
Mesos-Stream-Id: 130ae4e3-6b13-4ef4-baa9-9f2e85c3e9af
{
"framework_id" : {"value" : "12220-3440-12532-2345"},
"type" : "KILL",
"kill" : {
"task_id" : {"value" : "12220-3440-12532-my-task"},
"agent_id" : {"value" : "12220-3440-12532-S1233"}
}
}
KILL Response:
HTTP/1.1 202 Accepted
</code></pre>
<h3>SHUTDOWN</h3>
<p>Sent by the scheduler to shutdown a specific custom executor (NOTE: This is a new call that was not present in the old API). When an executor gets a shutdown event, it is expected to kill all its tasks (and send <code>TASK_KILLED</code> updates) and terminate. If an executor doesn&rsquo;t terminate within a certain timeout (configurable via the <code>--executor_shutdown_grace_period</code> agent flag), the agent will forcefully destroy the container (executor and its tasks) and transition its active tasks to <code>TASK_LOST</code>.</p>
<pre><code>SHUTDOWN Request (JSON):
POST /api/v1/scheduler HTTP/1.1
Host: masterhost:5050
Content-Type: application/json
Mesos-Stream-Id: 130ae4e3-6b13-4ef4-baa9-9f2e85c3e9af
{
"framework_id" : {"value" : "12220-3440-12532-2345"},
"type" : "SHUTDOWN",
"shutdown" : {
"executor_id" : {"value" : "123450-2340-1232-my-executor"},
"agent_id" : {"value" : "12220-3440-12532-S1233"}
}
}
SHUTDOWN Response:
HTTP/1.1 202 Accepted
</code></pre>
<h3>ACKNOWLEDGE</h3>
<p>Sent by the scheduler to acknowledge a status update. Note that with the new API, schedulers are responsible for explicitly acknowledging the receipt of status updates that have <code>status.uuid</code> set. These status updates are retried until they are acknowledged by the scheduler. The scheduler must not acknowledge status updates that do not have <code>status.uuid</code> set, as they are not retried. The <code>uuid</code> field contains raw bytes encoded in Base64.</p>
<pre><code>ACKNOWLEDGE Request (JSON):
POST /api/v1/scheduler HTTP/1.1
Host: masterhost:5050
Content-Type: application/json
Mesos-Stream-Id: 130ae4e3-6b13-4ef4-baa9-9f2e85c3e9af
{
"framework_id" : {"value" : "12220-3440-12532-2345"},
"type" : "ACKNOWLEDGE",
"acknowledge" : {
"agent_id" : {"value" : "12220-3440-12532-S1233"},
"task_id" : {"value" : "12220-3440-12532-my-task"},
"uuid" : "jhadf73jhakdlfha723adf"
}
}
ACKNOWLEDGE Response:
HTTP/1.1 202 Accepted
</code></pre>
<h3>RECONCILE</h3>
<p>Sent by the scheduler to query the status of non-terminal tasks. This causes the master to send back <code>UPDATE</code> events for each task in the list. Tasks that are no longer known to Mesos will result in <code>TASK_LOST</code> updates. If the list of tasks is empty, master will send <code>UPDATE</code> events for all currently known tasks of the framework.</p>
<pre><code>RECONCILE Request (JSON):
POST /api/v1/scheduler HTTP/1.1
Host: masterhost:5050
Content-Type: application/json
Mesos-Stream-Id: 130ae4e3-6b13-4ef4-baa9-9f2e85c3e9af
{
"framework_id" : {"value" : "12220-3440-12532-2345"},
"type" : "RECONCILE",
"reconcile" : {
"tasks" : [
{ "task_id" : {"value" : "312325"},
"agent_id" : {"value" : "123535"}
}
]
}
}
RECONCILE Response:
HTTP/1.1 202 Accepted
</code></pre>
<h3>MESSAGE</h3>
<p>Sent by the scheduler to send arbitrary binary data to the executor. Mesos neither interprets this data nor makes any guarantees about the delivery of this message to the executor. <code>data</code> is raw bytes encoded in Base64.</p>
<pre><code>MESSAGE Request (JSON):
POST /api/v1/scheduler HTTP/1.1
Host: masterhost:5050
Content-Type: application/json
Mesos-Stream-Id: 130ae4e3-6b13-4ef4-baa9-9f2e85c3e9af
{
"framework_id" : {"value" : "12220-3440-12532-2345"},
"type" : "MESSAGE",
"message" : {
"agent_id" : {"value" : "12220-3440-12532-S1233"},
"executor_id" : {"value" : "my-framework-executor"},
"data" : "adaf838jahd748jnaldf"
}
}
MESSAGE Response:
HTTP/1.1 202 Accepted
</code></pre>
<h3>REQUEST</h3>
<p>Sent by the scheduler to request resources from the master/allocator. The built-in hierarchical allocator simply ignores this request but other allocators (modules) can interpret this in a customizable fashion.</p>
<pre><code>Request (JSON):
POST /api/v1/scheduler HTTP/1.1
Host: masterhost:5050
Content-Type: application/json
Mesos-Stream-Id: 130ae4e3-6b13-4ef4-baa9-9f2e85c3e9af
{
"framework_id" : {"value" : "12220-3440-12532-2345"},
"type" : "REQUEST",
"requests" : [
{
"agent_id" : {"value" : "12220-3440-12532-S1233"},
"resources" : {}
}
]
}
REQUEST Response:
HTTP/1.1 202 Accepted
</code></pre>
<h2>Events</h2>
<p>Schedulers are expected to keep a <strong>persistent</strong> connection to the &ldquo;/scheduler&rdquo; endpoint (even after getting a <code>SUBSCRIBED</code> HTTP Response event). This is indicated by the &ldquo;Connection: keep-alive&rdquo; and &ldquo;Transfer-Encoding: chunked&rdquo; headers with <em>no</em> &ldquo;Content-Length&rdquo; header set. All subsequent events that are relevant to this framework generated by Mesos are streamed on this connection. The master encodes each Event in RecordIO format, i.e., string representation of the length of the event in bytes followed by JSON or binary Protobuf (possibly compressed) encoded event. The length of an event is a 64-bit unsigned integer (encoded as a textual value) and will never be &ldquo;0&rdquo;. Also, note that the RecordIO encoding should be decoded by the scheduler whereas the underlying HTTP chunked encoding is typically invisible at the application (scheduler) layer. The type of content encoding used for the events will be determined by the accept header of the POST request (e.g., Accept: application/json).</p>
<p>The following events are currently sent by the master. The canonical source of this information is at <a href="https://github.com/apache/mesos/blob/master/include/mesos/v1/scheduler/scheduler.proto">scheduler.proto</a>. Note that when sending JSON encoded events, master encodes raw bytes in Base64 and strings in UTF-8.</p>
<h3>SUBSCRIBED</h3>
<p>The first event sent by the master when the scheduler sends a <code>SUBSCRIBE</code> request on the persistent connection. See <code>SUBSCRIBE</code> in Calls section for the format.</p>
<h3>OFFERS</h3>
<p>Sent by the master whenever there are new resources that can be offered to the framework. Each offer corresponds to a set of resources on an agent. Until the scheduler &lsquo;Accept&rsquo;s or 'Decline&rsquo;s an offer the resources are considered allocated to the scheduler, unless the offer is otherwise rescinded, e.g., due to a lost agent or <code>--offer_timeout</code>.</p>
<pre><code>OFFERS Event (JSON)
&lt;event-length&gt;
{
"type" : "OFFERS",
"offers" : [
{
"offer_id" : {"value": "12214-23523-O235235"},
"framework_id" : {"value": "12124-235325-32425"},
"agent_id" : {"value": "12325-23523-S23523"},
"hostname" : "agent.host",
"resources" : [
{
"name" : "cpus",
"type" : "SCALAR",
"scalar" : {"value" : 2},
"role" : "*"
}
],
"attributes" : [
{
"name" : "os",
"type" : "TEXT",
"text" : {"value" : "ubuntu16.04"}
}
],
"executor_ids" : [
{"value" : "12214-23523-my-executor"}
]
}
]
}
</code></pre>
<h3>RESCIND</h3>
<p>Sent by the master when a particular offer is no longer valid (e.g., the agent corresponding to the offer has been removed) and hence needs to be rescinded. Any future calls (<code>ACCEPT</code> / <code>DECLINE</code>) made by the scheduler regarding this offer will be invalid.</p>
<pre><code>RESCIND Event (JSON)
&lt;event-length&gt;
{
"type" : "RESCIND",
"rescind" : {
"offer_id" : { "value" : "12214-23523-O235235"}
}
}
</code></pre>
<h3>UPDATE</h3>
<p>Sent by the master whenever there is a status update that is generated by the executor, agent or master. Status updates should be used by executors to reliably communicate the status of the tasks that they manage. It is crucial that a terminal update (e.g., <code>TASK_FINISHED</code>, <code>TASK_KILLED</code>, <code>TASK_FAILED</code>) is sent by the executor as soon as the task terminates, in order for Mesos to release the resources allocated to the task. It is also the responsibility of the scheduler to explicitly acknowledge the receipt of status updates that are reliably retried. See <code>ACKNOWLEDGE</code> in the Calls section above for the semantics. Note that <code>uuid</code> and <code>data</code> are raw bytes encoded in Base64.</p>
<pre><code>UPDATE Event (JSON)
&lt;event-length&gt;
{
"type" : "UPDATE",
"update" : {
"status" : {
"task_id" : { "value" : "12344-my-task"},
"state" : "TASK_RUNNING",
"source" : "SOURCE_EXECUTOR",
"uuid" : "adfadfadbhgvjayd23r2uahj",
"bytes" : "uhdjfhuagdj63d7hadkf"
}
}
}
</code></pre>
<h3>MESSAGE</h3>
<p>A custom message generated by the executor that is forwarded to the scheduler by the master. This message is not interpreted by Mesos and is only forwarded (without reliability guarantees) to the scheduler. It is up to the executor to retry if the message is dropped for any reason. The <code>data</code> field contains raw bytes encoded as Base64.</p>
<pre><code>MESSAGE Event (JSON)
&lt;event-length&gt;
{
"type" : "MESSAGE",
"message" : {
"agent_id" : { "value" : "12214-23523-S235235"},
"executor_id" : { "value" : "12214-23523-my-executor"},
"data" : "adfadf3t2wa3353dfadf"
}
}
</code></pre>
<h3>FAILURE</h3>
<p>Sent by the master when an agent is removed from the cluster (e.g., failed health checks) or when an executor is terminated. This event coincides with receipt of terminal <code>UPDATE</code> events for any active tasks belonging to the agent or executor and receipt of <code>RESCIND</code> events for any outstanding offers belonging to the agent. Note that there is no guaranteed order between the <code>FAILURE</code>, <code>UPDATE</code>, and <code>RESCIND</code> events.</p>
<pre><code>FAILURE Event (JSON)
&lt;event-length&gt;
{
"type" : "FAILURE",
"failure" : {
"agent_id" : { "value" : "12214-23523-S235235"},
"executor_id" : { "value" : "12214-23523-my-executor"},
"status" : 1
}
}
</code></pre>
<h3>ERROR</h3>
<p>Sent by the master when an asynchronous error event is generated (e.g., a framework is not authorized to subscribe with the given role). It is recommended that the framework abort when it receives an error and retry subscription as necessary.</p>
<pre><code>ERROR Event (JSON)
&lt;event-length&gt;
{
"type" : "ERROR",
"message" : "Framework is not authorized"
}
</code></pre>
<h3>HEARTBEAT</h3>
<p>This event is periodically sent by the master to inform the scheduler that a connection is alive. This also helps ensure that network intermediates do not close the persistent subscription connection due to lack of data flow. See the next section on how a scheduler can use this event to deal with network partitions.</p>
<pre><code>HEARTBEAT Event (JSON)
&lt;event-length&gt;
{
"type" : "HEARTBEAT"
}
</code></pre>
<h2>Disconnections</h2>
<p>Master considers a scheduler disconnected if the persistent subscription connection (opened via <code>SUBSCRIBE</code> request) to &ldquo;/scheduler&rdquo; breaks. The connection could break for several reasons, e.g., scheduler restart, scheduler failover, network error. Note that the master doesn&rsquo;t keep track of non-subscription connection(s) to
&ldquo;/scheduler&rdquo; because it is not expected to be a persistent connection.</p>
<p>If master realizes that the subscription connection is broken, it marks the scheduler as &ldquo;disconnected&rdquo; and starts a failover timeout (failover timeout is part of FrameworkInfo). It also drops any pending events in its queue. Additionally, it rejects subsequent non-subscribe HTTP requests to &ldquo;/scheduler&rdquo; with &ldquo;403 Forbidden&rdquo;, until the scheduler subscribes again with &ldquo;/scheduler&rdquo;. If the scheduler <em>does not</em> re-subscribe within the failover timeout, the master considers the scheduler gone forever and shuts down all its executors, thus killing all its tasks. Therefore, all production schedulers are recommended to use a high value (e.g., 4 weeks) for the failover timeout.</p>
<p>NOTE: To force shutdown of a framework before the failover timeout elapses (e.g., during framework development and testing), either the framework can send the <code>TEARDOWN</code> call (part of the Scheduler API) or an operator can use the <a href="/documentation/latest/./endpoints/master/teardown/">/teardown</a> master endpoint (part of the Operator API).</p>
<p>If the scheduler realizes that its subscription connection to &ldquo;/scheduler&rdquo; is broken or the master has changed (e.g., via ZooKeeper), it should resubscribe (using a backoff strategy). This is done by sending a <code>SUBSCRIBE</code> request (with framework ID set) on a <strong>new</strong> persistent connection to the &ldquo;/scheduler&rdquo; endpoint on the (possibly new) master. It should not send new non-subscribe HTTP requests to &ldquo;/scheduler&rdquo; unless it receives a <code>SUBSCRIBED</code> event; such requests will result in &ldquo;403 Forbidden&rdquo;.</p>
<p>If the master does not realize that the subscription connection is broken but the scheduler realizes it, the scheduler might open a new persistent connection to
&ldquo;/scheduler&rdquo; via <code>SUBSCRIBE</code>. In this case, the master closes the existing subscription connection and allows subscription on the new connection. The invariant here is that only one persistent subscription connection for a given framework ID is allowed on the master.</p>
<p>The master uses the <code>Mesos-Stream-Id</code> header to distinguish scheduler instances from one another. In the case of highly available schedulers with multiple instances, this can prevent unwanted behavior in certain failure scenarios. Each unique <code>Mesos-Stream-Id</code> is valid only for the life of a single subscription connection. Each response to a <code>SUBSCRIBE</code> request contains a <code>Mesos-Stream-Id</code>, and this ID must be included with all subsequent non-subscribe calls sent over that subscription connection. Whenever a new subscription connection is established, a new stream ID is generated and should be used for the life of that connection.</p>
<h3>Network partitions</h3>
<p>In the case of a network partition, the subscription connection between the scheduler and master might not necessarily break. To be able to detect this scenario, master periodically (e.g., 15s) sends <code>HEARTBEAT</code> events (similar to Twitter&rsquo;s Streaming API). If a scheduler doesn&rsquo;t receive a bunch (e.g., 5) of these heartbeats within a time window, it should immediately disconnect and try to resubscribe. It is highly recommended for schedulers to use an exponential backoff strategy (e.g., up to a maximum of 15s) to avoid overwhelming the master while reconnecting. Schedulers can use a similar timeout (e.g., 75s) for receiving responses to any HTTP requests.</p>
<h2>Master detection</h2>
<p>Mesos has a high-availability mode that uses multiple Mesos masters; one active master (called the leader or leading master) and several standbys in case it fails. The masters elect the leader, with ZooKeeper coordinating the election. For more details please refer to the <a href="/documentation/latest/./high-availability/">documentation</a>.</p>
<p>Schedulers are expected to make HTTP requests to the leading master. If requests are made to a non-leading master a &ldquo;HTTP 307 Temporary Redirect&rdquo; will be received with the &ldquo;Location&rdquo; header pointing to the leading master.</p>
<p>Example subscription workflow with redirection when the scheduler hits a non-leading master.</p>
<pre><code>Scheduler -&gt; Master
POST /api/v1/scheduler HTTP/1.1
Host: masterhost1:5050
Content-Type: application/json
Accept: application/json
Connection: keep-alive
{
"framework_info" : {
"user" : "foo",
"name" : "Example HTTP Framework"
},
"type" : "SUBSCRIBE"
}
Master -&gt; Scheduler
HTTP/1.1 307 Temporary Redirect
Location: masterhost2:5050
Scheduler -&gt; Master
POST /api/v1/scheduler HTTP/1.1
Host: masterhost2:5050
Content-Type: application/json
Accept: application/json
Connection: keep-alive
{
"framework_info" : {
"user" : "foo",
"name" : "Example HTTP Framework"
},
"type" : "SUBSCRIBE"
}
</code></pre>
<p>If the scheduler knows the list of master&rsquo;s hostnames for a cluster, it could use this mechanism to find the leading master to subscribe with. Alternatively, the scheduler could use a library that detects the leading master given a ZooKeeper (or etcd) URL. For a C++ library that does ZooKeeper based master detection please look at <code>src/scheduler/scheduler.cpp</code>.</p>
</div>
</div>
</div><!-- /.container -->
</div><!-- /.content -->
<hr>
<!-- footer -->
<div class="footer">
<div class="container">
<div class="col-md-4 social-blk">
<span class="social">
<a href="https://twitter.com/ApacheMesos"
class="twitter-follow-button"
data-show-count="false" data-size="large">Follow @ApacheMesos</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<a href="https://twitter.com/intent/tweet?button_hashtag=mesos"
class="twitter-hashtag-button"
data-size="large"
data-related="ApacheMesos">Tweet #mesos</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</span>
</div>
<div class="col-md-8 trademark">
<p>&copy; 2012-2017 <a href="http://apache.org">The Apache Software Foundation</a>.
Apache Mesos, the Apache feather logo, and the Apache Mesos project logo are trademarks of The Apache Software Foundation.
<p>
</div>
</div><!-- /.container -->
</div><!-- /.footer -->
<!-- JS -->
<script src="//code.jquery.com/jquery-1.11.0.min.js" type="text/javascript"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js" type="text/javascript"></script>
</body>
</html>