ArafatKhan2198 commented on code in PR #5803:
URL: https://github.com/apache/ozone/pull/5803#discussion_r1428870466


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/SCMNodeManager.java:
##########
@@ -1080,6 +1084,48 @@ public Map<String, Map<String, String>> 
getNodeStatusInfo() {
     return nodes;
   }
 
+  /**
+   * Based on the current time and the last heartbeat, calculate the time 
difference
+   * and get a string of the relative value. E.g. "2s ago", "1m 2s ago", etc.
+   *
+   * @return string with the relative value of the time diff.
+   */
+  public String getLastHeartbeatTimeDiff(long lastHeartbeatTime) {
+    long currentTime = Time.monotonicNow();
+    long timeDiff = currentTime - lastHeartbeatTime;
+
+    // Time is in ms. Calculate total time in seconds.
+    long seconds = timeDiff / 1000;
+    // Calculate days and subtract them from seconds.
+    long days = seconds / (24 * 60 * 60);
+    seconds -= days * 24 * 60 * 60;

Review Comment:
   ```suggestion
       long days = TimeUnit.MILLISECONDS.toDays(timeDiff);
       timeDiff -= TimeUnit.DAYS.toMillis(days);
   ```



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/SCMNodeManager.java:
##########
@@ -1080,6 +1084,48 @@ public Map<String, Map<String, String>> 
getNodeStatusInfo() {
     return nodes;
   }
 
+  /**
+   * Based on the current time and the last heartbeat, calculate the time 
difference
+   * and get a string of the relative value. E.g. "2s ago", "1m 2s ago", etc.
+   *
+   * @return string with the relative value of the time diff.
+   */
+  public String getLastHeartbeatTimeDiff(long lastHeartbeatTime) {
+    long currentTime = Time.monotonicNow();
+    long timeDiff = currentTime - lastHeartbeatTime;
+
+    // Time is in ms. Calculate total time in seconds.
+    long seconds = timeDiff / 1000;
+    // Calculate days and subtract them from seconds.
+    long days = seconds / (24 * 60 * 60);
+    seconds -= days * 24 * 60 * 60;
+    // Calculate hours and subtract them from seconds.
+    long hours = seconds / (60 * 60);
+    seconds -= hours * 60 * 60;
+    // Calculate minutes and subtract them from seconds.
+    long minutes = seconds / 60;
+    seconds -= minutes * 60;

Review Comment:
   ```suggestion
       long minutes = TimeUnit.MILLISECONDS.toMinutes(timeDiff);
       timeDiff -= TimeUnit.MINUTES.toMillis(minutes);
   ```



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/SCMNodeManager.java:
##########
@@ -1080,6 +1084,48 @@ public Map<String, Map<String, String>> 
getNodeStatusInfo() {
     return nodes;
   }
 
+  /**
+   * Based on the current time and the last heartbeat, calculate the time 
difference
+   * and get a string of the relative value. E.g. "2s ago", "1m 2s ago", etc.
+   *
+   * @return string with the relative value of the time diff.
+   */
+  public String getLastHeartbeatTimeDiff(long lastHeartbeatTime) {
+    long currentTime = Time.monotonicNow();
+    long timeDiff = currentTime - lastHeartbeatTime;
+
+    // Time is in ms. Calculate total time in seconds.
+    long seconds = timeDiff / 1000;

Review Comment:
   You can also use the TimeUnit enum for clarity when converting milliseconds 
to seconds, minutes, etc. 
   ```suggestion
       long seconds = TimeUnit.MILLISECONDS.toSeconds(timeDiff);
   ```



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/SCMNodeManager.java:
##########
@@ -1080,6 +1084,48 @@ public Map<String, Map<String, String>> 
getNodeStatusInfo() {
     return nodes;
   }
 
+  /**
+   * Based on the current time and the last heartbeat, calculate the time 
difference
+   * and get a string of the relative value. E.g. "2s ago", "1m 2s ago", etc.
+   *
+   * @return string with the relative value of the time diff.
+   */
+  public String getLastHeartbeatTimeDiff(long lastHeartbeatTime) {
+    long currentTime = Time.monotonicNow();
+    long timeDiff = currentTime - lastHeartbeatTime;
+
+    // Time is in ms. Calculate total time in seconds.
+    long seconds = timeDiff / 1000;
+    // Calculate days and subtract them from seconds.
+    long days = seconds / (24 * 60 * 60);
+    seconds -= days * 24 * 60 * 60;
+    // Calculate hours and subtract them from seconds.
+    long hours = seconds / (60 * 60);
+    seconds -= hours * 60 * 60;

Review Comment:
   ```suggestion
       long hours = TimeUnit.MILLISECONDS.toHours(timeDiff);
       timeDiff -= TimeUnit.HOURS.toMillis(hours);
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to