|
@@ -31,6 +31,7 @@ import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
+import java.util.Stack;
|
|
|
import java.util.concurrent.Callable;
|
|
|
import java.util.concurrent.CancellationException;
|
|
|
import java.util.concurrent.CompletionService;
|
|
@@ -60,6 +61,7 @@ import org.apache.hadoop.util.Shell;
|
|
|
import org.apache.hadoop.util.concurrent.HadoopExecutors;
|
|
|
import org.apache.hadoop.yarn.YarnUncaughtExceptionHandler;
|
|
|
import org.apache.hadoop.yarn.api.records.LocalResource;
|
|
|
+import org.apache.hadoop.yarn.api.records.LocalResourceVisibility;
|
|
|
import org.apache.hadoop.yarn.api.records.SerializedException;
|
|
|
import org.apache.hadoop.yarn.api.records.URL;
|
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
@@ -95,6 +97,8 @@ public class ContainerLocalizer {
|
|
|
private static final String USERCACHE_CTXT_FMT = "%s.user.cache.dirs";
|
|
|
private static final FsPermission FILECACHE_PERMS =
|
|
|
new FsPermission((short)0710);
|
|
|
+ private static final FsPermission USERCACHE_FOLDER_PERMS =
|
|
|
+ new FsPermission((short) 0755);
|
|
|
|
|
|
private final String user;
|
|
|
private final String appId;
|
|
@@ -237,10 +241,29 @@ public class ContainerLocalizer {
|
|
|
|
|
|
}
|
|
|
|
|
|
- Callable<Path> download(Path path, LocalResource rsrc,
|
|
|
+ Callable<Path> download(Path destDirPath, LocalResource rsrc,
|
|
|
UserGroupInformation ugi) throws IOException {
|
|
|
- diskValidator.checkStatus(new File(path.toUri().getRawPath()));
|
|
|
- return new FSDownloadWrapper(lfs, ugi, conf, path, rsrc);
|
|
|
+ // For private localization FsDownload creates folder in destDirPath. Parent
|
|
|
+ // directories till user filecache folder is created here.
|
|
|
+ if (rsrc.getVisibility() == LocalResourceVisibility.PRIVATE) {
|
|
|
+ createParentDirs(destDirPath);
|
|
|
+ }
|
|
|
+ diskValidator.checkStatus(new File(destDirPath.toUri().getRawPath()));
|
|
|
+ return new FSDownloadWrapper(lfs, ugi, conf, destDirPath, rsrc);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createParentDirs(Path destDirPath) throws IOException {
|
|
|
+ Path parent = destDirPath.getParent();
|
|
|
+ Path cacheRoot = LocalCacheDirectoryManager.getCacheDirectoryRoot(parent);
|
|
|
+ Stack<Path> dirs = new Stack<Path>();
|
|
|
+ while (!parent.equals(cacheRoot)) {
|
|
|
+ dirs.push(parent);
|
|
|
+ parent = parent.getParent();
|
|
|
+ }
|
|
|
+ // Create directories with user cache permission
|
|
|
+ while (!dirs.isEmpty()) {
|
|
|
+ createDir(lfs, dirs.pop(), USERCACHE_FOLDER_PERMS);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
static long getEstimatedSize(LocalResource rsrc) {
|
|
@@ -455,21 +478,21 @@ public class ContainerLocalizer {
|
|
|
// $x/usercache/$user/filecache
|
|
|
Path userFileCacheDir = new Path(base, FILECACHE);
|
|
|
usersFileCacheDirs[i] = userFileCacheDir.toString();
|
|
|
- createDir(lfs, userFileCacheDir, FILECACHE_PERMS, false);
|
|
|
+ createDir(lfs, userFileCacheDir, FILECACHE_PERMS);
|
|
|
// $x/usercache/$user/appcache/$appId
|
|
|
Path appBase = new Path(base, new Path(APPCACHE, appId));
|
|
|
// $x/usercache/$user/appcache/$appId/filecache
|
|
|
Path appFileCacheDir = new Path(appBase, FILECACHE);
|
|
|
appsFileCacheDirs[i] = appFileCacheDir.toString();
|
|
|
- createDir(lfs, appFileCacheDir, FILECACHE_PERMS, false);
|
|
|
+ createDir(lfs, appFileCacheDir, FILECACHE_PERMS);
|
|
|
}
|
|
|
conf.setStrings(String.format(APPCACHE_CTXT_FMT, appId), appsFileCacheDirs);
|
|
|
conf.setStrings(String.format(USERCACHE_CTXT_FMT, user), usersFileCacheDirs);
|
|
|
}
|
|
|
|
|
|
private static void createDir(FileContext lfs, Path dirPath,
|
|
|
- FsPermission perms, boolean createParent) throws IOException {
|
|
|
- lfs.mkdir(dirPath, perms, createParent);
|
|
|
+ FsPermission perms) throws IOException {
|
|
|
+ lfs.mkdir(dirPath, perms, false);
|
|
|
if (!perms.equals(perms.applyUMask(lfs.getUMask()))) {
|
|
|
lfs.setPermission(dirPath, perms);
|
|
|
}
|