This commit is contained in:
Anna Sudnitsina 2018-03-21 09:28:27 +00:00
parent 76d402d07d
commit 1a42e41157
3 changed files with 29 additions and 21 deletions

29
rbmd.py
View File

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

View File

@ -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("<br>"));
$("#ipv6").html(selected_node_body["ip"]["v6"].join("<br>"));
@ -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;

View File

@ -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);
};