Bladeren bron

commit 319fff84064b72f8306f07c50781df63f43064b5
Author: Chris Douglas <cdouglas@apache.org>
Date: Tue Jul 27 18:41:44 2010 -0700

JobHistory links broken in embedded mode


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

Owen O'Malley 14 jaren geleden
bovenliggende
commit
88977df668

+ 6 - 3
src/mapred/org/apache/hadoop/mapred/JobHistoryServer.java

@@ -22,6 +22,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.http.HttpServer;
 import org.apache.hadoop.net.NetUtils;
 import org.apache.hadoop.security.SecurityUtil;
@@ -164,17 +165,18 @@ public class JobHistoryServer {
     }
     final String historyLogDir =
       JobHistory.getCompletedJobHistoryLocation().toString();
+    FileSystem historyFS = new Path(historyLogDir).getFileSystem(conf);    
 
     context = historyServer.addContext("history", true);
 
     historyServer.setAttribute(context, "historyLogDir", historyLogDir);
-    historyServer.setAttribute(context, "fileSys", fs);
+    historyServer.setAttribute(context, "fileSys", historyFS);
     historyServer.setAttribute(context, "jobConf", conf);
     historyServer.setAttribute(context, "aclManager", aclsManager);
 
     if (!isEmbedded(conf)) {
       historyServer.setAttribute("historyLogDir", historyLogDir);
-      historyServer.setAttribute("fileSys", fs);
+      historyServer.setAttribute("fileSys", historyFS);
       historyServer.setAttribute("jobConf", conf);
       historyServer.setAttribute("aclManager", aclsManager);
     }
