diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/config.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/config.ts index 36803b41b7543..17ec0b4df2883 100644 --- a/x-pack/platform/plugins/private/upgrade_assistant/server/config.ts +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/config.ts @@ -7,6 +7,45 @@ import { offeringBasedSchema, schema, TypeOf } from '@kbn/config-schema'; import { PluginConfigDescriptor } from '@kbn/core/server'; +export const dataSourceExclusionsSchema = schema.recordOf( + schema.string(), + schema.arrayOf(schema.oneOf([schema.literal('readOnly'), schema.literal('reindex')])), + { defaultValue: {} } +); + +export const featureSetSchema = schema.object({ + /** + * Ml Snapshot should only be enabled for major version upgrades. Currently this + * is manually set to `true` on every `x.last` version. + * ML Upgrade mode can be toggled from outside Kibana, the purpose + * of this feature guard is to hide all ML related deprecations from the end user + * until the next major upgrade. + * + * When we want to enable ML model snapshot deprecation warnings again we need + * to change the constant `MachineLearningField.MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION` + * to something higher than 7.0.0 in the Elasticsearch code. + */ + mlSnapshots: schema.boolean({ defaultValue: true }), + /** + * Migrating system indices should only be enabled for major version upgrades. + * Currently this is manually set to `true` on every `x.last` version. + */ + migrateSystemIndices: schema.boolean({ defaultValue: true }), + /** + * Deprecations with reindexing corrective actions are only enabled for major version upgrades. + * Currently this is manually set to `true` on every `x.last` version. + * + * The reindex action includes some logic that is specific to the 8.0 upgrade + * End users could get into a bad situation if this is enabled before this logic is fixed. + */ + reindexCorrectiveActions: schema.boolean({ defaultValue: true }), + /** + * Migrating deprecated data streams should only be enabled for major version upgrades. + * Currently this is manually set to `true` on every `x.last` version. + */ + migrateDataStreams: schema.boolean({ defaultValue: true }), +}); + // ------------------------------- // >= 8.6 UA is always enabled to guide stack upgrades // even for minor releases. @@ -31,44 +70,8 @@ const configSchema = schema.object({ * xpack.upgrade_assistant.dataSourceExclusions: * 7_17_data_stream: ["readOnly"] */ - dataSourceExclusions: schema.recordOf( - schema.string(), - schema.arrayOf(schema.oneOf([schema.literal('readOnly'), schema.literal('reindex')])), - { defaultValue: {} } - ), - - featureSet: schema.object({ - /** - * Ml Snapshot should only be enabled for major version upgrades. Currently this - * is manually set to `true` on every `x.last` version. - * ML Upgrade mode can be toggled from outside Kibana, the purpose - * of this feature guard is to hide all ML related deprecations from the end user - * until the next major upgrade. - * - * When we want to enable ML model snapshot deprecation warnings again we need - * to change the constant `MachineLearningField.MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION` - * to something higher than 7.0.0 in the Elasticsearch code. - */ - mlSnapshots: schema.boolean({ defaultValue: true }), - /** - * Migrating system indices should only be enabled for major version upgrades. - * Currently this is manually set to `true` on every `x.last` version. - */ - migrateSystemIndices: schema.boolean({ defaultValue: true }), - /** - * Deprecations with reindexing corrective actions are only enabled for major version upgrades. - * Currently this is manually set to `true` on every `x.last` version. - * - * The reindex action includes some logic that is specific to the 8.0 upgrade - * End users could get into a bad situation if this is enabled before this logic is fixed. - */ - reindexCorrectiveActions: schema.boolean({ defaultValue: true }), - /** - * Migrating deprecated data streams should only be enabled for major version upgrades. - * Currently this is manually set to `true` on every `x.last` version. - */ - migrateDataStreams: schema.boolean({ defaultValue: true }), - }), + dataSourceExclusions: dataSourceExclusionsSchema, + featureSet: featureSetSchema, /** * This config allows to hide the UI without disabling the plugin. */ diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/plugin.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/plugin.ts index 019d83fc691de..13cc180c9cc85 100644 --- a/x-pack/platform/plugins/private/upgrade_assistant/server/plugin.ts +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/plugin.ts @@ -12,7 +12,6 @@ import { CoreStart, PluginInitializerContext, Logger, - SavedObjectsClient, SavedObjectsServiceStart, } from '@kbn/core/server'; import { SecurityPluginStart } from '@kbn/security-plugin/server'; @@ -24,21 +23,16 @@ import { LicensingPluginSetup } from '@kbn/licensing-plugin/server'; import { DEPRECATION_LOGS_SOURCE_ID, DEPRECATION_LOGS_INDEX } from '../common/constants'; import { CredentialStore, credentialStoreFactory } from './lib/reindexing/credential_store'; -import { ReindexWorker } from './lib/reindexing'; import { registerUpgradeAssistantUsageCollector } from './lib/telemetry'; import { versionService } from './lib/version'; -import { createReindexWorker } from './routes/reindex_indices'; import { registerRoutes } from './routes/register_routes'; -import { - reindexOperationSavedObjectType, - mlSavedObjectType, - hiddenTypes, -} from './saved_object_types'; +import { reindexOperationSavedObjectType, mlSavedObjectType } from './saved_object_types'; import { handleEsError } from './shared_imports'; import { RouteDependencies } from './types'; import type { UpgradeAssistantConfig } from './config'; import type { DataSourceExclusions, FeatureSet } from '../common/types'; import { defaultExclusions } from './lib/data_source_exclusions'; +import { ReindexingService } from './reindexing_service'; interface PluginsSetup { usageCollection: UsageCollectionSetup; @@ -59,40 +53,33 @@ export class UpgradeAssistantServerPlugin implements Plugin { private readonly initialFeatureSet: FeatureSet; private readonly initialDataSourceExclusions: DataSourceExclusions; - // Properties set at setup - private licensing?: LicensingPluginSetup; - // Properties set at start private savedObjectsServiceStart?: SavedObjectsServiceStart; private securityPluginStart?: SecurityPluginStart; - private worker?: ReindexWorker; + + private reindexingService?: ReindexingService; constructor({ logger, env, config }: PluginInitializerContext) { this.logger = logger.get(); + // used by worker and passed to routes this.credentialStore = credentialStoreFactory(this.logger); this.kibanaVersion = env.packageInfo.version; const { featureSet, dataSourceExclusions } = config.get(); this.initialFeatureSet = featureSet; this.initialDataSourceExclusions = Object.assign({}, defaultExclusions, dataSourceExclusions); + this.reindexingService = new ReindexingService({ logger: this.logger, config }); } - private getWorker() { - if (!this.worker) { - throw new Error('Worker unavailable'); - } - return this.worker; - } - - setup( - { http, deprecations, getStartServices, savedObjects, docLinks }: CoreSetup, - { usageCollection, features, licensing, logsShared, security }: PluginsSetup - ) { - this.licensing = licensing; + setup(coreSetup: CoreSetup, pluginSetup: PluginsSetup) { + const { http, getStartServices, savedObjects } = coreSetup; + const { usageCollection, features, licensing, logsShared, security } = pluginSetup; savedObjects.registerType(reindexOperationSavedObjectType); savedObjects.registerType(mlSavedObjectType); + this.reindexingService?.setup(coreSetup, pluginSetup); + features.registerElasticsearchFeature({ id: 'upgrade_assistant', management: { @@ -149,7 +136,7 @@ export class UpgradeAssistantServerPlugin implements Plugin { defaultTarget: versionService.getNextMajorVersion(), }; - registerRoutes(dependencies, this.getWorker.bind(this)); + registerRoutes(dependencies); if (usageCollection) { void getStartServices().then(([{ elasticsearch }]) => { @@ -172,23 +159,11 @@ export class UpgradeAssistantServerPlugin implements Plugin { // process jobs without the browser staying on the page, but will require that jobs go into // a paused state if no Kibana nodes have the required credentials. - this.worker = createReindexWorker({ - credentialStore: this.credentialStore, - licensing: this.licensing!, - elasticsearchService: elasticsearch, - logger: this.logger, - savedObjects: new SavedObjectsClient( - this.savedObjectsServiceStart.createInternalRepository(hiddenTypes) - ), - security: this.securityPluginStart, - }); - - this.worker.start(); + // The ReindexWorker will use the credentials stored in the cache to reindex the data + this.reindexingService?.start({ savedObjects, elasticsearch }, { security }); } stop(): void { - if (this.worker) { - this.worker.stop(); - } + this.reindexingService?.stop(); } } diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/__mocks__/request.mock.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/__mocks__/request.mock.ts new file mode 100644 index 0000000000000..c77f3a6661ebe --- /dev/null +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/__mocks__/request.mock.ts @@ -0,0 +1,15 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export const createRequestMock = (opts?: { + headers?: any; + params?: Record; + query?: Record; + body?: Record; +}) => { + return Object.assign({ headers: {} }, opts || {}); +}; diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/__mocks__/routes.mock.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/__mocks__/routes.mock.ts new file mode 100644 index 0000000000000..3e6870391328a --- /dev/null +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/__mocks__/routes.mock.ts @@ -0,0 +1,59 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { AwaitedProperties } from '@kbn/utility-types'; +import { RequestHandler, RequestHandlerContext } from '@kbn/core/server'; +import { + elasticsearchServiceMock, + savedObjectsClientMock, + deprecationsServiceMock, +} from '@kbn/core/server/mocks'; + +export const savedObjectsClient = savedObjectsClientMock.create(); +export const routeHandlerContextMock = { + core: { + elasticsearch: { + client: elasticsearchServiceMock.createScopedClusterClient(), + }, + savedObjects: { getClient: () => savedObjectsClient }, + deprecations: { client: deprecationsServiceMock.createClient() }, + }, +} as unknown as AwaitedProperties; + +/** + * Creates a very crude mock of the new platform router implementation. This enables use to test + * controller/handler logic without making HTTP requests to an actual server. This does not enable + * us to test whether our paths actual match, only the response codes of controllers given certain + * inputs. This should be replaced by a more wholistic solution (like functional tests) eventually. + * + * This also bypasses any validation installed on the route. + */ +export const createMockRouter = () => { + const paths: Record>> = {}; + + const assign = + (method: string) => + ({ path }: { path: string }, handler: RequestHandler) => { + paths[method] = { + ...(paths[method] || {}), + ...{ [path]: handler }, + }; + }; + + return { + getHandler({ method, pathPattern }: { method: string; pathPattern: string }) { + return paths[method][pathPattern]; + }, + get: assign('get'), + post: assign('post'), + put: assign('put'), + patch: assign('patch'), + delete: assign('delete'), + }; +}; + +export type MockRouter = ReturnType; diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/config.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/config.ts new file mode 100644 index 0000000000000..ce95d77025e74 --- /dev/null +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/config.ts @@ -0,0 +1,15 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { schema, TypeOf } from '@kbn/config-schema'; +import { dataSourceExclusionsSchema, featureSetSchema } from '../config'; + +const configSchema = schema.object({ + dataSourceExclusions: dataSourceExclusionsSchema, + featureSet: featureSetSchema, +}); + +export type ReindexingServiceConfig = TypeOf; diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/create_reindex_worker.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/create_reindex_worker.ts similarity index 89% rename from x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/create_reindex_worker.ts rename to x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/create_reindex_worker.ts index 81c65330d14b6..9fb19c93c4b4b 100644 --- a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/create_reindex_worker.ts +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/create_reindex_worker.ts @@ -9,8 +9,8 @@ import { ElasticsearchServiceStart, Logger, SavedObjectsClient } from '@kbn/core import { LicensingPluginSetup } from '@kbn/licensing-plugin/server'; import { SecurityPluginStart } from '@kbn/security-plugin/server'; -import { ReindexWorker } from '../../lib/reindexing'; -import { CredentialStore } from '../../lib/reindexing/credential_store'; +import { ReindexWorker } from '../lib/reindexing'; +import { CredentialStore } from '../lib/reindexing/credential_store'; interface CreateReindexWorker { logger: Logger; diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/index.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/index.ts new file mode 100644 index 0000000000000..eb9c82e902146 --- /dev/null +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/index.ts @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { ReindexingService } from './reindexing_service'; diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/lib/index.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/lib/index.ts new file mode 100644 index 0000000000000..6ca4dbfbb3c76 --- /dev/null +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/lib/index.ts @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { reindexHandler } from './reindex_handler'; diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/reindex_handler.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/lib/reindex_handler.ts similarity index 100% rename from x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/reindex_handler.ts rename to x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/lib/reindex_handler.ts diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/reindexing_service.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/reindexing_service.ts new file mode 100644 index 0000000000000..4a8300efb1dd6 --- /dev/null +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/reindexing_service.ts @@ -0,0 +1,124 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { + CoreSetup, + Logger, + SavedObjectsClient, + LoggerFactory, + SavedObjectsServiceStart, + ElasticsearchServiceStart, +} from '@kbn/core/server'; +import { SecurityPluginStart, SecurityPluginSetup } from '@kbn/security-plugin/server'; +import { LicensingPluginSetup } from '@kbn/licensing-plugin/server'; +import { ReindexWorker } from '../lib/reindexing'; +import { createReindexWorker } from './create_reindex_worker'; +import { CredentialStore, credentialStoreFactory } from '../lib/reindexing/credential_store'; +import { hiddenTypes } from '../saved_object_types'; +import { registerBatchReindexIndicesRoutes, registerReindexIndicesRoutes } from './routes'; +import { handleEsError } from '../shared_imports'; +import { ReindexingServiceConfig } from './config'; +import { defaultExclusions } from '../lib/data_source_exclusions'; +import type { DataSourceExclusions, FeatureSet } from '../../common/types'; + +import { RouteDependencies } from './types'; + +interface PluginsStart { + security: SecurityPluginStart; +} + +interface PluginsSetup { + licensing: LicensingPluginSetup; + security?: SecurityPluginSetup; +} + +interface ReindexingServiceType { + logger: LoggerFactory; + config: { get: () => ReindexingServiceConfig }; +} + +export class ReindexingService { + private reindexWorker: ReindexWorker | null = null; + + // Properties set at setup + private licensing?: LicensingPluginSetup; + + private readonly logger: Logger; + private readonly credentialStore: CredentialStore; + private securityPluginStart?: SecurityPluginStart; + private readonly initialFeatureSet: FeatureSet; + private readonly initialDataSourceExclusions: DataSourceExclusions; + + constructor({ logger, config }: ReindexingServiceType) { + this.logger = logger.get(); + // used by worker and passed to routes + this.credentialStore = credentialStoreFactory(this.logger); + + const { featureSet, dataSourceExclusions } = config.get(); + this.initialFeatureSet = featureSet; + this.initialDataSourceExclusions = Object.assign({}, defaultExclusions, dataSourceExclusions); + } + + public setup({ http }: CoreSetup, { licensing, security }: PluginsSetup) { + this.licensing = licensing; + // todo routing + const router = http.createRouter(); + + const dependencies: RouteDependencies = { + router, + credentialStore: this.credentialStore, + log: this.logger, + licensing, + getSecurityPlugin: () => this.securityPluginStart, + lib: { + handleEsError, + }, + config: { + featureSet: this.initialFeatureSet, + dataSourceExclusions: this.initialDataSourceExclusions, + isSecurityEnabled: () => security !== undefined && security.license.isEnabled(), + }, + }; + + registerReindexIndicesRoutes(dependencies, () => this.getWorker()); + registerBatchReindexIndicesRoutes(dependencies, () => this.getWorker()); + } + + public start( + { + savedObjects, + elasticsearch, + }: { savedObjects: SavedObjectsServiceStart; elasticsearch: ElasticsearchServiceStart }, + { security }: PluginsStart + ) { + this.securityPluginStart = security; + + this.reindexWorker = createReindexWorker({ + credentialStore: this.credentialStore, + licensing: this.licensing!, + elasticsearchService: elasticsearch, + logger: this.logger, + savedObjects: new SavedObjectsClient(savedObjects.createInternalRepository(hiddenTypes)), + security: this.securityPluginStart, + }); + + this.reindexWorker.start(); + } + + public stop() { + if (this.reindexWorker) { + this.reindexWorker.stop(); + } + } + + private getWorker() { + if (!this.reindexWorker) { + throw new Error('Worker unavailable'); + } + return this.reindexWorker; + } +} diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/batch_reindex_indices.test.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/batch_reindex_indices.test.ts similarity index 100% rename from x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/batch_reindex_indices.test.ts rename to x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/batch_reindex_indices.test.ts diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/batch_reindex_indices.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/batch_reindex_indices.ts similarity index 97% rename from x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/batch_reindex_indices.ts rename to x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/batch_reindex_indices.ts index 6abc8d4e40ee7..db6eee126f9df 100644 --- a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/batch_reindex_indices.ts +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/batch_reindex_indices.ts @@ -14,9 +14,9 @@ import { versionCheckHandlerWrapper } from '../../lib/es_version_precheck'; import { ReindexWorker } from '../../lib/reindexing'; import { reindexActionsFactory } from '../../lib/reindexing/reindex_actions'; import { sortAndOrderReindexOperations } from '../../lib/reindexing/op_utils'; -import { RouteDependencies } from '../../types'; +import { RouteDependencies } from '../types'; import { mapAnyErrorToKibanaHttpResponse } from './map_any_error_to_kibana_http_response'; -import { reindexHandler } from './reindex_handler'; +import { reindexHandler } from '../lib/reindex_handler'; import { GetBatchQueueResponse, PostBatchResponse } from './types'; export function registerBatchReindexIndicesRoutes( diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/index.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/index.ts similarity index 86% rename from x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/index.ts rename to x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/index.ts index 038f0c07c11fe..81f574f9872b8 100644 --- a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/index.ts +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/index.ts @@ -5,6 +5,5 @@ * 2.0. */ -export { createReindexWorker } from './create_reindex_worker'; export { registerReindexIndicesRoutes } from './reindex_indices'; export { registerBatchReindexIndicesRoutes } from './batch_reindex_indices'; diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/map_any_error_to_kibana_http_response.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/map_any_error_to_kibana_http_response.ts similarity index 100% rename from x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/map_any_error_to_kibana_http_response.ts rename to x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/map_any_error_to_kibana_http_response.ts diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/reindex_indices.test.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/reindex_indices.test.ts similarity index 100% rename from x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/reindex_indices.test.ts rename to x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/reindex_indices.test.ts diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/reindex_indices.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/reindex_indices.ts similarity index 98% rename from x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/reindex_indices.ts rename to x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/reindex_indices.ts index a241b54d4bf47..cc383720a1598 100644 --- a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/reindex_indices.ts +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/reindex_indices.ts @@ -13,9 +13,9 @@ import { ReindexStatusResponse, REINDEX_OP_TYPE } from '../../../common/types'; import { versionCheckHandlerWrapper } from '../../lib/es_version_precheck'; import { reindexServiceFactory, ReindexWorker, generateNewIndexName } from '../../lib/reindexing'; import { reindexActionsFactory } from '../../lib/reindexing/reindex_actions'; -import { RouteDependencies } from '../../types'; +import { RouteDependencies } from '../types'; import { mapAnyErrorToKibanaHttpResponse } from './map_any_error_to_kibana_http_response'; -import { reindexHandler } from './reindex_handler'; +import { reindexHandler } from '../lib/reindex_handler'; export function registerReindexIndicesRoutes( { diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/types.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/types.ts similarity index 100% rename from x-pack/platform/plugins/private/upgrade_assistant/server/routes/reindex_indices/types.ts rename to x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/routes/types.ts diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/types.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/types.ts new file mode 100644 index 0000000000000..e0ba9412fea1e --- /dev/null +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/reindexing_service/types.ts @@ -0,0 +1,29 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { IRouter, Logger } from '@kbn/core/server'; +import { LicensingPluginSetup } from '@kbn/licensing-plugin/server'; +import { SecurityPluginStart } from '@kbn/security-plugin/server'; +import { CredentialStore } from '../lib/reindexing/credential_store'; +import { handleEsError } from '../shared_imports'; +import type { DataSourceExclusions, FeatureSet } from '../../common/types'; + +export interface RouteDependencies { + router: IRouter; + credentialStore: CredentialStore; + log: Logger; + getSecurityPlugin: () => SecurityPluginStart | undefined; + licensing: LicensingPluginSetup; + lib: { + handleEsError: typeof handleEsError; + }; + config: { + dataSourceExclusions: DataSourceExclusions; + featureSet: FeatureSet; + isSecurityEnabled: () => boolean; + }; +} diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/register_routes.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/routes/register_routes.ts index c94a4a378a360..b1534ce0caa28 100644 --- a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/register_routes.ts +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/routes/register_routes.ts @@ -13,10 +13,8 @@ import { registerClusterUpgradeStatusRoutes } from './cluster_upgrade_status'; import { registerSystemIndicesMigrationRoutes } from './system_indices_migration'; import { registerESDeprecationRoutes } from './es_deprecations'; import { registerDeprecationLoggingRoutes } from './deprecation_logging'; -import { registerReindexIndicesRoutes, registerBatchReindexIndicesRoutes } from './reindex_indices'; import { registerUpdateSettingsRoute } from './update_index_settings'; import { registerMlSnapshotRoutes } from './ml_snapshots'; -import { ReindexWorker } from '../lib/reindexing'; import { registerUpgradeStatusRoute } from './status'; import { registerRemoteClustersRoute } from './remote_clusters'; import { registerNodeDiskSpaceRoute } from './node_disk_space'; @@ -24,7 +22,7 @@ import { registerClusterSettingsRoute } from './cluster_settings'; import { registerMigrateDataStreamRoutes } from './migrate_data_streams'; import { registerUpdateIndexRoute } from './update_index'; -export function registerRoutes(dependencies: RouteDependencies, getWorker: () => ReindexWorker) { +export function registerRoutes(dependencies: RouteDependencies) { registerAppRoutes(dependencies); registerCloudBackupStatusRoutes(dependencies); @@ -32,8 +30,6 @@ export function registerRoutes(dependencies: RouteDependencies, getWorker: () => registerSystemIndicesMigrationRoutes(dependencies); registerESDeprecationRoutes(dependencies); registerDeprecationLoggingRoutes(dependencies); - registerReindexIndicesRoutes(dependencies, getWorker); - registerBatchReindexIndicesRoutes(dependencies, getWorker); registerUpdateSettingsRoute(dependencies); registerMlSnapshotRoutes(dependencies); // Route for cloud to retrieve the upgrade status for ES and Kibana