summaryrefslogtreecommitdiffstats
path: root/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Autoscaling.java
blob: 9da17a392428f803316d9b692fbea1d28ef106fd (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
package com.yahoo.vespa.hosted.provision.autoscale;

import com.yahoo.config.provision.ClusterResources;

import java.time.Instant;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;

/**
 * An autoscaling result.
 *
 * @author bratseth
 */
public class Autoscaling {

    private final Optional<ClusterResources> resources;
    private final Instant at;

    public Autoscaling(ClusterResources resources, Instant at) {
        this(Optional.of(resources), at);
    }

    public Autoscaling(Optional<ClusterResources> resources, Instant at) {
        this.resources = resources;
        this.at = at;
    }

    /** Returns the resource target of this, or empty if non target. */
    public Optional<ClusterResources> resources() {
        return resources;
    }

    /** Returns the time this target was decided. */
    public Instant at() { return at; }

    @Override
    public boolean equals(Object o) {
        if ( ! (o instanceof Autoscaling other)) return false;
        if ( ! this.at.equals(other.at)) return false;
        if ( ! this.resources.equals(other.resources)) return false;
        return true;
    }

    @Override
    public int hashCode() {
        return Objects.hash(resources, at);
    }

    @Override
    public String toString() {
        return "autoscaling to " + resources + ", made at " + at;
    }

    public static Autoscaling empty() { return new Autoscaling(Optional.empty(), Instant.EPOCH); }

}