You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2017/11/13 18:33:48 UTC
ambari git commit: AMBARI-22430 Integrate Alert Definitions page with
websocket events. (atkach)
Repository: ambari
Updated Branches:
refs/heads/branch-3.0-perf eb156a92d -> 05cd35982
AMBARI-22430 Integrate Alert Definitions page 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/05cd3598
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/05cd3598
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/05cd3598
Branch: refs/heads/branch-3.0-perf
Commit: 05cd35982b30f424cec0b5b9d93bc4709880a3bc
Parents: eb156a9
Author: Andrii Tkach <at...@apache.org>
Authored: Mon Nov 13 19:00:16 2017 +0200
Committer: Andrii Tkach <at...@apache.org>
Committed: Mon Nov 13 19:00:16 2017 +0200
----------------------------------------------------------------------
ambari-web/app/assets/test/tests.js | 1 +
.../app/controllers/global/update_controller.js | 3 +-
.../alerts/definition_configs_controller.js | 11 +--
ambari-web/app/mappers.js | 1 +
.../app/mappers/alert_definitions_mapper.js | 10 ++-
.../socket/alert_definitions_mapper_adapter.js | 45 +++++++++++
ambari-web/app/utils/stomp_client.js | 2 +-
.../global/update_controller_test.js | 4 +-
.../alert_definitions_mapper_adapter_test.js | 85 ++++++++++++++++++++
ambari-web/test/utils/stomp_client_test.js | 2 +-
10 files changed, 146 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/05cd3598/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 ca980be..eac9967 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -172,6 +172,7 @@ var files = [
'test/mappers/socket/host_component_status_mapper_test',
'test/mappers/socket/service_state_mapper_test',
'test/mappers/socket/host_state_mapper_test',
+ 'test/mappers/socket/alert_definitions_mapper_adapter_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/05cd3598/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 5bd89ea..63a4da4 100644
--- a/ambari-web/app/controllers/global/update_controller.js
+++ b/ambari-web/app/controllers/global/update_controller.js
@@ -193,6 +193,7 @@ App.UpdateController = Em.Controller.extend({
App.StompClient.subscribe('/events/configs', this.makeCallForClusterEnv.bind(this));
App.StompClient.subscribe('/events/services', App.serviceStateMapper.map.bind(App.serviceStateMapper));
App.StompClient.subscribe('/events/hosts', App.hostStateMapper.map.bind(App.hostStateMapper));
+ App.StompClient.subscribe('/events/alert_definitions', App.alertDefinitionsMapperAdapter.map.bind(App.alertDefinitionsMapperAdapter));
App.updater.run(this, 'updateHostsMetrics', 'isWorking', App.contentUpdateInterval, '\/main\/(hosts).*');
App.updater.run(this, 'updateServiceMetric', 'isWorking', App.componentsUpdateInterval, '\/main\/(dashboard|services).*');
@@ -201,7 +202,6 @@ App.UpdateController = Em.Controller.extend({
App.updater.run(this, 'updateComponentConfig', 'isWorking');
App.updater.run(this, 'updateAlertGroups', 'isWorking', App.alertGroupsUpdateInterval, '\/main\/alerts.*');
- App.updater.run(this, 'updateAlertDefinitions', 'isWorking', App.alertDefinitionsUpdateInterval, '\/main\/alerts.*');
if (!App.get('router.mainAlertInstancesController.isUpdating')) {
App.updater.run(this, 'updateUnhealthyAlertInstances', 'updateAlertInstances', App.alertInstancesUpdateInterval, '\/main\/alerts.*');
}
@@ -214,6 +214,7 @@ App.UpdateController = Em.Controller.extend({
App.StompClient.unsubscribe('/events/configs');
App.StompClient.unsubscribe('/events/services');
App.StompClient.unsubscribe('/events/hosts');
+ App.StompClient.unsubscribe('/events/alert_definitions');
}
}.observes('isWorking', 'App.router.mainAlertInstancesController.isUpdating'),
http://git-wip-us.apache.org/repos/asf/ambari/blob/05cd3598/ambari-web/app/controllers/main/alerts/definition_configs_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/alerts/definition_configs_controller.js b/ambari-web/app/controllers/main/alerts/definition_configs_controller.js
index 31e34a9..89aee5b 100644
--- a/ambari-web/app/controllers/main/alerts/definition_configs_controller.js
+++ b/ambari-web/app/controllers/main/alerts/definition_configs_controller.js
@@ -656,20 +656,11 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
data: {
id: this.get('content.id'),
data: this.getPropertiesToUpdate(true)
- },
- success: 'saveConfigsSuccessCallback'
+ }
});
},
/**
- * Success-callback for saveConfigs-request
- * @method saveConfigsSuccessCallback
- */
- saveConfigsSuccessCallback: function () {
- App.router.get('updateController').updateAlertDefinitions(Em.K);
- },
-
- /**
* Create object with new values to put it on server
* @param {boolean} onlyChanged
* @method getPropertiesToUpdate
http://git-wip-us.apache.org/repos/asf/ambari/blob/05cd3598/ambari-web/app/mappers.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers.js b/ambari-web/app/mappers.js
index f4c7e5c..241ba29 100644
--- a/ambari-web/app/mappers.js
+++ b/ambari-web/app/mappers.js
@@ -50,3 +50,4 @@ require('mappers/socket/service_state_mapper');
require('mappers/socket/host_component_status_mapper');
require('mappers/socket/alert_summary_mapper');
require('mappers/socket/host_state_mapper');
+require('mappers/socket/alert_definitions_mapper_adapter');
http://git-wip-us.apache.org/repos/asf/ambari/blob/05cd3598/ambari-web/app/mappers/alert_definitions_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/alert_definitions_mapper.js b/ambari-web/app/mappers/alert_definitions_mapper.js
index ca0ada6..8f5a446 100644
--- a/ambari-web/app/mappers/alert_definitions_mapper.js
+++ b/ambari-web/app/mappers/alert_definitions_mapper.js
@@ -85,7 +85,7 @@ App.alertDefinitionsMapper = App.QuickDataMapper.create({
interval: 'AlertDefinition.source.ams.interval'
},
- map: function (json) {
+ map: function (json, ignoreDelete) {
console.time('App.alertDefinitionsMapper execution time');
if (json && json.items) {
var self = this,
@@ -223,9 +223,11 @@ App.alertDefinitionsMapper = App.QuickDataMapper.create({
}
}, this);
- alertDefinitionsToDelete.forEach(function(definitionId) {
- self.deleteRecord(existingAlertDefinitions.findProperty('id', definitionId));
- });
+ if (!ignoreDelete) {
+ alertDefinitionsToDelete.forEach(function(definitionId) {
+ self.deleteRecord(existingAlertDefinitions.findProperty('id', definitionId));
+ });
+ }
// load all mapped data to model
App.store.safeLoadMany(this.get('reportModel'), alertReportDefinitions);
http://git-wip-us.apache.org/repos/asf/ambari/blob/05cd3598/ambari-web/app/mappers/socket/alert_definitions_mapper_adapter.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/socket/alert_definitions_mapper_adapter.js b/ambari-web/app/mappers/socket/alert_definitions_mapper_adapter.js
new file mode 100644
index 0000000..224a27c
--- /dev/null
+++ b/ambari-web/app/mappers/socket/alert_definitions_mapper_adapter.js
@@ -0,0 +1,45 @@
+/**
+ * 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.alertDefinitionsMapperAdapter = App.QuickDataMapper.create({
+
+ /**
+ * @param {object} event
+ */
+ map: function(event) {
+ event.clusters[App.get('clusterId')].alertDefinitions.forEach((alertDefinition) => {
+ // TODO: remove when fields will be correctly named
+ alertDefinition.id = alertDefinition.definitionId;
+ alertDefinition.component_name = alertDefinition.componentName;
+ alertDefinition.service_name = alertDefinition.serviceName;
+
+ if (event.eventType === 'UPDATE') { // UPDATE/ADD
+ App.alertDefinitionsMapper.map({
+ items: [
+ {
+ AlertDefinition: alertDefinition
+ }
+ ]
+ }, true);
+ } else if (event.eventType === 'DELETE') {
+ this.deleteRecord(App.AlertDefinition.find(alertDefinition.id));
+ }
+ });
+ }
+});
http://git-wip-us.apache.org/repos/asf/ambari/blob/05cd3598/ambari-web/app/utils/stomp_client.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/stomp_client.js b/ambari-web/app/utils/stomp_client.js
index 18167f6..5c4847f 100644
--- a/ambari-web/app/utils/stomp_client.js
+++ b/ambari-web/app/utils/stomp_client.js
@@ -27,7 +27,7 @@ module.exports = Em.Object.extend({
/**
* @type {string}
*/
- webSocketUrl: 'ws://{hostname}:8080/api/stomp/v1',
+ webSocketUrl: 'ws://{hostname}:8080/api/stomp/v1/websocket',
/**
* @type {string}
http://git-wip-us.apache.org/repos/asf/ambari/blob/05cd3598/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 3c17bc3..c42926a 100644
--- a/ambari-web/test/controllers/global/update_controller_test.js
+++ b/ambari-web/test/controllers/global/update_controller_test.js
@@ -74,17 +74,19 @@ describe('App.UpdateController', function () {
expect(App.StompClient.unsubscribe.calledWith('/events/configs')).to.be.true;
expect(App.StompClient.unsubscribe.calledWith('/events/services')).to.be.true;
expect(App.StompClient.unsubscribe.calledWith('/events/hosts')).to.be.true;
+ expect(App.StompClient.unsubscribe.calledWith('/events/alert_definitions')).to.be.true;
});
it('isWorking = true', function () {
controller.set('isWorking', true);
- expect(App.updater.run.callCount).to.equal(10);
+ expect(App.updater.run.callCount).to.equal(9);
expect(App.StompClient.subscribe.calledWith('/events/hostcomponents')).to.be.true;
expect(App.StompClient.subscribe.calledWith('/events/alerts')).to.be.true;
expect(App.StompClient.subscribe.calledWith('/events/ui_topologies')).to.be.true;
expect(App.StompClient.subscribe.calledWith('/events/configs')).to.be.true;
expect(App.StompClient.subscribe.calledWith('/events/services')).to.be.true;
expect(App.StompClient.subscribe.calledWith('/events/hosts')).to.be.true;
+ expect(App.StompClient.subscribe.calledWith('/events/alert_definitions')).to.be.true;
});
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/05cd3598/ambari-web/test/mappers/socket/alert_definitions_mapper_adapter_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mappers/socket/alert_definitions_mapper_adapter_test.js b/ambari-web/test/mappers/socket/alert_definitions_mapper_adapter_test.js
new file mode 100644
index 0000000..49b8aa4
--- /dev/null
+++ b/ambari-web/test/mappers/socket/alert_definitions_mapper_adapter_test.js
@@ -0,0 +1,85 @@
+/**
+ * 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/alert_definitions_mapper_adapter');
+
+describe('App.alertDefinitionsMapperAdapter', function () {
+
+ describe('#map', function() {
+ beforeEach(function() {
+ sinon.stub(App.alertDefinitionsMapper, 'map');
+ sinon.stub(App.AlertDefinition, 'find').returns({});
+ sinon.stub(App.alertDefinitionsMapperAdapter, 'deleteRecord');
+ App.set('clusterId', 1);
+ });
+ afterEach(function() {
+ App.alertDefinitionsMapper.map.restore();
+ App.AlertDefinition.find.restore();
+ App.alertDefinitionsMapperAdapter.deleteRecord.restore();
+ });
+
+ it('should call App.alertDefinitionsMapper.map on UPDATE event', function() {
+ var event = {
+ eventType: 'UPDATE',
+ clusters: {
+ 1: {
+ alertDefinitions: [
+ {
+ definitionId: 1,
+ componentName: 'C1',
+ serviceName: 'S1'
+ }
+ ]
+ }
+ }
+ };
+ App.alertDefinitionsMapperAdapter.map(event);
+ expect(App.alertDefinitionsMapper.map.getCall(0).args[0]).to.be.eql({
+ items: [{
+ AlertDefinition: {
+ id: 1,
+ component_name: 'C1',
+ service_name: 'S1',
+ definitionId: 1,
+ componentName: 'C1',
+ serviceName: 'S1'
+ }
+ }]
+ });
+ });
+
+ it('should call deleteRecord on DELETE event', function() {
+ var event = {
+ eventType: 'DELETE',
+ clusters: {
+ 1: {
+ alertDefinitions: [
+ {
+ definitionId: 1
+ }
+ ]
+ }
+ }
+ };
+ App.alertDefinitionsMapperAdapter.map(event);
+ expect(App.alertDefinitionsMapperAdapter.deleteRecord.calledWith({})).to.be.true;
+ });
+ });
+});
http://git-wip-us.apache.org/repos/asf/ambari/blob/05cd3598/ambari-web/test/utils/stomp_client_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/utils/stomp_client_test.js b/ambari-web/test/utils/stomp_client_test.js
index 5ee7a5e..48b2e25 100644
--- a/ambari-web/test/utils/stomp_client_test.js
+++ b/ambari-web/test/utils/stomp_client_test.js
@@ -67,7 +67,7 @@ describe('App.StompClient', function () {
describe('#getSocket', function() {
it('should return WebSocket instance', function() {
- expect(stomp.getSocket().URL).to.be.equal('ws://:8080/api/stomp/v1');
+ expect(stomp.getSocket().URL).to.be.equal('ws://:8080/api/stomp/v1/websocket');
});
it('should return SockJS instance', function() {
expect(stomp.getSocket(true).url).to.be.equal('http://:8080/api/stomp/v1');