Repository: ignite Updated Branches: refs/heads/master 19cbf8058 -> 4ea7f926e
IGNITE-8138 Uptime output with days - Fixes #3775. Signed-off-by: dpavlov <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/dfb0b9ee Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/dfb0b9ee Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/dfb0b9ee Branch: refs/heads/master Commit: dfb0b9ee35afeb6adc546160c37b08a85d869f59 Parents: 19cbf80 Author: Sergey Skudnov <[email protected]> Authored: Mon May 14 13:35:14 2018 +0300 Committer: dpavlov <[email protected]> Committed: Mon May 14 13:35:14 2018 +0300 ---------------------------------------------------------------------- .../apache/ignite/internal/IgniteKernal.java | 10 ++++---- .../apache/ignite/internal/util/typedef/X.java | 25 +++++++++++++++++++- .../org/apache/ignite/lang/GridXSelfTest.java | 9 +++++++ 3 files changed, 38 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/dfb0b9ee/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index 86c85e8..090ef64 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -491,7 +491,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { /** {@inheritDoc} */ @Override public String getUpTimeFormatted() { - return X.timeSpan2HMSM(U.currentTimeMillis() - startTime); + return X.timeSpan2DHMSM(U.currentTimeMillis() - startTime); } /** {@inheritDoc} */ @@ -2308,10 +2308,10 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { if (!errOnStop) U.quiet(false, "Ignite node stopped OK [" + nodeName + "uptime=" + - X.timeSpan2HMSM(U.currentTimeMillis() - startTime) + ']'); + X.timeSpan2DHMSM(U.currentTimeMillis() - startTime) + ']'); else U.quiet(true, "Ignite node stopped wih ERRORS [" + nodeName + "uptime=" + - X.timeSpan2HMSM(U.currentTimeMillis() - startTime) + ']'); + X.timeSpan2DHMSM(U.currentTimeMillis() - startTime) + ']'); } if (log.isInfoEnabled()) @@ -2326,7 +2326,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { ">>> " + ack + NL + ">>> " + dash + NL + (igniteInstanceName == null ? "" : ">>> Ignite instance name: " + igniteInstanceName + NL) + - ">>> Grid uptime: " + X.timeSpan2HMSM(U.currentTimeMillis() - startTime) + + ">>> Grid uptime: " + X.timeSpan2DHMSM(U.currentTimeMillis() - startTime) + NL + NL); } @@ -2340,7 +2340,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { ">>> " + ack + NL + ">>> " + dash + NL + (igniteInstanceName == null ? "" : ">>> Ignite instance name: " + igniteInstanceName + NL) + - ">>> Grid uptime: " + X.timeSpan2HMSM(U.currentTimeMillis() - startTime) + + ">>> Grid uptime: " + X.timeSpan2DHMSM(U.currentTimeMillis() - startTime) + NL + ">>> See log above for detailed error message." + NL + ">>> Note that some errors during stop can prevent grid from" + NL + http://git-wip-us.apache.org/repos/asf/ignite/blob/dfb0b9ee/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/X.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/X.java b/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/X.java index 49732b6..6d13f09 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/X.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/X.java @@ -54,7 +54,7 @@ public final class X { public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; /** Time span dividers. */ - private static final long[] SPAN_DIVS = new long[] {1000L, 60L, 60L, 60L}; + private static final long[] SPAN_DIVS = new long[] {1000L, 60L, 60L, 24L}; /** The names of methods commonly used to access a wrapped exception. */ private static final String[] CAUSE_MTD_NAMES = new String[] { @@ -236,6 +236,29 @@ public final class X { } /** + * Creates string presentation of given time {@code span} in days, hh:mm:ss.mmm {@code HMS} format. + * + * @param span Time span. + * @return String presentation. + */ + public static String timeSpan2DHMSM(long span) { + long SPAN_DIV = 86400000L; + + String days = ""; + + String hmsm = timeSpan2HMSM(span % SPAN_DIV); + + long count = span / SPAN_DIV; + + if (count == 1) + days = count + " day, "; + else if (count > 1) + days = count + " days, "; + + return days + hmsm; + } + + /** * Clones a passed in object. If parameter {@code deep} is set to {@code true} * then this method will use deep cloning algorithm based on deep reflection * ignoring {@link Cloneable} interface unless parameter {@code honorCloneable} http://git-wip-us.apache.org/repos/asf/ignite/blob/dfb0b9ee/modules/core/src/test/java/org/apache/ignite/lang/GridXSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/lang/GridXSelfTest.java b/modules/core/src/test/java/org/apache/ignite/lang/GridXSelfTest.java index e7608b7..6efa6f2 100644 --- a/modules/core/src/test/java/org/apache/ignite/lang/GridXSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/lang/GridXSelfTest.java @@ -55,6 +55,15 @@ public class GridXSelfTest extends GridCommonAbstractTest { /** * */ + public void testTimeSpan() { + assertEquals(X.timeSpan2DHMSM(86400001L), "1 day, 00:00:00.001"); + + assertEquals(X.timeSpan2DHMSM(172800004L), "2 days, 00:00:00.004"); + } + + /** + * + */ public void testShallowClone() { // Single not cloneable object Object obj = new Object();
