mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[ML] New Platform Migration - server (#38360)
* wip: pull out all server dependencies * create new platform plugin * shim newPlatform plugin into legacy init * update server tests for migration refactor * cleanup interfaces * Only add ML links for sample data sets if full license from - 38120 * update test and fix typescript errors * Remove unused types
This commit is contained in:
parent
4526e2a2b5
commit
c47a0d5cdf
35 changed files with 640 additions and 478 deletions
|
@ -1,166 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
import { resolve } from 'path';
|
||||
import Boom from 'boom';
|
||||
import { checkLicense } from './server/lib/check_license';
|
||||
import { addLinksToSampleDatasets } from './server/lib/sample_data_sets';
|
||||
import { FEATURE_ANNOTATIONS_ENABLED } from './common/constants/feature_flags';
|
||||
import { LICENSE_TYPE } from './common/constants/license';
|
||||
|
||||
import { mirrorPluginStatus } from '../../server/lib/mirror_plugin_status';
|
||||
import { annotationRoutes } from './server/routes/annotations';
|
||||
import { jobRoutes } from './server/routes/anomaly_detectors';
|
||||
import { dataFeedRoutes } from './server/routes/datafeeds';
|
||||
import { indicesRoutes } from './server/routes/indices';
|
||||
import { jobValidationRoutes } from './server/routes/job_validation';
|
||||
import mappings from './mappings';
|
||||
import { makeMlUsageCollector } from './server/lib/ml_telemetry';
|
||||
import { notificationRoutes } from './server/routes/notification_settings';
|
||||
import { systemRoutes } from './server/routes/system';
|
||||
import { dataFrameRoutes } from './server/routes/data_frame';
|
||||
import { dataRecognizer } from './server/routes/modules';
|
||||
import { dataVisualizerRoutes } from './server/routes/data_visualizer';
|
||||
import { calendars } from './server/routes/calendars';
|
||||
import { fieldsService } from './server/routes/fields_service';
|
||||
import { filtersRoutes } from './server/routes/filters';
|
||||
import { resultsServiceRoutes } from './server/routes/results_service';
|
||||
import { jobServiceRoutes } from './server/routes/job_service';
|
||||
import { jobAuditMessagesRoutes } from './server/routes/job_audit_messages';
|
||||
import { fileDataVisualizerRoutes } from './server/routes/file_data_visualizer';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { initMlServerLog } from './server/client/log';
|
||||
|
||||
|
||||
export const ml = (kibana) => {
|
||||
return new kibana.Plugin({
|
||||
require: ['kibana', 'elasticsearch', 'xpack_main'],
|
||||
id: 'ml',
|
||||
configPrefix: 'xpack.ml',
|
||||
publicDir: resolve(__dirname, 'public'),
|
||||
|
||||
uiExports: {
|
||||
app: {
|
||||
title: i18n.translate('xpack.ml.mlNavTitle', {
|
||||
defaultMessage: 'Machine Learning'
|
||||
}),
|
||||
description: i18n.translate('xpack.ml.mlNavDescription', {
|
||||
defaultMessage: 'Machine Learning for the Elastic Stack'
|
||||
}),
|
||||
icon: 'plugins/ml/ml.svg',
|
||||
euiIconType: 'machineLearningApp',
|
||||
main: 'plugins/ml/app',
|
||||
},
|
||||
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
|
||||
hacks: ['plugins/ml/hacks/toggle_app_link_in_nav'],
|
||||
savedObjectSchemas: {
|
||||
'ml-telemetry': {
|
||||
isNamespaceAgnostic: true
|
||||
}
|
||||
},
|
||||
mappings,
|
||||
home: ['plugins/ml/register_feature'],
|
||||
injectDefaultVars(server) {
|
||||
const config = server.config();
|
||||
return {
|
||||
mlEnabled: config.get('xpack.ml.enabled'),
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
init: async function (server) {
|
||||
const thisPlugin = this;
|
||||
const xpackMainPlugin = server.plugins.xpack_main;
|
||||
mirrorPluginStatus(xpackMainPlugin, thisPlugin);
|
||||
xpackMainPlugin.status.once('green', () => {
|
||||
// Register a function that is called whenever the xpack info changes,
|
||||
// to re-compute the license check results for this plugin
|
||||
const mlFeature = xpackMainPlugin.info.feature(thisPlugin.id);
|
||||
mlFeature.registerLicenseCheckResultsGenerator(checkLicense);
|
||||
|
||||
// Add links to the Kibana sample data sets if ml is enabled
|
||||
// and there is a full license (trial or platinum).
|
||||
if (mlFeature.isEnabled() === true) {
|
||||
const licenseCheckResults = mlFeature.getLicenseCheckResults();
|
||||
if (licenseCheckResults.licenseType === LICENSE_TYPE.FULL) {
|
||||
addLinksToSampleDatasets(server);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
xpackMainPlugin.registerFeature({
|
||||
id: 'ml',
|
||||
name: i18n.translate('xpack.ml.featureRegistry.mlFeatureName', {
|
||||
defaultMessage: 'Machine Learning',
|
||||
}),
|
||||
icon: 'machineLearningApp',
|
||||
navLinkId: 'ml',
|
||||
app: ['ml', 'kibana'],
|
||||
catalogue: ['ml'],
|
||||
privileges: {},
|
||||
reserved: {
|
||||
privilege: {
|
||||
savedObject: {
|
||||
all: [],
|
||||
read: []
|
||||
},
|
||||
ui: [],
|
||||
},
|
||||
description: i18n.translate('xpack.ml.feature.reserved.description', {
|
||||
defaultMessage: 'To grant users access, you should also assign either the machine_learning_user or machine_learning_admin role.'
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
// Add server routes and initialize the plugin here
|
||||
const commonRouteConfig = {
|
||||
pre: [
|
||||
function forbidApiAccess() {
|
||||
const licenseCheckResults = xpackMainPlugin.info.feature(thisPlugin.id).getLicenseCheckResults();
|
||||
if (licenseCheckResults.isAvailable) {
|
||||
return null;
|
||||
} else {
|
||||
throw Boom.forbidden(licenseCheckResults.message);
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
server.injectUiAppVars('ml', () => {
|
||||
const config = server.config();
|
||||
return {
|
||||
kbnIndex: config.get('kibana.index'),
|
||||
mlAnnotationsEnabled: FEATURE_ANNOTATIONS_ENABLED,
|
||||
};
|
||||
});
|
||||
|
||||
annotationRoutes(server, commonRouteConfig);
|
||||
jobRoutes(server, commonRouteConfig);
|
||||
dataFeedRoutes(server, commonRouteConfig);
|
||||
dataFrameRoutes(server, commonRouteConfig);
|
||||
indicesRoutes(server, commonRouteConfig);
|
||||
jobValidationRoutes(server, commonRouteConfig);
|
||||
notificationRoutes(server, commonRouteConfig);
|
||||
systemRoutes(server, commonRouteConfig);
|
||||
dataRecognizer(server, commonRouteConfig);
|
||||
dataVisualizerRoutes(server, commonRouteConfig);
|
||||
calendars(server, commonRouteConfig);
|
||||
fieldsService(server, commonRouteConfig);
|
||||
filtersRoutes(server, commonRouteConfig);
|
||||
resultsServiceRoutes(server, commonRouteConfig);
|
||||
jobServiceRoutes(server, commonRouteConfig);
|
||||
jobAuditMessagesRoutes(server, commonRouteConfig);
|
||||
fileDataVisualizerRoutes(server, commonRouteConfig);
|
||||
|
||||
initMlServerLog(server);
|
||||
makeMlUsageCollector(server);
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
94
x-pack/plugins/ml/index.ts
Normal file
94
x-pack/plugins/ml/index.ts
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { resolve } from 'path';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import KbnServer, { Server } from 'src/legacy/server/kbn_server';
|
||||
import { plugin } from './server/new_platform';
|
||||
import {
|
||||
MlInitializerContext,
|
||||
MlCoreSetup,
|
||||
MlHttpServiceSetup,
|
||||
} from './server/new_platform/plugin';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import mappings from './mappings';
|
||||
|
||||
interface MlServer extends Server {
|
||||
addAppLinksToSampleDataset: () => {};
|
||||
}
|
||||
|
||||
export const ml = (kibana: any) => {
|
||||
return new kibana.Plugin({
|
||||
require: ['kibana', 'elasticsearch', 'xpack_main'],
|
||||
id: 'ml',
|
||||
configPrefix: 'xpack.ml',
|
||||
publicDir: resolve(__dirname, 'public'),
|
||||
|
||||
uiExports: {
|
||||
app: {
|
||||
title: i18n.translate('xpack.ml.mlNavTitle', {
|
||||
defaultMessage: 'Machine Learning',
|
||||
}),
|
||||
description: i18n.translate('xpack.ml.mlNavDescription', {
|
||||
defaultMessage: 'Machine Learning for the Elastic Stack',
|
||||
}),
|
||||
icon: 'plugins/ml/ml.svg',
|
||||
euiIconType: 'machineLearningApp',
|
||||
main: 'plugins/ml/app',
|
||||
},
|
||||
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
|
||||
hacks: ['plugins/ml/hacks/toggle_app_link_in_nav'],
|
||||
savedObjectSchemas: {
|
||||
'ml-telemetry': {
|
||||
isNamespaceAgnostic: true,
|
||||
},
|
||||
},
|
||||
mappings,
|
||||
home: ['plugins/ml/register_feature'],
|
||||
injectDefaultVars(server: any) {
|
||||
const config = server.config();
|
||||
return {
|
||||
mlEnabled: config.get('xpack.ml.enabled'),
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
async init(server: MlServer) {
|
||||
const kbnServer = (server as unknown) as KbnServer;
|
||||
|
||||
const initializerContext = ({
|
||||
legacyConfig: server.config(),
|
||||
logger: {
|
||||
get(...contextParts: string[]) {
|
||||
return kbnServer.newPlatform.coreContext.logger.get('plugins', 'ml', ...contextParts);
|
||||
},
|
||||
},
|
||||
} as unknown) as MlInitializerContext;
|
||||
|
||||
const mlHttpService: MlHttpServiceSetup = {
|
||||
...kbnServer.newPlatform.setup.core.http,
|
||||
route: server.route.bind(server),
|
||||
};
|
||||
|
||||
const core: MlCoreSetup = {
|
||||
addAppLinksToSampleDataset: server.addAppLinksToSampleDataset,
|
||||
injectUiAppVars: server.injectUiAppVars,
|
||||
http: mlHttpService,
|
||||
savedObjects: server.savedObjects,
|
||||
usage: server.usage,
|
||||
};
|
||||
|
||||
const plugins = {
|
||||
elasticsearch: server.plugins.elasticsearch,
|
||||
security: server.plugins.security,
|
||||
xpackMain: server.plugins.xpack_main,
|
||||
ml: this,
|
||||
};
|
||||
|
||||
plugin(initializerContext).setup(core, plugins);
|
||||
},
|
||||
});
|
||||
};
|
|
@ -4,6 +4,6 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { Server } from 'hapi';
|
||||
import { ElasticsearchPlugin } from 'src/legacy/core_plugins/elasticsearch';
|
||||
|
||||
export function callWithInternalUserFactory(server: Server): any;
|
||||
export function callWithInternalUserFactory(elasticsearchPlugin: ElasticsearchPlugin): any;
|
||||
|
|
|
@ -8,13 +8,13 @@
|
|||
|
||||
import { once } from 'lodash';
|
||||
|
||||
const _callWithInternalUser = once((server) => {
|
||||
const { callWithInternalUser } = server.plugins.elasticsearch.getCluster('admin');
|
||||
const _callWithInternalUser = once((elasticsearchPlugin) => {
|
||||
const { callWithInternalUser } = elasticsearchPlugin.getCluster('admin');
|
||||
return callWithInternalUser;
|
||||
});
|
||||
|
||||
export const callWithInternalUserFactory = (server) => {
|
||||
export const callWithInternalUserFactory = (elasticsearchPlugin) => {
|
||||
return (...args) => {
|
||||
return _callWithInternalUser(server)(...args);
|
||||
return _callWithInternalUser(elasticsearchPlugin)(...args);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -8,25 +8,21 @@ import { callWithInternalUserFactory } from './call_with_internal_user_factory';
|
|||
|
||||
describe('call_with_internal_user_factory', () => {
|
||||
describe('callWithInternalUserFactory', () => {
|
||||
let server: any;
|
||||
let elasticsearchPlugin: any;
|
||||
let callWithInternalUser: any;
|
||||
|
||||
beforeEach(() => {
|
||||
callWithInternalUser = jest.fn();
|
||||
server = {
|
||||
plugins: {
|
||||
elasticsearch: {
|
||||
getCluster: jest.fn(() => ({ callWithInternalUser })),
|
||||
},
|
||||
},
|
||||
elasticsearchPlugin = {
|
||||
getCluster: jest.fn(() => ({ callWithInternalUser })),
|
||||
};
|
||||
});
|
||||
|
||||
it('should use internal user "admin"', () => {
|
||||
const callWithInternalUserInstance = callWithInternalUserFactory(server);
|
||||
const callWithInternalUserInstance = callWithInternalUserFactory(elasticsearchPlugin);
|
||||
callWithInternalUserInstance();
|
||||
|
||||
expect(server.plugins.elasticsearch.getCluster).toHaveBeenCalledWith('admin');
|
||||
expect(elasticsearchPlugin.getCluster).toHaveBeenCalledWith('admin');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -9,15 +9,15 @@
|
|||
import { once } from 'lodash';
|
||||
import { elasticsearchJsPlugin } from './elasticsearch_ml';
|
||||
|
||||
const callWithRequest = once((server) => {
|
||||
const callWithRequest = once((elasticsearchPlugin) => {
|
||||
const config = { plugins: [ elasticsearchJsPlugin ] };
|
||||
const cluster = server.plugins.elasticsearch.createCluster('ml', config);
|
||||
const cluster = elasticsearchPlugin.createCluster('ml', config);
|
||||
|
||||
return cluster.callWithRequest;
|
||||
});
|
||||
|
||||
export const callWithRequestFactory = (server, request) => {
|
||||
export const callWithRequestFactory = (elasticsearchPlugin, request) => {
|
||||
return (...args) => {
|
||||
return callWithRequest(server)(request, ...args);
|
||||
return callWithRequest(elasticsearchPlugin)(request, ...args);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
|
||||
export let mlLog = () => {};
|
||||
|
||||
export function initMlServerLog(server) {
|
||||
mlLog = (level, message) => server.log(['ml', level], message);
|
||||
export function initMlServerLog(log) {
|
||||
mlLog = (level, message) => log(['ml', level], message);
|
||||
}
|
||||
|
|
|
@ -13,17 +13,13 @@ import {
|
|||
|
||||
describe('ML - security utils', () => {
|
||||
|
||||
function mockServerFactory(isAvailable = true, isEnabled = true) {
|
||||
function mockXpackMainPluginFactory(isAvailable = true, isEnabled = true) {
|
||||
return {
|
||||
plugins: {
|
||||
xpack_main: {
|
||||
info: {
|
||||
isAvailable: () => isAvailable,
|
||||
feature: () => ({
|
||||
isEnabled: () => isEnabled
|
||||
})
|
||||
}
|
||||
}
|
||||
info: {
|
||||
isAvailable: () => isAvailable,
|
||||
feature: () => ({
|
||||
isEnabled: () => isEnabled
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -31,15 +27,15 @@ describe('ML - security utils', () => {
|
|||
describe('isSecurityDisabled', () => {
|
||||
|
||||
it('returns not disabled for given mock server object #1', () => {
|
||||
expect(isSecurityDisabled(mockServerFactory())).to.be(false);
|
||||
expect(isSecurityDisabled(mockXpackMainPluginFactory())).to.be(false);
|
||||
});
|
||||
|
||||
it('returns not disabled for given mock server object #2', () => {
|
||||
expect(isSecurityDisabled(mockServerFactory(false))).to.be(false);
|
||||
expect(isSecurityDisabled(mockXpackMainPluginFactory(false))).to.be(false);
|
||||
});
|
||||
|
||||
it('returns disabled for given mock server object #3', () => {
|
||||
expect(isSecurityDisabled(mockServerFactory(true, false))).to.be(true);
|
||||
expect(isSecurityDisabled(mockXpackMainPluginFactory(true, false))).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { Server } from 'hapi';
|
||||
|
||||
import {
|
||||
createMlTelemetry,
|
||||
getSavedObjectsClient,
|
||||
|
@ -14,23 +12,19 @@ import {
|
|||
MlTelemetrySavedObject,
|
||||
} from './ml_telemetry';
|
||||
|
||||
// TODO this type should be defined by the platform
|
||||
interface KibanaHapiServer extends Server {
|
||||
usage: {
|
||||
collectorSet: {
|
||||
makeUsageCollector: any;
|
||||
register: any;
|
||||
};
|
||||
};
|
||||
}
|
||||
import { UsageInitialization } from '../../new_platform/plugin';
|
||||
|
||||
export function makeMlUsageCollector(server: KibanaHapiServer): void {
|
||||
const mlUsageCollector = server.usage.collectorSet.makeUsageCollector({
|
||||
export function makeMlUsageCollector({
|
||||
elasticsearchPlugin,
|
||||
usage,
|
||||
savedObjects,
|
||||
}: UsageInitialization): void {
|
||||
const mlUsageCollector = usage.collectorSet.makeUsageCollector({
|
||||
type: 'ml',
|
||||
isReady: () => true,
|
||||
fetch: async (): Promise<MlTelemetry> => {
|
||||
try {
|
||||
const savedObjectsClient = getSavedObjectsClient(server);
|
||||
const savedObjectsClient = getSavedObjectsClient(elasticsearchPlugin, savedObjects);
|
||||
const mlTelemetrySavedObject = (await savedObjectsClient.get(
|
||||
'ml-telemetry',
|
||||
ML_TELEMETRY_DOC_ID
|
||||
|
@ -41,5 +35,5 @@ export function makeMlUsageCollector(server: KibanaHapiServer): void {
|
|||
}
|
||||
},
|
||||
});
|
||||
server.usage.collectorSet.register(mlUsageCollector);
|
||||
usage.collectorSet.register(mlUsageCollector);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,8 @@ describe('ml_telemetry', () => {
|
|||
});
|
||||
|
||||
describe('storeMlTelemetry', () => {
|
||||
let server: any;
|
||||
let elasticsearchPlugin: any;
|
||||
let savedObjects: any;
|
||||
let mlTelemetry: MlTelemetry;
|
||||
let savedObjectsClientInstance: any;
|
||||
|
||||
|
@ -34,16 +35,12 @@ describe('ml_telemetry', () => {
|
|||
savedObjectsClientInstance = { create: jest.fn() };
|
||||
const callWithInternalUser = jest.fn();
|
||||
const internalRepository = jest.fn();
|
||||
server = {
|
||||
savedObjects: {
|
||||
SavedObjectsClient: jest.fn(() => savedObjectsClientInstance),
|
||||
getSavedObjectsRepository: jest.fn(() => internalRepository),
|
||||
},
|
||||
plugins: {
|
||||
elasticsearch: {
|
||||
getCluster: jest.fn(() => ({ callWithInternalUser })),
|
||||
},
|
||||
},
|
||||
elasticsearchPlugin = {
|
||||
getCluster: jest.fn(() => ({ callWithInternalUser })),
|
||||
};
|
||||
savedObjects = {
|
||||
SavedObjectsClient: jest.fn(() => savedObjectsClientInstance),
|
||||
getSavedObjectsRepository: jest.fn(() => internalRepository),
|
||||
};
|
||||
mlTelemetry = {
|
||||
file_data_visualizer: {
|
||||
|
@ -53,24 +50,25 @@ describe('ml_telemetry', () => {
|
|||
});
|
||||
|
||||
it('should call savedObjectsClient create with the given MlTelemetry object', () => {
|
||||
storeMlTelemetry(server, mlTelemetry);
|
||||
storeMlTelemetry(elasticsearchPlugin, savedObjects, mlTelemetry);
|
||||
expect(savedObjectsClientInstance.create.mock.calls[0][1]).toBe(mlTelemetry);
|
||||
});
|
||||
|
||||
it('should call savedObjectsClient create with the ml-telemetry document type and ID', () => {
|
||||
storeMlTelemetry(server, mlTelemetry);
|
||||
storeMlTelemetry(elasticsearchPlugin, savedObjects, mlTelemetry);
|
||||
expect(savedObjectsClientInstance.create.mock.calls[0][0]).toBe('ml-telemetry');
|
||||
expect(savedObjectsClientInstance.create.mock.calls[0][2].id).toBe(ML_TELEMETRY_DOC_ID);
|
||||
});
|
||||
|
||||
it('should call savedObjectsClient create with overwrite: true', () => {
|
||||
storeMlTelemetry(server, mlTelemetry);
|
||||
storeMlTelemetry(elasticsearchPlugin, savedObjects, mlTelemetry);
|
||||
expect(savedObjectsClientInstance.create.mock.calls[0][2].overwrite).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSavedObjectsClient', () => {
|
||||
let server: any;
|
||||
let elasticsearchPlugin: any;
|
||||
let savedObjects: any;
|
||||
let savedObjectsClientInstance: any;
|
||||
let callWithInternalUser: any;
|
||||
let internalRepository: any;
|
||||
|
@ -79,29 +77,26 @@ describe('ml_telemetry', () => {
|
|||
savedObjectsClientInstance = { create: jest.fn() };
|
||||
callWithInternalUser = jest.fn();
|
||||
internalRepository = jest.fn();
|
||||
server = {
|
||||
savedObjects: {
|
||||
SavedObjectsClient: jest.fn(() => savedObjectsClientInstance),
|
||||
getSavedObjectsRepository: jest.fn(() => internalRepository),
|
||||
},
|
||||
plugins: {
|
||||
elasticsearch: {
|
||||
getCluster: jest.fn(() => ({ callWithInternalUser })),
|
||||
},
|
||||
},
|
||||
elasticsearchPlugin = {
|
||||
getCluster: jest.fn(() => ({ callWithInternalUser })),
|
||||
};
|
||||
savedObjects = {
|
||||
SavedObjectsClient: jest.fn(() => savedObjectsClientInstance),
|
||||
getSavedObjectsRepository: jest.fn(() => internalRepository),
|
||||
};
|
||||
});
|
||||
|
||||
it('should return a SavedObjectsClient initialized with the saved objects internal repository', () => {
|
||||
const result = getSavedObjectsClient(server);
|
||||
const result = getSavedObjectsClient(elasticsearchPlugin, savedObjects);
|
||||
|
||||
expect(result).toBe(savedObjectsClientInstance);
|
||||
expect(server.savedObjects.SavedObjectsClient).toHaveBeenCalledWith(internalRepository);
|
||||
expect(savedObjects.SavedObjectsClient).toHaveBeenCalledWith(internalRepository);
|
||||
});
|
||||
});
|
||||
|
||||
describe('incrementFileDataVisualizerIndexCreationCount', () => {
|
||||
let server: any;
|
||||
let elasticsearchPlugin: any;
|
||||
let savedObjects: any;
|
||||
let savedObjectsClientInstance: any;
|
||||
let callWithInternalUser: any;
|
||||
let internalRepository: any;
|
||||
|
@ -147,36 +142,32 @@ describe('ml_telemetry', () => {
|
|||
);
|
||||
callWithInternalUser = jest.fn();
|
||||
internalRepository = jest.fn();
|
||||
server = {
|
||||
savedObjects: {
|
||||
SavedObjectsClient: jest.fn(() => savedObjectsClientInstance),
|
||||
getSavedObjectsRepository: jest.fn(() => internalRepository),
|
||||
},
|
||||
plugins: {
|
||||
elasticsearch: {
|
||||
getCluster: jest.fn(() => ({ callWithInternalUser })),
|
||||
},
|
||||
},
|
||||
savedObjects = {
|
||||
SavedObjectsClient: jest.fn(() => savedObjectsClientInstance),
|
||||
getSavedObjectsRepository: jest.fn(() => internalRepository),
|
||||
};
|
||||
elasticsearchPlugin = {
|
||||
getCluster: jest.fn(() => ({ callWithInternalUser })),
|
||||
};
|
||||
}
|
||||
|
||||
it('should not increment if telemetry status cannot be determined', async () => {
|
||||
mockInit();
|
||||
await incrementFileDataVisualizerIndexCreationCount(server);
|
||||
await incrementFileDataVisualizerIndexCreationCount(elasticsearchPlugin, savedObjects);
|
||||
|
||||
expect(savedObjectsClientInstance.create.mock.calls).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should not increment if telemetry status is disabled', async () => {
|
||||
mockInit(false);
|
||||
await incrementFileDataVisualizerIndexCreationCount(server);
|
||||
await incrementFileDataVisualizerIndexCreationCount(elasticsearchPlugin, savedObjects);
|
||||
|
||||
expect(savedObjectsClientInstance.create.mock.calls).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should initialize index_creation_count with 1', async () => {
|
||||
mockInit(true);
|
||||
await incrementFileDataVisualizerIndexCreationCount(server);
|
||||
await incrementFileDataVisualizerIndexCreationCount(elasticsearchPlugin, savedObjects);
|
||||
|
||||
expect(savedObjectsClientInstance.create.mock.calls[0][0]).toBe('ml-telemetry');
|
||||
expect(savedObjectsClientInstance.create.mock.calls[0][1]).toEqual({
|
||||
|
@ -186,7 +177,7 @@ describe('ml_telemetry', () => {
|
|||
|
||||
it('should increment index_creation_count to 2', async () => {
|
||||
mockInit(true, 1);
|
||||
await incrementFileDataVisualizerIndexCreationCount(server);
|
||||
await incrementFileDataVisualizerIndexCreationCount(elasticsearchPlugin, savedObjects);
|
||||
|
||||
expect(savedObjectsClientInstance.create.mock.calls[0][0]).toBe('ml-telemetry');
|
||||
expect(savedObjectsClientInstance.create.mock.calls[0][1]).toEqual({
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { Server } from 'hapi';
|
||||
import { ElasticsearchPlugin } from 'src/legacy/core_plugins/elasticsearch';
|
||||
import { SavedObjectsService } from 'src/legacy/server/kbn_server';
|
||||
import { callWithInternalUserFactory } from '../../client/call_with_internal_user_factory';
|
||||
|
||||
export interface MlTelemetry {
|
||||
|
@ -26,24 +27,34 @@ export function createMlTelemetry(count: number = 0): MlTelemetry {
|
|||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function storeMlTelemetry(server: Server, mlTelemetry: MlTelemetry): void {
|
||||
const savedObjectsClient = getSavedObjectsClient(server);
|
||||
// savedObjects
|
||||
export function storeMlTelemetry(
|
||||
elasticsearchPlugin: ElasticsearchPlugin,
|
||||
savedObjects: SavedObjectsService,
|
||||
mlTelemetry: MlTelemetry
|
||||
): void {
|
||||
const savedObjectsClient = getSavedObjectsClient(elasticsearchPlugin, savedObjects);
|
||||
savedObjectsClient.create('ml-telemetry', mlTelemetry, {
|
||||
id: ML_TELEMETRY_DOC_ID,
|
||||
overwrite: true,
|
||||
});
|
||||
}
|
||||
|
||||
export function getSavedObjectsClient(server: Server): any {
|
||||
const { SavedObjectsClient, getSavedObjectsRepository } = server.savedObjects;
|
||||
const callWithInternalUser = callWithInternalUserFactory(server);
|
||||
// needs savedObjects and elasticsearchPlugin
|
||||
export function getSavedObjectsClient(
|
||||
elasticsearchPlugin: ElasticsearchPlugin,
|
||||
savedObjects: SavedObjectsService
|
||||
): any {
|
||||
const { SavedObjectsClient, getSavedObjectsRepository } = savedObjects;
|
||||
const callWithInternalUser = callWithInternalUserFactory(elasticsearchPlugin);
|
||||
const internalRepository = getSavedObjectsRepository(callWithInternalUser);
|
||||
return new SavedObjectsClient(internalRepository);
|
||||
}
|
||||
|
||||
export async function incrementFileDataVisualizerIndexCreationCount(server: Server): Promise<void> {
|
||||
const savedObjectsClient = getSavedObjectsClient(server);
|
||||
export async function incrementFileDataVisualizerIndexCreationCount(
|
||||
elasticsearchPlugin: ElasticsearchPlugin,
|
||||
savedObjects: SavedObjectsService
|
||||
): Promise<void> {
|
||||
const savedObjectsClient = getSavedObjectsClient(elasticsearchPlugin, savedObjects);
|
||||
|
||||
try {
|
||||
const { attributes } = await savedObjectsClient.get('telemetry', 'telemetry');
|
||||
|
@ -69,5 +80,5 @@ export async function incrementFileDataVisualizerIndexCreationCount(server: Serv
|
|||
}
|
||||
|
||||
const mlTelemetry = createMlTelemetry(indicesCount);
|
||||
storeMlTelemetry(server, mlTelemetry);
|
||||
storeMlTelemetry(elasticsearchPlugin, savedObjects, mlTelemetry);
|
||||
}
|
||||
|
|
|
@ -9,8 +9,7 @@
|
|||
* Contains utility functions related to x-pack security.
|
||||
*/
|
||||
|
||||
export function isSecurityDisabled(server) {
|
||||
const xpackMainPlugin = server.plugins.xpack_main;
|
||||
export function isSecurityDisabled(xpackMainPlugin) {
|
||||
const xpackInfo = (xpackMainPlugin && xpackMainPlugin.info);
|
||||
// we assume that `xpack.isAvailable()` always returns `true` because we're inside x-pack
|
||||
// if for whatever reason it returns `false`, `isSecurityDisabled()` would also return `false`
|
||||
|
|
|
@ -38,25 +38,22 @@ const callWithRequest = (method) => {
|
|||
// we replace the return value of the factory with the above mocked callWithRequest
|
||||
import * as mockModule from '../../../client/call_with_internal_user_factory';
|
||||
|
||||
// mock server
|
||||
function mockServerFactory(isEnabled = false, licenseType = 'platinum') {
|
||||
// mock xpack_main plugin
|
||||
function mockXpackMainPluginFactory(isEnabled = false, licenseType = 'platinum') {
|
||||
return {
|
||||
plugins: {
|
||||
xpack_main: {
|
||||
info: {
|
||||
isAvailable: () => true,
|
||||
feature: () => ({
|
||||
isEnabled: () => isEnabled
|
||||
}),
|
||||
license: {
|
||||
getType: () => licenseType
|
||||
}
|
||||
}
|
||||
info: {
|
||||
isAvailable: () => true,
|
||||
feature: () => ({
|
||||
isEnabled: () => isEnabled
|
||||
}),
|
||||
license: {
|
||||
getType: () => licenseType
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const mockElasticsearchPlugin = {};
|
||||
// mock configuration to be passed to the estimator
|
||||
const formConfig = {
|
||||
aggTypes: ['count'],
|
||||
|
@ -91,7 +88,7 @@ describe('ML - BucketSpanEstimator', () => {
|
|||
|
||||
it('call factory and estimator with security disabled', (done) => {
|
||||
expect(function () {
|
||||
const estimateBucketSpan = estimateBucketSpanFactory(callWithRequest, mockServerFactory());
|
||||
const estimateBucketSpan = estimateBucketSpanFactory(callWithRequest, mockElasticsearchPlugin, mockXpackMainPluginFactory());
|
||||
|
||||
estimateBucketSpan(formConfig).catch((catchData) => {
|
||||
expect(catchData).to.be('Unable to retrieve cluster setting search.max_buckets');
|
||||
|
@ -104,8 +101,7 @@ describe('ML - BucketSpanEstimator', () => {
|
|||
|
||||
it('call factory and estimator with security enabled and sufficient permissions.', (done) => {
|
||||
expect(function () {
|
||||
const estimateBucketSpan = estimateBucketSpanFactory(callWithRequest, mockServerFactory(true));
|
||||
|
||||
const estimateBucketSpan = estimateBucketSpanFactory(callWithRequest, mockElasticsearchPlugin, mockXpackMainPluginFactory(true));
|
||||
estimateBucketSpan(formConfig).catch((catchData) => {
|
||||
expect(catchData).to.be('Unable to retrieve cluster setting search.max_buckets');
|
||||
mockCallWithInternalUserFactory.verify();
|
||||
|
@ -117,7 +113,7 @@ describe('ML - BucketSpanEstimator', () => {
|
|||
|
||||
it('call factory and estimator with security enabled and insufficient permissions.', (done) => {
|
||||
expect(function () {
|
||||
const estimateBucketSpan = estimateBucketSpanFactory(callWithRequest, mockServerFactory(true));
|
||||
const estimateBucketSpan = estimateBucketSpanFactory(callWithRequest, mockElasticsearchPlugin, mockXpackMainPluginFactory(true));
|
||||
|
||||
estimateBucketSpan(formConfig).catch((catchData) => {
|
||||
expect(catchData).to.be('Insufficient permissions to call bucket span estimation.');
|
||||
|
|
|
@ -15,8 +15,8 @@ import { polledDataCheckerFactory } from './polled_data_checker';
|
|||
import { callWithInternalUserFactory } from '../../client/call_with_internal_user_factory';
|
||||
import { isSecurityDisabled } from '../../lib/security_utils';
|
||||
|
||||
export function estimateBucketSpanFactory(callWithRequest, server) {
|
||||
const callWithInternalUser = callWithInternalUserFactory(server);
|
||||
export function estimateBucketSpanFactory(callWithRequest, elasticsearchPlugin, xpackMainPlugin) {
|
||||
const callWithInternalUser = callWithInternalUserFactory(elasticsearchPlugin);
|
||||
const PolledDataChecker = polledDataCheckerFactory(callWithRequest);
|
||||
const SingleSeriesChecker = singleSeriesCheckerFactory(callWithRequest);
|
||||
|
||||
|
@ -372,7 +372,7 @@ export function estimateBucketSpanFactory(callWithRequest, server) {
|
|||
});
|
||||
}
|
||||
|
||||
if (isSecurityDisabled(server)) {
|
||||
if (isSecurityDisabled(xpackMainPlugin)) {
|
||||
getBucketSpanEstimation();
|
||||
} else {
|
||||
// if security is enabled, check that the user has permission to
|
||||
|
|
|
@ -21,7 +21,7 @@ import { validateInfluencers } from './validate_influencers';
|
|||
import { validateModelMemoryLimit } from './validate_model_memory_limit';
|
||||
import { validateTimeRange, isValidTimeField } from './validate_time_range';
|
||||
|
||||
export async function validateJob(callWithRequest, payload, kbnVersion = 'current', server) {
|
||||
export async function validateJob(callWithRequest, payload, kbnVersion = 'current', elasticsearchPlugin, xpackMainPlugin) {
|
||||
const messages = getMessages();
|
||||
|
||||
try {
|
||||
|
@ -101,7 +101,7 @@ export async function validateJob(callWithRequest, payload, kbnVersion = 'curren
|
|||
return VALIDATION_STATUS[messages[m.id].status] === VALIDATION_STATUS.ERROR;
|
||||
});
|
||||
|
||||
validationMessages.push(...await validateBucketSpan(callWithRequest, job, duration, server));
|
||||
validationMessages.push(...await validateBucketSpan(callWithRequest, job, duration, elasticsearchPlugin, xpackMainPlugin));
|
||||
validationMessages.push(...await validateTimeRange(callWithRequest, job, duration));
|
||||
|
||||
// only run the influencer and model memory limit checks
|
||||
|
|
|
@ -48,7 +48,7 @@ const pickBucketSpan = (bucketSpans) => {
|
|||
return bucketSpans[i];
|
||||
};
|
||||
|
||||
export async function validateBucketSpan(callWithRequest, job, duration, server) {
|
||||
export async function validateBucketSpan(callWithRequest, job, duration, elasticsearchPlugin, xpackMainPlugin) {
|
||||
validateJobObject(job);
|
||||
|
||||
// if there is no duration, do not run the estimate test
|
||||
|
@ -114,7 +114,7 @@ export async function validateBucketSpan(callWithRequest, job, duration, server)
|
|||
try {
|
||||
const estimations = estimatorConfigs.map((data) => {
|
||||
return new Promise((resolve) => {
|
||||
estimateBucketSpanFactory(callWithRequest, server)(data)
|
||||
estimateBucketSpanFactory(callWithRequest, elasticsearchPlugin, xpackMainPlugin)(data)
|
||||
.then(resolve)
|
||||
// this catch gets triggered when the estimation code runs without error
|
||||
// but isn't able to come up with a bucket span estimation.
|
||||
|
|
11
x-pack/plugins/ml/server/new_platform/index.ts
Normal file
11
x-pack/plugins/ml/server/new_platform/index.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { Plugin, MlInitializerContext } from './plugin';
|
||||
|
||||
export function plugin(initializerContext: MlInitializerContext) {
|
||||
return new Plugin(initializerContext);
|
||||
}
|
240
x-pack/plugins/ml/server/new_platform/plugin.ts
Normal file
240
x-pack/plugins/ml/server/new_platform/plugin.ts
Normal file
|
@ -0,0 +1,240 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import Boom from 'boom';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { ServerRoute } from 'hapi';
|
||||
import { KibanaConfig, SavedObjectsService } from 'src/legacy/server/kbn_server';
|
||||
import { HttpServiceSetup, Logger, PluginInitializerContext } from 'src/core/server';
|
||||
import { ElasticsearchPlugin } from 'src/legacy/core_plugins/elasticsearch';
|
||||
import { XPackMainPlugin } from '../../../xpack_main/xpack_main';
|
||||
import { addLinksToSampleDatasets } from '../lib/sample_data_sets';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { checkLicense } from '../lib/check_license';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { mirrorPluginStatus } from '../../../../server/lib/mirror_plugin_status';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { FEATURE_ANNOTATIONS_ENABLED } from '../../common/constants/feature_flags';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { LICENSE_TYPE } from '../../common/constants/license';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { annotationRoutes } from '../routes/annotations';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { jobRoutes } from '../routes/anomaly_detectors';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { dataFeedRoutes } from '../routes/datafeeds';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { indicesRoutes } from '../routes/indices';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { jobValidationRoutes } from '../routes/job_validation';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { makeMlUsageCollector } from '../lib/ml_telemetry';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { notificationRoutes } from '../routes/notification_settings';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { systemRoutes } from '../routes/system';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { dataFrameRoutes } from '../routes/data_frame';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { dataRecognizer } from '../routes/modules';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { dataVisualizerRoutes } from '../routes/data_visualizer';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { calendars } from '../routes/calendars';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { fieldsService } from '../routes/fields_service';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { filtersRoutes } from '../routes/filters';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { resultsServiceRoutes } from '../routes/results_service';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { jobServiceRoutes } from '../routes/job_service';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { jobAuditMessagesRoutes } from '../routes/job_audit_messages';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { fileDataVisualizerRoutes } from '../routes/file_data_visualizer';
|
||||
// @ts-ignore: could not find declaration file for module
|
||||
import { initMlServerLog } from '../client/log';
|
||||
|
||||
export interface MlHttpServiceSetup extends HttpServiceSetup {
|
||||
route(route: ServerRoute | ServerRoute[]): void;
|
||||
}
|
||||
|
||||
export interface MlXpackMainPlugin extends XPackMainPlugin {
|
||||
status?: any;
|
||||
}
|
||||
|
||||
export interface MlCoreSetup {
|
||||
addAppLinksToSampleDataset: () => any;
|
||||
injectUiAppVars: (id: string, callback: () => {}) => any;
|
||||
http: MlHttpServiceSetup;
|
||||
savedObjects: SavedObjectsService;
|
||||
usage: {
|
||||
collectorSet: {
|
||||
makeUsageCollector: any;
|
||||
register: (collector: any) => void;
|
||||
};
|
||||
};
|
||||
}
|
||||
export interface MlInitializerContext extends PluginInitializerContext {
|
||||
legacyConfig: KibanaConfig;
|
||||
log: Logger;
|
||||
}
|
||||
export interface PluginsSetup {
|
||||
elasticsearch: ElasticsearchPlugin;
|
||||
xpackMain: MlXpackMainPlugin;
|
||||
security: any;
|
||||
// TODO: this is temporary for `mirrorPluginStatus`
|
||||
ml: any;
|
||||
}
|
||||
export interface RouteInitialization {
|
||||
commonRouteConfig: any;
|
||||
config?: any;
|
||||
elasticsearchPlugin: ElasticsearchPlugin;
|
||||
route(route: ServerRoute | ServerRoute[]): void;
|
||||
xpackMainPlugin?: MlXpackMainPlugin;
|
||||
savedObjects?: SavedObjectsService;
|
||||
}
|
||||
export interface UsageInitialization {
|
||||
elasticsearchPlugin: ElasticsearchPlugin;
|
||||
usage: {
|
||||
collectorSet: {
|
||||
makeUsageCollector: any;
|
||||
register: (collector: any) => void;
|
||||
};
|
||||
};
|
||||
savedObjects: SavedObjectsService;
|
||||
}
|
||||
export interface LogInitialization {
|
||||
log: Logger;
|
||||
}
|
||||
export class Plugin {
|
||||
private readonly pluginId: string = 'ml';
|
||||
private config: any;
|
||||
private log: Logger;
|
||||
|
||||
constructor(initializerContext: MlInitializerContext) {
|
||||
this.config = initializerContext.legacyConfig;
|
||||
this.log = initializerContext.logger.get();
|
||||
}
|
||||
|
||||
public setup(core: MlCoreSetup, plugins: PluginsSetup) {
|
||||
const xpackMainPlugin: MlXpackMainPlugin = plugins.xpackMain;
|
||||
const { addAppLinksToSampleDataset, http, injectUiAppVars } = core;
|
||||
const pluginId = this.pluginId;
|
||||
|
||||
mirrorPluginStatus(xpackMainPlugin, plugins.ml);
|
||||
xpackMainPlugin.status.once('green', () => {
|
||||
// Register a function that is called whenever the xpack info changes,
|
||||
// to re-compute the license check results for this plugin
|
||||
const mlFeature = xpackMainPlugin.info.feature(pluginId);
|
||||
mlFeature.registerLicenseCheckResultsGenerator(checkLicense);
|
||||
|
||||
// Add links to the Kibana sample data sets if ml is enabled
|
||||
// and there is a full license (trial or platinum).
|
||||
if (mlFeature.isEnabled() === true) {
|
||||
const licenseCheckResults = mlFeature.getLicenseCheckResults();
|
||||
if (licenseCheckResults.licenseType === LICENSE_TYPE.FULL) {
|
||||
addLinksToSampleDatasets({ addAppLinksToSampleDataset });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
xpackMainPlugin.registerFeature({
|
||||
id: 'ml',
|
||||
name: i18n.translate('xpack.ml.featureRegistry.mlFeatureName', {
|
||||
defaultMessage: 'Machine Learning',
|
||||
}),
|
||||
icon: 'machineLearningApp',
|
||||
navLinkId: 'ml',
|
||||
app: ['ml', 'kibana'],
|
||||
catalogue: ['ml'],
|
||||
privileges: {},
|
||||
reserved: {
|
||||
privilege: {
|
||||
savedObject: {
|
||||
all: [],
|
||||
read: [],
|
||||
},
|
||||
ui: [],
|
||||
},
|
||||
description: i18n.translate('xpack.ml.feature.reserved.description', {
|
||||
defaultMessage:
|
||||
'To grant users access, you should also assign either the machine_learning_user or machine_learning_admin role.',
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
// Add server routes and initialize the plugin here
|
||||
const commonRouteConfig = {
|
||||
pre: [
|
||||
function forbidApiAccess() {
|
||||
const licenseCheckResults = xpackMainPlugin.info
|
||||
.feature(pluginId)
|
||||
.getLicenseCheckResults();
|
||||
if (licenseCheckResults.isAvailable) {
|
||||
return null;
|
||||
} else {
|
||||
throw Boom.forbidden(licenseCheckResults.message);
|
||||
}
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
injectUiAppVars('ml', () => {
|
||||
return {
|
||||
kbnIndex: this.config.get('kibana.index'),
|
||||
mlAnnotationsEnabled: FEATURE_ANNOTATIONS_ENABLED,
|
||||
};
|
||||
});
|
||||
|
||||
const routeInitializationDeps: RouteInitialization = {
|
||||
commonRouteConfig,
|
||||
route: http.route,
|
||||
elasticsearchPlugin: plugins.elasticsearch,
|
||||
};
|
||||
|
||||
const extendedRouteInitializationDeps: RouteInitialization = {
|
||||
...routeInitializationDeps,
|
||||
config: this.config,
|
||||
xpackMainPlugin: plugins.xpackMain,
|
||||
savedObjects: core.savedObjects,
|
||||
};
|
||||
|
||||
const usageInitializationDeps: UsageInitialization = {
|
||||
elasticsearchPlugin: plugins.elasticsearch,
|
||||
usage: core.usage,
|
||||
savedObjects: core.savedObjects,
|
||||
};
|
||||
|
||||
const logInitializationDeps: LogInitialization = {
|
||||
log: this.log,
|
||||
};
|
||||
|
||||
annotationRoutes(routeInitializationDeps);
|
||||
jobRoutes(routeInitializationDeps);
|
||||
dataFeedRoutes(routeInitializationDeps);
|
||||
dataFrameRoutes(routeInitializationDeps);
|
||||
indicesRoutes(routeInitializationDeps);
|
||||
jobValidationRoutes(extendedRouteInitializationDeps);
|
||||
notificationRoutes(routeInitializationDeps);
|
||||
systemRoutes(extendedRouteInitializationDeps);
|
||||
dataRecognizer(routeInitializationDeps);
|
||||
dataVisualizerRoutes(routeInitializationDeps);
|
||||
calendars(routeInitializationDeps);
|
||||
fieldsService(routeInitializationDeps);
|
||||
filtersRoutes(routeInitializationDeps);
|
||||
resultsServiceRoutes(routeInitializationDeps);
|
||||
jobServiceRoutes(routeInitializationDeps);
|
||||
jobAuditMessagesRoutes(routeInitializationDeps);
|
||||
fileDataVisualizerRoutes(extendedRouteInitializationDeps);
|
||||
|
||||
initMlServerLog(logInitializationDeps);
|
||||
makeMlUsageCollector(usageInitializationDeps);
|
||||
}
|
||||
|
||||
public stop() {}
|
||||
}
|
|
@ -23,12 +23,12 @@ function getAnnotationsFeatureUnavailableErrorMessage() {
|
|||
})
|
||||
);
|
||||
}
|
||||
export function annotationRoutes(server, commonRouteConfig) {
|
||||
server.route({
|
||||
export function annotationRoutes({ commonRouteConfig, elasticsearchPlugin, route }) {
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/annotations',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { getAnnotations } = annotationServiceProvider(callWithRequest);
|
||||
return getAnnotations(request.payload)
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -38,11 +38,11 @@ export function annotationRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'PUT',
|
||||
path: '/api/ml/annotations/index',
|
||||
async handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const annotationsFeatureAvailable = await isAnnotationsFeatureAvailable(callWithRequest);
|
||||
if (annotationsFeatureAvailable === false) {
|
||||
return getAnnotationsFeatureUnavailableErrorMessage();
|
||||
|
@ -58,11 +58,11 @@ export function annotationRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'DELETE',
|
||||
path: '/api/ml/annotations/delete/{annotationId}',
|
||||
async handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const annotationsFeatureAvailable = await isAnnotationsFeatureAvailable(callWithRequest);
|
||||
if (annotationsFeatureAvailable === false) {
|
||||
return getAnnotationsFeatureUnavailableErrorMessage();
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
import { callWithRequestFactory } from '../client/call_with_request_factory';
|
||||
import { wrapError } from '../client/errors';
|
||||
|
||||
export function jobRoutes(server, commonRouteConfig) {
|
||||
export function jobRoutes({ commonRouteConfig, elasticsearchPlugin, route }) {
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/anomaly_detectors',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return callWithRequest('ml.jobs')
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -24,11 +24,11 @@ export function jobRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/anomaly_detectors/{jobId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const jobId = request.params.jobId;
|
||||
return callWithRequest('ml.jobs', { jobId })
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -38,11 +38,11 @@ export function jobRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/anomaly_detectors/_stats',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return callWithRequest('ml.jobStats')
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -51,11 +51,11 @@ export function jobRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/anomaly_detectors/{jobId}/_stats',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const jobId = request.params.jobId;
|
||||
return callWithRequest('ml.jobStats', { jobId })
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -65,11 +65,11 @@ export function jobRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'PUT',
|
||||
path: '/api/ml/anomaly_detectors/{jobId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const jobId = request.params.jobId;
|
||||
const body = request.payload;
|
||||
return callWithRequest('ml.addJob', { jobId, body })
|
||||
|
@ -80,11 +80,11 @@ export function jobRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/anomaly_detectors/{jobId}/_update',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const jobId = request.params.jobId;
|
||||
const body = request.payload;
|
||||
return callWithRequest('ml.updateJob', { jobId, body })
|
||||
|
@ -95,11 +95,11 @@ export function jobRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/anomaly_detectors/{jobId}/_open',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const jobId = request.params.jobId;
|
||||
return callWithRequest('ml.openJob', { jobId })
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -109,11 +109,11 @@ export function jobRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/anomaly_detectors/{jobId}/_close',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const options = {
|
||||
jobId: request.params.jobId
|
||||
};
|
||||
|
@ -129,11 +129,11 @@ export function jobRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'DELETE',
|
||||
path: '/api/ml/anomaly_detectors/{jobId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const options = {
|
||||
jobId: request.params.jobId
|
||||
};
|
||||
|
@ -149,11 +149,11 @@ export function jobRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/anomaly_detectors/_validate/detector',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const body = request.payload;
|
||||
return callWithRequest('ml.validateDetector', { body })
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -163,11 +163,11 @@ export function jobRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/anomaly_detectors/{jobId}/_forecast',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const jobId = request.params.jobId;
|
||||
const duration = request.payload.duration;
|
||||
return callWithRequest('ml.forecast', { jobId, duration })
|
||||
|
@ -178,11 +178,11 @@ export function jobRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/anomaly_detectors/{jobId}/results/overall_buckets',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return callWithRequest('ml.overallBuckets', {
|
||||
jobId: request.params.jobId,
|
||||
top_n: request.payload.topN,
|
||||
|
|
|
@ -36,13 +36,13 @@ function deleteCalendar(callWithRequest, calendarId) {
|
|||
return cal.deleteCalendar(calendarId);
|
||||
}
|
||||
|
||||
export function calendars(server, commonRouteConfig) {
|
||||
export function calendars({ commonRouteConfig, elasticsearchPlugin, route }) {
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/calendars',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return getAllCalendars(callWithRequest)
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -51,11 +51,11 @@ export function calendars(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/calendars/{calendarId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const calendarId = request.params.calendarId;
|
||||
return getCalendar(callWithRequest, calendarId)
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -65,11 +65,11 @@ export function calendars(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'PUT',
|
||||
path: '/api/ml/calendars',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const body = request.payload;
|
||||
return newCalendar(callWithRequest, body)
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -79,11 +79,11 @@ export function calendars(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'PUT',
|
||||
path: '/api/ml/calendars/{calendarId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const calendarId = request.params.calendarId;
|
||||
const body = request.payload;
|
||||
return updateCalendar(callWithRequest, calendarId, body)
|
||||
|
@ -94,11 +94,11 @@ export function calendars(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'DELETE',
|
||||
path: '/api/ml/calendars/{calendarId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const calendarId = request.params.calendarId;
|
||||
return deleteCalendar(callWithRequest, calendarId)
|
||||
.catch(resp => wrapError(resp));
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
import { callWithRequestFactory } from '../client/call_with_request_factory';
|
||||
import { wrapError } from '../client/errors';
|
||||
|
||||
export function dataFrameRoutes(server, commonRouteConfig) {
|
||||
export function dataFrameRoutes({ commonRouteConfig, elasticsearchPlugin, route }) {
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/_data_frame/transforms',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return callWithRequest('ml.getDataFrameTransforms')
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -22,11 +22,11 @@ export function dataFrameRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/_data_frame/transforms/_stats',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return callWithRequest('ml.getDataFrameTransformsStats')
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -35,11 +35,11 @@ export function dataFrameRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/_data_frame/transforms/{jobId}/_stats',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { jobId } = request.params;
|
||||
return callWithRequest('ml.getDataFrameTransformsStats', { jobId })
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -49,11 +49,11 @@ export function dataFrameRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'PUT',
|
||||
path: '/api/ml/_data_frame/transforms/{jobId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { jobId } = request.params;
|
||||
return callWithRequest('ml.createDataFrameTransformsJob', { body: request.payload, jobId })
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -63,11 +63,11 @@ export function dataFrameRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'DELETE',
|
||||
path: '/api/ml/_data_frame/transforms/{jobId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { jobId } = request.params;
|
||||
return callWithRequest('ml.deleteDataFrameTransformsJob', { jobId })
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -77,11 +77,11 @@ export function dataFrameRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/_data_frame/transforms/_preview',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return callWithRequest('ml.getDataFrameTransformsPreview', { body: request.payload })
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -90,11 +90,11 @@ export function dataFrameRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/_data_frame/transforms/{jobId}/_start',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { jobId } = request.params;
|
||||
return callWithRequest('ml.startDataFrameTransformsJob', { jobId })
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -104,11 +104,11 @@ export function dataFrameRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/_data_frame/transforms/{jobId}/_stop',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const options = {
|
||||
jobId: request.params.jobId
|
||||
};
|
||||
|
|
|
@ -60,13 +60,13 @@ function getStatsForFields(
|
|||
}
|
||||
|
||||
|
||||
export function dataVisualizerRoutes(server, commonRouteConfig) {
|
||||
export function dataVisualizerRoutes({ commonRouteConfig, elasticsearchPlugin, route }) {
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/data_visualizer/get_field_stats/{indexPatternTitle}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const indexPatternTitle = request.params.indexPatternTitle;
|
||||
const payload = request.payload;
|
||||
return getStatsForFields(
|
||||
|
@ -87,11 +87,11 @@ export function dataVisualizerRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/data_visualizer/get_overall_stats/{indexPatternTitle}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const indexPatternTitle = request.params.indexPatternTitle;
|
||||
const payload = request.payload;
|
||||
return getOverallStats(
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
import { callWithRequestFactory } from '../client/call_with_request_factory';
|
||||
import { wrapError } from '../client/errors';
|
||||
|
||||
export function dataFeedRoutes(server, commonRouteConfig) {
|
||||
export function dataFeedRoutes({ commonRouteConfig, elasticsearchPlugin, route }) {
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/datafeeds',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return callWithRequest('ml.datafeeds')
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -24,11 +24,11 @@ export function dataFeedRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/datafeeds/{datafeedId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const datafeedId = request.params.datafeedId;
|
||||
return callWithRequest('ml.datafeeds', { datafeedId })
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -38,11 +38,11 @@ export function dataFeedRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/datafeeds/_stats',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return callWithRequest('ml.datafeedStats')
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -51,11 +51,11 @@ export function dataFeedRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/datafeeds/{datafeedId}/_stats',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const datafeedId = request.params.datafeedId;
|
||||
return callWithRequest('ml.datafeedStats', { datafeedId })
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -65,11 +65,11 @@ export function dataFeedRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'PUT',
|
||||
path: '/api/ml/datafeeds/{datafeedId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const datafeedId = request.params.datafeedId;
|
||||
const body = request.payload;
|
||||
return callWithRequest('ml.addDatafeed', { datafeedId, body })
|
||||
|
@ -80,11 +80,11 @@ export function dataFeedRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/datafeeds/{datafeedId}/_update',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const datafeedId = request.params.datafeedId;
|
||||
const body = request.payload;
|
||||
return callWithRequest('ml.updateDatafeed', { datafeedId, body })
|
||||
|
@ -95,11 +95,11 @@ export function dataFeedRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'DELETE',
|
||||
path: '/api/ml/datafeeds/{datafeedId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const options = {
|
||||
datafeedId: request.params.datafeedId
|
||||
};
|
||||
|
@ -115,11 +115,11 @@ export function dataFeedRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/datafeeds/{datafeedId}/_start',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const datafeedId = request.params.datafeedId;
|
||||
const start = request.payload.start;
|
||||
const end = request.payload.end;
|
||||
|
@ -131,11 +131,11 @@ export function dataFeedRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/datafeeds/{datafeedId}/_stop',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const datafeedId = request.params.datafeedId;
|
||||
return callWithRequest('ml.stopDatafeed', { datafeedId })
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -145,11 +145,11 @@ export function dataFeedRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/datafeeds/{datafeedId}/_preview',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const datafeedId = request.params.datafeedId;
|
||||
return callWithRequest('ml.datafeedPreview', { datafeedId })
|
||||
.catch(resp => wrapError(resp));
|
||||
|
|
|
@ -41,13 +41,13 @@ function getTimeFieldRange(callWithRequest, payload) {
|
|||
query);
|
||||
}
|
||||
|
||||
export function fieldsService(server, commonRouteConfig) {
|
||||
export function fieldsService({ commonRouteConfig, elasticsearchPlugin, route }) {
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/fields_service/field_cardinality',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return getCardinalityOfFields(callWithRequest, request.payload)
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -56,11 +56,11 @@ export function fieldsService(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/fields_service/time_field_range',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return getTimeFieldRange(callWithRequest, request.payload)
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
|
|
@ -21,12 +21,12 @@ function importData(callWithRequest, id, index, settings, mappings, ingestPipeli
|
|||
return importDataFunc(id, index, settings, mappings, ingestPipeline, data);
|
||||
}
|
||||
|
||||
export function fileDataVisualizerRoutes(server, commonRouteConfig) {
|
||||
server.route({
|
||||
export function fileDataVisualizerRoutes({ commonRouteConfig, elasticsearchPlugin, route, savedObjects }) {
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/file_data_visualizer/analyze_file',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const data = request.payload;
|
||||
|
||||
return analyzeFiles(callWithRequest, data, request.query)
|
||||
|
@ -38,11 +38,11 @@ export function fileDataVisualizerRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/file_data_visualizer/import',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { id } = request.query;
|
||||
const { index, data, settings, mappings, ingestPipeline } = request.payload;
|
||||
|
||||
|
@ -50,7 +50,7 @@ export function fileDataVisualizerRoutes(server, commonRouteConfig) {
|
|||
// follow-up import calls to just add additional data will include the `id` of the created
|
||||
// index, we'll ignore those and don't increment the counter.
|
||||
if (id === undefined) {
|
||||
incrementFileDataVisualizerIndexCreationCount(server);
|
||||
incrementFileDataVisualizerIndexCreationCount(elasticsearchPlugin, savedObjects);
|
||||
}
|
||||
|
||||
return importData(callWithRequest, id, index, settings, mappings, ingestPipeline, data)
|
||||
|
|
|
@ -48,13 +48,13 @@ function deleteFilter(callWithRequest, filterId) {
|
|||
return mgr.deleteFilter(filterId);
|
||||
}
|
||||
|
||||
export function filtersRoutes(server, commonRouteConfig) {
|
||||
export function filtersRoutes({ commonRouteConfig, elasticsearchPlugin, route }) {
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/filters',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return getAllFilters(callWithRequest)
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -63,11 +63,11 @@ export function filtersRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/filters/_stats',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return getAllFilterStats(callWithRequest)
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -76,11 +76,11 @@ export function filtersRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/filters/{filterId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const filterId = request.params.filterId;
|
||||
return getFilter(callWithRequest, filterId)
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -90,11 +90,11 @@ export function filtersRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'PUT',
|
||||
path: '/api/ml/filters',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const body = request.payload;
|
||||
return newFilter(callWithRequest, body)
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -104,11 +104,11 @@ export function filtersRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'PUT',
|
||||
path: '/api/ml/filters/{filterId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const filterId = request.params.filterId;
|
||||
const payload = request.payload;
|
||||
return updateFilter(
|
||||
|
@ -124,11 +124,11 @@ export function filtersRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'DELETE',
|
||||
path: '/api/ml/filters/{filterId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const filterId = request.params.filterId;
|
||||
return deleteFilter(callWithRequest, filterId)
|
||||
.catch(resp => wrapError(resp));
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
import { callWithRequestFactory } from '../client/call_with_request_factory';
|
||||
import { wrapError } from '../client/errors';
|
||||
|
||||
export function indicesRoutes(server, commonRouteConfig) {
|
||||
export function indicesRoutes({ commonRouteConfig, elasticsearchPlugin, route }) {
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/indices/field_caps',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const index = request.payload.index;
|
||||
let fields = '*';
|
||||
if (request.payload.fields !== undefined && Array.isArray(request.payload.fields)) {
|
||||
|
|
|
@ -10,12 +10,12 @@ import { callWithRequestFactory } from '../client/call_with_request_factory';
|
|||
import { wrapError } from '../client/errors';
|
||||
import { jobAuditMessagesProvider } from '../models/job_audit_messages';
|
||||
|
||||
export function jobAuditMessagesRoutes(server, commonRouteConfig) {
|
||||
server.route({
|
||||
export function jobAuditMessagesRoutes({ commonRouteConfig, elasticsearchPlugin, route }) {
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/job_audit_messages/messages/{jobId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { getJobAuditMessages } = jobAuditMessagesProvider(callWithRequest);
|
||||
const { jobId } = request.params;
|
||||
const from = request.query.from;
|
||||
|
@ -27,11 +27,11 @@ export function jobAuditMessagesRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/job_audit_messages/messages',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { getJobAuditMessages } = jobAuditMessagesProvider(callWithRequest);
|
||||
const from = request.query.from;
|
||||
return getJobAuditMessages(undefined, from)
|
||||
|
|
|
@ -10,12 +10,12 @@ import { callWithRequestFactory } from '../client/call_with_request_factory';
|
|||
import { wrapError } from '../client/errors';
|
||||
import { jobServiceProvider } from '../models/job_service';
|
||||
|
||||
export function jobServiceRoutes(server, commonRouteConfig) {
|
||||
server.route({
|
||||
export function jobServiceRoutes({ commonRouteConfig, elasticsearchPlugin, route }) {
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/jobs/force_start_datafeeds',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { forceStartDatafeeds } = jobServiceProvider(callWithRequest);
|
||||
const {
|
||||
datafeedIds,
|
||||
|
@ -30,11 +30,11 @@ export function jobServiceRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/jobs/stop_datafeeds',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { stopDatafeeds } = jobServiceProvider(callWithRequest);
|
||||
const { datafeedIds } = request.payload;
|
||||
return stopDatafeeds(datafeedIds)
|
||||
|
@ -45,11 +45,11 @@ export function jobServiceRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/jobs/delete_jobs',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { deleteJobs } = jobServiceProvider(callWithRequest);
|
||||
const { jobIds } = request.payload;
|
||||
return deleteJobs(jobIds)
|
||||
|
@ -60,11 +60,11 @@ export function jobServiceRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/jobs/close_jobs',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { closeJobs } = jobServiceProvider(callWithRequest);
|
||||
const { jobIds } = request.payload;
|
||||
return closeJobs(jobIds)
|
||||
|
@ -75,11 +75,11 @@ export function jobServiceRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/jobs/jobs_summary',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { jobsSummary } = jobServiceProvider(callWithRequest);
|
||||
const { jobIds } = request.payload;
|
||||
return jobsSummary(jobIds)
|
||||
|
@ -90,11 +90,11 @@ export function jobServiceRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/jobs/jobs_with_timerange',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { jobsWithTimerange } = jobServiceProvider(callWithRequest);
|
||||
const { dateFormatTz } = request.payload;
|
||||
return jobsWithTimerange(dateFormatTz)
|
||||
|
@ -107,11 +107,11 @@ export function jobServiceRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/jobs/jobs',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { createFullJobsList } = jobServiceProvider(callWithRequest);
|
||||
const { jobIds } = request.payload;
|
||||
return createFullJobsList(jobIds)
|
||||
|
@ -122,11 +122,11 @@ export function jobServiceRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/jobs/groups',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { getAllGroups } = jobServiceProvider(callWithRequest);
|
||||
return getAllGroups()
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -136,11 +136,11 @@ export function jobServiceRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/jobs/update_groups',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { updateGroups } = jobServiceProvider(callWithRequest);
|
||||
const { jobs } = request.payload;
|
||||
return updateGroups(jobs)
|
||||
|
@ -151,11 +151,11 @@ export function jobServiceRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/jobs/deleting_jobs_tasks',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { deletingJobTasks } = jobServiceProvider(callWithRequest);
|
||||
return deletingJobTasks()
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -165,11 +165,11 @@ export function jobServiceRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/jobs/jobs_exist',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const { jobsExist } = jobServiceProvider(callWithRequest);
|
||||
const { jobIds } = request.payload;
|
||||
return jobsExist(jobIds)
|
||||
|
|
|
@ -14,7 +14,7 @@ import { estimateBucketSpanFactory } from '../models/bucket_span_estimator';
|
|||
import { calculateModelMemoryLimitProvider } from '../models/calculate_model_memory_limit';
|
||||
import { validateJob, validateCardinality } from '../models/job_validation';
|
||||
|
||||
export function jobValidationRoutes(server, commonRouteConfig) {
|
||||
export function jobValidationRoutes({ commonRouteConfig, config, elasticsearchPlugin, route, xpackMainPlugin }) {
|
||||
|
||||
function calculateModelMemoryLimit(callWithRequest, payload) {
|
||||
|
||||
|
@ -38,13 +38,13 @@ export function jobValidationRoutes(server, commonRouteConfig) {
|
|||
latestMs);
|
||||
}
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/validate/estimate_bucket_span',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
try {
|
||||
return estimateBucketSpanFactory(callWithRequest, server)(request.payload)
|
||||
return estimateBucketSpanFactory(callWithRequest, elasticsearchPlugin, xpackMainPlugin)(request.payload)
|
||||
// this catch gets triggered when the estimation code runs without error
|
||||
// but isn't able to come up with a bucket span estimation.
|
||||
// this doesn't return a HTTP error but an object with an error message
|
||||
|
@ -65,11 +65,11 @@ export function jobValidationRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/validate/calculate_model_memory_limit',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return calculateModelMemoryLimit(callWithRequest, request.payload)
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -78,11 +78,11 @@ export function jobValidationRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/validate/cardinality',
|
||||
handler(request, reply) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return validateCardinality(callWithRequest, request.payload)
|
||||
.then(reply)
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -92,14 +92,14 @@ export function jobValidationRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/validate/job',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
// pkg.branch corresponds to the version used in documentation links.
|
||||
const version = server.config().get('pkg.branch');
|
||||
return validateJob(callWithRequest, request.payload, version, server)
|
||||
const version = config.get('pkg.branch');
|
||||
return validateJob(callWithRequest, request.payload, version, elasticsearchPlugin, xpackMainPlugin)
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
config: {
|
||||
|
|
|
@ -57,13 +57,13 @@ function dataRecognizerJobsExist(callWithRequest, moduleId) {
|
|||
return dr.dataRecognizerJobsExist(moduleId);
|
||||
}
|
||||
|
||||
export function dataRecognizer(server, commonRouteConfig) {
|
||||
export function dataRecognizer({ commonRouteConfig, elasticsearchPlugin, route }) {
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/modules/recognize/{indexPatternTitle}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const indexPatternTitle = request.params.indexPatternTitle;
|
||||
return recognize(callWithRequest, indexPatternTitle)
|
||||
.catch(resp => wrapError(resp));
|
||||
|
@ -73,11 +73,11 @@ export function dataRecognizer(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/modules/get_module/{moduleId?}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
let moduleId = request.params.moduleId;
|
||||
if (moduleId === '') {
|
||||
// if the endpoint is called with a trailing /
|
||||
|
@ -92,11 +92,11 @@ export function dataRecognizer(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/modules/setup/{moduleId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const moduleId = request.params.moduleId;
|
||||
|
||||
const {
|
||||
|
@ -130,11 +130,11 @@ export function dataRecognizer(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/modules/jobs_exist/{moduleId}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const moduleId = request.params.moduleId;
|
||||
return dataRecognizerJobsExist(callWithRequest, moduleId)
|
||||
.catch(resp => wrapError(resp));
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
import { callWithRequestFactory } from '../client/call_with_request_factory';
|
||||
import { wrapError } from '../client/errors';
|
||||
|
||||
export function notificationRoutes(server, commonRouteConfig) {
|
||||
export function notificationRoutes({ commonRouteConfig, elasticsearchPlugin, route }) {
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/notification_settings',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
const params = {
|
||||
includeDefaults: true,
|
||||
filterPath: '**.xpack.notification'
|
||||
|
|
|
@ -58,13 +58,13 @@ function getCategoryExamples(callWithRequest, payload) {
|
|||
maxExamples);
|
||||
}
|
||||
|
||||
export function resultsServiceRoutes(server, commonRouteConfig) {
|
||||
export function resultsServiceRoutes({ commonRouteConfig, elasticsearchPlugin, route }) {
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/results/anomalies_table_data',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return getAnomaliesTableData(callWithRequest, request.payload)
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -73,11 +73,11 @@ export function resultsServiceRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/results/category_definition',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return getCategoryDefinition(callWithRequest, request.payload)
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -86,11 +86,11 @@ export function resultsServiceRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/results/category_examples',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return getCategoryExamples(callWithRequest, request.payload)
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
|
|
@ -15,8 +15,8 @@ import Boom from 'boom';
|
|||
|
||||
import { isSecurityDisabled } from '../lib/security_utils';
|
||||
|
||||
export function systemRoutes(server, commonRouteConfig) {
|
||||
const callWithInternalUser = callWithInternalUserFactory(server);
|
||||
export function systemRoutes({ commonRouteConfig, elasticsearchPlugin, route, xpackMainPlugin }) {
|
||||
const callWithInternalUser = callWithInternalUserFactory(elasticsearchPlugin);
|
||||
|
||||
function getNodeCount() {
|
||||
const filterPath = 'nodes.*.attributes';
|
||||
|
@ -37,11 +37,11 @@ export function systemRoutes(server, commonRouteConfig) {
|
|||
});
|
||||
}
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/_has_privileges',
|
||||
async handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
try {
|
||||
let upgradeInProgress = false;
|
||||
try {
|
||||
|
@ -60,7 +60,7 @@ export function systemRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
}
|
||||
|
||||
if (isSecurityDisabled(server)) {
|
||||
if (isSecurityDisabled(xpackMainPlugin)) {
|
||||
// if xpack.security.enabled has been explicitly set to false
|
||||
// return that security is disabled and don't call the privilegeCheck endpoint
|
||||
return {
|
||||
|
@ -82,15 +82,15 @@ export function systemRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/ml_node_count',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return new Promise((resolve, reject) => {
|
||||
// check for basic license first for consistency with other
|
||||
// security disabled checks
|
||||
if (isSecurityDisabled(server)) {
|
||||
if (isSecurityDisabled(xpackMainPlugin)) {
|
||||
getNodeCount()
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
|
@ -133,11 +133,11 @@ export function systemRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'GET',
|
||||
path: '/api/ml/info',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return callWithRequest('ml.info')
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
@ -146,11 +146,11 @@ export function systemRoutes(server, commonRouteConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
route({
|
||||
method: 'POST',
|
||||
path: '/api/ml/es_search',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
|
||||
return callWithRequest('search', request.payload)
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue