-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
78 lines (59 loc) · 2.53 KB
/
app.py
File metadata and controls
78 lines (59 loc) · 2.53 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
from flask import Flask, render_template, request, jsonify, redirect, url_for
app = Flask(__name__)
pwd = os.getcwd()
print(pwd)
def run_driver_node(driver_id):
command = f"python3 {pwd}/driverNode.py localhost:9092 localhost:9092"
os.system(f"osascript -e 'tell application \"Terminal\" to do script \"{command}\"'")
@app.route('/')
def index():
return render_template('tesss.html')
metric_result = {}
prev_metric_result = {}
heartBeat = {}
@app.route('/update_metrics', methods=['POST'])
def update_metrics():
global metric_result, prev_metric_result
data = request.json
current_metrics = data['metric_result']
prev_metric_result = metric_result.copy()
for node_id, metrics_per_test in current_metrics.items():
if node_id not in metric_result:
metric_result[node_id] = {}
for test_id, metrics in metrics_per_test.items():
if test_id not in metric_result[node_id] or metric_result[node_id][test_id] != metrics:
metric_result[node_id][test_id] = metrics
print("Updated metric results:", metric_result)
return jsonify({"status": "success"})
@app.route('/heartbeat', methods=['POST'])
def heartbeat():
global heartBeat
data = request.json
heartBeat[data['heartbeat']['node_id']] = data['heartbeat']
return jsonify({"status": "success"})
@app.route('/metrics')
def metrics():
global metric_result,heartBeat
return render_template('metrics.html', metric_result=metric_result,heartBeat=heartBeat)
@app.route('/get_metrics')
def get_metrics():
global metric_result, heartBeat
updated_table_html = render_template('partials/metric_table.html', metric_result=metric_result, heartBeat=heartBeat)
return jsonify({'updatedTableHTML': updated_table_html})
@app.route('/run-orchestration', methods=['POST'])
def run_orchestration_route():
num_drivers = int(request.form['num_drivers'])
test_type = request.form['test_type']
delay = request.form['delay']
delay = int(delay) if delay and delay.isdigit() else 0
num_messages = int(request.form['num_messages'])
orchestration_command = f"python3 {pwd}/orchetratorNode.py {num_drivers} {test_type} {delay} {num_messages}"
os.system(f"osascript -e 'tell application \"Terminal\" to do script \"{orchestration_command}\"'")
# Run driver nodes
for i in range(num_drivers):
run_driver_node(i + 1)
# Redirect to the 'metrics' endpoint
return redirect(url_for('metrics'))
if __name__ == '__main__':
app.run(debug=True)