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;
}
Aggregations