Skip to content

Commit

Permalink
Cleaning up orchestration/scripts, linting, rename/refactor check_glo…
Browse files Browse the repository at this point in the history
…bus_compute.py, check_globus_transfer.py, and globus_tomopy_flow_init.py
  • Loading branch information
davramov committed Aug 26, 2024
1 parent 6c3b1ea commit 80a9143
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 285 deletions.
49 changes: 0 additions & 49 deletions examples/alcf_compute_endpoint_test.py

This file was deleted.

151 changes: 0 additions & 151 deletions examples/test_cc_auth.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@
"import globus_sdk\n",
"\n",
"# from utils import get_flows_client, get_specific_flow_client\n",
"from ..orchestration.globus.flows import get_flows_client, get_specific_flow_client\n",
"from orchestration.globus.flows import get_flows_client, get_specific_flow_client\n",
"\n",
"# Tutorial client ID\n",
"# We recommend replacing this with your own client for any production use-cases\n",
Expand Down
File renamed without changes.
85 changes: 85 additions & 0 deletions orchestration/scripts/check_globus_compute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import argparse
from dotenv import load_dotenv
from typing import Optional

from globus_compute_sdk.sdk.login_manager import LoginManager
from globus_compute_sdk import Client
from prefect import task, flow, get_run_logger

load_dotenv()


@task
def get_login_manager(environment: Optional[str] = None) -> LoginManager:
"""
Create and return a LoginManager instance for Globus Compute.
:param environment: Optional environment name for token storage.
:return: LoginManager instance
"""
return LoginManager(environment=environment)


@flow(name="check-compute-status")
def check_globus_compute_status(endpoint_id: str) -> bool:
"""
Check the status of a Globus Compute endpoint and determine if it is online.
:param endpoint_id: UUID of the Globus Compute endpoint.
:return: bool - True if the status is 'online', False otherwise.
"""
logger = get_run_logger()
try:
# Initialize the LoginManager
login_manager = get_login_manager()

# Ensure the user is logged in
login_manager.ensure_logged_in()

# Initialize the Globus Compute client with the LoginManager
compute_client = Client(login_manager=login_manager)

# Check endpoint status
endpoint_status = compute_client.get_endpoint_status(endpoint_id)

# Log the full status details
logger.info(f"Endpoint {endpoint_id} status: {endpoint_status}")

# Determine if the status is 'online'
status = endpoint_status.get('status')
if status == 'online':
logger.info(f"Endpoint {endpoint_id} is online.")
return True
else:
logger.info(f"Endpoint {endpoint_id} is not online. Status: {status}")
return False
except Exception as e:
logger.error(f"Failed to check endpoint status: {str(e)}")
return False


def main() -> None:
"""
Main function to parse command-line arguments and check the Globus Compute endpoint status.
Example usage"
python check_globus_compute.py --endpoint_id "your-uuid-here"
IMPORTANT:
Ensure you are logged into Globus Compute
export GLOBUS_COMPUTE_CLIENT_ID="your-client-id" & export GLOBUS_COMPUTE_CLIENT_SECRET="your-client-secret"
:return: None
"""
parser = argparse.ArgumentParser(description="Check the status of a Globus Compute endpoint.")
parser.add_argument('--endpoint_id', type=str, required=True, help="The UUID of the Globus Compute endpoint.")

args = parser.parse_args()

online = check_globus_compute_status(args.endpoint_id)
if online:
print(f"Endpoint {args.endpoint_id} is online.")
else:
print(f"Endpoint {args.endpoint_id} is not online.")


if __name__ == "__main__":
main()
54 changes: 0 additions & 54 deletions orchestration/scripts/check_globus_compute_status.py

This file was deleted.

Loading

0 comments on commit 80a9143

Please sign in to comment.