Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into apps/home
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Jul 29, 2015
2 parents 09875a0 + 05ca74b commit 9ec0636
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 78 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
],
"private": false,
"version": "4.2.0-snapshot",
"build": {
"num": 8095
},
"main": "src/server/KbnServer.js",
"homepage": "https://www.elastic.co/products/kibana",
"bugs": {
Expand Down
21 changes: 10 additions & 11 deletions src/plugins/elasticsearch/lib/__tests__/upgrade_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var expect = require('expect.js');

var upgradeConfig = require('../upgrade_config');

describe('pluigns/elasticsearch', function () {
describe('plugins/elasticsearch', function () {
describe('lib/upgrade_config', function () {
var get;
var server;
Expand All @@ -17,6 +17,7 @@ describe('pluigns/elasticsearch', function () {
get = sinon.stub();
get.withArgs('kibana.index').returns('.my-kibana');
get.withArgs('pkg.version').returns('4.0.1');
get.withArgs('pkg.buildNum').returns(Math.random());
client = { create: sinon.stub() };
server = {
log: sinon.stub(),
Expand Down Expand Up @@ -44,20 +45,18 @@ describe('pluigns/elasticsearch', function () {
get.withArgs('env.dev').returns(false);
});

it('should resolve buildNum to pkg.buildNum', function () {
get.withArgs('pkg.buildNum').returns(5801);

it('should resolve buildNum to pkg.buildNum config', function () {
return upgrade(response).then(function (resp) {
sinon.assert.calledOnce(client.create);
var params = client.create.args[0][0];
expect(params.body).to.have.property('buildNum', 5801);
expect(params.body).to.have.property('buildNum', get('pkg.buildNum'));
});
});

it('should resolve version to kibana.package.version', function () {
it('should resolve version to pkg.version config', function () {
return upgrade(response).then(function (resp) {
var params = client.create.args[0][0];
expect(params).to.have.property('id', '4.0.1');
expect(params).to.have.property('id', get('pkg.version'));
});
});
});
Expand All @@ -69,17 +68,17 @@ describe('pluigns/elasticsearch', function () {
get.withArgs('env.dev').returns(true);
});

it('should resolve buildNum to the max integer', function () {
it('should resolve buildNum to pkg.buildNum config', function () {
return upgrade(response).then(function (resp) {
var params = client.create.args[0][0];
expect(params.body).to.have.property('buildNum', (Math.pow(2, 53) - 1));
expect(params.body).to.have.property('buildNum', get('pkg.buildNum'));
});
});

it('should resolve version to @@version', function () {
it('should resolve version to pkg.version config', function () {
return upgrade(response).then(function (resp) {
var params = client.create.args[0][0];
expect(params).to.have.property('id', '@@version');
expect(params).to.have.property('id', get('pkg.version'));
});
});
});
Expand Down
37 changes: 12 additions & 25 deletions src/plugins/kibana/public/settings/sections/objects/_objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ define(function (require) {
});

require('ui/modules').get('apps/settings')
.directive('kbnSettingsObjects', function (kbnIndex, Notifier, Private, kbnUrl) {
.directive('kbnSettingsObjects', function (kbnIndex, Notifier, Private, kbnUrl, Promise) {
return {
restrict: 'E',
controller: function ($scope, $injector, $q, AppState, es) {
Expand Down Expand Up @@ -41,7 +41,7 @@ define(function (require) {
$q.all(services).then(function (data) {
$scope.services = _.sortBy(data, 'title');
var tab = $scope.services[0];
if ($state.tab) tab = _.find($scope.services, {title: $state.tab});
if ($state.tab) $scope.currentTab = tab = _.find($scope.services, {title: $state.tab});

$scope.$watch('state.tab', function (tab) {
if (!tab) $scope.changeTab($scope.services[0]);
Expand Down Expand Up @@ -124,32 +124,19 @@ define(function (require) {
notify.error('The file could not be processed.');
}

return es.mget({
index: kbnIndex,
body: {docs: docs.map(_.partialRight(_.pick, '_id', '_type'))}
return Promise.map(docs, function (doc) {
var service = _.find($scope.services, {type: doc._type}).service;
return service.get().then(function (obj) {
obj.id = doc._id;
return obj.applyESResp(doc).then(function () {
return obj.save();
});
});
})
.then(function (response) {
var existingDocs = _.where(response.docs, {found: true});
var confirmMessage = 'The following objects will be overwritten:\n\n';
if (existingDocs.length === 0 || window.confirm(confirmMessage + _.pluck(existingDocs, '_id').join('\n'))) {
return es.bulk({
index: kbnIndex,
body: _.flattenDeep(docs.map(transformToBulk))
})
.then(refreshIndex)
.then(refreshData, notify.error);
}
});
.then(refreshIndex)
.then(refreshData, notify.error);
};

// Takes a doc and returns the associated two entries for an index bulk API request
function transformToBulk(doc) {
return [
{index: _.pick(doc, '_id', '_type')},
doc._source
];
}

function refreshIndex() {
return es.indices.refresh({
index: kbnIndex
Expand Down
5 changes: 4 additions & 1 deletion src/server/config/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let Promise = require('bluebird');
let Joi = require('joi');
let _ = require('lodash');
let override = require('./override');
let pkg = require('requirefrom')('src/utils')('packageJson');

module.exports = class Config {
constructor(schema, defaults) {
Expand Down Expand Up @@ -65,7 +66,9 @@ module.exports = class Config {
prod: env === 'production',
dev: env === 'development',
notProd: env !== 'production',
notDev: env !== 'development'
notDev: env !== 'development',
version: _.get(pkg, 'version'),
buildNum: env === 'development' ? Math.pow(2, 53) - 1 : _.get(pkg, 'build.num', NaN)
};

if (!context.dev && !context.prod && !context.test) {
Expand Down
7 changes: 2 additions & 5 deletions src/server/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ let path = require('path');

let utils = require('requirefrom')('src/utils');
let fromRoot = utils('fromRoot');
let pkg = utils('packageJson');
let buildNum = get(pkg, 'build.num', Math.pow(2, 53) - 1);

module.exports = Joi.object({

pkg: Joi.object({
version: Joi.string().valid(pkg.version).default(pkg.version),
buildNum: Joi.number().valid(buildNum).default(buildNum)
version: Joi.string().default(Joi.ref('$version')),
buildNum: Joi.number().default(Joi.ref('$buildNum'))
}).default(),

env: Joi.object({
Expand Down
73 changes: 37 additions & 36 deletions src/ui/public/courier/saved_object/saved_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,54 +92,55 @@ define(function (require) {

// fetch the object from ES
return docSource.fetch()
.then(function applyESResp(resp) {
.then(self.applyESResp);
})
.then(function () {
return customInit.call(self);
})
.then(function () {
// return our obj as the result of init()
return self;
});
});

self._source = _.cloneDeep(resp._source);
self.applyESResp = function (resp) {
self._source = _.cloneDeep(resp._source);

if (!resp.found) throw new errors.SavedObjectNotFound(type, self.id);
if (resp.found != null && !resp.found) throw new errors.SavedObjectNotFound(type, self.id);

var meta = resp._source.kibanaSavedObjectMeta || {};
delete resp._source.kibanaSavedObjectMeta;
var meta = resp._source.kibanaSavedObjectMeta || {};
delete resp._source.kibanaSavedObjectMeta;

if (!config.indexPattern && self._source.indexPattern) {
config.indexPattern = self._source.indexPattern;
delete self._source.indexPattern;
}
if (!config.indexPattern && self._source.indexPattern) {
config.indexPattern = self._source.indexPattern;
delete self._source.indexPattern;
}

// assign the defaults to the response
_.defaults(self._source, defaults);
// assign the defaults to the response
_.defaults(self._source, defaults);

// transform the source using _deserializers
_.forOwn(mapping, function ittr(fieldMapping, fieldName) {
if (fieldMapping._deserialize) {
self._source[fieldName] = fieldMapping._deserialize(self._source[fieldName], resp, fieldName, fieldMapping);
}
});
// transform the source using _deserializers
_.forOwn(mapping, function ittr(fieldMapping, fieldName) {
if (fieldMapping._deserialize) {
self._source[fieldName] = fieldMapping._deserialize(self._source[fieldName], resp, fieldName, fieldMapping);
}
});

// Give obj all of the values in _source.fields
_.assign(self, self._source);

return Promise.try(function () {
parseSearchSource(meta.searchSourceJSON);
})
.then(hydrateIndexPattern)
.then(function () {
return Promise.cast(afterESResp.call(self, resp));
})
.then(function () {
// Any time obj is updated, re-call applyESResp
docSource.onUpdate().then(applyESResp, notify.fatal);
});
});
// Give obj all of the values in _source.fields
_.assign(self, self._source);

return Promise.try(function () {
parseSearchSource(meta.searchSourceJSON);
})
.then(hydrateIndexPattern)
.then(function () {
return customInit.call(self);
return Promise.cast(afterESResp.call(self, resp));
})
.then(function () {
// return our obj as the result of init()
return self;
// Any time obj is updated, re-call applyESResp
docSource.onUpdate().then(self.applyESResp, notify.fatal);
});
});
};

function parseSearchSource(searchSourceJson) {
if (!self.searchSource) return;
Expand Down
1 change: 1 addition & 0 deletions src/ui/public/directives/file_upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define(function (require) {
});

$elem.on('click', function (e) {
$fileInput.val(null);
$fileInput.trigger('click');
});
}
Expand Down

0 comments on commit 9ec0636

Please sign in to comment.