Commit 48485307 authored by Kento HASEGAWA's avatar Kento HASEGAWA

Change to decide resolver at host

parent aadb00db
......@@ -117,12 +117,18 @@ def post():
_answer = request.form["answer"]
_client = request.form["client"]
if "solver" in request.form:
_solver = request.form["solver"]
else:
_solver = _client
receive_time = datetime.datetime.now()
receive_time_str = receive_time.strftime("%Y%m%d%H%M%S")
dat = {
"req_id": request.form['req_id'],
"client": _client,
"solver": _solver,
"answer": _answer,
"cputime": request.form['cputime'],
"timestamp": receive_time.strftime("%Y/%m/%d %H:%M:%S")
......@@ -220,10 +226,18 @@ def solve_questions(qname, qstr):
global questions
global current_seed
def worker(host, qname, qstr, qseed, req_id):
def worker(host, qname, qstr, qseed, req_id, resolver):
_url = "http://{}/start".format(host)
data = {
"client": host,
"qname": qname,
"question": qstr,
"qseed": qseed,
"req_id": req_id,
"resolver": resolver
}
try:
r = requests.post(_url, data={"client": host, "qname": qname, "question": qstr, "qseed": qseed, "req_id": req_id})
r = requests.post(_url, data=data)
client_res = json.loads(r.text)
except Exception as e:
sys.stderr.write(str(e) + "\n")
......@@ -234,11 +248,12 @@ def solve_questions(qname, qstr):
req_id = time.time()
questions[qname]['last_req'] = req_id
for c in clients:
for c in clients['solver']:
# 問題はSolverに送る
if c[1] == 'Solver':
client_addr = c[0]
_th = threading.Thread(name=client_addr, target=worker, args=(client_addr, qname, qstr, current_seed, req_id))
idx_of_resolver = current_seed % len(clients['resolver'])
resolver = clients['resolver'][idx_of_resolver][0]
_th = threading.Thread(name=client_addr, target=worker, args=(client_addr, qname, qstr, current_seed, req_id, resolver))
_th.start()
threads.append(_th)
current_seed += 1
......@@ -269,7 +284,7 @@ def get_clients():
res = OrderedDict()
for c in clients:
for c in clients['all']:
client_ip = c[0]
res[client_ip] = "http://{}".format(client_ip)
......@@ -291,7 +306,7 @@ def client_table():
global app_args
global clients
return render_template("part_client_table.html", clients=clients, local_mode=g.local_mode)
return render_template("part_client_table.html", clients=clients["all"], local_mode=g.local_mode)
@app.route("/get_question_status")
def question_status():
......@@ -305,20 +320,17 @@ def question_status():
update_answer_list(qname)
qdata = questions[qname]
return render_template("part_question_status.html", qname=qname, qdata=qdata, clients=clients)
return render_template("part_question_status.html", qname=qname, qdata=qdata, solvers=clients["solver"])
@app.route("/")
def index():
global app_args
global questions
global clients
question_path = os.path.abspath(app_args["question"])
print(g.local_mode)
return render_template("index.html", questions=questions, question_path=question_path, clients=clients)
return render_template("index.html", questions=questions, question_path=question_path)
def main(args):
raise NotImprementedError()
......@@ -337,7 +349,21 @@ def init_system():
with open(app_args["client"], "r") as fp:
_clients = fp.readlines()
clients = [v.rstrip().split() for v in _clients]
all_clients = [v.rstrip().split() for v in _clients]
solver = []
resolver = []
for v in all_clients:
if v[1].lower() == "solver":
solver.append(v)
elif v[1].lower() == "resolver":
resolver.append(v)
clients = {
"all": all_clients,
"solver": solver,
"resolver": resolver
}
if __name__ == "__main__":
......
......@@ -20,7 +20,7 @@
<div class="row">
<div class="col-5" id="question-control-pane">
<h3>問題一覧</h3>&nbsp;
<span><a href="/#" id="view-server-status-button">クライアント状況</a></span>
<span><a href="/#" id="view-server-status-button">システム状況</a></span>
<div id="question-table-wrapper">
<p>Loading...</p>
</div>
......
......@@ -12,8 +12,7 @@
<th>Client (Solver)</th>
<th>Status</th>
</tr>
{% for c in clients %}
{% if c[1] == "Solver" %}
{% for c in solvers %}
<tr>
<td>
{% if c|length > 3 %}
......@@ -26,7 +25,6 @@
</td>
<td></td>
</tr>
{% endif %}
{% endfor %}
</table>
</div>
......@@ -43,7 +41,7 @@
{% for v in qdata.answers %}
<tr>
<td>{{v.timestamp}}</td>
<td>{{v.client}}</td>
<td>{{v.solver}}</td>
<td>{{v.nlcheck}}</td>
</tr>
{% endfor %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment