Spring Boot YARN exit code
In this article, we’ll find the answer to this question:
- how to set up exit code on Spring Boot Yarn container
- Spring Boot Yarn exit code
Suppose we need to mark container’s start class using the @YarnComponent and mark method with the @OnContainerStart annotations in YourContainer.java:
@YarnComponent
class YourContainer {
@OnContainerStart
public void onContainerStart() {
// your code
}
}
Even though the description of the annotation says that it cannot return anything, the return value works. We make the return value of type int.
0 – means successful shutdown of the container, non-zero values – error:
@YarnComponent
class YourContainer {
@OnContainerStart
public int onContainerStart() {
try {
// your code
} catch (Exception e) {
log.error(e.getMessage());
return 1;
}
return 0;
}
}
The return value should be smaller than 256. You may notice, that:
- If you terminate the container with exit code 0 or some other positive number, then the same code will be sent to AppMaster;
- If you terminate the container with a negative code, then another number will be sent to AppMaster.
Why is this happening – let’s talk in this article.