From cbd019ed268d4e161510d824ad424029c3658ae4 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 6 Apr 2018 13:03:23 +0300 Subject: [PATCH] upd --- rbmd.py | 38 +++++++++++++++++++++----------------- requirements_new.txt | 14 ++++++++++++++ static/rbmd/script.js | 1 + templates/rbmd/index.html | 2 +- users.py | 2 +- 5 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 requirements_new.txt diff --git a/rbmd.py b/rbmd.py index 417c0b3..2afb6a5 100644 --- a/rbmd.py +++ b/rbmd.py @@ -30,7 +30,6 @@ class Application(tornado.web.Application): (r"/unmount", UnmountHandler), (r"/resolve", ResolveHandler), (r"/status", StatusHandler), - (r"/user", User), (r"/login", Auth), ] settings = dict( @@ -47,14 +46,10 @@ 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')) except ValueError: metrics = {} - my_status = zk_fetch("/rbmd/log/health") #action('status', 'get') - dct = {'metrics': metrics, 'status': my_status} + dct = {'metrics': metrics} self.render("index.html", **dct) def get_current_user(self): @@ -83,7 +78,7 @@ class Auth(tornado.web.RequestHandler): else: self.render("login.html", error="incorrect password") - +########### not used ########################## #create new user /user?name=user_name&password=user_password class User(tornado.web.RequestHandler): def get(self): @@ -132,7 +127,7 @@ class StatusHandler(tornado.web.RequestHandler): class SocketHandler(tornado.websocket.WebSocketHandler): waiters = set() - quorum = dict() + quorum = json.dumps(dict()) def get_compression_options(self): # Non-None enables compression with default options. @@ -151,12 +146,20 @@ class SocketHandler(tornado.websocket.WebSocketHandler): @classmethod def send_updates(cls, data, *stat): #SocketHandler.quorum = data - if json.loads(data)["health"] == "deadly.": + if data == '{}': + my_data = json.loads(data) + my_data["health"] = 'service is not available' + my_data["quorum"] = [{"node":""}] + data = json.dumps(my_data) + #if json.loads(data)["health"] == "deadly.": + if json.loads(data).get("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 + logging.info('send_upd') + for waiter in cls.waiters: try: waiter.write_message(SocketHandler.quorum) @@ -188,20 +191,21 @@ def action(name, method, data=None): def zk_handler(): - logging.basicConfig() #???????????????????????? + logging.basicConfig() zk = KazooClient(hosts=config("zookeeper")) - zk.start() + try: zk.start() + except: return '{"health": "connection cant be established"}' t1 = threading.Thread(target=DataWatch, args=(zk, "/rbmd/log/quorum"), kwargs=dict(func=SocketHandler.send_updates)) t1.setDaemon(True) t1.start() - -def zk_fetch(path): - zk = KazooClient(hosts=config("zookeeper")) - zk.start() - data = zk.get(path) - zk.stop() +########### not used ########################## +#def zk_fetch(path): +# zk = KazooClient(hosts=config("zookeeper")) +# zk.start() +# data = zk.get(path) +# zk.stop() def main(): diff --git a/requirements_new.txt b/requirements_new.txt new file mode 100644 index 0000000..5619919 --- /dev/null +++ b/requirements_new.txt @@ -0,0 +1,14 @@ +backports-abc==0.5 +bcrypt==3.1.4 +certifi==2018.1.18 +cffi==1.11.5 +chardet==3.0.4 +futures==3.2.0 +idna==2.6 +kazoo==2.4.0 +pycparser==2.18 +requests==2.18.4 +singledispatch==3.4.0.3 +six==1.11.0 +tornado==5.0.1 +urllib3==1.22 diff --git a/static/rbmd/script.js b/static/rbmd/script.js index aa3e955..893df97 100644 --- a/static/rbmd/script.js +++ b/static/rbmd/script.js @@ -7,6 +7,7 @@ $(function() { ws.onopen = function() {ws.send(""); }; ws.onmessage = function (evt) { a = JSON.parse(evt.data); +console.log(a); displayData(a); }; diff --git a/templates/rbmd/index.html b/templates/rbmd/index.html index 716bb96..20378a1 100644 --- a/templates/rbmd/index.html +++ b/templates/rbmd/index.html @@ -38,7 +38,7 @@
-
Status...
+
Connecting...
Show details diff --git a/users.py b/users.py index 4c1dfab..cf65a1a 100755 --- a/users.py +++ b/users.py @@ -46,7 +46,7 @@ class User: def add(self): if self.password is None: self.password = self._passgen() - print "Password has been generated: %s", self.password + print "Password has been generated: ", self.password hashed_password = bcrypt.hashpw(self.password.encode('utf-8'), bcrypt.gensalt()) try: self.connection["cursor"].execute(