summaryrefslogtreecommitdiffstats
path: root/vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentOperationStatus.java
blob: c665eca1cac689bf94aee85013fe8edf15776403 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi.metrics;

import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol;

import java.util.Set;

/**
 * Enum with possible outcomes of a single document feeding operation:
 * <ul>
 * <li>OK: Document was successfully added/updated/removed</li>
 * <li>REQUEST_ERROR: User-made error, for example invalid document format</li>
 * <li>SERVER_ERROR: Server-made error, for example insufficient disk space</li>
 * </ul>
 *
 * @author freva
 */
public enum DocumentOperationStatus {

    OK, REQUEST_ERROR, SERVER_ERROR;

    public static DocumentOperationStatus fromHttpStatusCode(int httpStatus) {
        switch (httpStatus / 100) {
            case 2: return OK;
            case 4: return REQUEST_ERROR;
            case 5: return SERVER_ERROR;
            default: return null;
        }
    }

    public static DocumentOperationStatus fromMessageBusErrorCodes(Set<Integer> errorCodes) {
        if (errorCodes.size() == 1 && errorCodes.contains(DocumentProtocol.ERROR_NO_SPACE))
            return SERVER_ERROR;

        return REQUEST_ERROR;
    }

}