Skip to content

Commit

Permalink
Refactored tree view. Added data view for servers-- fixes #1218.
Browse files Browse the repository at this point in the history
  • Loading branch information
mglukhovsky committed Oct 14, 2012
1 parent 3f3b42d commit e1b26a2
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 123 deletions.
2 changes: 1 addition & 1 deletion admin/static/coffee/namespaces/namespace.html
Expand Up @@ -27,7 +27,7 @@ <h2 class="title">Statistics</h3>
<div class="section replication"></div>
</div>
</div>
<div class="section server-assignments"></div>
<div class="section server-assignments tree-view"></div>
</div>
</script>

Expand Down
2 changes: 1 addition & 1 deletion admin/static/coffee/namespaces/server_assignments.coffee
Expand Up @@ -31,7 +31,7 @@ module 'NamespaceView', ->
machine.num_keys += parseInt(keys) if typeof keys is 'string'
machine.num_primaries += 1 if role is 'role_primary'
machine.num_secondaries += 1 if role is 'role_secondary'
machine['shards'].push
machine.shards.push
name: human_readable_shard shard
keys: parseInt(keys) if typeof keys is 'string'
role: role
Expand Down
10 changes: 5 additions & 5 deletions admin/static/coffee/namespaces/server_assignments.html
Expand Up @@ -2,9 +2,9 @@
<h2 class="title">Servers used by this table</h2>
<ul class="datacenters">
{{#each datacenters}}
<li class="datacenter">
<li class="datacenter parent">
<div class="tree-line"></div>
<div class="datacenter-info">
<div class="datacenter-info parent-info">
<p class="name">
{{#unless is_universe}}
Datacenter <a href="/#datacenters/{{id}}">{{name}}</a>
Expand All @@ -13,11 +13,11 @@ <h2 class="title">Servers used by this table</h2>
{{/unless}}
</p>
</div>
<ul class="machines">
<ul class="servers">
{{#each machines}}
<li class="machine">
<li class="server child">
<div class="tree-node"></div>
<div class="machine-info">
<div class="server-info child-info">
<p class="name"><a href="/#servers/{{id}}">{{name}}</a></p>
<p class="num-primaries"><span class="highlight">{{num_primaries}}</span> primaries</p>
<p class="num-secondaries"><span class="highlight">{{num_secondaries}}</span> secondaries</p>
Expand Down
86 changes: 37 additions & 49 deletions admin/static/coffee/servers/machine.coffee
Expand Up @@ -34,7 +34,6 @@ module 'MachineView', ->
events: ->
'click .close': 'close_alert'
'click .tab-link': 'change_route'
'click .show-data': 'show_data'
# operations in the dropdown menu
'click .operations .rename': 'rename_machine'
'click .operations .change-datacenter': 'change_datacenter'
Expand All @@ -52,6 +51,7 @@ module 'MachineView', ->
seconds: 73 # num seconds to track
type: 'server'
)
@data = new MachineView.Data model: @model
@logs = new LogView.Container
route: "/ajax/log/"+@model.get('id')+"_?"
type: 'machine'
Expand Down Expand Up @@ -88,6 +88,9 @@ module 'MachineView', ->
@.$('.profile').html @profile.render().$el
@.$('.performance-graph').html @performance_graph.render().$el

# data on this server
@.$('.server-data').html @data.render().$el

# log entries
@.$('.recent-log-entries').html @logs.render().$el

Expand All @@ -106,12 +109,6 @@ module 'MachineView', ->
event.preventDefault()
$(event.currentTarget).parent().slideUp('fast', -> $(this).remove())

# Pop up a modal to show assignments
show_data: (event) =>
event.preventDefault()
modal = new MachineView.DataModal model: @model
modal.render()

rename_machine: (event) =>
event.preventDefault()
rename_modal = new UIComponents.RenameItemModal @model.get('id'), 'machine'
Expand All @@ -132,6 +129,7 @@ module 'MachineView', ->
@title.destroy()
@profile.destroy()
@performance_graph.destroy()
@data.destroy()
@logs.destroy()
@model.off '', @render_can_unassign_button

Expand Down Expand Up @@ -188,7 +186,6 @@ module 'MachineView', ->
assigned_to_datacenter: datacenter_uuid
datacenter_name: datacenters.get(datacenter_uuid).get('name')


# Reachability
_.extend json,
reachability: DataUtils.get_machine_reachability(@model.get('id'))
Expand Down Expand Up @@ -242,58 +239,49 @@ module 'MachineView', ->
machines.get(@model.get('id')).set('datacenter_uuid', null)
clear_modals()

class @DataModal extends UIComponents.AbstractModal
render: =>
@data = new MachineView.Data(model: @model)
$('#modal-dialog').html @data.render().$el
modal = $('.modal').modal
'show': true
'backdrop': true
'keyboard': true

modal.on 'hidden', =>
modal.remove()

class @Data extends Backbone.View
className: 'machine-data-view modal overwrite_modal'
template: Handlebars.compile $('#machine_view_data-template').html()

initialize: =>
@namespaces_with_listeners = {}

namespaces.on 'change:blueprint', @render
namespaces.on 'change:key_distr', @render
namespaces.each (namespace) -> namespace.load_key_distr()

render: =>
json = {}
# If the machine is reachable, add relevant json
_namespaces = []
for namespace in namespaces.models
_shards = []
for machine_uuid, peer_roles of namespace.get('blueprint').peers_roles
if machine_uuid is @model.get('id')
data_by_namespace = []

# Examine each namespace and collect info on its shards / attach listeners to count the number of keys
namespaces.each (namespace) =>
ns =
name: namespace.get('name')
id: namespace.get('id')
shards: []
# Examine each machine's role for the namespace-- only consider namespaces that actually use this machine
for machine_id, peer_roles of namespace.get('blueprint').peers_roles
if machine_id is @model.get('id')
# Build up info on each shard present on this machine for this namespace
for shard, role of peer_roles
if role isnt 'role_nothing'
keys = namespace.compute_shard_rows_approximation shard
_shards[_shards.length] =
shard: shard
ns.shards.push
name: human_readable_shard shard
keys: keys if typeof keys is 'string'
if _shards.length > 0
if not @namespaces_with_listeners[namespace.get('id')]?
@namespaces_with_listeners[namespace.get('id')] = true
namespace.load_key_distr()
namespace.on 'change:key_distr', @render

_namespaces.push
shards: _shards
name: namespace.get('name')
uuid: namespace.get('id')

json = _.extend json,
data:
namespaces: _namespaces
num_keys: parseInt(keys) if typeof keys is 'string'
role: role
secondary: role is 'role_secondary'
primary: role is 'role_primary'

# Finished building, add it to the list
data_by_namespace.push ns


@.$el.html @template
# Sort the tables alphabetically by name
tables: _.sortBy(data_by_namespace, (namespace) -> namespace.name)

@.$el.html @template(json)
return @

destroy: =>
for namespace_id of @namespaces_with_listeners
namespaces.get(namespace_id).off 'change:key_distr', @render
namespaces.get(namespace_id).clear_timeout()
namespaces.off 'change:blueprint'
namespaces.off 'change:key_distr'
64 changes: 36 additions & 28 deletions admin/static/coffee/servers/machine.html
Expand Up @@ -10,7 +10,6 @@
</ul>
</div>
</div>
<button class="btn show-data">Show data on this server</button>
<div class="main_title"></div>
<div id="user-alert-space"></div>
<div class="section statistics">
Expand All @@ -20,6 +19,7 @@ <h2 class="title">Statistics</h3>
<div class="span8 performance-graph"></div>
</div>
</div>
<div class="section server-data tree-view"></div>
<div class="recent-log-entries"></div>
</div>
</script>
Expand All @@ -46,7 +46,7 @@ <h1>Error</h1>
{{#if assigned_to_datacenter}}
<span class="big">{{datacenter_name}} </span> datacenter
{{else}}
<span class="big">Unassigned </span>datacenter
<span jaclass="big">Unassigned </span>datacenter
{{/if}}
</p>
</div>
Expand All @@ -57,36 +57,44 @@ <h1>Error</h1>
<p class="ips"><span class="big">{{#if ips}}{{main_ip}}{{else}}N/A{{/if}} </span>IP address</p>
</div>
</div>
<!-- Review and remove
{{#unless stats_up_to_date}}
<p>The stats displayed might not be up to date<br />
(the server might be overload with queries).</p>
{{/unless}}
-->
</script>

<script id="machine_view_data-template" type="text/x-handlebars-template">
<h3 class="title">Data on this server</h3>
{{#unless data.namespaces}}
<p>No data found on this server.</p>
{{/unless}}
{{#each data.namespaces}}
<div class="namespace">
<h4>Table <a href="/#tables/{{uuid}}">{{name}}</a>:</h4>
<ul class="shard_ul">
{{#each shards}}
<li class="shard_li">
<h4>Shard {{name}}</h4>
{{#if keys}}
<p>About {{keys}} keys</p>
{{else}}
<p>Loading number of keys...</p>
{{/if}}
<h2 class="title">Data on this server</h2>
<ul class="tables">
{{#each tables}}
<li class="table parent">
<div class="tree-line"></div>
<div class="table-info parent-info">
<p class="name">Table {{name}}</p>
</div>
<ul class="shards">
{{#each shards}}
<li class="shard child">
<div class="tree-node"></div>
<div class="shard-info child-info">
<p class="name">{{name}}</p>
<p class="role"><span class="highlight">
{{#if primary}}
Primary
{{else}}{{#if secondary}}
Secondary
{{/if}}{{/if}}
</span> Role</p>
<p class="num-keys">
{{#if num_keys}}
<span class="highlight">~{{num_keys}}</span> documents
{{else}}
<span class="highlight">N/A</span> documents
{{/if}}
</p>
</div>
</li>
{{/each}}
</ul>
</li>
{{/each}}
</ul>
</div>
{{/each}}
{{/each}}
</ul>
</script>

<script id="reason-set_secondary-need_replica-template" type="text/x-handlebars-template">
Expand Down

0 comments on commit e1b26a2

Please sign in to comment.