Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
adc2019-system
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
adc2019
adc2019-system
Commits
9234c22e
Commit
9234c22e
authored
Aug 21, 2019
by
Kento HASEGAWA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve status display
parent
72e19f13
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
22 deletions
+52
-22
main.py
main.py
+1
-1
host.py
roles/host.py
+24
-2
solver.py
roles/solver.py
+27
-19
No files found.
main.py
View file @
9234c22e
...
@@ -5,7 +5,7 @@ import argparse
...
@@ -5,7 +5,7 @@ import argparse
from
flask
import
abort
,
Flask
,
g
,
jsonify
,
render_template
,
request
from
flask
import
abort
,
Flask
,
g
,
jsonify
,
render_template
,
request
# from gevent import pywsgi, monkey
# from gevent import pywsgi, monkey
# from geventwebsocket.handler import WebSocketHandler
# from geventwebsocket.handler import WebSocketHandler
from
queue
import
Queue
#
from queue import Queue
import
adc2019system
import
adc2019system
...
...
roles/host.py
View file @
9234c22e
...
@@ -146,6 +146,9 @@ class Host(object):
...
@@ -146,6 +146,9 @@ class Host(object):
elif
cmd
==
'stop'
:
elif
cmd
==
'stop'
:
self
.
worker_manager
.
request_stop
()
self
.
worker_manager
.
request_stop
()
return
{}
return
{}
elif
cmd
==
'worker/status'
:
self
.
worker_manager
.
update_status
(
params
[
'address'
],
params
[
'status'
])
return
{
'status'
:
'updated'
}
elif
cmd
==
'view/solution'
:
elif
cmd
==
'view/solution'
:
problem_key
=
params
[
'problem'
]
problem_key
=
params
[
'problem'
]
solution_id
=
params
[
'solution'
]
solution_id
=
params
[
'solution'
]
...
@@ -201,6 +204,16 @@ class WorkerManager(object):
...
@@ -201,6 +204,16 @@ class WorkerManager(object):
self
.
workers
=
dict
()
self
.
workers
=
dict
()
self
.
host
=
host_address
self
.
host
=
host_address
# self.heartbeat_thread = threading.Thread(name='heartbeat', target=self.heartbeat, daemon=True)
# self.heartbeat_thread.start()
# def heartbeat(self):
# while True:
# for k, v in self.workers.items():
# v.update_status()
# time.sleep(1)
def
add_worker
(
self
,
conf
):
def
add_worker
(
self
,
conf
):
worker_conf
=
dict
()
worker_conf
=
dict
()
...
@@ -213,6 +226,9 @@ class WorkerManager(object):
...
@@ -213,6 +226,9 @@ class WorkerManager(object):
def
get_workers
(
self
):
def
get_workers
(
self
):
return
self
.
workers
return
self
.
workers
def
update_status
(
self
,
address
,
status
):
self
.
workers
[
address
]
.
status
=
status
def
request_stop
(
self
):
def
request_stop
(
self
):
self
.
broadcast
(
'stop'
,
{})
self
.
broadcast
(
'stop'
,
{})
...
@@ -236,10 +252,17 @@ class Worker(object):
...
@@ -236,10 +252,17 @@ class Worker(object):
self
.
host
=
params
[
'host'
]
self
.
host
=
params
[
'host'
]
self
.
role
=
params
[
'role'
]
self
.
role
=
params
[
'role'
]
self
.
params
=
params
self
.
params
=
params
self
.
status
=
'
R
eady'
self
.
status
=
'
Not r
eady'
self
.
configure
()
self
.
configure
()
def
update_status
(
self
):
res
=
self
.
post
(
'status'
,
None
)
if
res
is
None
:
self
.
status
=
'Not connected'
else
:
self
.
status
=
res
.
json
()[
'status'
]
def
post
(
self
,
path
,
data
):
def
post
(
self
,
path
,
data
):
try
:
try
:
response
=
requests
.
post
(
response
=
requests
.
post
(
...
@@ -249,7 +272,6 @@ class Worker(object):
...
@@ -249,7 +272,6 @@ class Worker(object):
timeout
=
2
)
timeout
=
2
)
print
(
f
"I: Post to {self.address}, API Cmd: {path}"
)
print
(
f
"I: Post to {self.address}, API Cmd: {path}"
)
except
Exception
as
e
:
except
Exception
as
e
:
# sys.stderr.write(str(e) + "\n")
print
(
f
"W: Failed to connect {self.address}"
)
print
(
f
"W: Failed to connect {self.address}"
)
self
.
status
=
'Not connected'
self
.
status
=
'Not connected'
response
=
None
response
=
None
...
...
roles/solver.py
View file @
9234c22e
...
@@ -19,28 +19,38 @@ class Solver(object):
...
@@ -19,28 +19,38 @@ class Solver(object):
self
.
solver
=
importlib
.
import_module
(
f
"solvers.{config['solver']}"
)
self
.
solver
=
importlib
.
import_module
(
f
"solvers.{config['solver']}"
)
self
.
queue
=
OrderedDict
()
self
.
queue
=
OrderedDict
()
self
.
status
=
'Ready'
self
.
status
=
None
# self.thread = None
# self.thread = None
self
.
thread
=
threading
.
Thread
(
name
=
'solver'
,
target
=
self
.
solver_thread
,
daemon
=
True
)
self
.
thread
=
threading
.
Thread
(
name
=
'solver'
,
target
=
self
.
solver_thread
,
daemon
=
True
)
self
.
thread
.
start
()
self
.
thread
.
start
()
self
.
set_status
(
'Ready'
)
def
__del__
(
self
):
def
__del__
(
self
):
self
.
stop_solver
()
self
.
stop_solver
()
def
__repr__
(
self
):
def
__repr__
(
self
):
return
"Solver"
return
"Solver"
def
set_status
(
self
,
status
):
self
.
status
=
status
self
.
post
(
'worker/status'
,
{
'address'
:
self
.
address
,
'status'
:
self
.
status
})
def
solver_thread
(
self
):
def
solver_thread
(
self
):
while
True
:
while
True
:
if
len
(
self
.
queue
)
>
0
:
if
len
(
self
.
queue
)
>
0
:
print
(
"I: Solver started"
)
print
(
"I: Solver started"
)
self
.
status
=
'running'
_
,
params
=
self
.
queue
.
popitem
(
last
=
False
)
_
,
params
=
self
.
queue
.
popitem
(
last
=
False
)
# self.status = f'Running ({len(self.queue)} in queue)'
self
.
set_status
(
f
'Running ({len(self.queue)} in queue)'
)
self
.
solve
(
params
)
self
.
solve
(
params
)
# self.status = 'Ready'
self
.
set_status
(
'Ready'
)
else
:
else
:
self
.
status
=
'ready'
# self.status = 'Ready'
self
.
set_status
(
'Ready'
)
time
.
sleep
(
0.5
)
time
.
sleep
(
0.5
)
def
solve
(
self
,
params
):
def
solve
(
self
,
params
):
...
@@ -59,11 +69,15 @@ class Solver(object):
...
@@ -59,11 +69,15 @@ class Solver(object):
return
True
return
True
def
post
(
self
,
path
,
data
):
def
post
(
self
,
path
,
data
):
try
:
response
=
requests
.
post
(
response
=
requests
.
post
(
f
'http://{self.host}/api/{path}'
,
f
'http://{self.host}/api/{path}'
,
json
.
dumps
(
data
),
json
.
dumps
(
data
),
headers
=
{
'Content-Type'
:
'application/json'
})
headers
=
{
'Content-Type'
:
'application/json'
})
print
(
f
"I: Post to {self.host}, API Cmd: {path}"
)
print
(
f
"I: Post to {self.host}, API Cmd: {path}"
)
except
Exception
as
e
:
print
(
f
"W: Failed to connect to the host"
)
response
=
None
return
response
return
response
def
submit_solution
(
self
,
params
,
solution
):
def
submit_solution
(
self
,
params
,
solution
):
...
@@ -77,25 +91,19 @@ class Solver(object):
...
@@ -77,25 +91,19 @@ class Solver(object):
def
start_solver
(
self
,
params
):
def
start_solver
(
self
,
params
):
# if self.thread is None:
# print("I: Solver started")
# self.thread = threading.Thread(name='solver', target=self.solve, args=(params, ), daemon=True)
# self.thread.start()
# return {'status': 'started'}
# else:
# return {'status': 'busy'}
print
(
"I: Problem queued"
)
print
(
"I: Problem queued"
)
_id
=
params
[
'request_id'
]
_id
=
params
[
'request_id'
]
self
.
queue
[
_id
]
=
params
self
.
queue
[
_id
]
=
params
return
{
'status'
:
'queued'
}
# self.status = f'Running ({len(self.queue)} in queue)'
self
.
set_status
(
f
'Running ({len(self.queue)} in queue)'
)
return
{
'status'
:
self
.
status
}
def
stop_solver
(
self
):
def
stop_solver
(
self
):
if
self
.
thread
is
not
None
:
if
self
.
thread
is
not
None
:
self
.
solver
.
stop
()
self
.
solver
.
stop
()
return
{
'status'
:
'stopped'
}
return
{
'status'
:
self
.
status
}
def
call_api
(
self
,
method
,
cmd
,
params
):
def
call_api
(
self
,
method
,
cmd
,
params
):
if
cmd
==
'role'
:
if
cmd
==
'role'
:
...
@@ -105,6 +113,6 @@ class Solver(object):
...
@@ -105,6 +113,6 @@ class Solver(object):
elif
cmd
==
'stop'
:
elif
cmd
==
'stop'
:
return
self
.
stop_solver
()
return
self
.
stop_solver
()
elif
cmd
==
'status'
:
elif
cmd
==
'status'
:
return
self
.
status
return
{
'status'
:
self
.
status
}
else
:
else
:
return
None
return
None
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment