jn.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. var str= journals[i]['modelerType'];
  57. var index= str.indexOf("-");
  58. journals[i]['NameService']= str.substr(index + 1);
  59. }
  60. return journals;
  61. }
  62. function render() {
  63. var base = dust.makeBase(HELPERS);
  64. dust.render('jn', base.push(data), function(err, out) {
  65. $('#tab-overview').html(out);
  66. $('#tab-overview').addClass('active');
  67. });
  68. }
  69. function show_err_msg() {
  70. $('#alert-panel-body').html("Failed to load journalnode information");
  71. $('#alert-panel').show();
  72. }
  73. })();