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

src: remove flux_account_shares.cpp in favor of just using -t option with view-bank #471

Merged
merged 4 commits into from
Jul 30, 2024
Merged
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
32 changes: 16 additions & 16 deletions doc/guide/accounting-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,27 +252,27 @@ consists of the following tables:
| | share calculation |
+--------------------------+--------------------------------------------------+

To view all associations in a flux-accounting database, the ``flux
account-shares`` command will print this DB information in a hierarchical
format. An example is shown below:
To view all associations in a flux-accounting database, the ``view-bank``
command will print this DB information in a hierarchical format. An example is
shown below showing all associations under the root bank:

.. code-block:: console

$ flux account-shares
$ flux account view-bank root -t

Account Username RawShares RawUsage Fairshare
root 1 0
bank_A 1 0
bank_A user_1 1 0 0.5
bank_B 1 0
bank_B user_2 1 0 0.5
bank_B user_3 1 0 0.5
bank_C 1 0
bank_C_a 1 0
bank_C_a user_4 1 0 0.5
bank_C_b 1 0
bank_C_b user_5 1 0 0.5
bank_C_b user_6 1 0 0.5
root 1 0.0
bank_A 1 0.0
bank_A user_1 1 0.0 0.5
bank_B 1 0.0
bank_B user_2 1 0.0 0.5
bank_B user_3 1 0.0 0.5
bank_C 1 0.0
bank_C_a 1 0.0
bank_C_a user_4 1 0.0 0.5
bank_C_b 1 0.0
bank_C_b user_5 1 0.0 0.5
bank_C_b user_6 1 0.0 0.5


****************************
Expand Down
4 changes: 1 addition & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ accounting_test01_t_LDADD = \
$(JANSSON_LIBS)

noinst_PROGRAMS = \
cmd/flux-account-update-fshare \
cmd/flux-account-shares
cmd/flux-account-update-fshare

cmd_flux_account_update_fshare_SOURCES = cmd/flux_account_update_fshare.cpp

Expand Down Expand Up @@ -138,7 +137,6 @@ dist_fluxcmd_SCRIPTS = \
cmd/flux-account.py \
cmd/flux-account-update-fshare \
cmd/flux-account-priority-update.py \
cmd/flux-account-shares \
cmd/flux-account-pop-db.py \
cmd/flux-account-export-db.py \
cmd/flux-account-update-db.py \
Expand Down
56 changes: 44 additions & 12 deletions src/bindings/python/fluxacct/accounting/bank_subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,38 @@ def print_hierarchy(cur, bank, hierarchy_str, indent=""):
return hierarchy_str


def print_parsable_hierarchy(cur, bank, hierarchy_str, indent=""):
# look for all sub banks under this parent bank
select_stmt = "SELECT bank,shares,job_usage FROM bank_table WHERE parent_bank=?"
cur.execute(select_stmt, (bank,))
sub_banks = cur.fetchall()

if len(sub_banks) == 0:
# we've reached a bank with no sub banks, so print out every user
# under this bank
cur.execute(
"SELECT username,shares,job_usage,fairshare FROM association_table WHERE bank=?",
(bank,),
)
users = cur.fetchall()
if users:
for user in users:
hierarchy_str += (
f"{indent} {bank}|{user[0]}|{user[1]}|{user[2]}|{user[3]}\n"
)
else:
# continue traversing the hierarchy
for sub_bank in sub_banks:
hierarchy_str += (
f"{indent} {str(sub_bank[0])}||{str(sub_bank[1])}|{str(sub_bank[2])}\n"
)
hierarchy_str = print_parsable_hierarchy(
cur, sub_bank[0], hierarchy_str, indent + " "
)

return hierarchy_str


###############################################################
# #
# Subcommand Functions #
Expand Down Expand Up @@ -229,7 +261,7 @@ def add_bank(conn, bank, shares, parent_bank=""):
raise sqlite3.IntegrityError(f"bank {bank} already exists in bank_table")


