-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
58 lines (46 loc) · 1.79 KB
/
app.py
File metadata and controls
58 lines (46 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Flask app: serve dashboard and /api/jobs."""
from flask import Flask, jsonify, request, send_from_directory
import config
from slurm import fetch_jobs, fetch_node_capacities, fetch_node_states, fetch_nodes, update_job_settings
app = Flask(__name__, static_folder="static", static_url_path="")
@app.route("/")
def index():
return send_from_directory(app.static_folder, "index.html")
@app.route("/api/jobs")
def api_jobs():
jobs = fetch_jobs()
nodes = fetch_nodes()
node_states, node_reasons = fetch_node_states()
gpus_per_node, cpus_per_node = fetch_node_capacities()
if gpus_per_node <= 0:
gpus_per_node = config.GPUS_PER_NODE
if cpus_per_node <= 0:
cpus_per_node = config.CPUS_PER_NODE
return jsonify({
"jobs": jobs,
"nodes": nodes,
"node_states": node_states,
"node_reasons": node_reasons,
"gpus_per_node": gpus_per_node,
"cpus_per_node": cpus_per_node,
})
@app.route("/api/config")
def api_config():
return jsonify({
"refresh_intervals": config.REFRESH_INTERVALS,
"default_refresh": config.DEFAULT_REFRESH,
})
@app.route("/api/job/<job_id>/settings", methods=["POST"])
def api_job_settings(job_id):
data = request.get_json(silent=True) or {}
priority = data.get("priority")
num_cpus = data.get("num_cpus")
memory_mb = data.get("memory_mb")
if priority is None and num_cpus is None and memory_mb is None:
return jsonify({"ok": False, "error": "No settings to update"}), 400
ok, msg = update_job_settings(job_id, priority=priority, num_cpus=num_cpus, memory_mb=memory_mb)
if not ok:
return jsonify({"ok": False, "error": msg}), 400
return jsonify({"ok": True})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=config.PORT, debug=False)