Skip to content

Commit

Permalink
moved Task Manager server code under "server" directory (#53777)
Browse files Browse the repository at this point in the history
Changes Task Manager folder structure to include a "server" folder as required by our linting rules as part of the migration to the Kibana Platform
  • Loading branch information
gmmorris committed Jan 3, 2020
1 parent c9851c7 commit 9ffebd5
Showing 68 changed files with 143 additions and 154 deletions.
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { taskManagerMock } from '../../task_manager/task_manager.mock';
import { taskManagerMock } from '../../task_manager/server/task_manager.mock';
import { ActionTypeRegistry } from './action_type_registry';
import { ExecutorType } from './types';
import { ActionExecutor, ExecutorError, TaskRunnerFactory } from './lib';
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
import Boom from 'boom';
import { i18n } from '@kbn/i18n';
import { TaskManagerSetupContract } from './shim';
import { RunContext } from '../../task_manager';
import { RunContext } from '../../task_manager/server';
import { ExecutorError, TaskRunnerFactory } from './lib';
import { ActionType } from './types';
import { ActionsConfigurationUtilities } from './actions_config';
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import { ActionTypeRegistry } from './action_type_registry';
import { ActionsClient } from './actions_client';
import { ExecutorType } from './types';
import { ActionExecutor, TaskRunnerFactory } from './lib';
import { taskManagerMock } from '../../task_manager/task_manager.mock';
import { taskManagerMock } from '../../task_manager/server/task_manager.mock';
import { configUtilsMock } from './actions_config.mock';
import { getActionsConfigurationUtilities } from './actions_config';

Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

import { ActionExecutor, TaskRunnerFactory } from '../lib';
import { ActionTypeRegistry } from '../action_type_registry';
import { taskManagerMock } from '../../../task_manager/task_manager.mock';
import { taskManagerMock } from '../../../task_manager/server/task_manager.mock';
import { registerBuiltInActionTypes } from './index';
import { Logger } from '../../../../../../src/core/server';
import { loggingServiceMock } from '../../../../../../src/core/server/mocks';
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { taskManagerMock } from '../../task_manager/task_manager.mock';
import { taskManagerMock } from '../../task_manager/server/task_manager.mock';
import { createExecuteFunction } from './create_execute_function';
import { savedObjectsClientMock } from '../../../../../src/core/server/mocks';

Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
import sinon from 'sinon';
import { ExecutorError } from './executor_error';
import { ActionExecutor } from './action_executor';
import { ConcreteTaskInstance, TaskStatus } from '../../../task_manager';
import { ConcreteTaskInstance, TaskStatus } from '../../../task_manager/server';
import { TaskRunnerFactory } from './task_runner_factory';
import { actionTypeRegistryMock } from '../action_type_registry.mock';
import { actionExecutorMock } from './action_executor.mock';
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

import { ActionExecutorContract } from './action_executor';
import { ExecutorError } from './executor_error';
import { RunContext } from '../../../task_manager';
import { RunContext } from '../../../task_manager/server';
import { PluginStartContract as EncryptedSavedObjectsStartContract } from '../../../../../plugins/encrypted_saved_objects/server';
import { ActionTaskParams, GetBasePathFunction, SpaceIdToNamespaceFunction } from '../types';

2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/actions/server/shim.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import Hapi from 'hapi';
import { Legacy } from 'kibana';
import * as Rx from 'rxjs';
import { ActionsConfigType } from './types';
import { TaskManager } from '../../task_manager';
import { TaskManager } from '../../task_manager/server';
import { XPackMainPlugin } from '../../xpack_main/server/xpack_main';
import KbnServer from '../../../../../src/legacy/server/kbn_server';
import { LegacySpacesPlugin as SpacesPluginStartContract } from '../../spaces';
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

import { TaskRunnerFactory } from './lib';
import { AlertTypeRegistry } from './alert_type_registry';
import { taskManagerMock } from '../../task_manager/task_manager.mock';
import { taskManagerMock } from '../../task_manager/server/task_manager.mock';

const taskManager = taskManagerMock.create();

Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
import Boom from 'boom';
import { i18n } from '@kbn/i18n';
import { TaskRunnerFactory } from './lib';
import { RunContext } from '../../task_manager';
import { RunContext } from '../../task_manager/server';
import { TaskManagerSetupContract } from './shim';
import { AlertType } from './types';

4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/alerting/server/alerts_client.test.ts
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@ import uuid from 'uuid';
import { schema } from '@kbn/config-schema';
import { AlertsClient } from './alerts_client';
import { savedObjectsClientMock, loggingServiceMock } from '../../../../../src/core/server/mocks';
import { taskManagerMock } from '../../task_manager/task_manager.mock';
import { taskManagerMock } from '../../task_manager/server/task_manager.mock';
import { alertTypeRegistryMock } from './alert_type_registry.mock';
import { TaskStatus } from '../../task_manager';
import { TaskStatus } from '../../task_manager/server';
import { IntervalSchedule } from './types';
import { resolvable } from './test_utils';

Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
import { Request } from 'hapi';
import { AlertsClientFactory, ConstructorOpts } from './alerts_client_factory';
import { alertTypeRegistryMock } from '../alert_type_registry.mock';
import { taskManagerMock } from '../../../task_manager/task_manager.mock';
import { taskManagerMock } from '../../../task_manager/server/task_manager.mock';
import { KibanaRequest } from '../../../../../../src/core/server';
import { loggingServiceMock } from '../../../../../../src/core/server/mocks';

Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
import sinon from 'sinon';
import { schema } from '@kbn/config-schema';
import { AlertExecutorOptions } from '../types';
import { ConcreteTaskInstance, TaskStatus } from '../../../task_manager';
import { ConcreteTaskInstance, TaskStatus } from '../../../task_manager/server';
import { TaskRunnerContext, TaskRunnerFactory } from './task_runner_factory';
import { encryptedSavedObjectsMock } from '../../../../../plugins/encrypted_saved_objects/server/mocks';
import {
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
*/

import { Logger } from '../../../../../../src/core/server';
import { RunContext } from '../../../task_manager';
import { RunContext } from '../../../task_manager/server';
import { createExecutionHandler } from './create_execution_handler';
import { createAlertInstanceFactory } from './create_alert_instance_factory';
import { AlertInstance } from './alert_instance';
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/alerting/server/shim.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
import Hapi from 'hapi';
import { Legacy } from 'kibana';
import { LegacySpacesPlugin as SpacesPluginStartContract } from '../../spaces';
import { TaskManager } from '../../task_manager';
import { TaskManager } from '../../task_manager/server';
import { XPackMainPlugin } from '../../xpack_main/server/xpack_main';
import KbnServer from '../../../../../src/legacy/server/kbn_server';
import {
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/lens/server/usage/task.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ import {
} from 'elasticsearch';
import { ESSearchResponse } from '../../../apm/typings/elasticsearch';
import { XPackMainPlugin } from '../../../xpack_main/server/xpack_main';
import { RunContext } from '../../../task_manager';
import { RunContext } from '../../../task_manager/server';
import { getVisualizationCounts } from './visualization_counts';

// This task is responsible for running daily and aggregating all the Lens click event objects
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
*/

import { get } from 'lodash';
import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../../../../task_manager/plugin';
import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../../../../task_manager/server/plugin';
import { PLUGIN_ID, VIS_TELEMETRY_TASK, VIS_USAGE_TYPE } from '../../../../constants';

async function isTaskManagerReady(taskManager: TaskManagerPluginSetupContract | undefined) {
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
*/

import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../../../../task_manager/plugin';
import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../../../../task_manager/server/plugin';
import { getUsageCollector } from './get_usage_collector';

export function registerVisualizationsCollector(
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/index.ts
Original file line number Diff line number Diff line change
@@ -5,12 +5,12 @@
*/

import { CoreSetup, Logger } from 'kibana/server';
import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../../../task_manager/plugin';
import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../../../task_manager/server/plugin';
import { PLUGIN_ID, VIS_TELEMETRY_TASK } from '../../../constants';
import { visualizationsTaskRunner } from './visualizations/task_runner';
import KbnServer from '../../../../../../../src/legacy/server/kbn_server';
import { LegacyConfig } from '../../plugin';
import { TaskInstance } from '../../../../task_manager';
import { TaskInstance } from '../../../../task_manager/server';

export function registerTasks({
taskManager,
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import {
getMockTaskInstance,
} from '../../../../test_utils';
import { visualizationsTaskRunner } from './task_runner';
import { TaskInstance } from '../../../../../task_manager';
import { TaskInstance } from '../../../../../task_manager/server';

describe('visualizationsTaskRunner', () => {
let mockTaskInstance: TaskInstance;
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import _, { countBy, groupBy, mapValues } from 'lodash';
import { APICaller, CoreSetup } from 'kibana/server';
import { getNextMidnight } from '../../get_next_midnight';
import { VisState } from '../../../../../../../../src/legacy/core_plugins/visualizations/public';
import { TaskInstance } from '../../../../../task_manager';
import { TaskInstance } from '../../../../../task_manager/server';
import { ESSearchHit } from '../../../../../apm/typings/elasticsearch';
import { LegacyConfig } from '../../../plugin';

2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/oss_telemetry/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
*/

import { CoreSetup, Logger, Plugin, PluginInitializerContext } from 'kibana/server';
import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../task_manager/plugin';
import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../task_manager/server/plugin';
import { registerCollectors } from './lib/collectors';
import { registerTasks, scheduleTasks } from './lib/tasks';
import KbnServer from '../../../../../src/legacy/server/kbn_server';
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/oss_telemetry/test_utils/index.ts
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@

import { APICaller, CoreSetup } from 'kibana/server';

import { TaskInstance } from '../../task_manager';
import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../task_manager/plugin';
import { TaskInstance } from '../../task_manager/server';
import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../task_manager/server/plugin';

export const getMockTaskInstance = (): TaskInstance => ({
state: { runs: 0, stats: {} },
95 changes: 1 addition & 94 deletions x-pack/legacy/plugins/task_manager/index.ts
Original file line number Diff line number Diff line change
@@ -4,97 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Root } from 'joi';
import { Legacy } from 'kibana';
import { Plugin, PluginSetupContract } from './plugin';
import { SavedObjectsSerializer, SavedObjectsSchema } from '../../../../src/core/server';
import mappings from './mappings.json';
import { migrations } from './migrations';

export { PluginSetupContract as TaskManager };
export {
TaskInstance,
ConcreteTaskInstance,
TaskRunCreatorFunction,
TaskStatus,
RunContext,
} from './task';

export function taskManager(kibana: any) {
return new kibana.Plugin({
id: 'task_manager',
require: ['kibana', 'elasticsearch', 'xpack_main'],
configPrefix: 'xpack.task_manager',
config(Joi: Root) {
return Joi.object({
enabled: Joi.boolean().default(true),
max_attempts: Joi.number()
.description(
'The maximum number of times a task will be attempted before being abandoned as failed'
)
.min(1)
.default(3),
poll_interval: Joi.number()
.description('How often, in milliseconds, the task manager will look for more work.')
.min(100)
.default(3000),
request_capacity: Joi.number()
.description('How many requests can Task Manager buffer before it rejects new requests.')
.min(1)
// a nice round contrived number, feel free to change as we learn how it behaves
.default(1000),
index: Joi.string()
.description('The name of the index used to store task information.')
.default('.kibana_task_manager')
.invalid(['.tasks']),
max_workers: Joi.number()
.description(
'The maximum number of tasks that this Kibana instance will run simultaneously.'
)
.min(1) // disable the task manager rather than trying to specify it with 0 workers
.default(10),
}).default();
},
init(server: Legacy.Server) {
const plugin = new Plugin({
logger: {
get: () => ({
info: (message: string) => server.log(['info', 'task_manager'], message),
debug: (message: string) => server.log(['debug', 'task_manager'], message),
warn: (message: string) => server.log(['warn', 'task_manager'], message),
error: (message: string) => server.log(['error', 'task_manager'], message),
}),
},
});
const schema = new SavedObjectsSchema(this.kbnServer.uiExports.savedObjectSchemas);
const serializer = new SavedObjectsSerializer(schema);
const setupContract = plugin.setup(
{},
{
serializer,
config: server.config(),
elasticsearch: server.plugins.elasticsearch,
savedObjects: server.savedObjects,
}
);
this.kbnServer.afterPluginsInit(() => {
plugin.start();
});
server.expose(setupContract);
},
uiExports: {
mappings,
migrations,
savedObjectSchemas: {
task: {
hidden: true,
isNamespaceAgnostic: true,
convertToAliasScript: `ctx._id = ctx._source.type + ':' + ctx._id`,
indexPattern(config: any) {
return config.get('xpack.task_manager.index');
},
},
},
},
});
}
export * from './server/';
Loading

0 comments on commit 9ffebd5

Please sign in to comment.