Browse Source

[HUE-658] [fb] Hue should display hadoop fs errors in a popup and not in a 500

Display any browsing related fs error in a popup.
Romain Rigaux 13 years ago
parent
commit
3e77926ddd

+ 3 - 2
apps/filebrowser/src/filebrowser/views.py

@@ -46,6 +46,7 @@ from filebrowser.lib import xxd
 from filebrowser.forms import RenameForm, UploadForm, MkDirForm, RmDirForm, RmTreeForm,\
     RemoveForm, ChmodForm, ChownForm, EditorForm
 from hadoop.fs.hadoopfs import Hdfs
+from hadoop.fs.exceptions import WebHdfsException
 
 
 DEFAULT_CHUNK_SIZE_BYTES = 1024 * 4 # 4KB
@@ -115,8 +116,8 @@ def view(request, path):
             return listdir(request, path, False)
         else:
             return display(request, path)
-    except IOError:
-        raise Http404("File not found: %s" % escape(path))
+    except (IOError, WebHdfsException), e:
+        raise PopupException("Cannot access: %s" % escape(path), detail=e)
 
 
 def edit(request, path, form=None):

+ 22 - 0
apps/filebrowser/src/filebrowser/views_test.py

@@ -280,6 +280,28 @@ def test_view_i18n():
       LOG.error('Failed to cleanup test directory: %s' % (ex,))
 
 
+@attr('requires_hadoop')
+def test_view_access():
+  cluster = pseudo_hdfs4.shared_cluster()
+  NO_PERM_DIR = u'/test-no-perm'
+
+  try:
+    c = make_logged_in_client()
+    cluster.fs.setuser(cluster.superuser)
+    cluster.fs.mkdir(NO_PERM_DIR, mode='700')
+
+    response = c.get('/filebrowser/view/test-no-perm')
+    assert_true('Cannot access' in response.context['message'])
+
+    response = c.get('/filebrowser/view/test-does-not-exist')
+    assert_true('Cannot access' in response.context['message'])
+  finally:
+    try:
+      cluster.fs.rmtree(NO_PERM_DIR)
+    except:
+      pass      # Don't let cleanup errors mask earlier failures
+
+
 def view_helper(cluster, encoding, content):
   """
   Write the content in the given encoding directly into the filesystem.