ContainerLocalizer { Callable<Path> download(Path destDirPath, LocalResource rsrc, UserGroupInformation ugi) throws IOException { if (rsrc.getVisibility() == LocalResourceVisibility.PRIVATE) { createParentDirs(destDirPath); } diskValidator .checkStatus(new File(destDirPath.getParent().toUri().getRawPath())); return new FSDownloadWrapper(lfs, ugi, conf, destDirPath, rsrc); } ContainerLocalizer(FileContext lfs, String user, String appId,
      String localizerId, String tokenFileName,  List<Path> localDirs,
      RecordFactory recordFactory); @Private @VisibleForTesting LocalizationProtocol getProxy(final InetSocketAddress nmAddr); @SuppressWarnings("deprecation") void runLocalization(final InetSocketAddress nmAddr); static List<String> getJavaOpts(Configuration conf); static void buildMainArgs(List<String> command,
      String user, String appId, String locId,
      InetSocketAddress nmAddr,
      String tokenFileName,
      List<String> localDirs, Configuration conf); static void main(String[] argv); static final String FILECACHE; static final String APPCACHE; static final String USERCACHE; static final String CSI_VOLIUME_MOUNTS_ROOT; }
@Test public void testDiskCheckFailure() throws Exception { Configuration conf = new Configuration(); conf.set(YarnConfiguration.DISK_VALIDATOR, "read-write"); FileContext lfs = FileContext.getLocalFSFileContext(conf); Path fileCacheDir = lfs.makeQualified(new Path(basedir, "filecache")); lfs.mkdir(fileCacheDir, FsPermission.getDefault(), true); RecordFactory recordFactory = mock(RecordFactory.class); ContainerLocalizer localizer = new ContainerLocalizer(lfs, UserGroupInformation.getCurrentUser().getUserName(), "application_01", "container_01", String.format(ContainerExecutor.TOKEN_FILE_NAME_FMT, "container_01"), new ArrayList<>(), recordFactory){ @Override Configuration initConfiguration() { return conf; } }; LocalResource rsrc = mock(LocalResource.class); Path destDirPath = new Path(fileCacheDir, "11"); try { localizer.download(destDirPath, rsrc, UserGroupInformation.getCurrentUser()); } catch (DiskErrorException ex) { fail(ex.getCause().toString()); } }
@Test(timeout = 10000) public void testUserCacheDirPermission() throws Exception { Configuration conf = new Configuration(); conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, "077"); FileContext lfs = FileContext.getLocalFSFileContext(conf); Path fileCacheDir = lfs.makeQualified(new Path(basedir, "filecache")); lfs.mkdir(fileCacheDir, FsPermission.getDefault(), true); RecordFactory recordFactory = mock(RecordFactory.class); ContainerLocalizer localizer = new ContainerLocalizer(lfs, UserGroupInformation.getCurrentUser().getUserName(), "application_01", "container_01", String.format(ContainerExecutor.TOKEN_FILE_NAME_FMT, "container_01"), new ArrayList<>(), recordFactory); LocalResource rsrc = mock(LocalResource.class); when(rsrc.getVisibility()).thenReturn(LocalResourceVisibility.PRIVATE); Path destDirPath = new Path(fileCacheDir, "0/0/85"); FsPermission wrongPerm = new FsPermission((short) 0700); lfs.mkdir(destDirPath.getParent().getParent(), wrongPerm, false); lfs.mkdir(destDirPath.getParent(), wrongPerm, false); localizer .download(destDirPath, rsrc, UserGroupInformation.getCurrentUser()); Assert .assertEquals("Cache directory permissions filecache/0/0 is incorrect", USERCACHE_DIR_PERM, lfs.getFileStatus(destDirPath.getParent()).getPermission()); Assert.assertEquals("Cache directory permissions filecache/0 is incorrect", USERCACHE_DIR_PERM, lfs.getFileStatus(destDirPath.getParent().getParent()).getPermission()); }