浏览代码

HDFS-8678. Bring back the feature to view chunks of files in the HDFS file browser. Contributed by Ivo Udelsmann.

Ravi Prakash 8 年之前
父节点
当前提交
625df87c7b

+ 11 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.html

@@ -57,8 +57,17 @@
 	    <h4 class="modal-title" id="file-info-title">File information</h4>
 	    <h4 class="modal-title" id="file-info-title">File information</h4>
 	  </div>
 	  </div>
 	  <div class="modal-body" id="file-info-body">
 	  <div class="modal-body" id="file-info-body">
-	    <a id="file-info-download">Download</a>
-        <!--<a id="file-info-preview" style="cursor:pointer">Tail the file (last 32K)</a>-->
+	    <div class=row>
+              <span class="col-xs-4">
+                <a id="file-info-download">Download</a>
+              </span>
+              <span class="col-xs-4">
+                <a id="file-info-preview-head" style="cursor:pointer">Head the file (first 32K)</a>
+              </span>
+              <span class="col-xs-4">
+                <a id="file-info-preview-tail" style="cursor:pointer">Tail the file (last 32K)</a>
+	      </span>
+	    </div>
 	    <hr />
 	    <hr />
 	    <div class="panel panel-success" id="file-info-blockinfo-panel">
 	    <div class="panel panel-success" id="file-info-blockinfo-panel">
 	      <div class="panel-heading">
 	      <div class="panel-heading">

+ 32 - 5
hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js

@@ -192,13 +192,40 @@
       var download_url = '/webhdfs/v1' + abs_path + '?op=OPEN';
       var download_url = '/webhdfs/v1' + abs_path + '?op=OPEN';
 
 
       $('#file-info-download').attr('href', download_url);
       $('#file-info-download').attr('href', download_url);
-      $('#file-info-preview').click(function() {
+
+      var processPreview = function(url) {
+        url += "&noredirect=true";
+        $.ajax({
+          type: 'GET',
+          url: url,
+          processData: false,
+          crossDomain: true
+        }).done(function(data) {
+          url = data.Location;
+          $.ajax({
+            type: 'GET',
+            url: url,
+            processData: false,
+            crossDomain: true
+          }).complete(function(data) {
+            $('#file-info-preview-body').val(data.responseText);
+            $('#file-info-tail').show();
+          }).error(function(jqXHR, textStatus, errorThrown) {
+            show_err_msg("Couldn't preview the file. " + errorThrown);
+          });
+        }).error(function(jqXHR, textStatus, errorThrown) {
+          show_err_msg("Couldn't find datanode to read file from. " + errorThrown);
+        });
+      }
+
+      $('#file-info-preview-tail').click(function() {
         var offset = d.fileLength - TAIL_CHUNK_SIZE;
         var offset = d.fileLength - TAIL_CHUNK_SIZE;
         var url = offset > 0 ? download_url + '&offset=' + offset : download_url;
         var url = offset > 0 ? download_url + '&offset=' + offset : download_url;
-        $.get(url, function(t) {
-          $('#file-info-preview-body').val(t);
-          $('#file-info-tail').show();
-        }, "text").error(network_error_handler(url));
+        processPreview(url);
+      });
+      $('#file-info-preview-head').click(function() {
+        var url = d.fileLength > TAIL_CHUNK_SIZE ? download_url + '&length=' + TAIL_CHUNK_SIZE : download_url;
+        processPreview(url);
       });
       });
 
 
       if (d.fileLength > 0) {
       if (d.fileLength > 0) {