Browse Source

HUE-2496 [fb] API to fetch the content summary of a path

e.g.
http://127.0.0.1:8000/filebrowser/content_summary=/user/hive/warehouse/sample_07
{"spaceConsumed": 46055, "quota": -1, "spaceQuota": -1, "length": 46055, "directoryCount": 1, "fileCount": 1}
Romain Rigaux 10 years ago
parent
commit
de7a034

+ 1 - 0
apps/filebrowser/src/filebrowser/urls.py

@@ -28,6 +28,7 @@ urlpatterns = patterns('filebrowser.views',
   url(r'^listdir=(?P<path>.*)$', 'listdir', name='listdir'),
   url(r'^listdir=(?P<path>.*)$', 'listdir', name='listdir'),
   url(r'^display=(?P<path>.*)$', 'display', name='display'),
   url(r'^display=(?P<path>.*)$', 'display', name='display'),
   url(r'^stat=(?P<path>.*)$', 'stat', name='stat'),
   url(r'^stat=(?P<path>.*)$', 'stat', name='stat'),
+  url(r'^content_summary=(?P<path>.*)$', 'content_summary', name='content_summary'),
   url(r'^download=(?P<path>.*)$', 'download', name='download'),
   url(r'^download=(?P<path>.*)$', 'download', name='download'),
   url(r'^status$', 'status', name='status'),
   url(r'^status$', 'status', name='status'),
   url(r'^home_relative_view=(?P<path>.*)$', 'home_relative_view', name='home_relative_view'),
   url(r'^home_relative_view=(?P<path>.*)$', 'home_relative_view', name='home_relative_view'),

+ 7 - 0
apps/filebrowser/src/filebrowser/views.py

@@ -509,6 +509,13 @@ def stat(request, path):
     return JsonResponse(_massage_stats(request, stats))
     return JsonResponse(_massage_stats(request, stats))
 
 
 
 
+def content_summary(request, path):
+    if not request.fs.exists(path):
+        raise Http404(_("File not found: %(path)s") % {'path': escape(path)})
+    stats = request.fs.get_content_summary(path)
+    return JsonResponse(stats.summary)
+
+
 def display(request, path):
 def display(request, path):
     """
     """
     Implements displaying part of a file.
     Implements displaying part of a file.

+ 2 - 0
desktop/libs/hadoop/src/hadoop/fs/webhdfs_types.py

@@ -84,6 +84,8 @@ class WebHdfsContentSummary(object):
   Content summary info on a directory
   Content summary info on a directory
   """
   """
   def __init__(self, summary):
   def __init__(self, summary):
+    self.summary = summary
+
     for k, v in summary.iteritems():
     for k, v in summary.iteritems():
       setattr(self, k, v)
       setattr(self, k, v)