Skip to content

Commit

Permalink
Rules: Correct rule for file query to include bytes #6348
Browse files Browse the repository at this point in the history
  • Loading branch information
voetberg authored and bari12 committed Mar 15, 2024
1 parent 7537063 commit 145fac0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/rucio/core/rule.py
Expand Up @@ -1084,24 +1084,29 @@ def list_associated_rules_for_file(
:param session: The database session in use.
:raises: RucioException
"""

rucio.core.did.get_did(scope=scope, name=name, session=session) # Check if the did acually exists
stmt = select(
models.ReplicationRule
models.ReplicationRule,
models.DataIdentifier.bytes
).distinct(
).join(
models.ReplicaLock,
models.ReplicationRule.id == models.ReplicaLock.rule_id
).join(
models.DataIdentifier,
and_(models.ReplicationRule.scope == models.DataIdentifier.scope,
models.ReplicationRule.name == models.DataIdentifier.name)
).with_hint(
models.ReplicaLock, 'INDEX(LOCKS LOCKS_PK)', 'oracle'
).where(
and_(models.ReplicaLock.scope == scope,
models.ReplicaLock.name == name)
)

try:
for result in session.execute(stmt).yield_per(5):
yield result[0].to_dict()
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 as exc:
raise RucioException('Badly formatted input (IDs?)') from exc

Expand Down
15 changes: 15 additions & 0 deletions tests/test_rule.py
Expand Up @@ -1381,6 +1381,21 @@ def test_list_rules_by_did(self, mock_scope, did_factory, jdoe_account, rucio_cl
assert rule_id_1 in ids
assert rule_id_2 in ids

def test_list_rules_by_name(self, mock_scope, did_factory, jdoe_account, rucio_client):
""" NAME (CLIENT): List Replication Rules per NAME """
files = create_files(1, mock_scope, self.rse1_id)
dataset = did_factory.random_dataset_did()
add_did(did_type=DIDType.DATASET, account=jdoe_account, **dataset)
attach_dids(dids=files, account=jdoe_account, **dataset)

rule_id_1 = add_rule(dids=[dataset], account=jdoe_account, copies=1, rse_expression=self.rse1, grouping='NONE', weight='fakeweight', lifetime=None, locked=False, subscription_id=None)[0]
rule_id_2 = add_rule(dids=[dataset], account=jdoe_account, copies=1, rse_expression=self.rse2, grouping='NONE', weight='fakeweight', lifetime=None, locked=False, subscription_id=None)[0]
ret = rucio_client.list_associated_rules_for_file(scope=mock_scope.external, name=files[0]['name'])
ids = [rule['id'] for rule in ret]

assert rule_id_1 in ids
assert rule_id_2 in ids

def test_get_rule(self, mock_scope, did_factory, jdoe_account):
""" REPLICATION RULE (CLIENT): Get Replication Rule by id """
activity = get_schema_value('ACTIVITY')['enum'][0]
Expand Down

0 comments on commit 145fac0

Please sign in to comment.