Search in sources :

Example 1 with V1StatusCause

use of io.kubernetes.client.openapi.models.V1StatusCause in project java by kubernetes-client.

the class Exec method parseExitCode.

static int parseExitCode(ApiClient client, InputStream inputStream) {
    try {
        Type returnType = new TypeToken<V1Status>() {
        }.getType();
        String body;
        try (final Reader reader = new InputStreamReader(inputStream)) {
            body = Streams.toString(reader);
        }
        V1Status status = client.getJSON().deserialize(body, returnType);
        if (status == null) {
            return -1;
        }
        if (V1STATUS_SUCCESS.equals(status.getStatus()))
            return 0;
        if (V1STATUS_REASON_NONZEROEXITCODE.equals(status.getReason())) {
            V1StatusDetails details = status.getDetails();
            if (details != null) {
                List<V1StatusCause> causes = details.getCauses();
                if (causes != null) {
                    for (V1StatusCause cause : causes) {
                        if (V1STATUS_CAUSE_REASON_EXITCODE.equals(cause.getReason())) {
                            try {
                                return Integer.parseInt(cause.getMessage());
                            } catch (NumberFormatException nfe) {
                                log.error("Error parsing exit code from status channel response", nfe);
                            }
                        }
                    }
                }
            }
        }
    } catch (Throwable t) {
        log.error("Error parsing exit code from status channel response", t);
    }
    // Unable to parse the exit code from the content
    return -1;
}
Also used : V1StatusCause(io.kubernetes.client.openapi.models.V1StatusCause) Type(java.lang.reflect.Type) V1Status(io.kubernetes.client.openapi.models.V1Status) InputStreamReader(java.io.InputStreamReader) V1StatusDetails(io.kubernetes.client.openapi.models.V1StatusDetails) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader)

Aggregations

V1Status (io.kubernetes.client.openapi.models.V1Status)1 V1StatusCause (io.kubernetes.client.openapi.models.V1StatusCause)1 V1StatusDetails (io.kubernetes.client.openapi.models.V1StatusDetails)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 Type (java.lang.reflect.Type)1