ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gna...@apache.org
Subject ambari git commit: AMBARI-20173. DB selected is not persisted while switching between tabs, SavedQuery tab does not show preview, if the query is not executed before saving. (Venkata Sairam via gauravn7)
Date Tue, 28 Feb 2017 06:07:31 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk cbfd78cdb -> d7c8aeaab


AMBARI-20173. DB selected is not persisted while switching between tabs,SavedQuery tab does
not show preview, if the query is not executed before saving. (Venkata Sairam via gauravn7)


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

Branch: refs/heads/trunk
Commit: d7c8aeaab81a8a9cad5911ef0e859f0b5d681e8e
Parents: cbfd78c
Author: Gaurav Nagar <grvngr@gmail.com>
Authored: Tue Feb 28 11:37:20 2017 +0530
Committer: Gaurav Nagar <grvngr@gmail.com>
Committed: Tue Feb 28 11:37:20 2017 +0530

----------------------------------------------------------------------
 .../savedQueries/SavedQueryResourceManager.java | 44 ++++----------------
 .../resources/ui/app/routes/queries/query.js    |  3 ++
 .../resources/ui/app/routes/savedqueries.js     | 33 ++++++++-------
 .../resources/ui/app/services/saved-queries.js  | 10 +++++
 4 files changed, 41 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d7c8aeaa/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 ef497ce..3690683 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
@@ -6,9 +6,9 @@
  * 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
  * 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.
