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-22089. Hive View 2.0 - Unable to update existing saved queries, view creates new records under saved queries tab (pallavkul)
Date Mon, 09 Oct 2017 15:47:49 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk fc80a1837 -> beef96d41


AMBARI-22089. Hive View 2.0 - Unable to update existing saved queries, view creates new records
under saved queries tab (pallavkul)


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

Branch: refs/heads/trunk
Commit: beef96d413d4986cb0cc11c317d11d5a181da14c
Parents: fc80a18
Author: pallavkul <pallav.kul@gmail.com>
Authored: Mon Oct 9 21:17:35 2017 +0530
Committer: pallavkul <pallav.kul@gmail.com>
Committed: Mon Oct 9 21:17:35 2017 +0530

----------------------------------------------------------------------
 .../savedQueries/SavedQueryResourceManager.java | 17 ++++--
 .../savedQueries/SavedQueryService.java         | 46 +++++++--------
 .../resources/ui/app/routes/queries/query.js    | 60 ++++++++++++++------
 .../resources/ui/app/services/saved-queries.js  | 21 +++++++
 .../hive20/src/main/resources/ui/yarn.lock      |  2 +-
 5 files changed, 98 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/beef96d4/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/savedQueries/SavedQueryResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/savedQueries/SavedQueryResourceManager.java
b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/savedQueries/SavedQueryResourceManager.java
index 3690683..fff202c 100644
--- a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/savedQueries/SavedQueryResourceManager.java
+++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/savedQueries/SavedQueryResourceManager.java
@@ -115,12 +115,17 @@ public class SavedQueryResourceManager extends PersonalCRUDResourceManager<Saved
   }
 
   @Override
