Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin: add new external class for user/bank information #403

Closed
14 changes: 12 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ noinst_HEADERS = \
fairness/reader/data_reader_db.hpp \
fairness/writer/data_writer_base.hpp \
fairness/writer/data_writer_db.hpp \
fairness/writer/data_writer_stdout.hpp
fairness/writer/data_writer_stdout.hpp \
plugins/bank_info.hpp

fairness_libweighted_tree_la_SOURCES = \
fairness/account/account.cpp \
Expand Down Expand Up @@ -46,7 +47,8 @@ fairness_libweighted_tree_la_CXXFLAGS = \
TESTS = \
weighted_tree_test01.t \
data_reader_db_test01.t \
data_writer_db_test01.t
data_writer_db_test01.t \
user_bank_info_test01.t
check_PROGRAMS = $(TESTS)

TEST_EXTENSIONS = .t
Expand Down Expand Up @@ -93,6 +95,14 @@ data_writer_db_test01_t_LDADD = \
fairness/libweighted_tree.la \
common/libtap/libtap.la

user_bank_info_test01_t_SOURCES = \
plugins/test/user_bank_info_test01.cpp \
plugins/bank_info.cpp \
plugins/bank_info.hpp
user_bank_info_test01_t_CXXFLAGS = $(AM_CXXFLAGS) -I$(top_srcdir)
user_bank_info_test01_t_LDADD = \
common/libtap/libtap.la

noinst_PROGRAMS = \
cmd/flux-account-update-fshare \
cmd/flux-account-shares
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ jobtapdir = \
$(fluxlibdir)/job-manager/plugins/

jobtap_LTLIBRARIES = mf_priority.la
mf_priority_la_SOURCES = mf_priority.cpp
mf_priority_la_SOURCES = mf_priority.cpp bank_info.cpp
mf_priority_la_CPPFLAGS = -I$(top_srcdir)/src/plugins
mf_priority_la_LDFLAGS = $(fluxplugin_ldflags) -module
52 changes: 52 additions & 0 deletions src/plugins/bank_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/************************************************************\
* Copyright 2023 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
\************************************************************/

#include "bank_info.hpp"

user_bank_info* get_user_info (int userid,
char *bank,
std::map<int, std::map<std::string,
user_bank_info>> &users,
std::map<int, std::string> &users_def_bank)
{
std::map<std::string, user_bank_info>::iterator bank_it;

auto it = users.find (userid);
if (it == users.end ())
return NULL;

if (bank != NULL) {
bank_it = it->second.find (std::string (bank));
if (bank_it == it->second.end ())
return NULL;
} else {
bank = const_cast<char*> (users_def_bank[userid].c_str ());
bank_it = it->second.find (std::string (bank));
if (bank_it == it->second.end ())
return NULL;
}

return &bank_it->second;
}


bool check_map_for_dne_only (
std::map<int, std::map<std::string, user_bank_info>> &users,
std::map<int, std::string> &users_def_bank)
{
for (const auto& entry : users) {
auto def_bank_it = users_def_bank.find(entry.first);
if (def_bank_it != users_def_bank.end() &&
def_bank_it->second != "DNE")
return false;
}

return true;
}
52 changes: 52 additions & 0 deletions src/plugins/bank_info.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/************************************************************\
* Copyright 2023 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
\************************************************************/

// header file for the bank_info class

#ifndef BANK_INFO_H
#define BANK_INFO_H

#include <vector>
#include <string>
#include <map>
#include <iterator>

// all attributes are per-user/bank
class user_bank_info {
public:
std::string bank_name; // name of bank
double fairshare; // fair share value
int max_run_jobs; // max number of running jobs
int cur_run_jobs; // current number of running jobs
int max_active_jobs; // max number of active jobs
int cur_active_jobs; // current number of active jobs
std::vector<long int> held_jobs; // list of currently held job ID's
std::vector<std::string> queues; // list of accessible queues
int queue_factor; // priority factor associated with queue
int active; // active status
};

// get a user_bank_info object that points to user/bank
// information in users map; return NULL on failure
user_bank_info* get_user_info (int userid,
char *bank,
std::map<int,
std::map<std::string, user_bank_info>>
&users,
std::map<int, std::string> &users_def_bank);

// scan the users map and look at each user's default bank to see if any one
// of them have a valid bank (i.e one that is not "DNE"; if any of the users do
// do have a valid bank, return false)
bool check_map_for_dne_only (
std::map<int, std::map<std::string, user_bank_info>> &users,
std::map<int, std::string> &users_def_bank);

#endif // BANK_INFO_H
Loading
Loading