-
Notifications
You must be signed in to change notification settings - Fork 49
/
job-manager.c
277 lines (262 loc) · 8.09 KB
/
job-manager.c
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
/************************************************************\
* Copyright 2018 Lawrence Livermore National Security, LLC
* (c.f. AUTHORS, NOTICE.LLNS, COPYING)
*
* This file is part of the Flux resource manager framework.
* For details, see https://github.com/flux-framework.
*
* SPDX-License-Identifier: LGPL-3.0
\************************************************************/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <unistd.h>
#include <sys/types.h>
#include <flux/core.h>
#include "src/common/libjob/job_hash.h"
#include "src/common/libczmqcontainers/czmq_containers.h"
#include "job.h"
#include "conf.h"
#include "submit.h"
#include "restart.h"
#include "raise.h"
#include "kill.h"
#include "list.h"
#include "urgency.h"
#include "alloc.h"
#include "start.h"
#include "event.h"
#include "drain.h"
#include "wait.h"
#include "purge.h"
#include "queue.h"
#include "annotate.h"
#include "journal.h"
#include "getattr.h"
#include "update.h"
#include "jobtap-internal.h"
#include "job-manager.h"
void getinfo_handle_request (flux_t *h,
flux_msg_handler_t *mh,
const flux_msg_t *msg,
void *arg)
{
struct job_manager *ctx = arg;
if (flux_request_decode (msg, NULL, NULL) < 0)
goto error;
if (flux_respond_pack (h,
msg,
"{s:I}",
"max_jobid", ctx->max_jobid) < 0)
flux_log_error (h, "%s: flux_respond_pack", __FUNCTION__);
return;
error:
if (flux_respond_error (h, msg, errno, NULL) < 0)
flux_log_error (h, "%s: flux_respond_error", __FUNCTION__);
}
void disconnect_rpc (flux_t *h,
flux_msg_handler_t *mh,
const flux_msg_t *msg,
void *arg)
{
/* disconnects occur once per client, there is no way to know
* which services a client used, so we must check all services for
* cleanup */
alloc_disconnect_rpc (h, mh, msg, arg);
wait_disconnect_rpc (h, mh, msg, arg);
journal_listeners_disconnect_rpc (h, mh, msg, arg);
}
static void stats_cb (flux_t *h, flux_msg_handler_t *mh,
const flux_msg_t *msg, void *arg)
{
struct job_manager *ctx = arg;
int journal_listeners = journal_listeners_count (ctx->journal);
if (flux_respond_pack (h,
msg,
"{s:{s:i} s:i s:i s:I}",
"journal",
"listeners", journal_listeners,
"active_jobs", zhashx_size (ctx->active_jobs),
"inactive_jobs", zhashx_size (ctx->inactive_jobs),
"max_jobid", ctx->max_jobid) < 0) {
flux_log_error (h, "%s: flux_respond_pack", __FUNCTION__);
goto error;
}
return;
error:
if (flux_respond_error (h, msg, errno, NULL) < 0)
flux_log_error (h, "%s: flux_respond_error", __FUNCTION__);
}
static const struct flux_msg_handler_spec htab[] = {
{
FLUX_MSGTYPE_REQUEST,
"job-manager.list",
list_handle_request,
0
},
{
FLUX_MSGTYPE_REQUEST,
"job-manager.urgency",
urgency_handle_request,
FLUX_ROLE_USER
},
{
FLUX_MSGTYPE_REQUEST,
"job-manager.getattr",
getattr_handle_request,
FLUX_ROLE_USER
},
{
FLUX_MSGTYPE_REQUEST,
"job-manager.getinfo",
getinfo_handle_request,
FLUX_ROLE_USER
},
{
FLUX_MSGTYPE_REQUEST,
"job-manager.jobtap",
jobtap_handler,
FLUX_ROLE_OWNER,
},
{
FLUX_MSGTYPE_REQUEST,
"job-manager.jobtap-query",
jobtap_query_handler,
FLUX_ROLE_OWNER,
},
{
FLUX_MSGTYPE_REQUEST,
"job-manager.disconnect",
disconnect_rpc,
0
},
{
FLUX_MSGTYPE_REQUEST,
"job-manager.stats-get",
stats_cb,
FLUX_ROLE_USER,
},
FLUX_MSGHANDLER_TABLE_END,
};
int mod_main (flux_t *h, int argc, char **argv)
{
flux_reactor_t *r = flux_get_reactor (h);
int rc = -1;
struct job_manager ctx;
flux_error_t error;
memset (&ctx, 0, sizeof (ctx));
ctx.h = h;
ctx.owner = getuid ();
if (!(ctx.active_jobs = job_hash_create ())
|| !(ctx.inactive_jobs = job_hash_create ())) {
flux_log_error (h, "error creating jobs hash");
goto done;
}
zhashx_set_destructor (ctx.active_jobs, job_destructor);
zhashx_set_duplicator (ctx.active_jobs, job_duplicator);
zhashx_set_destructor (ctx.inactive_jobs, job_destructor);
zhashx_set_duplicator (ctx.inactive_jobs, job_duplicator);
if (!(ctx.conf = conf_create (&ctx, &error))) {
flux_log (h, LOG_ERR, "config: %s", error.text);
goto done;
}
if (!(ctx.jobtap = jobtap_create (&ctx))) {
flux_log (h, LOG_ERR, "error creating jobtap interface");
goto done;
}
if (!(ctx.purge = purge_create (&ctx))) {
flux_log_error (h, "error creating purge context");
goto done;
}
if (!(ctx.queue = queue_create (&ctx))) {
flux_log_error (h, "error creating queue context");
goto done;
}
if (!(ctx.event = event_ctx_create (&ctx))) {
flux_log_error (h, "error creating event batcher");
goto done;
}
if (!(ctx.submit = submit_ctx_create (&ctx))) {
flux_log_error (h, "error creating submit interface");
goto done;
}
if (!(ctx.alloc = alloc_ctx_create (&ctx))) {
flux_log_error (h, "error creating scheduler interface");
goto done;
}
if (!(ctx.start = start_ctx_create (&ctx))) {
flux_log_error (h, "error creating exec interface");
goto done;
}
if (!(ctx.drain = drain_ctx_create (&ctx))) {
flux_log_error (h, "error creating drain interface");
goto done;
}
if (!(ctx.wait = wait_ctx_create (&ctx))) {
flux_log_error (h, "error creating wait interface");
goto done;
}
if (!(ctx.raise = raise_ctx_create (&ctx))) {
flux_log_error (h, "error creating raise interface");
goto done;
}
if (!(ctx.kill = kill_ctx_create (&ctx))) {
flux_log_error (h, "error creating kill interface");
goto done;
}
if (!(ctx.annotate = annotate_ctx_create (&ctx))) {
flux_log_error (h, "error creating annotate interface");
goto done;
}
if (!(ctx.journal = journal_ctx_create (&ctx))) {
flux_log_error (h, "error creating journal interface");
goto done;
}
if (!(ctx.update = update_ctx_create (&ctx))) {
flux_log_error (h, "error creating job update interface");
goto done;
}
if (flux_msg_handler_addvec (h, htab, &ctx, &ctx.handlers) < 0) {
flux_log_error (h, "flux_msghandler_add");
goto done;
}
if (restart_from_kvs (&ctx) < 0) // logs its own error messages
goto done;
if (flux_reactor_run (r, 0) < 0) {
flux_log_error (h, "flux_reactor_run");
goto done;
}
if (restart_save_state (&ctx) < 0) {
flux_log_error (h, "error saving job manager state to KVS");
goto done;
}
rc = 0;
done:
flux_msg_handler_delvec (ctx.handlers);
queue_destroy (ctx.queue);
purge_destroy (ctx.purge);
journal_ctx_destroy (ctx.journal);
annotate_ctx_destroy (ctx.annotate);
kill_ctx_destroy (ctx.kill);
raise_ctx_destroy (ctx.raise);
wait_ctx_destroy (ctx.wait);
drain_ctx_destroy (ctx.drain);
start_ctx_destroy (ctx.start);
alloc_ctx_destroy (ctx.alloc);
submit_ctx_destroy (ctx.submit);
event_ctx_destroy (ctx.event);
update_ctx_destroy (ctx.update);
/* job aux containers may call destructors in jobtap plugins, so destroy
* jobs before unloading plugins; but don't destroy job hashes until after.
*/
zhashx_purge (ctx.active_jobs);
zhashx_purge (ctx.inactive_jobs);
jobtap_destroy (ctx.jobtap);
conf_destroy (ctx.conf);
zhashx_destroy (&ctx.active_jobs);
zhashx_destroy (&ctx.inactive_jobs);
return rc;
}
/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/