You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sr...@apache.org on 2014/11/20 01:34:50 UTC

ambari git commit: AMBARI-8391. Alerts UI: Create dialog to Manage Notifications of alerts (srimanth)

Repository: ambari
Updated Branches:
  refs/heads/trunk 1fab75b3a -> 7a4e75796


AMBARI-8391. Alerts UI: Create dialog to Manage Notifications of alerts (srimanth)


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

Branch: refs/heads/trunk
Commit: 7a4e75796f03c9e6ba707042db5e7a36c92c1268
Parents: 1fab75b
Author: Srimanth Gunturi <sg...@hortonworks.com>
Authored: Wed Nov 19 16:26:47 2014 -0800
Committer: Srimanth Gunturi <sg...@hortonworks.com>
Committed: Wed Nov 19 16:26:47 2014 -0800

----------------------------------------------------------------------
 ambari-web/app/controllers.js                   |   1 +
 .../alert_definitions_actions_controller.js     |  17 ++-
 .../manage_alert_notifications_controller.js    |  66 ++++++++++++
 ambari-web/app/mappers.js                       |   1 +
 ambari-web/app/messages.js                      |  10 ++
 ambari-web/app/models/alert_notification.js     |  19 +++-
 .../alerts/manage_alert_notifications_popup.hbs | 108 +++++++++++++++++++
 ambari-web/app/utils/ajax/ajax.js               |   4 +
 ambari-web/app/views.js                         |   1 +
 .../alerts/manage_alert_notifications_view.js   |  97 +++++++++++++++++
 10 files changed, 321 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7a4e7579/ambari-web/app/controllers.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers.js b/ambari-web/app/controllers.js
index 7c6db41..c4385ce 100644
--- a/ambari-web/app/controllers.js
+++ b/ambari-web/app/controllers.js
@@ -74,6 +74,7 @@ require('controllers/main/alerts/definition_details_controller');
 require('controllers/main/alerts/definition_configs_controller');
 require('controllers/main/alerts/alert_instances_controller');
 require('controllers/main/alerts/manage_alert_groups_controller');
+require('controllers/main/alerts/manage_alert_notifications_controller');
 require('controllers/main/service');
 require('controllers/main/service/item');
 require('controllers/main/service/info/summary');

http://git-wip-us.apache.org/repos/asf/ambari/blob/7a4e7579/ambari-web/app/controllers/main/alerts/alert_definitions_actions_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/alerts/alert_definitions_actions_controller.js b/ambari-web/app/controllers/main/alerts/alert_definitions_actions_controller.js
index e74e612..e6790a0 100644
--- a/ambari-web/app/controllers/main/alerts/alert_definitions_actions_controller.js
+++ b/ambari-web/app/controllers/main/alerts/alert_definitions_actions_controller.js
@@ -148,7 +148,20 @@ App.MainAlertDefinitionActionsController = Em.ArrayController.extend({
     });
   },
 
