aboutsummaryrefslogtreecommitdiffstats
path: root/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/VersionDependentTaskCompletion.java
blob: b979e82adea1ee1d84880eb8a7385a507c3ae46b (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
// Copyright Yahoo. 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.Objects;

/**
 * Wrapper for a remote (i.e. REST API) cluster controller task whose
 * completion depends on side effects by the task becoming visible in
 * the cluster before a response can be sent. Each such task is associated
 * with a particular cluster state version number representing a lower bound
 * on the published state containing the side effect. Each task is also
 * associated with a completion deadline.
 */
class VersionDependentTaskCompletion {
    private final long minimumVersion;
    private final RemoteClusterControllerTask task;
    private final long deadlineTimePointMs;

    VersionDependentTaskCompletion(long minimumVersion, RemoteClusterControllerTask task, long maxDeadlineTimePointMs) {
        this.minimumVersion = minimumVersion;
        this.task = task;
        this.deadlineTimePointMs = task.getDeadline().map(deadline ->
                Math.max(0, Math.min(deadline.toEpochMilli(), maxDeadlineTimePointMs)))
                .orElse(maxDeadlineTimePointMs);
    }

    long getMinimumVersion() {
        return minimumVersion;
    }

    RemoteClusterControllerTask getTask() {
        return task;
    }

    long getDeadlineTimePointMs() {
        return deadlineTimePointMs;
    }

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

    @Override
    public int hashCode() {
        return Objects.hash(minimumVersion, task);
    }
}