aboutsummaryrefslogtreecommitdiffstats
path: root/hosted-api/src/main/java/ai/vespa/hosted/api/DeploymentLog.java
blob: c05a8489e8e7912fc2298a0e89d865ef1d8f49a4 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.hosted.api;

import java.time.Instant;
import java.util.List;
import java.util.OptionalLong;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.Comparator.comparing;

/**
 * A list of {@link Entry} items from a deployment job.
 *
 * @author jonmv
 */
public class DeploymentLog {

    private final List<Entry> entries;
    private final boolean active;
    private final Status status;
    private final OptionalLong last;

    public DeploymentLog(List<Entry> entries, boolean active, Status status, OptionalLong last) {
        this.entries = entries.stream().sorted(comparing(Entry::at)).toList();
        this.active = active;
        this.status = status;
        this.last = last;
    }

    /** Returns this log updated with the content of the other. */
    public DeploymentLog updatedWith(DeploymentLog other) {
        return new DeploymentLog(Stream.concat(entries.stream(), other.entries.stream()).toList(),
                                 other.active,
                                 other.status,
                                 other.last);
    }

    public List<Entry> entries() {
        return entries;
    }

    public boolean isActive() {
        return active;
    }

    public Status status() {
        return status;
    }

    public OptionalLong last() {
        return last;
    }

    @Override
    public String toString() {
        return "status: " + status.name() + ", " + (active ? "active" : "not active") + ", log entries:\n" +
                entries.stream()
                       .map(entry -> String.format("%s %s %s", entry.at(), entry.level(), entry.message()))
                       .collect(Collectors.joining("\n"));
    }

    public static class Entry {

        private final Instant at;
        private final Level level;
        private final String message;
        private final boolean isVespaLogEntry;

        public Entry(Instant at, Level level, String message, boolean isVespaLogEntry) {
            this.at = at;
            this.level = level;
            this.message = message;
            this.isVespaLogEntry = isVespaLogEntry;
        }

        public Instant at() {
            return at;
        }

        public Level level() {
            return level;
        }

        public String message() {
            return message;
        }

        public boolean isVespaLogEntry() {
            return isVespaLogEntry;
        }

    }


    public enum Level {
        error,
        warning,
        info,
        debug;

        public static Level of(String level) {
            return switch (level) {
                case "error" -> error;
                case "warning" -> warning;
                case "info" -> info;
                case "debug" -> debug;
                default -> debug;
            };
        }
    }


    public enum Status {
        running,
        aborted,
        error,
        testFailure,
        nodeAllocationFailure,
        installationFailed,
        deploymentFailed,
        endpointCertificateTimeout,
        success;
    }

}