forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from tsullivan/alerting/task-scheduler-srcserver
Move to task manager module to src/server
- Loading branch information
Showing
23 changed files
with
173 additions
and
128 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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 { TaskManager } from './task_pool'; | ||
import { TaskInstance } from './task_pool/task'; | ||
|
||
export class TaskManagerClientWrapper { | ||
private client: TaskManager | null; | ||
|
||
constructor() { | ||
this.client = null; | ||
} | ||
|
||
public setClient(client: TaskManager) { | ||
this.client = client; | ||
} | ||
|
||
public schedule(task: TaskInstance) { | ||
if (this.client == null) { | ||
throw new Error('Task Manager Client has not been set properly!'); | ||
} | ||
this.client.schedule(task); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { taskManagerMixin } from './task_manager_mixin'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* 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 Joi from 'joi'; | ||
import { TaskManagerClientWrapper } from './client_wrapper'; | ||
import { | ||
Logger, | ||
TaskDefinition, | ||
TaskDictionary, | ||
TaskManager, | ||
TaskPool, | ||
TaskStore, | ||
validateTaskDefinition, | ||
} from './task_pool'; | ||
import { SanitizedTaskDefinition } from './task_pool/task'; | ||
|
||
export async function taskManagerMixin(kbnServer: any, server: any, config: any) { | ||
const logger = new Logger((...args) => server.log(...args)); | ||
const numWorkers = config.get('taskManager.num_workers'); | ||
const definitions = extractTaskDefinitions(numWorkers, kbnServer.uiExports.taskDefinitions); | ||
|
||
server.decorate('server', 'taskManager', new TaskManagerClientWrapper()); | ||
|
||
kbnServer.afterPluginsInit(async () => { | ||
const callCluster = server.plugins.elasticsearch.getCluster('admin').callWithInternalUser; | ||
const store = new TaskStore({ | ||
index: config.get('taskManager.index'), | ||
callCluster, | ||
maxAttempts: config.get('taskManager.max_attempts'), | ||
}); | ||
|
||
logger.debug('Initializing the task manager index'); | ||
await store.init(); | ||
|
||
const pool = new TaskPool({ | ||
logger, | ||
callCluster, | ||
numWorkers, | ||
store, | ||
definitions, | ||
pollInterval: config.get('taskManager.poll_interval'), | ||
kbnServer, | ||
}); | ||
|
||
pool.start(); | ||
|
||
const client = new TaskManager({ store, pool }); | ||
server.taskManager.setClient(client); | ||
}); | ||
} | ||
|
||
// TODO, move this to a file and properly test it, validate the taskDefinition via Joi or something | ||
function extractTaskDefinitions( | ||
numWorkers: number, | ||
taskDefinitions: TaskDictionary<TaskDefinition> = {} | ||
): TaskDictionary<SanitizedTaskDefinition> { | ||
return Object.keys(taskDefinitions).reduce( | ||
(acc, type) => { | ||
const rawDefinition = taskDefinitions[type]; | ||
rawDefinition.type = type; | ||
const definition = Joi.attempt(rawDefinition, validateTaskDefinition) as TaskDefinition; | ||
const workersOccupied = Math.min(numWorkers, definition.workersOccupied || 1); | ||
|
||
acc[type] = { | ||
...definition, | ||
workersOccupied, | ||
}; | ||
|
||
return acc; | ||
}, | ||
{} as TaskDictionary<SanitizedTaskDefinition> | ||
); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters