Skip to content

Commit

Permalink
Merge pull request #437 from cmoussa1/issue#436
Browse files Browse the repository at this point in the history
plugin: add `max_nodes` as an attribute per-association in plugin
  • Loading branch information
mergify[bot] authored Apr 3, 2024
2 parents daa7c80 + aa4ba6b commit b6f7a7e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/cmd/flux-account-priority-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def bulk_update(path):
for row in cur.execute(
"""SELECT userid, bank, default_bank,
fairshare, max_running_jobs, max_active_jobs,
queues, active, projects, default_project
queues, active, projects, default_project, max_nodes
FROM association_table"""
):
# create a JSON payload with the results of the query
Expand All @@ -92,6 +92,7 @@ def bulk_update(path):
"active": int(row[7]),
"projects": str(row[8]),
"def_project": str(row[9]),
"max_nodes": int(row[10]),
}
bulk_user_data.append(single_user_data)

Expand Down
3 changes: 2 additions & 1 deletion src/plugins/accounting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ json_t* Association::to_json () const

// 'o' steals the reference for both held_job_ids and user_queues
json_t *u = json_pack ("{s:s, s:f, s:i, s:i, s:i, s:i,"
" s:o, s:o, s:i, s:o, s:s, s:i}",
" s:o, s:o, s:i, s:o, s:s, s:i, s:i}",
"bank_name", bank_name.c_str (),
"fairshare", fairshare,
"max_run_jobs", max_run_jobs,
Expand All @@ -98,6 +98,7 @@ json_t* Association::to_json () const
"queue_factor", queue_factor,
"projects", user_projects,
"def_project", def_project.c_str (),
"max_nodes", max_nodes,
"active", active);

if (!u)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/accounting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Association {
int active; // active status
std::vector<std::string> projects; // list of accessible projects
std::string def_project; // default project
int max_nodes; // max num nodes across all running jobs

// methods
json_t* to_json () const; // convert object to JSON string
Expand Down
10 changes: 7 additions & 3 deletions src/plugins/mf_priority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern "C" {
#include <cinttypes>
#include <vector>
#include <sstream>
#include <cstdint>

// custom bank_info class file
#include "accounting.hpp"
Expand Down Expand Up @@ -152,6 +153,7 @@ static void add_special_association (flux_plugin_t *p, flux_t *h, int userid)
a->cur_active_jobs = 0;
a->active = 1;
a->held_jobs = std::vector<long int>();
a->max_nodes = INT16_MAX;

if (flux_jobtap_job_aux_set (p,
FLUX_JOBTAP_CURRENT_JOB,
Expand Down Expand Up @@ -207,7 +209,7 @@ static void rec_update_cb (flux_t *h,
void *arg)
{
char *bank, *def_bank, *assoc_queues, *assoc_projects, *def_project = NULL;
int uid, max_running_jobs, max_active_jobs = 0;
int uid, max_running_jobs, max_active_jobs, max_nodes = 0;
double fshare = 0.0;
json_t *data, *jtemp = NULL;
json_error_t error;
Expand All @@ -234,7 +236,7 @@ static void rec_update_cb (flux_t *h,

if (json_unpack_ex (el, &error, 0,
"{s:i, s:s, s:s, s:F, s:i,"
" s:i, s:s, s:i, s:s, s:s}",
" s:i, s:s, s:i, s:s, s:s, s:i}",
"userid", &uid,
"bank", &bank,
"def_bank", &def_bank,
Expand All @@ -244,7 +246,8 @@ static void rec_update_cb (flux_t *h,
"queues", &assoc_queues,
"active", &active,
"projects", &assoc_projects,
"def_project", &def_project) < 0)
"def_project", &def_project,
"max_nodes", &max_nodes) < 0)
flux_log (h, LOG_ERR, "mf_priority unpack: %s", error.text);

Association *b;
Expand All @@ -256,6 +259,7 @@ static void rec_update_cb (flux_t *h,
b->max_active_jobs = max_active_jobs;
b->active = active;
b->def_project = def_project;
b->max_nodes = max_nodes;

// split queues comma-delimited string and add it to b->queues vector
b->queues.clear ();
Expand Down
12 changes: 8 additions & 4 deletions src/plugins/test/accounting_test01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ void add_user_to_map (
a.queue_factor,
a.active,
a.projects,
a.def_project
a.def_project,
a.max_nodes
};
}

Expand All @@ -65,8 +66,10 @@ void add_user_to_map (
void initialize_map (
std::map<int, std::map<std::string, Association>> &users)
{
Association user1 = {"bank_A", 0.5, 5, 0, 7, 0, {}, {}, 0, 1, {"*"}, "*"};
Association user2 = {"bank_A", 0.5, 5, 0, 7, 0, {}, {}, 0, 1, {"*"}, "*"};
Association user1 = {"bank_A", 0.5, 5, 0, 7, 0, {},
{}, 0, 1, {"*"}, "*", 2147483647};
Association user2 = {"bank_A", 0.5, 5, 0, 7, 0, {},
{}, 0, 1, {"*"}, "*", 2147483647};

add_user_to_map (users, 1001, "bank_A", user1);
users_def_bank[1001] = "bank_A";
Expand Down Expand Up @@ -267,7 +270,8 @@ static void test_check_map_dne_true ()
users.clear ();
users_def_bank.clear ();

Association tmp_user = {"DNE", 0.5, 5, 0, 7, 0, {}, {}, 0, 1, {"*"}, "*"};
Association tmp_user = {"DNE", 0.5, 5, 0, 7, 0, {},
{}, 0, 1, {"*"}, "*", 2147483647};
add_user_to_map (users, 9999, "DNE", tmp_user);
users_def_bank[9999] = "DNE";

Expand Down
2 changes: 2 additions & 0 deletions t/expected/plugin_state/internal_state_1.expected
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"*"
],
"def_project": "*",
"max_nodes": 2147483647,
"active": 1
},
{
Expand All @@ -36,6 +37,7 @@
"*"
],
"def_project": "*",
"max_nodes": 2147483647,
"active": 1
}
]
Expand Down
3 changes: 3 additions & 0 deletions t/expected/plugin_state/internal_state_3.expected
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"*"
],
"def_project": "*",
"max_nodes": 2147483647,
"active": 1
},
{
Expand All @@ -36,6 +37,7 @@
"*"
],
"def_project": "*",
"max_nodes": 2147483647,
"active": 1
}
]
Expand All @@ -61,6 +63,7 @@
"*"
],
"def_project": "A",
"max_nodes": 10,
"active": 1
}
]
Expand Down
3 changes: 2 additions & 1 deletion t/t1019-mf-priority-info-fetch.t
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ test_expect_success 'add another user to flux-accounting DB and send it to plugi
--userid=1002 \
--bank=account3 \
--queues="bronze" \
--projects="A,B" &&
--projects="A,B" \
--max-nodes=10 &&
flux account-priority-update -p $(pwd)/FluxAccountingTest.db
'

Expand Down

0 comments on commit b6f7a7e

Please sign in to comment.