Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[types removal] Remove types from saved_objecs repository #32286

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/legacy/server/saved_objects/service/lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ export class SavedObjectsRepository {
}
this._allowedTypes = allowedTypes;

// ES7 and up expects the root type to be _doc
this._type = '_doc';
this._onBeforeWrite = onBeforeWrite;
this._unwrappedCallCluster = async (...args) => {
await migrator.awaitMigration();
Expand Down Expand Up @@ -112,7 +110,6 @@ export class SavedObjectsRepository {

const response = await this._writeToCluster(method, {
id: raw._id,
type: this._type,
index: this._index,
refresh: 'wait_for',
body: raw._source,
Expand Down Expand Up @@ -182,7 +179,6 @@ export class SavedObjectsRepository {
{
[method]: {
_id: expectedResult.rawMigratedDoc._id,
_type: this._type,
},
},
expectedResult.rawMigratedDoc._source,
Expand Down Expand Up @@ -270,7 +266,6 @@ export class SavedObjectsRepository {

const response = await this._writeToCluster('delete', {
id: this._serializer.generateRawId(namespace, type, id),
type: this._type,
index: this._index,
refresh: 'wait_for',
ignore: [404],
Expand Down Expand Up @@ -462,7 +457,6 @@ export class SavedObjectsRepository {
if(this._isTypeAllowed(type)) {
acc.push({
_id: this._serializer.generateRawId(namespace, type, id),
_type: this._type,
});
}else{
unsupportedTypes.push({ id, type, error: errors.createUnsupportedTypeError(type).output.payload });
Expand Down Expand Up @@ -518,7 +512,6 @@ export class SavedObjectsRepository {

const response = await this._callCluster('get', {
id: this._serializer.generateRawId(namespace, type, id),
type: this._type,
index: this._index,
ignore: [404]
});
Expand Down Expand Up @@ -568,7 +561,6 @@ export class SavedObjectsRepository {
const time = this._getCurrentTime();
const response = await this._writeToCluster('update', {
id: this._serializer.generateRawId(namespace, type, id),
type: this._type,
index: this._index,
...(version && decodeRequestVersion(version)),
refresh: 'wait_for',
Expand Down Expand Up @@ -638,7 +630,6 @@ export class SavedObjectsRepository {

const response = await this._writeToCluster('update', {
id: this._serializer.generateRawId(namespace, type, id),
type: this._type,
index: this._index,
refresh: 'wait_for',
_source: true,
Expand Down
43 changes: 17 additions & 26 deletions src/legacy/server/saved_objects/service/lib/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,9 @@ describe('SavedObjectsRepository', () => {
expect(bulkCalls.length).toEqual(1);

expect(bulkCalls[0][1].body).toEqual([
{ create: { _type: '_doc', _id: 'config:one' } },
{ create: { _id: 'config:one' } },
{ type: 'config', ...mockTimestampFields, config: { title: 'Test One' }, references: [{ name: 'ref_0', type: 'test', id: '1' }] },
{ create: { _type: '_doc', _id: 'index-pattern:two' } },
{ create: { _id: 'index-pattern:two' } },
{
type: 'index-pattern',
...mockTimestampFields,
Expand Down Expand Up @@ -551,15 +551,15 @@ describe('SavedObjectsRepository', () => {

expect(callAdminCluster).toHaveBeenCalledWith('bulk', expect.objectContaining({
body: [
{ create: { _type: '_doc', _id: 'config:one' } },
{ create: { _id: 'config:one' } },
{
type: 'config',
...mockTimestampFields,
config: { title: 'Test One!!' },
migrationVersion: { foo: '2.3.4' },
references: [{ name: 'search_0', type: 'search', id: '123' }],
},
{ create: { _type: '_doc', _id: 'index-pattern:two' } },
{ create: { _id: 'index-pattern:two' } },
{
type: 'index-pattern',
...mockTimestampFields,
Expand Down Expand Up @@ -606,7 +606,7 @@ describe('SavedObjectsRepository', () => {
expect(callAdminCluster).toHaveBeenCalledWith('bulk', expect.objectContaining({
body: [
// uses create because overwriting is not allowed
{ create: { _type: '_doc', _id: 'foo:bar' } },
{ create: { _id: 'foo:bar' } },
{ type: 'foo', ...mockTimestampFields, 'foo': {}, references: [] },
]
}));
Expand All @@ -625,7 +625,7 @@ describe('SavedObjectsRepository', () => {
expect(callAdminCluster).toHaveBeenCalledWith('bulk', expect.objectContaining({
body: [
// uses index because overwriting is allowed
{ index: { _type: '_doc', _id: 'foo:bar' } },
{ index: { _id: 'foo:bar' } },
{ type: 'foo', ...mockTimestampFields, 'foo': {}, references: [] },
]
}));
Expand Down Expand Up @@ -741,15 +741,15 @@ describe('SavedObjectsRepository', () => {
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster).toHaveBeenCalledWith('bulk', expect.objectContaining({
body: [
{ create: { _type: '_doc', _id: 'foo-namespace:config:one' } },
{ create: { _id: 'foo-namespace:config:one' } },
{
namespace: 'foo-namespace',
type: 'config',
...mockTimestampFields,
config: { title: 'Test One' },
references: [],
},
{ create: { _type: '_doc', _id: 'foo-namespace:index-pattern:two' } },
{ create: { _id: 'foo-namespace:index-pattern:two' } },
{
namespace: 'foo-namespace',
type: 'index-pattern',
Expand Down Expand Up @@ -786,9 +786,9 @@ describe('SavedObjectsRepository', () => {
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster).toHaveBeenCalledWith('bulk', expect.objectContaining({
body: [
{ create: { _type: '_doc', _id: 'config:one' } },
{ create: { _id: 'config:one' } },
{ type: 'config', ...mockTimestampFields, config: { title: 'Test One' }, references: [] },
{ create: { _type: '_doc', _id: 'index-pattern:two' } },
{ create: { _id: 'index-pattern:two' } },
{ type: 'index-pattern', ...mockTimestampFields, 'index-pattern': { title: 'Test Two' }, references: [] }
]
}));
Expand All @@ -810,7 +810,7 @@ describe('SavedObjectsRepository', () => {
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster).toHaveBeenCalledWith('bulk', expect.objectContaining({
body: [
{ create: { _type: '_doc', _id: 'globaltype:one' } },
{ create: { _id: 'globaltype:one' } },
{ type: 'globaltype', ...mockTimestampFields, 'globaltype': { title: 'Test One' }, references: [] },
]
}));
Expand Down Expand Up @@ -853,7 +853,6 @@ describe('SavedObjectsRepository', () => {

expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster).toHaveBeenCalledWith('delete', {
type: '_doc',
id: 'foo-namespace:index-pattern:logstash-*',
refresh: 'wait_for',
index: '.kibana-test',
Expand All @@ -869,7 +868,6 @@ describe('SavedObjectsRepository', () => {

expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster).toHaveBeenCalledWith('delete', {
type: '_doc',
id: 'index-pattern:logstash-*',
refresh: 'wait_for',
index: '.kibana-test',
Expand All @@ -887,7 +885,6 @@ describe('SavedObjectsRepository', () => {

expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster).toHaveBeenCalledWith('delete', {
type: '_doc',
id: 'globaltype:logstash-*',
refresh: 'wait_for',
index: '.kibana-test',
Expand Down Expand Up @@ -1173,7 +1170,6 @@ describe('SavedObjectsRepository', () => {
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({
id: 'foo-namespace:index-pattern:logstash-*',
type: '_doc'
}));
});

Expand All @@ -1185,7 +1181,6 @@ describe('SavedObjectsRepository', () => {
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({
id: 'index-pattern:logstash-*',
type: '_doc'
}));
});

Expand All @@ -1199,7 +1194,6 @@ describe('SavedObjectsRepository', () => {
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({
id: 'globaltype:logstash-*',
type: '_doc'
}));
});
});
Expand Down Expand Up @@ -1231,9 +1225,9 @@ describe('SavedObjectsRepository', () => {
expect(callAdminCluster).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({
body: {
docs: [
{ _type: '_doc', _id: 'config:one' },
{ _type: '_doc', _id: 'index-pattern:two' },
{ _type: '_doc', _id: 'globaltype:three' },
{ _id: 'config:one' },
{ _id: 'index-pattern:two' },
{ _id: 'globaltype:three' },
]
}
}));
Expand All @@ -1258,9 +1252,9 @@ describe('SavedObjectsRepository', () => {
expect(callAdminCluster).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({
body: {
docs: [
{ _type: '_doc', _id: 'foo-namespace:config:one' },
{ _type: '_doc', _id: 'foo-namespace:index-pattern:two' },
{ _type: '_doc', _id: 'globaltype:three' },
{ _id: 'foo-namespace:config:one' },
{ _id: 'foo-namespace:index-pattern:two' },
{ _id: 'globaltype:three' },
]
}
}));
Expand Down Expand Up @@ -1423,7 +1417,6 @@ describe('SavedObjectsRepository', () => {

expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster).toHaveBeenCalledWith('update', {
type: '_doc',
id: 'foo-namespace:index-pattern:logstash-*',
body: {
doc: {
Expand Down Expand Up @@ -1457,7 +1450,6 @@ describe('SavedObjectsRepository', () => {

expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster).toHaveBeenCalledWith('update', {
type: '_doc',
id: 'index-pattern:logstash-*',
body: {
doc: {
Expand Down Expand Up @@ -1492,7 +1484,6 @@ describe('SavedObjectsRepository', () => {

expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster).toHaveBeenCalledWith('update', {
type: '_doc',
id: 'globaltype:foo',
body: {
doc: {
Expand Down