Skip to content

Commit

Permalink
use new es client in so repository
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Jul 17, 2020
1 parent 7392dc8 commit e9ae3e9
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 207 deletions.
34 changes: 16 additions & 18 deletions src/core/server/saved_objects/saved_objects_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ import { KibanaMigrator, IKibanaMigrator } from './migrations';
import { CoreContext } from '../core_context';
import { LegacyServiceDiscoverPlugins } from '../legacy';
import {
LegacyAPICaller,
ElasticsearchServiceStart,
ILegacyClusterClient,
ElasticsearchClient,
IClusterClient,
InternalElasticsearchServiceSetup,
InternalElasticsearchServiceStart,
} from '../elasticsearch';
import { KibanaConfigType } from '../kibana_config';
import { migrationsRetryCallCluster } from '../elasticsearch/legacy';
import {
SavedObjectsConfigType,
SavedObjectsMigrationConfigType,
Expand All @@ -57,7 +56,7 @@ import { SavedObjectsSerializer } from './serialization';
import { registerRoutes } from './routes';
import { ServiceStatus } from '../status';
import { calculateStatus$ } from './status';

import { createMigrationEsClient } from './migrations/core/';
/**
* Saved Objects is Kibana's data persistence mechanism allowing plugins to
* use Elasticsearch for storing and querying state. The SavedObjectsServiceSetup API exposes methods
Expand Down Expand Up @@ -284,7 +283,7 @@ interface WrappedClientFactoryWrapper {

/** @internal */
export interface SavedObjectsStartDeps {
elasticsearch: ElasticsearchServiceStart;
elasticsearch: InternalElasticsearchServiceStart;
pluginsInitialized?: boolean;
}

Expand Down Expand Up @@ -383,12 +382,12 @@ export class SavedObjectsService
.atPath<KibanaConfigType>('kibana')
.pipe(first())
.toPromise();
const client = elasticsearch.legacy.client;
const client = elasticsearch.client;

const migrator = this.createMigrator(
kibanaConfig,
this.config.migration,
client,
elasticsearch.client,
migrationsRetryDelay
);

Expand Down Expand Up @@ -434,21 +433,24 @@ export class SavedObjectsService
await migrator.runMigrations();
}

const createRepository = (callCluster: LegacyAPICaller, includedHiddenTypes: string[] = []) => {
const createRepository = (
esClient: ElasticsearchClient,
includedHiddenTypes: string[] = []
) => {
return SavedObjectsRepository.createRepository(
migrator,
this.typeRegistry,
kibanaConfig.index,
callCluster,
esClient,
includedHiddenTypes
);
};

const repositoryFactory: SavedObjectsRepositoryFactory = {
createInternalRepository: (includedHiddenTypes?: string[]) =>
createRepository(client.callAsInternalUser, includedHiddenTypes),
createRepository(client.asInternalUser, includedHiddenTypes),
createScopedRepository: (req: KibanaRequest, includedHiddenTypes?: string[]) =>
createRepository(client.asScoped(req).callAsCurrentUser, includedHiddenTypes),
createRepository(client.asScoped(req).asCurrentUser, includedHiddenTypes),
};

const clientProvider = new SavedObjectsClientProvider({
Expand Down Expand Up @@ -484,7 +486,7 @@ export class SavedObjectsService
private createMigrator(
kibanaConfig: KibanaConfigType,
savedObjectsConfig: SavedObjectsMigrationConfigType,
esClient: ILegacyClusterClient,
client: IClusterClient,
migrationsRetryDelay?: number
): KibanaMigrator {
return new KibanaMigrator({
Expand All @@ -494,11 +496,7 @@ export class SavedObjectsService
savedObjectsConfig,
savedObjectValidations: this.validations,
kibanaConfig,
callCluster: migrationsRetryCallCluster(
esClient.callAsInternalUser,
this.logger,
migrationsRetryDelay
),
client: createMigrationEsClient(client.asInternalUser, this.logger, migrationsRetryDelay),
});
}
}
7 changes: 6 additions & 1 deletion src/core/server/saved_objects/serialization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@
* the raw document format as stored in ElasticSearch.
*/

export { SavedObjectUnsanitizedDoc, SavedObjectSanitizedDoc, SavedObjectsRawDoc } from './types';
export {
SavedObjectUnsanitizedDoc,
SavedObjectSanitizedDoc,
SavedObjectsRawDoc,
SavedObjectsRawDocSource,
} from './types';
export { SavedObjectsSerializer } from './serializer';
Loading

0 comments on commit e9ae3e9

Please sign in to comment.