From fd207e75b0bb94005d953bfc780e7b8ee7c166c8 Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Mon, 29 Jun 2020 09:12:09 -0500 Subject: [PATCH] ARTEMIS-2829 wrong return type for getDiskStoreUsage Since getDiskStoreUsage on the ActiveMQServerControl is converting a double to a long the value is always 0 in the management API. It should return a double instead. --- .../api/core/management/ActiveMQServerControl.java | 4 ++-- .../management/impl/ActiveMQServerControlImpl.java | 13 ++----------- .../artemis/core/server/ActiveMQServer.java | 2 ++ .../core/server/impl/ActiveMQServerImpl.java | 13 ++++++++----- .../ActiveMQServerControlUsingCoreTest.java | 4 ++-- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java index 90cd759c24..c1f6e1d776 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java @@ -445,10 +445,10 @@ public interface ActiveMQServerControl { long getAddressMemoryUsage(); /** - * Returns the bytes used by the disk store + * Returns the percentage of total disk store use */ @Attribute(desc = DISK_STORE_USAGE_DESCRIPTION) - long getDiskStoreUsage(); + double getDiskStoreUsage(); /** * Returns the memory used by all the addresses on broker as a percentage of the global-max-size diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java index 30aff028a6..4b75a721ee 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java @@ -109,7 +109,6 @@ import org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy; import org.apache.activemq.artemis.core.server.cluster.ha.LiveOnlyPolicy; import org.apache.activemq.artemis.core.server.cluster.ha.ScaleDownPolicy; import org.apache.activemq.artemis.core.server.cluster.ha.SharedStoreSlavePolicy; -import org.apache.activemq.artemis.core.server.files.FileStoreMonitor; import org.apache.activemq.artemis.core.server.group.GroupingHandler; import org.apache.activemq.artemis.core.server.impl.Activation; import org.apache.activemq.artemis.core.server.impl.AddressInfo; @@ -711,22 +710,14 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active } @Override - public long getDiskStoreUsage() { + public double getDiskStoreUsage() { if (AuditLogger.isEnabled()) { AuditLogger.getDiskStoreUsage(this.server); } checkStarted(); clearIO(); try { - //this should not happen but if it does, return -1 to highlight it is not working - if (server.getPagingManager() == null) { - return -1L; - } - - long usableSpace = server.getPagingManager().getDiskUsableSpace(); - long totalSpace = server.getPagingManager().getDiskTotalSpace(); - - return (long) FileStoreMonitor.calculateUsage(usableSpace, totalSpace); + return server.getDiskStoreUsage(); } finally { blockOnIO(); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java index 3bbc721503..d3b8ea5950 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java @@ -889,4 +889,6 @@ public interface ActiveMQServer extends ServiceComponent { void removeAddressInfo(SimpleString address, SecurityAuth auth, boolean force) throws Exception; String getInternalNamingPrefix(); + + double getDiskStoreUsage(); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index 6d78f16d5b..41edad9f3f 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -3086,16 +3086,19 @@ public class ActiveMQServerImpl implements ActiveMQServer { builder.register(BrokerMetricNames.TOTAL_CONNECTION_COUNT, this, metrics -> Double.valueOf(getTotalConnectionCount()), ActiveMQServerControl.TOTAL_CONNECTION_COUNT_DESCRIPTION); builder.register(BrokerMetricNames.ADDRESS_MEMORY_USAGE, this, metrics -> Double.valueOf(messagingServerControl.getAddressMemoryUsage()), ActiveMQServerControl.ADDRESS_MEMORY_USAGE_DESCRIPTION); builder.register(BrokerMetricNames.ADDRESS_MEMORY_USAGE_PERCENTAGE, this, metrics -> Double.valueOf(messagingServerControl.getAddressMemoryUsagePercentage()), ActiveMQServerControl.ADDRESS_MEMORY_USAGE_PERCENTAGE_DESCRIPTION); - builder.register(BrokerMetricNames.DISK_STORE_USAGE, this, metrics -> Double.valueOf(calculateDiskStoreUsage()), ActiveMQServerControl.DISK_STORE_USAGE_DESCRIPTION); + builder.register(BrokerMetricNames.DISK_STORE_USAGE, this, metrics -> Double.valueOf(getDiskStoreUsage()), ActiveMQServerControl.DISK_STORE_USAGE_DESCRIPTION); }); } } - private double calculateDiskStoreUsage() { - long usableSpace = getPagingManager().getDiskUsableSpace(); - long totalSpace = getPagingManager().getDiskTotalSpace(); + @Override + public double getDiskStoreUsage() { + //this should not happen but if it does, return -1 to highlight it is not working + if (getPagingManager() == null) { + return -1L; + } - return FileStoreMonitor.calculateUsage(usableSpace, totalSpace); + return FileStoreMonitor.calculateUsage(getPagingManager().getDiskUsableSpace(), getPagingManager().getDiskTotalSpace()); } private void unregisterMeters() { diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java index 2c32c25e48..4b8138b450 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java @@ -764,9 +764,9 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes } @Override - public long getDiskStoreUsage() { + public double getDiskStoreUsage() { try { - return (Long) proxy.invokeOperation("getDiskStoreUsage"); + return (Double) proxy.invokeOperation("getDiskStoreUsage"); } catch (Exception e) { e.printStackTrace(); }