summaryrefslogtreecommitdiffstats
path: root/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/ContentClusterStats.java
blob: 33ba51a0abaaa3858f8d75745689eb6106d014b2 (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
// 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 content nodes.
 *
 * @author hakonhall
 */
public class ContentClusterStats implements Iterable<NodeMergeStats> {

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

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

    public ContentClusterStats(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 ContentClusterStats)) {
            return false;
        }

        ContentClusterStats that = (ContentClusterStats) 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;
    }

}