Skip to content

Commit 49dde12

Browse files
committed
Return DataFrame from ds.systems.queues(), remove verbose logging
1 parent 0f2a637 commit 49dde12

3 files changed

Lines changed: 191 additions & 232 deletions

File tree

dapi/client.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -483,26 +483,20 @@ def list(self, category: Optional[str] = None, output: str = "df"):
483483
self._tapis, category=category, output=output
484484
)
485485

486-
def queues(self, system_id: str, verbose: bool = True) -> List[Any]:
487-
"""List logical queues available on a Tapis execution system.
488-
489-
This is a convenience wrapper around systems_module.list_system_queues().
486+
def queues(self, system_id: str, output: str = "df"):
487+
"""List batch queues available on a Tapis execution system.
490488
491489
Args:
492-
system_id (str): The ID of the execution system (e.g., 'frontera').
493-
verbose (bool, optional): If True, prints detailed queue information.
494-
Defaults to True.
490+
system_id (str): The ID of the execution system (e.g., "stampede3").
491+
output (str, optional): "df" for DataFrame (default), "raw" for Tapis objects.
495492
496493
Returns:
497-
List[Any]: List of queue objects with queue configuration details.
494+
DataFrame or List: Queues with name, maxNodes, maxMinutes, etc.
498495
499-
Raises:
500-
SystemInfoError: If the system is not found or queue retrieval fails.
501-
ValueError: If system_id is empty.
496+
Example:
497+
>>> ds.systems.queues("stampede3")
502498
"""
503-
return systems_module.list_system_queues(
504-
self._tapis, system_id, verbose=verbose
505-
)
499+
return systems_module.list_system_queues(self._tapis, system_id, output=output)
506500

507501
def check_credentials(self, system_id: str, username: str = None) -> bool:
508502
"""Check whether TMS credentials exist for a user on a system.

dapi/systems.py

Lines changed: 35 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -122,95 +122,62 @@ def list_systems(
122122
return pd.DataFrame(rows)
123123

124124

125-
def list_system_queues(t: Tapis, system_id: str, verbose: bool = True) -> List[Any]:
126-
"""
127-
Retrieves the list of batch logical queues available on a specific Tapis execution system.
125+
def list_system_queues(
126+
t: Tapis,
127+
system_id: str,
128+
output: str = "df",
129+
) -> Union[pd.DataFrame, List[Any]]:
130+
"""List batch queues available on a Tapis execution system.
128131
129132
Args:
130-
t: Authenticated Tapis client instance.
131-
system_id: The ID of the execution system (e.g., 'frontera', 'stampede2').
132-
verbose: If True, prints the found queues.
133+
t (Tapis): Authenticated Tapis client instance.
134+
system_id (str): The ID of the execution system (e.g., "stampede3").
135+
output (str, optional): "df" for DataFrame (default), "raw" for Tapis objects.
133136
134137
Returns:
135-
A list of queue objects (typically TapisResult instances or similar dict-like structures)
136-
defined for the system. Returns an empty list if the system exists but has no queues defined.
138+
Union[pd.DataFrame, List]: Queues with name, maxNodes, maxMinutes, maxCoresPerNode, etc.
137139
138140
Raises:
139141
SystemInfoError: If the system is not found or an API error occurs.
142+
ValueError: If system_id is empty or output is invalid.
140143
"""
141144
if not system_id:
142145
raise ValueError("system_id cannot be empty.")
146+
if output not in ("df", "raw"):
147+
raise ValueError(f"output must be 'df' or 'raw', got '{output}'")
143148

144149
try:
145-
if verbose:
146-
print(f"\nFetching queue information for system '{system_id}'...")
147-
148-
# Get system details - Fetch the full object to ensure queues are included
149-
# Removed 'select' parameter for simplicity and robustness against API variations
150150
system_details = t.systems.getSystem(systemId=system_id)
151-
152-
# Use 'batchLogicalQueues' based on the direct API call result
153151
queues = getattr(system_details, "batchLogicalQueues", [])
154152

155153
if not queues:
156-
# Check if the system itself was found but just has no queues
157-
try:
158-
# Minimal check to confirm system existence if queues list was empty
159-
# This might be slightly redundant if getSystem above succeeded, but safe.
160-
t.systems.getSystem(systemId=system_id, select="id")
161-
if verbose:
162-
# Updated message
163-
print(
164-
f"System '{system_id}' found, but it has no batch logical queues defined."
165-
)
166-
return [] # Return empty list as system exists but has no queues
167-
except BaseTapyException as e_check:
168-
# If this minimal check fails with 404, the system wasn't found initially
169-
if (
170-
hasattr(e_check, "response")
171-
and e_check.response
172-
and e_check.response.status_code == 404
173-
):
174-
raise SystemInfoError(
175-
f"Execution system '{system_id}' not found."
176-
) from e_check
177-
else: # Other error during the existence check
178-
raise SystemInfoError(
179-
f"Error confirming existence of system '{system_id}': {e_check}"
180-
) from e_check
181-
182-
if verbose:
183-
# Updated message
184-
print(f"Found {len(queues)} batch logical queues for system '{system_id}':")
185-
for q in queues:
186-
name = getattr(q, "name", "N/A")
187-
hpc_queue = getattr(
188-
q, "hpcQueueName", "N/A"
189-
) # Actual scheduler queue name
190-
max_jobs = getattr(q, "maxJobs", "N/A")
191-
max_user_jobs = getattr(q, "maxUserJobs", "N/A")
192-
max_mins = getattr(q, "maxMinutes", "N/A")
193-
max_nodes = getattr(q, "maxNodeCount", "N/A")
194-
# Add more attributes if desired (e.g., maxMemoryMB, maxCoresPerNode)
195-
print(
196-
f" - Name: {name} (HPC Queue: {hpc_queue}, Max Jobs: {max_jobs}, Max User Jobs: {max_user_jobs}, Max Mins: {max_mins}, Max Nodes: {max_nodes})"
197-
)
198-
199-
print()
200-
201-
# The items in the list are TapisResult objects themselves
202-
return queues
154+
if output == "raw":
155+
return []
156+
return pd.DataFrame()
157+
158+
if output == "raw":
159+
return queues
160+
161+
rows = []
162+
for q in queues:
163+
rows.append(
164+
{
165+
"name": getattr(q, "name", ""),
166+
"hpcQueue": getattr(q, "hpcQueueName", ""),
167+
"maxNodes": getattr(q, "maxNodeCount", None),
168+
"maxCoresPerNode": getattr(q, "maxCoresPerNode", None),
169+
"maxMinutes": getattr(q, "maxMinutes", None),
170+
"maxMemoryMB": getattr(q, "maxMemoryMB", None),
171+
"maxJobsPerUser": getattr(q, "maxJobsPerUser", None),
172+
}
173+
)
174+
return pd.DataFrame(rows)
203175

204176
except BaseTapyException as e:
205177
if hasattr(e, "response") and e.response and e.response.status_code == 404:
206178
raise SystemInfoError(f"Execution system '{system_id}' not found.") from e
207-
else:
208-
raise SystemInfoError(
209-
f"Failed to retrieve queues for system '{system_id}': {e}"
210-
) from e
211-
except Exception as e:
212179
raise SystemInfoError(
213-
f"An unexpected error occurred while fetching queues for system '{system_id}': {e}"
180+
f"Failed to retrieve queues for system '{system_id}': {e}"
214181
) from e
215182

216183

0 commit comments

Comments
 (0)