Skip to content

Commit 2dae54e

Browse files
committed
changes based on review
1 parent b732d77 commit 2dae54e

4 files changed

Lines changed: 29 additions & 17 deletions

File tree

x-pack/plugins/ml/server/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { getPluginPrivileges } from '../common/types/capabilities';
5050
import { setupCapabilitiesSwitcher } from './lib/capabilities';
5151
import { registerKibanaSettings } from './lib/register_settings';
5252
import { trainedModelsRoutes } from './routes/trained_models';
53-
import { setupSavedObjects, jobInitializationFactory } from './saved_objects';
53+
import { setupSavedObjects, jobSavedObjectsInitializationFactory } from './saved_objects';
5454
import { RouteGuard } from './lib/route_guard';
5555

5656
export type MlPluginSetup = SharedServices;
@@ -188,7 +188,7 @@ export class MlServerPlugin implements Plugin<MlPluginSetup, MlPluginStart, Plug
188188

189189
// check whether the job saved objects exist
190190
// and create them if needed.
191-
const { initializeJobs } = jobInitializationFactory(coreStart);
191+
const { initializeJobs } = jobSavedObjectsInitializationFactory(coreStart);
192192
await initializeJobs();
193193
}
194194

x-pack/plugins/ml/server/saved_objects/checks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export function checksFactory(
172172
filter: [
173173
{
174174
term: {
175-
type: 'ml-job',
175+
type: ML_SAVED_OBJECT_TYPE,
176176
},
177177
},
178178
],

x-pack/plugins/ml/server/saved_objects/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export { setupSavedObjects } from './saved_objects';
88
export { JobObject, JobSavedObjectService, jobSavedObjectServiceFactory } from './service';
99
export { checksFactory } from './checks';
1010
export { repairFactory } from './repair';
11-
export { jobInitializationFactory } from './initialization';
11+
export { jobSavedObjectsInitializationFactory } from './initialization';

x-pack/plugins/ml/server/saved_objects/initialization.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,35 @@ import { getInternalSavedObjectsClient } from './util';
1515
import { repairFactory } from './repair';
1616
import { jobSavedObjectServiceFactory } from './service';
1717
import { mlLog } from '../lib/log';
18+
import { ML_SAVED_OBJECT_TYPE } from '../../common/types/saved_objects';
1819

19-
export function jobInitializationFactory(core: CoreStart) {
20-
const client = core.elasticsearch.client;
20+
/**
21+
* Creates initializeJobs function which is used to check whether
22+
* ml job saved objects exist and creates them if needed
23+
*
24+
* @param core: CoreStart
25+
*/
26+
export function jobSavedObjectsInitializationFactory(core: CoreStart) {
27+
const client = (core.elasticsearch.client as unknown) as IScopedClusterClient;
2128

29+
/**
30+
* Check whether ML saved objects exist.
31+
* If they don't, check to see whether ML jobs exist.
32+
* If jobs exist, but the saved objects do not, create the saved objects.
33+
*
34+
*/
2235
async function initializeJobs() {
2336
try {
24-
if (await _needsInitializing()) {
25-
mlLog.info('Initializing job saved objects');
26-
const savedObjectsClient = getInternalSavedObjectsClient(core);
27-
const jobSavedObjectService = jobSavedObjectServiceFactory(savedObjectsClient);
28-
const { initSavedObjects } = repairFactory(
29-
(client as unknown) as IScopedClusterClient,
30-
jobSavedObjectService
31-
);
32-
await initSavedObjects();
33-
mlLog.info('Job saved objects initialized for * space');
37+
if ((await _needsInitializing()) === false) {
38+
// ml job saved objects have already been initialized
39+
return;
3440
}
41+
mlLog.info('Initializing job saved objects');
42+
const savedObjectsClient = getInternalSavedObjectsClient(core);
43+
const jobSavedObjectService = jobSavedObjectServiceFactory(savedObjectsClient);
44+
const { initSavedObjects } = repairFactory(client, jobSavedObjectService);
45+
await initSavedObjects();
46+
mlLog.info('Job saved objects initialized for * space');
3547
} catch (error) {
3648
mlLog.error('Error Initializing jobs');
3749
}
@@ -64,7 +76,7 @@ export function jobInitializationFactory(core: CoreStart) {
6476
filter: [
6577
{
6678
term: {
67-
type: 'ml-job',
79+
type: ML_SAVED_OBJECT_TYPE,
6880
},
6981
},
7082
],

0 commit comments

Comments
 (0)