ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From atk...@apache.org
Subject ambari git commit: AMBARI-21203 Integrate Alerts notifications with websocket events. (atkach)
Date Thu, 08 Jun 2017 16:45:11 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-3.0-perf c8aecb772 -> 12df64fe3


AMBARI-21203 Integrate Alerts notifications with websocket events. (atkach)


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

Branch: refs/heads/branch-3.0-perf
Commit: 12df64fe339473f04b9afa14ad08100fd2c60cd6
Parents: c8aecb7
Author: Andrii Tkach <atkach@apache.org>
Authored: Thu Jun 8 19:01:32 2017 +0300
Committer: Andrii Tkach <atkach@apache.org>
Committed: Thu Jun 8 19:01:32 2017 +0300

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js             |  1 +
 .../global/background_operations_controller.js  |  7 +-
 .../app/controllers/global/update_controller.js | 17 ++---
 ambari-web/app/mappers.js                       |  3 +-
 ambari-web/app/mappers/socket_events_mapper.js  | 44 ++++++++++++
 .../common/host_progress_popup_body_view.js     |  2 +-
 .../global/background_operations_test.js        |  4 +-
 .../global/update_controller_test.js            | 36 ++--------
 .../test/mappers/socket_events_mapper_test.js   | 74 ++++++++++++++++++++
 9 files changed, 138 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/12df64fe/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index 4e4133d..23d9f66 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -166,6 +166,7 @@ var files = [
   'test/mappers/configs/config_groups_mapper_test',
   'test/mappers/configs/service_config_version_mapper_test',
   'test/mappers/configs/themes_mapper_test',
+  'test/mappers/socket_events_mapper_test',
   'test/mixins/common/configs/enhanced_configs_test',
   'test/mixins/common/configs/config_recommendations_test',
   'test/mixins/common/configs/config_recommendation_parser_test',

http://git-wip-us.apache.org/repos/asf/ambari/blob/12df64fe/ambari-web/app/controllers/global/background_operations_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/background_operations_controller.js b/ambari-web/app/controllers/global/background_operations_controller.js
index 8be7b87..c05337c 100644
--- a/ambari-web/app/controllers/global/background_operations_controller.js
+++ b/ambari-web/app/controllers/global/background_operations_controller.js
@@ -199,7 +199,7 @@ App.BackgroundOperationsController = Em.Controller.extend({
     var request = this.get('services').findProperty('id', levelInfo.get('requestId'));
 
     if (levelInfo.get('name') === 'HOSTS_LIST') {
-      return !!(request && App.isEmptyObject(request.get('hostsMap')));
+      return Boolean(request && !request.get('hostsLevelLoaded'));
     }
     return false;
   },
@@ -250,19 +250,20 @@ App.BackgroundOperationsController = Em.Controller.extend({
       task.Tasks.request_inputs = requestInputs;
       if (host) {
         host.logTasks.push(task);
-        host.isModified = (host.isModified) ? true : previousTaskStatusMap[task.Tasks.id]
!== task.Tasks.status;
+        host.isModified = true;
       } else {
         hostsMap[task.Tasks.host_name] = {
           name: task.Tasks.host_name,
           publicName: task.Tasks.host_name,
           logTasks: [task],
-          isModified: previousTaskStatusMap[task.Tasks.id] !== task.Tasks.status
+          isModified: true
         };
       }
       currentTaskStatusMap[task.Tasks.id] = task.Tasks.status;
     }, this);
     request.set('previousTaskStatusMap', currentTaskStatusMap);
     request.set('hostsMap', hostsMap);
+    request.set('hostsLevelLoaded', true);
     this.set('serviceTimestamp', App.dateTime());
   },
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/12df64fe/ambari-web/app/controllers/global/update_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/update_controller.js b/ambari-web/app/controllers/global/update_controller.js
index 28fac62..e7ed53f 100644
--- a/ambari-web/app/controllers/global/update_controller.js
+++ b/ambari-web/app/controllers/global/update_controller.js
@@ -186,8 +186,11 @@ App.UpdateController = Em.Controller.extend({
    * Start polling, when <code>isWorking</code> become true
    */
   updateAll: function () {
+    var socket = App.socketEventsMapper;
     if (this.get('isWorking') && !App.get('isOnlyViewUser')) {
-      this.subscribeToHostComponentsStatus();
+      //TODO limit updates by location
+      App.StompClient.subscribe('/events/hostcomponents', socket.applyHostComponentStatusEvents.bind(socket));
+      App.StompClient.subscribe('/events/alerts', socket.applyAlertDefinitionSummaryEvents.bind(socket));
 
       App.updater.run(this, 'updateServices', 'isWorking');
       App.updater.run(this, 'updateHost', 'isWorking');
@@ -198,7 +201,6 @@ App.UpdateController = Em.Controller.extend({
 
       App.updater.run(this, 'updateAlertGroups', 'isWorking', App.alertGroupsUpdateInterval,
'\/main\/alerts.*');
       App.updater.run(this, 'updateAlertDefinitions', 'isWorking', App.alertDefinitionsUpdateInterval,
'\/main\/alerts.*');
-      App.updater.run(this, 'updateAlertDefinitionSummary', 'isWorking', App.alertDefinitionsUpdateInterval);
       if (!App.get('router.mainAlertInstancesController.isUpdating')) {
         App.updater.run(this, 'updateUnhealthyAlertInstances', 'updateAlertInstances', App.alertInstancesUpdateInterval,
'\/main\/alerts.*');
       }
@@ -207,19 +209,10 @@ App.UpdateController = Em.Controller.extend({
       App.updater.run(this, 'updateWizardWatcher', 'isWorking', App.bgOperationsUpdateInterval);
     } else {
       App.StompClient.unsubscribe('/events/hostcomponents');
+      App.StompClient.unsubscribe('/events/alerts');
     }
   }.observes('isWorking', 'App.router.mainAlertInstancesController.isUpdating'),
 
-  subscribeToHostComponentsStatus: function() {
-    //TODO limit updates by location
-    App.StompClient.subscribe('/events/hostcomponents', (event) => {
-      const hostComponent = App.HostComponent.find(event.componentName + '_' + event.hostName);
-      if (hostComponent.get('isLoaded')) {
-        hostComponent.set('workStatus', event.currentState);
-      }
-    });
-  },
-
   /**
    *
    * @param {Function} callback

http://git-wip-us.apache.org/repos/asf/ambari/blob/12df64fe/ambari-web/app/mappers.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers.js b/ambari-web/app/mappers.js
index cde9bcc..d77c834 100644
--- a/ambari-web/app/mappers.js
+++ b/ambari-web/app/mappers.js
@@ -44,4 +44,5 @@ require('mappers/alert_notification_mapper');
 require('mappers/root_service_mapper');
 require('mappers/widget_mapper');
 require('mappers/widget_layout_mapper');
-require('mappers/stack_upgrade_history_mapper');
\ No newline at end of file
+require('mappers/stack_upgrade_history_mapper');
+require('mappers/socket_events_mapper');
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/12df64fe/ambari-web/app/mappers/socket_events_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/socket_events_mapper.js b/ambari-web/app/mappers/socket_events_mapper.js
new file mode 100644
index 0000000..df2c1cd
--- /dev/null
+++ b/ambari-web/app/mappers/socket_events_mapper.js
@@ -0,0 +1,44 @@
+/**
+ * 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.socketEventsMapper = App.QuickDataMapper.create({
+
+  /**
+   * @param {object} event
+   */
+  applyAlertDefinitionSummaryEvents: function(event) {
+    const data = {
+      alerts_summary_grouped: []
+    };
+    for (let name in event.summaries) {
+      data.alerts_summary_grouped.push(event.summaries[name]);
+    }
+    App.alertDefinitionSummaryMapper.map(data);
+  },
+
+  /**
+   * @param {object} event
+   */
+  applyHostComponentStatusEvents: function (event) {
+    const hostComponent = App.HostComponent.find(event.componentName + '_' + event.hostName);
+    if (hostComponent.get('isLoaded')) {
+      hostComponent.set('workStatus', event.currentState);
+    }
+  }
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/12df64fe/ambari-web/app/views/common/host_progress_popup_body_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/host_progress_popup_body_view.js b/ambari-web/app/views/common/host_progress_popup_body_view.js
index 5cce8e7..767c86b 100644
--- a/ambari-web/app/views/common/host_progress_popup_body_view.js
+++ b/ambari-web/app/views/common/host_progress_popup_body_view.js
@@ -847,7 +847,7 @@ App.HostProgressPopupBodyView = App.TableView.extend({
    */
   gotoTasks: function (event) {
     var tasksInfo = [];
-    event.context.logTasks.forEach(function (_task) {
+    this.get('pageContent').findProperty('name', event.context.get('name')).get('logTasks').forEach(function
(_task) {
       tasksInfo.pushObject(this.get("controller").createTask(_task));
     }, this);
     if (tasksInfo.length) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/12df64fe/ambari-web/test/controllers/global/background_operations_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/global/background_operations_test.js b/ambari-web/test/controllers/global/background_operations_test.js
index 8f0c79e..43b2170 100644
--- a/ambari-web/test/controllers/global/background_operations_test.js
+++ b/ambari-web/test/controllers/global/background_operations_test.js
@@ -542,9 +542,7 @@ describe('App.BackgroundOperationsController', function () {
       }));
       controller.set('services', [Em.Object.create({
         id: 1,
-        hostsMap: {
-          'host1': {}
-        }
+        hostsLevelLoaded: true
       })]);
       expect(controller.isInitLoading()).to.be.false;
     });

http://git-wip-us.apache.org/repos/asf/ambari/blob/12df64fe/ambari-web/test/controllers/global/update_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/global/update_controller_test.js b/ambari-web/test/controllers/global/update_controller_test.js
index 4c50444..eafa032 100644
--- a/ambari-web/test/controllers/global/update_controller_test.js
+++ b/ambari-web/test/controllers/global/update_controller_test.js
@@ -57,12 +57,12 @@ describe('App.UpdateController', function () {
 
   describe('#updateAll()', function () {
     beforeEach(function() {
-      sinon.stub(controller, 'subscribeToHostComponentsStatus');
       sinon.stub(App.StompClient, 'unsubscribe');
+      sinon.stub(App.StompClient, 'subscribe');
     });
     afterEach(function() {
-      controller.subscribeToHostComponentsStatus.restore();
       App.StompClient.unsubscribe.restore();
+      App.StompClient.subscribe.restore();
     });
 
     it('isWorking = false', function () {
@@ -70,38 +70,14 @@ describe('App.UpdateController', function () {
       controller.updateAll();
       expect(App.updater.run.called).to.equal(false);
       expect(App.StompClient.unsubscribe.calledWith('/events/hostcomponents')).to.be.true;
+      expect(App.StompClient.unsubscribe.calledWith('/events/alerts')).to.be.true;
     });
 
     it('isWorking = true', function () {
       controller.set('isWorking', true);
-      expect(App.updater.run.callCount).to.equal(13);
-      expect(controller.subscribeToHostComponentsStatus.calledOnce).to.be.true;
-    });
-  });
-
-  describe('#subscribeToHostComponentsStatus', function() {
-    var hc = Em.Object.create({
-      workStatus: 'INSTALLED',
-      isLoaded: true
-    });
-    beforeEach(function() {
-      sinon.stub(App.StompClient, 'subscribe', function(topic, callback) {
-        callback({
-          componentName: 'C1',
-          hostName: 'host1',
-          currentState: 'STARTED'
-        });
-      });
-      sinon.stub(App.HostComponent, 'find').returns(hc);
-    });
-    afterEach(function() {
-      App.StompClient.subscribe.restore();
-      App.HostComponent.find.restore();
-    });
-
-    it('host-component should have STARTED status', function() {
-      controller.subscribeToHostComponentsStatus();
-      expect(hc.get('workStatus')).to.be.equal('STARTED');
+      expect(App.updater.run.callCount).to.equal(12);
+      expect(App.StompClient.subscribe.calledWith('/events/hostcomponents')).to.be.true;
+      expect(App.StompClient.subscribe.calledWith('/events/alerts')).to.be.true;
     });
   });
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/12df64fe/ambari-web/test/mappers/socket_events_mapper_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mappers/socket_events_mapper_test.js b/ambari-web/test/mappers/socket_events_mapper_test.js
new file mode 100644
index 0000000..d7391d6
--- /dev/null
+++ b/ambari-web/test/mappers/socket_events_mapper_test.js
@@ -0,0 +1,74 @@
+/**
+ * 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');
+
+require('mappers/socket_events_mapper');
+
+describe('App.socketEventsMapper', function () {
+
+  describe('#applyHostComponentStatusEvents', function() {
+    var hc = Em.Object.create({
+      workStatus: 'INSTALLED',
+      isLoaded: true
+    });
+    beforeEach(function() {
+      sinon.stub(App.HostComponent, 'find').returns(hc);
+    });
+    afterEach(function() {
+      App.HostComponent.find.restore();
+    });
+
+    it('host-component should have STARTED status', function() {
+      const event = {
+        componentName: 'C1',
+        hostName: 'host1',
+        currentState: 'STARTED'
+      };
+      App.socketEventsMapper.applyHostComponentStatusEvents(event);
+      expect(hc.get('workStatus')).to.be.equal('STARTED');
+    });
+  });
+
+  describe('#applyAlertDefinitionSummaryEvents', function() {
+    beforeEach(function() {
+      sinon.stub(App.alertDefinitionSummaryMapper, 'map');
+    });
+    afterEach(function() {
+      App.alertDefinitionSummaryMapper.map.restore();
+    });
+
+    it('App.alertDefinitionSummaryMapper.map should be called', function() {
+      const event = {
+        summaries: {
+          d1: {
+            definition_name: 'd1'
+          }
+        }
+      };
+      App.socketEventsMapper.applyAlertDefinitionSummaryEvents(event);
+      expect(App.alertDefinitionSummaryMapper.map.calledWith({
+        alerts_summary_grouped: [
+          {
+            definition_name: 'd1'
+          }
+        ]
+      })).to.be.true;
+    });
+  });
+});


Mime
View raw message