ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbhowm...@apache.org
Subject ambari git commit: AMBARI-15392 : deleting temporary table and actual table in case of error while uploading table. (Nitiraj Rathore via dipayanb)
Date Mon, 21 Mar 2016 14:51:31 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 eeec0969d -> a3086696b


AMBARI-15392 : deleting temporary table and actual table in case of error while uploading
table. (Nitiraj Rathore via dipayanb)


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

Branch: refs/heads/branch-2.2
Commit: a3086696b4ba7b6cf0bebe308aa1d257b0bb6bfb
Parents: eeec096
Author: Dipayan Bhowmick <dipayan.bhowmick@gmail.com>
Authored: Mon Mar 21 20:21:19 2016 +0530
Committer: Dipayan Bhowmick <dipayan.bhowmick@gmail.com>
Committed: Mon Mar 21 20:21:19 2016 +0530

----------------------------------------------------------------------
 .../ui/hive-web/app/controllers/upload-table.js | 213 +++++++++++++------
 1 file changed, 149 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a3086696/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/upload-table.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/upload-table.js
b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/upload-table.js
index 5085cc5..d883743 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/upload-table.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/upload-table.js
@@ -107,15 +107,19 @@ export default Ember.Controller.extend({
   }.observes('isFirstRowHeader'),
 
   popUploadProgressInfos : function(){
-    this.get('uploadProgressInfos').popObject();
+    var msg = this.get('uploadProgressInfos').popObject();
+   // console.log("popedup message : " + msg);
   },
 
   pushUploadProgressInfos : function(info){
     this.get('uploadProgressInfos').pushObject(info);
+   // console.log("pushed message : " + info);
   },
 
   clearUploadProgressModal : function(){
-    for( var i = 0 ; i < this.get('uploadProgressInfos').length ; i++){
+  //  console.log("inside clearUploadProgressModal this.get('uploadProgressInfos') : " +
this.get('uploadProgressInfos'));
+    var len = this.get('uploadProgressInfos').length;
+    for( var i = 0 ; i < len ; i++){
       this.popUploadProgressInfos();
     }
   },
@@ -138,7 +142,7 @@ export default Ember.Controller.extend({
     this.set('isFirstRowHeader',true);
     this.set('files');
     this.set("firstRow");
-    this.set("selectedDatabase");
+    this.set("selectedDatabase",null);
     this.set("databaseName");
     this.set("filePath");
     this.set('tableName');
@@ -170,8 +174,6 @@ export default Ember.Controller.extend({
     console.log("finding status of job: ", jobId);
     var self = this;
     var fetchJobPromise = this.get('jobService').fetchJobStatus(jobId);
-//      console.log("fetchJobPromise : ", fetchJobPromise);
-
       fetchJobPromise.then(function (data) {
         console.log("waitForJobStatus : data : ", data);
         var status = data.jobStatus;
@@ -205,6 +207,7 @@ export default Ember.Controller.extend({
   generatePreview : function(files){
     var self = this;
     var promise = null;
+    this.waitForGeneratingPreview();
     if(this.get('isLocalUpload')){
       promise = this.uploadForPreview(files);
     }else{
@@ -249,14 +252,52 @@ export default Ember.Controller.extend({
     this.setError(error);
   },
 
+  createTable: function () {
+    console.log("table headers : ", this.get('header'));
+    var headers = this.get('header');
+
+    var selectedDatabase = this.get('selectedDatabase');
+    if (null == selectedDatabase || typeof selectedDatabase === 'undefined') {
+      throw new Error(Ember.I18n.t('hive.errors.emptyDatabase'));
+    }
+
+    this.set('databaseName', this.get('selectedDatabase').get('name'));
+    var databaseName = this.get('databaseName');
+    var tableName = this.get('tableName');
+    var isFirstRowHeader = this.get('isFirstRowHeader');
+    var filetype = this.get("selectedFileType");
+
+    if (null == databaseName || typeof databaseName === 'undefined' || databaseName == '')
{
+      throw new Error(Ember.I18n.t('hive.errors.emptyDatabase'));
+    }
+    if (null == tableName || typeof tableName === 'undefined' || tableName == '') {
+      throw new Error(Ember.I18n.t('hive.errors.emptyTableName'));
+    }
+    if (null == isFirstRowHeader || typeof isFirstRowHeader === 'undefined') {
+      throw new Error(Ember.I18n.t('hive.errors.emptyIsFirstRow'));
+    }
+
+    this.validateColumns();
+
+    return this.get('uploader').createTable({
+      "isFirstRowHeader": isFirstRowHeader,
+      "header": headers,
+      "tableName": tableName,
+      "databaseName": databaseName,
+      "fileType":filetype
+    });
+  },
+
   createActualTable : function(){
     console.log("createActualTable");
+    this.pushUploadProgressInfos("<li> Starting to create Actual table.... </li>");
     return this.createTable();
   },
 
   waitForCreateActualTable: function (jobId) {
     console.log("waitForCreateActualTable");
-    this.pushUploadProgressInfos("<li>Creating actual table.... </li>");
+    this.popUploadProgressInfos();
+    this.pushUploadProgressInfos("<li> Waiting for creation of Actual table.... </li>");
     var self = this;
     var p = new Ember.RSVP.Promise(function (resolve, reject) {
       self.waitForJobStatus(jobId, resolve, reject);
@@ -268,16 +309,19 @@ export default Ember.Controller.extend({
   onCreateActualTableSuccess : function(){
     console.log("onCreateTableSuccess");
     this.popUploadProgressInfos();
-    this.pushUploadProgressInfos("<li> Successfully created actual table. </li>");
+    this.pushUploadProgressInfos("<li> Successfully created Actual table. </li>");
   },
 
   onCreateActualTableFailure : function(error){
     console.log("onCreateActualTableFailure");
+    this.popUploadProgressInfos();
+    this.pushUploadProgressInfos("<li> Failed to create Actual table. </li>");
     this.setError(error);
   },
 
   createTempTable : function(){
     console.log("createTempTable");
+    this.pushUploadProgressInfos("<li> Starting to create Temporary table.... </li>");
     var tempTableName = this.generateTempTableName();
     this.set('tempTableName',tempTableName);
     return this.get('uploader').createTable({
@@ -291,7 +335,8 @@ export default Ember.Controller.extend({
 
   waitForCreateTempTable: function (jobId) {
     console.log("waitForCreateTempTable");
-    this.pushUploadProgressInfos("<li>Creating temporary table.... </li>");
+    this.popUploadProgressInfos();
+    this.pushUploadProgressInfos("<li> Waiting for creation of Temporary table....
</li>");
     var self = this;
     var p = new Ember.RSVP.Promise(function (resolve, reject) {
       self.waitForJobStatus(jobId, resolve, reject);
@@ -303,18 +348,60 @@ export default Ember.Controller.extend({
   onCreateTempTableSuccess : function(){
     console.log("onCreateTempTableSuccess");
     this.popUploadProgressInfos();
-    this.pushUploadProgressInfos("<li> Successfully created temporary table. </li>");
+    this.pushUploadProgressInfos("<li> Successfully created Temporary table. </li>");
   },
 
+  deleteTable : function(databaseName, tableName){
+    console.log("deleting table " + databaseName + "." + tableName);
+
+    return this.get('uploader').deleteTable({
+      "database":  databaseName,
+      "table": tableName
+    });
+  },
+
+  deleteTableOnError : function(databaseName,tableName, tableLabel){
+      //delete table and wait for delete job
+    var self = this;
+    this.pushUploadProgressInfos("<li> Deleting " + tableLabel + " table...  </li>");
+
+    return this.deleteTable(databaseName,tableName).then(function(data){
+      return new Ember.RSVP.Promise(function(resolve,reject){
+        self.waitForJobStatus(data.jobId,resolve,reject);
+      });
+    }).then(function(){
+      self.popUploadProgressInfos();
+      self.pushUploadProgressInfos("<li> Successfully deleted " + tableLabel + " table.
</li>");
+      return Ember.RSVP.Promise.resolve();
+    },function(err){
+      self.popUploadProgressInfos();
+      self.pushUploadProgressInfos("<li> Failed to delete " + tableLabel + " table.
</li>");
+      self.setError(err);
+      return Ember.RSVP.Promise.reject();
+    });
+  },
+
+  rollBackActualTableCreation : function(){
+    return this.deleteTableOnError(this.get("databaseName"),this.get("tableName"),"Actual");
+  },
+
+
   onCreateTempTableFailure : function(error){
     console.log("onCreateTempTableFailure");
     this.setError(error);
+    this.popUploadProgressInfos();
+    this.pushUploadProgressInfos("<li> Failed to create temporary table. </li>");
+    return this.rollBackActualTableCreation().then(function(data){
+      return Ember.RSVP.Promise.reject(error); // always reject for the flow to stop
+    },function(err){
+      return Ember.RSVP.Promise.reject(error); // always reject for the flow to stop
+    });
   },
 
   uploadFile : function(){
     console.log("uploadFile");
+    this.pushUploadProgressInfos("<li> Starting to upload the file .... </li>");
     if( this.get("isLocalUpload")){
-      this.pushUploadProgressInfos("<li>Uploading file .... </li>");
       return this.uploadTable();
     }else{
       return this.uploadTableFromHdfs();
@@ -323,8 +410,9 @@ export default Ember.Controller.extend({
 
   waitForUploadingFile: function (data) {
     console.log("waitForUploadingFile");
+    this.popUploadProgressInfos();
+    this.pushUploadProgressInfos("<li> Waiting for uploading file .... </li>");
     if( data.jobId ){
-      this.pushUploadProgressInfos("<li>Uploading file .... </li>");
       var self = this;
           var p = new Ember.RSVP.Promise(function (resolve, reject) {
             self.waitForJobStatus(data.jobId, resolve, reject);
@@ -341,13 +429,34 @@ export default Ember.Controller.extend({
     this.pushUploadProgressInfos("<li> Successfully uploaded file. </li>");
   },
 
+  rollBackTempTableCreation : function(){
+    var self = this;
+    return this.deleteTableOnError(this.get("databaseName"),this.get("tempTableName"),"Temporary").then(function(data){
+      return self.rollBackActualTableCreation();
+    },function(err){
+      return self.rollBackActualTableCreation();
+    })
+  },
+
   onUploadingFileFailure: function (error) {
     console.log("onUploadingFileFailure");
     this.setError(error);
+    this.popUploadProgressInfos();
+    this.pushUploadProgressInfos("<li> Failed to upload file. </li>");
+    return this.rollBackTempTableCreation().then(function(data){
+      return Ember.RSVP.Promise.reject(error); // always reject for the flow to stop
+    },function(err){
+      return Ember.RSVP.Promise.reject(error); // always reject for the flow to stop
+    });
+  },
+
+  rollBackUploadFile : function(){
+    return this.rollBackTempTableCreation();
   },
 
   insertIntoTable : function(){
     console.log("insertIntoTable");
+    this.pushUploadProgressInfos("<li> Starting to Insert rows from temporary table
to actual table .... </li>");
 
     return this.get('uploader').insertIntoTable({
       "fromDatabase":  this.get("databaseName"),
@@ -359,7 +468,8 @@ export default Ember.Controller.extend({
 
   waitForInsertIntoTable: function (jobId) {
     console.log("waitForInsertIntoTable");
-    this.pushUploadProgressInfos("<li>Inserting rows from temporary table to actual
table .... </li>");
+    this.popUploadProgressInfos();
+    this.pushUploadProgressInfos("<li> Waiting for Insertion of rows from temporary
table to actual table .... </li>");
     var self = this;
     var p = new Ember.RSVP.Promise(function (resolve, reject) {
       self.waitForJobStatus(jobId, resolve, reject);
@@ -371,26 +481,35 @@ export default Ember.Controller.extend({
   onInsertIntoTableSuccess : function(){
     console.log("onInsertIntoTableSuccess");
     this.popUploadProgressInfos();
-    this.pushUploadProgressInfos("<li>Successfully inserted rows from temporary table
to actual table. </li>");
+    this.pushUploadProgressInfos("<li> Successfully inserted rows from temporary table
to actual table. </li>");
   },
 
   onInsertIntoTableFailure : function(error){
     console.log("onInsertIntoTableFailure");
     this.setError(error);
+    this.popUploadProgressInfos();
+    this.pushUploadProgressInfos("<li> Failed to insert rows from temporary table to
actual table. </li>");
+    return this.rollBackUploadFile().then(function(data){
+      return Ember.RSVP.Promise.reject(error); // always reject for the flow to stop
+    },function(err){
+      return Ember.RSVP.Promise.reject(error); // always reject for the flow to stop
+    });
   },
 
   deleteTempTable : function(){
     console.log("deleteTempTable");
+    this.pushUploadProgressInfos("<li> Starting to delete temporary table .... </li>");
 
-    return this.get('uploader').deleteTable({
-      "database":  this.get("databaseName"),
-      "table": this.get("tempTableName")
-    });
+    return this.deleteTable(
+      this.get("databaseName"),
+      this.get("tempTableName")
+    );
   },
 
   waitForDeleteTempTable: function (jobId) {
     console.log("waitForDeleteTempTable");
-    this.pushUploadProgressInfos("<li>Deleting temporary table .... </li>");
+    this.popUploadProgressInfos();
+    this.pushUploadProgressInfos("<li> Waiting for deletion of temporary table ....
</li>");
     var self = this;
     var p = new Ember.RSVP.Promise(function (resolve, reject) {
       self.waitForJobStatus(jobId, resolve, reject);
@@ -409,6 +528,7 @@ export default Ember.Controller.extend({
   onDeleteTempTableFailure : function(error){
     console.log("onDeleteTempTableFailure");
     this.setError(error);
+    this.setError("You will have to manually delete the table " + this.get("databaseName")
+ "." + this.get("tempTableName"));
   },
 
   createTableAndUploadFile : function(){
@@ -430,8 +550,8 @@ export default Ember.Controller.extend({
         return self.createTempTable(data);
       },function(error){
         if(!self.get('error')){
-          self.onCreateActualTableFailure(new Error("Server job for creation of actual table
failed."));
           console.log("Error occurred: ", error);
+          self.onCreateActualTableFailure(new Error("Server job for creation of actual table
failed."));
         }
         throw error;
       })
@@ -440,8 +560,8 @@ export default Ember.Controller.extend({
         return self.waitForCreateTempTable(data.jobId);
       },function(error){
         if(!self.get('error')){
-          self.onCreateTempTableFailure(error);
           console.log("Error occurred: ", error);
+          return self.onCreateTempTableFailure(error);
         }
         throw error;
       })
@@ -451,8 +571,8 @@ export default Ember.Controller.extend({
         return self.uploadFile(data);
       },function(error){
         if(!self.get('error')){
-          self.onCreateTempTableFailure(new Error("Server job for creation of temporary table
failed."));
           console.log("Error occurred: ", error);
+          return self.onCreateTempTableFailure(new Error("Server job for creation of temporary
table failed."));
         }
         throw error;
       }).then(function(data){
@@ -460,8 +580,8 @@ export default Ember.Controller.extend({
         return self.waitForUploadingFile(data);
       },function(error){
         if(!self.get('error')){
-          self.onUploadingFileFailure(error);
           console.log("Error occurred: ", error);
+          return self.onUploadingFileFailure(error);
         }
         throw error;
       })
@@ -471,8 +591,8 @@ export default Ember.Controller.extend({
         return self.insertIntoTable(data);
       },function(error){
         if(!self.get('error')){
-          self.onUploadingFileFailure(new Error("Server job for upload of file failed."));
           console.log("Error occurred: ", error);
+          return self.onUploadingFileFailure(new Error("Server job for upload of file failed."));
         }
         throw error;
       })
@@ -481,8 +601,8 @@ export default Ember.Controller.extend({
         return self.waitForInsertIntoTable(data.jobId);
       },function(error){
         if(!self.get('error')){
-          self.onInsertIntoTableFailure(error);
           console.log("Error occurred: ", error);
+          return self.onInsertIntoTableFailure(error);
         }
         throw error;
       })
@@ -492,9 +612,8 @@ export default Ember.Controller.extend({
         return self.deleteTempTable(data);
       },function(error){
         if(!self.get('error')){
-          self.onInsertIntoTableFailure(new Error("Server job for insert from temporary to
actual table failed."));
-          self.setError(error);
           console.log("Error occurred: ", error);
+          return self.onInsertIntoTableFailure(new Error("Server job for insert from temporary
to actual table failed."));
         }
         throw error;
       })
@@ -503,8 +622,8 @@ export default Ember.Controller.extend({
         return self.waitForDeleteTempTable(data.jobId);
       },function(error){
         if(!self.get('error')){
-          self.onDeleteTempTableFailure(error);
           console.log("Error occurred: ", error);
+          self.onDeleteTempTableFailure(error);
         }
         throw error;
       })
@@ -513,52 +632,18 @@ export default Ember.Controller.extend({
         self.onDeleteTempTableSuccess(data);
       },function(error){
         if(!self.get('error')){
-          self.onDeleteTempTableFailure(new Error("Server job for deleting temporary table
failed."));
           console.log("Error occurred: ", error);
+          self.onDeleteTempTableFailure(new Error("Server job for deleting temporary table
failed."));
         }
         throw error;
+      }).catch(function(error){
+        console.log("inside catch : ", error);
       }).finally(function(){
         console.log("finally hide the modal always");
         self.hideUploadModal();
       });
   },
 
-  createTable: function () {
-    console.log("table headers : ", this.get('header'));
-    var headers = this.get('header');
-
-    var selectedDatabase = this.get('selectedDatabase');
-    if (null == selectedDatabase || typeof selectedDatabase === 'undefined') {
-      throw new Error(Ember.I18n.t('hive.errors.emptyDatabase'));
-    }
-
-    this.set('databaseName', this.get('selectedDatabase').get('name'));
-    var databaseName = this.get('databaseName');
-    var tableName = this.get('tableName');
-    var isFirstRowHeader = this.get('isFirstRowHeader');
-    var filetype = this.get("selectedFileType");
-
-    if (null == databaseName || typeof databaseName === 'undefined' || databaseName == '')
{
-      throw new Error(Ember.I18n.t('hive.errors.emptyDatabase'));
-    }
-    if (null == tableName || typeof tableName === 'undefined' || tableName == '') {
-      throw new Error(Ember.I18n.t('hive.errors.emptyTableName'));
-    }
-    if (null == isFirstRowHeader || typeof isFirstRowHeader === 'undefined') {
-      throw new Error(Ember.I18n.t('hive.errors.emptyIsFirstRow'));
-    }
-
-    this.validateColumns();
-
-    return this.get('uploader').createTable({
-      "isFirstRowHeader": isFirstRowHeader,
-      "header": headers,
-      "tableName": tableName,
-      "databaseName": databaseName,
-      "fileType":filetype
-    });
-  },
-
   validateColumns: function () {
     // throw exception if invalid.
   },


Mime
View raw message