-
Notifications
You must be signed in to change notification settings - Fork 149
/
calls.go
391 lines (350 loc) · 10.8 KB
/
calls.go
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
package calls
import (
"time"
"github.com/mesos/mesos-go/api/v1/lib"
"github.com/mesos/mesos-go/api/v1/lib/maintenance"
"github.com/mesos/mesos-go/api/v1/lib/master"
"github.com/mesos/mesos-go/api/v1/lib/quota"
)
// GetHealth retrieves the health status of master.
func GetHealth() *master.Call {
return &master.Call{
Type: master.Call_GET_HEALTH,
}
}
// GetFlags retrieves the master's overall flag configuration.
func GetFlags() *master.Call {
return &master.Call{
Type: master.Call_GET_FLAGS,
}
}
// GetVersion retrieves the master's version information.
func GetVersion() *master.Call {
return &master.Call{
Type: master.Call_GET_VERSION,
}
}
// GetMetrics gives the snapshot of current metrics to the end user. If timeout is set in the call, it will be used to
// determine the maximum amount of time the API will take to respond. If the timeout is exceeded, some metrics may not
// be included in the response.
func GetMetrics(d *time.Duration) (call *master.Call) {
call = &master.Call{
Type: master.Call_GET_METRICS,
GetMetrics: &master.Call_GetMetrics{},
}
if d != nil {
call.GetMetrics.Timeout = &mesos.DurationInfo{
Nanoseconds: d.Nanoseconds(),
}
}
return
}
// GetLoggingLevel retrieves the master's logging level.
func GetLoggingLevel() *master.Call {
return &master.Call{
Type: master.Call_GET_LOGGING_LEVEL,
}
}
// SetLoggingLevel sets the logging verbosity level for a specified duration for master. Mesos uses glog for logging.
// The library only uses verbose logging which means nothing will be output unless the verbosity level is set (by
// default it's 0, libprocess uses levels 1, 2, and 3).
func SetLoggingLevel(level uint32, d time.Duration) *master.Call {
return &master.Call{
Type: master.Call_SET_LOGGING_LEVEL,
SetLoggingLevel: &master.Call_SetLoggingLevel{
Level: level,
Duration: mesos.DurationInfo{
Nanoseconds: d.Nanoseconds(),
},
},
}
}
// ListFiles retrieves the file listing for a directory in master.
func ListFiles(path string) *master.Call {
return &master.Call{
Type: master.Call_LIST_FILES,
ListFiles: &master.Call_ListFiles{
Path: path,
},
}
}
// ReadFile reads data from a file on the master. This call takes the path of the file to be read and the offset to
// start reading.
func ReadFile(path string, offset uint64) *master.Call {
return &master.Call{
Type: master.Call_READ_FILE,
ReadFile: &master.Call_ReadFile{
Path: path,
Offset: offset,
},
}
}
// ReadFileWithLength is similar to ReadFile but species the maximum number of bytes to read from the file.
func ReadFileWithLength(path string, offset, length uint64) *master.Call {
call := ReadFile(path, offset)
call.ReadFile.Length = &length
return call
}
// GetState retrieves the overall cluster state.
func GetState() *master.Call {
return &master.Call{
Type: master.Call_GET_STATE,
}
}
// GetAgents retrieves information about all the agents known to the master.
func GetAgents() *master.Call {
return &master.Call{
Type: master.Call_GET_AGENTS,
}
}
// GetFrameworks retrieves information about all the frameworks known to the master.
func GetFrameworks() *master.Call {
return &master.Call{
Type: master.Call_GET_FRAMEWORKS,
}
}
// GetExecutors retrieves information about all the executors known to the master.
func GetExecutors() *master.Call {
return &master.Call{
Type: master.Call_GET_EXECUTORS,
}
}
// GetOperations retrieves information about all the operations known to the master.
func GetOperations() *master.Call {
return &master.Call{
Type: master.Call_GET_OPERATIONS,
}
}
// GetTasks retrieves information about all the tasks known to the master.
func GetTasks() *master.Call {
return &master.Call{
Type: master.Call_GET_TASKS,
}
}
// GetRoles retrieves information about all the roles known to the master.
func GetRoles() *master.Call {
return &master.Call{
Type: master.Call_GET_ROLES,
}
}
// GetWeights retrieves the information about role weights.
func GetWeights() *master.Call {
return &master.Call{
Type: master.Call_GET_WEIGHTS,
}
}
// UpdateWeights updates weights for specific roles.
func UpdateWeights(weights ...mesos.WeightInfo) *master.Call {
return &master.Call{
Type: master.Call_UPDATE_WEIGHTS,
UpdateWeights: &master.Call_UpdateWeights{
WeightInfos: weights,
},
}
}
// GetMaster retrieves information about the master.
func GetMaster() *master.Call {
return &master.Call{
Type: master.Call_GET_MASTER,
}
}
// Subscribe results in a streaming response. The client is expected to keep a persistent connection open to the
// endpoint even after getting a SUBSCRIBED HTTP Response event. This is indicated by "Connection: keep-alive" and
// "Transfer-Encoding: chunked" headers with no "Content-Length" header set. All subsequent events generated by Mesos
// are streamed on this connection. The master encodes each Event in RecordIO format, i.e., string representation of
// length of the event in bytes followed by JSON or binary Protobuf encoded event.
func Subscribe() *master.Call {
return &master.Call{
Type: master.Call_SUBSCRIBE,
}
}
// ReserveResources reserves resources dynamically on a specific agent.
func ReserveResources(a mesos.AgentID, r ...mesos.Resource) *master.Call {
return &master.Call{
Type: master.Call_RESERVE_RESOURCES,
ReserveResources: &master.Call_ReserveResources{
AgentID: a,
Resources: r,
},
}
}
// UnreserveResources unreserves resources dynamically on a specific agent.
func UnreserveResources(a mesos.AgentID, r ...mesos.Resource) *master.Call {
return &master.Call{
Type: master.Call_UNRESERVE_RESOURCES,
UnreserveResources: &master.Call_UnreserveResources{
AgentID: a,
Resources: r,
},
}
}
// CreateVolumes creates persistent volumes on reserved resources. The request is forwarded asynchronously to the Mesos
// agent where the reserved resources are located. That asynchronous message may not be delivered or creating the
// volumes at the agent might fail.
func CreateVolumes(a mesos.AgentID, v ...mesos.Resource) *master.Call {
return &master.Call{
Type: master.Call_CREATE_VOLUMES,
CreateVolumes: &master.Call_CreateVolumes{
AgentID: a,
Volumes: v,
},
}
}
// DestroyVolumes destroys persistent volumes. The request is forwarded asynchronously to the Mesos agent where the
// reserved resources are located.
func DestroyVolumes(a mesos.AgentID, v ...mesos.Resource) *master.Call {
return &master.Call{
Type: master.Call_DESTROY_VOLUMES,
DestroyVolumes: &master.Call_DestroyVolumes{
AgentID: a,
Volumes: v,
},
}
}
// GrowVolume grows a persistent volume on an agent's ROOT or PATH disks. The request is forwarded asynchronously to
// the Mesos agent where the persistent volume is located.
func GrowVolume(a *mesos.AgentID, volume, addition mesos.Resource) *master.Call {
return &master.Call{
Type: master.Call_GROW_VOLUME,
GrowVolume: &master.Call_GrowVolume{
AgentID: a,
Volume: volume,
Addition: addition,
},
}
}
// ShrinkVolume shrinks a persistent volume on an agent's ROOT or PATH disks. The request is forwarded asynchronously
// to the Mesos agent where the persistent volume is located.
func ShrinkVolume(a *mesos.AgentID, volume mesos.Resource, subtract mesos.Value_Scalar) *master.Call {
return &master.Call{
Type: master.Call_SHRINK_VOLUME,
ShrinkVolume: &master.Call_ShrinkVolume{
AgentID: a,
Volume: volume,
Subtract: subtract,
},
}
}
// GetMaintenanceStatus retrieves the cluster's maintenance status.
func GetMaintenanceStatus() *master.Call {
return &master.Call{
Type: master.Call_GET_MAINTENANCE_STATUS,
}
}
//GetMaintenanceSchedule retrieves the cluster's maintenance schedule.
func GetMaintenanceSchedule() *master.Call {
return &master.Call{
Type: master.Call_GET_MAINTENANCE_SCHEDULE,
}
}
// UpdateMaintenanceSchedule updates the cluster's maintenance schedule.
func UpdateMaintenanceSchedule(s maintenance.Schedule) *master.Call {
return &master.Call{
Type: master.Call_UPDATE_MAINTENANCE_SCHEDULE,
UpdateMaintenanceSchedule: &master.Call_UpdateMaintenanceSchedule{
Schedule: s,
},
}
}
// StartMaintenance starts the maintenance of the cluster, this would bring a set of machines down.
func StartMaintenance(m ...mesos.MachineID) *master.Call {
return &master.Call{
Type: master.Call_START_MAINTENANCE,
StartMaintenance: &master.Call_StartMaintenance{
Machines: m,
},
}
}
// StopMaintenance stops the maintenance of the cluster, this would bring a set of machines back up.
func StopMaintenance(m ...mesos.MachineID) *master.Call {
return &master.Call{
Type: master.Call_STOP_MAINTENANCE,
StopMaintenance: &master.Call_StopMaintenance{
Machines: m,
},
}
}
// GetQuota retrieves the cluster's configured quotas.
func GetQuota() *master.Call {
return &master.Call{
Type: master.Call_GET_QUOTA,
}
}
// SetQuota sets the quota for resources to be used by a particular role.
func SetQuota(qr quota.QuotaRequest) *master.Call {
return &master.Call{
Type: master.Call_SET_QUOTA,
SetQuota: &master.Call_SetQuota{
QuotaRequest: qr,
},
}
}
// RemoveQuota removes the quota for a particular role.
func RemoveQuota(role string) *master.Call {
return &master.Call{
Type: master.Call_REMOVE_QUOTA,
RemoveQuota: &master.Call_RemoveQuota{
Role: role,
},
}
}
// MarkAgentGone removes the quota for a particular role.
func MarkAgentGone(id mesos.AgentID) *master.Call {
return &master.Call{
Type: master.Call_MARK_AGENT_GONE,
MarkAgentGone: &master.Call_MarkAgentGone{
AgentID: id,
},
}
}
// Teardown removes the quota for a particular role.
func Teardown(id mesos.FrameworkID) *master.Call {
return &master.Call{
Type: master.Call_TEARDOWN,
Teardown: &master.Call_Teardown{
FrameworkID: id,
},
}
}
// DrainAgent marks an agent for automated draining of tasks.
// This prevents further tasks from being launched on the agent, by preventing
// offers from being sent for the agent (see 'DeactivateAgent'), and also
// begins killing tasks running on the agent.
// EXPERIMENTAL.
func DrainAgent(a mesos.AgentID, options ...func(*master.Call_DrainAgent)) *master.Call {
c := &master.Call{
Type: master.Call_DRAIN_AGENT,
DrainAgent: &master.Call_DrainAgent{
AgentID: a,
},
}
for _, f := range options {
if f != nil {
f(c.DrainAgent)
}
}
return c
}
// DeactivateAgent turns off offers for a specific agent.
// A deactivated agent will continue to run tasks and communicate statuses
// with the master.
// EXPERIMENTAL.
func DeactivateAgent(a mesos.AgentID) *master.Call {
return &master.Call{
Type: master.Call_DEACTIVATE_AGENT,
DeactivateAgent: &master.Call_DeactivateAgent{
AgentID: a,
},
}
}
// ReactivateAgent turns on offers for a specific agent, which was previously drained or
// deactivated.
// EXPERIMENTAL.
func ReactivateAgent(a mesos.AgentID) *master.Call {
return &master.Call{
Type: master.Call_REACTIVATE_AGENT,
ReactivateAgent: &master.Call_ReactivateAgent{
AgentID: a,
},
}
}