dn.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. dust.loadSource(dust.compile($('#tmpl-dn').html(), 'dn'));
  22. function load() {
  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 workaround(dn) {
  30. function node_map_to_array(nodes) {
  31. var res = [];
  32. for (var n in nodes) {
  33. var p = nodes[n];
  34. p.name = n;
  35. res.push(p);
  36. }
  37. return res;
  38. }
  39. dn.VolumeInfo = node_map_to_array(JSON.parse(dn.VolumeInfo));
  40. dn.BPServiceActorInfo = JSON.parse(dn.BPServiceActorInfo);
  41. return dn;
  42. }
  43. function render() {
  44. var base = dust.makeBase({
  45. 'helper_relative_time' : function (chunk, ctx, bodies, params) {
  46. var value = dust.helpers.tap(params.value, chunk, ctx);
  47. return chunk.write(moment().subtract(Number(value), 'seconds').fromNow(true));
  48. }
  49. });
  50. dust.render('dn', base.push(data), function(err, out) {
  51. $('#tab-overview').html(out);
  52. $('#tab-overview').addClass('active');
  53. });
  54. }
  55. function show_err_msg() {
  56. $('#alert-panel-body').html("Failed to load datanode information");
  57. $('#alert-panel').show();
  58. }
  59. load();
  60. })();