diff options
author | Geir Storli <geirst@oath.com> | 2018-02-20 14:06:22 +0100 |
---|---|---|
committer | Geir Storli <geirst@oath.com> | 2018-02-20 14:06:22 +0100 |
commit | 255f0759c016c04085b98dce7ce521eca8a70535 (patch) | |
tree | 888efa31003eb06fbda20f9729b14fa98b5fb73a | |
parent | f0ca62f5f8e2899a7da8c204897e228afcc506f2 (diff) |
Add factory functions for BucketSpaceStats.
2 files changed, 14 insertions, 7 deletions
diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/ContentNodeStats.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/ContentNodeStats.java index 76edaacf06f..cefb3c3c31f 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/ContentNodeStats.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/ContentNodeStats.java @@ -17,16 +17,24 @@ public class ContentNodeStats { private long bucketsTotal; private long bucketsPending; - public BucketSpaceStats() { + private BucketSpaceStats() { this.bucketsTotal = 0; this.bucketsPending = 0; } - public BucketSpaceStats(long bucketsTotal, long bucketsPending) { + private BucketSpaceStats(long bucketsTotal, long bucketsPending) { this.bucketsTotal = bucketsTotal; this.bucketsPending = bucketsPending; } + public static BucketSpaceStats empty() { + return new BucketSpaceStats(); + } + + public static BucketSpaceStats of(long bucketsTotal, long bucketsPending) { + return new BucketSpaceStats(bucketsTotal, bucketsPending); + } + public long getBucketsTotal() { return bucketsTotal; } @@ -65,11 +73,10 @@ public class ContentNodeStats { for (StorageNode.BucketSpaceStats stats : storageNode.getBucketSpacesStats()) { if (stats.valid()) { this.bucketSpaces.put(stats.getName(), - new BucketSpaceStats(stats.getBucketStats().getTotal(), + BucketSpaceStats.of(stats.getBucketStats().getTotal(), stats.getBucketStats().getPending())); } else { - // TODO: better handling of invalid bucket space stats - this.bucketSpaces.put(stats.getName(), new BucketSpaceStats()); + this.bucketSpaces.put(stats.getName(), BucketSpaceStats.empty()); } } } diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ClusterStatsAggregatorTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ClusterStatsAggregatorTest.java index 6035ae9d8ce..c92d414aac8 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ClusterStatsAggregatorTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ClusterStatsAggregatorTest.java @@ -18,10 +18,10 @@ public class ClusterStatsAggregatorTest { private final Map<Integer, Map<String, ContentNodeStats.BucketSpaceStats> > stats = new HashMap<>(); public StatsBuilder add(int nodeIndex, String bucketSpace, long bucketsTotal, long bucketsPending) { - return add(nodeIndex, bucketSpace, new ContentNodeStats.BucketSpaceStats(bucketsTotal, bucketsPending)); + return add(nodeIndex, bucketSpace, ContentNodeStats.BucketSpaceStats.of(bucketsTotal, bucketsPending)); } public StatsBuilder add(int nodeIndex, String bucketSpace) { - return add(nodeIndex, bucketSpace, new ContentNodeStats.BucketSpaceStats()); + return add(nodeIndex, bucketSpace, ContentNodeStats.BucketSpaceStats.empty()); } public StatsBuilder add(int nodeIndex, String bucketSpace, ContentNodeStats.BucketSpaceStats bucketSpaceStats) { Map<String, ContentNodeStats.BucketSpaceStats> contentNodeStats = stats.get(nodeIndex); |