Skip to content

Commit

Permalink
Rules: Listing replication rules returns size info rucio#5978
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwaizer authored and bari12 committed Aug 11, 2023
1 parent 90283c3 commit 9d43293
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion bin/rucio
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,7 @@ def list_rules(args):
'%s[%d/%d/%d]' % (rule['state'], rule['locks_ok_cnt'], rule['locks_replicating_cnt'], rule['locks_stuck_cnt']),
rule['rse_expression'],
rule['copies'],
sizefmt(rule['bytes'], args.human) if rule['bytes'] is not None else 'N/A',
rule['expires_at'],
rule['created_at'],
sep=',')
Expand All @@ -1490,9 +1491,10 @@ def list_rules(args):
'%s[%d/%d/%d]' % (rule['state'], rule['locks_ok_cnt'], rule['locks_replicating_cnt'], rule['locks_stuck_cnt']),
rule['rse_expression'],
rule['copies'],
sizefmt(rule['bytes'], args.human) if rule['bytes'] is not None else 'N/A',
rule['expires_at'],
rule['created_at']])
print(tabulate(table, tablefmt='simple', headers=['ID', 'ACCOUNT', 'SCOPE:NAME', 'STATE[OK/REPL/STUCK]', 'RSE_EXPRESSION', 'COPIES', 'EXPIRES (UTC)', 'CREATED (UTC)'], disable_numparse=True))
print(tabulate(table, tablefmt='simple', headers=['ID', 'ACCOUNT', 'SCOPE:NAME', 'STATE[OK/REPL/STUCK]', 'RSE_EXPRESSION', 'COPIES', 'SIZE', 'EXPIRES (UTC)', 'CREATED (UTC)'], disable_numparse=True))
return SUCCESS


Expand Down
14 changes: 12 additions & 2 deletions lib/rucio/core/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,16 @@ def list_rules(filters={}, *, session: "Session"):
:raises: RucioException
"""

stmt = select(models.ReplicationRule)
stmt = select(
models.ReplicationRule,
models.DataIdentifier.bytes
).join(
models.DataIdentifier,
and_(
models.ReplicationRule.scope == models.DataIdentifier.scope,
models.ReplicationRule.name == models.DataIdentifier.name
)
)
if filters:
for (key, value) in filters.items():
if key in ['account', 'scope']:
Expand Down Expand Up @@ -750,8 +759,9 @@ def list_rules(filters={}, *, session: "Session"):
stmt = stmt.where(getattr(models.ReplicationRule, key) == value)

try:
for rule in session.execute(stmt).yield_per(5).scalars():
for rule, data_identifier_bytes in session.execute(stmt).yield_per(5):
d = rule.to_dict()
d['bytes'] = data_identifier_bytes
yield d
except StatementError:
raise RucioException('Badly formatted input (IDs?)')
Expand Down

0 comments on commit 9d43293

Please sign in to comment.