2012-03-07 11:30:20 -05:00
|
|
|
/*
|
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-01-05 05:50:24 -05:00
|
|
|
var zk_error = function zk_error( xhr, text_status, error_thrown )
|
|
|
|
{
|
|
|
|
var zk = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
eval( 'zk = ' + xhr.responseText + ';' );
|
|
|
|
}
|
|
|
|
catch( e ) {}
|
|
|
|
|
|
|
|
var message = '<p class="txt">Loading of "<code>' + xhr.url + '</code>" '
|
|
|
|
+ 'failed (HTTP-Status <code>' + xhr.status + '</code>)</p>' + "\n";
|
|
|
|
|
|
|
|
if( zk.error )
|
|
|
|
{
|
|
|
|
message += '<p class="msg">"' + zk.error.esc() + '"</p>' + "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
this.closest( '#cloud' )
|
|
|
|
.html( '<div class="block" id="error">' + message + '</div>' );
|
|
|
|
};
|
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
var init_debug = function( cloud_element )
|
|
|
|
{
|
|
|
|
var debug_element = $( '#debug', cloud_element );
|
2012-05-17 04:45:29 -04:00
|
|
|
var debug_button = $( '#menu #cloud .dump a' );
|
2012-03-21 05:36:59 -04:00
|
|
|
|
|
|
|
var clipboard_element = $( '.clipboard', debug_element );
|
|
|
|
var clipboard_button = $( 'a', clipboard_element );
|
|
|
|
|
|
|
|
debug_button
|
|
|
|
.die( 'click' )
|
|
|
|
.live
|
2012-03-07 11:30:20 -05:00
|
|
|
(
|
2012-03-21 05:36:59 -04:00
|
|
|
'click',
|
|
|
|
function( event )
|
2012-03-07 11:30:20 -05:00
|
|
|
{
|
2012-03-21 05:36:59 -04:00
|
|
|
debug_element.trigger( 'show' );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
);
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$( '.close', debug_element )
|
|
|
|
.die( 'click' )
|
|
|
|
.live
|
|
|
|
(
|
|
|
|
'click',
|
|
|
|
function( event )
|
|
|
|
{
|
|
|
|
debug_element.trigger( 'hide' );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
);
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$( '.clipboard', debug_element )
|
|
|
|
.die( 'click' )
|
|
|
|
.live
|
|
|
|
(
|
|
|
|
'click',
|
|
|
|
function( event )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
);
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
debug_element
|
|
|
|
.die( 'show' )
|
|
|
|
.live
|
|
|
|
(
|
|
|
|
'show',
|
|
|
|
function( event )
|
|
|
|
{
|
|
|
|
debug_element.show();
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$.ajax
|
|
|
|
(
|
|
|
|
{
|
2012-04-12 03:41:36 -04:00
|
|
|
url : app.config.solr_path + '/zookeeper?wt=json&dump=true',
|
2012-03-21 05:36:59 -04:00
|
|
|
dataType : 'text',
|
|
|
|
context : debug_element,
|
|
|
|
beforeSend : function( xhr, settings )
|
|
|
|
{
|
|
|
|
$( '.debug', debug_element )
|
|
|
|
.html( '<span class="loader">Loading Dump ...</span>' );
|
|
|
|
|
|
|
|
ZeroClipboard.setMoviePath( 'img/ZeroClipboard.swf' );
|
|
|
|
|
|
|
|
clipboard_client = new ZeroClipboard.Client();
|
|
|
|
|
|
|
|
clipboard_client.addEventListener
|
|
|
|
(
|
|
|
|
'load',
|
|
|
|
function( client )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
clipboard_client.addEventListener
|
|
|
|
(
|
|
|
|
'complete',
|
|
|
|
function( client, text )
|
|
|
|
{
|
|
|
|
clipboard_element
|
|
|
|
.addClass( 'copied' );
|
|
|
|
|
|
|
|
clipboard_button
|
|
|
|
.data( 'text', clipboard_button.text() )
|
|
|
|
.text( clipboard_button.data( 'copied' ) );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
success : function( response, text_status, xhr )
|
|
|
|
{
|
|
|
|
clipboard_client.glue
|
|
|
|
(
|
|
|
|
clipboard_element.get(0),
|
|
|
|
clipboard_button.get(0)
|
|
|
|
);
|
|
|
|
|
|
|
|
clipboard_client.setText( response.replace( /\\/g, '\\\\' ) );
|
|
|
|
|
|
|
|
$( '.debug', debug_element )
|
|
|
|
.removeClass( 'loader' )
|
|
|
|
.text( response );
|
|
|
|
},
|
|
|
|
error : function( xhr, text_status, error_thrown )
|
|
|
|
{
|
|
|
|
},
|
|
|
|
complete : function( xhr, text_status )
|
2012-03-07 11:30:20 -05:00
|
|
|
{
|
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.die( 'hide' )
|
|
|
|
.live
|
|
|
|
(
|
|
|
|
'hide',
|
|
|
|
function( event )
|
|
|
|
{
|
|
|
|
$( '.debug', debug_element )
|
|
|
|
.empty();
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
clipboard_element
|
|
|
|
.removeClass( 'copied' );
|
|
|
|
|
|
|
|
clipboard_button
|
|
|
|
.data( 'copied', clipboard_button.text() )
|
|
|
|
.text( clipboard_button.data( 'text' ) );
|
|
|
|
|
|
|
|
clipboard_client.destroy();
|
|
|
|
|
|
|
|
debug_element.hide();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2012-04-20 07:34:43 -04:00
|
|
|
var helper_path_class = function( p )
|
2012-03-21 05:36:59 -04:00
|
|
|
{
|
2012-04-20 07:34:43 -04:00
|
|
|
var classes = [ 'link' ];
|
|
|
|
classes.push( 'lvl-' + p.target.depth );
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-05-21 04:37:34 -04:00
|
|
|
if( p.target.data && p.target.data.leader )
|
2012-04-20 07:34:43 -04:00
|
|
|
{
|
|
|
|
classes.push( 'leader' );
|
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-05-21 04:37:34 -04:00
|
|
|
if( p.target.data && p.target.data.state )
|
2012-04-20 07:34:43 -04:00
|
|
|
{
|
|
|
|
classes.push( p.target.data.state );
|
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-04-20 07:34:43 -04:00
|
|
|
return classes.join( ' ' );
|
|
|
|
};
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-04-20 07:34:43 -04:00
|
|
|
var helper_node_class = function( d )
|
|
|
|
{
|
|
|
|
var classes = [ 'node' ];
|
|
|
|
classes.push( 'lvl-' + d.depth );
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-05-21 04:37:34 -04:00
|
|
|
if( d.data && d.data.leader )
|
2012-04-20 07:34:43 -04:00
|
|
|
{
|
|
|
|
classes.push( 'leader' );
|
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-05-21 04:37:34 -04:00
|
|
|
if( d.data && d.data.state )
|
2012-04-20 07:34:43 -04:00
|
|
|
{
|
|
|
|
classes.push( d.data.state );
|
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-04-20 07:34:43 -04:00
|
|
|
return classes.join( ' ' );
|
|
|
|
};
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-04-20 07:34:43 -04:00
|
|
|
var helper_data = {
|
|
|
|
protocol: [],
|
|
|
|
host: [],
|
|
|
|
hostname: [],
|
|
|
|
port: [],
|
|
|
|
pathname: []
|
|
|
|
};
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-04-20 07:34:43 -04:00
|
|
|
var helper_node_text = function( d )
|
|
|
|
{
|
2012-05-21 04:37:34 -04:00
|
|
|
if( !d.data || !d.data.uri )
|
2012-04-20 07:34:43 -04:00
|
|
|
{
|
|
|
|
return d.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
var name = d.data.uri.hostname;
|
|
|
|
|
|
|
|
if( 1 !== helper_data.protocol.length )
|
|
|
|
{
|
|
|
|
name = d.data.uri.protocol + '//' + name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( 1 !== helper_data.port.length )
|
|
|
|
{
|
|
|
|
name += ':' + d.data.uri.port;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( 1 !== helper_data.pathname.length )
|
|
|
|
{
|
|
|
|
name += d.data.uri.pathname;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
};
|
|
|
|
|
|
|
|
var generate_graph = function( graph_element, graph_data, leaf_count )
|
|
|
|
{
|
|
|
|
var w = graph_element.width(),
|
|
|
|
h = leaf_count * 20;
|
2012-03-21 05:36:59 -04:00
|
|
|
|
|
|
|
var tree = d3.layout.tree()
|
2012-04-20 07:34:43 -04:00
|
|
|
.size([h, w - 400]);
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-04-20 07:34:43 -04:00
|
|
|
var diagonal = d3.svg.diagonal()
|
|
|
|
.projection(function(d) { return [d.y, d.x]; });
|
|
|
|
|
|
|
|
var vis = d3.select( '#canvas' ).append( 'svg' )
|
|
|
|
.attr( 'width', w )
|
|
|
|
.attr( 'height', h)
|
|
|
|
.append( 'g' )
|
|
|
|
.attr( 'transform', 'translate(100, 0)' );
|
|
|
|
|
|
|
|
var nodes = tree.nodes( graph_data );
|
|
|
|
|
|
|
|
var link = vis.selectAll( 'path.link' )
|
|
|
|
.data( tree.links( nodes ) )
|
|
|
|
.enter().append( 'path' )
|
|
|
|
.attr( 'class', helper_path_class )
|
|
|
|
.attr( 'd', diagonal );
|
|
|
|
|
|
|
|
var node = vis.selectAll( 'g.node' )
|
|
|
|
.data( nodes )
|
|
|
|
.enter().append( 'g' )
|
|
|
|
.attr( 'class', helper_node_class )
|
|
|
|
.attr( 'transform', function(d) { return 'translate(' + d.y + ',' + d.x + ')'; } )
|
|
|
|
|
|
|
|
node.append( 'circle' )
|
|
|
|
.attr( 'r', 4.5 );
|
|
|
|
|
|
|
|
node.append( 'text' )
|
|
|
|
.attr( 'dx', function( d ) { return 0 === d.depth ? -8 : 8; } )
|
|
|
|
.attr( 'dy', function( d ) { return 5; } )
|
|
|
|
.attr( 'text-anchor', function( d ) { return 0 === d.depth ? 'end' : 'start'; } )
|
|
|
|
.attr( 'data-href', function( d ) { return d.name; } )
|
|
|
|
.text( helper_node_text );
|
|
|
|
|
|
|
|
$( 'text[data-href*="//"]', graph_element )
|
|
|
|
.die( 'click' )
|
|
|
|
.live
|
|
|
|
(
|
|
|
|
'click',
|
|
|
|
function()
|
|
|
|
{
|
|
|
|
location.href = $( this ).data( 'href' );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
var generate_rgraph = function( graph_element, graph_data, leaf_count )
|
|
|
|
{
|
|
|
|
var max_val = Math.min( graph_element.width(), $( 'body' ).height() )
|
|
|
|
var r = max_val / 2;
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-04-20 07:34:43 -04:00
|
|
|
var cluster = d3.layout.cluster()
|
|
|
|
.size([360, r - 160]);
|
|
|
|
|
|
|
|
var diagonal = d3.svg.diagonal.radial()
|
|
|
|
.projection(function(d) { return [d.y, d.x / 180 * Math.PI]; });
|
|
|
|
|
|
|
|
var vis = d3.select( '#canvas' ).append( 'svg' )
|
|
|
|
.attr( 'width', r * 2 )
|
|
|
|
.attr( 'height', r * 2 )
|
|
|
|
.append( 'g' )
|
|
|
|
.attr( 'transform', 'translate(' + r + ',' + r + ')' );
|
|
|
|
|
|
|
|
var nodes = cluster.nodes( graph_data );
|
|
|
|
|
|
|
|
var link = vis.selectAll( 'path.link' )
|
|
|
|
.data( cluster.links( nodes ) )
|
|
|
|
.enter().append( 'path' )
|
|
|
|
.attr( 'class', helper_path_class )
|
|
|
|
.attr( 'd', diagonal );
|
|
|
|
|
|
|
|
var node = vis.selectAll( 'g.node' )
|
|
|
|
.data( nodes )
|
|
|
|
.enter().append( 'g' )
|
|
|
|
.attr( 'class', helper_node_class )
|
|
|
|
.attr( 'transform', function(d) { return 'rotate(' + (d.x - 90) + ')translate(' + d.y + ')'; } )
|
|
|
|
|
|
|
|
node.append( 'circle' )
|
|
|
|
.attr( 'r', 4.5 );
|
|
|
|
|
|
|
|
node.append( 'text' )
|
|
|
|
.attr( 'dx', function(d) { return d.x < 180 ? 8 : -8; } )
|
|
|
|
.attr( 'dy', '.31em' )
|
|
|
|
.attr( 'text-anchor', function(d) { return d.x < 180 ? 'start' : 'end'; } )
|
|
|
|
.attr( 'transform', function(d) { return d.x < 180 ? null : 'rotate(180)'; } )
|
|
|
|
.attr( 'data-href', function( d ) { return d.name; } )
|
|
|
|
.text( helper_node_text );
|
|
|
|
|
|
|
|
$( 'text[data-href*="//"]', graph_element )
|
|
|
|
.die( 'click' )
|
|
|
|
.live
|
|
|
|
(
|
|
|
|
'click',
|
|
|
|
function()
|
|
|
|
{
|
|
|
|
location.href = $( this ).data( 'href' );
|
|
|
|
}
|
|
|
|
);
|
2012-03-21 05:36:59 -04:00
|
|
|
};
|
|
|
|
|
2012-04-20 07:34:43 -04:00
|
|
|
var prepare_graph = function( graph_element, callback )
|
2012-03-21 05:36:59 -04:00
|
|
|
{
|
|
|
|
$.ajax
|
|
|
|
(
|
|
|
|
{
|
2012-04-20 07:34:43 -04:00
|
|
|
url : app.config.solr_path + '/zookeeper?wt=json&path=%2Flive_nodes',
|
2012-03-21 05:36:59 -04:00
|
|
|
dataType : 'json',
|
|
|
|
success : function( response, text_status, xhr )
|
|
|
|
{
|
2012-04-20 07:34:43 -04:00
|
|
|
var live_nodes = {};
|
|
|
|
for( var c in response.tree[0].children )
|
2012-03-21 05:36:59 -04:00
|
|
|
{
|
2012-04-20 07:34:43 -04:00
|
|
|
live_nodes[response.tree[0].children[c].data.title] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.ajax
|
|
|
|
(
|
2012-03-21 05:36:59 -04:00
|
|
|
{
|
2012-04-20 07:34:43 -04:00
|
|
|
url : app.config.solr_path + '/zookeeper?wt=json&detail=true&path=%2Fclusterstate.json',
|
|
|
|
dataType : 'json',
|
|
|
|
context : graph_element,
|
|
|
|
beforeSend : function( xhr, settings )
|
2012-03-07 11:30:20 -05:00
|
|
|
{
|
2012-04-20 07:34:43 -04:00
|
|
|
this
|
|
|
|
.show();
|
|
|
|
},
|
|
|
|
success : function( response, text_status, xhr )
|
|
|
|
{
|
|
|
|
var state = null;
|
|
|
|
eval( 'state = ' + response.znode.data + ';' );
|
|
|
|
|
|
|
|
var leaf_count = 0;
|
2012-05-21 04:37:34 -04:00
|
|
|
var graph_data = {
|
|
|
|
name: null,
|
|
|
|
children : []
|
|
|
|
};
|
|
|
|
|
2012-04-20 07:34:43 -04:00
|
|
|
for( var c in state )
|
|
|
|
{
|
|
|
|
var shards = [];
|
2012-12-13 15:33:59 -05:00
|
|
|
for( var s in state[c].shards )
|
2012-04-20 07:34:43 -04:00
|
|
|
{
|
|
|
|
var nodes = [];
|
2012-12-13 15:33:59 -05:00
|
|
|
for( var n in state[c].shards[s].replicas )
|
2012-04-20 07:34:43 -04:00
|
|
|
{
|
|
|
|
leaf_count++;
|
2012-12-13 15:33:59 -05:00
|
|
|
var replica = state[c].shards[s].replicas[n]
|
2012-04-20 07:34:43 -04:00
|
|
|
|
2012-09-22 12:21:19 -04:00
|
|
|
var uri = replica.base_url;
|
2012-04-20 07:34:43 -04:00
|
|
|
var parts = uri.match( /^(\w+:)\/\/(([\w\d\.-]+)(:(\d+))?)(.+)$/ );
|
|
|
|
var uri_parts = {
|
|
|
|
protocol: parts[1],
|
|
|
|
host: parts[2],
|
|
|
|
hostname: parts[3],
|
|
|
|
port: parseInt( parts[5] || 80, 10 ),
|
|
|
|
pathname: parts[6]
|
|
|
|
};
|
|
|
|
|
|
|
|
helper_data.protocol.push( uri_parts.protocol );
|
|
|
|
helper_data.host.push( uri_parts.host );
|
|
|
|
helper_data.hostname.push( uri_parts.hostname );
|
|
|
|
helper_data.port.push( uri_parts.port );
|
|
|
|
helper_data.pathname.push( uri_parts.pathname );
|
|
|
|
|
2012-09-22 12:21:19 -04:00
|
|
|
var status = replica.state;
|
2012-04-20 07:34:43 -04:00
|
|
|
|
2012-09-22 12:21:19 -04:00
|
|
|
if( !live_nodes[replica.node_name] )
|
2012-04-20 07:34:43 -04:00
|
|
|
{
|
|
|
|
status = 'gone';
|
|
|
|
}
|
|
|
|
|
|
|
|
var node = {
|
|
|
|
name: uri,
|
|
|
|
data: {
|
|
|
|
type : 'node',
|
|
|
|
state : status,
|
2012-09-22 12:21:19 -04:00
|
|
|
leader : 'true' === replica.leader,
|
2012-04-20 07:34:43 -04:00
|
|
|
uri : uri_parts
|
|
|
|
}
|
|
|
|
};
|
|
|
|
nodes.push( node );
|
|
|
|
}
|
|
|
|
|
|
|
|
var shard = {
|
|
|
|
name: s,
|
|
|
|
data: {
|
2013-01-08 17:39:10 -05:00
|
|
|
type : 'shard'
|
2012-04-20 07:34:43 -04:00
|
|
|
},
|
|
|
|
children: nodes
|
|
|
|
};
|
|
|
|
shards.push( shard );
|
2012-03-21 05:36:59 -04:00
|
|
|
}
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-04-20 07:34:43 -04:00
|
|
|
var collection = {
|
|
|
|
name: c,
|
|
|
|
data: {
|
2013-01-08 17:39:10 -05:00
|
|
|
type : 'collection'
|
2012-04-20 07:34:43 -04:00
|
|
|
},
|
|
|
|
children: shards
|
|
|
|
};
|
2012-05-21 04:37:34 -04:00
|
|
|
graph_data.children.push( collection );
|
2012-04-20 07:34:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
helper_data.protocol = $.unique( helper_data.protocol );
|
|
|
|
helper_data.host = $.unique( helper_data.host );
|
|
|
|
helper_data.hostname = $.unique( helper_data.hostname );
|
|
|
|
helper_data.port = $.unique( helper_data.port );
|
|
|
|
helper_data.pathname = $.unique( helper_data.pathname );
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-04-20 07:34:43 -04:00
|
|
|
callback( graph_element, graph_data, leaf_count );
|
|
|
|
},
|
|
|
|
error : function( xhr, text_status, error_thrown)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
complete : function( xhr, text_status )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2012-03-21 05:36:59 -04:00
|
|
|
},
|
|
|
|
error : function( xhr, text_status, error_thrown)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
complete : function( xhr, text_status )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-04-20 07:34:43 -04:00
|
|
|
var init_graph = function( graph_element )
|
|
|
|
{
|
|
|
|
prepare_graph
|
|
|
|
(
|
|
|
|
graph_element,
|
|
|
|
function( graph_element, graph_data, leaf_count )
|
|
|
|
{
|
|
|
|
generate_graph( graph_element, graph_data, leaf_count );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
var init_rgraph = function( graph_element )
|
|
|
|
{
|
|
|
|
prepare_graph
|
|
|
|
(
|
|
|
|
graph_element,
|
|
|
|
function( graph_element, graph_data, leaf_count )
|
|
|
|
{
|
|
|
|
generate_rgraph( graph_element, graph_data, leaf_count );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
var init_tree = function( tree_element )
|
|
|
|
{
|
|
|
|
$.ajax
|
|
|
|
(
|
|
|
|
{
|
2012-04-12 03:41:36 -04:00
|
|
|
url : app.config.solr_path + '/zookeeper?wt=json',
|
2012-03-21 05:36:59 -04:00
|
|
|
dataType : 'json',
|
|
|
|
context : tree_element,
|
|
|
|
beforeSend : function( xhr, settings )
|
|
|
|
{
|
|
|
|
this
|
|
|
|
.show();
|
|
|
|
},
|
|
|
|
success : function( response, text_status, xhr )
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$( '#tree', this )
|
|
|
|
.jstree
|
2012-03-07 11:30:20 -05:00
|
|
|
(
|
|
|
|
{
|
2012-03-21 05:36:59 -04:00
|
|
|
"plugins" : [ "json_data" ],
|
|
|
|
"json_data" : {
|
|
|
|
"data" : response.tree,
|
|
|
|
"progressive_render" : true
|
|
|
|
},
|
|
|
|
"core" : {
|
|
|
|
"animation" : 0
|
|
|
|
}
|
2012-03-07 11:30:20 -05:00
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
)
|
|
|
|
.jstree
|
|
|
|
(
|
|
|
|
'open_node',
|
|
|
|
'li:first'
|
2012-03-07 11:30:20 -05:00
|
|
|
);
|
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
var tree_links = $( '#tree a', this );
|
|
|
|
|
|
|
|
tree_links
|
|
|
|
.die( 'click' )
|
2012-03-07 11:30:20 -05:00
|
|
|
.live
|
|
|
|
(
|
2012-03-21 05:36:59 -04:00
|
|
|
'click',
|
2012-03-07 11:30:20 -05:00
|
|
|
function( event )
|
|
|
|
{
|
2012-03-21 05:36:59 -04:00
|
|
|
$( 'a.active', $( this ).parents( '#tree' ) )
|
|
|
|
.removeClass( 'active' );
|
|
|
|
|
|
|
|
$( this )
|
|
|
|
.addClass( 'active' );
|
|
|
|
|
|
|
|
tree_element
|
|
|
|
.addClass( 'show' );
|
|
|
|
|
|
|
|
var file_content = $( '#file-content' );
|
|
|
|
|
|
|
|
$( 'a.close', file_content )
|
|
|
|
.die( 'click' )
|
|
|
|
.live
|
|
|
|
(
|
|
|
|
'click',
|
|
|
|
function( event )
|
|
|
|
{
|
|
|
|
$( '#tree a.active' )
|
|
|
|
.removeClass( 'active' );
|
|
|
|
|
|
|
|
tree_element
|
|
|
|
.removeClass( 'show' );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
);
|
2012-03-07 11:30:20 -05:00
|
|
|
|
|
|
|
$.ajax
|
|
|
|
(
|
|
|
|
{
|
2012-03-21 05:36:59 -04:00
|
|
|
url : this.href,
|
|
|
|
dataType : 'json',
|
|
|
|
context : file_content,
|
2012-03-07 11:30:20 -05:00
|
|
|
beforeSend : function( xhr, settings )
|
|
|
|
{
|
2012-03-21 05:36:59 -04:00
|
|
|
},
|
|
|
|
success : function( response, text_status, xhr )
|
|
|
|
{
|
|
|
|
var props = [];
|
|
|
|
for( var key in response.znode.prop )
|
|
|
|
{
|
|
|
|
props.push
|
|
|
|
(
|
|
|
|
'<li><dl class="clearfix">' + "\n" +
|
|
|
|
'<dt>' + key.esc() + '</dt>' + "\n" +
|
|
|
|
'<dd>' + response.znode.prop[key].esc() + '</dd>' + "\n" +
|
|
|
|
'</dl></li>'
|
|
|
|
);
|
|
|
|
}
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$( '#prop ul', this )
|
|
|
|
.empty()
|
|
|
|
.html( props.join( "\n" ) );
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$( '#prop ul li:odd', this )
|
|
|
|
.addClass( 'odd' );
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
var data_element = $( '#data', this );
|
|
|
|
|
2012-09-04 11:40:02 -04:00
|
|
|
var highlight = false;
|
2013-09-03 13:29:49 -04:00
|
|
|
var data = '<em>Node "' + response.znode.path + '" has no utf8 Content</em>';
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-09-04 11:40:02 -04:00
|
|
|
if( response.znode.data )
|
|
|
|
{
|
|
|
|
var classes = '';
|
|
|
|
var path = response.znode.path.split( '.' );
|
|
|
|
|
|
|
|
if( 1 < path.length )
|
2012-03-07 11:30:20 -05:00
|
|
|
{
|
2012-09-04 11:40:02 -04:00
|
|
|
highlight = true;
|
|
|
|
classes = 'syntax language-' + path.pop().esc();
|
2012-03-07 11:30:20 -05:00
|
|
|
}
|
2012-09-04 11:40:02 -04:00
|
|
|
|
|
|
|
data = '<pre class="' + classes + '">'
|
|
|
|
+ response.znode.data.esc()
|
|
|
|
+ '</pre>';
|
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-09-04 11:40:02 -04:00
|
|
|
data_element
|
|
|
|
.show()
|
|
|
|
.html( data );
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-09-04 11:40:02 -04:00
|
|
|
if( highlight )
|
|
|
|
{
|
|
|
|
hljs.highlightBlock( data_element.get(0) );
|
2012-03-21 05:36:59 -04:00
|
|
|
}
|
2012-09-04 11:40:02 -04:00
|
|
|
|
2012-03-07 11:30:20 -05:00
|
|
|
},
|
2012-03-21 05:36:59 -04:00
|
|
|
error : function( xhr, text_status, error_thrown)
|
2012-03-07 11:30:20 -05:00
|
|
|
{
|
|
|
|
},
|
|
|
|
complete : function( xhr, text_status )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
return false;
|
2012-03-07 11:30:20 -05:00
|
|
|
}
|
|
|
|
);
|
2012-03-21 05:36:59 -04:00
|
|
|
},
|
2013-01-05 05:50:24 -05:00
|
|
|
error : zk_error,
|
2012-03-21 05:36:59 -04:00
|
|
|
complete : function( xhr, text_status )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
// #/~cloud
|
|
|
|
sammy.get
|
|
|
|
(
|
2012-05-07 15:39:22 -04:00
|
|
|
/^#\/(~cloud)$/,
|
2012-03-21 05:36:59 -04:00
|
|
|
function( context )
|
|
|
|
{
|
|
|
|
var content_element = $( '#content' );
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$.get
|
|
|
|
(
|
|
|
|
'tpl/cloud.html',
|
|
|
|
function( template )
|
|
|
|
{
|
|
|
|
content_element
|
|
|
|
.html( template );
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
var cloud_element = $( '#cloud', content_element );
|
2012-05-17 04:45:29 -04:00
|
|
|
var navigation_element = $( '#menu #cloud' );
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
init_debug( cloud_element );
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$( '.tree', navigation_element )
|
|
|
|
.die( 'activate' )
|
|
|
|
.live
|
|
|
|
(
|
|
|
|
'activate',
|
|
|
|
function( event )
|
2012-03-07 11:30:20 -05:00
|
|
|
{
|
2012-05-17 04:45:29 -04:00
|
|
|
$( this ).addClass( 'active' );
|
2012-03-21 05:36:59 -04:00
|
|
|
init_tree( $( '#tree-content', cloud_element ) );
|
|
|
|
}
|
|
|
|
);
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$( '.graph', navigation_element )
|
|
|
|
.die( 'activate' )
|
|
|
|
.live
|
|
|
|
(
|
|
|
|
'activate',
|
|
|
|
function( event )
|
2012-03-07 11:30:20 -05:00
|
|
|
{
|
2012-05-17 04:45:29 -04:00
|
|
|
$( this ).addClass( 'active' );
|
2012-03-21 05:36:59 -04:00
|
|
|
init_graph( $( '#graph-content', cloud_element ) );
|
2012-02-23 14:23:10 -05:00
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
);
|
|
|
|
|
2012-04-20 07:34:43 -04:00
|
|
|
$( '.rgraph', navigation_element )
|
|
|
|
.die( 'activate' )
|
|
|
|
.live
|
|
|
|
(
|
|
|
|
'activate',
|
|
|
|
function( event )
|
|
|
|
{
|
2012-05-17 04:45:29 -04:00
|
|
|
$( this ).addClass( 'active' );
|
2012-04-20 07:34:43 -04:00
|
|
|
init_rgraph( $( '#graph-content', cloud_element ) );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2013-01-05 05:50:24 -05:00
|
|
|
$.ajax
|
|
|
|
(
|
|
|
|
{
|
|
|
|
url : app.config.solr_path + '/zookeeper?wt=json',
|
|
|
|
dataType : 'json',
|
|
|
|
context : cloud_element,
|
|
|
|
success : function( response, text_status, xhr )
|
|
|
|
{
|
|
|
|
$( 'a[href="' + context.path + '"]', navigation_element )
|
|
|
|
.trigger( 'activate' );
|
|
|
|
},
|
|
|
|
error : zk_error
|
|
|
|
}
|
|
|
|
);
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-03-07 11:30:20 -05:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2012-09-22 12:21:19 -04:00
|
|
|
);
|