JobSubmissionFiles { public static Path getStagingDir(Cluster cluster, Configuration conf) throws IOException, InterruptedException { UserGroupInformation user = UserGroupInformation.getLoginUser(); return getStagingDir(cluster, conf, user); }  static Path getJobSplitFile(Path jobSubmissionDir); static Path getJobSplitMetaFile(Path jobSubmissionDir); static Path getJobConfPath(Path jobSubmitDir); static Path getJobJar(Path jobSubmitDir); static Path getJobDistCacheFiles(Path jobSubmitDir); static Path getJobLog4jFile(Path jobSubmitDir); static Path getJobDistCacheArchives(Path jobSubmitDir); static Path getJobDistCacheLibjars(Path jobSubmitDir); static Path getStagingDir(Cluster cluster, Configuration conf); @VisibleForTesting static Path getStagingDir(Cluster cluster, Configuration conf,
      UserGroupInformation realUser); final static FsPermission JOB_DIR_PERMISSION; final static FsPermission JOB_FILE_PERMISSION; }
@Test public void testGetStagingDirWhenFullFileOwnerNameAndFullUserName() throws IOException, InterruptedException { Cluster cluster = mock(Cluster.class); Configuration conf = new Configuration(); Path stagingPath = mock(Path.class); UserGroupInformation user = UserGroupInformation .createUserForTesting(USER_1, GROUP_NAMES); assertEquals(USER_1, user.getUserName()); FileSystem fs = new FileSystemTestHelper.MockFileSystem(); when(cluster.getStagingAreaDir()).thenReturn(stagingPath); when(stagingPath.getFileSystem(conf)).thenReturn(fs); String stagingDirOwner = USER_1.toLowerCase(); FileStatus fileStatus = new FileStatus(1, true, 1, 1, 100L, 100L, FsPermission.getDefault(), stagingDirOwner, stagingDirOwner, stagingPath); when(fs.getFileStatus(stagingPath)).thenReturn(fileStatus); assertEquals(stagingPath, JobSubmissionFiles.getStagingDir(cluster, conf, user)); stagingDirOwner = USER_1; fileStatus = new FileStatus(1, true, 1, 1, 100L, 100L, FsPermission.getDefault(), stagingDirOwner, stagingDirOwner, stagingPath); when(fs.getFileStatus(stagingPath)).thenReturn(fileStatus); assertEquals(stagingPath, JobSubmissionFiles.getStagingDir(cluster, conf, user)); }
@Test(expected = IOException.class) public void testGetStagingWhenFileOwnerNameAndCurrentUserNameDoesNotMatch() throws IOException, InterruptedException { Cluster cluster = mock(Cluster.class); Configuration conf = new Configuration(); String stagingDirOwner = "someuser"; Path stagingPath = mock(Path.class); UserGroupInformation user = UserGroupInformation .createUserForTesting(USER_1, GROUP_NAMES); assertEquals(USER_1, user.getUserName()); FileSystem fs = new FileSystemTestHelper.MockFileSystem(); FileStatus fileStatus = new FileStatus(1, true, 1, 1, 100L, 100L, FsPermission.getDefault(), stagingDirOwner, stagingDirOwner, stagingPath); when(stagingPath.getFileSystem(conf)).thenReturn(fs); when(fs.getFileStatus(stagingPath)).thenReturn(fileStatus); when(cluster.getStagingAreaDir()).thenReturn(stagingPath); assertEquals(stagingPath, JobSubmissionFiles.getStagingDir(cluster, conf, user)); }
@Test public void testGetStagingDirWhenShortFileOwnerNameAndFullUserName() throws IOException, InterruptedException { Cluster cluster = mock(Cluster.class); Configuration conf = new Configuration(); String stagingDirOwner = USER_1_SHORT_NAME; Path stagingPath = mock(Path.class); UserGroupInformation user = UserGroupInformation .createUserForTesting(USER_1, GROUP_NAMES); assertEquals(USER_1, user.getUserName()); FileSystem fs = new FileSystemTestHelper.MockFileSystem(); FileStatus fileStatus = new FileStatus(1, true, 1, 1, 100L, 100L, FsPermission.getDefault(), stagingDirOwner, stagingDirOwner, stagingPath); when(stagingPath.getFileSystem(conf)).thenReturn(fs); when(fs.getFileStatus(stagingPath)).thenReturn(fileStatus); when(cluster.getStagingAreaDir()).thenReturn(stagingPath); assertEquals(stagingPath, JobSubmissionFiles.getStagingDir(cluster, conf, user)); }
@Test public void testGetStagingDirWhenShortFileOwnerNameAndShortUserName() throws IOException, InterruptedException { Cluster cluster = mock(Cluster.class); Configuration conf = new Configuration(); String stagingDirOwner = USER_1_SHORT_NAME; Path stagingPath = mock(Path.class); UserGroupInformation user = UserGroupInformation .createUserForTesting(USER_1_SHORT_NAME, GROUP_NAMES); assertEquals(USER_1_SHORT_NAME, user.getUserName()); FileSystem fs = new FileSystemTestHelper.MockFileSystem(); FileStatus fileStatus = new FileStatus(1, true, 1, 1, 100L, 100L, FsPermission.getDefault(), stagingDirOwner, stagingDirOwner, stagingPath); when(stagingPath.getFileSystem(conf)).thenReturn(fs); when(fs.getFileStatus(stagingPath)).thenReturn(fileStatus); when(cluster.getStagingAreaDir()).thenReturn(stagingPath); assertEquals(stagingPath, JobSubmissionFiles.getStagingDir(cluster, conf, user)); }