Skip to content

Commit

Permalink
Rename resolve import conflicts API to resolve import errors (#33024) (
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote authored Mar 13, 2019
1 parent 1757332 commit b5fd3da
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 127 deletions.
4 changes: 2 additions & 2 deletions docs/api/saved-objects.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ NOTE: You cannot access these endpoints via the Console in Kibana.
* <<saved-objects-api-delete>>
* <<saved-objects-api-export>>
* <<saved-objects-api-import>>
* <<saved-objects-api-resolve-import-conflicts>>
* <<saved-objects-api-resolve-import-errors>>

include::saved-objects/get.asciidoc[]
include::saved-objects/bulk_get.asciidoc[]
Expand All @@ -31,4 +31,4 @@ include::saved-objects/update.asciidoc[]
include::saved-objects/delete.asciidoc[]
include::saved-objects/export.asciidoc[]
include::saved-objects/import.asciidoc[]
include::saved-objects/resolve_import_conflicts.asciidoc[]
include::saved-objects/resolve_import_errors.asciidoc[]
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[[saved-objects-api-resolve-import-conflicts]]
=== Resolve Import Conflicts
[[saved-objects-api-resolve-import-errors]]
=== Resolve Import Errors

experimental[This functionality is *experimental* and may be changed or removed completely in a future release.]

The resolve import conflicts API enables you to resolve conflicts given by the import API by either overwriting specific saved objects or changing references to a newly created object.
The resolve import errors API enables you to resolve errors given by the import API by either overwriting specific saved objects or changing references to a newly created object.

Note: You cannot access this endpoint via the Console in Kibana.

==== Request

`POST /api/saved_objects/_resolve_import_conflicts`
`POST /api/saved_objects/_resolve_import_errors`

==== Request body

Expand All @@ -35,12 +35,12 @@ In the scenario the import wasn't successful a top level `errors` array will con

==== Examples

The following example resolves conflicts for an index pattern and dashboard but indicates to skip the index pattern.
The following example resolves errors for an index pattern and dashboard but indicates to skip the index pattern.
This will cause the index pattern to not be in the system and the dashboard to overwrite the existing saved object.

[source,js]
--------------------------------------------------
POST api/saved_objects/_resolve_import_conflicts
POST api/saved_objects/_resolve_import_errors
Content-Type: multipart/form-data; boundary=EXAMPLE
--EXAMPLE
Content-Disposition: form-data; name="file"; filename="export.ndjson"
Expand Down Expand Up @@ -71,12 +71,12 @@ containing a JSON structure similar to the following example:
}
--------------------------------------------------

The following example resolves conflicts for a visualization and dashboard but indicates
The following example resolves errors for a visualization and dashboard but indicates
to replace the dashboard references to another visualization.

[source,js]
--------------------------------------------------
POST api/saved_objects/_resolve_import_conflicts
POST api/saved_objects/_resolve_import_errors
Content-Type: multipart/form-data; boundary=EXAMPLE
--EXAMPLE
Content-Disposition: form-data; name="file"; filename="export.ndjson"
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/server/saved_objects/import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
*/

export { importSavedObjects } from './import_saved_objects';
export { resolveImportConflicts } from './resolve_import_conflicts';
export { resolveImportErrors } from './resolve_import_errors';
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import { Readable } from 'stream';
import { SavedObject } from '../service';
import { resolveImportConflicts } from './resolve_import_conflicts';
import { resolveImportErrors } from './resolve_import_errors';

