mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Move updateConfigDoc method out of scenario_manager and into its own support/es_client.
This commit is contained in:
parent
53ede1a4ca
commit
ac4a0ed748
4 changed files with 70 additions and 50 deletions
48
test/fixtures/scenario_manager.js
vendored
48
test/fixtures/scenario_manager.js
vendored
|
@ -140,52 +140,4 @@ ScenarioManager.prototype.loadIfEmpty = function (id) {
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Add fields to the config doc (like setting timezone and defaultIndex)
|
||||
* @return {Promise} A promise that is resolved when elasticsearch has a response
|
||||
*/
|
||||
ScenarioManager.prototype.updateConfigDoc = function (docMap) {
|
||||
// first we need to get the config doc's id so we can use it in our _update call
|
||||
var self = this;
|
||||
var configId;
|
||||
var docMapString = JSON.stringify(docMap);
|
||||
|
||||
return this.client.search({
|
||||
index: '.kibana',
|
||||
type: 'config'
|
||||
})
|
||||
.then(function (response) {
|
||||
if (response.errors) {
|
||||
throw new Error(
|
||||
'get config failed\n' +
|
||||
response.items
|
||||
.map(i => i[Object.keys(i)[0]].error)
|
||||
.filter(Boolean)
|
||||
.map(err => ' ' + JSON.stringify(err))
|
||||
.join('\n')
|
||||
);
|
||||
} else {
|
||||
configId = response.hits.hits[0]._id;
|
||||
console.log('config._id =' + configId);
|
||||
}
|
||||
})
|
||||
// now that we have the id, we can update
|
||||
// return scenarioManager.updateConfigDoc({'dateFormat:tz':'UTC', 'defaultIndex':'logstash-*'});
|
||||
.then(function (response) {
|
||||
console.log('updating config with ' + docMapString);
|
||||
return self.client.update({
|
||||
index: '.kibana',
|
||||
type: 'config',
|
||||
id: configId,
|
||||
body: {
|
||||
'doc':
|
||||
docMap
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(function (err) {
|
||||
throw err;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = ScenarioManager;
|
||||
|
|
|
@ -3,7 +3,8 @@ import {
|
|||
common,
|
||||
dashboardPage,
|
||||
headerPage,
|
||||
scenarioManager
|
||||
scenarioManager,
|
||||
esClient
|
||||
} from '../../../support';
|
||||
|
||||
(function () {
|
||||
|
@ -22,7 +23,7 @@ import {
|
|||
return scenarioManager.unload('emptyKibana')
|
||||
.then(function () {
|
||||
return common.try(function () {
|
||||
return scenarioManager.updateConfigDoc({'dateFormat:tz':'UTC', 'defaultIndex':'logstash-*'});
|
||||
return esClient.updateConfigDoc({'dateFormat:tz':'UTC', 'defaultIndex':'logstash-*'});
|
||||
});
|
||||
})
|
||||
// and load a set of makelogs data
|
||||
|
|
65
test/support/es_client.js
Normal file
65
test/support/es_client.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
var elasticsearch = require('elasticsearch');
|
||||
var Promise = require('bluebird');
|
||||
|
||||
function EsClient(server) {
|
||||
if (!server) throw new Error('No server defined');
|
||||
|
||||
// NOTE: some large sets of test data can take several minutes to load
|
||||
this.client = new elasticsearch.Client({
|
||||
host: server,
|
||||
requestTimeout: 300000,
|
||||
defer: function () {
|
||||
return Promise.defer();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add fields to the config doc (like setting timezone and defaultIndex)
|
||||
* @return {Promise} A promise that is resolved when elasticsearch has a response
|
||||
*/
|
||||
EsClient.prototype.updateConfigDoc = function (docMap) {
|
||||
// first we need to get the config doc's id so we can use it in our _update call
|
||||
var self = this;
|
||||
var configId;
|
||||
var docMapString = JSON.stringify(docMap);
|
||||
|
||||
return this.client.search({
|
||||
index: '.kibana',
|
||||
type: 'config'
|
||||
})
|
||||
.then(function (response) {
|
||||
if (response.errors) {
|
||||
throw new Error(
|
||||
'get config failed\n' +
|
||||
response.items
|
||||
.map(i => i[Object.keys(i)[0]].error)
|
||||
.filter(Boolean)
|
||||
.map(err => ' ' + JSON.stringify(err))
|
||||
.join('\n')
|
||||
);
|
||||
} else {
|
||||
configId = response.hits.hits[0]._id;
|
||||
console.log('config._id =' + configId);
|
||||
}
|
||||
})
|
||||
// now that we have the id, we can update
|
||||
// return scenarioManager.updateConfigDoc({'dateFormat:tz':'UTC', 'defaultIndex':'logstash-*'});
|
||||
.then(function (response) {
|
||||
console.log('updating config with ' + docMapString);
|
||||
return self.client.update({
|
||||
index: '.kibana',
|
||||
type: 'config',
|
||||
id: configId,
|
||||
body: {
|
||||
'doc':
|
||||
docMap
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(function (err) {
|
||||
throw err;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = EsClient;
|
|
@ -1,4 +1,5 @@
|
|||
import url from 'url';
|
||||
import EsClient from './es_client';
|
||||
import ScenarioManager from '../fixtures/scenario_manager';
|
||||
import Common from './pages/common';
|
||||
import DiscoverPage from './pages/discover_page';
|
||||
|
@ -18,6 +19,7 @@ exports.defaultTimeout = exports.config.defaultTimeout;
|
|||
exports.defaultTryTimeout = exports.config.defaultTryTimeout;
|
||||
exports.defaultFindTimeout = exports.config.defaultFindTimeout;
|
||||
exports.scenarioManager = new ScenarioManager(url.format(exports.config.servers.elasticsearch));
|
||||
exports.esClient = new EsClient(url.format(exports.config.servers.elasticsearch));
|
||||
|
||||
defineDelayedExport('remote', (suite) => suite.remote);
|
||||
defineDelayedExport('common', () => new Common());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue