-
Notifications
You must be signed in to change notification settings - Fork 190
feat: add RSS read adapter #8733
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
base: integration
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| """Response translation for the read adapter module. | ||
|
|
||
| This module translates responses from diracx Pydantic models to legacy format. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Dict | ||
|
|
||
| from diracx.core.models.rss import ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it working knowing that we get results from autorest models? |
||
| AllowedStatus, | ||
| BannedStatus, | ||
| ComputeElementStatus, | ||
| FTSStatus, | ||
| SiteStatus, | ||
| StorageElementStatus, | ||
| ) | ||
|
|
||
|
|
||
| def translate_storage_element_status( | ||
| response: dict[str, StorageElementStatus], | ||
| ) -> list[tuple]: | ||
| """Translate storage element status from diracx format to legacy format. | ||
|
|
||
| Args: | ||
| response: Dictionary of storage element names to StorageElementStatus | ||
|
|
||
| Returns: | ||
| List of tuples in legacy format: (name, element_type, status_type, status, vo) | ||
|
|
||
| """ | ||
| legacy_format = [] | ||
| for name, status in response.items(): | ||
| legacy_format.append( | ||
| ( | ||
| name, | ||
| "StorageElement", | ||
| "ReadAccess", | ||
| _translate_resource_status(status.read), | ||
| None, | ||
| ) | ||
| ) | ||
| legacy_format.append( | ||
| ( | ||
| name, | ||
| "StorageElement", | ||
| "WriteAccess", | ||
| _translate_resource_status(status.write), | ||
| None, | ||
| ) | ||
| ) | ||
| legacy_format.append( | ||
| ( | ||
| name, | ||
| "StorageElement", | ||
| "CheckAccess", | ||
| _translate_resource_status(status.check), | ||
| None, | ||
| ) | ||
| ) | ||
| legacy_format.append( | ||
| ( | ||
| name, | ||
| "StorageElement", | ||
| "RemoveAccess", | ||
| _translate_resource_status(status.remove), | ||
| None, | ||
| ) | ||
| ) | ||
|
|
||
| return legacy_format | ||
|
|
||
|
|
||
| def translate_computing_element_status( | ||
| response: dict[str, ComputeElementStatus], | ||
| ) -> list[tuple]: | ||
| """Translate computing element status from diracx format to legacy format. | ||
|
|
||
| Args: | ||
| response: Dictionary of computing element names to ComputeElementStatus | ||
|
|
||
| Returns: | ||
| List of tuples in legacy format: (name, element_type, status_type, status, vo) | ||
|
|
||
| """ | ||
| legacy_format = [] | ||
| for name, status in response.items(): | ||
| legacy_format.append( | ||
| ( | ||
| name, | ||
| "ComputeElement", | ||
| "all", | ||
| _translate_resource_status(status.all), | ||
| None, | ||
| ) | ||
| ) | ||
| return legacy_format | ||
|
|
||
|
|
||
| def translate_fts_status(response: dict[str, FTSStatus]) -> list[tuple]: | ||
| """Translate FTS server status from diracx format to legacy format. | ||
|
|
||
| Args: | ||
| response: Dictionary of FTS server names to FTSStatus | ||
|
|
||
| Returns: | ||
| List of tuples in legacy format: (name, element_type, status_type, status, vo) | ||
|
|
||
| """ | ||
| legacy_format = [] | ||
| for name, status in response.items(): | ||
| legacy_format.append( | ||
| ( | ||
| name, | ||
| "FTS", | ||
| "all", | ||
| _translate_resource_status(status.all), | ||
| None, | ||
| ) | ||
| ) | ||
| return legacy_format | ||
|
|
||
|
|
||
| def translate_site_status(response: dict[str, SiteStatus]) -> list[tuple]: | ||
| """Translate site status from diracx format to legacy format. | ||
|
|
||
| Args: | ||
| response: Dictionary of site names to SiteStatus | ||
|
|
||
| Returns: | ||
| List of tuples in legacy format: (site, status) | ||
|
|
||
| """ | ||
| legacy_format = [] | ||
| for name, status in response.items(): | ||
| legacy_format.append((name, _translate_resource_status(status.all))) | ||
| return legacy_format | ||
|
|
||
|
|
||
| def _translate_resource_status(status: AllowedStatus | BannedStatus) -> str: | ||
| """Translate a single resource status from diracx format to legacy format. | ||
|
|
||
| Args: | ||
| status: ResourceStatus (AllowedStatus or BannedStatus) | ||
|
|
||
| Returns: | ||
| Legacy status string - only "Active" or "Banned" as per DIRAC streamlining | ||
|
|
||
| """ | ||
| if isinstance(status, AllowedStatus): | ||
| # DIRAC is being streamlined to only use Active/Banned states | ||
| # All allowed statuses (including Degraded) are mapped to Active | ||
| return "Active" | ||
| else: # BannedStatus | ||
| # All banned statuses are mapped to Banned | ||
| return "Banned" | ||
|
Comment on lines
+140
to
+156
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @HeloiseJoffe is going to make a small utility that you will be able to reuse. |
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about merging |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """RSS API calling and apply translation for the read adapter module.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from DIRAC.Core.Security.DiracX import DiracXClient | ||
|
|
||
| from .ResponseTranslation import ( | ||
| translate_computing_element_status, | ||
| translate_fts_status, | ||
| translate_site_status, | ||
| translate_storage_element_status, | ||
| ) | ||
|
|
||
|
|
||
| def get_storage_element_status() -> list[tuple]: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you would just need to have 1 function that would have almost the same form as |
||
| """Get storage element status from the RSS API and translate to legacy format. | ||
|
|
||
| Returns: | ||
| List of tuples in legacy format: (name, element_type, status_type, status, vo) | ||
|
|
||
| """ | ||
| with DiracXClient() as client: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you pass the client as an argument of the functions? So that a same one can be reused if needed |
||
| response = client.rss.get_storage_status() | ||
| return translate_storage_element_status(response) | ||
|
|
||
|
|
||
| def get_computing_element_status() -> list[tuple]: | ||
| """Get computing element status from the RSS API and translate to legacy format. | ||
|
|
||
| Returns: | ||
| List of tuples in legacy format: (name, element_type, status_type, status, vo) | ||
|
|
||
| """ | ||
| with DiracXClient() as client: | ||
| response = client.rss.get_compute_status() | ||
| return translate_computing_element_status(response) | ||
|
|
||
|
|
||
| def get_fts_status() -> list[tuple]: | ||
| """Get merged FTS server status from all VOs. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why "merged"? |
||
|
|
||
| Returns: | ||
| List of tuples in legacy format: (name, element_type, status_type, status, vo) | ||
|
|
||
| """ | ||
| with DiracXClient() as client: | ||
| response = client.rss.get_fts_status() | ||
| return translate_fts_status(response) | ||
|
|
||
|
|
||
| def get_site_status() -> list[tuple]: | ||
| """Get site status from the RSS API and translate to legacy format. | ||
|
|
||
| Returns: | ||
| List of tuples in legacy format: (site, status) | ||
|
|
||
| """ | ||
| with DiracXClient() as client: | ||
| response = client.rss.get_site_status() | ||
| return translate_site_status(response) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't add In this context, I think you can get rid of this |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| """Read adapter module for translating diracx RSS API responses to legacy format. | ||
|
|
||
| This module provides functionality to: | ||
| - Call diracx RSS API endpoints and translate the outputs | ||
| - Translate responses from new diracx format to legacy format | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from .ResponseTranslation import ( | ||
| translate_computing_element_status, | ||
| translate_fts_status, | ||
| translate_site_status, | ||
| translate_storage_element_status, | ||
| ) | ||
| from .Statuses import ( | ||
| get_computing_element_status, | ||
| get_fts_status, | ||
| get_site_status, | ||
| get_storage_element_status, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "get_computing_element_status", | ||
| "get_fts_status", | ||
| "get_site_status", | ||
| "get_storage_element_status", | ||
| "translate_computing_element_status", | ||
| "translate_fts_status", | ||
| "translate_site_status", | ||
| "translate_storage_element_status", | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some code de-duplication that can be achieved in this module, at the same time maybe reducing readability. Up to you.