From 8cde490aadfa56c314d925d3cca09f4830d6e2c4 Mon Sep 17 00:00:00 2001 From: Pasquale Andriani Date: Tue, 23 Oct 2012 19:50:26 +0200 Subject: [PATCH 1/2] allow "," as decimal separator in cpuUsed regular expression --- .../main/java/org/jclouds/cloudstack/domain/VirtualMachine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java index c15ff744b9..dca59fc620 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java @@ -588,7 +588,7 @@ public class VirtualMachine { @Nullable VirtualMachine.State state, @Nullable String templateDisplayText, @Nullable String templateId, @Nullable String templateName, @Nullable String zoneId, @Nullable String zoneName, @Nullable Set nics, @Nullable String hypervisor, @Nullable Set securityGroups) { - Preconditions.checkArgument(Strings.isNullOrEmpty(cpuUsed) || cpuUsed.matches("^[0-9\\.\\-]+%$"), "cpuUsed value should be a decimal number followed by %"); + Preconditions.checkArgument(Strings.isNullOrEmpty(cpuUsed) || cpuUsed.matches("^[0-9\\.|,\\-]+%$"), "cpuUsed value should be a decimal number followed by %"); this.id = checkNotNull(id, "id"); this.account = account; this.cpuCount = cpuCount; From 256ba24dd08b593dcf6d78769f7f292aa78ed594 Mon Sep 17 00:00:00 2001 From: Pasquale Andriani Date: Thu, 25 Oct 2012 01:04:19 +0200 Subject: [PATCH 2/2] added test for allowing ',' decimal separator --- .../java/org/jclouds/cloudstack/domain/VirtualMachine.java | 2 +- .../org/jclouds/cloudstack/domain/VirtualMachineTest.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java index dca59fc620..0ccd08fc04 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java @@ -667,7 +667,7 @@ public class VirtualMachine { * @return the amount of the vm's CPU currently used */ public float getCpuUsed() { - return cpuUsed != null ? Float.parseFloat(cpuUsed.substring(0, cpuUsed.length() - 1)) : 0.0f; + return cpuUsed != null ? Float.parseFloat(cpuUsed.substring(0, cpuUsed.length() - 1).replace(',', '.')) : 0.0f; } private String getCpuUsedAsString() { diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/domain/VirtualMachineTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/domain/VirtualMachineTest.java index 95db9e170d..9299c8224a 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/domain/VirtualMachineTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/domain/VirtualMachineTest.java @@ -47,6 +47,10 @@ public class VirtualMachineTest { // Retrieving CpuUsed should just give us a straightforward float vm = VirtualMachine.builder().id("3").cpuUsed("23.4%").build(); assertEquals(vm.getCpuUsed(), 23.4, 0.01); + + //Allow ',' as decimal separator + vm = VirtualMachine.builder().id("4").cpuUsed("23,4%").build(); + assertEquals(vm.getCpuUsed(), 23.4, 0.01); } }