Skip to content

Commit

Permalink
First attempt at server shim
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Nov 18, 2019
1 parent b0afa91 commit 4b26855
Show file tree
Hide file tree
Showing 114 changed files with 148 additions and 97 deletions.
46 changes: 0 additions & 46 deletions x-pack/legacy/plugins/watcher/plugin_definition.js

This file was deleted.

35 changes: 35 additions & 0 deletions x-pack/legacy/plugins/watcher/plugin_definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 { plugin } from './server/np_ready';
import { ServerShim } from './server/np_ready/plugin';
import { PLUGIN } from './common/constants';

export const pluginDefinition = {
id: PLUGIN.ID,
configPrefix: 'xpack.watcher',
publicDir: resolve(__dirname, 'public'),
require: ['kibana', 'elasticsearch', 'xpack_main'],
uiExports: {
styleSheetPaths: resolve(__dirname, 'public/np_ready/application/index.scss'),
managementSections: ['plugins/watcher/legacy'],
home: ['plugins/watcher/register_feature'],
},
init(server: any) {
const serverShim: ServerShim = server as any;
plugin({} as any).setup(server.newPlatform.setup.core, {
__LEGACY: {
route: server.route.bind(server),
plugins: {
elasticsearch: server.plugins.elasticsearch,
[PLUGIN.ID]: server.plugins[PLUGIN.ID],
xpack_main: server.plugins.xpack_main,
},
},
});
},
};
5 changes: 1 addition & 4 deletions x-pack/legacy/plugins/watcher/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ routes.when('/management/elasticsearch/watcher/:param1?/:param2?/:param3?/:param
if (elem) {
((unmountApp as unknown) as AppUnmount)();
}
// NOTE: We depend upon Angular's $http service because it's decorated with interceptors,
// e.g. to check license status per request.
// setHttpClient($http);

$scope.$$postDigest(() => {
elem = document.getElementById('watchReactRoot')!;
Expand All @@ -74,7 +71,7 @@ routes.when('/management/elasticsearch/watcher/:param1?/:param2?/:param3?/:param

instance.start(npStart.core, npStart.plugins);

unmountApp = mountApp();
(mountApp() as Promise<AppUnmount>).then(fn => (unmountApp = fn));

manageAngularLifecycle($scope, $route, elem);
});
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/watcher/public/np_ready/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
CoreStart,
ChromeStart,
} from 'src/core/public';
import { boot } from './application/boot';

interface LegacyPlugins {
__LEGACY: {
Expand All @@ -32,10 +31,11 @@ export class WatcherUIPlugin implements Plugin<void, void, LegacyPlugins, any> {
application.register({
id: 'watcher',
title: 'Watcher',
mount: (ctx, { element }) => {
mount: async (ctx, { element }) => {
const docLinks = this.docLinks!;
const chrome = this.chrome!;
const euiUtils = this.euiUtils!;
const { boot } = await import('./application/boot');
return boot({
...__LEGACY,
element,
Expand Down
9 changes: 9 additions & 0 deletions x-pack/legacy/plugins/watcher/server/np_ready/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 { PluginInitializerContext } from 'src/core/server';
import { WatcherServerPlugin } from './plugin';

export const plugin = (ctx: PluginInitializerContext) => new WatcherServerPlugin();
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { get } from 'lodash';
import { ES_SCROLL_SETTINGS } from '../../../common/constants';
import { ES_SCROLL_SETTINGS } from '../../../../common/constants';

export function fetchAllFromScroll(response, callWithRequest, hits = []) {
const newHits = get(response, 'hits.hits', []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import expect from '@kbn/expect';
import { licensePreRoutingFactory } from '../license_pre_routing_factory';
import { LICENSE_STATUS_VALID, LICENSE_STATUS_EXPIRED } from '../../../../../../common/constants/license_status';
import { LICENSE_STATUS_VALID, LICENSE_STATUS_EXPIRED } from '../../../../../../../common/constants/license_status';

describe('license_pre_routing_factory', () => {
describe('#reportingFeaturePreRoutingFactory', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import { once } from 'lodash';
import { wrapCustomError } from '../error_wrappers';
import { PLUGIN } from '../../../common/constants';
import { LICENSE_STATUS_VALID } from '../../../../../common/constants/license_status';
import { PLUGIN } from '../../../../common/constants';
import { LICENSE_STATUS_VALID } from '../../../../../../common/constants/license_status';

export const licensePreRoutingFactory = once((server) => {
const xpackMainPlugin = server.plugins.xpack_main;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import expect from '@kbn/expect';
import { ActionStatus } from '../action_status';
import { ACTION_STATES } from '../../../../common/constants';
import { ACTION_STATES } from '../../../../../common/constants';
import moment from 'moment';

describe('action_status', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import { get } from 'lodash';
import { badImplementation, badRequest } from 'boom';
import { getMoment } from '../../../common/lib/get_moment';
import { ACTION_STATES } from '../../../common/constants';
import { getMoment } from '../../../../common/lib/get_moment';
import { ACTION_STATES } from '../../../../common/constants';
import { i18n } from '@kbn/i18n';

export class ActionStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { merge } from 'lodash';
import { ACTION_TYPES } from '../../../common/constants';
import { ACTION_TYPES } from '../../../../common/constants';

function isEnabledByDefault(actionType) {
switch (actionType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { get, map, pick } from 'lodash';
import { badRequest } from 'boom';
import { Action } from '../../../common/models/action';
import { Action } from '../../../../common/models/action';
import { WatchStatus } from '../watch_status';
import { i18n } from '@kbn/i18n';
import { WatchErrors } from '../watch_errors';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import { isEmpty, cloneDeep, has, merge } from 'lodash';
import { BaseWatch } from './base_watch';
import { WATCH_TYPES } from '../../../common/constants';
import { serializeJsonWatch } from '../../../common/lib/serialization';
import { WATCH_TYPES } from '../../../../common/constants';
import { serializeJsonWatch } from '../../../../common/lib/serialization';

export class JsonWatch extends BaseWatch {
// This constructor should not be used directly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { get, contains, values } from 'lodash';
import { WATCH_TYPES } from '../../../../../common/constants';
import { WATCH_TYPES } from '../../../../../../common/constants';

export function getWatchType(watchJson) {
const type = get(watchJson, 'metadata.xpack.type');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { merge } from 'lodash';
import { badRequest } from 'boom';
import { BaseWatch } from './base_watch';
import { WATCH_TYPES } from '../../../common/constants';
import { WATCH_TYPES } from '../../../../common/constants';
import { i18n } from '@kbn/i18n';

export class MonitoringWatch extends BaseWatch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import expect from '@kbn/expect';
import { AGG_TYPES } from '../../../../../common/constants';
import { AGG_TYPES } from '../../../../../../common/constants';
import { formatVisualizeData } from '../format_visualize_data';

describe('watch', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import { cloneDeep } from 'lodash';
import { buildInput } from '../../../../common/lib/serialization';
import { AGG_TYPES } from '../../../../common/constants';
import { buildInput } from '../../../../../common/lib/serialization';
import { AGG_TYPES } from '../../../../../common/constants';

/*
input.search.request.body.query.bool.filter.range
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AGG_TYPES } from '../../../../common/constants';
import { AGG_TYPES } from '../../../../../common/constants';

export function formatVisualizeData({ aggType, termField }, results) {
if (aggType === AGG_TYPES.COUNT && !Boolean(termField)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import { merge } from 'lodash';
import { BaseWatch } from '../base_watch';
import { WATCH_TYPES, COMPARATORS, SORT_ORDERS } from '../../../../common/constants';
import { serializeThresholdWatch } from '../../../../common/lib/serialization';
import { WATCH_TYPES, COMPARATORS, SORT_ORDERS } from '../../../../../common/constants';
import { serializeThresholdWatch } from '../../../../../common/lib/serialization';

import { buildVisualizeQuery } from './build_visualize_query';
import { formatVisualizeData } from './format_visualize_data';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { COMPARATORS, SORT_ORDERS } from '../../../../common/constants';
import { COMPARATORS, SORT_ORDERS } from '../../../../../common/constants';
import { WatchErrors } from '../../watch_errors';
import { ThresholdWatch } from './threshold_watch';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { set } from 'lodash';
import { badRequest } from 'boom';
import { WATCH_TYPES } from '../../../common/constants';
import { WATCH_TYPES } from '../../../../common/constants';
import { JsonWatch } from './json_watch';
import { MonitoringWatch } from './monitoring_watch';
import { ThresholdWatch } from './threshold_watch';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { WATCH_TYPES } from '../../../common/constants';
import { WATCH_TYPES } from '../../../../common/constants';
import { Watch } from './watch';
import { JsonWatch } from './json_watch';
import { MonitoringWatch } from './monitoring_watch';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { badRequest } from 'boom';
import { getMoment } from '../../../common/lib/get_moment';
import { getMoment } from '../../../../common/lib/get_moment';
import { get, cloneDeep } from 'lodash';
import { WatchStatus } from '../watch_status';
import { i18n } from '@kbn/i18n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import expect from '@kbn/expect';
import { WatchStatus } from '../watch_status';
import { ACTION_STATES, WATCH_STATES, WATCH_STATE_COMMENTS } from '../../../../common/constants';
import { ACTION_STATES, WATCH_STATES, WATCH_STATE_COMMENTS } from '../../../../../common/constants';
import moment from 'moment';

describe('watch_status', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import { get, map, forEach, max } from 'lodash';
import { badRequest } from 'boom';
import { getMoment } from '../../../common/lib/get_moment';
import { getMoment } from '../../../../common/lib/get_moment';
import { ActionStatus } from '../action_status';
import { ACTION_STATES, WATCH_STATES, WATCH_STATE_COMMENTS } from '../../../common/constants';
import { ACTION_STATES, WATCH_STATES, WATCH_STATE_COMMENTS } from '../../../../common/constants';
import { i18n } from '@kbn/i18n';

function getActionStatusTotals(watchStatus) {
Expand Down
56 changes: 56 additions & 0 deletions x-pack/legacy/plugins/watcher/server/np_ready/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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, CoreSetup, ElasticsearchServiceSetup } from 'src/core/server';
import { i18n } from '@kbn/i18n';
import { XPackMainPlugin } from '../../../xpack_main/xpack_main';
import { PLUGIN } from '../../common/constants';
// @ts-ignore
import { registerFieldsRoutes } from './routes/api/fields';
// @ts-ignore
import { registerSettingsRoutes } from './routes/api/settings';
// @ts-ignore
import { registerHistoryRoutes } from './routes/api/history';
// @ts-ignore
import { registerIndicesRoutes } from './routes/api/indices';
// @ts-ignore
import { registerLicenseRoutes } from './routes/api/license';
// @ts-ignore
import { registerWatchesRoutes } from './routes/api/watches';
// @ts-ignore
import { registerWatchRoutes } from './routes/api/watch';
import { registerLicenseChecker } from '../../../../server/lib/register_license_checker';

export interface ServerShim {
route: any;
plugins: {
xpack_main: XPackMainPlugin;
watcher: any;
elasticsearch: ElasticsearchServiceSetup;
};
}

export class WatcherServerPlugin implements Plugin<void, void, any, any> {
async setup(core: CoreSetup, { __LEGACY: serverShim }: { __LEGACY: ServerShim }) {
// Register license checker
registerLicenseChecker(
serverShim as any,
PLUGIN.ID,
PLUGIN.getI18nName(i18n),
PLUGIN.MINIMUM_LICENSE_REQUIRED
);

registerFieldsRoutes(serverShim);
registerHistoryRoutes(serverShim);
registerIndicesRoutes(serverShim);
registerLicenseRoutes(serverShim);
registerSettingsRoutes(serverShim);
registerWatchesRoutes(serverShim);
registerWatchRoutes(serverShim);
}
start() {}
stop() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { callWithRequestFactory } from '../../../lib/call_with_request_factory';
import { WatchHistoryItem } from '../../../models/watch_history_item';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { wrapEsError, wrapUnknownError, wrapCustomError } from '../../../lib/error_wrappers';
import { INDEX_NAMES } from '../../../../common/constants';
import { licensePreRoutingFactory } from'../../../lib/license_pre_routing_factory';
import { INDEX_NAMES } from '../../../../../common/constants';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';

function fetchHistoryItem(callWithRequest, watchHistoryItemId) {
return callWithRequest('search', {
Expand Down
Loading

0 comments on commit 4b26855

Please sign in to comment.