This commit is contained in:
Anna Sudnitsina 2018-04-06 13:03:23 +03:00
parent 8e2f54e7c9
commit cbd019ed26
5 changed files with 38 additions and 19 deletions

38
rbmd.py
View File

@ -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():

14
requirements_new.txt Normal file
View File

@ -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

View File

@ -7,6 +7,7 @@ $(function() {
ws.onopen = function() {ws.send(""); };
ws.onmessage = function (evt) {
a = JSON.parse(evt.data);
console.log(a);
displayData(a);
};

View File

@ -38,7 +38,7 @@
</div>
<div class="w3-col m9" >
<div class="w3-container" id="statusContainer">
<div class="w3-padding w3-display-left" id="status">Status... </div>
<div class="w3-padding w3-display-left" id="status">Connecting... </div>
<a href="javascript:void(0)" class="w3-right" id="showDeadlyDetails" onclick="openNode(event, deadNode)">
Show details
</a>

View File

@ -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(