Explorar o código

commit f1e5da4123246f98124a516e93ecdfa3104d9f9c
Author: Hemanth Yamijala <yhemanth@friendchild-lm.(none)>
Date: Fri Jan 29 00:00:30 2010 +0530

MAPREDUCE:842 (follow-up patch to fix a backport bug) from https://issues.apache.org/jira/secure/attachment/12431690/MR-842-follow-up.patch

+++ b/YAHOO-CHANGES.txt
+ MAPREDUCE-842. Fixing a bug in the earlier version of the patch
+ related to improper localization of the job token file.
+ (Ravi Gummadi via yhemanth)
+


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-patches@1077133 13f79535-47bb-0310-9956-ffa450edef68

Owen O'Malley %!s(int64=14) %!d(string=hai) anos
pai
achega
dee48574ef

+ 4 - 2
src/mapred/org/apache/hadoop/mapred/TaskTracker.java

@@ -922,8 +922,7 @@ public class TaskTracker
         rjob.jobConf = localJobConf;  
         rjob.keepJobFiles = ((localJobConf.getKeepTaskFilesPattern() != null) ||
                              localJobConf.getKeepFailedTaskFiles());
-        // save local copy of JobToken file
-        localizeJobTokenFile(t.getUser(), jobId, localJobConf);       
+
         TokenStorage ts = TokenCache.loadTokens(rjob.jobConf);
         Token<JobTokenIdentifier> jt = (Token<JobTokenIdentifier>)ts.getJobToken(); 
         getJobTokenSecretManager().addTokenForJob(jobId.toString(), jt);
@@ -985,6 +984,9 @@ public class TaskTracker
     // Download the job.jar for this job from the system FS
     localizeJobJarFile(userName, jobId, userFs, localJobConf);
 
+    // save local copy of JobToken file
+    localizeJobTokenFile(userName, jobId, localJobConf);
+
     return localJobConf;
   }
 

+ 26 - 0
src/test/org/apache/hadoop/mapred/TestTaskTrackerLocalization.java

@@ -33,7 +33,10 @@ import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.fs.LocalDirAllocator;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.mapreduce.server.tasktracker.Localizer;
+import org.apache.hadoop.mapreduce.security.SecureShuffleUtils;
+import org.apache.hadoop.mapreduce.security.token.JobTokenIdentifier;
 import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.token.Token;
 import org.apache.hadoop.util.Shell;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.mapred.JvmManager.JvmEnv;
@@ -129,6 +132,7 @@ public class TestTaskTrackerLocalization extends TestCase {
 
     // for test case system FS is the local FS
     tracker.systemFS = FileSystem.getLocal(trackerFConf);
+    tracker.systemDirectory = new Path(TEST_ROOT_DIR.getAbsolutePath());
     tracker.setLocalFileSystem(tracker.systemFS);
     
     taskTrackerUGI = UserGroupInformation.login(trackerFConf);
@@ -142,6 +146,9 @@ public class TestTaskTrackerLocalization extends TestCase {
         new MapTask(jobConfFile.toURI().toString(), taskId, 1, null, 1);
     task.setConf(jobConf); // Set conf. Set user name in particular.
 
+    // create jobTokens file
+    uploadJobTokensFile();
+
     taskController = new DefaultTaskController();
     taskController.setConf(trackerFConf);
     taskController.setup();
@@ -189,6 +196,25 @@ public class TestTaskTrackerLocalization extends TestCase {
     return jobConfFile;
    }
   
+  /**
+   * create fake JobTokens file
+   * @return
+   * @throws IOException
+   */
+  protected void uploadJobTokensFile() throws IOException {
+
+    File dir = new File(TEST_ROOT_DIR, jobId.toString());
+    if(!dir.exists())
+      assertTrue("faild to create dir="+dir.getAbsolutePath(), dir.mkdirs());
+
+    File jobTokenFile = new File(dir, SecureShuffleUtils.JOB_TOKEN_FILENAME);
+    FileOutputStream fos = new FileOutputStream(jobTokenFile);
+    java.io.DataOutputStream out = new java.io.DataOutputStream(fos);
+    Token<JobTokenIdentifier> jt = new Token<JobTokenIdentifier>();
+    jt.write(out); // writing empty file, we don't need the keys for this test
+    out.close();
+  }
+
   @Override
   protected void tearDown()
       throws Exception {