summaryrefslogtreecommitdiffstats
path: root/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/StorageMergeStats.java
blob: ec55a6ca1afb09d56eb87d52e6a2ed53f9dfbd2d (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2017 Yahoo Holdings. 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.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Class for storing the pending merge operation stats for all the storage nodes.
 *
 * @author hakonhall
 * @since 5.34
 */
public class StorageMergeStats implements Iterable<NodeMergeStats> {

    // Maps a storage node index to the storage node's pending merges stats.
    private final Map<Integer, NodeMergeStats> mapToNodeStats;

    public StorageMergeStats(Set<Integer> storageNodes) {
        mapToNodeStats = new HashMap<>(storageNodes.size());
        for (Integer index : storageNodes) {
            mapToNodeStats.put(index, new NodeMergeStats(index));
        }
    }

    public StorageMergeStats(Map<Integer, NodeMergeStats> mapToNodeStats) {
        this.mapToNodeStats = mapToNodeStats;
    }

    @Override
    public Iterator<NodeMergeStats> iterator() {
        return mapToNodeStats.values().iterator();
    }

    NodeMergeStats getStorageNode(Integer index) {
        return mapToNodeStats.get(index);
    }

    int size() {
        return mapToNodeStats.size();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof StorageMergeStats)) {
            return false;
        }

        StorageMergeStats that = (StorageMergeStats) o;

        if (mapToNodeStats != null ? !mapToNodeStats.equals(that.mapToNodeStats) : that.mapToNodeStats != null) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        return mapToNodeStats != null ? mapToNodeStats.hashCode() : 0;
    }

}