@@ -250,7 +252,8 @@ public class JobHistoryServer {
   }
 
   static String getHistoryUrlPrefix(JobConf conf) {
-    return "http://" + getAddress(conf) + "/history";
+    return (isEmbedded(conf) ? "" : "http://" + getAddress(conf))
+      + "/history";
   }
 
   private static String getBindAddress(JobConf conf) {

+ 8 - 2
src/test/org/apache/hadoop/mapred/TestWebUIAuthorization.java

@@ -335,12 +335,20 @@ public class TestWebUIAuthorization extends ClusterMapReduceTestCase {
     JobConf conf = new JobConf(cluster.createJobConf());
     conf.set(JobContext.JOB_ACL_VIEW_JOB, viewColleague + " group3");
 
+    JobTracker jobTracker = getMRCluster().getJobTrackerRunner().getJobTracker();
+    
     //Initialize history server, if need to be started in standalone mode
+    String jhUrlPrefix = JobHistoryServer.getHistoryUrlPrefix(jobTracker.conf);
+    String jobHistoryUrl;
     if ("false".equals(props.getProperty(
         JobHistoryServer.MAPRED_HISTORY_SERVER_EMBEDDED, "true"))) {
       JobHistoryServer historyServer = new JobHistoryServer(cluster.
           getJobTrackerRunner().getJobTracker().conf);
       historyServer.start();
+      jobHistoryUrl = jhUrlPrefix;
+    } else {
+      jobHistoryUrl = "http://" + JobHistoryServer.getAddress(jobTracker.conf) +
+        jhUrlPrefix;
     }
 
     // Let us add group1 and group3 to modify-job-acl. So modifyColleague and
@@ -367,7 +375,6 @@ public class TestWebUIAuthorization extends ClusterMapReduceTestCase {
 
     JobID jobid = job.getID();
 
-    JobTracker jobTracker = getMRCluster().getJobTrackerRunner().getJobTracker();
     JobInProgress jip = jobTracker.getJob(jobid);
     JobConf finalJobConf = jip.getJobConf();
     Path doneDir = JobHistory.getCompletedJobHistoryLocation();
@@ -381,7 +388,6 @@ public class TestWebUIAuthorization extends ClusterMapReduceTestCase {
         JobHistory.JobInfo.getDoneJobHistoryFileName(finalJobConf, jobid));
 
     String urlEncodedHistoryFileName = URLEncoder.encode(historyFilePath.toString());
-    String jobHistoryUrl = JobHistoryServer.getHistoryUrlPrefix(jobTracker.conf);
 
     // validate access of jobdetails_history.jsp
     String jobDetailsJSP = jobHistoryUrl +

+ 16 - 5
src/webapps/history/jobhistoryhome.jsp

@@ -1,13 +1,14 @@
 <%@ page
   contentType="text/html; charset=UTF-8"
   import="java.io.*"
-  import="java.net.URLEncoder"
+  import="java.net.*"
   import="java.util.*"
   import="java.util.regex.Pattern"
   import="java.util.regex.Matcher"
   import="java.util.concurrent.atomic.AtomicBoolean"
-  import="org.apache.hadoop.mapred.*"
+  import="org.apache.hadoop.net.*"
   import="org.apache.hadoop.util.*"
+  import="org.apache.hadoop.mapred.*"
   import="org.apache.hadoop.fs.*"
   import="javax.servlet.jsp.*"
   import="java.text.SimpleDateFormat"
@@ -15,9 +16,19 @@
 %>
 <%	
   JobConf jobConf = (JobConf) application.getAttribute("jobConf");
+  String trackerUrl;
+  String trackerName;
+  
   String trackerAddress = jobConf.get("mapred.job.tracker.http.address");
-  String trackerName =
-           StringUtils.simpleHostname(trackerAddress);
+  InetSocketAddress infoSocAddr = NetUtils.createSocketAddr(trackerAddress);
+  if (JobHistoryServer.isEmbedded(jobConf)) {
+    trackerName = StringUtils.simpleHostname(InetAddress.
+      getLocalHost().getCanonicalHostName());
+    trackerUrl = "";
+  } else {
+    trackerUrl = "http://" + trackerAddress;
+    trackerName = StringUtils.simpleHostname(infoSocAddr.getHostName());
+  }
 %>
 <%!	
   private static SimpleDateFormat dateFormat = 
@@ -46,7 +57,7 @@ window.location.href = url;
 <link rel="stylesheet" type="text/css" href="/static/hadoop.css">
 </head>
 <body>
-<h1> <a href="http://<%=trackerAddress%>/jobtracker.jsp"><%= trackerName %></a> Hadoop Map/Reduce
+<h1> <a href="<%=trackerUrl%>/jobtracker.jsp"><%= trackerName %></a> Hadoop Map/Reduce
      <a href="jobhistoryhome.jsp">History Viewer</a></h1>
 <hr>
 <%

+ 18 - 4
src/webapps/history/legacyjobhistory.jsp

@@ -1,9 +1,11 @@
 <%@ page
   contentType="text/html; charset=UTF-8"
   import="java.io.*"
+  import="java.net.*"
   import="java.util.*"
   import="org.apache.hadoop.mapred.*"
   import="org.apache.hadoop.util.*"
+  import="org.apache.hadoop.net.*"
   import="org.apache.hadoop.fs.*"
   import="javax.servlet.jsp.*"
   import="java.text.SimpleDateFormat"
@@ -11,9 +13,21 @@
   import="org.apache.hadoop.mapred.*"
 %>
 <%	
-    JobConf jobConf = (JobConf)application.getAttribute("jobConf");
-    String trackerAddress = jobConf.get("mapred.job.tracker.http.address");
-    String trackerName = StringUtils.simpleHostname(trackerAddress);
+  JobConf jobConf = (JobConf) application.getAttribute("jobConf");
+  String trackerUrl;
+  String trackerName;
+
+  String trackerAddress = jobConf.get("mapred.job.tracker.http.address");
+  InetSocketAddress infoSocAddr = NetUtils.createSocketAddr(trackerAddress);
+  if (JobHistoryServer.isEmbedded(jobConf)) {
+    trackerName = StringUtils.simpleHostname(InetAddress.
+      getLocalHost().getCanonicalHostName());
+    trackerName = StringUtils.getHostname();
+    trackerUrl = "";
+  } else {
+    trackerUrl = "http://" + trackerAddress;
+    trackerName = StringUtils.simpleHostname(infoSocAddr.getHostName());
+  }
 %>
 <%!	
   private static SimpleDateFormat dateFormat = 
@@ -42,7 +56,7 @@ window.location.href = url;
 <link rel="stylesheet" type="text/css" href="/static/hadoop.css">
 </head>
 <body>
-<h1> <a href="http://<%=trackerAddress%>/jobtracker.jsp"><%= trackerName %></a> Hadoop Map/Reduce
+<h1> <a href="<%=trackerUrl%>/jobtracker.jsp"><%= trackerName %></a> Hadoop Map/Reduce
      <a href="jobhistoryhome.jsp">History Viewer</a></h1>
 <hr>
 <%