From b3f1726eb1d5f3b8657a172e902c74043579a655 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 2 Jun 2016 08:54:25 -0700 Subject: [PATCH 1/2] Adding alpha to non-upgradeable config list --- src/plugins/elasticsearch/lib/__tests__/is_upgradeable.js | 1 + src/plugins/elasticsearch/lib/is_upgradeable.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/elasticsearch/lib/__tests__/is_upgradeable.js b/src/plugins/elasticsearch/lib/__tests__/is_upgradeable.js index bc527560acf5..56713adcaeae 100644 --- a/src/plugins/elasticsearch/lib/__tests__/is_upgradeable.js +++ b/src/plugins/elasticsearch/lib/__tests__/is_upgradeable.js @@ -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 = { diff --git a/src/plugins/elasticsearch/lib/is_upgradeable.js b/src/plugins/elasticsearch/lib/is_upgradeable.js index 115cdbe138e7..2da4012d01e5 100644 --- a/src/plugins/elasticsearch/lib/is_upgradeable.js +++ b/src/plugins/elasticsearch/lib/is_upgradeable.js @@ -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; From acbd03e8eab592d5150f53476f5116c2c902dfd3 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 2 Jun 2016 09:38:12 -0700 Subject: [PATCH 2/2] If no configs are upgradeable, create a new config --- .../lib/__tests__/upgrade_config.js | 14 +++++++++--- .../elasticsearch/lib/upgrade_config.js | 22 ++++++++++++------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/plugins/elasticsearch/lib/__tests__/upgrade_config.js b/src/plugins/elasticsearch/lib/__tests__/upgrade_config.js index de3d5cf5dd6f..fb871ba001a9 100644 --- a/src/plugins/elasticsearch/lib/__tests__/upgrade_config.js +++ b/src/plugins/elasticsearch/lib/__tests__/upgrade_config.js @@ -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'); }); }); diff --git a/src/plugins/elasticsearch/lib/upgrade_config.js b/src/plugins/elasticsearch/lib/upgrade_config.js index f0919efd319f..9050767d969a 100644 --- a/src/plugins/elasticsearch/lib/upgrade_config.js +++ b/src/plugins/elasticsearch/lib/upgrade_config.js @@ -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 @@ -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