Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 bb66b4be1 -> 2bdc93db2


AMBARI-19436. Need ability to upload a file in HDFS browser. (Padma Priya via 
pallavkul)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2bdc93db
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2bdc93db
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2bdc93db

Branch: refs/heads/branch-2.5
Commit: 2bdc93db2532a9e624d64d6d10359f69a555c7db
Parents: bb66b4b
Author: pallavkul <[email protected]>
Authored: Tue Jan 10 20:42:21 2017 +0530
Committer: pallavkul <[email protected]>
Committed: Tue Jan 10 20:44:17 2017 +0530

----------------------------------------------------------------------
 .../resources/ui/app/components/file-upload.js  | 19 +++++++------
 .../resources/ui/app/components/hdfs-browser.js |  2 ++
 .../ui/app/services/hdfs-file-uploader.js       | 20 ++++++++++++++
 .../app/templates/components/hdfs-browser.hbs   | 13 ++++-----
 .../addon/components/directory-viewer.js        | 17 ++++++------
 .../unit/services/hdfs-file-uploader-test.js    | 28 ++++++++++++++++++++
 6 files changed, 77 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2bdc93db/contrib/views/wfmanager/src/main/resources/ui/app/components/file-upload.js
----------------------------------------------------------------------
diff --git 
a/contrib/views/wfmanager/src/main/resources/ui/app/components/file-upload.js 
b/contrib/views/wfmanager/src/main/resources/ui/app/components/file-upload.js
index 5ea37b5..4bfe404 100644
--- 
a/contrib/views/wfmanager/src/main/resources/ui/app/components/file-upload.js
+++ 
b/contrib/views/wfmanager/src/main/resources/ui/app/components/file-upload.js
@@ -19,11 +19,8 @@ import Ember from 'ember';
 import EmberUploader from 'ember-uploader';
 export default EmberUploader.FileField.extend({
   filesDidChange: function(files) {
-    if (!this.get("selectedPath") || this.get("selectedPath")===""){
-      this.sendAction("uploadValidation","No file selected");
-    }
     const uploader = EmberUploader.Uploader.create({
-      url: Ember.ENV.FILE_API_URL+"/upload",
+      url: `${Ember.ENV.FILE_API_URL}/upload`,
       method: 'PUT',
       ajaxSettings: {
         headers: {
@@ -35,14 +32,20 @@ export default EmberUploader.FileField.extend({
       this.sendAction("uploadProgress",e);
     });
     uploader.on('didUpload', (e) => {
-      this.sendAction("uploadSuccess",e);
+      this.sendAction("uploadSuccess", e);
     });
     uploader.on('didError', (jqXHR, textStatus, errorThrown) => {
-
-      this.sendAction("uploadFailure",textStatus,errorThrown);
+      var message = jqXHR.responseJSON.message.substr(0, 
jqXHR.responseJSON.message.indexOf("\n"));
+      if(message.indexOf("already exists") > 0){
+        message = `File ${message.substr(0, message.indexOf("for"))} exists`;
+      }else if(message.indexOf('Permission denied') >= 0){
+        message = `Permission Denied.`;
+      }
+      this.sendAction("uploadFailure", message, errorThrown);
     });
     if (!Ember.isEmpty(files)) {
-      uploader.upload(files[0], { path: "/user/admin/"});
+      var path = Ember.isEmpty(this.get('selectedPath')) ? '/' : 
this.get('selectedPath');
+      uploader.upload(files[0], { path: path});
     }
   }
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/2bdc93db/contrib/views/wfmanager/src/main/resources/ui/app/components/hdfs-browser.js
----------------------------------------------------------------------
diff --git 
a/contrib/views/wfmanager/src/main/resources/ui/app/components/hdfs-browser.js 
b/contrib/views/wfmanager/src/main/resources/ui/app/components/hdfs-browser.js
index 47e7983..1af9f4d 100644
--- 
a/contrib/views/wfmanager/src/main/resources/ui/app/components/hdfs-browser.js
+++ 
b/contrib/views/wfmanager/src/main/resources/ui/app/components/hdfs-browser.js
@@ -19,6 +19,7 @@ import Ember from 'ember';
 import HdfsViewerConfig from '../utils/hdfsviewer';
 export default Ember.Component.extend({
   config: HdfsViewerConfig.create(),
+  uploaderService : Ember.inject.service('hdfs-file-uploader'),
   initialize:function(){
     var self=this;
     self.$("#filediv").modal("show");
@@ -96,6 +97,7 @@ export default Ember.Component.extend({
       this.set("uploadSelected",false);
     },
     uploadSuccess(e){
+      this.get('uploaderService').trigger('uploadSuccess');
     },
     uploadFailure(textStatus,errorThrown){
       this.showNotification({

http://git-wip-us.apache.org/repos/asf/ambari/blob/2bdc93db/contrib/views/wfmanager/src/main/resources/ui/app/services/hdfs-file-uploader.js
----------------------------------------------------------------------
diff --git 
a/contrib/views/wfmanager/src/main/resources/ui/app/services/hdfs-file-uploader.js
 
b/contrib/views/wfmanager/src/main/resources/ui/app/services/hdfs-file-uploader.js
new file mode 100644
index 0000000..035d9d7
--- /dev/null
+++ 
b/contrib/views/wfmanager/src/main/resources/ui/app/services/hdfs-file-uploader.js
@@ -0,0 +1,20 @@
+/*
+*    Licensed to the Apache Software Foundation (ASF) under one or more
+*    contributor license agreements.  See the NOTICE file distributed with
+*    this work for additional information regarding copyright ownership.
+*    The ASF licenses this file to You under the Apache License, Version 2.0
+*    (the "License"); you may not use this file except in compliance with
+*    the License.  You may obtain a copy of the License at
+*
+*        http://www.apache.org/licenses/LICENSE-2.0
+*
+*    Unless required by applicable law or agreed to in writing, software
+*    distributed under the License is distributed on an "AS IS" BASIS,
+*    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*    See the License for the specific language governing permissions and
+*    limitations under the License.
+*/
+import Ember from 'ember';
+
+export default Ember.Service.extend(Ember.Evented, {
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/2bdc93db/contrib/views/wfmanager/src/main/resources/ui/app/templates/components/hdfs-browser.hbs
----------------------------------------------------------------------
diff --git 
a/contrib/views/wfmanager/src/main/resources/ui/app/templates/components/hdfs-browser.hbs
 
b/contrib/views/wfmanager/src/main/resources/ui/app/templates/components/hdfs-browser.hbs
index 4f9b4ce..b8da4a0 100644
--- 
a/contrib/views/wfmanager/src/main/resources/ui/app/templates/components/hdfs-browser.hbs
+++ 
b/contrib/views/wfmanager/src/main/resources/ui/app/templates/components/hdfs-browser.hbs
@@ -29,11 +29,11 @@
           <div class="row">
              <div class="col-xs-12">
                 <div class="pull-right">
-                  <span class="">
+                  <!-- <span class="">
                       <button type="button" class="btn btn-default" {{action 
"createFolder"}} disabled={{isFilePathInvalid}}>Create Folder</button>
-                  </span>
+                  </span> -->
                   {{#unless uploadSelected}}
-                    <span class="hide">
+                    <span>
                       <button type="button" class="btn btn-default" {{action 
"uploadSelect"}} disabled={{isFilePathInvalid}}>Upload File</button>
                     </span>
                   {{/unless}}
@@ -61,11 +61,12 @@
 
             {{/if}}
           <div class="directory-viewer-wrap hdfs-browse">
-            {{directory-viewer
+            {{#directory-viewer
               config=config
               errorAction="viewerError"
               pathSelectAction="viewerSelectedPath"
-            }}
+              uploaderService=uploaderService
+            }}{{/directory-viewer}}
           </div>
         </div>
       </div>
@@ -79,8 +80,8 @@
                 {{input name="selectedPath" class="form-control" type="text" 
value=selectedPath}}
               </div>
               <div class="col-xs-4">
-                <button type="button" class="btn btn-primary" {{action 
"selectFile"}}>Select</button>
                 <button type="button" class="btn btn-default" 
data-dismiss="modal">Close</button>
+                <button type="button" class="btn btn-primary" {{action 
"selectFile"}}>Select</button>
               </div>
         </div>
     </div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/2bdc93db/contrib/views/wfmanager/src/main/resources/ui/externaladdons/hdfs-directory-viewer/addon/components/directory-viewer.js
----------------------------------------------------------------------
diff --git 
a/contrib/views/wfmanager/src/main/resources/ui/externaladdons/hdfs-directory-viewer/addon/components/directory-viewer.js
 
b/contrib/views/wfmanager/src/main/resources/ui/externaladdons/hdfs-directory-viewer/addon/components/directory-viewer.js
index 991d122..65746e8 100644
--- 
a/contrib/views/wfmanager/src/main/resources/ui/externaladdons/hdfs-directory-viewer/addon/components/directory-viewer.js
+++ 
b/contrib/views/wfmanager/src/main/resources/ui/externaladdons/hdfs-directory-viewer/addon/components/directory-viewer.js
@@ -31,6 +31,9 @@ export default Ember.Component.extend({
   }),
 
   startFetch: Ember.on('didInitAttrs', function() {
+    this.get('uploaderService').on('uploadSuccess', function(){
+      this.fetchData();
+    }.bind(this));
     this.fetchData();
   }),
 
@@ -95,24 +98,22 @@ export default Ember.Component.extend({
   },
 
   insertPathToTreeData(treeData, paths, pathSegment) {
-    let firstPathSegment;
-    if (pathSegment.indexOf('/') !== -1) {
-      firstPathSegment = pathSegment.substring(0, pathSegment.indexOf('/'));
-    } else {
-      firstPathSegment = pathSegment;
-    }
-
+    let isFinalSegment = pathSegment.indexOf('/') === -1? true: false;
+    let firstPathSegment = isFinalSegment? pathSegment: 
pathSegment.substring(0, pathSegment.indexOf('/'));
     if(treeData.length === 0) {
       treeData.pushObjects(paths);
     } else {
       treeData.forEach((entry) => {
         entry.state = {};
         if (entry.pathSegment === firstPathSegment) {
+          let nodesLength = entry.nodes.length;
           entry.state.expanded = true;
-          if(entry.nodes.length === 0) {
+          if(nodesLength === 0) {
             paths.forEach((pathEntry) => {
               entry.nodes.push(pathEntry);
             });
+          } else if(nodesLength > 0 && nodesLength !== paths.length && 
isFinalSegment){
+            entry.nodes = paths;
           } else {
             this.insertPathToTreeData(entry.nodes, paths, 
pathSegment.substring(pathSegment.indexOf('/') + 1));
           }

http://git-wip-us.apache.org/repos/asf/ambari/blob/2bdc93db/contrib/views/wfmanager/src/main/resources/ui/tests/unit/services/hdfs-file-uploader-test.js
----------------------------------------------------------------------
diff --git 
a/contrib/views/wfmanager/src/main/resources/ui/tests/unit/services/hdfs-file-uploader-test.js
 
b/contrib/views/wfmanager/src/main/resources/ui/tests/unit/services/hdfs-file-uploader-test.js
new file mode 100644
index 0000000..ac027e1
--- /dev/null
+++ 
b/contrib/views/wfmanager/src/main/resources/ui/tests/unit/services/hdfs-file-uploader-test.js
@@ -0,0 +1,28 @@
+/*
+*    Licensed to the Apache Software Foundation (ASF) under one or more
+*    contributor license agreements.  See the NOTICE file distributed with
+*    this work for additional information regarding copyright ownership.
+*    The ASF licenses this file to You under the Apache License, Version 2.0
+*    (the "License"); you may not use this file except in compliance with
+*    the License.  You may obtain a copy of the License at
+*
+*        http://www.apache.org/licenses/LICENSE-2.0
+*
+*    Unless required by applicable law or agreed to in writing, software
+*    distributed under the License is distributed on an "AS IS" BASIS,
+*    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*    See the License for the specific language governing permissions and
+*    limitations under the License.
+*/
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('service:hdfs-file-uploader', 'Unit | Service | hdfs file uploader', 
{
+  // Specify the other units that are required for this test.
+  // needs: ['service:foo']
+});
+
+// Replace this with your real tests.
+test('it exists', function(assert) {
+  let service = this.subject();
+  assert.ok(service);
+});

Reply via email to