Skip to content

Commit

Permalink
Merge pull request #7356 from ycombinator/gh-7353
Browse files Browse the repository at this point in the history
If there is no upgradeable config, create a new one
  • Loading branch information
ycombinator committed Jun 6, 2016
2 parents e60f58a + acbd03e commit 36beb93
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/plugins/elasticsearch/lib/__tests__/is_upgradeable.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('plugins/elasticsearch', function () {
upgradeDoc('4.0.0-rc1', '4.0.0', true);
upgradeDoc('4.0.0-rc1-snapshot', '4.0.0', false);
upgradeDoc('4.1.0-rc1-snapshot', '4.1.0-rc1', false);
upgradeDoc('5.0.0-alpha1', '5.0.0', false);

it('should handle missing _id field', function () {
let doc = {
Expand Down
14 changes: 11 additions & 3 deletions src/plugins/elasticsearch/lib/__tests__/upgrade_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,18 @@ describe('plugins/elasticsearch', function () {
});
});

it('should resolve with undefined if the nothing is upgradeable', function () {
const response = { hits: { hits: [ { _id: '4.0.1-beta1' }, { _id: '4.0.0-snapshot1' } ] } };
it('should create new config if the nothing is upgradeable', function () {
get.withArgs('pkg.buildNum').returns(9833);
client.create.returns(Promise.resolve());
const response = { hits: { hits: [ { _id: '4.0.1-alpha3' }, { _id: '4.0.1-beta1' }, { _id: '4.0.0-snapshot1' } ] } };
return upgrade(response).then(function (resp) {
expect(resp).to.be(undefined);
sinon.assert.calledOnce(client.create);
const params = client.create.args[0][0];
expect(params).to.have.property('body');
expect(params.body).to.have.property('buildNum', 9833);
expect(params).to.have.property('index', '.my-kibana');
expect(params).to.have.property('type', 'config');
expect(params).to.have.property('id', '4.0.1');
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/elasticsearch/lib/is_upgradeable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const rcVersionRegex = /(\d+\.\d+\.\d+)\-rc(\d+)/i;

module.exports = function (server, doc) {
const config = server.config();
if (/beta|snapshot/i.test(doc._id)) return false;
if (/alpha|beta|snapshot/i.test(doc._id)) return false;
if (!doc._id) return false;
if (doc._id === config.get('pkg.version')) return false;

Expand Down
22 changes: 14 additions & 8 deletions src/plugins/elasticsearch/lib/upgrade_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ module.exports = function (server) {
const client = server.plugins.elasticsearch.client;
const config = server.config();

function createNewConfig() {
return client.create({
index: config.get('kibana.index'),
type: 'config',
body: { buildNum: config.get('pkg.buildNum') },
id: config.get('pkg.version')
});
}

return function (response) {
const newConfig = {};

// Check to see if there are any doc. If not then we set the build number and id
if (response.hits.hits.length === 0) {
return client.create({
index: config.get('kibana.index'),
type: 'config',
body: { buildNum: config.get('pkg.buildNum') },
id: config.get('pkg.version')
});
return createNewConfig();
}

// if we already have a the current version in the index then we need to stop
Expand All @@ -30,9 +34,11 @@ module.exports = function (server) {
if (devConfig) return Promise.resolve();

// Look for upgradeable configs. If none of them are upgradeable
// then resolve with null.
// then create a new one.
const body = _.find(response.hits.hits, isUpgradeable.bind(null, server));
if (!body) return Promise.resolve();
if (!body) {
return createNewConfig();
}

// if the build number is still the template string (which it wil be in development)
// then we need to set it to the max interger. Otherwise we will set it to the build num
Expand Down

0 comments on commit 36beb93

Please sign in to comment.