// find user log directory
Path userLogFile =
getJobHistoryLogLocationForUser(logFileName, jobConf);
try{
FSDataOutputStream out = null;
PrintWriter writer = null;
if (LOG_DIR != null) {
// create output stream for logging in hadoop.job.history.location
if (restarted) {
logFile = recoverJobHistoryFile(jobConf, logFile);
logFileName = logFile.getName();
}
int defaultBufferSize =
LOGDIR_FS.getConf().getInt("io.file.buffer.size", 4096);
out = LOGDIR_FS.create(logFile,
new FsPermission(HISTORY_FILE_PERMISSION),
true,
defaultBufferSize,
LOGDIR_FS.getDefaultReplication(),
jobHistoryBlockSize, null);
writer = new PrintWriter(out);
fileManager.addWriter(jobId, writer);
// cache it ...
fileManager.setHistoryFile(jobId, logFile);
}
if (userLogFile != null) {
// Get the actual filename as recoverJobHistoryFile() might return
// a different filename
userLogDir = userLogFile.getParent().toString();
userLogFile = new Path(userLogDir, logFileName);
// create output stream for logging
// in hadoop.job.history.user.location
fs = userLogFile.getFileSystem(jobConf);
out = fs.create(userLogFile, true, 4096);
writer = new PrintWriter(out);
fileManager.addWriter(jobId, writer);
}
ArrayList<PrintWriter> writers = fileManager.getWriters(jobId);
// Log the history meta info
JobHistory.MetaInfoManager.logMetaInfo(writers);
String viewJobACL = "*";
String modifyJobACL = "*";
if (aclsEnabled) {
viewJobACL = jobConf.get(JobACL.VIEW_JOB.getAclName(), " ");
modifyJobACL = jobConf.get(JobACL.MODIFY_JOB.getAclName(), " ");
}
//add to writer as well
JobHistory.log(writers, RecordTypes.Job,
new Keys[]{Keys.JOBID, Keys.JOBNAME, Keys.USER,
Keys.SUBMIT_TIME, Keys.JOBCONF,
Keys.VIEW_JOB, Keys.MODIFY_JOB,
Keys.JOB_QUEUE},
new String[]{jobId.toString(), jobName, user,
String.valueOf(submitTime) , jobConfPath,
viewJobACL, modifyJobACL,
jobConf.getQueueName()}
);
}catch(IOException e){
LOG.error("Failed creating job history log file, disabling history", e);
disableHistory = true;
}
}
// Always store job conf on local file system
String localJobFilePath = JobInfo.getLocalJobFilePath(jobId);
File localJobFile = new File(localJobFilePath);
FileOutputStream jobOut = null;
try {
jobOut = new FileOutputStream(localJobFile);
jobConf.writeXml(jobOut);
if (LOG.isDebugEnabled()) {
LOG.debug("Job conf for " + jobId + " stored at "
+ localJobFile.getAbsolutePath());
}
} catch (IOException ioe) {
LOG.error("Failed to store job conf on the local filesystem ", ioe);
} finally {
if (jobOut != null) {
try {
jobOut.close();
} catch (IOException ie) {
LOG.info("Failed to close the job configuration file "
+ StringUtils.stringifyException(ie));
}
}
}
/* Storing the job conf on the log dir */
Path jobFilePath = null;
if (LOG_DIR != null) {
jobFilePath = new Path(LOG_DIR + File.separator +
jobUniqueString + "_conf.xml");
fileManager.setConfFile(jobId, jobFilePath);
}
Path userJobFilePath = null;
if (userLogDir != null) {
userJobFilePath = new Path(userLogDir + File.separator +
jobUniqueString + "_conf.xml");
}
FSDataOutputStream jobFileOut = null;
try {
if (LOG_DIR != null) {
int defaultBufferSize =
LOGDIR_FS.getConf().getInt("io.file.buffer.size", 4096);
if (!LOGDIR_FS.exists(jobFilePath)) {
jobFileOut = LOGDIR_FS.create(jobFilePath,
new FsPermission(HISTORY_FILE_PERMISSION),
true,
defaultBufferSize,
LOGDIR_FS.getDefaultReplication(),
LOGDIR_FS.getDefaultBlockSize(), null);
jobConf.writeXml(jobFileOut);
jobFileOut.close();
}
}
if (userLogDir != null) {
fs = new Path(userLogDir).getFileSystem(jobConf);
jobFileOut = fs.create(userJobFilePath);
jobConf.writeXml(jobFileOut);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Job conf for " + jobId + " stored at "
+ jobFilePath + "and" + userJobFilePath );
}
} catch (IOException ioe) {
LOG.error("Failed to store job conf in the log dir", ioe);
} finally {
if (jobFileOut != null) {
try {
jobFileOut.close();
} catch (IOException ie) {
LOG.info("Failed to close the job configuration file "
+ StringUtils.stringifyException(ie));
}
}