Skip to content

Commit a134ffb

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

2 files changed

Lines changed: 53 additions & 3 deletions

File tree

dashboard/iriapi_manager.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,60 @@
1+
from amsc_client import Client
12
from trame.widgets import vuetify3 as vuetify
23

4+
from error_manager import add_error
5+
from state_manager import state
6+
7+
8+
def update_iriapi_info():
9+
print("Updating AmSC IRI API info...")
10+
try:
11+
# create an authenticated client
12+
client = Client(token=state.iriapi_key)
13+
# update Perlmutter info
14+
nersc = client.facility("nersc")
15+
perlmutter = nersc.resource("compute")
16+
state.perlmutter_description = f"{perlmutter.description}"
17+
state.perlmutter_status = f"{perlmutter.status}"
18+
print(
19+
f"Perlmutter status is {state.perlmutter_status} with description '{state.perlmutter_description}'"
20+
)
21+
except Exception as e:
22+
print(f"An unexpected error occurred when connecting to AmSC IRI API:\n{e}")
23+
# reset key expiration date
24+
state.iriapi_key_expiration = "Unavailable"
25+
# reset Perlmutter status
26+
state.perlmutter_description = "Unavailable"
27+
state.perlmutter_status = "unavailable"
28+
title = "Unable to connect to NERSC"
29+
msg = f"Error occurred when connecting to NERSC through the AmSC IRI API: {e}"
30+
add_error(title, msg)
31+
print(msg)
32+
33+
34+
@state.change("iriapi_key_dict")
35+
def load_iriapi_credentials(**kwargs):
36+
# skip if triggered on server ready (all state variables marked as modified)
37+
if len(state.modified_keys) == 1:
38+
# return if no key file has been uploaded (redundant)
39+
if state.iriapi_key_dict is not None:
40+
print("Loading AmSC IRI API credentials...")
41+
# store the whole content of the key file in a string
42+
token_str = state.iriapi_key_dict["content"].decode("utf-8")
43+
# store the client ID and key in the respective state variables
44+
state.iriapi_key = token_str
45+
# update AmSC IRI API info
46+
update_iriapi_info()
47+
348

449
def load_iriapi_card():
550
print("Setting AmSC IRI API card...")
651
# row with component to upload input file with top padding
752
with vuetify.VRow(style="padding-top: 20px;"):
853
with vuetify.VCol():
954
vuetify.VFileInput(
10-
v_model=("sfapi_key_dict",),
55+
v_model=("iriapi_key_dict",),
1156
label="Token File",
12-
accept=".pem",
57+
accept=".txt",
1358
prepend_icon="",
1459
prepend_inner_icon="mdi-paperclip",
1560
__properties=["accept"],
@@ -18,7 +63,7 @@ def load_iriapi_card():
1863
with vuetify.VRow():
1964
with vuetify.VCol():
2065
vuetify.VTextField(
21-
v_model=("sfapi_key_expiration",),
66+
v_model=("iriapi_key_expiration",),
2267
label="Token Expiration (if expired or unavailable, please upload a valid token)",
2368
readonly=True,
2469
)

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)