dfshealth.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. (function () {
  19. "use strict";
  20. dust.loadSource(dust.compile($('#tmpl-dfshealth').html(), 'dfshealth'));
  21. dust.loadSource(dust.compile($('#tmpl-startup-progress').html(), 'startup-progress'));
  22. dust.loadSource(dust.compile($('#tmpl-datanode').html(), 'datanode-info'));
  23. dust.loadSource(dust.compile($('#tmpl-datanode-volume-failures').html(), 'datanode-volume-failures'));
  24. dust.loadSource(dust.compile($('#tmpl-snapshot').html(), 'snapshot-info'));
  25. $.fn.dataTable.ext.order['ng-value'] = function (settings, col)
  26. {
  27. return this.api().column(col, {order:'index'} ).nodes().map(function (td, i) {
  28. return $(td).attr('ng-value');
  29. });
  30. };
  31. function load_overview() {
  32. var BEANS = [
  33. {"name": "nn", "url": "/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo"},
  34. {"name": "nnstat", "url": "/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus"},
  35. {"name": "fs", "url": "/jmx?qry=Hadoop:service=NameNode,name=FSNamesystemState"},
  36. {"name": "fsn", "url": "/jmx?qry=Hadoop:service=NameNode,name=FSNamesystem"},
  37. {"name": "replicastat", "url": "/jmx?qry=Hadoop:service=NameNode,name=ReplicatedBlocksState"},
  38. {"name": "ecstat", "url": "/jmx?qry=Hadoop:service=NameNode,name=ECBlockGroupsState"},
  39. {"name": "blockstats", "url": "/jmx?qry=Hadoop:service=NameNode,name=BlockStats"},
  40. {"name": "mem", "url": "/jmx?qry=java.lang:type=Memory"}
  41. ];
  42. var HELPERS = {
  43. 'helper_fs_max_objects': function (chunk, ctx, bodies, params) {
  44. var o = ctx.current();
  45. if (o.MaxObjects > 0) {
  46. chunk.write('(' + Math.round((o.FilesTotal + o.BlockTotal) / o.MaxObjects * 100) * 100 + ')%');
  47. }
  48. },
  49. 'helper_dir_status': function (chunk, ctx, bodies, params) {
  50. var j = ctx.current();
  51. for (var i in j) {
  52. chunk.write('<tr><td>' + i + '</td><td>' + j[i] + '</td><td>' + params.type + '</td></tr>');
  53. }
  54. },
  55. 'helper_date_tostring' : function (chunk, ctx, bodies, params) {
  56. var value = dust.helpers.tap(params.value, chunk, ctx);
  57. return chunk.write('' + moment(Number(value)).format('ddd MMM DD HH:mm:ss ZZ YYYY'));
  58. }
  59. };
  60. var data = {};
  61. var non_ha = false;
  62. $.ajax({'url': '/conf', 'dataType': 'xml', 'async': true}).done(
  63. function(d) {
  64. var $xml = $(d);
  65. var namespace, nnId;
  66. $xml.find('property').each(function(idx,v) {
  67. if ($(v).find('name').text() === 'dfs.nameservice.id') {
  68. namespace = $(v).find('value').text();
  69. }
  70. if ($(v).find('name').text() === 'dfs.ha.namenode.id') {
  71. nnId = $(v).find('value').text();
  72. }
  73. });
  74. if (namespace && nnId) {
  75. data['HAInfo'] = {"Namespace": namespace, "NamenodeID": nnId};
  76. } else {
  77. non_ha = true;
  78. }
  79. });
  80. // Workarounds for the fact that JMXJsonServlet returns non-standard JSON strings
  81. function workaround(nn) {
  82. nn.JournalTransactionInfo = JSON.parse(nn.JournalTransactionInfo);
  83. nn.NameJournalStatus = JSON.parse(nn.NameJournalStatus);
  84. nn.NameDirStatuses = JSON.parse(nn.NameDirStatuses);
  85. nn.NodeUsage = JSON.parse(nn.NodeUsage);
  86. nn.CorruptFiles = JSON.parse(nn.CorruptFiles);
  87. return nn;
  88. }
  89. load_json(
  90. BEANS,
  91. guard_with_startup_progress(function(d) {
  92. for (var k in d) {
  93. data[k] = k === 'nn' ? workaround(d[k].beans[0]) : d[k].beans[0];
  94. }
  95. var blockstats = data['blockstats'];
  96. for (var k in blockstats.StorageTypeStats) {
  97. var b = blockstats.StorageTypeStats[k].value;
  98. b.capacityUsedPercentage = b.capacityUsed * 100.0 / b.capacityTotal;
  99. b.capacityRemainingPercentage = b.capacityRemaining * 100.0 / b.capacityTotal;
  100. }
  101. data.fs.ObjectsTotal = data.fs.FilesTotal + data.fs.BlocksTotal;
  102. var wait_for_conf = setInterval(function() {
  103. if (non_ha ||
  104. (('HAInfo' in data) &&
  105. ("Namespace" in data['HAInfo']) &&
  106. ("NamenodeID" in data['HAInfo'])
  107. )
  108. ) {
  109. render();
  110. clearInterval(wait_for_conf);
  111. }
  112. }, 5);
  113. }),
  114. function (url, jqxhr, text, err) {
  115. show_err_msg('<p>Failed to retrieve data from ' + url + ', cause: ' + err + '</p>');
  116. });
  117. function render() {
  118. var base = dust.makeBase(HELPERS);
  119. dust.render('dfshealth', base.push(data), function(err, out) {
  120. $('#tab-overview').html(out);
  121. $('#ui-tabs a[href="#tab-overview"]').tab('show');
  122. });
  123. }
  124. }
  125. function show_err_msg(msg) {
  126. $('#alert-panel-body').html(msg);
  127. $('#alert-panel').show();
  128. }
  129. function ajax_error_handler(url, jqxhr, text, err) {
  130. show_err_msg('<p>Failed to retrieve data from ' + url + ', cause: ' + err + '</p>');
  131. }
  132. function guard_with_startup_progress(fn) {
  133. return function() {
  134. try {
  135. fn.apply(this, arguments);
  136. } catch (err) {
  137. if (err instanceof TypeError) {
  138. show_err_msg('NameNode is still loading. Redirecting to the Startup Progress page.');
  139. load_startup_progress();
  140. }
  141. }
  142. };
  143. }
  144. function load_startup_progress() {
  145. function workaround(r) {
  146. function rename_property(o, s, d) {
  147. if (o[s] !== undefined) {
  148. o[d] = o[s];
  149. delete o[s];
  150. }
  151. }
  152. r.percentComplete *= 100;
  153. $.each(r.phases, function (idx, p) {
  154. p.percentComplete *= 100;
  155. $.each(p.steps, function (idx2, s) {
  156. s.percentComplete *= 100;
  157. // dust.js is confused by these optional keys in nested
  158. // structure, rename them
  159. rename_property(s, "desc", "stepDesc");
  160. rename_property(s, "file", "stepFile");
  161. rename_property(s, "size", "stepSize");
  162. });
  163. });
  164. return r;
  165. }
  166. $.get('/startupProgress', function (resp) {
  167. var data = workaround(resp);
  168. dust.render('startup-progress', data, function(err, out) {
  169. $('#tab-startup-progress').html(out);
  170. $('#ui-tabs a[href="#tab-startup-progress"]').tab('show');
  171. });
  172. }).fail(ajax_error_handler);
  173. }
  174. function load_datanode_info() {
  175. var HELPERS = {
  176. 'helper_relative_time' : function (chunk, ctx, bodies, params) {
  177. var value = dust.helpers.tap(params.value, chunk, ctx);
  178. return chunk.write(moment().subtract(Number(value), 'seconds').format('ddd MMM DD HH:mm:ss ZZ YYYY'));
  179. },
  180. 'helper_usage_bar' : function (chunk, ctx, bodies, params) {
  181. var value = dust.helpers.tap(params.value, chunk, ctx);
  182. var v = Number(value);
  183. var r = null;
  184. if (v < 70) {
  185. r = 'progress-bar-success';
  186. } else if (v < 85) {
  187. r = 'progress-bar-warning';
  188. } else {
  189. r = "progress-bar-danger";
  190. }
  191. return chunk.write(r);
  192. },
  193. };
  194. function workaround(r) {
  195. function node_map_to_array(nodes) {
  196. var res = [];
  197. for (var n in nodes) {
  198. var p = nodes[n];
  199. p.name = n;
  200. res.push(p);
  201. }
  202. return res;
  203. }
  204. function augment_live_nodes(nodes) {
  205. for (var i = 0, e = nodes.length; i < e; ++i) {
  206. var n = nodes[i];
  207. n.usedPercentage = Math.round((n.used + n.nonDfsUsedSpace) * 1.0 / n.capacity * 100);
  208. var port = n.infoAddr.split(":")[1];
  209. var securePort = n.infoSecureAddr.split(":")[1];
  210. var dnHost = n.name.split(":")[0];
  211. n.dnWebAddress = "http://" + dnHost + ":" + port;
  212. if (securePort != 0) {
  213. n.dnWebAddress = "https://" + dnHost + ":" + securePort;
  214. }
  215. if (n.adminState === "In Service") {
  216. n.state = "alive";
  217. } else if (nodes[i].adminState === "Decommission In Progress") {
  218. n.state = "decommissioning";
  219. } else if (nodes[i].adminState === "Decommissioned") {
  220. n.state = "decommissioned";
  221. } else if (nodes[i].adminState === "Entering Maintenance") {
  222. n.state = "entering-maintenance";
  223. } else if (nodes[i].adminState === "In Maintenance") {
  224. n.state = "in-maintenance";
  225. }
  226. }
  227. }
  228. function augment_dead_nodes(nodes) {
  229. for (var i = 0, e = nodes.length; i < e; ++i) {
  230. if (nodes[i].adminState === "Decommissioned") {
  231. nodes[i].state = "down-decommissioned";
  232. } else if (nodes[i].adminState === "In Maintenance") {
  233. nodes[i].state = "down-maintenance";
  234. } else {
  235. nodes[i].state = "down";
  236. }
  237. }
  238. }
  239. r.LiveNodes = node_map_to_array(JSON.parse(r.LiveNodes));
  240. augment_live_nodes(r.LiveNodes);
  241. r.DeadNodes = node_map_to_array(JSON.parse(r.DeadNodes));
  242. augment_dead_nodes(r.DeadNodes);
  243. r.DecomNodes = node_map_to_array(JSON.parse(r.DecomNodes));
  244. r.EnteringMaintenanceNodes = node_map_to_array(JSON.parse(r.EnteringMaintenanceNodes));
  245. return r;
  246. }
  247. function renderHistogram(dnData) {
  248. var data = dnData.LiveNodes.map(function(dn) {
  249. return (dn.usedSpace / dn.capacity) * 100.0;
  250. });
  251. var formatCount = d3.format(",.0f");
  252. var widthCap = $("div.container").width();
  253. var heightCap = 150;
  254. var margin = {top: 10, right: 60, bottom: 30, left: 30},
  255. width = widthCap * 0.9,
  256. height = heightCap - margin.top - margin.bottom;
  257. var x = d3.scaleLinear()
  258. .domain([0.0, 100.0])
  259. .range([0, width]);
  260. var bins = d3.histogram()
  261. .domain(x.domain())
  262. .thresholds(x.ticks(20))
  263. (data);
  264. var y = d3.scaleLinear()
  265. .domain([0, d3.max(bins, function(d) { return d.length; })])
  266. .range([height, 0]);
  267. var svg = d3.select("#datanode-usage-histogram").append("svg")
  268. .attr("width", width + 50.0)
  269. .attr("height", height + margin.top + margin.bottom)
  270. .append("g")
  271. .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
  272. svg.append("text")
  273. .attr("x", (width / 2))
  274. .attr("y", heightCap - 6 - (margin.top / 2))
  275. .attr("text-anchor", "middle")
  276. .style("font-size", "15px")
  277. .text("Disk usage of each DataNode (%)");
  278. var bar = svg.selectAll(".bar")
  279. .data(bins)
  280. .enter().append("g")
  281. .attr("class", "bar")
  282. .attr("transform", function(d) { return "translate(" + x(d.x0) + "," + y(d.length) + ")"; });
  283. window.liveNodes = dnData.LiveNodes;
  284. bar.append("rect")
  285. .attr("x", 1)
  286. .attr("width", x(bins[0].x1) - x(bins[0].x0) - 1)
  287. .attr("height", function(d) { return height - y(d.length); })
  288. .attr("onclick", function (d) { return "open_hostip_list(" + d.x0 + "," + d.x1 + ")"; });
  289. bar.append("text")
  290. .attr("dy", ".75em")
  291. .attr("y", 6)
  292. .attr("x", (x(bins[0].x1) - x(bins[0].x0)) / 2)
  293. .attr("text-anchor", "middle")
  294. .text(function(d) { return formatCount(d.length); });
  295. svg.append("g")
  296. .attr("class", "axis axis--x")
  297. .attr("transform", "translate(0," + height + ")")
  298. .call(d3.axisBottom(x));
  299. }
  300. $.get(
  301. '/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo',
  302. guard_with_startup_progress(function (resp) {
  303. var data = workaround(resp.beans[0]);
  304. var base = dust.makeBase(HELPERS);
  305. dust.render('datanode-info', base.push(data), function(err, out) {
  306. $('#tab-datanode').html(out);
  307. $('#table-datanodes').dataTable( {
  308. 'lengthMenu': [ [25, 50, 100, -1], [25, 50, 100, "All"] ],
  309. 'columnDefs': [
  310. { 'targets': [ 0 ], 'visible': false, 'searchable': false }
  311. ],
  312. 'columns': [
  313. { 'orderDataType': 'ng-value', 'searchable': true , "defaultContent": "" },
  314. { 'orderDataType': 'ng-value', 'searchable': true , "defaultContent": "" },
  315. { 'orderDataType': 'ng-value', 'searchable': true , "defaultContent": ""},
  316. { 'orderDataType': 'ng-value', 'type': 'num' , "defaultContent": 0},
  317. { 'orderDataType': 'ng-value', 'type': 'num' , "defaultContent": 0},
  318. { 'orderDataType': 'ng-value', 'type': 'num' , "defaultContent": 0},
  319. { 'orderDataType': 'ng-value', 'type': 'num' , "defaultContent": 0},
  320. { 'orderDataType': 'ng-value', 'type': 'num' , "defaultContent": 0},
  321. { 'type': 'num' , "defaultContent": 0},
  322. { 'orderDataType': 'ng-value', 'type': 'num' , "defaultContent": 0},
  323. { 'orderDataType': 'ng-value', 'type': 'num' , "defaultContent": 0},
  324. { 'type': 'string' , "defaultContent": ""}
  325. ],
  326. initComplete: function () {
  327. var column = this.api().column([0]);
  328. var select = $('<select class="datanodestatus form-control input-sm"><option value="">All</option></select>')
  329. .appendTo('#datanodefilter')
  330. .on('change', function () {
  331. var val = $.fn.dataTable.util.escapeRegex(
  332. $(this).val());
  333. column.search(val ? '^' + val + '$' : '', true, false).draw();
  334. });
  335. console.log(select);
  336. column.data().unique().sort().each(function (d, j) {
  337. select.append('<option value="' + d + '">' + d + '</option>');
  338. });
  339. }
  340. });
  341. renderHistogram(data);
  342. $('#ui-tabs a[href="#tab-datanode"]').tab('show');
  343. });
  344. })).fail(ajax_error_handler);
  345. }
  346. function load_datanode_volume_failures() {
  347. var HELPERS = {
  348. 'helper_date_tostring' : function (chunk, ctx, bodies, params) {
  349. var value = dust.helpers.tap(params.value, chunk, ctx);
  350. return chunk.write('' + moment(Number(value)).format('ddd MMM DD HH:mm:ss ZZ YYYY'));
  351. }
  352. };
  353. function workaround(r) {
  354. function node_map_to_array(nodes) {
  355. var res = [];
  356. for (var n in nodes) {
  357. var p = nodes[n];
  358. // Filter the display to only datanodes with volume failures.
  359. if (p.volfails > 0) {
  360. p.name = n;
  361. res.push(p);
  362. }
  363. }
  364. return res;
  365. }
  366. r.LiveNodes = node_map_to_array(JSON.parse(r.LiveNodes));
  367. return r;
  368. }
  369. $.get(
  370. '/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo',
  371. guard_with_startup_progress(function (resp) {
  372. var data = workaround(resp.beans[0]);
  373. var base = dust.makeBase(HELPERS);
  374. dust.render('datanode-volume-failures', base.push(data), function(err, out) {
  375. $('#tab-datanode-volume-failures').html(out);
  376. $('#ui-tabs a[href="#tab-datanode-volume-failures"]').tab('show');
  377. });
  378. })).fail(ajax_error_handler);
  379. }
  380. function load_snapshot_info() {
  381. $.get(
  382. '/jmx?qry=Hadoop:service=NameNode,name=SnapshotInfo',
  383. guard_with_startup_progress(function (resp) {
  384. dust.render('snapshot-info', resp.beans[0], function(err, out) {
  385. $('#tab-snapshot').html(out);
  386. $('#ui-tabs a[href="#tab-snapshot"]').tab('show');
  387. // Build a map to store snapshottable directory -> snapshots
  388. var snapshots = 'Snapshots' in resp.beans[0] ? resp.beans[0].Snapshots : [];
  389. var snapshotsMap = snapshots.reduce(function(result, snapshot) {
  390. var rootPath = snapshot.snapshotDirectory.substr(0, snapshot.snapshotDirectory.indexOf(".snapshot") -1 );
  391. if (rootPath in result) {
  392. var arr = result[rootPath];
  393. arr.push(snapshot);
  394. result[rootPath] = arr;
  395. } else {
  396. result[rootPath] = [snapshot];
  397. }
  398. return result;
  399. }, {});
  400. var table = $('#table-snapshots').DataTable( {
  401. 'lengthMenu': [ [25, 50, 100, -1], [25, 50, 100, "All"] ],
  402. 'columns': [
  403. { 'orderable': false, 'searchable': false, 'data': null, 'defaultContent': "" },
  404. { 'data': 'path', 'orderDataType': 'ng-value', 'searchable': true , 'type': 'string', 'defaultContent': "" },
  405. { 'data': 'snapshotNumber', 'orderDataType': 'ng-value', 'searchable': false , 'type': 'num', 'defaultContent': 0 },
  406. { 'data': 'snapshotQuota', 'orderDataType': 'ng-value', 'searchable': false , 'type': 'num', 'defaultContent': 0 },
  407. { 'data': 'modificationTime', 'orderDataType': 'ng-value', 'searchable': false , 'type': 'string', 'defaultContent': "" },
  408. { 'data': 'permission', 'orderable': false, 'searchable': false , 'type': 'string', 'defaultContent': "" },
  409. { 'data': 'owner', 'orderDataType': 'ng-value', 'searchable': true , 'type': 'string', 'defaultContent': "" },
  410. { 'data': 'group', 'orderDataType': 'ng-value', 'searchable': true , 'type': 'string', 'defaultContent': "" }
  411. ],
  412. 'order': [[ 1, 'asc' ]]
  413. });
  414. // Add event listener for opening and closing details
  415. $('#table-snapshots tbody').on('click', 'td.details-control', function () {
  416. var tr = $(this).closest('tr');
  417. var row = table.row( tr );
  418. if ( row.child.isShown() ) {
  419. // This row is already open - close it
  420. row.child.hide();
  421. tr.removeClass('shown');
  422. }
  423. else {
  424. // Open this row
  425. row.child( formatExpandedRow(row.data(), snapshotsMap) ).show();
  426. var tableId = getSubTableId(row.data());
  427. if (!$.fn.dataTable.isDataTable('#'+tableId)) {
  428. $('#' + tableId).DataTable({
  429. 'lengthMenu': [[25, 50, 100, -1], [25, 50, 100, "All"]],
  430. 'columns': [
  431. {
  432. 'orderDataType': 'ng-value',
  433. 'searchable': true,
  434. 'type': 'num',
  435. 'defaultContent': 0
  436. },
  437. {
  438. 'orderDataType': 'ng-value',
  439. 'searchable': true,
  440. 'type': 'string',
  441. 'defaultContent': ""
  442. },
  443. {
  444. 'orderDataType': 'ng-value',
  445. 'searchable': true,
  446. 'type': 'string',
  447. 'defaultContent': ""
  448. },
  449. {
  450. 'orderDataType': 'ng-value',
  451. 'searchable': true,
  452. 'type': 'string',
  453. 'defaultContent': ""
  454. }
  455. ],
  456. 'order': [[0, 'asc']]
  457. });
  458. }
  459. tr.addClass('shown');
  460. }
  461. });
  462. });
  463. })).fail(ajax_error_handler);
  464. }
  465. function getSubTableId(row) {
  466. var path = row.path;
  467. // replace all "/" with "-"
  468. path = path.replace(/\//g, '-');
  469. return "table-snapshots"+path;
  470. }
  471. function formatExpandedRow (row, snapshotsMap) {
  472. // `row` is the original data object for the row
  473. var tableId = getSubTableId(row);
  474. var path = row.path;
  475. var snapshots = snapshotsMap[path];
  476. if (!snapshots || snapshots.length === 0) {
  477. return 'No snapshots found for this path';
  478. }
  479. var tbody = snapshots.reduce(function(result, snapshot) {
  480. var html = '<tr>'+
  481. '<td ng-value="'+snapshot.snapshotID+'">'+ snapshot.snapshotID +'</td>'+
  482. '<td ng-value="'+snapshot.snapshotDirectory+'">'+ snapshot.snapshotDirectory +'</td>'+
  483. '<td ng-value="'+snapshot.modificationTime+'">'+ moment(Number(snapshot.modificationTime)).format('ddd MMM DD HH:mm:ss ZZ YYYY') +'</td>'+
  484. '<td ng-value="'+snapshot.status+'">'+ snapshot.status +'</td>'+
  485. '</tr>';
  486. return result + html;
  487. }, "");
  488. return '<table class="table sub-table" id='+ tableId +'>'+
  489. '<thead>'+
  490. '<tr>'+
  491. '<th>Snapshot ID</th>'+
  492. '<th>Snapshot Directory</th>'+
  493. '<th>Modification Time</th>' +
  494. '<th>Status</th>' +
  495. '</tr>'+
  496. '</thead>'+
  497. '<tbody>'+
  498. tbody +
  499. '</tbody>'+
  500. '</table>';
  501. }
  502. function load_page() {
  503. var hash = window.location.hash;
  504. switch(hash) {
  505. case "#tab-datanode":
  506. load_datanode_info();
  507. break;
  508. case "#tab-datanode-volume-failures":
  509. load_datanode_volume_failures();
  510. break;
  511. case "#tab-snapshot":
  512. load_snapshot_info();
  513. break;
  514. case "#tab-startup-progress":
  515. load_startup_progress();
  516. break;
  517. case "#tab-overview":
  518. load_overview();
  519. break;
  520. default:
  521. window.location.hash = "tab-overview";
  522. break;
  523. }
  524. }
  525. load_page();
  526. $(window).bind('hashchange', function () {
  527. load_page();
  528. });
  529. })();
  530. function open_hostip_list(x0, x1) {
  531. close_hostip_list();
  532. var ips = new Array();
  533. for (var i = 0; i < liveNodes.length; i++) {
  534. var dn = liveNodes[i];
  535. var index = (dn.usedSpace / dn.capacity) * 100.0;
  536. if (index == 0) {
  537. index = 1;
  538. }
  539. //More than 100% do not care,so not record in 95%-100% bar
  540. if (index > x0 && index <= x1) {
  541. ips.push(dn.infoAddr.split(":")[0]);
  542. }
  543. }
  544. var ipsText = '';
  545. for (var i = 0; i < ips.length; i++) {
  546. ipsText += ips[i] + '\n';
  547. }
  548. var histogram_div = document.getElementById('datanode-usage-histogram');
  549. histogram_div.setAttribute('style', 'position: relative');
  550. var ips_div = document.createElement("textarea");
  551. ips_div.setAttribute('id', 'datanode_ips');
  552. ips_div.setAttribute('rows', '8');
  553. ips_div.setAttribute('cols', '14');
  554. ips_div.setAttribute('style', 'position: absolute;top: 0px;right: -38px;');
  555. ips_div.setAttribute('readonly', 'readonly');
  556. histogram_div.appendChild(ips_div);
  557. var close_div = document.createElement("div");
  558. histogram_div.appendChild(close_div);
  559. close_div.setAttribute('id', 'close_ips');
  560. close_div.setAttribute('style', 'position: absolute;top: 0px;right: -62px;width:20px;height;20px');
  561. close_div.setAttribute('onclick', 'close_hostip_list()');
  562. close_div.innerHTML = "X";
  563. ips_div.innerHTML = ipsText;
  564. }
  565. function close_hostip_list() {
  566. $("#datanode_ips").remove();
  567. $("#close_ips").remove();
  568. }