This is an automated email from the ASF dual-hosted git repository.

ctubbsii pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/2.1 by this push:
     new 313238b5e8 Roll up the manager's safe mode status indicator to the nav 
bar (#3561)
313238b5e8 is described below

commit 313238b5e8887f3e70809d920c1d359fc1b29010
Author: Dom G <[email protected]>
AuthorDate: Sun Aug 13 23:22:43 2023 -0400

    Roll up the manager's safe mode status indicator to the nav bar (#3561)
    
    When the manager is in safe mode, make its icon in the server nav menu
    yellow, and roll that yellow indicator up into the top bar.
---
 .../apache/accumulo/monitor/resources/js/navbar.js | 230 ++++++++++++++-------
 1 file changed, 152 insertions(+), 78 deletions(-)

diff --git 
a/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/navbar.js
 
b/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/navbar.js
index cc49d3a736..00840c93d7 100644
--- 
a/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/navbar.js
+++ 
b/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/navbar.js
@@ -19,115 +19,189 @@
 "use strict";
 
 /**
- * Creates the initial sidebar
+ * The status options from the servers
  */
-$(document).ready(function () {
-  refreshSidebar();
-});
+const STATUS = {
+  WARN: 'WARN',
+  OK: 'OK',
+  ERROR: 'ERROR'
+};
 
 /**
- * Makes the REST calls, generates the sidebar with the new information
+ * The class names of bootstrap notification color classes
  */
-function refreshSidebar() {
-  getStatus().then(function () {
-    refreshSideBarNotifications();
-  });
-}
+const CLASS = {
+  WARNING: 'warning',
+  NORMAL: 'normal',
+  ERROR: 'error'
+};
 
 /**
- * Used to redraw the navbar
+ * Remove other bootstrap color classes and add the given class to the given 
element
+ * @param {string} elementId the element id to update
+ * @param {string} status the status of that element. used to set the 
associated color
  */
-function refreshNavBar() {
-  refreshSidebar();
+function updateElementStatus(elementId, status) {
+  const $element = $(`#${elementId}`);
+
+  switch (status) {
+  case STATUS.ERROR:
+    
$element.removeClass(CLASS.NORMAL).removeClass(CLASS.WARNING).addClass(CLASS.ERROR);
+    break;
+  case STATUS.WARN:
+    
$element.removeClass(CLASS.NORMAL).removeClass(CLASS.ERROR).addClass(CLASS.WARNING);
+    break;
+  case STATUS.OK:
+    
$element.removeClass(CLASS.ERROR).removeClass(CLASS.WARNING).addClass(CLASS.NORMAL);
+    break;
+  default:
+    console.error('Unrecognized status: ' + status);
+  }
 }
 
 /**
- * Generates the sidebar notifications for servers and logs
+ * Updates the notifications of the servers dropdown notification as well as 
the individual server notifications.
+ * @param {JSON} statusData object containing the status info for the servers
  */
-function refreshSideBarNotifications() {
+function updateServerNotifications(statusData) {
+  getManager().then(function () {
 
-  var data = sessionStorage.status === undefined ?
-    undefined : JSON.parse(sessionStorage.status);
+    // gather information about the manager
+    const managerData = JSON.parse(sessionStorage.manager);
+    const managerState = managerData.managerState;
+    const managerGoalState = managerData.managerGoalState;
 
-  // Setting individual status notification
-  if (data.managerStatus === 'OK') {
-    $('#managerStatusNotification').removeClass('error').addClass('normal');
-  } else {
-    $('#managerStatusNotification').removeClass('normal').addClass('error');
-  }
-  if (data.tServerStatus === 'OK') {
-    $('#serverStatusNotification').removeClass('error').removeClass('warning').
-    addClass('normal');
-  } else if (data.tServerStatus === 'WARN') {
-    $('#serverStatusNotification').removeClass('error').removeClass('normal').
-    addClass('warning');
-  } else {
-    
$('#serverStatusNotification').removeClass('normal').removeClass('warning').
-    addClass('error');
-  }
-  if (data.gcStatus === 'OK') {
-    $('#gcStatusNotification').removeClass('error').addClass('normal');
-  } else {
-    $('#gcStatusNotification').addClass('error').removeClass('normal');
-  }
+    const isSafeMode = managerState === 'SAFE_MODE' || managerGoalState === 
'SAFE_MODE';
+    const isCleanStop = managerState === 'CLEAN_STOP' || managerGoalState === 
'CLEAN_STOP';
 
-  // Setting overall status notification
-  if (data.managerStatus === 'OK' &&
-    data.tServerStatus === 'OK' &&
-    data.gcStatus === 'OK') {
-    $('#statusNotification').removeClass('error').removeClass('warning').
-    addClass('normal');
-  } else if (data.managerStatus === 'ERROR' ||
-    data.tServerStatus === 'ERROR' ||
-    data.gcStatus === 'ERROR') {
-    $('#statusNotification').removeClass('normal').removeClass('warning').
-    addClass('error');
-  } else if (data.tServerStatus === 'WARN') {
-    $('#statusNotification').removeClass('normal').removeClass('error').
-    addClass('warning');
-  }
+    // setting manager status notification
+    if (statusData.managerStatus === STATUS.ERROR || isCleanStop) {
+      updateElementStatus('managerStatusNotification', STATUS.ERROR);
+    } else if (statusData.managerStatus === STATUS.WARN || isSafeMode) {
+      updateElementStatus('managerStatusNotification', STATUS.WARN);
+    } else if (statusData.managerStatus === STATUS.OK) {
+      updateElementStatus('managerStatusNotification', STATUS.OK);
+    } else {
+      console.error('Unrecognized manager state: ' + statusData.managerStatus 
+ '. Could not properly set manager status notification.');
+    }
 
-  // Setting "Recent Logs" notifications
-  // Color
-  if (data.logNumber > 0) {
-    if (data.logsHaveError) {
-      
$('#recentLogsNotifications').removeClass('warning').removeClass('normal').addClass('error');
+    // setting tserver status notification
+    if (statusData.tServerStatus === STATUS.OK) {
+      updateElementStatus('serverStatusNotification', STATUS.OK);
+    } else if (statusData.tServerStatus === STATUS.WARN) {
+      updateElementStatus('serverStatusNotification', STATUS.WARN);
+    } else {
+      updateElementStatus('serverStatusNotification', STATUS.ERROR);
+    }
+
+    // setting gc status notification
+    if (statusData.gcStatus === STATUS.OK) {
+      updateElementStatus('gcStatusNotification', STATUS.OK);
+    } else {
+      updateElementStatus('gcStatusNotification', STATUS.ERROR);
+    }
+
+    // Setting overall servers status notification
+    if ((statusData.managerStatus === STATUS.OK && !isSafeMode && 
!isCleanStop) &&
+      statusData.tServerStatus === STATUS.OK &&
+      statusData.gcStatus === STATUS.OK) {
+      updateElementStatus('statusNotification', STATUS.OK);
+    } else if (statusData.managerStatus === STATUS.ERROR || isCleanStop ||
+      statusData.tServerStatus === STATUS.ERROR ||
+      statusData.gcStatus === STATUS.ERROR) {
+      updateElementStatus('statusNotification', STATUS.ERROR);
+    } else if (statusData.managerStatus === STATUS.WARN || isSafeMode ||
+      statusData.tServerStatus === STATUS.WARN ||
+      statusData.gcStatus === STATUS.WARN) {
+      updateElementStatus('statusNotification', STATUS.WARN);
+    }
+
+  });
+}
+
+/**
+ * Updates the notification color for the recent logs icon within the debug 
dropdown
+ */
+function updateRecentLogsNotification(statusData) {
+  if (statusData.logNumber > 0) {
+    if (statusData.logsHaveError) {
+      updateElementStatus('recentLogsNotifications', STATUS.ERROR);
     } else {
-      
$('#recentLogsNotifications').removeClass('error').removeClass('normal').addClass('warning');
+      updateElementStatus('recentLogsNotifications', STATUS.WARN);
     }
   } else {
-    
$('#recentLogsNotifications').removeClass('error').removeClass('warning').addClass('normal');
+    updateElementStatus('recentLogsNotifications', STATUS.OK);
   }
   // Number
-  var logNumber = data.logNumber > 99 ? '99+' : data.logNumber;
+  const logNumber = statusData.logNumber > 99 ? '99+' : statusData.logNumber;
   $('#recentLogsNotifications').html(logNumber);
+}
 
-
-  // Setting "Table Problems" notifications
-  // Color
-  if (data.problemNumber > 0) {
-    $('#tableProblemsNotifications').removeClass('normal').addClass('error');
+/**
+ * Updates the notification color for the table problems icon within the debug 
dropdown
+ */
+function updateTableProblemsNotification(statusData) {
+  if (statusData.problemNumber > 0) {
+    updateElementStatus('tableProblemsNotifications', STATUS.ERROR);
   } else {
-    $('#tableProblemsNotifications').removeClass('error').addClass('normal');
+    updateElementStatus('tableProblemsNotifications', STATUS.OK);
   }
   // Number
-  var problemNumber = data.problemNumber > 99 ? '99+' : data.problemNumber;
+  var problemNumber = statusData.problemNumber > 99 ? '99+' : 
statusData.problemNumber;
   $('#tableProblemsNotifications').html(problemNumber);
+}
 
-
-  // Setting "Debug" overall logs notifications
-  // Color
-  if (data.logNumber > 0 || data.problemNumber > 0) {
-    if (data.logsHaveError || data.problemNumber > 0) {
-      
$('#errorsNotification').removeClass('warning').removeClass('normal').addClass('error');
+/**
+ * Updates the notification color for the debug dropdown icon
+ */
+function updateDebugDropdownNotification(statusData) {
+  if (statusData.logNumber > 0 || statusData.problemNumber > 0) {
+    if (statusData.logsHaveError || statusData.problemNumber > 0) {
+      updateElementStatus('errorsNotification', STATUS.ERROR);
     } else {
-      
$('#errorsNotification').removeClass('error').removeClass('normal').addClass('warning');
+      updateElementStatus('errorsNotification', STATUS.WARN);
     }
   } else {
-    
$('#errorsNotification').removeClass('error').removeClass('warning').addClass('normal');
+    updateElementStatus('errorsNotification', STATUS.OK);
   }
   // Number
-  var totalNumber = data.logNumber + data.problemNumber > 99 ?
-    '99+' : data.logNumber + data.problemNumber;
+  var totalNumber = statusData.logNumber + statusData.problemNumber > 99 ?
+    '99+' : statusData.logNumber + statusData.problemNumber;
   $('#errorsNotification').html(totalNumber);
 }
+
+/**
+ * Creates the initial sidebar
+ */
+$(document).ready(function () {
+  refreshSidebar();
+});
+
+/**
+ * Makes the REST call for the server status, generates the sidebar with the 
new information
+ */
+function refreshSidebar() {
+  getStatus().then(function () {
+    refreshSideBarNotifications();
+  });
+}
+
+/**
+ * Used to redraw the navbar
+ */
+function refreshNavBar() {
+  refreshSidebar();
+}
+
+/**
+ * Generates the sidebar notifications for servers and logs
+ */
+function refreshSideBarNotifications() {
+
+  const statusData = sessionStorage?.status ? 
JSON.parse(sessionStorage.status) : undefined;
+
+  updateServerNotifications(statusData);
+  updateRecentLogsNotification(statusData);
+  updateTableProblemsNotification(statusData);
+  updateDebugDropdownNotification(statusData);
+}

Reply via email to