From 949aa77ca34a6d88ab0d4f95af7aeccc3509c327 Mon Sep 17 00:00:00 2001 From: Melissa Alvarez Date: Tue, 18 Feb 2020 14:54:33 -0500 Subject: [PATCH] migrates notification server routes to NP --- .../plugins/ml/server/new_platform/plugin.ts | 1 - .../plugins/ml/server/routes/apidoc.json | 4 +- .../ml/server/routes/notification_settings.js | 26 ----------- .../ml/server/routes/notification_settings.ts | 43 +++++++++++++++++++ 4 files changed, 46 insertions(+), 28 deletions(-) delete mode 100644 x-pack/legacy/plugins/ml/server/routes/notification_settings.js create mode 100644 x-pack/legacy/plugins/ml/server/routes/notification_settings.ts diff --git a/x-pack/legacy/plugins/ml/server/new_platform/plugin.ts b/x-pack/legacy/plugins/ml/server/new_platform/plugin.ts index 60ede82d0de85..e006ad3d3718f 100644 --- a/x-pack/legacy/plugins/ml/server/new_platform/plugin.ts +++ b/x-pack/legacy/plugins/ml/server/new_platform/plugin.ts @@ -33,7 +33,6 @@ import { dataFeedRoutes } from '../routes/datafeeds'; import { indicesRoutes } from '../routes/indices'; import { jobValidationRoutes } from '../routes/job_validation'; 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'; diff --git a/x-pack/legacy/plugins/ml/server/routes/apidoc.json b/x-pack/legacy/plugins/ml/server/routes/apidoc.json index 4682371c16424..89751abdbe20d 100644 --- a/x-pack/legacy/plugins/ml/server/routes/apidoc.json +++ b/x-pack/legacy/plugins/ml/server/routes/apidoc.json @@ -92,6 +92,8 @@ "EstimateBucketSpan", "CalculateModelMemoryLimit", "ValidateCardinality", - "ValidateJob" + "ValidateJob", + "NotificationSettings", + "GetNotificationSettings" ] } diff --git a/x-pack/legacy/plugins/ml/server/routes/notification_settings.js b/x-pack/legacy/plugins/ml/server/routes/notification_settings.js deleted file mode 100644 index 3290b5a821902..0000000000000 --- a/x-pack/legacy/plugins/ml/server/routes/notification_settings.js +++ /dev/null @@ -1,26 +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 { callWithRequestFactory } from '../client/call_with_request_factory'; -import { wrapError } from '../client/errors'; - -export function notificationRoutes({ commonRouteConfig, elasticsearchPlugin, route }) { - route({ - method: 'GET', - path: '/api/ml/notification_settings', - handler(request) { - const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request); - const params = { - includeDefaults: true, - filterPath: '**.xpack.notification', - }; - return callWithRequest('cluster.getSettings', params).catch(resp => wrapError(resp)); - }, - config: { - ...commonRouteConfig, - }, - }); -} diff --git a/x-pack/legacy/plugins/ml/server/routes/notification_settings.ts b/x-pack/legacy/plugins/ml/server/routes/notification_settings.ts new file mode 100644 index 0000000000000..c65627543b21d --- /dev/null +++ b/x-pack/legacy/plugins/ml/server/routes/notification_settings.ts @@ -0,0 +1,43 @@ +/* + * 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 { licensePreRoutingFactory } from '../new_platform/licence_check_pre_routing_factory'; +import { wrapError } from '../client/error_wrapper'; +import { RouteInitialization } from '../new_platform/plugin'; + +/** + * Routes for notification settings + */ +export function notificationRoutes({ xpackMainPlugin, router }: RouteInitialization) { + /** + * @apiGroup NotificationSettings + * + * @api {get} /api/ml/notification_settings Get notification settings + * @apiName GetNotificationSettings + * @apiDescription Returns cluster notification settings + */ + router.get( + { + path: '/api/ml/notification_settings', + validate: false, + }, + licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => { + try { + const params = { + includeDefaults: true, + filterPath: '**.xpack.notification', + }; + const resp = await context.ml!.mlClient.callAsCurrentUser('cluster.getSettings', params); + + return response.ok({ + body: resp, + }); + } catch (e) { + return response.customError(wrapError(e)); + } + }) + ); +}