-
-  manageNotifications: Em.K
+  /**
+   *  "Manage Alert Notifications" handler
+   */
+  manageNotifications: function () {
+    return App.ModalPopup.show({
+      header: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.header'),
+      bodyClass: App.ManageAlertNotificationsView.extend({
+        controllerBinding: 'App.router.manageAlertNotificationsController'
+      }),
+      classNames: ['sixty-percent-width-modal', 'manage-configuration-group-popup'],
+      secondary: null,
+      primary: Em.I18n.t('common.close'),
+      didInsertElement: Em.K
+    });
+  }
 
 });
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/7a4e7579/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
new file mode 100644
index 0000000..e30831c
--- /dev/null
+++ b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
@@ -0,0 +1,66 @@
+/**
+ * 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.
+ */
+
+var App = require('app');
+
+App.ManageAlertNotificationsController = Em.Controller.extend({
+  name: 'manageAlertNotificationsController',
+  isLoaded: false,
+
+  /**
+   * @type {App.AlertNotification[]}
+   */
+  alertNotifications: function () {
+    if (this.get('isLoaded')) {
+      return App.AlertNotification.find().toArray();
+    }
+    return [];
+  }.property('isLoaded'),
+
+  /**
+   * @type {App.AlertNotification}
+   */
+  selectedAlertNotification: null,
+
+  loadAlertNotifications: function () {
+    if (this.get('isLoaded')) {
+      return;
+    }
+    App.ajax.send({
+      name: 'alerts.notifications',
+      sender: this,
+      data: {},
+      success: 'getAlertNotificationsSuccessCallback',
+      error: 'getAlertNotificationsErrorCallback'
+    });
+  },
+
+  getAlertNotificationsSuccessCallback: function (json) {
+    App.alertNotificationMapper.map(json);
+    this.set('isLoaded', true);
+  },
+
+  getAlertNotificationsErrorCallback: function () {
+    this.set('isLoaded', true);
+  },
+
+  addAlertNotification: Em.K,
+  deleteAlertNotification: Em.K,
+  editAlertNotification: Em.K,
+  duplicateAlertNotification: Em.K
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/7a4e7579/ambari-web/app/mappers.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers.js b/ambari-web/app/mappers.js
index daa2cf6..9f0ecc3 100644
--- a/ambari-web/app/mappers.js
+++ b/ambari-web/app/mappers.js
@@ -38,4 +38,5 @@ require('mappers/alert_definitions_mapper');
 require('mappers/alert_definition_summary_mapper');
 require('mappers/alert_instances_mapper');
 require('mappers/alert_groups_mapper');
+require('mappers/alert_notification_mapper');
 require('mappers/root_service_mapper');

http://git-wip-us.apache.org/repos/asf/ambari/blob/7a4e7579/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index 33a36bd..14ee759 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -74,6 +74,7 @@ Em.I18n.translations = {
   'common.hosts':'Hosts',
   'common.services':'Services',
   'common.group':'Group',
+  'common.groups':'Groups',
   'common.progress':'Progress',
   'common.status':'Status',
   'common.action':'Action',
@@ -161,6 +162,7 @@ Em.I18n.translations = {
   'common.add': 'Add',
   'common.edit': 'Edit',
   'common.delete': 'Delete',
+  'common.duplicate': 'Duplicate',
   'common.empty': 'Empty',
   'common.override':'Override',
   'common.undo':'Undo',
@@ -1723,6 +1725,14 @@ Em.I18n.translations = {
   'alerts.actions.manage_alert_groups_popup.selectDefsDialog.selectedDefsLink': '{0} out of {1} alert definitions selected',
   'alerts.actions.manage_alert_groups_popup.selectDefsDialog.message.warning': 'At least one alert definition needs to be selected.',
 
+  'alerts.actions.manage_alert_notifications_popup.header':'Manage Alert Notifications',
+  'alerts.actions.manage_alert_notifications_popup.addButton':'Create new Alert Notification',
+  'alerts.actions.manage_alert_notifications_popup.removeButton':'Delete Alert Notification',
+  'alerts.actions.manage_alert_notifications_popup.editButton':'Edit Alert Notification',
+  'alerts.actions.manage_alert_notifications_popup.duplicateButton':'Duplicate Alert Notification',
+  'alerts.actions.manage_alert_notifications_popup.method':'Method',
+  'alerts.actions.manage_alert_notifications_popup.email':'Email',
+
   'hosts.host.add':'Add New Hosts',
   'hosts.table.noHosts':'No hosts to display',
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/7a4e7579/ambari-web/app/models/alert_notification.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/alert_notification.js b/ambari-web/app/models/alert_notification.js
index 8206217..6f5db0a 100644
--- a/ambari-web/app/models/alert_notification.js
+++ b/ambari-web/app/models/alert_notification.js
@@ -24,4 +24,21 @@ App.AlertNotification = DS.Model.extend({
   type: DS.attr('string'),
   description: DS.attr('string'),
   properties: DS.attr('string')
-});
\ No newline at end of file
+});
+
+App.AlertNotification.FIXTURES = [
+  {
+    "description" : "Admins",
+    "id" : 1,
+    "name" : "Administrators",
+    "type" : "EMAIL",
+    "properties" : ""
+  },
+  {
+    "description" : "Operators",
+    "id" : 2,
+    "name" : "Operators",
+    "type" : "SNMP",
+    "properties" : ""
+  }
+];
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/7a4e7579/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs b/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs
new file mode 100644
index 0000000..201c524
--- /dev/null
+++ b/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs
@@ -0,0 +1,108 @@
+{{!
+* 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.
+}}
+
+{{#if controller.isLoaded}}
+  <div class="row-fluid  manage-configuration-group-content">
+    <div class="span12">
+      <div class="row-fluid">
+        <div class="span4">
+          <span>&nbsp;</span>
+          {{view Em.Select
+          contentBinding="alertNotifications"
+          optionLabelPath="content.name"
+          multiple="multiple"
+          class="group-select"
+          selectionBinding="view.selectedAlertNotification"
+          }}
+          <div class="btn-toolbar pull-right">
+            <button rel="button-info" class="btn"
+              {{translateAttr data-original-title="alerts.actions.manage_alert_notifications_popup.addButton"}}
+              {{action addAlertNotification target="controller"}}><i class="icon-plus"></i></button>
+            <button rel="button-info" class="btn"
+              {{translateAttr data-original-title="alerts.actions.manage_alert_notifications_popup.removeButton"}}
+              {{bindAttr disabled="view.isRemoveButtonDisabled"}}
+              {{action deleteAlertNotification target="controller"}}><i class="icon-minus"></i></button>
+            <div class="btn-group dropup">
+              <button class="btn dropdown-toggle" data-toggle="dropdown">
+                <i class="icon-cog"></i>&nbsp;<span class="caret"></span>
+              </button>
+              <ul class="dropdown-menu">
+                <li {{bindAttr class="view.isEditButtonDisabled:disabled"}}>
+                  <a href="" rel="button-info-dropdown"
+                    {{translateAttr data-original-title="alerts.actions.manage_alert_notifications_popup.editButton"}}
+                    {{action editAlertNotification target="controller"}}>{{t common.edit}}</a>
+                </li>
+                <li {{bindAttr class="view.isDuplicateButtonDisabled:disabled"}}>
+                  <a href="" rel="button-info-dropdown"
+                    {{translateAttr data-original-title="alerts.actions.manage_alert_notifications_popup.duplicateButton"}}
+                    {{action duplicateAlertNotification target="controller"}}>{{t common.duplicate}}</a>
+                </li>
+              </ul>
+            </div>
+          </div>
+        </div>
+        <div class="span8">
+          <span>&nbsp;</span>
+
+          <div class="row-fluid">
+            <div class="span12 pull-right">
+              {{#if selectedAlertNotification}}
+              <div class="row-fluid">
+                <div class="span3">{{t common.name}}</div>
+                <div class="span9">{{selectedAlertNotification.name}}</div>
+              </div>
+              <div class="row-fluid">
+                <div class="span3">{{t common.groups}}</div>
+                <div class="span9">{{view.selectedAlertNotificationGroups}}</div>
+              </div>
+              <div class="row-fluid">
+                <div class="span3">{{t alerts.actions.manage_alert_notifications_popup.method}}</div>
+                <div class="span9">{{selectedAlertNotification.type}}</div>
+              </div>
+              {{#if view.showEmailDetails}}
+                <div class="row-fluid">
+                  <div class="span3">{{t alerts.actions.manage_alert_notifications_popup.email}}</div>
+                  <div class="span9">{{selectedAlertNotification.properties.email}}</div>
+                </div>
+              {{/if}}
+              {{#if view.showSNMPDetails}}
+              {{/if}}
+                <div class="row-fluid">
+                  <div class="span3">{{t common.description}}</div>
+                  <div class="span9">{{selectedAlertNotification.description}}</div>
+                </div>
+              {{/if}}
+            </div>
+          </div>
+        </div>
+        <div class="clearfix"></div>
+        <div class="row-fluid">
+          <div class="span12 text-error" id="manage-config-group-error-div">
+            {{#if view.errorMessage}}
+              {{errorMessage}}
+            {{else}}
+              &nbsp;
+            {{/if}}
+          </div>
+        </div>
+      </div>
+    </div>
+  </div>
+{{else}}
+  <div class="spinner"></div>
+{{/if}}

http://git-wip-us.apache.org/repos/asf/ambari/blob/7a4e7579/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 b271a10..d4a8402 100644
--- a/ambari-web/app/utils/ajax/ajax.js
+++ b/ambari-web/app/utils/ajax/ajax.js
@@ -364,6 +364,10 @@ var urls = {
     'real': '/clusters/{clusterName}/alerts?fields=*',
     'mock': '/data/alerts/alert_instances.json'
   },
+  'alerts.notifications': {
+    'real': '/alert_targets?fields=*',
+    'mock': ''
+  },
   'alerts.instances.by_definition': {
     'real': '/clusters/{clusterName}/alerts?fields=*&Alert/definition_id={definitionId}',
     'mock': '/data/alerts/alert_instances.json'

http://git-wip-us.apache.org/repos/asf/ambari/blob/7a4e7579/ambari-web/app/views.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views.js b/ambari-web/app/views.js
index 50f3147..dab4751 100644
--- a/ambari-web/app/views.js
+++ b/ambari-web/app/views.js
@@ -47,6 +47,7 @@ require('views/main/alerts/alert_definitions_actions_view');
 require('views/main/alerts/definition_configs_view');
 require('views/main/alerts');
 require('views/main/alerts/manage_alert_groups_view');
+require('views/main/alerts/manage_alert_notifications_view');
 require('views/main/charts');
 require('views/main/views/details');
 require('views/main/host');

http://git-wip-us.apache.org/repos/asf/ambari/blob/7a4e7579/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js b/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js
new file mode 100644
index 0000000..4c2255d
--- /dev/null
+++ b/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js
@@ -0,0 +1,97 @@
+/**
+ * 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.
+ */
+
+var App = require('app');
+
+App.ManageAlertNotificationsView = Em.View.extend({
+
+  templateName: require('templates/main/alerts/manage_alert_notifications_popup'),
+
+  selectedAlertNotification: null,
+
+  selectedAlertNotificationGroups: function () {
+    //TODO: Implement binding to AlertGroups
+    return ['Group1', 'Group2'].join(', ');
+  }.property('controller.selectedAlertNotification'),
+
+  isEditButtonDisabled: true,
+
+  isRemoveButtonDisabled: true,
+
+  isDuplicateButtonDisabled: true,
+
+  showEmailDetails: function () {
+    return this.get('controller.selectedAlertNotification.type') === 'EMAIL';
+  }.property('controller.selectedAlertNotification.type'),
+
+  showSNMPDetails: function () {
+    return this.get('controller.selectedAlertNotification.type') === 'SNMP';
+  }.property('controller.selectedAlertNotification.type'),
+
+  buttonObserver: function () {
+    var selectedAlertNotification = this.get('controller.selectedAlertNotification');
+    if (selectedAlertNotification) {
+      this.set('isEditButtonDisabled', false);
+      this.set('isRemoveButtonDisabled', false);
+      this.set('isDuplicateButtonDisabled', false);
+    } else {
+      this.set('isEditButtonDisabled', true);
+      this.set('isRemoveButtonDisabled', true);
+      this.set('isDuplicateButtonDisabled', true);
+    }
+  }.observes('controller.selectedAlertNotification'),
+
+  onAlertNotificationSelect: function () {
+    var selectedAlertNotification = this.get('selectedAlertNotification');
+    var length = selectedAlertNotification.length;
+    if (selectedAlertNotification && length) {
+      this.set('controller.selectedAlertNotification', selectedAlertNotification[length - 1]);
+    }
+    if (selectedAlertNotification && length > 1) {
+      this.set('selectedAlertNotification', selectedAlertNotification[length - 1]);
+    }
+  }.observes('selectedAlertNotification'),
+
+  onLoad: function () {
+    if (this.get('controller.isLoaded')) {
+      var notifications = this.get('controller.alertNotifications');
+      if (notifications && notifications.length) {
+        this.set('selectedAlertNotification', notifications[0]);
+      }  else {
+        this.set('selectedAlertNotification', null);
+      }
+      Em.run.later(this, function () {
+        App.tooltip(this.$("[rel='button-info']"));
+        App.tooltip(this.$("[rel='button-info-dropdown']"), {placement: 'left'});
+      }, 50) ;
+    }
+  }.observes('controller.isLoaded'),
+
+  willInsertElement: function () {
+    this.get('controller').loadAlertNotifications();
+  },
+
+  didInsertElement: function () {
+    this.onLoad();
+  },
+
+  errorMessage: function () {
+    return this.get('controller.errorMessage');
+  }.property('controller.errorMessage')
+
+});