@@ -53,12 +53,11 @@ public class SavedQueryResourceManager extends PersonalCRUDResourceManager<Saved
 
   @Override
   public SavedQuery create(SavedQuery object) {
+    String query = object.getShortQuery();
+    object.setShortQuery(makeShortQuery(query));
     object = super.create(object);
     try {
-
-      if (object.getQueryFile() == null || object.getQueryFile().isEmpty()) {
-        createDefaultQueryFile(object);
-      }
+      createDefaultQueryFile(object, query);
 
     } catch (ServiceFormattedException e) {
       cleanupAfterErrorAndThrowAgain(object, e);
@@ -66,7 +65,7 @@ public class SavedQueryResourceManager extends PersonalCRUDResourceManager<Saved
     return object;
   }
 
-  private void createDefaultQueryFile(SavedQuery object) {
+  private void createDefaultQueryFile(SavedQuery object, String query) {
     String userScriptsPath = context.getProperties().get("scripts.dir");
     if (userScriptsPath == null) {
       String msg = "scripts.dir is not configured!";
@@ -82,7 +81,7 @@ public class SavedQueryResourceManager extends PersonalCRUDResourceManager<Saved
     String newFilePath = null;
     try {
       newFilePath = HdfsUtil.findUnallocatedFileName(sharedObjectsFactory.getHdfsApi(), baseFileName,
".hql");
-      HdfsUtil.putStringToFile(sharedObjectsFactory.getHdfsApi(), newFilePath, "");
+      HdfsUtil.putStringToFile(sharedObjectsFactory.getHdfsApi(), newFilePath, query);
     } catch (HdfsApiException e) {
       throw new ServiceFormattedException(e);
     }
@@ -94,28 +93,9 @@ public class SavedQueryResourceManager extends PersonalCRUDResourceManager<Saved
   @Override
   public SavedQuery read(Object id) throws ItemNotFound {
     SavedQuery savedQuery = super.read(id);
-    fillShortQueryField(savedQuery);
     return savedQuery;
   }
 
-  private void fillShortQueryField(SavedQuery savedQuery) {
-    if (savedQuery.getQueryFile() != null) {
-      FilePaginator paginator = new FilePaginator(savedQuery.getQueryFile(), sharedObjectsFactory.getHdfsApi());
-      String query = null;
-      try {
-        query = paginator.readPage(0);
-      } catch (IOException e) {
-        LOG.error("Can't read query file " + savedQuery.getQueryFile());
-        return;
-      } catch (InterruptedException e) {
-        LOG.error("Can't read query file " + savedQuery.getQueryFile());
-        return;
-      }
-      savedQuery.setShortQuery(makeShortQuery(query));
-    }
-    storageFactory.getStorage().store(SavedQuery.class, savedQuery);
-  }
-
   private void emptyShortQueryField(SavedQuery query) {
     query.setShortQuery("");
     storageFactory.getStorage().store(SavedQuery.class, query);
@@ -131,7 +111,7 @@ public class SavedQueryResourceManager extends PersonalCRUDResourceManager<Saved
   protected static String makeShortQuery(String query) {
     query = query.replaceAll("(?i)set\\s+[\\w\\-.]+(\\s*)=(\\s*)[\\w\\-.]+(\\s*);", "");
     query = query.trim();
-    return query.substring(0, (query.length() > 42)?42:query.length());
+    return query.substring(0, (query.length() > 42) ? 42 : query.length());
   }
 
   @Override
@@ -146,12 +126,6 @@ public class SavedQueryResourceManager extends PersonalCRUDResourceManager<Saved
   @Override
   public List<SavedQuery> readAll(FilteringStrategy filteringStrategy) {
     List<SavedQuery> queries = super.readAll(filteringStrategy);
-    for(SavedQuery query : queries) {
-      String shortQuery = query.getShortQuery();
-      if(shortQuery == null || shortQuery.isEmpty()) {
-        fillShortQueryField(query);
-      }
-    }
     return queries;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/d7c8aeaa/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 efab0ad..8f0085c 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
@@ -156,6 +156,9 @@ export default Ember.Route.extend(UILoggerMixin, {
 
   },
   checkIfDeafultDatabaseExists(alldatabases){
+    if(this.get('controller.model').get('selectedDb')) {
+      return this.get('controller.model').get('selectedDb');
+    }
     let defaultDB = alldatabases.findBy('name', 'default'), selectedDb;
     if(defaultDB) {
       selectedDb = defaultDB.get("name");

http://git-wip-us.apache.org/repos/asf/ambari/blob/d7c8aeaa/contrib/views/hive20/src/main/resources/ui/app/routes/savedqueries.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive20/src/main/resources/ui/app/routes/savedqueries.js b/contrib/views/hive20/src/main/resources/ui/app/routes/savedqueries.js
index 7b18424..5369f8e 100644
--- a/contrib/views/hive20/src/main/resources/ui/app/routes/savedqueries.js
+++ b/contrib/views/hive20/src/main/resources/ui/app/routes/savedqueries.js
@@ -17,6 +17,7 @@
  */
 
 import Ember from 'ember';
+import UILoggerMixin from '../mixins/ui-logger';
 
 export default Ember.Route.extend({
 
@@ -84,7 +85,7 @@ export default Ember.Route.extend({
 
     openAsWorksheet(savedQuery){
 
-      let hasWorksheetModel = this.modelFor('queries');
+      let hasWorksheetModel = this.modelFor('queries'), self = this;
       let worksheetId;
 
       if (Ember.isEmpty(hasWorksheetModel)){
@@ -103,19 +104,23 @@ export default Ember.Route.extend({
         });
         worksheetId = `worksheet${worksheets.get('length') + 1}`;
       }
-
-      let localWs = {
-        id: worksheetId,
-        title: savedQuery.get('title'),
-        query: savedQuery.get('shortQuery'),
-        selectedDb : savedQuery.get('dataBase'),
-        owner: savedQuery.get('owner'),
-        selected: true
-      };
-
-      this.store.createRecord('worksheet', localWs );
-
-      this.transitionTo('queries.query', localWs.title);
+      this.get("savedQueries").fetchSavedQuery(savedQuery.get('queryFile')).then(function(response)
{
+        let localWs = {
+          id: worksheetId,
+          title: savedQuery.get('title'),
+          queryFile: savedQuery.get('queryFile'),
+          query: response.file.fileContent,
+          selectedDb : savedQuery.get('dataBase'),
+          owner: savedQuery.get('owner'),
+          selected: true
+        };
+
+        self.store.createRecord('worksheet', localWs );
+
+        self.transitionTo('queries.query', localWs.title);
+      }, (error) => {
+         self.get('logger').danger('Failed to load the query', self.extractError(error));
+      });
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/d7c8aeaa/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 80a19f3..2752375 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
@@ -48,6 +48,16 @@ export default Ember.Service.extend({
       dataType:"json",
       headers: {'X-Requested-By': 'ambari'}
     })
+  },
+
+  fetchSavedQuery(path) {
+    let url = this.get('store').adapterFor('application').buildURL()+ '/files/' + encodeURIComponent(path);
+
+    return $.ajax({
+      type: "GET",
+      url: url,
+      headers: {'X-Requested-By': 'ambari'}
+    })
   }
 
 });


Mime
View raw message