ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pallav...@apache.org
Subject ambari git commit: AMBARI-20357. [Hive2] JS error in udf delete (pallavkul)
Date Wed, 08 Mar 2017 15:21:08 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk ece0736c0 -> fd07c16dc


AMBARI-20357. [Hive2] JS error in udf delete (pallavkul)


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

Branch: refs/heads/trunk
Commit: fd07c16dcab7f89cadae19b9df72da174ffe89d5
Parents: ece0736
Author: pallavkul <pallav.kul@gmail.com>
Authored: Wed Mar 8 20:50:09 2017 +0530
Committer: pallavkul <pallav.kul@gmail.com>
Committed: Wed Mar 8 20:50:09 2017 +0530

----------------------------------------------------------------------
 .../resources/ui/app/components/udf-item.js     | 148 +++++++++++++------
 .../resources/ui/app/routes/queries/query.js    |   4 +-
 .../src/main/resources/ui/app/routes/udfs.js    |  18 ++-
 .../main/resources/ui/app/routes/udfs/new.js    | 138 ++++++++++-------
 .../resources/ui/app/services/auto-refresh.js   |   2 +-
 .../ui/app/templates/components/udf-item.hbs    |  26 ++--
 .../main/resources/ui/app/templates/udfs.hbs    |   3 +
 7 files changed, 221 insertions(+), 118 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/fd07c16d/contrib/views/hive20/src/main/resources/ui/app/components/udf-item.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive20/src/main/resources/ui/app/components/udf-item.js b/contrib/views/hive20/src/main/resources/ui/app/components/udf-item.js
index 44f56e5..3e6e623 100644
--- a/contrib/views/hive20/src/main/resources/ui/app/components/udf-item.js
+++ b/contrib/views/hive20/src/main/resources/ui/app/components/udf-item.js
@@ -17,8 +17,9 @@
  */
 
 import Ember from 'ember';
+import UILoggerMixin from '../mixins/ui-logger';
 
