aboutsummaryrefslogtreecommitdiffstats
path: root/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/StatusCode.java
blob: 6ce9b6cfc623f3461b728bcb3bc985a37f9d2fff (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.metricsproxy.metric.model;

/**
 * Status code for a Vespa service.
 *
 * @author gjoranv
 */
public enum StatusCode {

    UP(0, "up"),
    DOWN(1, "down"),
    UNKNOWN(2, "unknown");

    public final int code;
    public final String status;

    StatusCode(int code, String status) {
        this.code = code;
        this.status = status;
    }

    public static StatusCode fromString(String statusString) {
        if ("ok".equalsIgnoreCase(statusString)) return UP;
        try {
            return valueOf(statusString.trim().toUpperCase());
        } catch (IllegalArgumentException | NullPointerException e) {
            return UNKNOWN;
        }
    }

}