aboutsummaryrefslogtreecommitdiffstats
path: root/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfo.java
blob: 37479fc628380d974a2c560cf3fc477959ced4c7 (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 Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.orchestrator.status;

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

/**
 * ZooKeeper-backed information Host status information about a host.
 *
 * @author hakonhall
 */
// @Immutable
public class HostInfo {
    private final HostStatus status;
    private final Optional<Instant> suspendedSince;

    public static HostInfo createSuspended(HostStatus status, Instant suspendedSince) {
        if (!status.isSuspended()) {
            throw new IllegalArgumentException(status + " is not a suspended-status");
        }

        return new HostInfo(status, Optional.of(suspendedSince));
    }

    public static HostInfo createNoRemarks() {
        return new HostInfo(HostStatus.NO_REMARKS, Optional.empty());
    }

    private HostInfo(HostStatus status, Optional<Instant> suspendedSince) {
        this.status = Objects.requireNonNull(status);
        this.suspendedSince = Objects.requireNonNull(suspendedSince);
    }

    public HostStatus status() { return status; }

    /**
     * The instant the host status was set to a suspended status. Is preserved when transitioning
     * between suspended statuses. Returns empty if and only if NO_REMARKS.
     */
    public Optional<Instant> suspendedSince() { return suspendedSince; }

    @Override
    public String toString() {
        return "HostInfo{" +
                ", status=" + status +
                ", suspendedSince=" + suspendedSince +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        HostInfo hostInfo = (HostInfo) o;
        return status == hostInfo.status &&
                suspendedSince.equals(hostInfo.suspendedSince);
    }

    @Override
    public int hashCode() {
        return Objects.hash(status, suspendedSince);
    }
}