/
interface.py
335 lines (270 loc) · 10.9 KB
/
interface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
from __future__ import absolute_import, division, print_function
class Scheduler(object):
def on_registered(self, driver, framework_id, master):
"""Event handler triggered when the scheduler successfully registers
with a master.
Parameters
----------
driver: SchedulerDriver
Interface for interacting with Mesos Master
framework_id : string
Unique ID generated by the master
master : Master
Information about the master itself
Returns
-------
self
"""
pass
def on_reregistered(self, driver, framework_id, master):
"""Event handler triggered when the scheduler re-registers with a newly
elected master.
This is only called when the scheduler has previously been registered.
masterInfo contains information about the newly elected master.
Parameters
----------
driver: SchedulerDriver
Interface for interacting with Mesos Master
framework_id : string
Unique ID generated by the master
master : Master
Information about the master itself
"""
pass
def on_disconnected(self, driver):
"""Event handler triggereg when the scheduler becomes disconnected from
the master.
(e.g. the master fails and another is taking over)
Parameters
----------
driver: SchedulerDriver
Interface for interacting with Mesos Master
"""
pass
def on_offers(self, driver, offers):
"""Event handler triggered 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.on_rescinded).
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).
Parameters
----------
driver: SchedulerDriver
Interface for interacting with Mesos Master
offers: list of Offer
Resource offer instances
"""
pass
def on_rescinded(driver, offer_id):
"""Event handler triggered 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 framework that attempts to
launch tasks using an invalid offer will receive TASK_LOST status
updates for those tasks (see Scheduler.on_offers).
Parameters
----------
driver: SchedulerDriver
Interface for interacting with Mesos Master
offer_id: string
The unique identifier of the Mesos offer
"""
pass
def on_update(self, driver, status):
"""Event handler triggered 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.)
If implicit acknowledgements are being used, then 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).
If explicit acknowledgements are in use, the scheduler must acknowledge
this status on the driver.
Parameters
----------
driver: SchedulerDriver
Interface for interacting with Mesos Master
offer_id: string
The unique identifier of the Mesos offer
"""
pass
def on_message(self, driver, executor_id, slave_id, message):
"""Event handler triggered when an executor sends a message.
These messages are best effort; do not expect a framework message to be
retransmitted in any reliable fashion.
Parameters
----------
driver: SchedulerDriver
Interface for interacting with Mesos Master
executor_id: string
The unique identifier of the Mesos executor the message came from
slave_id: string
The unique identifier of the Mesos slave the message came from
message: string
Arbitrary byte stream
"""
pass
def on_slave_lost(self, driver, slave_id):
"""Event handler triggered 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.
Parameters
----------
driver: SchedulerDriver
Interface for interacting with Mesos Master
slave_id: string
The unique identifier of the lost Mesos slave
"""
pass
def on_executor_lost(self, driver, executor_id, slave_id, status):
"""Event handler triggered when an executor has exited/terminated.
Note that any tasks running will have TASK_LOST status updates
automatically generated.
NOTE: This callback is not reliably delivered.
Parameters
----------
driver: SchedulerDriver
Interface for interacting with Mesos Master
executor_id: string
The unique identifier of the lost Mesos executor
slave_id: string
The unique identifier of the Mesos slave where the executor loss
happened
status: int
TODO: figure it out
"""
pass
def on_error(self, driver, message):
"""Event handler triggered when there is an unrecoverable error in the
scheduler or scheduler driver.
The driver will be aborted BEFORE invoking this callback.
Parameters
----------
driver: SchedulerDriver
Interface for interacting with Mesos Master
message: string
Arbitrary byte stream
"""
pass
class Executor(object):
"""Base class for Mesos executors.
Users' executors should extend this class to get default implementations of
methods they don't override.
"""
def on_registered(self, driver, executor, framework, slave):
"""Event handler triggered when the executor driver has been able to
successfully connect with Mesos.
In particular, a scheduler can pass some data to its executors through
the FrameworkInfo.ExecutorInfo's data field.
Parameters
----------
driver: ExecutorDriver
Interface for interacting with Mesos Slave
executor: Executor
The unique identifier of the lost Mesos executor
framework: Framework
TODO: write docs
slave: Salve
TODO: write docs
"""
pass
def on_reregistered(self, driver, slave):
"""Event handler triggered when the executor re-registers with a
restarted slave.
Parameters
----------
driver: ExecutorDriver
Interface for interacting with Mesos Slave
slave: Slave
TODO: write docs
"""
pass
def on_disconnected(self, driver):
"""Event handler triggered when the executor becomes "disconnected" from
the slave.
(e.g., the slave is being restarted due to an upgrade)
Parameters
----------
driver: ExecutorDriver
Interface for interacting with Mesos Slave
"""
pass
def on_launch(self, driver, task):
"""Event handler triggered when a task has been launched on this
executor (initiated via Scheduler.launch).
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.
Parameters
----------
driver: ExecutorDriver
Interface for interacting with Mesos Slave
task: Task
TODO: write docs
"""
pass
def on_kill(self, driver, task_id):
"""Event handler triggered when a task running within this executor has
been killed (via SchedulerDriver.kill).
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's update method.
Parameters
----------
driver: ExecutorDriver
Interface for interacting with Mesos Slave
task_id: string
Unique identifier of the killed task
"""
pass
def on_message(self, driver, message):
"""Event handler triggered 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.
Parameters
----------
driver: ExecutorDriver
Interface for interacting with Mesos Slave
message: string
Arbitrary byte stream
"""
pass
def on_shutdown(self, driver):
"""Event handler triggered when the executor should terminate all of its
currently running tasks.
Note that after 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.
Parameters
----------
driver: ExecutorDriver
Interface for interacting with Mesos Slave
"""
pass
def on_error(self, driver, message):
"""Event handler triggered when a fatal error has occurred with the
executor and/or executor driver.
The driver will be aborted BEFORE invoking this callback.
Parameters
----------
driver: ExecutorDriver
Interface for interacting with Mesos Slave
message: string
Arbitrary byte stream
"""
pass