1
0

dfshealth.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. var data = {};
  21. function generate_browse_dn_link(info_http_addr, info_https_addr) {
  22. var is_https = window.location.protocol === 'https:';
  23. var authority = is_https ? info_https_addr : info_http_addr;
  24. var nn_info_port = window.location.port;
  25. if (nn_info_port === "") {
  26. nn_info_port = is_https ? 443 : 80;
  27. }
  28. var l = '//' + authority + '/browseDirectory.jsp?dir=%2F&namenodeInfoPort=' +
  29. nn_info_port + '&nnaddr=' + data.nnstat.HostAndPort;
  30. return l;
  31. }
  32. function render() {
  33. var helpers = {
  34. 'helper_fs_max_objects': function (chunk, ctx, bodies, params) {
  35. var o = ctx.current();
  36. if (o.MaxObjects > 0) {
  37. chunk.write('(' + Math.round((o.FilesTotal + o.BlockTotal) / o.MaxObjects * 100) * 100 + ')%');
  38. }
  39. },
  40. 'helper_dir_status': function (chunk, ctx, bodies, params) {
  41. var j = ctx.current();
  42. for (var i in j) {
  43. chunk.write('<tr><td>' + i + '</td><td>' + j[i] + '</td><td>' + params.type + '</td></tr>');
  44. }
  45. }
  46. };
  47. var base = dust.makeBase(helpers);
  48. var TEMPLATES = [ { 'name': 'dfshealth', 'url': 'dfshealth.dust.html' } ];
  49. load_templates(dust, TEMPLATES, function() {
  50. dust.render('dfshealth', base.push(data), function(err, out) {
  51. $('#panel').append(out);
  52. $('#browse-dir-first').click(function () {
  53. var len = data.nn.LiveNodes.length;
  54. if (len < 1) {
  55. show_err_msg('Cannot browse the DFS since there are no live nodes available.');
  56. return false;
  57. }
  58. var dn = data.nn.LiveNodes[Math.floor(Math.random() * len)];
  59. window.location.href = generate_browse_dn_link(dn.infoAddr, dn.infoSecureAddr);
  60. });
  61. $('.browse-dir-links').click(function () {
  62. var http_addr = $(this).attr('info-http-addr'), https_addr = $(this).attr('info-https-addr');
  63. window.location.href = generate_browse_dn_link(http_addr, https_addr);
  64. });
  65. });
  66. }, function () {
  67. show_err_msg('Failed to load the page.');
  68. });
  69. }
  70. var BEANS = [
  71. {"name": "nn", "url": "/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo"},
  72. {"name": "nnstat", "url": "/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus"},
  73. {"name": "fs", "url": "/jmx?qry=Hadoop:service=NameNode,name=FSNamesystemState"},
  74. {"name": "mem", "url": "/jmx?qry=java.lang:type=Memory"},
  75. {"name": "startup", "url": "/startupProgress"}
  76. ];
  77. // Workarounds for the fact that JMXJsonServlet returns non-standard JSON strings
  78. function data_workaround(d) {
  79. function node_map_to_array(nodes) {
  80. var res = [];
  81. for (var n in nodes) {
  82. var p = nodes[n];
  83. p.name = n;
  84. res.push(p);
  85. }
  86. return res;
  87. }
  88. function startup_progress_workaround(r) {
  89. function rename_property(o, s, d) {
  90. if (o[s] !== undefined) {
  91. o[d] = o[s];
  92. delete o[s];
  93. }
  94. }
  95. r.percentComplete *= 100;
  96. $.each(r.phases, function (idx, p) {
  97. p.percentComplete *= 100;
  98. $.each(p.steps, function (idx2, s) {
  99. s.percentComplete *= 100;
  100. // dust.js is confused by these optional keys in nested
  101. // structure, rename them
  102. rename_property(s, "desc", "stepDesc");
  103. rename_property(s, "file", "stepFile");
  104. rename_property(s, "size", "stepSize");
  105. });
  106. });
  107. return r;
  108. }
  109. d.nn.JournalTransactionInfo = JSON.parse(d.nn.JournalTransactionInfo);
  110. d.nn.NameJournalStatus = JSON.parse(d.nn.NameJournalStatus);
  111. d.nn.NameDirStatuses = JSON.parse(d.nn.NameDirStatuses);
  112. d.nn.NodeUsage = JSON.parse(d.nn.NodeUsage);
  113. d.nn.LiveNodes = node_map_to_array(JSON.parse(d.nn.LiveNodes));
  114. d.nn.DeadNodes = node_map_to_array(JSON.parse(d.nn.DeadNodes));
  115. d.nn.DecomNodes = node_map_to_array(JSON.parse(d.nn.DecomNodes));
  116. d.nn.CorruptFiles = JSON.parse(d.nn.CorruptFiles);
  117. d.fs.SnapshotStats = JSON.parse(d.fs.SnapshotStats);
  118. d.startup = startup_progress_workaround(d.startup);
  119. return d;
  120. }
  121. function show_err_msg(msg) {
  122. $('#alert-panel-body').html(msg);
  123. $('#alert-panel').show();
  124. }
  125. load_json(
  126. BEANS,
  127. function(d) {
  128. for (var k in d) {
  129. data[k] = k === "startup" ? d[k] : d[k].beans[0];
  130. }
  131. data = data_workaround(data);
  132. render();
  133. },
  134. function (url, jqxhr, text, err) {
  135. show_err_msg('<p>Failed to retrieve data from ' + url + ', cause: ' + err + '</p>');
  136. });
  137. })();