-
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
2
commits 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.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
190 changes: 190 additions & 0 deletions
190
src/DIRAC/ResourceStatusSystem/Client/RssReadAdapter.py
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,190 @@ | ||
| """RSS API calling and translation for the read adapter module. | ||
|
|
||
| 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 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, | ||
| ) | ||
|
|
||
| from DIRAC.Core.Security.DiracX import DiracXClient | ||
|
|
||
|
|
||
| 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
+142
to
+158
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. |
||
|
|
||
|
|
||
| def get_resource_rss_status(client: DiracXClient) -> list[tuple]: | ||
| """Get all resource statuses from the RSS API and translate to legacy format. | ||
|
|
||
| Returns: | ||
| List of tuples in legacy format: (name, element_type, status_type, status, vo) | ||
|
|
||
| """ | ||
| status: list[tuple] = [] | ||
| # Storage elements | ||
| response = client.rss.get_storage_status() | ||
| status.extend(translate_storage_element_status(response)) | ||
| # Computing Elements | ||
| response = client.rss.get_compute_status() | ||
| status.extend(translate_computing_element_status(response)) | ||
| # FTS | ||
| response = client.rss.get_fts_status() | ||
| status.extend(translate_fts_status(response)) | ||
|
|
||
| return status | ||
|
|
||
|
|
||
| def get_site_status(client: DiracXClient) -> list[tuple]: | ||
| """Get site status from the RSS API and translate to legacy format. | ||
|
|
||
| Returns: | ||
| List of tuples in legacy format: (site, status) | ||
|
|
||
| """ | ||
| response = client.rss.get_site_status() | ||
| return translate_site_status(response) | ||
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.