Skip to content

Commit

Permalink
changes based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Nov 4, 2020
1 parent b732d77 commit 2dae54e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/ml/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { getPluginPrivileges } from '../common/types/capabilities';
import { setupCapabilitiesSwitcher } from './lib/capabilities';
import { registerKibanaSettings } from './lib/register_settings';
import { trainedModelsRoutes } from './routes/trained_models';
import { setupSavedObjects, jobInitializationFactory } from './saved_objects';
import { setupSavedObjects, jobSavedObjectsInitializationFactory } from './saved_objects';
import { RouteGuard } from './lib/route_guard';

export type MlPluginSetup = SharedServices;
Expand Down Expand Up @@ -188,7 +188,7 @@ export class MlServerPlugin implements Plugin<MlPluginSetup, MlPluginStart, Plug

// check whether the job saved objects exist
// and create them if needed.
const { initializeJobs } = jobInitializationFactory(coreStart);
const { initializeJobs } = jobSavedObjectsInitializationFactory(coreStart);
await initializeJobs();
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/server/saved_objects/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export function checksFactory(
filter: [
{
term: {
type: 'ml-job',
type: ML_SAVED_OBJECT_TYPE,
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export { setupSavedObjects } from './saved_objects';
export { JobObject, JobSavedObjectService, jobSavedObjectServiceFactory } from './service';
export { checksFactory } from './checks';
export { repairFactory } from './repair';
export { jobInitializationFactory } from './initialization';
export { jobSavedObjectsInitializationFactory } from './initialization';
38 changes: 25 additions & 13 deletions x-pack/plugins/ml/server/saved_objects/initialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,35 @@ import { getInternalSavedObjectsClient } from './util';
import { repairFactory } from './repair';
import { jobSavedObjectServiceFactory } from './service';
import { mlLog } from '../lib/log';
import { ML_SAVED_OBJECT_TYPE } from '../../common/types/saved_objects';

export function jobInitializationFactory(core: CoreStart) {
const client = core.elasticsearch.client;
/**
* Creates initializeJobs function which is used to check whether
* ml job saved objects exist and creates them if needed
*
* @param core: CoreStart
*/
export function jobSavedObjectsInitializationFactory(core: CoreStart) {
const client = (core.elasticsearch.client as unknown) as IScopedClusterClient;

/**
* Check whether ML saved objects exist.
* If they don't, check to see whether ML jobs exist.
* If jobs exist, but the saved objects do not, create the saved objects.
*
*/
async function initializeJobs() {
try {
if (await _needsInitializing()) {
mlLog.info('Initializing job saved objects');
const savedObjectsClient = getInternalSavedObjectsClient(core);
const jobSavedObjectService = jobSavedObjectServiceFactory(savedObjectsClient);
const { initSavedObjects } = repairFactory(
(client as unknown) as IScopedClusterClient,
jobSavedObjectService
);
await initSavedObjects();
mlLog.info('Job saved objects initialized for * space');
if ((await _needsInitializing()) === false) {
// ml job saved objects have already been initialized
return;
}
mlLog.info('Initializing job saved objects');
const savedObjectsClient = getInternalSavedObjectsClient(core);
const jobSavedObjectService = jobSavedObjectServiceFactory(savedObjectsClient);
const { initSavedObjects } = repairFactory(client, jobSavedObjectService);
await initSavedObjects();
mlLog.info('Job saved objects initialized for * space');
} catch (error) {
mlLog.error('Error Initializing jobs');
}
Expand Down Expand Up @@ -64,7 +76,7 @@ export function jobInitializationFactory(core: CoreStart) {
filter: [
{
term: {
type: 'ml-job',
type: ML_SAVED_OBJECT_TYPE,
},
},
],
Expand Down

0 comments on commit 2dae54e

Please sign in to comment.