-
Notifications
You must be signed in to change notification settings - Fork 0
/
dispatcher.py
72 lines (54 loc) · 1.99 KB
/
dispatcher.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
64
65
66
67
68
69
70
71
72
from sys import argv
import Pyro4
import syntax_tree as st
from parser import parse_makefile
from ui import ConfigParser
from daemons import DISPATCHER_NAME, NoJobAvailableYet, AllJobsCompleted
class Dispatcher(object):
def __init__(self, config_file):
config = ConfigParser(config_file)
# init scheduler for task list
makefile = parse_makefile(config.mkfile_filepath)
self.scheduler = makefile.build_deps(config.mk_target)
self.map_host = {}
for host in config.build_hosts():
self.map_host[host.name] = host
def get_work(self):
try:
job = self.scheduler.get_job()
except st.AllJobsCompleted:
raise AllJobsCompleted()
except st.HigherLevelJobsStillRunning:
raise NoJobAvailableYet()
else:
return job
def put_result(self, job):
try:
self.scheduler.finish_job(job)
except st.JobAlreadyDone:
pass
def request_file(self, file_names, slave_name):
"""Tells the dispatcher to send over files needed to complete the job"""
self.map_host[slave_name].send_files(file_names)
def upload_file(self, file_names, slave_name, local_path=None):
"""Tells the dispatcher to retrieve the target file after the job is done"""
self.map_host[slave_name].get_files(file_names, local_folder=local_path)
# main program
def main_dispatcher():
Pyro4.config.SERIALIZER = 'pickle'
Pyro4.config.SERIALIZERS_ACCEPTED = ['pickle']
if len(argv) != 3:
print("Not enough args")
exit(-1)
print(argv[2])
ns = Pyro4.naming.locateNS(host=argv[2])
dispatcher = Dispatcher(argv[1])
Pyro4.config.HOST = argv[2]
daemon = Pyro4.core.Daemon()
uri = daemon.register(dispatcher)
ns.register(DISPATCHER_NAME, uri)
print("Dispatcher initialised and registered.")
print(AllJobsCompleted.__module__)
daemon.requestLoop()
if __name__ == '__main__':
main_dispatcher()