Explorar el Código

[jb] Avoid exeception when building log job links with a terminal dot

Fix the error in the logs:
NoReverseMatch: Reverse for 'jobbrowser.views.single_job' with arguments '()'
and keyword arguments '{'job': u'job_201306261521_0058.'}' not found. 1 pattern(s) tried: ['jobbrowser/jobs/(?P<job>\\w+)$']

Happens on Pig app log display.
Romain Rigaux hace 10 años
padre
commit
c4a3aa8

+ 2 - 2
apps/jobbrowser/src/jobbrowser/models.py

@@ -569,13 +569,13 @@ class LinkJobLogs(object):
   @classmethod
   def _make_mr_links(cls, log):
     escaped_logs = escape(log)
-    return re.sub('(job_[0-9_]+(/|\.)?)', LinkJobLogs._replace_mr_link, escaped_logs)
+    return re.sub('(job_[0-9]{12}_[0-9]+)', LinkJobLogs._replace_mr_link, escaped_logs)
 
   @classmethod
   def _make_links(cls, log):
     escaped_logs = escape(log)
     hdfs_links = re.sub('((?<= |;)/|hdfs://)[^ <&\t;,\n]+', LinkJobLogs._replace_hdfs_link, escaped_logs)
-    return re.sub('(job_[0-9_]+(/|\.)?)', LinkJobLogs._replace_mr_link, hdfs_links)
+    return re.sub('(job_[0-9]{12}_[0-9]+)', LinkJobLogs._replace_mr_link, hdfs_links)
 
   @classmethod
   def _replace_hdfs_link(self, match):

+ 6 - 2
apps/jobbrowser/src/jobbrowser/tests.py

@@ -832,10 +832,14 @@ def test_make_log_links():
       LinkJobLogs._make_links('- More information at: http://localhost:50030/jobdetails.jsp?jobid=job_201306261521_0058')
   )
   assert_equal(
-      """ Logging error messages to: job_201307091553_0028/attempt_201307091553_002""",
+      """ Logging error messages to: <a href="/jobbrowser/jobs/job_201307091553_0028" target="_blank">job_201307091553_0028</a>/attempt_201307091553_002""",
       LinkJobLogs._make_links(' Logging error messages to: job_201307091553_0028/attempt_201307091553_002')
   )
   assert_equal(
-      """ pig-job_201307091553_0028.log""",
+      """ pig-<a href="/jobbrowser/jobs/job_201307091553_0028" target="_blank">job_201307091553_0028</a>.log""",
       LinkJobLogs._make_links(' pig-job_201307091553_0028.log')
   )
+  assert_equal(
+      """MapReduceLauncher  - HadoopJobId: <a href="/jobbrowser/jobs/job_201306261521_0058" target="_blank">job_201306261521_0058</a>. Look at the UI""",
+      LinkJobLogs._make_links('MapReduceLauncher  - HadoopJobId: job_201306261521_0058. Look at the UI')
+  )