jn.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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-jn').html(), 'jn'));
  22. var BEANS = [
  23. {"name": "jn", "url": "/jmx?qry=Hadoop:service=JournalNode,name=JournalNodeInfo"},
  24. {"name": "journals", "url": "/jmx?qry=Hadoop:service=JournalNode,name=Journal-*"}
  25. ];
  26. var HELPERS = {
  27. 'helper_date_tostring' : function (chunk, ctx, bodies, params) {
  28. var value = dust.helpers.tap(params.value, chunk, ctx);
  29. return chunk.write('' + moment(Number(value)).format('ddd MMM DD HH:mm:ss ZZ YYYY'));
  30. }
  31. };
  32. load_json(
  33. BEANS,
  34. guard_with_startup_progress(function(d) {
  35. for (var k in d) {
  36. data[k] = k === 'journals' ? workaround(d[k].beans) : d[k].beans[0];
  37. }
  38. render();
  39. }),
  40. function (url, jqxhr, text, err) {
  41. show_err_msg('<p>Failed to retrieve data from ' + url + ', cause: ' + err + '</p>');
  42. });
  43. function guard_with_startup_progress(fn) {
  44. return function() {
  45. try {
  46. fn.apply(this, arguments);
  47. } catch (err) {
  48. if (err instanceof TypeError) {
  49. show_err_msg('JournalNode error: ' + err);
  50. }
  51. }
  52. };
  53. }
  54. function workaround(journals) {
  55. for (var i in journals){
  56. journals[i]['NameService']= journals[i]['modelerType'].split("-")[1];
  57. }
  58. return journals;
  59. }
  60. function render() {
  61. var base = dust.makeBase(HELPERS);
  62. dust.render('jn', base.push(data), function(err, out) {
  63. $('#tab-overview').html(out);
  64. $('#tab-overview').addClass('active');
  65. });
  66. }
  67. function show_err_msg() {
  68. $('#alert-panel-body').html("Failed to load journalnode information");
  69. $('#alert-panel').show();
  70. }
  71. })();