1

I'm following this example about create YarnApp by java API.

https://github.com/hortonworks/simple-yarn-app

Works fine, but, the log exists only execution, after it the log gone.

How I can caught this by code ? or maybe enable one option?

franklinsijo
  • 17,784
  • 4
  • 45
  • 63
Alan
  • 151
  • 1
  • 1
  • 7

1 Answers1

0

You can find logs using LogCliHelpers by application id after application had finished:

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
import org.apache.hadoop.yarn.client.api.YarnClientApplication;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.logaggregation.LogCLIHelpers;

import java.io.IOException;
import java.io.PrintStream;

public static void getLogs(YarnConfiguration conf, YarnClientApplication app) throws IOException, YarnException {
    ApplicationSubmissionContext appContext =
            app.getApplicationSubmissionContext();
    ApplicationId appId = appContext.getApplicationId();
    LogCLIHelpers logCLIHelpers = new LogCLIHelpers();
    logCLIHelpers.setConf(conf);
    FileSystem fs = FileSystem.get(conf);
    Path logFile = new Path("/path/to/log/file.log");
    fs.create(logFile, false);
    try (PrintStream printStream = new PrintStream(logFile.toString())) {
      logCLIHelpers.dumpAllContainersLogs(appId, UserGroupInformation.getCurrentUser().getShortUserName(), printStream);
    }
}
Boris Azanov
  • 4,408
  • 1
  • 15
  • 28
  • Tks Boris for your answer. I'm using the API version 3.0.0. This class changes a lot. Actually it's logCLIHelpers.dumpAllContainersLogs(ContainerLogsRequest arg0). I'm not understand when write the log to hdfs. – Alan Apr 14 '20 at 14:49
  • @Alan Sorry, I can't update my code now and yes, it's use API 2.2.0. maybe you can find answer here: https://stackoverflow.com/questions/23058663/where-are-logs-in-spark-on-yarn – Boris Azanov Apr 14 '20 at 20:08