milleruntime commented on code in PR #2685:
URL: https://github.com/apache/accumulo/pull/2685#discussion_r869097338
##########
server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/tservers.js:
##########
@@ -16,165 +16,94 @@
* specific language governing permissions and limitations
* under the License.
*/
+/* JSLint global definitions */
+/*global
+ $, document, sessionStorage, getTServers, clearDeadServers, refreshNavBar,
+ getRecoveryList, bigNumberForQuantity, timeDuration, dateFormat
+*/
"use strict";
-var tserversTable;
+var tserversTable, deadTServersTable, badTServersTable;
var recoveryList = [];
/**
- * Creates tservers initial table
+ * Refreshes the list of recovering tservers used to highlight rows
*/
-$(document).ready(function() {
-
- refreshRecoveryList();
-
- // Create a table for tserver list
- tserversTable = $('#tservers').DataTable({
- "ajax": {
- "url": '/rest/tservers',
- "dataSrc": "servers"
- },
- "stateSave": true,
- "columnDefs": [
- { "targets": "big-num",
- "render": function ( data, type, row ) {
- if(type === 'display') data = bigNumberForQuantity(data);
- return data;
- }
- },
- { "targets": "duration",
- "render": function ( data, type, row ) {
- if(type === 'display') data = timeDuration(data);
- return data;
- }
- },
- { "targets": "percent",
- "render": function ( data, type, row ) {
- if(type === 'display') data = Math.round(data * 100) + '%';
- return data;
- }
- }
- ],
- "columns": [
- { "data": "hostname",
- "type": "html",
- "render": function ( data, type, row, meta ) {
- if(type === 'display') data = '<a href="/tservers?s=' + row.id +
'">' + row.hostname + '</a>';
- return data;
- }
- },
- { "data": "tablets" },
- { "data": "lastContact" },
- { "data": "responseTime" },
- { "data": "entries" },
- { "data": "ingest" },
- { "data": "query" },
- { "data": "holdtime" },
- { "data": "scansCombo" },
- { "data": "minorCombo" },
- { "data": "majorCombo" },
- { "data": "indexCacheHitRate" },
- { "data": "dataCacheHitRate" },
- { "data": "osload" }
- ],
- "rowCallback": function (row, data, index) {
- // reset background of each row
- $(row).css('background-color', '');
-
- // return if the current row's tserver is not recovering
- if (!recoveryList.includes(data.hostname))
- return;
-
- // only show the caption if we know there are rows in the tservers
table
- $('#recovery-caption').show();
-
- // highlight current row
- console.log('Highlighting row index:' + index + ' tserver:' +
data.hostname);
- $(row).css('background-color', 'gold');
- }
+function refreshRecoveryList() {
+ $('#recovery-caption').hide(); // Hide the caption about highlighted rows
on each refresh
+ getRecoveryList().then(function () {
+ recoveryList = [];
+ var data = sessionStorage.recoveryList === undefined ?
+ [] : JSON.parse(sessionStorage.recoveryList);
+ data.recoveryList.forEach(function (entry) {
+ recoveryList.push(entry.server);
+ });
});
- refreshTServers();
-});
+}
/**
- * Makes the REST calls, generates the tables with the new information
+ * Performs an ajax reload for the given Datatable
+ *
+ * @param {DataTable} table DataTable to perform an ajax reload on
*/
-function refreshTServers() {
- getTServers().then(function() {
- refreshBadTServersTable();
- refreshDeadTServersTable();
- refreshRecoveryList();
- refreshTServersTable();
- });
+function ajaxReloadTable(table) {
+ if (table) {
+ table.ajax.reload(null, false); // user paging is not reset on reload
+ }
}
/**
- * Used to redraw the page
+ * Refreshes data in the tserver table
*/
-function refresh() {
- refreshTServers();
+function refreshTServersTable() {
+ refreshRecoveryList();
+ ajaxReloadTable(tserversTable);
}
/**
- * Generates the tservers rows
+ * Refreshes data in the deadtservers table
*/
-function refreshBadTServersTable() {
- $('#badtservers').hide(); // Hide table on each refresh
-
- var data = sessionStorage.tservers === undefined ?
- [] : JSON.parse(sessionStorage.tservers);
-
- clearTableBody('badtservers');
-
- // return if the table is empty
- if (data.length === 0 || data.badServers.length === 0)
- return;
-
- $('#badtservers').show();
- $.each(data.badServers, function (key, val) {
- var items = [];
- items.push(createFirstCell(val.id, val.id));
- items.push(createRightCell(val.status, val.status));
+function refreshDeadTServersTable() {
+ ajaxReloadTable(deadTServersTable);
- $('<tr/>', {
- html: items.join('')
- }).appendTo('#badtservers tbody');
- });
+ // Only show the table if there are non-empty rows
+ if ($('#deadtservers tbody .dataTables_empty').length) {
+ $('#deadtservers_wrapper').hide();
+ } else {
+ $('#deadtservers_wrapper').show();
+ }
}
-
/**
- * Generates the deadtservers rows
+ * Refreshes data in the badtservers table
*/
-function refreshDeadTServersTable() {
- $('#deadtservers').hide(); // Hide table on each refresh
-
- var data = sessionStorage.tservers === undefined ?
- [] : JSON.parse(sessionStorage.tservers);
-
- clearTableBody('deadtservers');
-
- // return if the table is empty
- if (data.length === 0 || data.deadServers.length === 0)
- return;
-
- $('#deadtservers').show();
- $.each(data.deadServers, function (key, val) {
- var items = [];
- items.push(createFirstCell(val.server, val.server));
+function refreshBadTServersTable() {
+ ajaxReloadTable(badTServersTable);
- var date = new Date(val.lastStatus);
- date = date.toLocaleString().split(' ').join(' ');
- items.push(createRightCell(val.lastStatus, date));
- items.push(createRightCell(val.status, val.status));
- items.push(createRightCell('', '<a href="javascript:clearDeadTServers(\'' +
- val.server + '\');">clear</a>'));
+ // Only show the table if there are non-empty rows
+ if ($('#badtservers tbody .dataTables_empty').length) {
Review Comment:
Nice! Sorry I missed this, ignore my other comment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]