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/6631ad53 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/6631ad53 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/6631ad53 Branch: refs/heads/branch-dev-logsearch Commit: 6631ad53609da987e716bc08c04ded44986a7b77 Parents: a307ba7 Author: pallavkul <pallav....@gmail.com> Authored: Wed Mar 8 22:57:02 2017 +0530 Committer: pallavkul <pallav....@gmail.com> Committed: Wed Mar 8 23:00:44 2017 +0530 ---------------------------------------------------------------------- .../resources/ui/app/components/udf-item.js | 150 +++++++++++++------ .../resources/ui/app/routes/queries/query.js | 4 +- .../src/main/resources/ui/app/routes/udfs.js | 4 +- .../main/resources/ui/app/routes/udfs/new.js | 141 ++++++++++------- .../resources/ui/app/services/auto-refresh.js | 2 +- .../ui/app/templates/components/udf-item.hbs | 26 ++-- 6 files changed, 207 insertions(+), 120 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/6631ad53/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..6005444 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,13 @@ export default Ember.Component.extend({ }, removeUdf(){ - let self = this; - this.get('store').find('udf', this.get('udfId')).then(function(resultUdf) { - resultUdf.destroyRecord().then(function() { + var self = this; + let record = this.get('store').peekRecord('udf', this.get('udfId') ); + if(record){ + record.destroyRecord().then(function(){ self.send('cancelUdf'); self.sendAction('refreshUdfList'); - }, function(response) { - console.log('UDF NOT deleted', response); - }); - return false; - }); + })} }, cancelUdf(){ @@ -144,10 +190,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/6631ad53/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/6631ad53/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..68e06a9 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,7 @@ import Ember from 'ember'; export default Ember.Route.extend({ + model() { return this.store.findAll('udf').then(udfs => udfs.toArray()); }, @@ -48,7 +49,6 @@ export default Ember.Route.extend({ actions:{ refreshUdfList(){ - this.get('store').findAll('udf').then((data) => { let udfList = []; data.forEach(x => { @@ -65,8 +65,6 @@ export default Ember.Route.extend({ this.controllerFor('udfs').set('udflist',udfList); this.transitionTo('udfs'); }); - } - } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/6631ad53/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..348887b 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,13 +61,13 @@ 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); - }); controller.set('isAddingNewFileResource', false); controller.set('selectedFileResource',null); + controller.set('resourceId', null); }, @@ -62,50 +82,14 @@ export default Ember.Route.extend(UILoggerMixin, { 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') - }); - + if (this.validateUDF(udfName, udfClassName)) { - 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'); - }) - - }); - - } 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 +108,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'); + }); + + }); + + } + + } else { + + let resourcePayload = {"name":resourceName,"path":resourcePath}; + var newFileResource = this.get('store').createRecord('file-resource', + {name:resourceName, + path:resourcePath }); - }) - .catch((error) => { - this.get('logger').danger('Failed to create File Resource.', this.extractError(error)); - this.transitionTo('udfs'); - }); + + + 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 +183,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/6631ad53/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/6631ad53/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}}