describe('resolveImportConflicts()', () => {
describe('resolveImportErrors()', () => {
const savedObjects: SavedObject[] = [
{
id: '1',
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('resolveImportConflicts()', () => {
savedObjectsClient.bulkCreate.mockResolvedValue({
saved_objects: savedObjects,
});
const result = await resolveImportConflicts({
const result = await resolveImportErrors({
readStream,
objectLimit: 4,
skips: [],
Expand All @@ -112,7 +112,7 @@ Object {
savedObjectsClient.bulkCreate.mockResolvedValue({
saved_objects: savedObjects,
});
const result = await resolveImportConflicts({
const result = await resolveImportErrors({
readStream,
objectLimit: 4,
skips: [
Expand Down Expand Up @@ -150,7 +150,7 @@ Object {
savedObjectsClient.bulkCreate.mockResolvedValue({
saved_objects: savedObjects,
});
const result = await resolveImportConflicts({
const result = await resolveImportErrors({
readStream,
objectLimit: 4,
skips: [],
Expand Down Expand Up @@ -206,7 +206,7 @@ Object {
savedObjectsClient.bulkCreate.mockResolvedValue({
saved_objects: savedObjects,
});
const result = await resolveImportConflicts({
const result = await resolveImportErrors({
readStream,
objectLimit: 4,
skips: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { collectSavedObjects } from './collect_saved_objects';
import { createObjectsFilter } from './create_objects_filter';
import { CustomError, extractErrors } from './extract_errors';

interface ResolveImportConflictsOptions {
interface ResolveImportErrorsOptions {
readStream: Readable;
objectLimit: number;
savedObjectsClient: SavedObjectsClient;
Expand All @@ -48,14 +48,14 @@ interface ImportResponse {
errors?: CustomError[];
}

export async function resolveImportConflicts({
export async function resolveImportErrors({
readStream,
objectLimit,
skips,
overwrites,
savedObjectsClient,
replaceReferences,
}: ResolveImportConflictsOptions): Promise<ImportResponse> {
}: ResolveImportErrorsOptions): Promise<ImportResponse> {
let errors: CustomError[] = [];
const filter = createObjectsFilter(skips, overwrites, replaceReferences);
const objectsToResolve = await collectSavedObjects(readStream, objectLimit, filter);
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/server/saved_objects/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export { createDeleteRoute } from './delete';
export { createFindRoute } from './find';
export { createGetRoute } from './get';
export { createImportRoute } from './import';
export { createResolveImportConflictsRoute } from './resolve_import_conflicts';
export { createResolveImportErrorsRoute } from './resolve_import_errors';
export { createUpdateRoute } from './update';
export { createExportRoute } from './export';
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import Hapi from 'hapi';
import { createMockServer } from './_mock_server';
import { createResolveImportConflictsRoute } from './resolve_import_conflicts';
import { createResolveImportErrorsRoute } from './resolve_import_errors';

describe('POST /api/saved_objects/_resolve_import_conflicts', () => {
describe('POST /api/saved_objects/_resolve_import_errors', () => {
let server: Hapi.Server;
const savedObjectsClient = {
errors: {} as any,
Expand Down Expand Up @@ -53,13 +53,13 @@ describe('POST /api/saved_objects/_resolve_import_conflicts', () => {
},
};

server.route(createResolveImportConflictsRoute(prereqs, server));
server.route(createResolveImportErrorsRoute(prereqs, server));
});

test('formats successful response', async () => {
const request = {
method: 'POST',
url: '/api/saved_objects/_resolve_import_conflicts',
url: '/api/saved_objects/_resolve_import_errors',
payload: [
'--BOUNDARY',
'Content-Disposition: form-data; name="file"; filename="export.ndjson"',
Expand All @@ -83,7 +83,7 @@ describe('POST /api/saved_objects/_resolve_import_conflicts', () => {
// NOTE: changes to this scenario should be reflected in the docs
const request = {
method: 'POST',
url: '/api/saved_objects/_resolve_import_conflicts',
url: '/api/saved_objects/_resolve_import_errors',
payload: [
'--EXAMPLE',
'Content-Disposition: form-data; name="file"; filename="export.ndjson"',
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('POST /api/saved_objects/_resolve_import_conflicts', () => {
// NOTE: changes to this scenario should be reflected in the docs
const request = {
method: 'POST',
url: '/api/saved_objects/_resolve_import_conflicts',
url: '/api/saved_objects/_resolve_import_errors',
payload: [
'--EXAMPLE',
'Content-Disposition: form-data; name="file"; filename="export.ndjson"',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Joi from 'joi';
import { extname } from 'path';
import { Readable } from 'stream';
import { SavedObjectsClient } from '../';
import { resolveImportConflicts } from '../import';
import { resolveImportErrors } from '../import';
import { Prerequisites } from './types';

interface HapiReadableStream extends Readable {
Expand Down Expand Up @@ -54,8 +54,8 @@ interface ImportRequest extends Hapi.Request {
};
}

export const createResolveImportConflictsRoute = (prereqs: Prerequisites, server: Hapi.Server) => ({
path: '/api/saved_objects/_resolve_import_conflicts',
export const createResolveImportErrorsRoute = (prereqs: Prerequisites, server: Hapi.Server) => ({
path: '/api/saved_objects/_resolve_import_errors',
method: 'POST',
config: {
pre: [prereqs.getSavedObjectsClient],
Expand Down Expand Up @@ -102,7 +102,7 @@ export const createResolveImportConflictsRoute = (prereqs: Prerequisites, server
if (fileExtension !== '.ndjson') {
return Boom.badRequest(`Invalid file extension ${fileExtension}`);
}
return await resolveImportConflicts({
return await resolveImportErrors({
savedObjectsClient,
readStream: request.payload.file,
objectLimit: request.server.config().get('savedObjects.maxImportExportSize'),
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/server/saved_objects/saved_objects_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
createUpdateRoute,
createExportRoute,
createImportRoute,
createResolveImportConflictsRoute,
createResolveImportErrorsRoute,
} from './routes';

export function savedObjectsMixin(kbnServer, server) {
Expand Down Expand Up @@ -66,7 +66,7 @@ export function savedObjectsMixin(kbnServer, server) {
server.route(createUpdateRoute(prereqs));
server.route(createExportRoute(prereqs, server));
server.route(createImportRoute(prereqs, server));
server.route(createResolveImportConflictsRoute(prereqs, server));
server.route(createResolveImportErrorsRoute(prereqs, server));

const schema = new SavedObjectsSchema(kbnServer.uiExports.savedObjectSchemas);
const serializer = new SavedObjectsSerializer(schema);
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/server/saved_objects/saved_objects_mixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ describe('Saved Objects Mixin', () => {
savedObjectsMixin(mockKbnServer, mockServer);
expect(mockServer.route).toHaveBeenCalledWith(expect.objectContaining({ path: '/api/saved_objects/_import', method: 'POST' }));
});
it('should add POST /api/saved_objects/_resolve_import_conflicts', () => {
it('should add POST /api/saved_objects/_resolve_import_errors', () => {
savedObjectsMixin(mockKbnServer, mockServer);
expect(mockServer.route)
.toHaveBeenCalledWith(expect.objectContaining({ path: '/api/saved_objects/_resolve_import_conflicts', method: 'POST' }));
.toHaveBeenCalledWith(expect.objectContaining({ path: '/api/saved_objects/_resolve_import_errors', method: 'POST' }));
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/api_integration/apis/saved_objects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ({ loadTestFile }) {
loadTestFile(require.resolve('./find'));
loadTestFile(require.resolve('./get'));
loadTestFile(require.resolve('./import'));
loadTestFile(require.resolve('./resolve_import_conflicts'));
loadTestFile(require.resolve('./resolve_import_errors'));
loadTestFile(require.resolve('./update'));
loadTestFile(require.resolve('./migrations'));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ export default function ({ getService }) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');

describe('resolve_import_conflicts', () => {
describe('resolve_import_errors', () => {
describe('without kibana index', () => {
// Cleanup data that got created in import
after(() => esArchiver.unload('saved_objects/basic'));

it('should return 200 and import nothing when empty parameters are passed in', async () => {
await supertest
.post('/api/saved_objects/_resolve_import_conflicts')
.post('/api/saved_objects/_resolve_import_errors')
.attach('file', join(__dirname, '../../fixtures/import.ndjson'))
.expect(200)
.then((resp) => {
Expand All @@ -44,7 +44,7 @@ export default function ({ getService }) {

it('should return 200 and import everything when overwrite parameters contains all objects', async () => {
await supertest
.post('/api/saved_objects/_resolve_import_conflicts')
.post('/api/saved_objects/_resolve_import_errors')
.field('overwrites', JSON.stringify([
{
type: 'index-pattern',
Expand All @@ -71,7 +71,7 @@ export default function ({ getService }) {

it('should return 400 when no file passed in', async () => {
await supertest
.post('/api/saved_objects/_resolve_import_conflicts')
.post('/api/saved_objects/_resolve_import_errors')
.field('skips', '[]')
.expect(400)
.then((resp) => {
Expand Down Expand Up @@ -100,7 +100,7 @@ export default function ({ getService }) {
]
};
await supertest
.post('/api/saved_objects/_resolve_import_conflicts')
.post('/api/saved_objects/_resolve_import_errors')
.field('replaceReferences', JSON.stringify(
[
{
Expand Down Expand Up @@ -138,7 +138,7 @@ export default function ({ getService }) {
fileChunks.push(`{"type":"visualization","id":"${i}","attributes":{},"references":[]}`);
}
await supertest
.post('/api/saved_objects/_resolve_import_conflicts')
.post('/api/saved_objects/_resolve_import_errors')
.attach('file', Buffer.from(fileChunks.join('\n'), 'utf8'), 'export.ndjson')
.expect(400)
.then((resp) => {
Expand All @@ -158,7 +158,7 @@ export default function ({ getService }) {

it('should return 200 when skipping all the records', async () => {
await supertest
.post('/api/saved_objects/_resolve_import_conflicts')
.post('/api/saved_objects/_resolve_import_errors')
.field('skips', JSON.stringify(
[
{
Expand All @@ -184,7 +184,7 @@ export default function ({ getService }) {

it('should return 200 when manually overwriting each object', async () => {
await supertest
.post('/api/saved_objects/_resolve_import_conflicts')
.post('/api/saved_objects/_resolve_import_errors')
.field('overwrites', JSON.stringify(
[
{
Expand All @@ -210,7 +210,7 @@ export default function ({ getService }) {

it('should return 200 with only one record when overwriting 1 and skipping 1', async () => {
await supertest
.post('/api/saved_objects/_resolve_import_conflicts')
.post('/api/saved_objects/_resolve_import_errors')
.field('overwrites', JSON.stringify(
[
{
Expand Down
Loading

0 comments on commit b5fd3da

Please sign in to comment.