You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by xi...@apache.org on 2014/12/10 21:59:48 UTC

[1/2] ambari git commit: AMBARI-8646. Reset Group filter to All if group was deleted.(xiwang)

Repository: ambari
Updated Branches:
  refs/heads/trunk bd3aea50a -> 494ae7a15


AMBARI-8646. Reset Group filter to All if group was deleted.(xiwang)


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

Branch: refs/heads/trunk
Commit: 494ae7a15fd78d47bae9ed775b6b3c221aa57495
Parents: 1aff154
Author: Xi Wang <xi...@apache.org>
Authored: Wed Dec 10 11:22:42 2014 -0800
Committer: Xi Wang <xi...@apache.org>
Committed: Wed Dec 10 12:59:08 2014 -0800

----------------------------------------------------------------------
 ambari-web/app/views/main/alert_definitions_view.js | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/494ae7a1/ambari-web/app/views/main/alert_definitions_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/alert_definitions_view.js b/ambari-web/app/views/main/alert_definitions_view.js
index 425242a..733e214 100644
--- a/ambari-web/app/views/main/alert_definitions_view.js
+++ b/ambari-web/app/views/main/alert_definitions_view.js
@@ -373,13 +373,16 @@ App.MainAlertDefinitionsView = App.TableView.extend({
 
     onValueChange: function () {
       var value = this.get('value');
-      if (value != undefined ) {
+      if (value != undefined) {
         this.get('content').setEach('selected', false);
         this.set('selected', this.get('content').findProperty('value', value));
         var selectEntry = this.get('content').findProperty('value', value);
         if (selectEntry) {
           selectEntry.set('selected', true);
         }
+      } else {
+        this.set('value', '');
+        this.get('parentView').updateFilter(this.get('column'), '', 'alert_group');
       }
     }.observes('value')
   }),


[2/2] ambari git commit: AMBARI-8626. Remove unneeded ajax-calls and models for manage alert group.(xiwang)

Posted by xi...@apache.org.
AMBARI-8626. Remove unneeded ajax-calls and models for manage alert group.(xiwang)


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

Branch: refs/heads/trunk
Commit: 1aff154abe88c1c71ad07cb5c30eb1095f648a73
Parents: bd3aea5
Author: Xi Wang <xi...@apache.org>
Authored: Tue Dec 9 14:35:57 2014 -0800
Committer: Xi Wang <xi...@apache.org>
Committed: Wed Dec 10 12:59:08 2014 -0800

----------------------------------------------------------------------
 .../alerts/manage_alert_groups_controller.js    | 260 ++++++++++---------
 ambari-web/app/mappers/alert_groups_mapper.js   |   6 +-
 ambari-web/app/models/alert_group.js            |  64 +----
 .../main/alerts/manage_alert_groups_popup.hbs   |   4 +-
 ambari-web/app/utils/ajax/ajax.js               |   5 -
 .../main/alerts/manage_alert_groups_view.js     |   2 -
 6 files changed, 156 insertions(+), 185 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1aff154a/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js b/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js
index fca6800..6d273cf 100644
--- a/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js
+++ b/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js
@@ -34,138 +34,119 @@ App.ManageAlertGroupsController = Em.Controller.extend({
 
   selectedDefinitions: [],
 
-  alertDefinitions: [],
-
-  alertNotifications: [],
-
-  // load alert definitions for all services
-  loadAlertDefinitions: function () {
-    App.ajax.send({
-      name: 'alerts.load_all_alert_definitions',
-      sender: this,
-      success: 'onLoadAlertDefinitionsSuccess',
-      error: 'onLoadAlertDefinitionsError'
-    });
-  },
-
-  onLoadAlertDefinitionsSuccess: function (data) {
-    var alertDefinitions = [];
-    if (data && data.items) {
-      data.items.forEach( function(def) {
-        if (def && def.AlertDefinition) {
-          alertDefinitions.pushObject (Em.Object.create({
-            name: def.AlertDefinition.name,
-            serviceName: def.AlertDefinition.service_name,
-            serviceNameDisplay:function() {
-              return App.format.role(this.get('serviceName'));
-            }.property('serviceName'),
-            componentName: def.AlertDefinition.component_name,
-            componentNameDisplay: function() {
-              return App.format.role(this.get('componentName'));
-            }.property('componentName'),
-            label: def.AlertDefinition.label,
-            id: def.AlertDefinition.id
-          }));
-        }
+  /**
+   * List of all Alert Notifications
+   * @type {App.AlertNotification[]}
+   */
+  alertNotifications: function () {
+    return this.get('isLoaded') ? App.AlertNotification.find().map (function (target) {
+      return Em.Object.create ({
+        name: target.get('name'),
+        id: target.get('id'),
+        description: target.get('description'),
+        type: target.get('type'),
+        global: target.get('global')
       });
-    }
-    this.set('alertDefinitions', alertDefinitions);
-  },
+    }) : [];
+  }.property('isLoaded'),
 
-  onLoadAlertDefinitionsError: function () {
-    console.error('Unable to load all alert definitions.');
-  },
+  /**
+   * List of all global Alert Notifications
+   * @type {App.AlertNotification[]}
+   */
+  alertGlobalNotifications: function () {
+    return this.get('alertNotifications').filterProperty('global');
+  }.property('alertNotifications'),
 
-  // load all alert notifications
+  /**
+   * Load all Alert Notifications from server
+   * @returns {$.ajax|null}
+   */
   loadAlertNotifications: function () {
-    App.ajax.send({
-      name: 'alerts.load_alert_notification',
-      sender: this,
-      success: 'onLoadAlertNotificationsSuccess',
-      error: 'onLoadAlertNotificationsError'
-    });
-  },
-
-  onLoadAlertNotificationsSuccess: function (data) {
-    var alertNotifications = [];
-    if (data && data.items) {
-      data.items.forEach( function(target) {
-        if (target && target.AlertTarget) {
-          alertNotifications.pushObject (Em.Object.create({
-            name: target.AlertTarget.name,
-            type: target.AlertTarget.notification_type,
-            description: target.AlertTarget.description,
-            global: target.AlertTarget.global,
-            id: target.AlertTarget.id
-          }));
-        }
-      });
-    }
-    this.set('alertNotifications', alertNotifications);
-    this.set('alertGlobalNotifications', alertNotifications.filterProperty('global'));
-  },
-
-  onLoadAlertNotificationsError: function () {
-    console.error('Unable to load all alert notifications.');
-  },
-
-  loadAlertGroups: function () {
     this.set('isLoaded', false);
     this.set('alertGroups', []);
     this.set('originalAlertGroups', []);
+    this.set('selectedAlertGroup', null);
     this.set('isRemoveButtonDisabled', true);
     this.set('isRenameButtonDisabled', true);
     this.set('isDuplicateButtonDisabled', true);
-    App.ajax.send({
-      name: 'alerts.load_alert_groups',
+    return App.ajax.send({
+      name: 'alerts.notifications',
       sender: this,
-      success: 'onLoadAlertGroupsSuccess',
-      error: 'onLoadAlertGroupsError'
+      success: 'getAlertNotificationsSuccessCallback',
+      error: 'getAlertNotificationsErrorCallback'
     });
   },
 
-  onLoadAlertGroupsSuccess: function (data) {
-    var self = this;
-    if (data && data.items) {
-      this.set('alertGroupsCount', data.items.length);
-      data.items.forEach(function(alert_group) {
-        App.ajax.send({
-          name: 'alerts.load_an_alert_group',
-          sender: self,
-          data: {
-            "group_id": alert_group.AlertGroup.id
-          },
-          success: 'onLoadAlertGroupSuccess',
-          error: 'onLoadAlertGroupError'
-        });
-      }, this);
-    }
+  /**
+   * Success-callback for load alert notifications request
+   * @param {object} json
+   * @method getAlertNotificationsSuccessCallback
+   */
+  getAlertNotificationsSuccessCallback: function (json) {
+    App.alertNotificationMapper.map(json);
+    this.loadAlertGroups();
   },
 
-  onLoadAlertGroupSuccess: function (data) {
-    var alertGroups = this.get('alertGroups');
-    if (data && data.AlertGroup) {
-      alertGroups.pushObject (App.AlertGroupComplex.create({
-        name: data.AlertGroup.name,
-        default: data.AlertGroup.default,
-        id: data.AlertGroup.id,
-        definitions: data.AlertGroup.definitions,
-        notifications: data.AlertGroup.targets
-      }));
-    }
-    if (this.get('alertGroupsCount') == alertGroups.length) {
-      this.set('isLoaded', true);
-      this.set('originalAlertGroups', this.copyAlertGroups(alertGroups));
-      this.set('selectedAlertGroup', alertGroups[0])
-    }
+  /**
+   * Error-callback for load alert notifications request
+   * @method getAlertNotificationsErrorCallback
+   */
+  getAlertNotificationsErrorCallback: function () {
+    this.set('isLoaded', true);
   },
 
+  /**
+   * Load all alert groups from alert group model
+   */
+  loadAlertGroups: function () {
+    var alertGroups = App.AlertGroup.find().map(function (group) {
+      var definitions = group.get('definitions').map (function (def) {
+        return Em.Object.create ({
+          name: def.get('name'),
+          serviceName: def.get('serviceName'),
+          componentName: def.get('componentName'),
+          serviceNameDisplay: def.get('service.displayName'),
+          componentNameDisplay: def.get('componentNameFormatted'),
+          label: def.get('label'),
+          id: def.get('id')
+        });
+      });
+
+      var targets = group.get('targets').map (function (target) {
+        return Em.Object.create ({
+          name: target.get('name'),
+          id: target.get('id'),
+          description: target.get('description'),
+          type: target.get('type'),
+          global: target.get('global')
+        });
+      });
 
-  onLoadAlertGroupsError: function () {
-    console.error('Unable to load all alert groups.');
-  },
-  onLoadAlertGroupError: function () {
-    console.error('Unable to load an alert group.');
+      return Em.Object.create({
+        id: group.get('id'),
+        name: group.get('name'),
+        default: group.get('default'),
+        displayName: function () {
+          var name = this.get('name');
+          if (name && name.length > App.config.CONFIG_GROUP_NAME_MAX_LENGTH) {
+            var middle = Math.floor(App.config.CONFIG_GROUP_NAME_MAX_LENGTH / 2);
+            name = name.substring(0, middle) + "..." + name.substring(name.length - middle);
+          }
+          return this.get('default') ? (name + ' Default') : name;
+        }.property('name', 'default'),
+        label: function () {
+          return this.get('displayName') + ' (' + this.get('definitions.length') + ')';
+        }.property('displayName', 'definitions.length'),
+        definitions: definitions,
+        isAddDefinitionsDisabled: group.get('isAddDefinitionsDisabled'),
+        notifications: targets
+      });
+    });
+    this.set('alertGroups', alertGroups);
+    this.set('isLoaded', true);
+    this.set('originalAlertGroups', this.copyAlertGroups(this.get('alertGroups')));
+    this.set('selectedAlertGroup', this.get('alertGroups')[0]);
   },
 
   /**
@@ -205,7 +186,6 @@ App.ManageAlertGroupsController = Em.Controller.extend({
       alertGroups.removeObject(defaultGroup);
     });
     var sorted = defaultGroups.sortProperty('name').concat(alertGroups.sortProperty('name'));
-   // var sorted = alertGroups.sortProperty('name');
 
     this.removeObserver('alertGroups.@each.name', this, 'resortAlertGroup');
     this.set('alertGroups', sorted);
@@ -235,13 +215,44 @@ App.ManageAlertGroupsController = Em.Controller.extend({
   }.property('selectedAlertGroup', 'selectedAlertGroup.definitions.length', 'selectedDefinitions.length'),
 
   /**
+   * Provides alert definitions which are available for inclusion in
+   * non-default alert groups.
+   */
+  getAvailableDefinitions: function (selectedAlertGroup) {
+    if (selectedAlertGroup.get('default')) return [];
+    var usedDefinitionsMap = {};
+    var availableDefinitions = [];
+    var sharedDefinitions = App.AlertDefinition.getAllDefinitions();
+
+    selectedAlertGroup.get('definitions').forEach(function (def) {
+      usedDefinitionsMap[def.name] = true;
+    });
+    sharedDefinitions.forEach(function (shared_def) {
+      if (!usedDefinitionsMap[shared_def.get('name')]) {
+        availableDefinitions.pushObject(shared_def);
+      }
+    });
+    return availableDefinitions.map (function (def) {
+      return Em.Object.create ({
+        name: def.get('name'),
+        serviceName: def.get('serviceName'),
+        componentName: def.get('componentName'),
+        serviceNameDisplay: def.get('service.displayName'),
+        componentNameDisplay: def.get('componentNameFormatted'),
+        label: def.get('label'),
+        id: def.get('id')
+      });
+    });
+  },
+
+  /**
    * add alert definitions to a group
    */
   addDefinitions: function () {
     if (this.get('selectedAlertGroup.isAddDefinitionsDisabled')){
       return false;
     }
-    var availableDefinitions = this.get('selectedAlertGroup.availableDefinitions');
+    var availableDefinitions = this.getAvailableDefinitions(this.get('selectedAlertGroup'));
     var popupDescription = {
       header: Em.I18n.t('alerts.actions.manage_alert_groups_popup.selectDefsDialog.title'),
       dialogMessage: Em.I18n.t('alerts.actions.manage_alert_groups_popup.selectDefsDialog.message').format(this.get('selectedAlertGroup.displayName'))
@@ -461,7 +472,7 @@ App.ManageAlertGroupsController = Em.Controller.extend({
   copyAlertGroups: function (originGroups) {
     var alertGroups = [];
     originGroups.forEach(function (alertGroup) {
-      var copiedGroup =  App.AlertGroupComplex.create($.extend(true, {}, alertGroup));
+      var copiedGroup =  Em.Object.create($.extend(true, {}, alertGroup));
       alertGroups.pushObject(copiedGroup);
     });
     return alertGroups;
@@ -667,10 +678,23 @@ App.ManageAlertGroupsController = Em.Controller.extend({
         return !(this.get('alertGroupName').trim().length > 0 && !this.get('warningMessage'));
       }.property('warningMessage', 'alertGroupName'),
       onPrimary: function () {
-        var newAlertGroup = App.AlertGroupComplex.create({
+        var newAlertGroup = Em.Object.create({
           name: this.get('alertGroupName').trim(),
+          default: false,
+          displayName: function () {
+            var name = this.get('name');
+            if (name && name.length > App.config.CONFIG_GROUP_NAME_MAX_LENGTH) {
+              var middle = Math.floor(App.config.CONFIG_GROUP_NAME_MAX_LENGTH / 2);
+              name = name.substring(0, middle) + "..." + name.substring(name.length - middle);
+            }
+            return this.get('default') ? (name + ' Default') : name;
+          }.property('name', 'default'),
+          label: function () {
+            return this.get('displayName') + ' (' + this.get('definitions.length') + ')';
+          }.property('displayName', 'definitions.length'),
           definitions: [],
-          notifications: self.get('alertGlobalNotifications')
+          notifications: self.get('alertGlobalNotifications'),
+          isAddDefinitionsDisabled: false
         });
         self.get('alertGroups').pushObject(newAlertGroup);
         self.set('selectedAlertGroup', newAlertGroup);

http://git-wip-us.apache.org/repos/asf/ambari/blob/1aff154a/ambari-web/app/mappers/alert_groups_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/alert_groups_mapper.js b/ambari-web/app/mappers/alert_groups_mapper.js
index 0060a15..a1b33f5 100644
--- a/ambari-web/app/mappers/alert_groups_mapper.js
+++ b/ambari-web/app/mappers/alert_groups_mapper.js
@@ -80,9 +80,10 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
         Em.keys(typesMap).forEach(function(k) {
           group[typesMap[k]] = [];
         });
+        group.targets = [];
         if (item.AlertGroup.definitions) {
           item.AlertGroup.definitions.forEach(function(definition) {
-              var type = typesMap[definition.source_type];
+            var type = typesMap[definition.source_type];
             if (!group[type].contains(definition.id)) {
               group[type].push(definition.id);
             }
@@ -94,6 +95,9 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
         }
         if (item.AlertGroup.targets) {
           item.AlertGroup.targets.forEach(function(target) {
+            if (!group.targets.contains(target.id)) {
+              group.targets.push(target.id);
+            }
             if (Em.isNone(alertNotificationsGroupsMap[target.id])) {
               alertNotificationsGroupsMap[target.id] = [];
             }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1aff154a/ambari-web/app/models/alert_group.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/alert_group.js b/ambari-web/app/models/alert_group.js
index 6ffe263..15e88b2 100644
--- a/ambari-web/app/models/alert_group.js
+++ b/ambari-web/app/models/alert_group.js
@@ -79,7 +79,10 @@ App.AlertGroup = DS.Model.extend({
    */
   scriptAlertDefinitions: DS.hasMany('App.ScriptAlertDefinition'),
 
-  targets: [],
+  /**
+   * @type {App.AlertNotification[]}
+   */
+  targets: DS.hasMany('App.AlertNotification'),
 
   /**
    * @type {string}
@@ -98,65 +101,12 @@ App.AlertGroup = DS.Model.extend({
    */
   displayNameDefinitions: function () {
     return this.get('displayName') + ' (' + this.get('definitions.length') + ')';
-  }.property('displayName', 'definitions.length')
-});
-App.AlertGroup.FIXTURES = [];
-
-App.AlertGroupComplex = Ember.Object.extend({
-  id: null,
-  name: null,
-  default: null,
-  definitions: [],
-  targets: [],
-
-  /**
-   * all alert definitions that belong to all services
-   */
-  alertDefinitionsBinding: 'App.router.manageAlertGroupsController.alertDefinitions',
-  /**
-   * all alert notifications
-   */
-  alertNotificationsBinding: 'App.router.manageAlertGroupsController.alertNotifications',
-
-
-  displayName: function () {
-    var name = this.get('name');
-    if (name && name.length > App.config.CONFIG_GROUP_NAME_MAX_LENGTH) {
-      var middle = Math.floor(App.config.CONFIG_GROUP_NAME_MAX_LENGTH / 2);
-      name = name.substring(0, middle) + "..." + name.substring(name.length - middle);
-    }
-    return this.get('default') ? (name + ' Default') : name;
-  }.property('name', 'default'),
-
-  displayNameDefinitions: function () {
-    return this.get('displayName') + ' (' + this.get('definitions.length') + ')';
   }.property('displayName', 'definitions.length'),
 
-  /**
-   * Provides alert definitions which are available for inclusion in
-   * non-default alert groups.
-   */
-  availableDefinitions: function () {
-    if (this.get('default')) return [];
-    var usedDefinitionsMap = {};
-    var availableDefinitions = [];
-    var sharedDefinitions = this.get('alertDefinitions');
-
-    this.get('definitions').forEach(function (def) {
-      usedDefinitionsMap[def.name] = true;
-    });
-    sharedDefinitions.forEach(function (shared_def) {
-      if (!usedDefinitionsMap[shared_def.get('name')]) {
-        availableDefinitions.pushObject(shared_def);
-      }
-    });
-    return availableDefinitions;
-  }.property('alertDefinitions', 'definitions.@each', 'definitions.length'),
-
   isAddDefinitionsDisabled: function () {
-    return (this.get('default') || this.get('availableDefinitions.length') === 0);
-  }.property('availableDefinitions.length')
-
+    return this.get('default');
+  }.property('default')
 });
+App.AlertGroup.FIXTURES = [];
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/1aff154a/ambari-web/app/templates/main/alerts/manage_alert_groups_popup.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/alerts/manage_alert_groups_popup.hbs b/ambari-web/app/templates/main/alerts/manage_alert_groups_popup.hbs
index 15cf3b1..2d7366a 100644
--- a/ambari-web/app/templates/main/alerts/manage_alert_groups_popup.hbs
+++ b/ambari-web/app/templates/main/alerts/manage_alert_groups_popup.hbs
@@ -24,7 +24,7 @@
           <span>&nbsp;</span>
           {{view Em.Select
           contentBinding="alertGroups"
-          optionLabelPath="content.displayNameDefinitions"
+          optionLabelPath="content.label"
           selectionBinding="view.selectedAlertGroup"
           multiple="multiple"
           class="group-select select-group-box"
@@ -73,7 +73,7 @@
             </div>
             <div class="row-fluid notification-editable-list">
               <div class="span11">
-                {{view App.EditableList itemsBinding="selectedAlertGroup.notifications" resourcesBinding="selectedAlertGroup.alertNotifications" nameBinding="selectedAlertGroup.displayName"}}
+                {{view App.EditableList itemsBinding="selectedAlertGroup.notifications" resourcesBinding="controller.alertNotifications" nameBinding="selectedAlertGroup.displayName"}}
               </div>
             </div>
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/1aff154a/ambari-web/app/utils/ajax/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax/ajax.js b/ambari-web/app/utils/ajax/ajax.js
index 7aa5fbd..11f1f74 100644
--- a/ambari-web/app/utils/ajax/ajax.js
+++ b/ambari-web/app/utils/ajax/ajax.js
@@ -304,11 +304,6 @@ var urls = {
     'real': '/clusters/{clusterName}/request_schedules/{request_schedule_id}',
     'type': 'DELETE'
   },
-
-  'alerts.load_alert_notification': {
-    'real': '/alert_targets?fields=*',
-    'mock': 'data/alerts/alertNotifications.json'
-  },
   'alerts.load_alert_groups': {
     'real': '/clusters/{clusterName}/alert_groups?fields=*',
     'mock': 'data/alerts/alertGroups.json'

http://git-wip-us.apache.org/repos/asf/ambari/blob/1aff154a/ambari-web/app/views/main/alerts/manage_alert_groups_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/alerts/manage_alert_groups_view.js b/ambari-web/app/views/main/alerts/manage_alert_groups_view.js
index ab62b9c..42e6859 100644
--- a/ambari-web/app/views/main/alerts/manage_alert_groups_view.js
+++ b/ambari-web/app/views/main/alerts/manage_alert_groups_view.js
@@ -67,8 +67,6 @@ App.MainAlertsManageAlertGroupView = Em.View.extend({
    * @method willInsertElement
    */
   willInsertElement: function() {
-    this.get('controller').loadAlertGroups();
-    this.get('controller').loadAlertDefinitions();
     this.get('controller').loadAlertNotifications();
   },