def view_bank(conn, bank, tree=False, users=False):
def view_bank(conn, bank, tree=False, users=False, parsable=False):
cur = conn.cursor()
bank_str = ""
try:
Expand All @@ -241,18 +273,18 @@ def view_bank(conn, bank, tree=False, users=False):
else:
raise ValueError(f"bank {bank} not found in bank_table")

# print out the hierarchy view with the specified bank as the root of the tree
if tree is True:
# get specific information about bank passed in
cur.execute(
"SELECT bank,shares,job_usage FROM bank_table WHERE bank=?", (bank,)
)
parent_bank = cur.fetchall()
name = parent_bank[0][0]
shares = parent_bank[0][1]
usage = parent_bank[0][2]
name = result[0][1]
shares = result[0][4]
usage = result[0][5]

# create headers for the hierarchy string
if parsable is True:
# print out the database hierarchy starting with the bank passed in
hierarchy_str = "Bank|Username|RawShares|RawUsage|Fairshare\n"
hierarchy_str += f"{name}||{str(shares)}|{str(round(usage, 2))}\n"
hierarchy_str = print_parsable_hierarchy(cur, bank, hierarchy_str, "")
return hierarchy_str
if tree is True:
# print out the hierarchy view with the specified bank as the root of the tree
hierarchy_str = (
"Bank".ljust(20)
+ "Username".rjust(20)
Expand Down
1 change: 1 addition & 0 deletions src/cmd/flux-account-service.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def view_bank(self, handle, watcher, msg, arg):
msg.payload["bank"],
msg.payload["tree"],
msg.payload["users"],
msg.payload["parsable"],
)

payload = {"view_bank": val}
Expand Down
9 changes: 9 additions & 0 deletions src/cmd/flux-account.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ def add_view_bank_arg(subparsers):
help="list all potential users under bank",
metavar="USERS",
)
subparser_view_bank.add_argument(
"-P",
"--parsable",
action="store_const",
const=True,
help="list all sub banks in a parsable format with specified bank as root of tree",
metavar="PARSABLE",
)


def add_delete_bank_arg(subparsers):
Expand Down Expand Up @@ -617,6 +625,7 @@ def select_accounting_function(args, output_file, parser):
"bank": args.bank,
"tree": args.tree,
"users": args.users,
"parsable": args.parsable,
}
return_val = flux.Flux().rpc("accounting.view_bank", data).get()
elif args.func == "delete_bank":
Expand Down
78 changes: 0 additions & 78 deletions src/cmd/flux_account_shares.cpp

This file was deleted.

4 changes: 3 additions & 1 deletion t/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# This list is included in both TESTS and dist_check_SCRIPTS.
TESTSCRIPTS = \
t0000-sharness.t \
t1000-print-hierarchy.t \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this file isn't deleted, even though it's removed from the testsuite?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I forgot to delete this file. Thanks for catching that

t1001-mf-priority-basic.t \
t1002-mf-priority-small-no-tie.t \
t1003-mf-priority-small-tie.t \
Expand Down Expand Up @@ -36,6 +35,9 @@ TESTSCRIPTS = \
t1033-mf-priority-update-job.t \
t1034-mf-priority-config.t \
t1035-flux-account-scrub-old-jobs.t \
t1036-hierarchy-small-no-tie-db.t \
t1037-hierarchy-small-tie-db.t \
t1038-hierarchy-small-tie-all-db.t \
t5000-valgrind.t \
python/t1000-example.py \
python/t1001_db.py \
Expand Down
26 changes: 15 additions & 11 deletions t/expected/pop_db/db_hierarchy_base.expected
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
Account Username RawShares RawUsage Fairshare
root 1 0
A 1 0
A user1000 1 0 0.5
A user1001 1 0 0.5
A user1002 1 0 0.5
A user1003 1 0 0.5
A user1004 1 0 0.5
B 1 0
C 1 0
D 1 0
bank_id bank active parent_bank shares job_usage
1 root 1 1 0.0

