Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Commit

Permalink
added version compatibility check
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Menezes committed Jan 15, 2016
1 parent 64f0bba commit 250ede7
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
22 changes: 22 additions & 0 deletions _site/dist/kopf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down Expand Up @@ -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 : '';
};
Expand Down
18 changes: 18 additions & 0 deletions src/kopf/controllers/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
4 changes: 4 additions & 0 deletions src/kopf/services/elastic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : '';
};
Expand Down
21 changes: 21 additions & 0 deletions tests/jasmine/global.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

});
5 changes: 5 additions & 0 deletions tests/jasmine/services/elastic.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

});

0 comments on commit 250ede7

Please sign in to comment.