This is an automated email from the ASF dual-hosted git repository. jensdeppe pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push: new 03f6d27 GEODE-2321: Pulse application works incorrectly in some locales (#1661) 03f6d27 is described below commit 03f6d272b15c5757001664331c99947b7e6c6a1e Author: Jens Deppe <jde...@pivotal.io> AuthorDate: Fri Mar 30 07:15:21 2018 -0700 GEODE-2321: Pulse application works incorrectly in some locales (#1661) - Ensure that all number formatting is consistent. Formatting, as it exists, will be according to the US locale. - This also fixes GEODE-1409 --- .../geode/tools/pulse/internal/data/PulseConstants.java | 16 +++++++++++++--- .../pulse/internal/service/ClusterDetailsService.java | 6 ++---- .../internal/service/ClusterMembersRGraphService.java | 13 ++++++------- .../pulse/internal/service/ClusterRegionService.java | 7 +++---- .../pulse/internal/service/ClusterRegionsService.java | 7 +++---- .../internal/service/ClusterSelectedRegionService.java | 15 +++++++-------- .../pulse/internal/service/MemberDetailsService.java | 9 +++------ .../pulse/internal/service/MemberRegionsService.java | 7 ++----- .../org/apache/geode/tools/pulse/tests/ui/PulseBase.java | 7 +++---- 9 files changed, 42 insertions(+), 45 deletions(-) diff --git a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/PulseConstants.java b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/PulseConstants.java index 73c2f66..66a16ba 100644 --- a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/PulseConstants.java +++ b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/PulseConstants.java @@ -17,6 +17,10 @@ package org.apache.geode.tools.pulse.internal.data; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.Locale; + import org.apache.logging.log4j.Level; public class PulseConstants { @@ -51,9 +55,15 @@ public class PulseConstants { // Date pattern to be used in log messages public static final String PULSE_QUERY_HISTORY_DATE_PATTERN = "EEE, MMM dd yyyy, HH:mm:ss z"; - // Decimal format pattern "###.##" and "0.0000" - public static final String DECIMAL_FORMAT_PATTERN = "###.##"; - public static final String DECIMAL_FORMAT_PATTERN_2 = "0.0000"; + // Use US locale so that number formatting remains consistent in the UI + public static DecimalFormat TWO_PLACE_DECIMAL_FORMAT = + (DecimalFormat) NumberFormat.getNumberInstance(Locale.US); + public static DecimalFormat FOUR_PLACE_DECIMAL_FORMAT = + (DecimalFormat) NumberFormat.getNumberInstance(Locale.US); + static { + TWO_PLACE_DECIMAL_FORMAT.applyPattern("###.##"); + FOUR_PLACE_DECIMAL_FORMAT.applyPattern("0.0000"); + } // DEFAULT VALUES public static final String GEMFIRE_DEFAULT_HOST = "localhost"; diff --git a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterDetailsService.java b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterDetailsService.java index b700b07..bdafc1f 100644 --- a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterDetailsService.java +++ b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterDetailsService.java @@ -17,7 +17,7 @@ package org.apache.geode.tools.pulse.internal.service; -import java.text.DecimalFormat; +import static org.apache.geode.tools.pulse.internal.data.PulseConstants.TWO_PLACE_DECIMAL_FORMAT; import javax.servlet.http.HttpServletRequest; @@ -28,7 +28,6 @@ import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.apache.geode.tools.pulse.internal.data.Cluster; -import org.apache.geode.tools.pulse.internal.data.PulseConstants; import org.apache.geode.tools.pulse.internal.data.Repository; /** @@ -87,9 +86,8 @@ public class ClusterDetailsService implements PulseService { responseJSON.put("totalRegions", cluster.getTotalRegionCount()); Long heapSize = cluster.getTotalHeapSize(); - DecimalFormat df2 = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN); Double heapS = heapSize.doubleValue() / 1024; - responseJSON.put("totalHeap", Double.valueOf(df2.format(heapS))); + responseJSON.put("totalHeap", TWO_PLACE_DECIMAL_FORMAT.format(heapS)); responseJSON.put("functions", cluster.getRunningFunctionCount()); responseJSON.put("uniqueCQs", cluster.getRegisteredCQCount()); responseJSON.put("subscriptions", cluster.getSubscriptionCount()); diff --git a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterMembersRGraphService.java b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterMembersRGraphService.java index cbd8f25..73648da 100644 --- a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterMembersRGraphService.java +++ b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterMembersRGraphService.java @@ -17,7 +17,8 @@ package org.apache.geode.tools.pulse.internal.service; -import java.text.DecimalFormat; +import static org.apache.geode.tools.pulse.internal.data.PulseConstants.TWO_PLACE_DECIMAL_FORMAT; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -32,7 +33,6 @@ import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.apache.geode.tools.pulse.internal.data.Cluster; -import org.apache.geode.tools.pulse.internal.data.PulseConstants; import org.apache.geode.tools.pulse.internal.data.Repository; /** @@ -122,7 +122,6 @@ public class ClusterMembersRGraphService implements PulseService { ObjectNode data1 = mapper.createObjectNode(); clusterTopologyJSON.put(this.DATA, data1); ArrayNode childHostArray = mapper.createArrayNode(); - DecimalFormat df2 = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN); updateAlertLists(cluster); @@ -160,13 +159,13 @@ public class ClusterMembersRGraphService implements PulseService { if (usedHeapSize > 0) { double heapUsage = (currentHeap.doubleValue() / usedHeapSize.doubleValue()) * 100; - memberData.put(this.MEMORY_USAGE, Double.valueOf(df2.format(heapUsage))); + memberData.put(this.MEMORY_USAGE, TWO_PLACE_DECIMAL_FORMAT.format(heapUsage)); } else memberData.put(this.MEMORY_USAGE, 0); double currentCPUUsage = member.getCpuUsage(); - memberData.put(this.CPU_USAGE, Double.valueOf(df2.format(currentCPUUsage))); + memberData.put(this.CPU_USAGE, TWO_PLACE_DECIMAL_FORMAT.format(currentCPUUsage)); memberData.put(this.REGIONS, member.getMemberRegions().size()); memberData.put(this.HOST, member.getHost()); if ((member.getMemberPort() == null) || (member.getMemberPort().equals(""))) { @@ -226,10 +225,10 @@ public class ClusterMembersRGraphService implements PulseService { } ObjectNode data = mapper.createObjectNode(); - data.put(this.LOAD_AVG, Double.valueOf(df2.format(hostLoadAvg))); + data.put(this.LOAD_AVG, TWO_PLACE_DECIMAL_FORMAT.format(hostLoadAvg)); data.put(this.SOCKETS, hostSockets); data.put(this.THREADS, hostNumThreads); - data.put(this.CPU_USAGE, Double.valueOf(df2.format(hostCpuUsage))); + data.put(this.CPU_USAGE, TWO_PLACE_DECIMAL_FORMAT.format(hostCpuUsage)); data.put(this.MEMORY_USAGE, hostMemoryUsage); String hostNodeType; diff --git a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterRegionService.java b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterRegionService.java index d00c0f4..5457f76 100644 --- a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterRegionService.java +++ b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterRegionService.java @@ -17,7 +17,8 @@ package org.apache.geode.tools.pulse.internal.service; -import java.text.DecimalFormat; +import static org.apache.geode.tools.pulse.internal.data.PulseConstants.FOUR_PLACE_DECIMAL_FORMAT; + import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -35,7 +36,6 @@ import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.apache.geode.tools.pulse.internal.data.Cluster; -import org.apache.geode.tools.pulse.internal.data.PulseConstants; import org.apache.geode.tools.pulse.internal.data.Repository; /** @@ -181,8 +181,7 @@ public class ClusterRegionService implements PulseService { reg.getRegionStatisticTrend(Cluster.Region.REGION_STAT_DISK_WRITES_PER_SEC_TREND))); regionJSON.put("emptyNodes", reg.getEmptyNode()); Long entrySize = reg.getEntrySize(); - DecimalFormat form = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN_2); - String entrySizeInMB = form.format(entrySize / (1024f * 1024f)); + String entrySizeInMB = FOUR_PLACE_DECIMAL_FORMAT.format(entrySize / (1024f * 1024f)); if (entrySize < 0) { regionJSON.put(this.ENTRY_SIZE, VALUE_NA); diff --git a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterRegionsService.java b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterRegionsService.java index 027f9ff..f68cf0b 100644 --- a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterRegionsService.java +++ b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterRegionsService.java @@ -17,7 +17,8 @@ package org.apache.geode.tools.pulse.internal.service; -import java.text.DecimalFormat; +import static org.apache.geode.tools.pulse.internal.data.PulseConstants.FOUR_PLACE_DECIMAL_FORMAT; + import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -35,7 +36,6 @@ import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.apache.geode.tools.pulse.internal.data.Cluster; -import org.apache.geode.tools.pulse.internal.data.PulseConstants; import org.apache.geode.tools.pulse.internal.data.Repository; /** @@ -176,8 +176,7 @@ public class ClusterRegionsService implements PulseService { reg.getRegionStatisticTrend(Cluster.Region.REGION_STAT_DISK_WRITES_PER_SEC_TREND))); regionJSON.put("emptyNodes", reg.getEmptyNode()); Long entrySize = reg.getEntrySize(); - DecimalFormat form = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN_2); - String entrySizeInMB = form.format(entrySize / (1024f * 1024f)); + String entrySizeInMB = FOUR_PLACE_DECIMAL_FORMAT.format(entrySize / (1024f * 1024f)); if (entrySize < 0) { regionJSON.put(this.ENTRY_SIZE, VALUE_NA); diff --git a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterSelectedRegionService.java b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterSelectedRegionService.java index 5052186..5163553 100644 --- a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterSelectedRegionService.java +++ b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/ClusterSelectedRegionService.java @@ -17,7 +17,9 @@ package org.apache.geode.tools.pulse.internal.service; -import java.text.DecimalFormat; +import static org.apache.geode.tools.pulse.internal.data.PulseConstants.FOUR_PLACE_DECIMAL_FORMAT; +import static org.apache.geode.tools.pulse.internal.data.PulseConstants.TWO_PLACE_DECIMAL_FORMAT; + import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -37,7 +39,6 @@ import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.apache.geode.tools.pulse.internal.data.Cluster; -import org.apache.geode.tools.pulse.internal.data.PulseConstants; import org.apache.geode.tools.pulse.internal.data.Repository; import org.apache.geode.tools.pulse.internal.util.TimeUtils; @@ -123,7 +124,6 @@ public class ClusterSelectedRegionService implements PulseService { regionJSON.put("putsRate", reg.getPutsRate()); regionJSON.put("lruEvictionRate", reg.getLruEvictionRate()); - DecimalFormat df2 = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN); Cluster.Member[] clusterMembersList = cluster.getMembers(); // collect members of this region @@ -156,19 +156,19 @@ public class ClusterSelectedRegionService implements PulseService { long currentHeap = member.getCurrentHeapSize(); if (usedHeapSize > 0) { double heapUsage = ((double) currentHeap / (double) usedHeapSize) * 100; - regionMember.put("heapUsage", Double.valueOf(df2.format(heapUsage))); + regionMember.put("heapUsage", TWO_PLACE_DECIMAL_FORMAT.format(heapUsage)); } else { regionMember.put("heapUsage", 0); } double currentCPUUsage = member.getCpuUsage(); double loadAvg = member.getLoadAverage(); - regionMember.put("cpuUsage", Double.valueOf(df2.format(currentCPUUsage))); + regionMember.put("cpuUsage", TWO_PLACE_DECIMAL_FORMAT.format(currentCPUUsage)); regionMember.put("currentHeapUsage", member.getCurrentHeapSize()); regionMember.put("isManager", member.isManager()); regionMember.put("uptime", TimeUtils.convertTimeSecondsToHMS(member.getUptime())); - regionMember.put("loadAvg", Double.valueOf(df2.format(loadAvg))); + regionMember.put("loadAvg", TWO_PLACE_DECIMAL_FORMAT.format(loadAvg)); regionMember.put("sockets", member.getTotalFileDescriptorOpen()); regionMember.put("threads", member.getNumThreads()); @@ -209,8 +209,7 @@ public class ClusterSelectedRegionService implements PulseService { regionJSON.put("emptyNodes", reg.getEmptyNode()); Long entrySize = reg.getEntrySize(); - DecimalFormat form = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN_2); - String entrySizeInMB = form.format(entrySize / (1024f * 1024f)); + String entrySizeInMB = FOUR_PLACE_DECIMAL_FORMAT.format(entrySize / (1024f * 1024f)); if (entrySize < 0) { regionJSON.put(this.ENTRY_SIZE, PulseService.VALUE_NA); } else { diff --git a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/MemberDetailsService.java b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/MemberDetailsService.java index 52d5662..28cd2e4 100644 --- a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/MemberDetailsService.java +++ b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/MemberDetailsService.java @@ -17,10 +17,9 @@ package org.apache.geode.tools.pulse.internal.service; +import static org.apache.geode.tools.pulse.internal.data.PulseConstants.TWO_PLACE_DECIMAL_FORMAT; import static org.apache.geode.tools.pulse.internal.util.NameUtil.makeCompliantName; -import java.text.DecimalFormat; - import javax.servlet.http.HttpServletRequest; import com.fasterxml.jackson.databind.JsonNode; @@ -31,7 +30,6 @@ import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.apache.geode.tools.pulse.internal.data.Cluster; -import org.apache.geode.tools.pulse.internal.data.PulseConstants; import org.apache.geode.tools.pulse.internal.data.Repository; /** @@ -60,7 +58,6 @@ public class MemberDetailsService implements PulseService { JsonNode requestDataJSON = mapper.readTree(request.getParameter("pulseData")); String memberName = requestDataJSON.get("MemberDetails").get("memberName").textValue(); - DecimalFormat df2 = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN); Cluster.Member clusterMember = cluster.getMember(makeCompliantName(memberName)); if (clusterMember != null) { @@ -71,7 +68,7 @@ public class MemberDetailsService implements PulseService { responseJSON.put("clusterName", cluster.getServerName()); responseJSON.put("userName", userName); double loadAvg = clusterMember.getLoadAverage(); - responseJSON.put("loadAverage", Double.valueOf(df2.format(loadAvg))); + responseJSON.put("loadAverage", TWO_PLACE_DECIMAL_FORMAT.format(loadAvg)); responseJSON.put("sockets", clusterMember.getTotalFileDescriptorOpen()); responseJSON.put("threads", clusterMember.getNumThreads()); responseJSON.put("offHeapFreeSize", clusterMember.getOffHeapFreeSize()); @@ -84,7 +81,7 @@ public class MemberDetailsService implements PulseService { Long diskUsageVal = clusterMember.getTotalDiskUsage(); Double diskUsage = diskUsageVal.doubleValue() / 1024; - responseJSON.put("diskStorageUsed", Double.valueOf(df2.format(diskUsage))); + responseJSON.put("diskStorageUsed", TWO_PLACE_DECIMAL_FORMAT.format(diskUsage)); Cluster.Alert[] alertsList = cluster.getAlertsList(); diff --git a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/MemberRegionsService.java b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/MemberRegionsService.java index bd1bdae..ee5dd62 100644 --- a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/MemberRegionsService.java +++ b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/service/MemberRegionsService.java @@ -17,10 +17,9 @@ package org.apache.geode.tools.pulse.internal.service; +import static org.apache.geode.tools.pulse.internal.data.PulseConstants.FOUR_PLACE_DECIMAL_FORMAT; import static org.apache.geode.tools.pulse.internal.util.NameUtil.makeCompliantName; -import java.text.DecimalFormat; - import javax.servlet.http.HttpServletRequest; import com.fasterxml.jackson.databind.JsonNode; @@ -33,7 +32,6 @@ import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.apache.geode.tools.pulse.internal.data.Cluster; -import org.apache.geode.tools.pulse.internal.data.PulseConstants; import org.apache.geode.tools.pulse.internal.data.Repository; /** @@ -88,8 +86,7 @@ public class MemberRegionsService implements PulseService { regionJSON.put("entryCount", memberRegion.getSystemRegionEntryCount()); Long entrySize = memberRegion.getEntrySize(); - DecimalFormat form = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN_2); - String entrySizeInMB = form.format(entrySize / (1024f * 1024f)); + String entrySizeInMB = FOUR_PLACE_DECIMAL_FORMAT.format(entrySize / (1024f * 1024f)); if (entrySize < 0) { regionJSON.put(this.ENTRY_SIZE, VALUE_NA); diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseBase.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseBase.java index 7cc49b0..4ad0e69 100644 --- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseBase.java +++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseBase.java @@ -15,6 +15,7 @@ */ package org.apache.geode.tools.pulse.tests.ui; +import static org.apache.geode.tools.pulse.internal.data.PulseConstants.TWO_PLACE_DECIMAL_FORMAT; import static org.apache.geode.tools.pulse.tests.ui.PulseTestConstants.CLUSTER_CLIENTS_ID; import static org.apache.geode.tools.pulse.tests.ui.PulseTestConstants.CLUSTER_FUNCTIONS_ID; import static org.apache.geode.tools.pulse.tests.ui.PulseTestConstants.CLUSTER_GCPAUSES_ID; @@ -320,8 +321,7 @@ public abstract class PulseBase { searchByIdAndClick("M1&M1"); String LoadAvg = getWebDriver().findElement(By.id(MEMBER_VIEW_LOADAVG_ID)).getText(); String memberLoadAvg = JMXProperties.getInstance().getProperty("member.M1.loadAverage"); - assertEquals(new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN) - .format(Double.valueOf(memberLoadAvg)), LoadAvg); + assertEquals(TWO_PLACE_DECIMAL_FORMAT.format(Double.valueOf(memberLoadAvg)), LoadAvg); } @Ignore("WIP") // May be useful in near future @@ -743,8 +743,7 @@ public abstract class PulseBase { By.xpath("//div[@id='_tooltip']/div/div/div[2]/div[" + (j + 2) + "]/div[2]/div")) .getText(); String loadAvgM1 = JMXProperties.getInstance().getProperty("member.M" + (i) + ".loadAverage"); - assertEquals(new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN) - .format(Double.valueOf(loadAvgM1)), LoadAvgM1); + assertEquals(TWO_PLACE_DECIMAL_FORMAT.format(Double.valueOf(loadAvgM1)), LoadAvgM1); String ThreadsM1 = getWebDriver() .findElement( -- To stop receiving notification emails like this one, please contact jensde...@apache.org.