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

[experimental] plugn: add new bank_info class #401

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 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
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
51 changes: 51 additions & 0 deletions src/plugins/bank_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/************************************************************\
* 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"

int user_bank_lookup (int userid, char *bank)
{
auto it = users.find (userid);
if (it == users.end ()) {
return BANK_USER_NOT_FOUND;
}

// make sure user belongs to bank they specified; if no bank was passed in,
// look up their default bank
if (bank != NULL) {
auto bank_it = it->second.find (std::string (bank));
if (bank_it == it->second.end ())
return BANK_INVALID;
} else {
bank = const_cast<char*> (users_def_bank[userid].c_str ());
auto bank_it = it->second.find (std::string (bank));
if (bank_it == it->second.end ())
return BANK_NO_DEFAULT;
}

return BANK_SUCCESS;
}


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

auto it = users.find (userid);

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

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

// different codes to return as a result of looking up user/bank information:
//
// BANK_SUCCESS: we found an entry for the passed-in user/bank
// BANK_USER_NOT_FOUND: the user could not be found in the plugin map
// BANK_INVALID: the user specified a bank they don't belong to
// BANK_NO_DEFAULT: the user does not have a default bank in the plugin map
enum bank_info_codes {
BANK_SUCCESS,
BANK_USER_NOT_FOUND,
BANK_INVALID,
BANK_NO_DEFAULT
};

// these data structures are defined in the priority plugin
extern std::map<int, std::map<std::string, user_bank_info>> users;
extern std::map<int, std::string> users_def_bank;

// check if a user has an entry in the users map
int user_bank_lookup (int userid, char *bank);

// get a user_bank_info object that points to user/bank
// information in users map
user_bank_info get_user_info (int userid, char *bank);

#endif // BANK_INFO_H
Loading