-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
68 lines (55 loc) · 2.7 KB
/
server.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
import tornado
from tornado.web import Application, StaticFileHandler
from tornado.httpserver import HTTPServer
from appliance import Appliance
from container import Container
from volume import PersistentVolume
from cluster.handler import ClusterInfoHandler
from appliance.handler import AppliancesHandler, ApplianceHandler
from appliance.ui.handler import ApplianceUIHandler
from container.handler import ContainersHandler, ContainerHandler, ServicesHandler, JobsHandler
from volume.handler import ApplianceVolumesHandler, ApplianceVolumeHandler, GlobalVolumeHandler
from cluster.manager import ClusterManager
from index.handler import IndexHandler
from ping.handler import PingHandler
from swagger.handler import SwaggerAPIHandler, SwaggerUIHandler
from config import config, get_global_scheduler
from schedule.universal import GlobalScheduleExecutor
from util import dirname
def start_cluster_monitor():
tornado.ioloop.IOLoop.instance().add_callback(ClusterManager().start_monitor)
def start_global_scheduler():
scheduler = GlobalScheduleExecutor(get_global_scheduler())
tornado.ioloop.IOLoop.instance().add_callback(scheduler.start_rescheduler)
def start_server():
app = Application([
(r'\/*', IndexHandler),
(r'/ping\/*', PingHandler),
(r'/cluster\/*', ClusterInfoHandler),
(r'/appliance\/*', AppliancesHandler),
(r'/appliance/(%s)\/*'%Appliance.ID_PATTERN, ApplianceHandler),
(r'/appliance/(%s)/container\/*'%Appliance.ID_PATTERN, ContainersHandler),
(r'/appliance/(%s)/volume\/*' % Appliance.ID_PATTERN, ApplianceVolumesHandler),
(r'/appliance/(%s)/service\/*'%Appliance.ID_PATTERN, ServicesHandler),
(r'/appliance/(%s)/job\/*'%Container.ID_PATTERN, JobsHandler),
(r'/appliance/(%s)/ui\/*'%Appliance.ID_PATTERN, ApplianceUIHandler),
(r'/appliance/(%s)/container/(%s)\/*'%(Appliance.ID_PATTERN,
Container.ID_PATTERN), ContainerHandler),
(r'/appliance/(%s)/volume/(%s)\/*'%(Appliance.ID_PATTERN,
PersistentVolume.ID_PATTERN), ApplianceVolumeHandler),
(r'/volume/(%s)\/*'%PersistentVolume.ID_PATTERN, GlobalVolumeHandler),
(r'/static/(.*)', StaticFileHandler, dict(path='%s/static'%dirname(__file__))),
(r'/api', SwaggerAPIHandler),
(r'/api/ui', SwaggerUIHandler),
])
ssl_options = None
if config.pivot.https:
ssl_options = dict(certfile='/etc/pivot/server.pem', keyfile='/etc/pivot/server.key')
server = tornado.httpserver.HTTPServer(app, ssl_options=ssl_options)
server.bind(config.pivot.port)
server.start(config.pivot.n_parallel)
start_cluster_monitor()
start_global_scheduler()
tornado.ioloop.IOLoop.instance().start()
if __name__ == '__main__':
start_server()