dn.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 = {ozone: {enabled: false}};
  21. dust.loadSource(dust.compile($('#tmpl-dn').html(), 'dn'));
  22. function loadDatanodeInfo() {
  23. $.get('/jmx?qry=Hadoop:service=DataNode,name=DataNodeInfo', function(resp) {
  24. data.dn = workaround(resp.beans[0]);
  25. data.dn.HostName = resp.beans[0]['DatanodeHostname'];
  26. render();
  27. }).fail(show_err_msg);
  28. }
  29. function loadOzoneScmInfo() {
  30. $.get('/jmx?qry=Hadoop:service=OzoneDataNode,name=SCMConnectionManager', function (resp) {
  31. if (resp.beans.length > 0) {
  32. data.ozone.SCMServers = resp.beans[0].SCMServers;
  33. data.ozone.enabled = true;
  34. render();
  35. }
  36. }).fail(show_err_msg);
  37. }
  38. function loadOzoneStorageInfo() {
  39. $.get('/jmx?qry=Hadoop:service=OzoneDataNode,name=ContainerLocationManager', function (resp) {
  40. if (resp.beans.length > 0) {
  41. data.ozone.LocationReport = resp.beans[0].LocationReport;
  42. data.ozone.enabled = true;
  43. render();
  44. }
  45. }).fail(show_err_msg);
  46. }
  47. function workaround(dn) {
  48. function node_map_to_array(nodes) {
  49. var res = [];
  50. for (var n in nodes) {
  51. var p = nodes[n];
  52. p.name = n;
  53. res.push(p);
  54. }
  55. return res;
  56. }
  57. dn.VolumeInfo = node_map_to_array(JSON.parse(dn.VolumeInfo));
  58. dn.BPServiceActorInfo = JSON.parse(dn.BPServiceActorInfo);
  59. return dn;
  60. }
  61. function render() {
  62. var base = dust.makeBase({
  63. 'helper_relative_time' : function (chunk, ctx, bodies, params) {
  64. var value = dust.helpers.tap(params.value, chunk, ctx);
  65. return chunk.write(moment().subtract(Number(value), 'seconds').fromNow(true));
  66. }
  67. });
  68. dust.render('dn', base.push(data), function(err, out) {
  69. $('#tab-overview').html(out);
  70. $('#tab-overview').addClass('active');
  71. });
  72. }
  73. function show_err_msg() {
  74. $('#alert-panel-body').html("Failed to load datanode information");
  75. $('#alert-panel').show();
  76. }
  77. loadDatanodeInfo();
  78. loadOzoneScmInfo();
  79. loadOzoneStorageInfo();
  80. })();