I actually retrieve my spark application's logs on a linux shell with :
yarn logs -applicationId applicationid
Is there any way to retrieve it programmatically using java ?
I wanted to do it programmatically using java, so i finally took a look at the code behind the command :
yarn logs -applicationId applicationid
which is in :
src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java
I now retrieve the logs in a string (content). The code is:
String applicationId = "application_1492795815045_3940";
ApplicationId appId = appId = ConverterUtils.toApplicationId(applicationId);
LogCLIHelpers logCliHelper = new LogCLIHelpers();
Configuration config = new Configuration();
logCliHelper.setConf(config);
String appOwner = UserGroupInformation.getCurrentUser().getShortUserName();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
// Function to retrieve logs
logCliHelper.dumpAllContainersLogs(appId, appOwner, ps);
String content = new String(baos.toByteArray(), StandardCharsets.UTF_8);
System.out.println(content)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With