Hadoop, {release-year-token}.
Failed to retrieve data from ' + url + ', cause: ' + err + '
'); + }); + + function render() { + var base = dust.makeBase(HELPERS); + dust.render('federationhealth', base.push(data), function(err, out) { + $('#tab-overview').html(out); + $('#ui-tabs a[href="#tab-overview"]').tab('show'); + }); + } + } + + function load_namenode_info() { + var HELPERS = { + 'helper_lastcontact_tostring' : function (chunk, ctx, bodies, params) { + var value = dust.helpers.tap(params.value, chunk, ctx); + return chunk.write('' + new Date(Date.now()-1000*Number(value))); + } + }; + + function workaround(r) { + function node_map_to_array(nodes) { + var res = []; + for (var n in nodes) { + var p = nodes[n]; + p.name = n; + res.push(p); + } + return res; + } + + function capitalise(string) { + return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); + } + + function augment_namenodes(nodes) { + for (var i = 0, e = nodes.length; i < e; ++i) { + var n = nodes[i]; + n.usedPercentage = Math.round(n.used * 1.0 / n.totalSpace * 100); + n.title = "Unavailable"; + n.iconState = "down"; + if (n.isSafeMode === true) { + n.title = capitalise(n.state) + " (safe mode)" + n.iconState = "decommisioned"; + } else if (n.state === "ACTIVE") { + n.title = capitalise(n.state); + n.iconState = "alive"; + } else if (nodes[i].state === "STANDBY") { + n.title = capitalise(n.state); + n.iconState = "down-decommisioned"; + } else if (nodes[i].state === "UNAVAILABLE") { + n.title = capitalise(n.state); + n.iconState = "down"; + } + if (n.namenodeId === "null") { + n.namenodeId = ""; + } + } + } + + r.Nameservices = node_map_to_array(JSON.parse(r.Nameservices)); + augment_namenodes(r.Nameservices); + r.Namenodes = node_map_to_array(JSON.parse(r.Namenodes)); + augment_namenodes(r.Namenodes); + return r; + } + + $.get( + '/jmx?qry=Hadoop:service=Router,name=FederationState', + guard_with_startup_progress(function (resp) { + var data = workaround(resp.beans[0]); + var base = dust.makeBase(HELPERS); + dust.render('namenode-info', base.push(data), function(err, out) { + $('#tab-namenode').html(out); + $('#ui-tabs a[href="#tab-namenode"]').tab('show'); + }); + })).error(ajax_error_handler); + } + + // TODO Copied directly from dfshealth.js; is there a way to import this function? + function load_datanode_info() { + + var HELPERS = { + 'helper_relative_time' : function (chunk, ctx, bodies, params) { + var value = dust.helpers.tap(params.value, chunk, ctx); + return chunk.write(moment().subtract(Number(value), 'seconds').format('YYYY-MM-DD HH:mm:ss')); + }, + 'helper_usage_bar' : function (chunk, ctx, bodies, params) { + var value = dust.helpers.tap(params.value, chunk, ctx); + var v = Number(value); + var r = null; + if (v < 70) { + r = 'progress-bar-success'; + } else if (v < 85) { + r = 'progress-bar-warning'; + } else { + r = "progress-bar-danger"; + } + return chunk.write(r); + }, + }; + + function workaround(r) { + function node_map_to_array(nodes) { + var res = []; + for (var n in nodes) { + var p = nodes[n]; + p.name = n; + res.push(p); + } + return res; + } + + function augment_live_nodes(nodes) { + for (var i = 0, e = nodes.length; i < e; ++i) { + var n = nodes[i]; + n.usedPercentage = Math.round((n.used + n.nonDfsUsedSpace) * 1.0 / n.capacity * 100); + if (n.adminState === "In Service") { + n.state = "alive"; + } else if (nodes[i].adminState === "Decommission In Progress") { + n.state = "decommisioning"; + } else if (nodes[i].adminState === "Decommissioned") { + n.state = "decommissioned"; + } + } + } + + function augment_dead_nodes(nodes) { + for (var i = 0, e = nodes.length; i < e; ++i) { + if (nodes[i].decommissioned) { + nodes[i].state = "down-decommissioned"; + } else { + nodes[i].state = "down"; + } + } + } + + r.LiveNodes = node_map_to_array(JSON.parse(r.LiveNodes)); + augment_live_nodes(r.LiveNodes); + r.DeadNodes = node_map_to_array(JSON.parse(r.DeadNodes)); + augment_dead_nodes(r.DeadNodes); + r.DecomNodes = node_map_to_array(JSON.parse(r.DecomNodes)); + return r; + } + + $.get( + '/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo', + guard_with_startup_progress(function (resp) { + var data = workaround(resp.beans[0]); + var base = dust.makeBase(HELPERS); + dust.render('datanode-info', base.push(data), function(err, out) { + $('#tab-datanode').html(out); + $('#table-datanodes').dataTable( { + 'lengthMenu': [ [25, 50, 100, -1], [25, 50, 100, "All"] ], + 'columns': [ + { 'orderDataType': 'ng-value', 'searchable': true }, + { 'orderDataType': 'ng-value', 'type': 'numeric' }, + { 'orderDataType': 'ng-value', 'type': 'numeric' }, + { 'orderDataType': 'ng-value', 'type': 'numeric'} + ]}); + $('#ui-tabs a[href="#tab-datanode"]').tab('show'); + }); + })).error(ajax_error_handler); + } + + function load_mount_table() { + var HELPERS = {} + + function workaround(resource) { + resource.MountTable = JSON.parse(resource.MountTable) + return resource; + } + + $.get( + '/jmx?qry=Hadoop:service=Router,name=FederationState', + guard_with_startup_progress(function (resp) { + var data = workaround(resp.beans[0]); + var base = dust.makeBase(HELPERS); + dust.render('mounttable', base.push(data), function(err, out) { + $('#tab-mounttable').html(out); + $('#ui-tabs a[href="#tab-mounttable"]').tab('show'); + }); + })).error(ajax_error_handler); + } + + function toTitleCase(str) { + return str.replace(/\w\S*/g, function(txt){ + return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); + }); + } + + function show_err_msg(msg) { + $('#alert-panel-body').html(msg); + $('#alert-panel').show(); + } + + function ajax_error_handler(url, jqxhr, text, err) { + show_err_msg('Failed to retrieve data from ' + url + ', cause: ' + err + '
'); + } + + function guard_with_startup_progress(fn) { + return function() { + try { + fn.apply(this, arguments); + } catch (err) { + if (err instanceof TypeError) { + show_err_msg('Router error: ' + err); + } + } + }; + } + + function load_page() { + var hash = window.location.hash; + switch(hash) { + case "#tab-mounttable": + load_mount_table(); + break; + case "#tab-namenode": + load_namenode_info(); + break; + case "#tab-datanode": + load_datanode_info(); + break; + case "#tab-overview": + load_overview(); + break; + default: + window.location.hash = "tab-overview"; + break; + } + } + load_page(); + + $(window).bind('hashchange', function () { + load_page(); + }); +})(); \ No newline at end of file diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/router/index.html b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/router/index.html new file mode 100644 index 0000000000..4ee04acdcc --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/router/index.html @@ -0,0 +1,24 @@ + + + + + +