-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored the setup service, moved into a component, added ES versio…
…n check #73
- Loading branch information
Spencer Alger
committed
May 6, 2014
1 parent
950cfcc
commit 3835b38
Showing
12 changed files
with
197 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
define(function (require) { | ||
return function SetupErrorFactory(configFile) { | ||
var _ = require('lodash'); | ||
|
||
function SetupError(template, err) { | ||
// don't override other setup errors | ||
if (err && err instanceof SetupError) return err; | ||
|
||
var err2 = new Error(_.template(template, { configFile: configFile })); | ||
if (err) { | ||
err2.origError = err; | ||
if (err.stack) err2.stack = err.stack; | ||
} | ||
return err2; | ||
} | ||
return SetupError; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
var $ = require('jquery'); | ||
|
||
require('notify/notify'); | ||
|
||
require('modules').get('kibana/services') | ||
.service('kbnSetup', function (Private, Promise, Notifier, es, configFile) { | ||
// setup steps | ||
var checkForEs = Private(require('./steps/check_for_es')); | ||
var checkEsVersion = Private(require('./steps/check_es_version')); | ||
var checkForKibanaIndex = Private(require('./steps/check_for_kibana_index')); | ||
var createKibanaIndex = Private(require('./steps/create_kibana_index')); | ||
|
||
var notify = new Notifier({ location: 'Setup' }); | ||
|
||
return _.once(function () { | ||
notify.lifecycle('bootstrap'); | ||
|
||
return checkForEs() | ||
.then(checkEsVersion) | ||
.then(checkForKibanaIndex) | ||
.then(function (exists) { | ||
if (!exists) return createKibanaIndex(); | ||
}) | ||
.finally(function () { | ||
notify.lifecycle('bootstrap', true); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
define(function (require) { | ||
return function CheckEsVersionFn(Private, es, configFile, Notifier) { | ||
return function checkEsVersion() { | ||
var notify = new Notifier({ location: 'Setup: Elasticsearch version check' }); | ||
var complete = notify.lifecycle('check es version'); | ||
|
||
var SetupError = Private(require('../_setup_error')); | ||
|
||
|
||
// core expression for finding a version | ||
var versionExp = '([\\d\\.]*\\d)(?:\\.\\w+)?'; | ||
|
||
/** | ||
* Regular Expression to extract a version number from a string | ||
* @type {RegExp} | ||
*/ | ||
var versionRE = new RegExp(versionExp); | ||
|
||
/** | ||
* Regular Expression to extract a version range from a string | ||
* @type {RegExp} | ||
*/ | ||
var versionRangeRE = new RegExp(versionExp + '\\s*\\-\\s*' + versionExp); | ||
|
||
var int = function (txt) { | ||
var i = parseInt(txt, 10); | ||
return (!i || isNaN(i)) ? 0 : i; | ||
}; | ||
|
||
return es.info() | ||
.then(function (info) { | ||
var raw = info.version.number; | ||
var sections = raw.split('-'); | ||
var someTypeOfBeta = sections.length > 1; | ||
var all = sections.shift().split('.'); | ||
var major = int(all.shift()); | ||
var minor = int(all.shift()); | ||
var patch = int(all.shift()); | ||
|
||
var currentRelease = major === 1 && minor >= 1; | ||
var betaPreRelease = major === 1 && minor === 0 && someTypeOfBeta; | ||
|
||
if (currentRelease || betaPreRelease) return true; | ||
else throw SetupError('Incompatible Elasticsearch version "' + raw + '". Expected version 1.1 or a 1.0-Beta release'); | ||
}) | ||
.then(complete, complete.failure); | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
define(function (require) { | ||
return function checkForEsFunction(Private, Notifier, es, configFile) { | ||
var SetupError = Private(require('../_setup_error')); | ||
var notify = new Notifier({ location: 'Setup: Elasticsearch check' }); | ||
|
||
return function checkForES() { | ||
var complete = notify.lifecycle('es check'); | ||
return es.ping({ | ||
requestTimeout: 2000 | ||
}) | ||
.catch(function (err) { | ||
throw new SetupError('Unable to connect to Elasticsearch at "<%= configFile.elasticsearch %>"', err); | ||
}) | ||
.then(complete, complete.failure); | ||
}; | ||
}; | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/kibana/components/setup/steps/check_for_kibana_index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
define(function (require) { | ||
return function CheckForKibanaIndexFn(Private, es, Notifier, configFile) { | ||
var SetupError = Private(require('../_setup_error')); | ||
var notify = new Notifier({ location: 'Setup: Kibana index check' }); | ||
|
||
return function checkForKibana() { | ||
var complete = notify.lifecycle('kibana index check'); | ||
return es.indices.exists({ | ||
index: configFile.kibanaIndex | ||
}) | ||
.catch(function (err) { | ||
throw new SetupError('Unable to check for Kibana index "<%= configFile.kibanaIndex %>"', err); | ||
}) | ||
.then(complete, complete.failure); | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
define(function (require) { | ||
return function CreateKibanaIndexFn(Private, es, configFile, Notifier) { | ||
return function createKibanaIndex() { | ||
var notify = new Notifier({ location: 'Setup: Kibana Index Creation' }); | ||
var complete = notify.lifecycle('kibana index creation'); | ||
|
||
var SetupError = Private(require('../_setup_error')); | ||
|
||
return es.indices.create({ | ||
index: configFile.kibanaIndex, | ||
body: { | ||
settings: { | ||
mappings: { | ||
mappings: { | ||
_source: { | ||
enabled: false | ||
}, | ||
properties: { | ||
type: { | ||
type: 'string', | ||
index: 'not_analyzed' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
.catch(function (err) { | ||
throw new SetupError('Unable to create Kibana index "<%= configFile.kibanaIndex %>"', err); | ||
}) | ||
.then(function () { | ||
return es.cluster.health({ | ||
waitForStatus: 'yellow', | ||
index: configFile.kibanaIndex | ||
}); | ||
}) | ||
.catch(function (err) { | ||
throw new SetupError('Waiting for Kibana index "<%= configFile.kibanaIndex %>" to come online failed', err); | ||
}) | ||
.then(complete, complete.failure); | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.