-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from DesignSafe-CI/tapisv3
Tapisv3
- Loading branch information
Showing
42 changed files
with
13,397 additions
and
2,265 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,20 +1,42 @@ | ||
""" | ||
`dapi` is a library that simplifies the process of submitting, running, and monitoring [TAPIS v2 / AgavePy](https://agavepy.readthedocs.io/en/latest/index.html) jobs on [DesignSafe](https://designsafe-ci.org) via [Jupyter Notebooks](https://jupyter.designsafe-ci.org). | ||
dapi` is a library that simplifies the process of submitting, running, and monitoring [TAPIS v3](https://tapis.readthedocs.io/en/latest/) jobs on [DesignSafe](https://designsafe-ci.org) via [Jupyter Notebooks](https://jupyter.designsafe-ci.org). | ||
## Features | ||
* Simplified TAPIS v2 Calls: No need to fiddle with complex API requests. `dapi` abstracts away the complexities. | ||
### Jobs | ||
* Get TAPIS v3 templates for jobs: No need to fiddle with complex API requests. `dapi` abstracts away the complexities. | ||
* Seamless Integration with DesignSafe Jupyter Notebooks: Launch DesignSafe applications directly from the Jupyter environment. | ||
### Database | ||
Connects to SQL databases on DesignSafe: | ||
| Database | dbname | env_prefix | | ||
|----------|--------|------------| | ||
| NGL | `ngl`| `NGL_` | | ||
| Earthake Recovery | `eq` | `EQ_` | | ||
| Vp | `vp` | `VP_` | | ||
Define the following environment variables: | ||
``` | ||
{env_prefix}DB_USER | ||
{env_prefix}DB_PASSWORD | ||
{env_prefix}DB_HOST | ||
{env_prefix}DB_PORT | ||
``` | ||
For e.g., to add the environment variable `NGL_DB_USER` edit `~/.bashrc`, `~/.zshrc`, or a similar shell-specific configuration file for the current user and add `export NGL_DB_USER="dspublic"`. | ||
## Installation | ||
```shell | ||
pip3 install dapi | ||
``` | ||
""" | ||
from . import apps | ||
from . import auth | ||
from . import db | ||
from . import jobs |
This file contains 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,3 @@ | ||
from .apps import find_apps, get_app_version | ||
|
||
__all__ = ["find_apps", "get_app_version"] |
This file contains 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,57 @@ | ||
from tapipy.tapis import Tapis | ||
from typing import List, Dict, Any, Optional | ||
|
||
|
||
def find_apps( | ||
t: Tapis, search_term: str, list_type: str = "ALL", verbose: bool = True | ||
) -> List[Any]: | ||
""" | ||
Search for Tapis apps matching a search term. | ||
Args: | ||
t (Tapis): Tapis client instance | ||
search_term (str): Name or partial name to search for | ||
list_type (str): One of 'OWNED', 'SHARED_PUBLIC', 'SHARED_DIRECT', 'READ_PERM', 'MINE', 'ALL' | ||
verbose (bool): If True, prints all found apps | ||
Returns: | ||
List[Any]: List of matching app objects | ||
""" | ||
results = t.apps.getApps(search=f"(id.like.*{search_term}*)", listType=list_type) | ||
|
||
if verbose: | ||
if not results: | ||
print(f"No apps found matching '{search_term}'") | ||
else: | ||
print(f"\nFound {len(results)} matching apps:") | ||
for app in results: | ||
print(f"- {app.id}") | ||
print() | ||
|
||
return results | ||
|
||
|
||
def get_app_version(t: Tapis, app_id: str, verbose: bool = True) -> Optional[Any]: | ||
""" | ||
Get latest version info for a specific app ID. | ||
Args: | ||
t (Tapis): Tapis client instance | ||
app_id (str): Exact app ID to look up | ||
verbose (bool): If True, prints basic app info | ||
Returns: | ||
Optional[Any]: Latest version info for the app, or None if not found | ||
""" | ||
try: | ||
app_info = t.apps.getAppLatestVersion(appId=app_id) | ||
if verbose: | ||
print(f"App: {app_info.id}") | ||
print(f"Version: {app_info.version}") | ||
print(f"System: {app_info.jobAttributes.execSystemId}") | ||
return app_info | ||
except Exception as e: | ||
print(f"Error getting app info for '{app_id}': {str(e)}") | ||
print("\nCouldn't find exact match. Here are similar apps:") | ||
_ = find_apps(t, app_id) | ||
return None |
This file contains 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 |
---|---|---|
@@ -1,30 +1,42 @@ | ||
from agavepy.agave import Agave | ||
from collections.abc import Mapping | ||
import os | ||
from getpass import getpass | ||
from tapipy.tapis import Tapis | ||
from dotenv import load_dotenv | ||
|
||
|
||
def init(username, password): | ||
def init(): | ||
""" | ||
Initialize an Agave object with a new client and an active token. | ||
Initialize a Tapis object with authentication. | ||
Tries to read credentials from environment variables first. | ||
If not found, prompts the user for input. | ||
Args: | ||
username (str): The username. | ||
password (str): The password. | ||
Save the user credentials in the .env file. | ||
``` | ||
DESIGNSAFE_USERNAME=<username> | ||
DESIGNSAFE_PASSWORD=<password> | ||
``` | ||
Returns: | ||
object: The Agave object. | ||
object: The authenticated Tapis object. | ||
""" | ||
# Authenticate with Agave | ||
ag = Agave( | ||
base_url="https://agave.designsafe-ci.org", username=username, password=password | ||
) | ||
# Create a new client | ||
new_client = ag.clients_create() | ||
# create a new ag object with the new client, at this point ag will have a new token | ||
ag = Agave( | ||
base_url="https://agave.designsafe-ci.org", | ||
username=username, | ||
password=password, | ||
api_key=new_client["api_key"], | ||
api_secret=new_client["api_secret"], | ||
) | ||
return ag | ||
base_url = "https://designsafe.tapis.io" | ||
|
||
# Load environment variables from .env file | ||
load_dotenv() | ||
|
||
# Try to get credentials from environment variables | ||
username = os.getenv("DESIGNSAFE_USERNAME") | ||
password = os.getenv("DESIGNSAFE_PASSWORD") | ||
|
||
# If environment variables are not set, prompt user for input | ||
if not username: | ||
username = input("Enter username: ") | ||
if not password: | ||
password = getpass("Enter password: ") | ||
|
||
# Initialize Tapis object | ||
t = Tapis(base_url=base_url, username=username, password=password) | ||
|
||
t.get_tokens() | ||
|
||
return t |
This file contains 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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
""" | ||
`dapi` job submodule simplifies the process of submitting, running, and monitoring [TAPIS v2 / AgavePy](https://agavepy.readthedocs.io/en/latest/index.html) jobs on [DesignSafe](https://designsafe-ci.org) via [Jupyter Notebooks](https://jupyter.designsafe-ci.org). | ||
`dapi` job submodule simplifies the process of submitting, running, and monitoring [Tapis v3](https://tapis.readthedocs.io/en/latest/) jobs on [DesignSafe](https://designsafe-ci.org) via [Jupyter Notebooks](https://jupyter.designsafe-ci.org). | ||
## Features | ||
* Simplified TAPIS v2 Calls: No need to fiddle with complex API requests. `dapi` abstracts away the complexities. | ||
* Simplified TAPIS v3 Calls: No need to fiddle with complex API requests. `dapi` abstracts away the complexities. | ||
* Seamless Integration with DesignSafe Jupyter Notebooks: Launch DesignSafe applications directly from the Jupyter environment. | ||
## Installation | ||
# Installation | ||
```shell | ||
pip3 install dapi | ||
``` | ||
""" | ||
from .dir import get_ds_path_uri | ||
from .jobs import get_status, runtime_summary, generate_job_info, get_archive_path | ||
from .jobs import get_status, runtime_summary, generate_job_info |
This file contains 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
Oops, something went wrong.