From 250ede716d90c6d1ec95afa80712cd9cdb7dfee5 Mon Sep 17 00:00:00 2001 From: Leonardo Menezes Date: Fri, 15 Jan 2016 17:37:33 +0100 Subject: [PATCH] added version compatibility check --- _site/dist/kopf.js | 22 ++++++++++++++++++++++ src/kopf/controllers/global.js | 18 ++++++++++++++++++ src/kopf/services/elastic.js | 4 ++++ tests/jasmine/global.tests.js | 21 +++++++++++++++++++++ tests/jasmine/services/elastic.tests.js | 5 +++++ 5 files changed, 70 insertions(+) diff --git a/_site/dist/kopf.js b/_site/dist/kopf.js index b580c681..3c7a72f5 100644 --- a/_site/dist/kopf.js +++ b/_site/dist/kopf.js @@ -1226,6 +1226,24 @@ kopf.controller('GlobalController', ['$scope', '$location', '$sce', '$window', $scope.modal = new ModalControls(); + $scope.$watch( + function() { + return ElasticService.cluster; + }, + function(newValue, oldValue) { + var version = ElasticService.getVersion(); + if (version && version.isValid()) { + var major = version.getMajor(); + if (major != parseInt($scope.version.charAt(0))) { + AlertService.warn( + 'This version of kopf is not compatible with your ES version', + 'Upgrading to newest supported version is recommeded' + ); + } + } + } + ); + $scope.getTheme = function() { return ExternalSettingsService.getTheme(); }; @@ -4657,6 +4675,10 @@ kopf.factory('ElasticService', ['$http', '$q', '$timeout', '$location', } }; + this.getVersion = function() { + return this.version; + }; + this.getHost = function() { return this.isConnected() ? this.connection.host : ''; }; diff --git a/src/kopf/controllers/global.js b/src/kopf/controllers/global.js index 8509d8f3..6b0ffed1 100644 --- a/src/kopf/controllers/global.js +++ b/src/kopf/controllers/global.js @@ -7,6 +7,24 @@ kopf.controller('GlobalController', ['$scope', '$location', '$sce', '$window', $scope.modal = new ModalControls(); + $scope.$watch( + function() { + return ElasticService.cluster; + }, + function(newValue, oldValue) { + var version = ElasticService.getVersion(); + if (version && version.isValid()) { + var major = version.getMajor(); + if (major != parseInt($scope.version.charAt(0))) { + AlertService.warn( + 'This version of kopf is not compatible with your ES version', + 'Upgrading to newest supported version is recommeded' + ); + } + } + } + ); + $scope.getTheme = function() { return ExternalSettingsService.getTheme(); }; diff --git a/src/kopf/services/elastic.js b/src/kopf/services/elastic.js index 77b102d9..2afb3025 100755 --- a/src/kopf/services/elastic.js +++ b/src/kopf/services/elastic.js @@ -142,6 +142,10 @@ kopf.factory('ElasticService', ['$http', '$q', '$timeout', '$location', } }; + this.getVersion = function() { + return this.version; + }; + this.getHost = function() { return this.isConnected() ? this.connection.host : ''; }; diff --git a/tests/jasmine/global.tests.js b/tests/jasmine/global.tests.js index 6e449fcd..17b624e3 100644 --- a/tests/jasmine/global.tests.js +++ b/tests/jasmine/global.tests.js @@ -108,4 +108,25 @@ describe('GlobalController', function() { expect(this.ElasticService.connect).toHaveBeenCalledWith('http://thishost:4321'); }); + it('should warn if not supported version is found', function() { + this.ElasticService.getVersion = function(){}; + spyOn(this.ElasticService, 'getVersion').andReturn(new Version('1.0.0')); + spyOn(this.AlertService, 'warn').andReturn(''); + this.ElasticService.cluster = ''; + this.scope.$digest(); + expect(this.AlertService.warn).toHaveBeenCalledWith( + 'This version of kopf is not compatible with your ES version', + 'Upgrading to newest supported version is recommeded' + ); + }); + + it('should NOT warn if supported version is found', function() { + this.ElasticService.getVersion = function(){}; + spyOn(this.ElasticService, 'getVersion').andReturn(new Version('2.0.0')); + spyOn(this.AlertService, 'warn').andReturn(''); + this.ElasticService.cluster = ''; + this.scope.$digest(); + expect(this.AlertService.warn).not.toHaveBeenCalledWith(); + }); + }); \ No newline at end of file diff --git a/tests/jasmine/services/elastic.tests.js b/tests/jasmine/services/elastic.tests.js index 5db5f3e3..c62e35ac 100644 --- a/tests/jasmine/services/elastic.tests.js +++ b/tests/jasmine/services/elastic.tests.js @@ -688,4 +688,9 @@ describe("ElasticService", function() { expect(callbacks.error).toHaveBeenCalledWith({notreallyusingtheresponse:{}}); }); + it("should return the correct versiom", function() { + elasticService.setVersion('1.2.0'); + expect(elasticService.getVersion().getValue()).toEqual('1.2.0'); + }); + });