3 # Copyright 2016 RIFT.IO Inc
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
23 import tornado
.httpserver
27 PongAdminStatusHandler
,
31 from util
.util
import (
35 logging
.basicConfig(level
=logging
.DEBUG
,
36 format
='(%(threadName)-10s) %(name)-8s :: %(message)s',
40 log
= logging
.getLogger("main")
43 parser
= argparse
.ArgumentParser()
45 "--pong-manager-port",
48 help="port number for pong")
53 help="ip address of pong")
55 arguments
= parser
.parse_args()
58 log
.debug("setup application")
59 pong_instance
= Pong(arguments
.worker_count
)
60 pong_application_arguments
= {'pong_instance': pong_instance
}
61 pong_application
= tornado
.web
.Application([
62 (r
"/version", VersionHandler
, pong_application_arguments
),
63 (r
"/api/v1/pong/stats", PongStatsHandler
, pong_application_arguments
),
64 (r
"/api/v1/pong/server/?([0-9a-z\.]*)", PongServerHandler
, pong_application_arguments
),
65 (r
"/api/v1/pong/adminstatus/([a-z]+)", PongAdminStatusHandler
, pong_application_arguments
)
67 pong_server
= tornado
.httpserver
.HTTPServer(
70 # setup SIGINT handler
71 log
.debug("setup SIGINT handler")
72 def signal_handler(signal
, frame
):
73 print("") # print newline to clear user input
80 signal
.signal(signal
.SIGINT
, signal_handler
)
83 log
.debug("pong application listening on %s" % arguments
.pong_manager_port
)
85 pong_server
.listen(arguments
.pong_manager_port
)
87 print("port %s is already is use, exiting" % arguments
.ping_manager_port
)
89 tornado
.ioloop
.IOLoop
.instance().start()
91 if __name__
== "__main__":