You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by gn...@apache.org on 2017/01/27 13:57:01 UTC

ambari git commit: AMBARI-19742. User preference like opened tabs/work in-progress should not be available to a different user. (Venkata Sairam via gauravn7)

Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 31527a015 -> 650b88d44


AMBARI-19742. User preference like opened tabs/work in-progress should not be available to a different user. (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/650b88d4
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/650b88d4
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/650b88d4

Branch: refs/heads/branch-2.5
Commit: 650b88d44b89e8544c751ff8778a839bd9b702ef
Parents: 31527a0
Author: Gaurav Nagar <gr...@gmail.com>
Authored: Fri Jan 27 19:26:33 2017 +0530
Committer: Gaurav Nagar <gr...@gmail.com>
Committed: Fri Jan 27 19:26:33 2017 +0530

----------------------------------------------------------------------
 .../ui/app/components/bundle-config.js          | 27 ++++++---
 .../resources/ui/app/components/coord-config.js | 64 +++++++++++---------
 .../ui/app/components/designer-workspace.js     | 25 ++++----
 .../ui/app/components/flow-designer.js          | 12 ++--
 .../main/resources/ui/app/services/user-info.js | 56 +++++++++++++++++
 .../ui/app/services/workspace-manager.js        | 61 ++++++++++++++-----
 .../ui/tests/unit/services/user-info-test.js    | 29 +++++++++
 7 files changed, 207 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/650b88d4/contrib/views/wfmanager/src/main/resources/ui/app/components/bundle-config.js
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/resources/ui/app/components/bundle-config.js b/contrib/views/wfmanager/src/main/resources/ui/app/components/bundle-config.js
index e29935c..8b4c3d8 100644
--- a/contrib/views/wfmanager/src/main/resources/ui/app/components/bundle-config.js
+++ b/contrib/views/wfmanager/src/main/resources/ui/app/components/bundle-config.js
@@ -48,23 +48,19 @@ export default Ember.Component.extend(Ember.Evented, Validations, {
   fileBrowser : Ember.inject.service('file-browser'),
   workspaceManager : Ember.inject.service('workspace-manager'),
   initialize : function(){
-    var draftBundle = this.get('workspaceManager').restoreWorkInProgress(this.get('tabInfo.id'));
-    if(draftBundle){
-      this.set('bundle', JSON.parse(draftBundle));
-    }else{
-      this.set('bundle', this.createBundle());
-    }
+    var self = this;
+    this.get('workspaceManager').restoreWorkInProgress(this.get('tabInfo.id')).promise.then(function(draftBundle){
+      self.loadBundle(draftBundle);
+    }.bind(this)).catch(function(data){
+      self.loadBundle();
+    }.bind(this));
     this.get('fileBrowser').on('fileBrowserOpened',function(context){
       this.get('fileBrowser').setContext(context);
     }.bind(this));
     this.on('fileSelected',function(fileName){
       this.set(this.get('filePathModel'), fileName);
     }.bind(this));
-    if(Ember.isBlank(this.get('bundle.name'))){
-      this.set('bundle.name', Ember.copy(this.get('tabInfo.name')));
-    }
     this.set('showErrorMessage', false);
-    this.schedulePersistWorkInProgress();
   }.on('init'),
   onDestroy : function(){
     Ember.run.cancel(this.schedulePersistWorkInProgress);
@@ -92,6 +88,17 @@ export default Ember.Component.extend(Ember.Evented, Validations, {
   bundleFilePath : Ember.computed('tabInfo.filePath', function(){
     return this.get('tabInfo.filePath');
   }),
+  loadBundle(draftBundle){
+    if(draftBundle){
+      this.set('bundle', JSON.parse(draftBundle));
+    }else{
+      this.set('bundle', this.createBundle());
+    }
+    if(Ember.isBlank(this.get('bundle.name'))){
+      this.set('bundle.name', Ember.copy(this.get('tabInfo.name')));
+    }
+    this.schedulePersistWorkInProgress();
+  }, 
   schedulePersistWorkInProgress (){
     Ember.run.later(function(){
       this.persistWorkInProgress();

http://git-wip-us.apache.org/repos/asf/ambari/blob/650b88d4/contrib/views/wfmanager/src/main/resources/ui/app/components/coord-config.js
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/resources/ui/app/components/coord-config.js b/contrib/views/wfmanager/src/main/resources/ui/app/components/coord-config.js
index fa664c7..57dbeb0 100644
--- a/contrib/views/wfmanager/src/main/resources/ui/app/components/coord-config.js
+++ b/contrib/views/wfmanager/src/main/resources/ui/app/components/coord-config.js
@@ -75,22 +75,13 @@ export default Ember.Component.extend(Validations, Ember.Evented, {
     this.persistWorkInProgress();
   }.on('willDestroyElement'),
   initialize : function(){
-    var draftCoordinator = this.get('workspaceManager').restoreWorkInProgress(this.get('tabInfo.id'));
-    if(draftCoordinator){
-      this.set('coordinator', JSON.parse(draftCoordinator));
-    }else{
-      this.set('coordinator', this.createNewCoordinator());
-    }
-    this.set('timeUnitOptions',Ember.A([]));
-    this.get('timeUnitOptions').pushObject({value:'',displayName:'Select'});
-    this.get('timeUnitOptions').pushObject({value:'months',displayName:'Months'});
-    this.get('timeUnitOptions').pushObject({value:'endOfMonths',displayName:'End of Months'});
-    this.get('timeUnitOptions').pushObject({value:'days',displayName:'Days'});
-    this.get('timeUnitOptions').pushObject({value:'endOfDays',displayName:'End of Days'});
-    this.get('timeUnitOptions').pushObject({value:'hours',displayName:'Hours'});
-    this.get('timeUnitOptions').pushObject({value:'minutes',displayName:'Minutes'});
-    this.get('timeUnitOptions').pushObject({value:'cron',displayName:'Cron'});
-    this.set('coordinator.slaInfo', SlaInfo.create({}));
+    var self = this;
+
+    this.get('workspaceManager').restoreWorkInProgress(this.get('tabInfo.id')).promise.then(function(draftCoordinator){
+      self.loadCoordinator(draftCoordinator);
+    }.bind(this)).catch(function(data){
+      self.loadCoordinator();
+    }.bind(this));
 
     this.get('fileBrowser').on('fileBrowserOpened',function(context){
       this.get('fileBrowser').setContext(context);
@@ -98,18 +89,7 @@ export default Ember.Component.extend(Validations, Ember.Evented, {
     this.on('fileSelected',function(fileName){
       this.set(this.get('filePathModel'), fileName);
     }.bind(this));
-    this.set('coordinatorControls',[
-      {'name':'timeout', 'displayName':'Timeout', 'value':''},
-      {'name':'concurrency', 'displayName':'Concurrency', 'value':''},
-      {'name':'execution', 'displayName':'Execution', 'value':''},
-      {'name':'throttle', 'displayName':'Throttle', 'value':''}
-    ]);
-    this.set('timezoneList', Ember.copy(Constants.timezoneList));
-    if(Ember.isBlank(this.get('coordinator.name'))){
-      this.set('coordinator.name', Ember.copy(this.get('tabInfo.name')));
-    }
-    this.schedulePersistWorkInProgress();
-    this.set('childComponents', new Map());
+
   }.on('init'),
   conditionalDataInExists :false,
   elementsInserted : function(){
@@ -141,6 +121,34 @@ export default Ember.Component.extend(Validations, Ember.Evented, {
       this.sendAction('changeTabName', this.get('tabInfo'), this.get('coordinator.name'));
     }
   }),
+  loadCoordinator(draftCoordinator){
+    if(draftCoordinator){
+      this.set('coordinator', JSON.parse(draftCoordinator));
+    }else{
+      this.set('coordinator', this.createNewCoordinator());
+    }
+    this.set('timeUnitOptions',Ember.A([]));
+    this.get('timeUnitOptions').pushObject({value:'',displayName:'Select'});
+    this.get('timeUnitOptions').pushObject({value:'months',displayName:'Months'});
+    this.get('timeUnitOptions').pushObject({value:'endOfMonths',displayName:'End of Months'});
+    this.get('timeUnitOptions').pushObject({value:'days',displayName:'Days'});
+    this.get('timeUnitOptions').pushObject({value:'endOfDays',displayName:'End of Days'});
+    this.get('timeUnitOptions').pushObject({value:'hours',displayName:'Hours'});
+    this.get('timeUnitOptions').pushObject({value:'minutes',displayName:'Minutes'});
+    this.get('timeUnitOptions').pushObject({value:'cron',displayName:'Cron'});
+    this.set('coordinator.slaInfo', SlaInfo.create({}));
+    this.set('coordinatorControls',[
+      {'name':'timeout', 'displayName':'Timeout', 'value':''},
+      {'name':'concurrency', 'displayName':'Concurrency', 'value':''},
+      {'name':'execution', 'displayName':'Execution', 'value':''},
+      {'name':'throttle', 'displayName':'Throttle', 'value':''}
+    ]);
+    this.set('timezoneList', Ember.copy(Constants.timezoneList));
+    if(Ember.isBlank(this.get('coordinator.name'))){
+      this.set('coordinator.name', Ember.copy(this.get('tabInfo.name')));
+    }
+    this.schedulePersistWorkInProgress();    
+  },
   coordinatorFilePath : Ember.computed('tabInfo.filePath', function(){
     return this.get('tabInfo.filePath');
   }),

http://git-wip-us.apache.org/repos/asf/ambari/blob/650b88d4/contrib/views/wfmanager/src/main/resources/ui/app/components/designer-workspace.js
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/resources/ui/app/components/designer-workspace.js b/contrib/views/wfmanager/src/main/resources/ui/app/components/designer-workspace.js
index 53fd27d..5b517af 100644
--- a/contrib/views/wfmanager/src/main/resources/ui/app/components/designer-workspace.js
+++ b/contrib/views/wfmanager/src/main/resources/ui/app/components/designer-workspace.js
@@ -19,6 +19,7 @@ import CommonUtils from "../utils/common-utils";
 import Constants from '../utils/constants';
 export default Ember.Component.extend({
   workspaceManager : Ember.inject.service('workspace-manager'),
+  userInfo : Ember.inject.service('user-info'),
   xmlAppPath : null,
   appPath : null,
   type : 'wf',
@@ -42,18 +43,20 @@ export default Ember.Component.extend({
     this.get('tabCounter').set('wf', 0);
     this.get('tabCounter').set('coord', 0);
     this.get('tabCounter').set('bundle', 0);
-    var tabs = this.get('workspaceManager').restoreTabs();
-    if(tabs){
-      this.set('tabs', tabs);
-    }
-    this.get('tabs').forEach((tab)=>{
-      this.get('tabCounter').set(tab.type, (this.get('tabCounter').get(tab.type)) + 1);
-    }, this);
-
-    Ember.getOwner(this).lookup('route:design').on('openNewTab', function(path){
-      this.createNewTab('wf', path);
-    }.bind(this));
+    var tabsData = this.get('workspaceManager').restoreTabs();
+    tabsData.promise.then(function(tabs){
+        if(tabs){
+          this.set('tabs', tabs);
+        }
+        this.get('tabs').forEach((tab)=>{
+          this.get('tabCounter').set(tab.type, (this.get('tabCounter').get(tab.type)) + 1);
+        }, this);
+        Ember.getOwner(this).lookup('route:design').on('openNewTab', function(path){
+          this.createNewTab('wf', path);
+        }.bind(this));
 
+      }.bind(this)).catch(function(data){
+      });
   }.on('init'),
   elementsInserted : function(){
     this.$('.nav-tabs a[data-toggle="tab"]').on('shown.bs.tab', function (e) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/650b88d4/contrib/views/wfmanager/src/main/resources/ui/app/components/flow-designer.js
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/resources/ui/app/components/flow-designer.js b/contrib/views/wfmanager/src/main/resources/ui/app/components/flow-designer.js
index 0a0d2f2..1292832 100644
--- a/contrib/views/wfmanager/src/main/resources/ui/app/components/flow-designer.js
+++ b/contrib/views/wfmanager/src/main/resources/ui/app/components/flow-designer.js
@@ -586,10 +586,14 @@ export default Ember.Component.extend(FindNodeMixin, Validations, {
   },
   getDraftWorkflow(){
     var deferred = Ember.RSVP.defer();
-    var drafWorkflowJson = this.get('workspaceManager').restoreWorkInProgress(this.get('tabInfo.id'));
-    var workflowImporter=WorkflowJsonImporter.create({});
-    var workflow=workflowImporter.importWorkflow(drafWorkflowJson);
-    deferred.resolve(workflow);
+
+    this.get('workspaceManager').restoreWorkInProgress(this.get('tabInfo.id')).promise.then(function(drafWorkflowJson){
+          var workflowImporter=WorkflowJsonImporter.create({});
+          var workflow=workflowImporter.importWorkflow(drafWorkflowJson);
+          deferred.resolve(workflow);
+        }.bind(this)).catch(function(data){
+          deferred.resolve("");
+        });
     return deferred;
   },
   createSnapshot() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/650b88d4/contrib/views/wfmanager/src/main/resources/ui/app/services/user-info.js
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/resources/ui/app/services/user-info.js b/contrib/views/wfmanager/src/main/resources/ui/app/services/user-info.js
new file mode 100644
index 0000000..7c59f40
--- /dev/null
+++ b/contrib/views/wfmanager/src/main/resources/ui/app/services/user-info.js
@@ -0,0 +1,56 @@
+/*
+*    Licensed to the Apache Software Foundation (ASF) under one or more
+*    contributor license agreements.  See the NOTICE file distributed with
+*    this work for additional information regarding copyright ownership.
+*    The ASF licenses this file 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
+*
+*    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.
+*    See the License for the specific language governing permissions and
+*    limitations under the License.
+*/
+
+import Ember from 'ember';
+
+export default Ember.Service.extend({
+  data:null,
+  userName: null,
+  init() {
+  },
+  getUserData(){
+    var url = Ember.ENV.API_URL + "/getCurrentUserName", self = this;
+    var deferred = Ember.RSVP.defer();
+    if(self.get("userName") !== null && self.get("userName") !== undefined){
+      deferred.resolve(self.get("userName"));
+    } else{
+      Ember.$.ajax({
+        url: url,
+        method: 'GET',
+        dataType: "text",
+        beforeSend: function (xhr) {
+          xhr.setRequestHeader("X-XSRF-HEADER", Math.round(Math.random()*100000));
+          xhr.setRequestHeader("X-Requested-By", "Ambari");
+        }
+      }).done(function(data){
+        self.set("userName", data);
+        deferred.resolve(data);
+      }).fail(function(data){
+        self.set("userName", "");
+        deferred.reject(data);
+      });
+    }
+    return deferred;
+  },
+  setUserData(data){
+    this.set("data", data);
+  },
+  getUserName(){
+    var res = this.getUserData();
+    return res;
+  }
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/650b88d4/contrib/views/wfmanager/src/main/resources/ui/app/services/workspace-manager.js
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/resources/ui/app/services/workspace-manager.js b/contrib/views/wfmanager/src/main/resources/ui/app/services/workspace-manager.js
index 24ab53c..c377ecc 100644
--- a/contrib/views/wfmanager/src/main/resources/ui/app/services/workspace-manager.js
+++ b/contrib/views/wfmanager/src/main/resources/ui/app/services/workspace-manager.js
@@ -20,18 +20,36 @@ import Ember from 'ember';
 export default Ember.Service.extend({
   tabsInfo : {},
   workInProgress : {},
+  userInfo : Ember.inject.service('user-info'),
   setLastActiveTab(tabId){
-    console.log("setting last active tabId "+tabId);
-    localStorage.setItem('lastActiveTab', tabId);
+    this.get("userInfo").getUserData().promise.then(function(data){
+       localStorage.setItem(data+"-lastActiveTab", tabId);
+      }.bind(this)).catch(function(e){
+        console.error(e);
+      });
   },
   getLastActiveTab(){
-    console.log("get last active "+localStorage.getItem('lastActiveTab'));
-    return localStorage.getItem('lastActiveTab');
+      this.get("userInfo").getUserData().promise.then(function(data){
+        return localStorage.getItem(data+"-lastActiveTab");
+      }.bind(this)).catch(function(e){
+        console.error(e);
+      });
   },
   restoreTabs(){
-    var tabs = localStorage.getItem('tabsInfo');
-    console.log("Restoring tabs "+tabs);
-    return JSON.parse(tabs);
+      var deferred = Ember.RSVP.defer();
+
+      this.get("userInfo").getUserData().promise.then(function(data){
+        var tabs = localStorage.getItem(data+'-tabsInfo');
+        console.log("Restoring tabs "+tabs);
+        deferred.resolve(JSON.parse(tabs));
+
+        //return JSON.parse(tabs);
+
+      }.bind(this)).catch(function(e){
+        deferred.resolve("");
+        console.error(e);
+      });
+    return deferred;
   },
   saveTabs(tabs){
     if(!tabs){
@@ -46,18 +64,33 @@ export default Ember.Service.extend({
         filePath : tab.filePath
       });
     });
-    console.log("Saving tabs "+JSON.stringify(tabArray));
-    localStorage.setItem('tabsInfo', JSON.stringify(tabArray));
+    this.get("userInfo").getUserData().promise.then(function(data){
+          localStorage.setItem(data+'-tabsInfo', JSON.stringify(tabArray));
+    }.bind(this)).catch(function(e){
+      console.error(e);
+    });
   },
   restoreWorkInProgress(id){
-    console.log("Restoring workInProgress "+id);
-    return localStorage.getItem(id);
+    var deferred = Ember.RSVP.defer();
+    this.get("userInfo").getUserData().promise.then(function(data){
+       deferred.resolve(localStorage.getItem(data+"-"+id));
+    }.bind(this)).catch(function(data){
+       deferred.resolve("");
+    });
+    return deferred;
   },
   saveWorkInProgress(id, workInProgress){
-    console.log("Restoring workInProgress "+id);
-    localStorage.setItem(id, workInProgress);
+    this.get("userInfo").getUserData().promise.then(function(data){
+      localStorage.setItem(data+"-"+id, workInProgress);
+    }.bind(this)).catch(function(e){
+      console.error(e);
+    });    
   },
   deleteWorkInProgress(id){
-    localStorage.removeItem(id);
+    this.get("userInfo").getUserData().promise.then(function(data){
+      localStorage.removeItem(data+"-"+id);
+    }.bind(this)).catch(function(e){
+      console.error(e);
+    });
   }
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/650b88d4/contrib/views/wfmanager/src/main/resources/ui/tests/unit/services/user-info-test.js
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/resources/ui/tests/unit/services/user-info-test.js b/contrib/views/wfmanager/src/main/resources/ui/tests/unit/services/user-info-test.js
new file mode 100644
index 0000000..b8acb3e
--- /dev/null
+++ b/contrib/views/wfmanager/src/main/resources/ui/tests/unit/services/user-info-test.js
@@ -0,0 +1,29 @@
+/*
+*    Licensed to the Apache Software Foundation (ASF) under one or more
+*    contributor license agreements.  See the NOTICE file distributed with
+*    this work for additional information regarding copyright ownership.
+*    The ASF licenses this file 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
+*
+*    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.
+*    See the License for the specific language governing permissions and
+*    limitations under the License.
+*/
+
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('service:user-info', 'Unit | Service | user info', {
+  // Specify the other units that are required for this test.
+  // needs: ['service:foo']
+});
+
+// Replace this with your real tests.
+test('it exists', function(assert) {
+  let service = this.subject();
+  assert.ok(service);
+});