-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
63 lines (52 loc) · 1.55 KB
/
main.py
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
import json
from logging.config import dictConfig
from flask import Flask, request
from core import data_to_solver_input, check_input
from core.solvers import *
dictConfig({
'version': 1,
'formatters': {'default': {
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
}},
'handlers': {'wsgi': {
'class': 'logging.StreamHandler',
'stream': 'ext://sys.stdout',
'formatter': 'default'
}},
'root': {
'level': 'INFO',
'handlers': ['wsgi']
}
})
app = Flask(__name__)
app.app_context()
@app.route('/')
def serve():
print("Request received")
input = request.json
print(input)
check_input(input)
solver = input.get("solver", {'type': 'NeptuneMinDelayAndUtilization'})
solver_type = solver.get("type")
solver_args = solver.get("args", {})
with_db = input.get("with_db", True)
solver = eval(solver_type)(**solver_args)
print(solver)
solver.load_data(data_to_solver_input(input, with_db=with_db, workload_coeff=input.get("workload_coeff", 1)))
solver.solve()
x, c = solver.results()
score = solver.score()
print("INTER", score)
response = app.response_class(
response=json.dumps({
"cpu_routing_rules": x,
"cpu_allocations": c,
"gpu_routing_rules": {},
"gpu_allocations": {},
"score" : score
}),
status=200,
mimetype='application/json'
)
return response
app.run(host='0.0.0.0', port=5000, threaded=False, processes=10, debug=True)