forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt es-archiver to call
_migrate
endpoint instead of creating a m…
…igrator (elastic#56971) * es-archiver call _migrate endpoint instead of creating a migrator * fix crlf.... * use promise instead of callback accessor * attempt with disabled authent * enable security again * set mapping to dynamic before calling migration endpoint * rename space data from non-spaced tests * add documentation on the `rerun` flag * create router with the `/api/saved_objects` prefix * add unit test about strict mapping * add integration test on migrate endpoint * wrap route handler with handleLegacyErrors * add remark about limitations of the rerun flag * Apply suggestions from code review Co-Authored-By: Aleh Zasypkin <[email protected]> * do not return detailed index result * add access tag to migrate route * use /internal prefix for migrate endpoint * fix integ tests Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Josh Dover <[email protected]> Co-authored-by: Aleh Zasypkin <[email protected]>
- Loading branch information
1 parent
f17dd96
commit 812596e
Showing
16 changed files
with
221 additions
and
100 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
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
26 changes: 26 additions & 0 deletions
26
src/core/server/saved_objects/routes/integration_tests/migrate.test.mocks.ts
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,26 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { mockKibanaMigrator } from '../../migrations/kibana/kibana_migrator.mock'; | ||
|
||
export const migratorInstanceMock = mockKibanaMigrator.create(); | ||
export const KibanaMigratorMock = jest.fn().mockImplementation(() => migratorInstanceMock); | ||
jest.doMock('../../migrations/kibana/kibana_migrator', () => ({ | ||
KibanaMigrator: KibanaMigratorMock, | ||
})); |
62 changes: 62 additions & 0 deletions
62
src/core/server/saved_objects/routes/integration_tests/migrate.test.ts
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,62 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { migratorInstanceMock } from './migrate.test.mocks'; | ||
import * as kbnTestServer from '../../../../../test_utils/kbn_server'; | ||
|
||
describe('SavedObjects /_migrate endpoint', () => { | ||
let root: ReturnType<typeof kbnTestServer.createRoot>; | ||
|
||
beforeEach(async () => { | ||
root = kbnTestServer.createRoot({ migrations: { skip: true } }); | ||
await root.setup(); | ||
await root.start(); | ||
migratorInstanceMock.runMigrations.mockClear(); | ||
}, 30000); | ||
|
||
afterEach(async () => { | ||
await root.shutdown(); | ||
}); | ||
|
||
it('calls runMigrations on the migrator with rerun=true when accessed', async () => { | ||
await kbnTestServer.request | ||
.post(root, '/internal/saved_objects/_migrate') | ||
.send({}) | ||
.expect(200); | ||
|
||
expect(migratorInstanceMock.runMigrations).toHaveBeenCalledTimes(1); | ||
expect(migratorInstanceMock.runMigrations).toHaveBeenCalledWith({ rerun: true }); | ||
}); | ||
|
||
it('calls runMigrations multiple time when multiple access', async () => { | ||
await kbnTestServer.request | ||
.post(root, '/internal/saved_objects/_migrate') | ||
.send({}) | ||
.expect(200); | ||
|
||
expect(migratorInstanceMock.runMigrations).toHaveBeenCalledTimes(1); | ||
|
||
await kbnTestServer.request | ||
.post(root, '/internal/saved_objects/_migrate') | ||
.send({}) | ||
.expect(200); | ||
|
||
expect(migratorInstanceMock.runMigrations).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
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,45 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { IRouter } from '../../http'; | ||
import { IKibanaMigrator } from '../migrations'; | ||
|
||
export const registerMigrateRoute = ( | ||
router: IRouter, | ||
migratorPromise: Promise<IKibanaMigrator> | ||
) => { | ||
router.post( | ||
{ | ||
path: '/_migrate', | ||
validate: false, | ||
options: { | ||
tags: ['access:migrateSavedObjects'], | ||
}, | ||
}, | ||
router.handleLegacyErrors(async (context, req, res) => { | ||
const migrator = await migratorPromise; | ||
await migrator.runMigrations({ rerun: true }); | ||
return res.ok({ | ||
body: { | ||
success: 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
Oops, something went wrong.