Skip to content

Commit

Permalink
plugin_query: add projects, def_project
Browse files Browse the repository at this point in the history
Add the projects and def_project fields to the list of information returned
for each association in the plugin.query callback.

Add the projects and def_project key-value pairs to the expected files for
t1019-mf-priority-info-fetch.t.
  • Loading branch information
cmoussa1 committed Dec 7, 2022
1 parent ffae2ba commit d3cc570
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 8 deletions.
48 changes: 45 additions & 3 deletions src/plugins/mf_priority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,27 +273,69 @@ static json_t *add_held_jobs (
}


/*
* Add projects to a JSON array to be added to a bank_info JSON object.
*/
static json_t *add_projects (
const std::pair<std::string, struct bank_info> &b)
{
json_t *projects = NULL;

// add any projects to a JSON array
if (!(projects = json_array ()))
goto error;

for (auto const &j : b.second.projects) {
}

for (auto const &j : b.second.projects) {
json_t *project = json_string (j.c_str ());

if (!project)
goto error;

if (json_array_append_new (projects, project) < 0) {
json_decref (project);
goto error;
}
}

return projects;
error:
json_decref (projects);
return NULL;
}


/*
* Create a JSON object for a bank that a user belongs to.
*/
static json_t *pack_bank_info_object (
const std::pair<std::string, struct bank_info> &b)
{
json_t *bank_info, *held_jobs = NULL;
json_t *bank_info, *held_jobs, *projects = NULL;

held_jobs = add_held_jobs (b);
if (held_jobs == NULL)
goto error;

if (!(bank_info = json_pack ("{s:s, s:f, s:i, s:i, s:i, s:i, s:o, s:i}",
projects = add_projects (b);
if (projects == NULL)
goto error;

if (!(bank_info = json_pack ("{s:s, s:f, s:i, s:i, s:i, "
" s:i, s:o, s:i, s:o, s:s}",
"bank", b.first.c_str (),
"fairshare", b.second.fairshare,
"max_run_jobs", b.second.max_run_jobs,
"cur_run_jobs", b.second.cur_run_jobs,
"max_active_jobs", b.second.max_active_jobs,
"cur_active_jobs", b.second.cur_active_jobs,
"held_jobs", held_jobs,
"active", b.second.active))) {
"active", b.second.active,
"projects", projects,
"def_project",
b.second.def_project.c_str ()))) {
goto error;
}

Expand Down
12 changes: 10 additions & 2 deletions t/expected/plugin_state/internal_state_1.expected
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
"max_active_jobs": 7,
"cur_active_jobs": 0,
"held_jobs": [],
"active": 1
"active": 1,
"projects": [
"*"
],
"def_project": "*"
},
{
"bank": "account2",
Expand All @@ -20,7 +24,11 @@
"max_active_jobs": 7,
"cur_active_jobs": 0,
"held_jobs": [],
"active": 1
"active": 1,
"projects": [
"*"
],
"def_project": "*"
}
]
}
Expand Down
18 changes: 15 additions & 3 deletions t/expected/plugin_state/internal_state_3.expected
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
"max_active_jobs": 7,
"cur_active_jobs": 0,
"held_jobs": [],
"active": 1
"active": 1,
"projects": [
"*"
],
"def_project": "*"
},
{
"bank": "account2",
Expand All @@ -20,7 +24,11 @@
"max_active_jobs": 7,
"cur_active_jobs": 0,
"held_jobs": [],
"active": 1
"active": 1,
"projects": [
"*"
],
"def_project": "*"
}
]
},
Expand All @@ -35,7 +43,11 @@
"max_active_jobs": 7,
"cur_active_jobs": 0,
"held_jobs": [],
"active": 1
"active": 1,
"projects": [
"*"
],
"def_project": "*"
}
]
}
Expand Down

0 comments on commit d3cc570

Please sign in to comment.