Skip to content

Commit 6d5f9d0

Browse files
authored
Merge pull request #1105 from grondo/expiration-update
resource: support resource expiration updates
2 parents 7d63065 + 25c4953 commit 6d5f9d0

File tree

2 files changed

+72
-4
lines changed

2 files changed

+72
-4
lines changed

resource/modules/resource_match.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,13 +1236,15 @@ static void update_resource (flux_future_t *f, void *arg)
12361236
int rc = -1;
12371237
const char *up = NULL;
12381238
const char *down = NULL;
1239+
double expiration = -1.;
12391240
json_t *resources = NULL;
12401241
std::shared_ptr<resource_ctx_t> ctx = getctx ((flux_t *)arg);
12411242

1242-
if ( (rc = flux_rpc_get_unpack (f, "{s?:o s?:s s?:s}",
1243+
if ( (rc = flux_rpc_get_unpack (f, "{s?:o s?:s s?:s s?:F}",
12431244
"resources", &resources,
12441245
"up", &up,
1245-
"down", &down)) < 0) {
1246+
"down", &down,
1247+
"expiration", &expiration)) < 0) {
12461248
flux_log_error (ctx->h, "%s: exiting due to resource.acquire failure",
12471249
__FUNCTION__);
12481250
flux_reactor_stop (flux_get_reactor (ctx->h));
@@ -1252,6 +1254,12 @@ static void update_resource (flux_future_t *f, void *arg)
12521254
flux_log_error (ctx->h, "%s: update_resource_db", __FUNCTION__);
12531255
goto done;
12541256
}
1257+
if (expiration >= 0.) {
1258+
/* Update graph duration:
1259+
*/
1260+
ctx->db->metadata.graph_duration.graph_end =
1261+
std::chrono::system_clock::from_time_t ((time_t) expiration);
1262+
}
12551263
for (auto &kv : ctx->notify_msgs) {
12561264
if ( (rc += flux_respond (ctx->h, kv.second->get_msg (), NULL)) < 0) {
12571265
flux_log_error (ctx->h, "%s: flux_respond", __FUNCTION__);

t/t4011-match-duration.t

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ test_description='Test that parent duration is inherited according to RFC14'
77
#
88
# test_under_flux is under sharness.d/
99
#
10-
test_under_flux 1
10+
test_under_flux 2
1111

12+
flux setattr log-stderr-level 1
1213
export FLUX_URI_RESOLVE_LOCAL=t
1314

1415
# Ensure fluxion modules are loaded under flux-alloc(1)
@@ -34,6 +35,35 @@ test_expect_success 'load fluxion modules in parent instance' '
3435
load_qmanager &&
3536
test_debug "flux dmesg -H | grep version"
3637
'
38+
# Usage: job_manager_get_R ID
39+
# This needs to be a shell script since it will be run under flux-proxy(1):
40+
cat <<'EOF' >job_manager_get_R
41+
#!/bin/sh
42+
flux python -c \
43+
"import flux; \
44+
payload = {\"id\":$(flux job id $1),\"attrs\":[\"R\"]}; \
45+
print(flux.Flux().rpc(\"job-manager.getattr\", payload).get_str()) \
46+
"
47+
EOF
48+
chmod +x job_manager_get_R
49+
50+
export PATH=$(pwd):$PATH
51+
52+
subinstance_get_R() {
53+
flux proxy $1 flux kvs get resource.R
54+
}
55+
subinstance_get_expiration() {
56+
subinstance_get_R $1 | jq .execution.expiration
57+
}
58+
# Usage: subinstance_get_duration ID JOBID
59+
subinstance_get_job_duration() {
60+
flux proxy $1 job_manager_get_R $2 |
61+
jq '.R.execution | .expiration - .starttime'
62+
}
63+
subinstance_get_job_expiration() {
64+
flux proxy $1 job_manager_get_R $2 | jq '.R.execution.expiration'
65+
}
66+
3767
test_expect_success HAVE_JQ 'parent expiration is inherited when duration=0' '
3868
cat >get_R.sh <<-EOT &&
3969
#!/bin/sh
@@ -59,8 +89,38 @@ test_expect_success HAVE_JQ 'parent expiration is inherited when duration=0' '
5989
echo $exp2 | jq ". == $expiration" &&
6090
flux shutdown --quiet $jobid
6191
'
92+
# Check if running job updates are supported:
93+
id=$(flux submit sleep inf)
94+
flux update $id duration=1m && test_set_prereq FLUX_UPDATE_RUNNING
95+
flux cancel $id
96+
97+
test_expect_success FLUX_UPDATE_RUNNING \
98+
'expiration update is detected by subinstance scheduler' '
99+
id=$(flux alloc --bg -t5m -n2) &&
100+
exp1=$(subinstance_get_expiration $id) &&
101+
test_debug "echo instance expiration is $exp1" &&
102+
id1=$(flux proxy $id flux submit sleep 300) &&
103+
duration1=$(subinstance_get_job_duration $id $id1) &&
104+
test_debug "echo initial duration of subinstance job1 is $duration1" &&
105+
echo $duration1 | jq -e ". < 300" &&
106+
test_debug "echo updating duration of alloc job +5m" &&
107+
flux update $id duration=+5m &&
108+
test_debug "echo waiting for resource-update event" &&
109+
flux proxy $id flux kvs eventlog wait-event -vt 30 \
110+
resource.eventlog resource-update &&
111+
exp2=$(subinstance_get_expiration $id) &&
112+
test_debug "echo expiration updated from $exp1 to $exp2" &&
113+
echo $exp2 | jq -e ". == $exp1 + 300" &&
114+
id2=$(flux proxy $id flux submit sleep 300) &&
115+
duration2=$(subinstance_get_job_duration $id $id2) &&
116+
test_debug "echo duration of subinstance job2 is $duration2" &&
117+
echo $duration2 | jq -e ". > 300" &&
118+
flux proxy $id flux cancel --all &&
119+
flux shutdown --quiet $id
120+
'
62121
test_expect_success 'unload fluxion modules' '
63122
remove_qmanager &&
64-
remove_resource
123+
remove_resource &&
124+
flux module load sched-simple
65125
'
66126
test_done

0 commit comments

Comments
 (0)