Skip to content

Commit

Permalink
replace ui defaults format from JSON to YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
marconetto committed Jul 17, 2024
1 parent 35eced3 commit 1c32c92
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 42 deletions.
8 changes: 7 additions & 1 deletion docs/configfiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## UI defaults

This JSON file is used as input for both CLI and GUI to deploy environments,
This YAML file is used as input for both CLI and GUI to deploy environments,
collect data, plot graphs, and get advice.

It currently has these fields:
Expand All @@ -24,6 +24,12 @@ It currently has these fields:
- `createjumpbox` (optional): boolean for creating a VM in the same resource
group

Example inside matrix multiplication folder:

```yaml title="ui_defaults.yaml"
--8<-- "https://raw.githubusercontent.com/Azure/hpcadvisor/main/examples/matrixmult/ui_defaults.yaml"
```




Expand Down
6 changes: 3 additions & 3 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ which has three files:
- `plotfilter_matrixmult.json`: filter to consider only data for this
application when generating the plots and the recommendation (pareto-front
data).
- `ui_defaults.json`: user input to create the environment, setup application,
- `ui_defaults.yaml`: user input to create the environment, setup application,
and define scenarios to be explored.

```json title="ui_defaults.json"
--8<-- "https://raw.githubusercontent.com/Azure/hpcadvisor/main/examples/matrixmult/ui_defaults.json"
```yaml title="ui_defaults.yaml"
--8<-- "https://raw.githubusercontent.com/Azure/hpcadvisor/main/examples/matrixmult/ui_defaults.yaml"
```


Expand Down
30 changes: 0 additions & 30 deletions examples/matrixmult/ui_defaults.json

This file was deleted.

15 changes: 15 additions & 0 deletions examples/matrixmult/ui_defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
subscription: mysubscription
skus: [Standard_HC44rs, Standard_HB120rs_v2, Standard_HB120rs_v3]
rgprefix: nettoaha
appsetupurl: https://raw.githubusercontent.com/Azure/hpcadvisor/main/examples/matrixmult/appsetup_matrix.sh
nnodes: [2, 3, 4]
appname: matrixmult
tags:
appname: matrixmult
version: v1
region: southcentralus
createjumpbox: true
ppr: 100
appinputs:
appinteractions: "3"
appmatrixsize: ["4000", "7000"]
23 changes: 15 additions & 8 deletions src/hpcadvisor/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import datetime
import json
import os
import random
import string
import sys
import time

import yaml

from hpcadvisor import logger

log = logger.logger
Expand Down Expand Up @@ -146,24 +147,30 @@ def get_userinput_from_file(user_input_file):
]

try:
with open(user_input_file, "r") as json_file:
json_data = json.load(json_file)
except json.JSONDecodeError:
log.critical(f"User input not valid json file: " + user_input_file)
sys.exit(1)
with open(user_input_file, "r") as file:
try:
data = yaml.safe_load(file)
except yaml.YAMLError as e:
log.critical(f"User input not valid YAML file: {user_input_file}\n{e}")
sys.exit(1)
except Exception as e:
log.critical(f"Error reading file as YAML: {user_input_file}\n{e}")
sys.exit(1)
except FileNotFoundError:
log.critical("File not found: " + user_input_file)
sys.exit(1)

missing_variables = [var for var in required_variables if var not in json_data]
missing_variables = [var for var in required_variables if var not in data]

if missing_variables:
log.critical("Missing variables in user input file:")
for var in missing_variables:
log.critical(f"missing variable: {var}")
sys.exit(1)

return json_data
log.debug(f"User input data: {data}")

return data


def list_deployments():
Expand Down

0 comments on commit 1c32c92

Please sign in to comment.