aboutsummaryrefslogtreecommitdiffstats
path: root/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ContentClusterStatsBuilder.java
blob: 42db4da6c57f9a4d3d041143099331c7073aa973 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core;

import java.util.HashMap;
import java.util.Map;

/**
 * Builder used for testing only.
 */
public class ContentClusterStatsBuilder {

    private final Map<Integer, ContentNodeStatsBuilder> stats = new HashMap<>();

    public ContentClusterStatsBuilder add(int nodeIndex, String bucketSpace, long bucketsTotal, long bucketsPending) {
        return add(nodeIndex, bucketSpace, ContentNodeStats.BucketSpaceStats.of(bucketsTotal, bucketsPending));
    }

    ContentClusterStatsBuilder addInvalid(int nodeIndex, String bucketSpace, long bucketsTotal, long bucketsPending) {
        return add(nodeIndex, bucketSpace, ContentNodeStats.BucketSpaceStats.invalid(bucketsTotal, bucketsPending));
    }

    public ContentClusterStatsBuilder add(int nodeIndex, String bucketSpace) {
        return add(nodeIndex, bucketSpace, ContentNodeStats.BucketSpaceStats.invalid());
    }

    public ContentClusterStatsBuilder add(int nodeIndex, String bucketSpace, ContentNodeStats.BucketSpaceStats bucketSpaceStats) {
        ContentNodeStatsBuilder nodeStatsBuilder = stats.get(nodeIndex);
        if (nodeStatsBuilder == null) {
            nodeStatsBuilder = ContentNodeStatsBuilder.forNode(nodeIndex);
            stats.put(nodeIndex, nodeStatsBuilder);
        }
        nodeStatsBuilder.add(bucketSpace, bucketSpaceStats);
        return this;
    }

    public ContentClusterStatsBuilder add(int nodeIndex) {
        stats.put(nodeIndex, ContentNodeStatsBuilder.forNode(nodeIndex));
        return this;
    }

    ContentClusterStats build() {
        Map<Integer, ContentNodeStats> nodeToStatsMap = new HashMap<>();
        stats.forEach((nodeIndex, nodeStatsBuilder) ->
                nodeToStatsMap.put(nodeIndex, nodeStatsBuilder.build()));
        return new ContentClusterStats(nodeToStatsMap);
    }
}