-
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
Draft
Loxeris
wants to merge
1
commit into
DIRACGrid:integration
Choose a base branch
from
Loxeris:read-adapter-rss
base: integration
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+472
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ( | ||
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]: | ||
| """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: | ||
| 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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", | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.