2015-11-07 18:39:39 +08:00
|
|
|
#!/usr/bin/env python3.5
|
2014-10-05 16:25:31 +08:00
|
|
|
|
|
|
|
import asyncio
|
2014-10-25 11:34:52 +08:00
|
|
|
import argparse
|
2014-12-31 17:41:22 +08:00
|
|
|
import atexit
|
2015-02-03 22:06:45 +08:00
|
|
|
import os
|
2016-02-17 01:07:13 +08:00
|
|
|
import logging
|
2014-10-05 16:25:31 +08:00
|
|
|
|
2016-02-18 22:35:02 +08:00
|
|
|
from artiq.tools import (simple_network_args, atexit_register_coroutine,
|
|
|
|
bind_address_from_args)
|
2015-10-16 00:53:35 +08:00
|
|
|
from artiq.protocols.pc_rpc import Server as RPCServer
|
2015-10-14 01:06:57 +08:00
|
|
|
from artiq.protocols.sync_struct import Publisher
|
2015-10-16 00:53:35 +08:00
|
|
|
from artiq.protocols.logging import Server as LoggingServer
|
2016-01-27 03:31:42 +08:00
|
|
|
from artiq.master.log import log_args, init_log
|
2015-10-12 17:18:23 +08:00
|
|
|
from artiq.master.databases import DeviceDB, DatasetDB
|
2015-01-14 12:16:49 +08:00
|
|
|
from artiq.master.scheduler import Scheduler
|
2016-02-16 01:20:50 +08:00
|
|
|
from artiq.master.worker_db import RIDCounter
|
2016-02-17 01:07:13 +08:00
|
|
|
from artiq.master.experiments import (FilesystemBackend, GitBackend,
|
|
|
|
ExperimentDB)
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
2014-10-05 16:25:31 +08:00
|
|
|
|
|
|
|
|
2015-01-23 00:52:13 +08:00
|
|
|
def get_argparser():
|
2014-12-08 19:22:02 +08:00
|
|
|
parser = argparse.ArgumentParser(description="ARTIQ master")
|
2015-10-14 01:06:57 +08:00
|
|
|
|
2015-12-27 18:03:13 +08:00
|
|
|
simple_network_args(parser, [
|
|
|
|
("notify", "notifications", 3250),
|
|
|
|
("control", "control", 3251),
|
|
|
|
("logging", "remote logging", 1066)
|
|
|
|
])
|
2015-10-14 01:06:57 +08:00
|
|
|
|
2015-08-08 11:13:36 +08:00
|
|
|
group = parser.add_argument_group("databases")
|
2015-10-12 17:18:23 +08:00
|
|
|
group.add_argument("--device-db", default="device_db.pyon",
|
|
|
|
help="device database file (default: '%(default)s')")
|
|
|
|
group.add_argument("--dataset-db", default="dataset_db.pyon",
|
|
|
|
help="dataset file (default: '%(default)s')")
|
2015-10-14 01:06:57 +08:00
|
|
|
|
2015-08-07 15:51:56 +08:00
|
|
|
group = parser.add_argument_group("repository")
|
|
|
|
group.add_argument(
|
|
|
|
"-g", "--git", default=False, action="store_true",
|
|
|
|
help="use the Git repository backend")
|
|
|
|
group.add_argument(
|
|
|
|
"-r", "--repository", default="repository",
|
|
|
|
help="path to the repository (default: '%(default)s')")
|
2014-10-25 11:34:52 +08:00
|
|
|
|
2015-10-14 01:06:57 +08:00
|
|
|
log_args(parser)
|
2015-07-22 05:13:50 +08:00
|
|
|
|
2015-10-14 01:06:57 +08:00
|
|
|
return parser
|
2015-07-22 05:13:50 +08:00
|
|
|
|
|
|
|
|
2014-10-05 16:25:31 +08:00
|
|
|
def main():
|
2015-01-23 00:52:13 +08:00
|
|
|
args = get_argparser().parse_args()
|
2015-10-16 00:53:35 +08:00
|
|
|
log_buffer = init_log(args)
|
2015-02-04 14:44:39 +08:00
|
|
|
if os.name == "nt":
|
2015-02-03 22:06:45 +08:00
|
|
|
loop = asyncio.ProactorEventLoop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
else:
|
|
|
|
loop = asyncio.get_event_loop()
|
2015-11-11 16:22:12 +08:00
|
|
|
atexit.register(loop.close)
|
2014-12-31 17:41:22 +08:00
|
|
|
|
2015-10-12 17:18:23 +08:00
|
|
|
device_db = DeviceDB(args.device_db)
|
|
|
|
dataset_db = DatasetDB(args.dataset_db)
|
|
|
|
dataset_db.start()
|
2015-11-11 16:22:12 +08:00
|
|
|
atexit_register_coroutine(dataset_db.stop)
|
2015-07-22 05:13:50 +08:00
|
|
|
|
2015-08-07 15:51:56 +08:00
|
|
|
if args.git:
|
|
|
|
repo_backend = GitBackend(args.repository)
|
|
|
|
else:
|
|
|
|
repo_backend = FilesystemBackend(args.repository)
|
2016-01-27 03:31:42 +08:00
|
|
|
experiment_db = ExperimentDB(repo_backend, device_db.get_device_db)
|
2015-12-06 18:39:27 +08:00
|
|
|
atexit.register(experiment_db.close)
|
|
|
|
experiment_db.scan_repository_async()
|
2015-08-07 15:51:56 +08:00
|
|
|
|
2015-05-17 16:11:00 +08:00
|
|
|
worker_handlers = {
|
2015-10-12 19:46:31 +08:00
|
|
|
"get_device_db": device_db.get_device_db,
|
2015-10-12 17:18:23 +08:00
|
|
|
"get_device": device_db.get,
|
|
|
|
"get_dataset": dataset_db.get,
|
2016-01-27 03:31:42 +08:00
|
|
|
"update_dataset": dataset_db.update
|
2015-02-20 03:09:11 +08:00
|
|
|
}
|
2016-02-16 01:20:50 +08:00
|
|
|
scheduler = Scheduler(RIDCounter(), worker_handlers, experiment_db)
|
2015-10-30 13:41:18 +08:00
|
|
|
worker_handlers.update({
|
|
|
|
"scheduler_submit": scheduler.submit,
|
|
|
|
"scheduler_delete": scheduler.delete,
|
|
|
|
"scheduler_request_termination": scheduler.request_termination,
|
|
|
|
"scheduler_get_status": scheduler.get_status
|
|
|
|
})
|
2015-03-09 23:22:41 +08:00
|
|
|
scheduler.start()
|
2015-11-11 16:22:12 +08:00
|
|
|
atexit_register_coroutine(scheduler.stop)
|
2014-12-31 17:41:22 +08:00
|
|
|
|
2015-12-27 18:03:13 +08:00
|
|
|
bind = bind_address_from_args(args)
|
|
|
|
|
2015-10-16 00:53:35 +08:00
|
|
|
server_control = RPCServer({
|
2015-10-12 17:18:23 +08:00
|
|
|
"master_device_db": device_db,
|
|
|
|
"master_dataset_db": dataset_db,
|
2015-01-26 23:37:33 +08:00
|
|
|
"master_schedule": scheduler,
|
2015-12-06 18:39:27 +08:00
|
|
|
"master_experiment_db": experiment_db
|
2014-12-31 20:13:10 +08:00
|
|
|
})
|
|
|
|
loop.run_until_complete(server_control.start(
|
2015-12-27 18:03:13 +08:00
|
|
|
bind, args.port_control))
|
2015-11-11 16:22:12 +08:00
|
|
|
atexit_register_coroutine(server_control.stop)
|
2014-12-31 17:41:22 +08:00
|
|
|
|
2014-12-31 20:13:10 +08:00
|
|
|
server_notify = Publisher({
|
2015-05-17 16:11:00 +08:00
|
|
|
"schedule": scheduler.notifier,
|
2015-10-12 17:18:23 +08:00
|
|
|
"devices": device_db.data,
|
|
|
|
"datasets": dataset_db.data,
|
2015-12-06 18:39:27 +08:00
|
|
|
"explist": experiment_db.explist,
|
2016-03-18 00:40:17 +08:00
|
|
|
"explist_status": experiment_db.status,
|
2015-10-14 01:06:57 +08:00
|
|
|
"log": log_buffer.data
|
2014-12-31 17:41:22 +08:00
|
|
|
})
|
2014-12-31 20:13:10 +08:00
|
|
|
loop.run_until_complete(server_notify.start(
|
2015-12-27 18:03:13 +08:00
|
|
|
bind, args.port_notify))
|
2015-11-11 16:22:12 +08:00
|
|
|
atexit_register_coroutine(server_notify.stop)
|
2014-12-31 17:41:22 +08:00
|
|
|
|
2015-10-16 00:53:35 +08:00
|
|
|
server_logging = LoggingServer()
|
|
|
|
loop.run_until_complete(server_logging.start(
|
2015-12-27 18:03:13 +08:00
|
|
|
bind, args.port_logging))
|
2015-11-11 16:22:12 +08:00
|
|
|
atexit_register_coroutine(server_logging.stop)
|
2015-10-16 00:53:35 +08:00
|
|
|
|
2016-02-18 22:35:02 +08:00
|
|
|
logger.info("running, bound to %s", bind)
|
2014-12-31 17:41:22 +08:00
|
|
|
loop.run_forever()
|
2014-10-05 16:25:31 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|