DATACOUCH-40 - Make ClusterInfo more reliable on the values returned.
This commit is contained in:
@@ -37,27 +37,27 @@ public class ClusterInfo extends AbstractMonitor {
|
||||
|
||||
@ManagedMetric(description = "Total RAM assigned")
|
||||
public long getTotalRAMAssigned() {
|
||||
return (Long) parseStorageTotals().get("ram").get("total");
|
||||
return convertPotentialLong(parseStorageTotals().get("ram").get("total"));
|
||||
}
|
||||
|
||||
@ManagedMetric(description = "Total RAM used")
|
||||
public long getTotalRAMUsed() {
|
||||
return (Long) parseStorageTotals().get("ram").get("used");
|
||||
return convertPotentialLong(parseStorageTotals().get("ram").get("used"));
|
||||
}
|
||||
|
||||
@ManagedMetric(description = "Total Disk Space assigned")
|
||||
public long getTotalDiskAssigned() {
|
||||
return (Long) parseStorageTotals().get("hdd").get("total");
|
||||
return convertPotentialLong(parseStorageTotals().get("hdd").get("total"));
|
||||
}
|
||||
|
||||
@ManagedMetric(description = "Total Disk Space used")
|
||||
public long getTotalDiskUsed() {
|
||||
return (Long) parseStorageTotals().get("hdd").get("used");
|
||||
return convertPotentialLong(parseStorageTotals().get("hdd").get("used"));
|
||||
}
|
||||
|
||||
@ManagedMetric(description = "Total Disk Space free")
|
||||
public long getTotalDiskFree() {
|
||||
return (Long) parseStorageTotals().get("hdd").get("free");
|
||||
return convertPotentialLong(parseStorageTotals().get("hdd").get("free"));
|
||||
}
|
||||
|
||||
@ManagedAttribute(description = "Cluster is Balanced")
|
||||
@@ -75,6 +75,24 @@ public class ClusterInfo extends AbstractMonitor {
|
||||
return (Integer) fetchPoolInfo().get("maxBucketCount");
|
||||
}
|
||||
|
||||
/**
|
||||
* Depending on the value size, either int or long can be passed in and get
|
||||
* converted to long.
|
||||
*
|
||||
* @param value the value to convert.
|
||||
*
|
||||
* @return the converted value.
|
||||
*/
|
||||
private long convertPotentialLong(Object value) {
|
||||
if (value instanceof Integer) {
|
||||
return new Long((Integer) value);
|
||||
} else if (value instanceof Long) {
|
||||
return (Long) value;
|
||||
} else {
|
||||
throw new IllegalStateException("Cannot convert value to long: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, Object> fetchPoolInfo() {
|
||||
return getTemplate().getForObject("http://"
|
||||
+ randomAvailableHostname() + ":8091/pools/default", HashMap.class);
|
||||
|
||||
@@ -49,8 +49,8 @@ public class ClusterInfoTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void totalRAMAssigned() {
|
||||
assertThat(ci.getTotalRAMAssigned(), greaterThan(0L));
|
||||
public void totalDiskAssigned() {
|
||||
assertThat(ci.getTotalDiskAssigned(), greaterThan(0L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user