ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akovale...@apache.org
Subject git commit: AMBARI-4850. Mirroring: disable ability to edit target clusters. (akovalenko)
Date Wed, 26 Feb 2014 16:51:02 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk f9bc43dde -> d77b11dd7


AMBARI-4850. Mirroring: disable ability to edit target clusters. (akovalenko)


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

Branch: refs/heads/trunk
Commit: d77b11dd72271192a9d7f1972dd12a298c29a4f4
Parents: f9bc43d
Author: Aleksandr Kovalenko <akovalenko@hortonworks.com>
Authored: Wed Feb 26 18:48:42 2014 +0200
Committer: Aleksandr Kovalenko <akovalenko@hortonworks.com>
Committed: Wed Feb 26 18:48:42 2014 +0200

----------------------------------------------------------------------
 .../mirroring/manage_clusters_controller.js     | 71 +++++++--------
 .../main/mirroring/manage_clusters.hbs          | 12 +--
 ambari-web/app/utils/ajax.js                    | 94 +++++---------------
 3 files changed, 60 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d77b11dd/ambari-web/app/controllers/main/mirroring/manage_clusters_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/mirroring/manage_clusters_controller.js b/ambari-web/app/controllers/main/mirroring/manage_clusters_controller.js
index e221e75..e345253 100644
--- a/ambari-web/app/controllers/main/mirroring/manage_clusters_controller.js
+++ b/ambari-web/app/controllers/main/mirroring/manage_clusters_controller.js
@@ -26,8 +26,9 @@ App.MainMirroringManageClustersController = Em.ArrayController.extend({
 
   clusters: [],
 
-  // array of original clusters to compare with changed ones
-  originalClusters: [],
+  clustersToDelete: [],
+
+  clustersToCreate: [],
 
   queriesCount: 0,
 
@@ -41,7 +42,6 @@ App.MainMirroringManageClustersController = Em.ArrayController.extend({
   onLoad: function () {
     if (this.get('isLoaded')) {
       var clusters = [];
-      var originalClusters = [];
       App.TargetCluster.find().forEach(function (cluster) {
         var newCluster = {
           name: cluster.get('name'),
@@ -52,21 +52,31 @@ App.MainMirroringManageClustersController = Em.ArrayController.extend({
           working: cluster.get('working'),
           temp: cluster.get('temp')
         };
-        clusters.push(Ember.Object.create(newCluster));
-        originalClusters.push(Ember.Object.create(newCluster));
+        // Source cluster should be shown on top
+        if (cluster.get('name') === App.get('clusterName')) {
+          clusters.unshift(Ember.Object.create(newCluster));
+        } else {
+          clusters.push(Ember.Object.create(newCluster));
+        }
       }, this);
       this.set('clusters', clusters);
-      this.set('originalClusters', originalClusters);
+      this.get('clustersToDelete').clear();
+      this.get('clustersToCreate').clear();
     }
   }.observes('isLoaded'),
 
   selectedCluster: null,
 
+  // Disable input fields for already created clusters
+  isEditDisabled: function () {
+    return !this.get('clustersToCreate').mapProperty('name').contains(this.get('selectedCluster.name'));
+  }.property('selectedCluster.name', 'clustersToCreate.@each.name'),
+
   addCluster: function () {
     var self = this;
     App.showPromptPopup(Em.I18n.t('mirroring.manageClusters.specifyName'),
         function (clusterName) {
-          self.get('clusters').pushObject(Ember.Object.create({
+          var newCluster = Ember.Object.create({
             name: clusterName,
             execute: '',
             workflow: '',
@@ -74,7 +84,9 @@ App.MainMirroringManageClustersController = Em.ArrayController.extend({
             staging: '',
             working: '',
             temp: ''
-          }));
+          });
+          self.get('clusters').pushObject(newCluster);
+          self.get('clustersToCreate').pushObject(newCluster);
         }
     );
   },
@@ -82,6 +94,11 @@ App.MainMirroringManageClustersController = Em.ArrayController.extend({
   removeCluster: function () {
     var self = this;
     App.showConfirmationPopup(function () {
+      if (self.get('clustersToCreate').mapProperty('name').contains(self.get('selectedCluster.name')))
{
+        self.set('clustersToCreate', self.get('clustersToCreate').without(self.get('selectedCluster')));
+      } else {
+        self.get('clustersToDelete').push(self.get('selectedCluster'));
+      }
       self.set('clusters', self.get('clusters').without(self.get('selectedCluster')));
     });
   },
@@ -89,23 +106,9 @@ App.MainMirroringManageClustersController = Em.ArrayController.extend({
   save: function () {
     // define clusters need to be deleted, modified or created
     var clusters = this.get('clusters');
-    var originalClusters = this.get('originalClusters');
-    var originalClustersNames = originalClusters.mapProperty('name');
-    var clustersToModify = [];
-    var clustersToCreate = [];
-    clusters.forEach(function (cluster) {
-      var clusterName = cluster.get('name');
-      if (originalClustersNames.contains(clusterName)) {
-        if (JSON.stringify(cluster) !== JSON.stringify(originalClusters.findProperty('name',
clusterName))) {
-          clustersToModify.push(clusterName);
-        }
-        originalClustersNames = originalClustersNames.without(clusterName);
-      } else {
-        clustersToCreate.push(clusterName);
-      }
-    }, this);
-    var clustersToDelete = originalClustersNames;
-    var queriesCount = clustersToCreate.length + clustersToDelete.length + clustersToModify.length;
+    var clustersToCreate = this.get('clustersToCreate');
+    var clustersToDelete = this.get('clustersToDelete');
+    var queriesCount = clustersToCreate.length + clustersToDelete.length;
     this.set('queriesCount', queriesCount);
 
     // send request to delete, modify or create cluster
@@ -116,7 +119,7 @@ App.MainMirroringManageClustersController = Em.ArrayController.extend({
           name: 'mirroring.delete_entity',
           sender: this,
           data: {
-            name: cluster,
+            name: cluster.get('name'),
             type: 'cluster',
             falconServer: App.get('falconServerURL')
           },
@@ -130,21 +133,7 @@ App.MainMirroringManageClustersController = Em.ArrayController.extend({
           sender: this,
           data: {
             type: 'cluster',
-            entity: this.formatClusterXML(clusters.findProperty('name', cluster)),
-            falconServer: App.get('falconServerURL')
-          },
-          success: 'onQueryResponse',
-          error: 'onQueryResponse'
-        });
-      }, this);
-      clustersToModify.forEach(function (cluster) {
-        App.ajax.send({
-          name: 'mirroring.update_entity',
-          sender: this,
-          data: {
-            name: cluster,
-            type: 'cluster',
-            entity: this.formatClusterXML(clusters.findProperty('name', cluster)),
+            entity: this.formatClusterXML(cluster),
             falconServer: App.get('falconServerURL')
           },
           success: 'onQueryResponse',

http://git-wip-us.apache.org/repos/asf/ambari/blob/d77b11dd/ambari-web/app/templates/main/mirroring/manage_clusters.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/mirroring/manage_clusters.hbs b/ambari-web/app/templates/main/mirroring/manage_clusters.hbs
index 4186a54..cf13f68 100644
--- a/ambari-web/app/templates/main/mirroring/manage_clusters.hbs
+++ b/ambari-web/app/templates/main/mirroring/manage_clusters.hbs
@@ -30,15 +30,15 @@
           <div style="margin-bottom: 15px">{{t mirroring.manageClusters.interfaces}}</div>
           <div class="control-group">
             <label class="control-label-manage-clusters">{{t mirroring.manageClusters.execute}}</label>
-            {{view Ember.TextField class="span8" valueBinding="controller.selectedCluster.execute"}}
+            {{view Ember.TextField class="span8" valueBinding="controller.selectedCluster.execute"
disabledBinding="controller.isEditDisabled"}}
           </div>
           <div class="control-group">
             <label class="control-label-manage-clusters">{{t mirroring.manageClusters.readonly}}</label>
-            {{view Ember.TextField class="span8" valueBinding="controller.selectedCluster.readonly"}}
+            {{view Ember.TextField class="span8" valueBinding="controller.selectedCluster.readonly"
disabledBinding="controller.isEditDisabled"}}
           </div>
           <div class="control-group">
             <label class="control-label-manage-clusters">{{t mirroring.manageClusters.workflow}}</label>
-            {{view Ember.TextField class="span8" valueBinding="controller.selectedCluster.workflow"}}
+            {{view Ember.TextField class="span8" valueBinding="controller.selectedCluster.workflow"
disabledBinding="controller.isEditDisabled"}}
           </div>
         </div>
         <div class="accordion control-group" id="advanced-fields">
@@ -52,15 +52,15 @@
               <div class="accordion-inner">
                 <div class="control-group">
                   <label class="control-label-manage-clusters">{{t mirroring.manageClusters.staging}}</label>
-                  {{view Ember.TextField class="span8" valueBinding="controller.selectedCluster.staging"}}
+                  {{view Ember.TextField class="span8" valueBinding="controller.selectedCluster.staging"
disabledBinding="controller.isEditDisabled"}}
                 </div>
                 <div class="control-group">
                   <label class="control-label-manage-clusters">{{t mirroring.manageClusters.working}}</label>
-                  {{view Ember.TextField class="span8" valueBinding="controller.selectedCluster.working"}}
+                  {{view Ember.TextField class="span8" valueBinding="controller.selectedCluster.working"
disabledBinding="controller.isEditDisabled"}}
                 </div>
                 <div class="control-group">
                   <label class="control-label-manage-clusters">{{t mirroring.manageClusters.temp}}</label>
-                  {{view Ember.TextField class="span8" valueBinding="controller.selectedCluster.temp"}}
+                  {{view Ember.TextField class="span8" valueBinding="controller.selectedCluster.temp"
disabledBinding="controller.isEditDisabled"}}
                 </div>
               </div>
             </div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/d77b11dd/ambari-web/app/utils/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax.js b/ambari-web/app/utils/ajax.js
index c8953c5..6a17f41 100644
--- a/ambari-web/app/utils/ajax.js
+++ b/ambari-web/app/utils/ajax.js
@@ -1426,50 +1426,37 @@ var urls = {
   },
 
   'mirroring.get_all_entities': {
-    'real': '/proxy?url=http://{falconServer}:15000/api/entities/list/{type}?fields=status',
+    'real': '/proxy?url=http://{falconServer}:15000/api/entities/list/{type}?fields=status&user.name=ambari-qa',
     'mock': '/data/mirroring/{type}s.xml',
     'apiPrefix': '',
     'format': function () {
       return {
-        dataType: 'xml',
-        headers: {
-          'AmbariProxy-Remote-user': 'ambari-qa'
-        }
+        dataType: 'xml'
       }
     }
   },
 
   'mirroring.get_definition': {
-    'real': '/proxy?url=http://{falconServer}:15000/api/entities/definition/{type}/{name}',
+    'real': '/proxy?url=http://{falconServer}:15000/api/entities/definition/{type}/{name}?user.name=ambari-qa',
     'mock': '/data/mirroring/{name}_definition.xml',
     'apiPrefix': '',
     'format': function () {
       return {
         cache: true,
-        dataType: 'xml',
-        headers: {
-          'AmbariProxy-Remote-user': 'ambari-qa'
-        }
+        dataType: 'xml'
       }
     }
   },
 
   'mirroring.dataset.get_all_instances': {
-    'real': '/proxy?url=http://{falconServer}:15000/api/instance/status/feed/{dataset}?start={start}&end={end}',
+    'real': '/proxy?url=http://{falconServer}:15000/api/instance/status/feed/{dataset}?start={start}&end={end}&user.name=ambari-qa',
     'mock': '/data/mirroring/{dataset}_instances.json',
-    'apiPrefix': '',
-    'format': function (data) {
-      return {
-        headers: {
-          'AmbariProxy-Remote-user': 'ambari-qa'
-        }
-      }
-    }
+    'apiPrefix': ''
   },
 
 
   'mirroring.create_new_dataset': {
-    'real': '/proxy?url=http://{falconServer}:15000/api/entities/submitAndSchedule/feed',
+    'real': '/proxy?url=http://{falconServer}:15000/api/entities/submitAndSchedule/feed?user.name=ambari-qa',
     'mock': '/data/mirroring/succeeded.json',
     'apiPrefix': '',
     'type': 'POST',
@@ -1479,7 +1466,6 @@ var urls = {
         dataType: 'xml',
         data: data.dataset,
         headers: {
-          'AmbariProxy-Remote-user': 'ambari-qa',
           'AmbariProxy-Content-Type': 'text/xml'
         }
       }
@@ -1487,7 +1473,7 @@ var urls = {
   },
 
   'mirroring.submit_entity': {
-    'real': '/proxy?url=http://{falconServer}:15000/api/entities/submit/{type}',
+    'real': '/proxy?url=http://{falconServer}:15000/api/entities/submit/{type}?user.name=ambari-qa',
     'mock': '/data/mirroring/succeeded.json',
     'apiPrefix': '',
     'type': 'POST',
@@ -1497,7 +1483,6 @@ var urls = {
         dataType: 'xml',
         data: data.entity,
         headers: {
-          'AmbariProxy-Remote-user': 'ambari-qa',
           'AmbariProxy-Content-Type': 'text/xml'
         }
       }
@@ -1505,7 +1490,7 @@ var urls = {
   },
 
   'mirroring.update_entity': {
-    'real': '/proxy?url=http://{falconServer}:15000/api/entities/update/{type}/{name}',
+    'real': '/proxy?url=http://{falconServer}:15000/api/entities/update/{type}/{name}?user.name=ambari-qa',
     'mock': '/data/mirroring/succeeded.json',
     'apiPrefix': '',
     'type': 'POST',
@@ -1514,100 +1499,69 @@ var urls = {
         contentType: 'text/xml',
         dataType: 'xml',
         data: data.entity,
-        headers: {
-          'AmbariProxy-Remote-user': 'ambari-qa',
-          'AmbariProxy-Content-Type': 'text/xml'
-        }
+          headers: {
+        'AmbariProxy-Content-Type': 'text/xml'
+      }
       }
     }
   },
 
   'mirroring.delete_entity': {
-    'real': '/proxy?url=http://{falconServer}:15000/api/entities/delete/{type}/{name}',
+    'real': '/proxy?url=http://{falconServer}:15000/api/entities/delete/{type}/{name}?user.name=ambari-qa',
     'mock': '/data/mirroring/succeeded.json',
     'apiPrefix': '',
     'type': 'DELETE',
     'format': function (data) {
       return {
-        dataType: 'xml',
-        headers: {
-          'AmbariProxy-Remote-user': 'ambari-qa'
-        }
+        dataType: 'xml'
       }
     }
   },
 
   'mirroring.suspend_entity': {
-    'real': '/proxy?url=http://{falconServer}:15000/api/entities/suspend/{type}/{name}',
+    'real': '/proxy?url=http://{falconServer}:15000/api/entities/suspend/{type}/{name}?user.name=ambari-qa',
     'mock': '/data/mirroring/succeeded.json',
     'apiPrefix': '',
     'type': 'POST',
     'format': function (data) {
       return {
         dataType: 'xml',
-        data: data.entity,
-        headers: {
-          'AmbariProxy-Remote-user': 'ambari-qa'
-        }
+        data: data.entity
       }
     }
   },
 
   'mirroring.schedule_entity': {
-    'real': '/proxy?url=http://{falconServer}:15000/api/entities/resume/{type}/{name}',
+    'real': '/proxy?url=http://{falconServer}:15000/api/entities/resume/{type}/{name}?user.name=ambari-qa',
     'mock': '/data/mirroring/succeeded.json',
     'apiPrefix': '',
     'type': 'POST',
     'format': function (data) {
       return {
-        dataType: 'xml',
-        headers: {
-          'AmbariProxy-Remote-user': 'ambari-qa'
-        }
+        dataType: 'xml'
       }
     }
   },
 
   'mirroring.suspend_instance': {
-    'real': '/proxy?url=http://{falconServer}:15000/api/instance/suspend/feed/{feed}?start={name}',
+    'real': '/proxy?url=http://{falconServer}:15000/api/instance/suspend/feed/{feed}?start={name}&user.name=ambari-qa',
     'mock': '/data/mirroring/succeeded.json',
     'apiPrefix': '',
-    'type': 'POST',
-    'format': function (data) {
-      return {
-        headers: {
-          'AmbariProxy-Remote-user': 'ambari-qa'
-        }
-      }
-    }
+    'type': 'POST'
   },
 
   'mirroring.resume_instance': {
-    'real': '/proxy?url=http://{falconServer}:15000/api/instance/resume/feed/{feed}?start={name}',
+    'real': '/proxy?url=http://{falconServer}:15000/api/instance/resume/feed/{feed}?start={name}&user.name=ambari-qa',
     'mock': '/data/mirroring/succeeded.json',
     'apiPrefix': '',
-    'type': 'POST',
-    'format': function (data) {
-      return {
-        headers: {
-          'AmbariProxy-Remote-user': 'ambari-qa'
-        }
-      }
-    }
+    'type': 'POST'
   },
 
   'mirroring.kill_instance': {
-    'real': '/proxy?url=http://{falconServer}:15000/api/instance/kill/feed/{feed}?start={name}',
+    'real': '/proxy?url=http://{falconServer}:15000/api/instance/kill/feed/{feed}?start={name}&user.name=ambari-qa',
     'mock': '/data/mirroring/succeeded.json',
     'apiPrefix': '',
-    'type': 'POST',
-    'format': function (data) {
-      return {
-        headers: {
-          'AmbariProxy-Remote-user': 'ambari-qa'
-        }
-      }
-    }
+    'type': 'POST'
   },
 
   'bulk_request.host_components': {


Mime
View raw message