Bank Username RawShares RawUsage Fairshare
root 1 0.0
A 1 0.0
A user1000 1 0.0 0.5
A user1001 1 0.0 0.5
A user1002 1 0.0 0.5
A user1003 1 0.0 0.5
A user1004 1 0.0 0.5
B 1 0.0
C 1 0.0
D 1 0.0

36 changes: 20 additions & 16 deletions t/expected/pop_db/db_hierarchy_new_users.expected
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
Account Username RawShares RawUsage Fairshare
root 1 0
A 1 0
A user1000 1 0 0.5
A user1001 1 0 0.5
A user1002 1 0 0.5
A user1003 1 0 0.5
A user1004 1 0 0.5
B 1 0
B user1005 1 0 0.5
B user1006 1 0 0.5
B user1007 1 0 0.5
B user1008 1 0 0.5
B user1009 1 0 0.5
C 1 0
D 1 0
bank_id bank active parent_bank shares job_usage
1 root 1 1 0.0

Bank Username RawShares RawUsage Fairshare
root 1 0.0
A 1 0.0
A user1000 1 0.0 0.5
A user1001 1 0.0 0.5
A user1002 1 0.0 0.5
A user1003 1 0.0 0.5
A user1004 1 0.0 0.5
B 1 0.0
B user1005 1 0.0 0.5
B user1006 1 0.0 0.5
B user1007 1 0.0 0.5
B user1008 1 0.0 0.5
B user1009 1 0.0 0.5
C 1 0.0
D 1 0.0

28 changes: 16 additions & 12 deletions t/expected/print_hierarchy/small_no_tie.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
Account Username RawShares RawUsage Fairshare
root 1000 133
account1 1000 121
account1 leaf.1.1 10000 100 0.285714
account1 leaf.1.2 1000 11 0.142857
account1 leaf.1.3 100000 10 0.428571
account2 100 11
account2 leaf.2.1 100000 8 0.714286
account2 leaf.2.2 10000 3 0.571429
account3 10 1
account3 leaf.3.1 100 0 1
account3 leaf.3.2 10 1 0.857143
bank_id bank active parent_bank shares job_usage
1 root 1 1000 133.0

Bank Username RawShares RawUsage Fairshare
root 1000 133.0
account1 1000 121.0
account1 leaf.1.1 10000 100.0 0.285714
account1 leaf.1.2 1000 11.0 0.142857
account1 leaf.1.3 100000 10.0 0.428571
account2 100 11.0
account2 leaf.2.1 100000 8.0 0.714286
account2 leaf.2.2 10000 3.0 0.571429
account3 10 1.0
account3 leaf.3.1 100 0.0 1.0
account3 leaf.3.2 10 1.0 0.857143

25 changes: 13 additions & 12 deletions t/expected/print_hierarchy/small_no_tie_parsable.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Account|Username|RawShares|RawUsage|Fairshare
root||1000|133
account1||1000|121
account1|leaf.1.1|10000|100|0.285714
account1|leaf.1.2|1000|11|0.142857
account1|leaf.1.3|100000|10|0.428571
account2||100|11
account2|leaf.2.1|100000|8|0.714286
account2|leaf.2.2|10000|3|0.571429
account3||10|1
account3|leaf.3.1|100|0|1
account3|leaf.3.2|10|1|0.857143
Bank|Username|RawShares|RawUsage|Fairshare
root||1000|133.0
account1||1000|121.0
account1|leaf.1.1|10000|100.0|0.285714
account1|leaf.1.2|1000|11.0|0.142857
account1|leaf.1.3|100000|10.0|0.428571
account2||100|11.0
account2|leaf.2.1|100000|8.0|0.714286
account2|leaf.2.2|10000|3.0|0.571429
account3||10|1.0
account3|leaf.3.1|100|0.0|1.0
account3|leaf.3.2|10|1.0|0.857143

Loading
Loading