From 1a42e41157b559e31e25a34d5e0d8f245045b2d6 Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 21 Mar 2018 09:28:27 +0000 Subject: [PATCH] upd --- rbmd.py | 29 ++++++++++++++++++----------- static/rbmd/script.js | 20 +++++++++++--------- templates/rbmd/index.html | 1 - 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/rbmd.py b/rbmd.py index 2b9ecbb..662a507 100644 --- a/rbmd.py +++ b/rbmd.py @@ -16,7 +16,6 @@ import threading import os.path import uuid - from tornado.options import define, options define("port", default=8000, help="run on the given port", type=int) @@ -33,7 +32,6 @@ class Application(tornado.web.Application): (r"/status", StatusHandler), (r"/user", User), (r"/login", Auth), - ] settings = dict( cookie_secret="=&r854^9nk7ys49@m7a5eu(g&jn8pytk6f%@quumabt*x5e*)i", @@ -49,6 +47,8 @@ class Application(tornado.web.Application): class MainHandler(tornado.web.RequestHandler): @tornado.web.authenticated def get(self): + logging.info(tornado.escape.xhtml_escape(self.current_user)) + logging.info('123') user_id = self.get_secure_cookie("user") ws = config("ws") try: metrics = json.loads(action('metrics', 'get')) @@ -63,7 +63,7 @@ class MainHandler(tornado.web.RequestHandler): class Auth(tornado.web.RequestHandler): def get(self): - self.render("login.html", error=None) + self.render("login.html", error=None) def post(self): con = sqlite3.connect(options.sqlite_db) @@ -84,7 +84,7 @@ class Auth(tornado.web.RequestHandler): self.render("login.html", error="incorrect password") -#create new user +#create new user /user?name=user_name&password=user_password class User(tornado.web.RequestHandler): def get(self): con = sqlite3.connect(options.sqlite_db) @@ -108,6 +108,7 @@ class MountHandler(tornado.web.RequestHandler): if self.get_secure_cookie("user"): data = {k: v[0] for k, v in self.request.arguments.items()} res = action('mount', 'post', json.dumps(data)) + self.write(res) class UnmountHandler(tornado.web.RequestHandler): @@ -115,6 +116,7 @@ class UnmountHandler(tornado.web.RequestHandler): #data = self.request.arguments data = {k: v[0] for k, v in self.request.arguments.items()} res = action('umount', 'post', json.dumps(data)) + self.write(res) class ResolveHandler(tornado.web.RequestHandler): @@ -123,6 +125,7 @@ class ResolveHandler(tornado.web.RequestHandler): #data = self.request.arguments data = {k: v[0] for k, v in self.request.arguments.items()} res = action('resolve', 'post', json.dumps(data)) + self.write(res) class StatusHandler(tornado.web.RequestHandler): pass @@ -136,17 +139,23 @@ class SocketHandler(tornado.websocket.WebSocketHandler): return {} def check_origin(self, origin): - return True + return True def open(self): SocketHandler.waiters.add(self) SocketHandler.send_updates(SocketHandler.quorum) - + def on_close(self): SocketHandler.waiters.remove(self) @classmethod def send_updates(cls, data, *stat): + #SocketHandler.quorum = data + if json.loads(data)["health"] == "deadly.": + dead_data = action('status', 'get') + my_data = json.loads(data) + my_data["deadlyreason"] = json.loads(dead_data)["deadlyreason"] + data = json.dumps(my_data) SocketHandler.quorum = data for waiter in cls.waiters: try: @@ -154,8 +163,8 @@ class SocketHandler(tornado.websocket.WebSocketHandler): except: logging.error("Error sending message", exc_info=True) - def on_message(self, message): - logging.info(logging.info(message)) + def on_message(self, message): pass + # logging.info(message) def config(point): with open('conf.json') as conf: @@ -165,8 +174,6 @@ def config(point): def action(name, method, data=None): with open('conf.json') as conf: url = json.load(conf)["api"] + '/' + name - logging.info(url) - logging.info(data) if method == 'get': try: res = requests.get(url).content @@ -181,7 +188,7 @@ def action(name, method, data=None): def zk_handler(): - logging.basicConfig() + logging.basicConfig() #???????????????????????? zk = KazooClient(hosts=config("zookeeper")) zk.start() t1 = threading.Thread(target=DataWatch, args=(zk, "/rbmd/log/quorum"), kwargs=dict(func=SocketHandler.send_updates)) diff --git a/static/rbmd/script.js b/static/rbmd/script.js index 72a09ea..234e31d 100644 --- a/static/rbmd/script.js +++ b/static/rbmd/script.js @@ -64,17 +64,17 @@ $(function() { $( "#statusContainer:contains('deadly')" ).css("background-color", "#f44336" );; var node2 = a; w3DisplayData("id01", node2); - $('.tablink').css('display', 'block'); + $('.tablink').css('display', 'block'); if (selected_node != undefined && selected_node != 'dead'){ //a.quorum.forEach(function(item) {if (item.node == selected_node) { console.log(item.node)}}) - var selected_node_body = a.quorum.find(function(node) { return node.node == selected_node}); + var selected_node_body = a.quorum.find(function(node) { return node.node == selected_node}); var t = new Date(selected_node_body["updated"] * 1000) - var up_formatted = t.getFullYear() + "/" + - (t.getMonth() + 1) + "/" + - t.getDate() + " " + - t.getHours() + ":" + - t.getMinutes() + ":" + - t.getSeconds(); + var up_formatted = t.getFullYear() + "/" + + (t.getMonth() + 1) + "/" + + t.getDate() + " " + + t.getHours() + ":" + + t.getMinutes() + ":" + + t.getSeconds(); $("#name").html(selected_node); $("#ipv4").html(selected_node_body["ip"]["v4"].join("
")); $("#ipv6").html(selected_node_body["ip"]["v6"].join("
")); @@ -99,6 +99,7 @@ $(function() { } if (selected_node =='dead') { var t, up_formatted + console.log(a.deadlyreason); if (a.deadlyreason["updated"] != 0) { t = new Date(a.deadlyreason["updated"] * 1000) up_formatted = t.getFullYear() + "/" + (t.getMonth() + 1) + "/" + t.getDate() + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds(); @@ -119,7 +120,8 @@ $(function() { } $("#leader").html(a.leader); - } + } + function openNode(evt, nodeName) { var i, x, tablinks; selected_node = nodeName; diff --git a/templates/rbmd/index.html b/templates/rbmd/index.html index ae3d9b3..2fff30d 100644 --- a/templates/rbmd/index.html +++ b/templates/rbmd/index.html @@ -76,7 +76,6 @@ var a, selected_node, deadNode; ws.onopen = function() {ws.send(""); }; ws.onmessage = function (evt) { - console.log(evt.data); a = JSON.parse(evt.data); displayData(a); };