From af4fc2e62805a5bd392214521a93650085b8d020 Mon Sep 17 00:00:00 2001 From: Eric Yang Date: Wed, 9 May 2018 13:32:51 -0400 Subject: [PATCH] YARN-8261. Fixed a bug in creation of localized container directory. Contributed by Jason Lowe --- .../linux/runtime/docker/DockerClient.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/docker/DockerClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/docker/DockerClient.java index 7bd4546fc8..dd49e150ca 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/docker/DockerClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/docker/DockerClient.java @@ -110,7 +110,7 @@ public String writeCommandToTempFile(DockerCommand cmd, ApplicationId appId = containerId.getApplicationAttemptId() .getApplicationId(); File dockerCommandFile; - String cmdDir = null; + File cmdDir = null; if(nmContext == null || nmContext.getLocalDirsHandler() == null) { throw new ContainerExecutionException( @@ -118,12 +118,17 @@ public String writeCommandToTempFile(DockerCommand cmd, } try { - cmdDir = nmContext.getLocalDirsHandler().getLocalPathForWrite( + String cmdDirPath = nmContext.getLocalDirsHandler().getLocalPathForWrite( ResourceLocalizationService.NM_PRIVATE_DIR + Path.SEPARATOR + 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, - TMP_FILE_SUFFIX, new File(cmdDir)); + TMP_FILE_SUFFIX, cmdDir); Writer writer = new OutputStreamWriter( new FileOutputStream(dockerCommandFile.toString()), "UTF-8");