upd
This commit is contained in:
parent
8e2f54e7c9
commit
cbd019ed26
38
rbmd.py
38
rbmd.py
|
@ -30,7 +30,6 @@ class Application(tornado.web.Application):
|
||||||
(r"/unmount", UnmountHandler),
|
(r"/unmount", UnmountHandler),
|
||||||
(r"/resolve", ResolveHandler),
|
(r"/resolve", ResolveHandler),
|
||||||
(r"/status", StatusHandler),
|
(r"/status", StatusHandler),
|
||||||
(r"/user", User),
|
|
||||||
(r"/login", Auth),
|
(r"/login", Auth),
|
||||||
]
|
]
|
||||||
settings = dict(
|
settings = dict(
|
||||||
|
@ -47,14 +46,10 @@ class Application(tornado.web.Application):
|
||||||
class MainHandler(tornado.web.RequestHandler):
|
class MainHandler(tornado.web.RequestHandler):
|
||||||
@tornado.web.authenticated
|
@tornado.web.authenticated
|
||||||
def get(self):
|
def get(self):
|
||||||
logging.info(tornado.escape.xhtml_escape(self.current_user))
|
|
||||||
logging.info('123')
|
|
||||||
user_id = self.get_secure_cookie("user")
|
user_id = self.get_secure_cookie("user")
|
||||||
# ws = config("ws")
|
|
||||||
try: metrics = json.loads(action('metrics', 'get'))
|
try: metrics = json.loads(action('metrics', 'get'))
|
||||||
except ValueError: metrics = {}
|
except ValueError: metrics = {}
|
||||||
my_status = zk_fetch("/rbmd/log/health") #action('status', 'get')
|
dct = {'metrics': metrics}
|
||||||
dct = {'metrics': metrics, 'status': my_status}
|
|
||||||
self.render("index.html", **dct)
|
self.render("index.html", **dct)
|
||||||
|
|
||||||
def get_current_user(self):
|
def get_current_user(self):
|
||||||
|
@ -83,7 +78,7 @@ class Auth(tornado.web.RequestHandler):
|
||||||
else:
|
else:
|
||||||
self.render("login.html", error="incorrect password")
|
self.render("login.html", error="incorrect password")
|
||||||
|
|
||||||
|
########### not used ##########################
|
||||||
#create new user /user?name=user_name&password=user_password
|
#create new user /user?name=user_name&password=user_password
|
||||||
class User(tornado.web.RequestHandler):
|
class User(tornado.web.RequestHandler):
|
||||||
def get(self):
|
def get(self):
|
||||||
|
@ -132,7 +127,7 @@ class StatusHandler(tornado.web.RequestHandler):
|
||||||
|
|
||||||
class SocketHandler(tornado.websocket.WebSocketHandler):
|
class SocketHandler(tornado.websocket.WebSocketHandler):
|
||||||
waiters = set()
|
waiters = set()
|
||||||
quorum = dict()
|
quorum = json.dumps(dict())
|
||||||
|
|
||||||
def get_compression_options(self):
|
def get_compression_options(self):
|
||||||
# Non-None enables compression with default options.
|
# Non-None enables compression with default options.
|
||||||
|
@ -151,12 +146,20 @@ class SocketHandler(tornado.websocket.WebSocketHandler):
|
||||||
@classmethod
|
@classmethod
|
||||||
def send_updates(cls, data, *stat):
|
def send_updates(cls, data, *stat):
|
||||||
#SocketHandler.quorum = data
|
#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')
|
dead_data = action('status', 'get')
|
||||||
my_data = json.loads(data)
|
my_data = json.loads(data)
|
||||||
my_data["deadlyreason"] = json.loads(dead_data)["deadlyreason"]
|
my_data["deadlyreason"] = json.loads(dead_data)["deadlyreason"]
|
||||||
data = json.dumps(my_data)
|
data = json.dumps(my_data)
|
||||||
SocketHandler.quorum = data
|
SocketHandler.quorum = data
|
||||||
|
logging.info('send_upd')
|
||||||
|
|
||||||
for waiter in cls.waiters:
|
for waiter in cls.waiters:
|
||||||
try:
|
try:
|
||||||
waiter.write_message(SocketHandler.quorum)
|
waiter.write_message(SocketHandler.quorum)
|
||||||
|
@ -188,20 +191,21 @@ def action(name, method, data=None):
|
||||||
|
|
||||||
|
|
||||||
def zk_handler():
|
def zk_handler():
|
||||||
logging.basicConfig() #????????????????????????
|
logging.basicConfig()
|
||||||
zk = KazooClient(hosts=config("zookeeper"))
|
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 = threading.Thread(target=DataWatch, args=(zk, "/rbmd/log/quorum"), kwargs=dict(func=SocketHandler.send_updates))
|
||||||
t1.setDaemon(True)
|
t1.setDaemon(True)
|
||||||
t1.start()
|
t1.start()
|
||||||
|
|
||||||
|
|
||||||
|
########### not used ##########################
|
||||||
def zk_fetch(path):
|
#def zk_fetch(path):
|
||||||
zk = KazooClient(hosts=config("zookeeper"))
|
# zk = KazooClient(hosts=config("zookeeper"))
|
||||||
zk.start()
|
# zk.start()
|
||||||
data = zk.get(path)
|
# data = zk.get(path)
|
||||||
zk.stop()
|
# zk.stop()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
14
requirements_new.txt
Normal file
14
requirements_new.txt
Normal 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
|
|
@ -7,6 +7,7 @@ $(function() {
|
||||||
ws.onopen = function() {ws.send(""); };
|
ws.onopen = function() {ws.send(""); };
|
||||||
ws.onmessage = function (evt) {
|
ws.onmessage = function (evt) {
|
||||||
a = JSON.parse(evt.data);
|
a = JSON.parse(evt.data);
|
||||||
|
console.log(a);
|
||||||
displayData(a);
|
displayData(a);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="w3-col m9" >
|
<div class="w3-col m9" >
|
||||||
<div class="w3-container" id="statusContainer">
|
<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)">
|
<a href="javascript:void(0)" class="w3-right" id="showDeadlyDetails" onclick="openNode(event, deadNode)">
|
||||||
Show details
|
Show details
|
||||||
</a>
|
</a>
|
||||||
|
|
2
users.py
2
users.py
|
@ -46,7 +46,7 @@ class User:
|
||||||
def add(self):
|
def add(self):
|
||||||
if self.password is None:
|
if self.password is None:
|
||||||
self.password = self._passgen()
|
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())
|
hashed_password = bcrypt.hashpw(self.password.encode('utf-8'), bcrypt.gensalt())
|
||||||
try:
|
try:
|
||||||
self.connection["cursor"].execute(
|
self.connection["cursor"].execute(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user