-export default Ember.Component.extend({
+export default Ember.Component.extend(UILoggerMixin, {
 
   store: Ember.inject.service(),
 
@@ -30,10 +31,43 @@ export default Ember.Component.extend({
   showDeleteUdfModal: false,
   expandedValue: null,
   udfId: null,
+  editUdfId: Ember.computed('udf', function () {
+    return this.get('udf.id');
+  }),
+  editUdfName: Ember.computed('udf', function () {
+    return this.get('udf.name');
+  }),
+  editUdfClassName: Ember.computed('udf', function () {
+    return this.get('udf.classname');
+  }),
+  editOwner: Ember.computed('udf', function () {
+    return this.get('udf.owner');
+  }),
+  editFileResource: Ember.computed('udf', function () {
+    return this.get('udf.fileResource');
+  }),
   fileResourceList:[],
   selectedFileResource: null,
   isAddingNewFileResource: false,
 
+  validate(udfName, udfClassName, resourceName, resourcePath){
+    if (Ember.isEmpty(udfName)) {
+      this.get('logger').danger('UDF Name can not be empty.');
+      return false;
+    }
+
+    if (Ember.isEmpty(udfClassName)) {
+      this.get('logger').danger('UDF Class Name can not be empty.');
+      return false;
+    }
+
+    if (Ember.isEmpty(resourceName) || Ember.isEmpty(resourcePath)) {
+      this.get('logger').danger('File Resource can not be empty.');
+      return false;
+    }
+    return true;
+  },
+
   actions: {
     toggleExpandUdf(fileResourceId) {
 
@@ -59,14 +93,30 @@ export default Ember.Component.extend({
         this.set('expandedEdit', true);
         this.set('valueLoading', true);
 
-        this.get('store').find('fileResource', fileResourceId).then((data) => {
-          this.set('udfFileResourceName', data.get('name'));
-          this.set('udfFileResourcePath', data.get('path'));
-        });
+        this.get('store').findAll('file-resource').then((data) => {
+          let fileResourceList = [];
+          data.forEach(x => {
+            let localFileResource = {'id': x.get('id'),
+              'name': x.get('name'),
+              'path': x.get('path'),
+              'owner': x.get('owner')
+            };
+            fileResourceList.push(localFileResource);
+          });
 
+          fileResourceList.filterBy('id', fileResourceId).map((data) => {
+            this.set('udfFileResourceName', data.name);
+            this.set('udfFileResourcePath', data.path);
 
+                    this.get('store').find('udf', udfId).then((data) => {
+                        this.set('editUdfId', udfId);
+                        this.set('editUdfName', data.get('name'));
+                        this.set('editUdfClassName', data.get('classname'));
+                        this.set('editOwner', data.get('owner'));
+                      });
+          });
+        });
         this.send('setFileResource', fileResourceId);
-
       }
     },
 
@@ -75,39 +125,38 @@ export default Ember.Component.extend({
     },
 
     saveUDf(name, classname, udfid, udfFileResourceName, udfFileResourcePath){
-
       let self = this;
-
-      if(!Ember.isEmpty(this.get('selectedFileResource'))){
-        this.get('store').findRecord('udf', udfid).then(function(resultUdf) {
-          resultUdf.set('name', name);
-          resultUdf.set('classname', classname);
-          resultUdf.set('fileResource', self.get('selectedFileResource').id);
-          resultUdf.save();
-          self.set('expandedEdit', false);
-        });
-      } else {
-
-        let resourcePayload = {"name":udfFileResourceName,"path":udfFileResourcePath};
-
-        this.get('udfService').savefileResource(resourcePayload)
-          .then((data) => {
-            console.log('fileResource is', data.fileResource.id);
-            self.get('store').findRecord('udf', udfid).then(function(resultUdf) {
-
-              resultUdf.set('name', name);
-              resultUdf.set('classname', classname);
-              resultUdf.set('fileResource', data.fileResource.id);
-              resultUdf.save();
-              self.set('expandedEdit', false);
-            });
-          }, (error) => {
-            console.log("Error encountered", error);
+      if (this.validate(name, classname, udfFileResourceName, udfFileResourcePath)) {
+        if (!Ember.isEmpty(this.get('selectedFileResource'))) {
+          this.get('store').findRecord('udf', udfid).then(function (resultUdf) {
+            resultUdf.set('name', name);
+            resultUdf.set('classname', classname);
+            resultUdf.set('fileResource', self.get('selectedFileResource').id);
+            resultUdf.save();
+            self.set('expandedEdit', false);
           });
+        }
+        else {
+
+          let resourcePayload = {"name": udfFileResourceName, "path": udfFileResourcePath};
+
+          this.get('udfService').savefileResource(resourcePayload)
+            .then((data) => {
+              console.log('fileResource is', data.fileResource.id);
+              self.get('store').findRecord('udf', udfid).then(function (resultUdf) {
+
+                resultUdf.set('name', name);
+                resultUdf.set('classname', classname);
+                resultUdf.set('fileResource', data.fileResource.id);
+                resultUdf.save();
+                self.set('expandedEdit', false);
+              });
+            }, (error) => {
+              console.log("Error encountered", error);
+            });
+        }
       }
-
       this.set('isAddingNewFileResource', false);
-
     },
 
     showRemoveUdfModal(udfId){
@@ -117,16 +166,7 @@ export default Ember.Component.extend({
     },
 
     removeUdf(){
-      let self = this;
-      this.get('store').find('udf', this.get('udfId')).then(function(resultUdf) {
-        resultUdf.destroyRecord().then(function() {
-          self.send('cancelUdf');
-          self.sendAction('refreshUdfList');
-        }, function(response) {
-          console.log('UDF NOT deleted', response);
-        });
-        return false;
-      });
+      this.sendAction('removeUdf', this.get('udfId') );
     },
 
     cancelUdf(){
@@ -144,10 +184,22 @@ export default Ember.Component.extend({
     },
 
     setFileResource(fileResourceId){
-      let localSelectedFileResource = this.get('fileResourceList').filterBy('id', fileResourceId);
-      this.set('selectedFileResource',localSelectedFileResource[0]);
-    }
+      this.get('store').findAll('file-resource').then((data) => {
+        let fileResourceList = [];
+        data.forEach(x => {
+          let localFileResource = {'id': x.get('id'),
+            'name': x.get('name'),
+            'path': x.get('path'),
+            'owner': x.get('owner')
+          };
+          fileResourceList.push(localFileResource);
+        });
+
+        let localSelectedFileResource =  fileResourceList.filterBy('id', fileResourceId);
+        this.set('selectedFileResource',localSelectedFileResource.get('firstObject'));
+      });
 
+    }
   }
 
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/fd07c16d/contrib/views/hive20/src/main/resources/ui/app/routes/queries/query.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive20/src/main/resources/ui/app/routes/queries/query.js b/contrib/views/hive20/src/main/resources/ui/app/routes/queries/query.js
index 80116da..6b395ac 100644
--- a/contrib/views/hive20/src/main/resources/ui/app/routes/queries/query.js
+++ b/contrib/views/hive20/src/main/resources/ui/app/routes/queries/query.js
@@ -522,7 +522,7 @@ export default Ember.Route.extend(UILoggerMixin, {
       Ember.run.later(() => {
 
       if(this.get('controller.model').get('isQueryDirty')) {
-        this.get('controller.model').set('tabDataToClose', {index:index, id:id})
+        this.get('controller.model').set('tabDataToClose', {index:index, id:id});
         this.send('openWorksheetModal');
       } else {
          this.send('closeWorksheet', index, id);
@@ -627,7 +627,7 @@ export default Ember.Route.extend(UILoggerMixin, {
     closeWorksheetModal(){
       this.get('controller').set('showWorksheetModal', false);
       this.closeWorksheetAfterSave();
-      this.get('controller.model').set('tabDataToClose', null)
+      this.get('controller.model').set('tabDataToClose', null);
   },
 
     expandQueryEdidorPanel(){

http://git-wip-us.apache.org/repos/asf/ambari/blob/fd07c16d/contrib/views/hive20/src/main/resources/ui/app/routes/udfs.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive20/src/main/resources/ui/app/routes/udfs.js b/contrib/views/hive20/src/main/resources/ui/app/routes/udfs.js
index 138e85f..5733d5c 100644
--- a/contrib/views/hive20/src/main/resources/ui/app/routes/udfs.js
+++ b/contrib/views/hive20/src/main/resources/ui/app/routes/udfs.js
@@ -19,6 +19,9 @@
 import Ember from 'ember';
 
 export default Ember.Route.extend({
+
+  showDeleteUdfModal: false,
+
   model() {
     return this.store.findAll('udf').then(udfs => udfs.toArray());
   },
@@ -48,7 +51,6 @@ export default Ember.Route.extend({
   actions:{
 
     refreshUdfList(){
-
       this.get('store').findAll('udf').then((data) => {
         let udfList = [];
         data.forEach(x => {
@@ -65,8 +67,20 @@ export default Ember.Route.extend({
         this.controllerFor('udfs').set('udflist',udfList);
         this.transitionTo('udfs');
       });
+    },
 
-    }
+    removeUdf(udfId){
+      var self = this;
+      let record = this.get('store').peekRecord('udf', udfId );
+      if(record){
+        record.destroyRecord().then(function(){
+          self.send('cancelUdf');
+          self.send('refreshUdfList');
+        })}
+    },
 
+    cancelUdf(){
+      this.set('showDeleteUdfModal', false);
+    }
   }
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/fd07c16d/contrib/views/hive20/src/main/resources/ui/app/routes/udfs/new.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive20/src/main/resources/ui/app/routes/udfs/new.js b/contrib/views/hive20/src/main/resources/ui/app/routes/udfs/new.js
index 84733e8..6207b77 100644
--- a/contrib/views/hive20/src/main/resources/ui/app/routes/udfs/new.js
+++ b/contrib/views/hive20/src/main/resources/ui/app/routes/udfs/new.js
@@ -25,6 +25,26 @@ export default Ember.Route.extend(UILoggerMixin, {
 
   },
 
+  validateUDF(udfName, udfClassName){
+    if (Ember.isEmpty(udfName)) {
+      this.get('logger').danger('UDF Name can not be empty.');
+      return false;
+    }
+    if (Ember.isEmpty(udfClassName)) {
+      this.get('logger').danger('UDF Class Name can not be empty.');
+      return false;
+    }
+    return true;
+  },
+
+  validateFileResource(resourceName, resourcePath){
+    if (Ember.isEmpty(resourceName) || Ember.isEmpty(resourcePath)) {
+      this.get('logger').danger('File Resource can not be empty.');
+      return false;
+    }
+    return true;
+  },
+
   udf: Ember.inject.service(),
   store: Ember.inject.service(),
 
@@ -41,7 +61,7 @@ export default Ember.Route.extend(UILoggerMixin, {
                                 };
         fileResourceList.push(localFileResource);
       });
-      fileResourceList.push({'name':'Add New File Resource', 'action':'addNewFileResource'})
+      fileResourceList.push({'name':'Add New File Resource', 'action':'addNewFileResource'});
       controller.set('fileResourceList', fileResourceList);
 
     });
@@ -60,52 +80,19 @@ export default Ember.Route.extend(UILoggerMixin, {
       this.get('controller').set('udfName', udfName);
       this.get('controller').set('udfClassName', udfClassName);
 
-      if(!Ember.isEmpty( this.get('controller').get('resourceId'))){
 
-        let newUDF = this.get('store').createRecord('udf',
-          {name:udfName,
-           classname:udfClassName,
-           fileResource: this.get('controller').get('resourceId')
-          });
 
 
-        newUDF.save().then((data) => {
-          console.log('udf saved');
-
-          this.get('store').findAll('udf').then((data) => {
-            let udfList = [];
-            data.forEach(x => {
-              let localUdf = {
-                'id': x.get('id'),
-                'name': x.get('name'),
-                'classname': x.get('classname'),
-                'fileResource': x.get('fileResource'),
-                'owner': x.get('owner')
-              };
-              udfList.pushObject(localUdf);
-            });
-
-            this.controllerFor('udfs').set('udflist',udfList);
-            this.transitionTo('udfs');
-          })
+      if(!Ember.isEmpty( this.get('controller').get('resourceId'))){
 
-        });
+        if (this.validateUDF(udfName, udfClassName)) {
 
-      } else {
-
-        let resourcePayload = {"name":resourceName,"path":resourcePath};
-
-        var newFileResource = this.get('store').createRecord('file-resource',
-          {name:resourceName,
-            path:resourcePath
-          });
 
-        newFileResource.save().then((data) => {
-          console.log('fileResource is', data.get('id'));
           let newUDF = this.get('store').createRecord('udf',
-            {name:udfName,
-              classname:udfClassName,
-              fileResource: data.get('id')
+            {
+              name: udfName,
+              classname: udfClassName,
+              fileResource: this.get('controller').get('resourceId')
             });
 
           newUDF.save().then((data) => {
@@ -124,20 +111,66 @@ export default Ember.Route.extend(UILoggerMixin, {
                 udfList.pushObject(localUdf);
               });
 
-              this.controllerFor('udfs').set('udflist',udfList);
+              this.controllerFor('udfs').set('udflist', udfList);
               this.transitionTo('udfs');
-            })
-          })
-          .catch((error) => {
-            this.get('logger').danger('Failed to create UDF.', this.extractError(error));
-            this.transitionTo('udfs');
+            });
 
           });
-        })
-        .catch((error) => {
-          this.get('logger').danger('Failed to create File Resource.', this.extractError(error));
-          this.transitionTo('udfs');
-        });
+
+        }
+
+      } else {
+
+        let resourcePayload = {"name":resourceName,"path":resourcePath};
+
+        var newFileResource = this.get('store').createRecord('file-resource',
+          {name:resourceName,
+            path:resourcePath
+          });
+
+
+        if (this.validateFileResource(resourceName, resourcePath) && this.validateUDF(udfName,
udfClassName)) {
+
+          newFileResource.save().then((data) => {
+              console.log('fileResource is', data.get('id'));
+              let newUDF = this.get('store').createRecord('udf',
+                {name:udfName,
+                  classname:udfClassName,
+                  fileResource: data.get('id')
+                });
+
+              newUDF.save().then((data) => {
+                  console.log('udf saved');
+
+                  this.get('store').findAll('udf').then((data) => {
+                    let udfList = [];
+                    data.forEach(x => {
+                      let localUdf = {
+                        'id': x.get('id'),
+                        'name': x.get('name'),
+                        'classname': x.get('classname'),
+                        'fileResource': x.get('fileResource'),
+                        'owner': x.get('owner')
+                      };
+                      udfList.pushObject(localUdf);
+                    });
+
+                    this.controllerFor('udfs').set('udflist',udfList);
+                    this.transitionTo('udfs');
+                  });
+                })
+                .catch((error) => {
+                  this.get('logger').danger('Failed to create UDF.', this.extractError(error));
+                  this.transitionTo('udfs');
+
+                });
+            })
+            .catch((error) => {
+              this.get('logger').danger('Failed to create File Resource.', this.extractError(error));
+              this.transitionTo('udfs');
+            });
+
+        }
 
       }
     },
@@ -153,10 +186,11 @@ export default Ember.Route.extend(UILoggerMixin, {
 
     handleFileResourceChange(filter){
       console.log('filter', filter);
-      if(filter.action == "addNewFileResource"){
+      if(filter.action === "addNewFileResource"){
         this.get('controller').set('isAddingNewFileResource', true);
         this.get('controller').set('resourceName','');
         this.get('controller').set('resourcePath','');
+        this.get('controller').set('resourceId', null);
         this.get('controller').set('selectedFileResource',null);
 
       }else {

http://git-wip-us.apache.org/repos/asf/ambari/blob/fd07c16d/contrib/views/hive20/src/main/resources/ui/app/services/auto-refresh.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive20/src/main/resources/ui/app/services/auto-refresh.js b/contrib/views/hive20/src/main/resources/ui/app/services/auto-refresh.js
index 2e8ec62..b3276e7 100644
--- a/contrib/views/hive20/src/main/resources/ui/app/services/auto-refresh.js
+++ b/contrib/views/hive20/src/main/resources/ui/app/services/auto-refresh.js
@@ -50,7 +50,7 @@ export default Ember.Service.extend({
       databaseRefreshStartingCallback();
       let oldDatabases = this.get('store').peekAll('database').mapBy('name');
       this.get('store').query('database', {}).then((data) => {
-        let deletedDbCount = 0
+        let deletedDbCount = 0;
         let newDatabases = data.mapBy('name');
         oldDatabases.forEach((oldDB) => {
           if (!newDatabases.contains(oldDB)) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/fd07c16d/contrib/views/hive20/src/main/resources/ui/app/templates/components/udf-item.hbs
----------------------------------------------------------------------
diff --git a/contrib/views/hive20/src/main/resources/ui/app/templates/components/udf-item.hbs
b/contrib/views/hive20/src/main/resources/ui/app/templates/components/udf-item.hbs
index fec48fb..929b91a 100644
--- a/contrib/views/hive20/src/main/resources/ui/app/templates/components/udf-item.hbs
+++ b/contrib/views/hive20/src/main/resources/ui/app/templates/components/udf-item.hbs
@@ -39,19 +39,19 @@
 
 {{#if expandedEdit}}
   {{udf-edit
-  udfid=udf.id
-  name=udf.name
-  classname=udf.classname
-  owner=udf.owner
-  fileResource=udf.fileResource
-  udfFileResourceName=udfFileResourceName
-  udfFileResourcePath=udfFileResourcePath
-  fileResourceList=fileResourceList
-  selectedFileResource=selectedFileResource
-  isAddingNewFileResource=isAddingNewFileResource
-  handleResourceChange='handleResourceChange'
-  cancelEditUdf='cancelEditUdf'
-  saveUDf='saveUDf'
+    udfid=editUdfId
+    name=editUdfName
+    classname=editUdfClassName
+    owner=editOwner
+    fileResource=editFileResource
+    udfFileResourceName=udfFileResourceName
+    udfFileResourcePath=udfFileResourcePath
+    fileResourceList=fileResourceList
+    selectedFileResource=selectedFileResource
+    isAddingNewFileResource=isAddingNewFileResource
+    handleResourceChange='handleResourceChange'
+    cancelEditUdf='cancelEditUdf'
+    saveUDf='saveUDf'
   }}
 {{/if}}
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/fd07c16d/contrib/views/hive20/src/main/resources/ui/app/templates/udfs.hbs
----------------------------------------------------------------------
diff --git a/contrib/views/hive20/src/main/resources/ui/app/templates/udfs.hbs b/contrib/views/hive20/src/main/resources/ui/app/templates/udfs.hbs
index ef6a01c..ffb824e 100644
--- a/contrib/views/hive20/src/main/resources/ui/app/templates/udfs.hbs
+++ b/contrib/views/hive20/src/main/resources/ui/app/templates/udfs.hbs
@@ -35,7 +35,10 @@
           {{udf-item
           udf=udf
           fileResourceList=fileResourceList
+          showDeleteUdfModal=showDeleteUdfModal
           refreshUdfList='refreshUdfList'
+          removeUdf='removeUdf'
+          cancelUdf='cancelUdf'
           }}
         {{/each}}
       </tbody>


Mime
View raw message