summaryrefslogtreecommitdiffstats
path: root/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/ClusterStateHistoryEntry.java
blob: 65c0f210fd579b24e253365f6d119987b994595d (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
// 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 com.yahoo.vdslib.state.ClusterState;

import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

public class ClusterStateHistoryEntry {

    private final ClusterStateBundle state;
    private final long time;

    ClusterStateHistoryEntry(final ClusterStateBundle state, final long time) {
        this.state = state;
        this.time = time;
    }

    public ClusterState getBaselineState() {
        return state.getBaselineClusterState();
    }

    public Map<String, ClusterState> getDerivedBucketSpaceStates() {
        return state.getDerivedBucketSpaceStates().entrySet().stream()
                .collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue().getClusterState()));
    }

    public long time() {
        return time;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ClusterStateHistoryEntry that = (ClusterStateHistoryEntry) o;
        return time == that.time &&
                Objects.equals(state, that.state);
    }

    @Override
    public int hashCode() {
        return Objects.hash(state, time);
    }

    // String representation only used for test expectation failures and debugging output.
    // Actual status page history entry rendering emits formatted date/time.
    public String toString() {
        return String.format("state '%s' at time %d", state, time);
    }

}