Skip to content

Commit ff42e75

Browse files
committed
Continue IRI API implementation
1 parent ba5f2af commit ff42e75

2 files changed

Lines changed: 59 additions & 6 deletions

File tree

dashboard/iriapi_manager.py

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,76 @@
1+
import os
2+
3+
from amsc_client import Client
14
from trame.widgets import vuetify3 as vuetify
25

6+
from error_manager import add_error
7+
from state_manager import state
8+
9+
IRI_ACCESS_TOKEN_ENV = "IRI_ACCESS_TOKEN"
10+
11+
12+
def update_iriapi_info():
13+
print("Updating AmSC IRI API info...")
14+
try:
15+
# Create an authenticated client
16+
client = Client(token=state.iriapi_key)
17+
# Update Perlmutter info
18+
nersc = client.facility("nersc")
19+
perlmutter = nersc.resource("compute")
20+
state.perlmutter_description = f"{perlmutter.description}"
21+
state.perlmutter_status = f"{perlmutter.status}"
22+
print(
23+
f"Perlmutter status is {state.perlmutter_status} with description '{state.perlmutter_description}'"
24+
)
25+
except Exception as e:
26+
print(f"An unexpected error occurred when connecting to AmSC IRI API:\n{e}")
27+
# Reset key expiration date
28+
state.iriapi_key_expiration = "Unavailable"
29+
# Reset Perlmutter status
30+
state.perlmutter_description = "Unavailable"
31+
state.perlmutter_status = "unavailable"
32+
title = "Unable to connect to NERSC"
33+
msg = f"Error occurred when connecting to NERSC through the AmSC IRI API: {e}"
34+
add_error(title, msg)
35+
print(msg)
36+
37+
38+
@state.change("iriapi_key_dict")
39+
def load_iriapi_credentials(**kwargs):
40+
# Load credentials from the uploaded token file
41+
if state.iriapi_key_dict is not None:
42+
print("Loading AmSC IRI API credentials from file...")
43+
state.iriapi_key = state.iriapi_key_dict["content"].decode("utf-8")
44+
update_iriapi_info()
45+
346

447
def load_iriapi_card():
548
print("Setting AmSC IRI API card...")
6-
# row with component to upload input file with top padding
49+
# Prefer an environment-provided token when running in deployed contexts
50+
if IRI_ACCESS_TOKEN_ENV in os.environ:
51+
print("Loading AmSC IRI API credentials from environment...")
52+
state.iriapi_key = os.environ[IRI_ACCESS_TOKEN_ENV]
53+
update_iriapi_info()
54+
# Row with component to upload input file with top padding
755
with vuetify.VRow(style="padding-top: 20px;"):
856
with vuetify.VCol():
957
vuetify.VFileInput(
10-
v_model=("sfapi_key_dict",),
58+
v_model=("iriapi_key_dict",),
1159
label="Token File",
12-
accept=".pem",
60+
accept=".txt",
1361
prepend_icon="",
1462
prepend_inner_icon="mdi-paperclip",
1563
__properties=["accept"],
1664
)
17-
# row with text field to display key expiration date
65+
# Row with text field to display key expiration date
1866
with vuetify.VRow():
1967
with vuetify.VCol():
2068
vuetify.VTextField(
21-
v_model=("sfapi_key_expiration",),
69+
v_model=("iriapi_key_expiration",),
2270
label="Token Expiration (if expired or unavailable, please upload a valid token)",
2371
readonly=True,
2472
)
25-
# row with text field to display Perlmutter status
73+
# Row with text field to display Perlmutter status
2674
with vuetify.VRow():
2775
with vuetify.VCol():
2876
vuetify.VTextField(

dashboard/state_manager.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@ def initialize_state():
3939
state.opacity = 0.05
4040
# HPC connection
4141
state.hpc_connection = "local"
42+
# IRI API
43+
state.iriapi_key = None
44+
state.iriapi_key_dict = None
45+
state.iriapi_key_expiration = "Unavailable"
4246
# Superfacility API
4347
state.sfapi_client_id = None
4448
state.sfapi_key = None
4549
state.sfapi_key_dict = None
4650
state.sfapi_key_expiration = "Unavailable"
51+
# NERSC
4752
state.perlmutter_description = "Unavailable"
4853
state.perlmutter_status = "unavailable"
4954
# Simulation plots in interactive dialog

0 commit comments

Comments
 (0)