123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- (function () {
- "use strict";
- dust.loadSource(dust.compile($('#tmpl-dfshealth').html(), 'dfshealth'));
- dust.loadSource(dust.compile($('#tmpl-startup-progress').html(), 'startup-progress'));
- dust.loadSource(dust.compile($('#tmpl-datanode').html(), 'datanode-info'));
- dust.loadSource(dust.compile($('#tmpl-snapshot').html(), 'snapshot-info'));
- function load_overview() {
- var BEANS = [
- {"name": "nn", "url": "/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo"},
- {"name": "nnstat", "url": "/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus"},
- {"name": "fs", "url": "/jmx?qry=Hadoop:service=NameNode,name=FSNamesystemState"},
- {"name": "mem", "url": "/jmx?qry=java.lang:type=Memory"}
- ];
- var HELPERS = {
- 'helper_fs_max_objects': function (chunk, ctx, bodies, params) {
- var o = ctx.current();
- if (o.MaxObjects > 0) {
- chunk.write('(' + Math.round((o.FilesTotal + o.BlockTotal) / o.MaxObjects * 100) * 100 + ')%');
- }
- },
- 'helper_dir_status': function (chunk, ctx, bodies, params) {
- var j = ctx.current();
- for (var i in j) {
- chunk.write('<tr><td>' + i + '</td><td>' + j[i] + '</td><td>' + params.type + '</td></tr>');
- }
- }
- };
- var data = {};
- // Workarounds for the fact that JMXJsonServlet returns non-standard JSON strings
- function workaround(nn) {
- nn.JournalTransactionInfo = JSON.parse(nn.JournalTransactionInfo);
- nn.NameJournalStatus = JSON.parse(nn.NameJournalStatus);
- nn.NameDirStatuses = JSON.parse(nn.NameDirStatuses);
- nn.NodeUsage = JSON.parse(nn.NodeUsage);
- nn.CorruptFiles = JSON.parse(nn.CorruptFiles);
- return nn;
- }
- load_json(
- BEANS,
- guard_with_startup_progress(function(d) {
- for (var k in d) {
- data[k] = k === 'nn' ? workaround(d[k].beans[0]) : d[k].beans[0];
- }
- render();
- }),
- function (url, jqxhr, text, err) {
- show_err_msg('<p>Failed to retrieve data from ' + url + ', cause: ' + err + '</p>');
- });
- function render() {
- var base = dust.makeBase(HELPERS);
- dust.render('dfshealth', base.push(data), function(err, out) {
- $('#tab-overview').html(out);
- $('a[href="#tab-datanode"]').click(load_datanode_info);
- $('#ui-tabs a[href="#tab-overview"]').tab('show');
- });
- }
- }
- $('#ui-tabs a[href="#tab-overview"]').click(load_overview);
- function show_err_msg(msg) {
- $('#alert-panel-body').html(msg);
- $('#alert-panel').show();
- }
- function ajax_error_handler(url, jqxhr, text, err) {
- show_err_msg('<p>Failed to retrieve data from ' + url + ', cause: ' + err + '</p>');
- }
- function guard_with_startup_progress(fn) {
- return function() {
- try {
- fn.apply(this, arguments);
- } catch (err) {
- if (err instanceof TypeError) {
- show_err_msg('NameNode is still loading. Redirecting to the Startup Progress page.');
- load_startup_progress();
- }
- }
- };
- }
- function load_startup_progress() {
- function workaround(r) {
- function rename_property(o, s, d) {
- if (o[s] !== undefined) {
- o[d] = o[s];
- delete o[s];
- }
- }
- r.percentComplete *= 100;
- $.each(r.phases, function (idx, p) {
- p.percentComplete *= 100;
- $.each(p.steps, function (idx2, s) {
- s.percentComplete *= 100;
- // dust.js is confused by these optional keys in nested
- // structure, rename them
- rename_property(s, "desc", "stepDesc");
- rename_property(s, "file", "stepFile");
- rename_property(s, "size", "stepSize");
- });
- });
- return r;
- }
- $.get('/startupProgress', function (resp) {
- var data = workaround(resp);
- dust.render('startup-progress', data, function(err, out) {
- $('#tab-startup-progress').html(out);
- $('#ui-tabs a[href="#tab-startup-progress"]').tab('show');
- });
- }).error(ajax_error_handler);
- }
- $('#ui-tabs a[href="#tab-startup-progress"]').click(load_startup_progress);
- function load_datanode_info() {
- function workaround(r) {
- function node_map_to_array(nodes) {
- var res = [];
- for (var n in nodes) {
- var p = nodes[n];
- p.name = n;
- res.push(p);
- }
- return res;
- }
- r.LiveNodes = node_map_to_array(JSON.parse(r.LiveNodes));
- r.DeadNodes = node_map_to_array(JSON.parse(r.DeadNodes));
- r.DecomNodes = node_map_to_array(JSON.parse(r.DecomNodes));
- return r;
- }
- $.get(
- '/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo',
- guard_with_startup_progress(function (resp) {
- var data = workaround(resp.beans[0]);
- dust.render('datanode-info', data, function(err, out) {
- $('#tab-datanode').html(out);
- $('#ui-tabs a[href="#tab-datanode"]').tab('show');
- });
- })).error(ajax_error_handler);
- }
- $('a[href="#tab-datanode"]').click(load_datanode_info);
- function load_snapshot_info() {
- $.get(
- '/jmx?qry=Hadoop:service=NameNode,name=FSNamesystemState',
- guard_with_startup_progress(function (resp) {
- var data = JSON.parse(resp.beans[0].SnapshotStats);
- dust.render('snapshot-info', data, function(err, out) {
- $('#tab-snapshot').html(out);
- $('#ui-tabs a[href="#tab-snapshot"]').tab('show');
- });
- })).error(ajax_error_handler);
- }
- $('#ui-tabs a[href="#tab-snapshot"]').click(load_snapshot_info);
- function load_page() {
- var hash = window.location.hash;
- switch(hash) {
- case "#tab-datanode":
- load_datanode_info();
- break;
- case "#tab-snapshot":
- load_snapshot_info();
- break;
- case "#tab-startup-progress":
- load_startup_progress();
- break;
- case "#tab-overview":
- load_overview();
- break;
- default:
- window.location.hash = "tab-overview";
- break;
- }
- }
- load_page();
- $(window).bind('hashchange', function () {
- load_page();
- });
- })();
|