Skip to content

Commit

Permalink
[ML] Changing shared module setup function parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Jul 2, 2020
1 parent 7d63caf commit ad6b84d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export class DataRecognizer {
// takes a module config id, an optional jobPrefix and the request object
// creates all of the jobs, datafeeds and savedObjects listed in the module config.
// if any of the savedObjects already exist, they will not be overwritten.
async setupModuleItems(
async setup(
moduleId: string,
jobPrefix?: string,
groups?: string[],
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/ml/server/routes/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function getModule(context: RequestHandlerContext, moduleId: string) {
}
}

function saveModuleItems(
function setup(
context: RequestHandlerContext,
moduleId: string,
prefix?: string,
Expand All @@ -57,7 +57,7 @@ function saveModuleItems(
context.ml!.mlClient.callAsCurrentUser,
context.core.savedObjects.client
);
return dr.setupModuleItems(
return dr.setup(
moduleId,
prefix,
groups,
Expand Down Expand Up @@ -438,7 +438,7 @@ export function dataRecognizer({ router, mlLicense }: RouteInitialization) {
estimateModelMemory,
} = request.body as TypeOf<typeof setupModuleBodySchema>;

const result = await saveModuleItems(
const result = await setup(
context,
moduleId,
prefix,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ml/server/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
export * from '../common/types/anomalies';
export * from '../common/types/anomaly_detection_jobs';
export * from './lib/capabilities/errors';
export { ModuleSetupPayload } from './shared_services/providers/modules';
23 changes: 20 additions & 3 deletions x-pack/plugins/ml/server/shared_services/providers/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
*/

import { LegacyAPICaller, KibanaRequest, SavedObjectsClientContract } from 'kibana/server';
import { TypeOf } from '@kbn/config-schema';
import { DataRecognizer } from '../../models/data_recognizer';
import { SharedServicesChecks } from '../shared_services';
import { setupModuleBodySchema } from '../../routes/schemas/modules';

export type ModuleSetupPayload = { moduleId: string } & TypeOf<typeof setupModuleBodySchema>;

export interface ModulesProvider {
modulesProvider(
Expand All @@ -17,7 +21,7 @@ export interface ModulesProvider {
recognize: DataRecognizer['findMatches'];
getModule: DataRecognizer['getModule'];
listModules: DataRecognizer['listModules'];
setupModuleItems: DataRecognizer['setupModuleItems'];
setup(payload: ModuleSetupPayload): ReturnType<DataRecognizer['setup']>;
};
}

Expand Down Expand Up @@ -52,11 +56,24 @@ export function getModulesProvider({

return dr.listModules();
},
async setupModuleItems(...args) {
async setup(payload: ModuleSetupPayload) {
isFullLicense();
await hasMlCapabilities(['canCreateJob']);

return dr.setupModuleItems(...args);
return dr.setup(
payload.moduleId,
payload.prefix,
payload.groups,
payload.indexPatternName,
payload.query,
payload.useDedicatedIndex,
payload.startDatafeed,
payload.start,
payload.end,
payload.jobOverrides,
payload.datafeedOverrides,
payload.estimateModelMemory
);
},
};
},
Expand Down

0 comments on commit ad6b84d

Please sign in to comment.