Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Radu Carpa committed Nov 21, 2023
1 parent 31dbba4 commit 2d01d1b
Show file tree
Hide file tree
Showing 6 changed files with 346 additions and 71 deletions.
22 changes: 14 additions & 8 deletions lib/rucio/api/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Interface for the requests abstraction layer
"""

from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional

from rucio.api import permission
from rucio.common import exception
Expand Down Expand Up @@ -219,19 +219,25 @@ def list_requests_history(src_rses, dst_rses, states, issuer, vo='def', offset=N
yield api_update_return_dict(req, session=session)


@stream_session
def get_request_stats(state, issuer, vo='def', *, session: "Session"):
@read_session
def get_request_metrics(src_rse: Optional[str], dst_rse: Optional[str], activity: Optional[str], issuer, vo='def', *, session: "Session"):
"""
Get statistics of requests in a specific state grouped by source RSE, destination RSE, and activity.
:param state: request state.
:param src_rse: source RSE.
:param dst_rse: destination RSE.
:param activity: activity
:param issuer: Issuing account as a string.
:param session: The database session in use.
"""
src_rse_id = None
if src_rse:
src_rse_id = get_rse_id(rse=src_rse, vo=vo, session=session)
dst_rse_id = None
if dst_rse:
dst_rse_id = get_rse_id(rse=dst_rse, vo=vo, session=session)
kwargs = {'issuer': issuer}
if not permission.has_permission(issuer=issuer, vo=vo, action='get_request_stats', kwargs=kwargs, session=session):
if not permission.has_permission(issuer=issuer, vo=vo, action='get_request_metrics', kwargs=kwargs, session=session):
raise exception.AccessDenied(f'{issuer} cannot get request statistics')

for req in request.get_request_stats(state, session=session):
req = req.to_dict()
yield api_update_return_dict(req, session=session)
return request.get_request_metrics(dest_rse_id=dst_rse_id, src_rse_id=src_rse_id, activity=activity, session=session)
13 changes: 13 additions & 0 deletions lib/rucio/core/permission/atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def has_permission(issuer, action, kwargs, *, session: "Optional[Session]" = Non
'set_rse_usage': perm_set_rse_usage,
'set_rse_limits': perm_set_rse_limits,
'get_request_by_did': perm_get_request_by_did,
'get_request_metrics': perm_get_request_metrics,
'cancel_request': perm_cancel_request,
'get_next': perm_get_next,
'set_local_account_limit': perm_set_local_account_limit,
Expand Down Expand Up @@ -940,6 +941,18 @@ def perm_get_request_by_did(issuer, kwargs, *, session: "Optional[Session]" = No
return True


def perm_get_request_metrics(issuer, kwargs, *, session: "Optional[Session]" = None):
"""
Checks if an account can get the request stats
:param issuer: Account identifier which issues the command.
:param kwargs: List of arguments for the action.
:param session: The DB session to use
:returns: True if account is allowed, otherwise False
"""
return _is_root(issuer) or has_account_attribute(account=issuer, key='admin', session=session)


def perm_cancel_request(issuer, kwargs, *, session: "Optional[Session]" = None):
"""
Checks if an account can cancel a request.
Expand Down
Loading

0 comments on commit 2d01d1b

Please sign in to comment.