-  public SavedQuery update(SavedQuery newObject, String id) throws ItemNotFound {
-    SavedQuery savedQuery = super.update(newObject, id);
-    // Emptying short query so that in next read, this gets updated with proper value
-    // from the queryFile
-    emptyShortQueryField(savedQuery);
-    return savedQuery;
+  public SavedQuery update(SavedQuery object, String id) throws ItemNotFound {
+    String query = object.getShortQuery();
+    object.setShortQuery(makeShortQuery(query));
+    object = super.update(object, id);
+    try {
+      createDefaultQueryFile(object, query);
+
+    } catch (ServiceFormattedException e) {
+      cleanupAfterErrorAndThrowAgain(object, e);
+    }
+    return object;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/beef96d4/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/savedQueries/SavedQueryService.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/savedQueries/SavedQueryService.java
b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/savedQueries/SavedQueryService.java
index 7139ce8..35382f9 100644
--- a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/savedQueries/SavedQueryService.java
+++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/savedQueries/SavedQueryService.java
@@ -83,36 +83,36 @@ public class SavedQueryService extends BaseService {
   @Path("{queryId}")
   @Produces(MediaType.APPLICATION_JSON)
   public Response getOne(@PathParam("queryId") String queryId,
-		         @QueryParam("op") String operation) {
+             @QueryParam("op") String operation) {
     try {
-      final SavedQuery savedQuery = getResourceManager().read(queryId);    
-      if(operation.equals("download")) {
-    	StreamingOutput stream = new StreamingOutput() {
-    	@Override
-    	public void write(OutputStream os) throws IOException, WebApplicationException {
-    	  Writer writer = new BufferedWriter(new OutputStreamWriter(os));
-    	  try { 
+      final SavedQuery savedQuery = getResourceManager().read(queryId);
+      if(operation!= null && operation.equals("download")) {
+      StreamingOutput stream = new StreamingOutput() {
+      @Override
+      public void write(OutputStream os) throws IOException, WebApplicationException {
+        Writer writer = new BufferedWriter(new OutputStreamWriter(os));
+        try {
             BufferedReader br=new BufferedReader(new InputStreamReader(getSharedObjectsFactory().getHdfsApi().open(savedQuery.getQueryFile())));
-	    String line;
-    	    line=br.readLine();
-    	    while (line != null){
-    	      writer.write(line+"\n");  
-    	      line = br.readLine();
+      String line;
+          line=br.readLine();
+          while (line != null){
+            writer.write(line+"\n");
+            line = br.readLine();
             }
             writer.flush();
-    	  } catch (InterruptedException e) {
-	    e.printStackTrace();
-	  } finally {
-	    writer.close();
-    	  }
-    	}
-    	};
-    	return Response.ok(stream).
+        } catch (InterruptedException e) {
+      e.printStackTrace();
+    } finally {
+      writer.close();
+        }
+      }
+      };
+      return Response.ok(stream).
                type(MediaType.TEXT_PLAIN).
-    	       build();
+             build();
       }
       else {
-    	 JSONObject object = new JSONObject();
+       JSONObject object = new JSONObject();
          object.put("savedQuery", savedQuery);
          return Response.ok(object).build();
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/beef96d4/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 9e8b6db..9bb5c8f 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
@@ -631,6 +631,8 @@ export default Ember.Route.extend(UILoggerMixin, {
       let owner = this.get('controller.model').get('owner');
       let queryFile = this.get('controller.model').get('queryFile');
       let logFile = this.get('controller.model').get('logFile');
+      let shortQuery = (currentQuery.length > 0) ? currentQuery : ";";
+      let savedQueryId = this.get('controller.model').get('id')
 
       let payload = {"title" : newTitle,
         "dataBase": selectedDb,
@@ -639,32 +641,54 @@ export default Ember.Route.extend(UILoggerMixin, {
         "queryFile" : queryFile,
         "logFile" : logFile};
 
-      let newSaveQuery = this.get('store').createRecord('saved-query',
-        { dataBase:selectedDb,
-          title:newTitle,
-          queryFile: queryFile,
-          owner: owner,
-          shortQuery: (currentQuery.length > 0) ? currentQuery : ";"
-        });
 
+      let existingSavedQuery = this.get('store').peekRecord('saved-query', savedQueryId);
 
-      newSaveQuery.save().then((data) => {
-        console.log('saved query saved');
+      if(existingSavedQuery){
 
-        this.get('controller.model').set('title', newTitle);
-        this.get('controller.model').set('isQueryDirty', false);
-        this.get('controller').set('worksheetModalSuccess', true);
+          this.get('savedQueries').updateSavedQuery(existingSavedQuery.get('id'), shortQuery,
selectedDb, owner).then( data => {
+              console.log('saved query updated.');
+              this.get('controller.model').set('title', newTitle);
+              this.get('controller.model').set('isQueryDirty', false);
+              this.get('controller').set('worksheetModalSuccess', true);
 
-        Ember.run.later(() => {
-          this.get('controller').set('showWorksheetModal', false);
-          this.closeWorksheetAfterSave();
-        }, 2 * 1000);
+              Ember.run.later(() => {
+                this.get('controller').set('showWorksheetModal', false);
+                this.closeWorksheetAfterSave();
+              }, 2 * 1000);
 
-      });
+            }).catch(function (response) {
+               console.log('error', response);
+            });
+
+      } else{
+
+        let newSaveQuery = this.get('store').createRecord('saved-query',
+          { dataBase:selectedDb,
+            title:newTitle,
+            queryFile: queryFile,
+            owner: owner,
+            shortQuery: (currentQuery.length > 0) ? currentQuery : ";"
+          });
+
+        newSaveQuery.save().then((data) => {
+          console.log('saved query saved');
 
+          this.get('controller.model').set('title', newTitle);
+          this.get('controller.model').set('isQueryDirty', false);
+          this.get('controller').set('worksheetModalSuccess', true);
+
+          Ember.run.later(() => {
+            this.get('controller').set('showWorksheetModal', false);
+            this.closeWorksheetAfterSave();
+          }, 2 * 1000);
+
+        });
+
+      }
     },
 
-    closeWorksheetModal(){
+  closeWorksheetModal(){
       this.get('controller').set('showWorksheetModal', false);
       this.closeWorksheetAfterSave();
       this.get('controller.model').set('tabDataToClose', null);

http://git-wip-us.apache.org/repos/asf/ambari/blob/beef96d4/contrib/views/hive20/src/main/resources/ui/app/services/saved-queries.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive20/src/main/resources/ui/app/services/saved-queries.js b/contrib/views/hive20/src/main/resources/ui/app/services/saved-queries.js
index 4b4b29e..b1a28ce 100644
--- a/contrib/views/hive20/src/main/resources/ui/app/services/saved-queries.js
+++ b/contrib/views/hive20/src/main/resources/ui/app/services/saved-queries.js
@@ -50,6 +50,27 @@ export default Ember.Service.extend({
     });
   },
 
+  updateSavedQuery(savedQueryId, shortQuery, selectedDb, owner){
+    return new Ember.RSVP.Promise((resolve, reject) => {
+
+      this.get('store').findRecord('saved-query', savedQueryId, {async: true} ).then(savedQuery
=> {
+          savedQuery.set('shortQuery', shortQuery);
+          savedQuery.set('dataBase', selectedDb );
+          savedQuery.set('owner', owner );
+          savedQuery.save().then(() => {
+            return resolve("");
+          })
+
+
+
+
+       }).catch(function (response) {
+          console.log('error', response);
+          return reject(response);
+       });
+    });
+  },
+
   fetchSavedQuery(path) {
     let url = this.get('store').adapterFor('application').buildURL()+ '/files/' + encodeURIComponent(path);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/beef96d4/contrib/views/hive20/src/main/resources/ui/yarn.lock
----------------------------------------------------------------------
diff --git a/contrib/views/hive20/src/main/resources/ui/yarn.lock b/contrib/views/hive20/src/main/resources/ui/yarn.lock
index 477a15c..607cf81 100644
--- a/contrib/views/hive20/src/main/resources/ui/yarn.lock
+++ b/contrib/views/hive20/src/main/resources/ui/yarn.lock
@@ -569,7 +569,7 @@ babel-plugin-transform-es2015-block-scoped-functions@^6.22.0:
   dependencies:
     babel-runtime "^6.22.0"
 
-babel-plugin-transform-es2015-block-scoping@^6.23.0:
+babel-plugin-transform-es2015-block-scoping@^6.23.0, babel-plugin-transform-es2015-block-scoping@^6.24.1:
   version "6.24.1"
   resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-block-scoping/-/babel-plugin-transform-es2015-block-scoping-6.24.1.tgz#76c295dc3a4741b1665adfd3167215dcff32a576"
   dependencies:


Mime
View raw message