Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Backend UI Work #1

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions webui/backend/ray_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async def hgetall_as_dict(redis_conn, key):

# Cache information about the local schedulers.
local_schedulers = {}
errors = []

def duration_to_string(duration):
"""Format a duration in seconds as a string.
Expand Down Expand Up @@ -125,6 +126,35 @@ async def handle_get_drivers(websocket, redis_conn):
reply = sorted(drivers, key=(lambda driver: driver["start time"]))[::-1]
await websocket.send(json.dumps(reply))

async def listen_for_errors(redis_ip_address, redis_port):
pubsub_conn = await aioredis.create_connection((redis_ip_address, redis_port), loop=loop)
data_conn = await aioredis.create_connection((redis_ip_address, redis_port), loop=loop)

error_pattern = "__keyspace@0__:ErrorKeys"
psub = await pubsub_conn.execute_pubsub("psubscribe", error_pattern)
channel = pubsub_conn.pubsub_patterns[error_pattern]
print("Listening for error messages...")
index = 0
while (await channel.wait_message()):
msg = await channel.get()
info = await data_conn.execute("lrange", "ErrorKeys", index, -1)

for error_key in info:
worker, task = key_to_hex_identifiers(error_key)
# TODO(richard): Filter out workers so that only relevant task errors are
# necessary.
result = await data_conn.execute("hget", error_key, "message")
result = result.decode("ascii")
# TODO(richard): Maybe also get rid of the coloring.
errors.append({"driver_id": worker,
"task_id": task,
"error": result})
index += 1

async def handle_get_errors(websocket):
"""Send error messages to the frontend."""
await websocket.send(json.dumps(errors))

node_info = collections.OrderedDict()
worker_info = collections.OrderedDict()

Expand Down Expand Up @@ -245,12 +275,18 @@ async def send_heartbeats(websocket, redis_conn):
continue
local_schedulers[local_scheduler_id]["last_heartbeat"] = time.time()

async def serve_requests(websocket, path):
redis_conn = await aioredis.create_connection((redis_ip_address, redis_port), loop=loop)
async def cache_data_from_redis(redis_ip_address, redis_port):
"""Open up ports to listen for new updates from Redis."""
# TODO(richard): A lot of code needs to be ported in order to open new
# websockets.

asyncio.ensure_future(listen_for_errors(redis_ip_address, redis_port))

async def serve_requests(websocket, path):
# We loop infinitely because otherwise the websocket will be closed.
# TODO(rkn): Maybe we should open a new web sockets for every request instead
# of looping here.
redis_conn = await aioredis.create_connection((redis_ip_address, redis_port), loop=loop)
while True:
command = json.loads(await websocket.recv())
print("received command {}".format(command))
Expand All @@ -261,6 +297,8 @@ async def serve_requests(websocket, path):
await handle_get_drivers(websocket, redis_conn)
elif command["command"] == "get-recent-tasks":
await handle_get_recent_tasks(websocket, redis_conn, command["num"])
elif command["command"] == "get-errors":
await handle_get_errors(websocket)
elif command["command"] == "get-heartbeats":
await send_heartbeats(websocket, redis_conn)

Expand Down Expand Up @@ -335,9 +373,12 @@ async def serve_requests(websocket, path):
redis_ip_address, redis_port = redis_address[0], int(redis_address[1])

# The port here must match the value used by the frontend to connect over
# websockets.
# websockets. TODO(richard): Automatically increment the port if it is already
# taken.
port = 8888
start_server = websockets.serve(serve_requests, "localhost", port)

loop.run_until_complete(cache_data_from_redis(redis_ip_address, redis_port))

start_server = websockets.serve(serve_requests, "localhost", port)
loop.run_until_complete(start_server)
loop.run_forever()
10 changes: 0 additions & 10 deletions webui/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<!--
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<!doctype html>
<html lang="en">
<head>
Expand Down
12 changes: 2 additions & 10 deletions webui/src/ray-app.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<!--
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/app-layout/app-drawer/app-drawer.html">
<link rel="import" href="../bower_components/app-layout/app-drawer-layout/app-drawer-layout.html">
Expand Down Expand Up @@ -75,6 +65,7 @@
<a name="objects" href="/objects">Objects</a>
<a name="tasks" href="/tasks">Tasks</a>
<a name="events" href="/events">Events</a>
<a name="errors" href="/errors">Errors</a>
<a name="timeline" href="/timeline">Timeline</a>
<a name="recent-tasks" href="/recent-tasks">Recent Tasks</a>
</iron-selector>
Expand All @@ -100,6 +91,7 @@
<ray-objects name="objects"></ray-objects>
<ray-tasks name="tasks"></ray-tasks>
<ray-events name="events"></ray-events>
<ray-errors name="errors"></ray-errors>
<ray-timeline name="timeline"></ray-timeline>
<ray-recent-tasks name="recent-tasks"></ray-recent-tasks>
<ray-view404 name="view404"></ray-view404>
Expand Down
46 changes: 46 additions & 0 deletions webui/src/ray-errors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="shared-styles.html">

<dom-module id="ray-errors">
<template>
<style include="shared-styles">
:host {
display: block;

padding: 10px;
}
</style>

<div class="card">
<h1>Errors</h1>
<vaadin-grid id="errors">
<table>
<colgroup>
<col name="driver_id" sortable="" sort-direction="desc"/>
<col name="task_id" sortable="" sort-direction="desc"/>
<col name="error" sortable="" sort-direction="desc"/>
</colgroup>
</table>
</vaadin-grid>
</div>
</template>

<script>
var backend_address = "ws://127.0.0.1:8888";
Polymer({
is: 'ray-errors',
ready: function() {
var eventSocket = new WebSocket(backend_address);
var errors = Polymer.dom(this.root).querySelector("#errors");

eventSocket.onopen = function() {
eventSocket.send(JSON.stringify({"command": "get-errors"}));
}
eventSocket.onmessage = function(answer) {
console.dir(answer.data);
errors.items = JSON.parse(answer.data);
}
}
});
</script>
</dom-module>
10 changes: 0 additions & 10 deletions webui/src/ray-events.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<!--
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="shared-styles.html">

Expand Down
12 changes: 1 addition & 11 deletions webui/src/ray-icons.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<!--
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../bower_components/iron-icon/iron-icon.html">
<link rel="import" href="../bower_components/iron-iconset-svg/iron-iconset-svg.html">

Expand All @@ -28,4 +18,4 @@
</g>
</defs>
</svg>
</iron-iconset-svg>
</iron-iconset-svg>
10 changes: 0 additions & 10 deletions webui/src/ray-objects.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<!--
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="shared-styles.html">

Expand Down
10 changes: 0 additions & 10 deletions webui/src/ray-overview.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<!--
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="shared-styles.html">

Expand Down
10 changes: 0 additions & 10 deletions webui/src/ray-tasks.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<!--
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="shared-styles.html">

Expand Down
10 changes: 0 additions & 10 deletions webui/src/ray-timeline.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<!--
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="shared-styles.html">

Expand Down