Skip to content

Commit

Permalink
adapt es archiver to convert legacy mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Jan 24, 2020
1 parent 3ae4147 commit c65c28a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
19 changes: 2 additions & 17 deletions src/core/server/saved_objects/saved_objects_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { KibanaConfigType } from '../kibana_config';
import { migrationsRetryCallCluster } from '../elasticsearch/retry_call_cluster';
import { SavedObjectsConfigType } from './saved_objects_config';
import { KibanaRequest } from '../http';
import { SavedObjectsClientContract, SavedObjectsLegacyMapping } from './types';
import { SavedObjectsClientContract } from './types';
import { ISavedObjectsRepository, SavedObjectsRepository } from './service/lib/repository';
import {
SavedObjectsClientFactoryProvider,
Expand All @@ -46,7 +46,7 @@ import { SavedObjectsTypeMapping } from './mappings';
import { MigrationDefinition } from './migrations/core/document_migrator';
import { SavedObjectsSchemaDefinition } from './schema';
import { PropertyValidators } from './validation';
// import { PluginOpaqueId } from '..';
import { convertLegacyMappings } from './utils';

/**
* Saved Objects is Kibana's data persistence mechanism allowing plugins to
Expand Down Expand Up @@ -377,18 +377,3 @@ export class SavedObjectsService
});
}
}

const convertLegacyMappings = (
legacyMappings: SavedObjectsLegacyMapping[]
): SavedObjectsTypeMapping[] => {
return legacyMappings.reduce((mappings, { pluginId, properties }) => {
return [
...mappings,
...Object.entries(properties).map(([type, definition]) => ({
pluginId,
type,
definition,
})),
];
}, [] as SavedObjectsTypeMapping[]);
};
36 changes: 36 additions & 0 deletions src/core/server/saved_objects/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 { SavedObjectsLegacyMapping } from './types';
import { SavedObjectsTypeMapping } from './mappings';

export const convertLegacyMappings = (
legacyMappings: SavedObjectsLegacyMapping[]
): SavedObjectsTypeMapping[] => {
return legacyMappings.reduce((mappings, { pluginId, properties }) => {
return [
...mappings,
...Object.entries(properties).map(([type, definition]) => ({
pluginId,
type,
definition,
})),
];
}, [] as SavedObjectsTypeMapping[]);
};
3 changes: 2 additions & 1 deletion src/es_archiver/lib/indices/kibana_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { toArray } from 'rxjs/operators';
import { deleteIndex } from './delete_index';
import { collectUiExports } from '../../../legacy/ui/ui_exports';
import { KibanaMigrator } from '../../../core/server/saved_objects/migrations';
import { convertLegacyMappings } from '../../../core/server/saved_objects/utils';
import { SavedObjectsSchema } from '../../../core/server/saved_objects';
import { findPluginSpecs } from '../../../legacy/plugin_discovery';

Expand Down Expand Up @@ -103,7 +104,7 @@ export async function migrateKibanaIndex({ client, log, kibanaPluginIds }) {
},
version: kibanaVersion,
savedObjectSchemas: new SavedObjectsSchema(uiExports.savedObjectSchemas),
savedObjectMappings: uiExports.savedObjectMappings,
savedObjectMappings: convertLegacyMappings(uiExports.savedObjectMappings),
savedObjectMigrations: uiExports.savedObjectMigrations,
savedObjectValidations: uiExports.savedObjectValidations,
callCluster: (path, ...args) => _.get(client, path).call(client, ...args),
Expand Down

0 comments on commit c65c28a

Please sign in to comment.