YARN-8261. Fixed a bug in creation of localized container directory.

Contributed by Jason Lowe
This commit is contained in:
Eric Yang 2018-05-09 13:32:51 -04:00
parent 343b51dcf4
commit af4fc2e628

View File

@ -110,7 +110,7 @@ public String writeCommandToTempFile(DockerCommand cmd,
ApplicationId appId = containerId.getApplicationAttemptId() ApplicationId appId = containerId.getApplicationAttemptId()
.getApplicationId(); .getApplicationId();
File dockerCommandFile; File dockerCommandFile;
String cmdDir = null; File cmdDir = null;
if(nmContext == null || nmContext.getLocalDirsHandler() == null) { if(nmContext == null || nmContext.getLocalDirsHandler() == null) {
throw new ContainerExecutionException( throw new ContainerExecutionException(
@ -118,12 +118,17 @@ public String writeCommandToTempFile(DockerCommand cmd,
} }
try { try {
cmdDir = nmContext.getLocalDirsHandler().getLocalPathForWrite( String cmdDirPath = nmContext.getLocalDirsHandler().getLocalPathForWrite(
ResourceLocalizationService.NM_PRIVATE_DIR + Path.SEPARATOR + ResourceLocalizationService.NM_PRIVATE_DIR + Path.SEPARATOR +
appId + Path.SEPARATOR + filePrefix + Path.SEPARATOR).toString(); appId + Path.SEPARATOR + filePrefix + Path.SEPARATOR).toString();
cmdDir = new File(cmdDirPath);
if (!cmdDir.mkdirs() && !cmdDir.exists()) {
throw new IOException("Cannot create container private directory "
+ cmdDir);
}
dockerCommandFile = File.createTempFile(TMP_FILE_PREFIX + filePrefix, dockerCommandFile = File.createTempFile(TMP_FILE_PREFIX + filePrefix,
TMP_FILE_SUFFIX, new File(cmdDir)); TMP_FILE_SUFFIX, cmdDir);
Writer writer = new OutputStreamWriter( Writer writer = new OutputStreamWriter(
new FileOutputStream(dockerCommandFile.toString()), "UTF-8"); new FileOutputStream(dockerCommandFile.toString()), "UTF-8");