Skip to content

Commit

Permalink
[Reporting] New Platform Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Jan 31, 2020
1 parent 31fae25 commit 74bb4d0
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 128 deletions.
1 change: 1 addition & 0 deletions src/plugins/kibana_utils/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@

export * from './defer';
export * from './of';
export { createGetterSetter, Get, Set } from './create_getter_setter';
export { distinctUntilChangedWithInitialValue } from './distinct_until_changed_with_initial_value';
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { createGetterSetter, Get, Set } from './create_getter_setter';
import { createGetterSetter, Get, Set } from '../../common';
import { CoreStart } from '../../../../core/public';
import { KUSavedObjectClient, createSavedObjectsClient } from './saved_objects_client';

Expand Down
1 change: 0 additions & 1 deletion src/plugins/kibana_utils/public/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
* under the License.
*/

export * from './create_getter_setter';
export * from './create_kibana_utils_core';
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { CoreStart } from '../../../../core/public';
import { Get } from './create_getter_setter';
import { Get } from '../../common';

type CoreSavedObjectClient = CoreStart['savedObjects']['client'];

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/kibana_utils/public/core/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { createGetterSetter } from './create_getter_setter';
import { createGetterSetter } from '../../common';
import { CoreStart } from '../../../../core/public';

export const [getCoreStart, setCoreStart] = createGetterSetter<CoreStart>('CoreStart');
2 changes: 1 addition & 1 deletion src/plugins/kibana_utils/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

export { defer, Defer, of } from '../common';
export { defer, Defer, of, createGetterSetter, Get, Set } from '../common';
export * from './core';
export * from './errors';
export * from './field_mapping';
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/kibana_utils/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { Get, Set, createGetterSetter } from '../common';
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { createGetterSetter } from '../../../../../../src/plugins/kibana_utils/public/core';
import { createGetterSetter } from '../../../../../../src/plugins/kibana_utils/public';
import { ExpressionsStart } from './types';

export const [getExpressions, setExpressions] = createGetterSetter<ExpressionsStart>('Expressions');
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { CancellationToken } from '../../../common/cancellation_token';
import { fieldFormats } from '../../../../../../../src/plugins/data/server';
import { LevelLogger } from '../../../server/lib/level_logger';
import { executeJobFactory } from './execute_job';
import { setFieldFormats } from '../../../server/services';

const delay = ms => new Promise(resolve => setTimeout(() => resolve(), ms));

Expand Down Expand Up @@ -67,8 +68,7 @@ describe('CSV Execute Job', function() {
uiSettingsGetStub.withArgs('csv:separator').returns(',');
uiSettingsGetStub.withArgs('csv:quoteValues').returns(true);

mockServer = {
expose: function() {},
setFieldFormats({
fieldFormatServiceFactory: function() {
const uiConfigMock = {};
uiConfigMock['format:defaultTypeMap'] = {
Expand All @@ -81,6 +81,10 @@ describe('CSV Execute Job', function() {

return fieldFormatsRegistry;
},
});

mockServer = {
expose: function() {},
plugins: {
elasticsearch: {
getCluster: function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ESQueueWorkerExecuteFn, ExecuteJobFactory, Logger, ServerFacade } from
import { JobDocPayloadDiscoverCsv } from '../types';
import { fieldFormatMapFactory } from './lib/field_format_map';
import { createGenerateCsv } from './lib/generate_csv';
import { getFieldFormats } from '../../../server/services';

export const executeJobFactory: ExecuteJobFactory<ESQueueWorkerExecuteFn<
JobDocPayloadDiscoverCsv
Expand Down Expand Up @@ -87,7 +88,7 @@ export const executeJobFactory: ExecuteJobFactory<ESQueueWorkerExecuteFn<

const [formatsMap, uiSettings] = await Promise.all([
(async () => {
const fieldFormats = await server.fieldFormatServiceFactory(uiConfig);
const fieldFormats = await getFieldFormats().fieldFormatServiceFactory(uiConfig);
return fieldFormatMapFactory(indexPatternSavedObject, fieldFormats);
})(),
(async () => {
Expand Down
44 changes: 2 additions & 42 deletions x-pack/legacy/plugins/reporting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,16 @@

import { i18n } from '@kbn/i18n';
import { Legacy } from 'kibana';
import { IUiSettingsClient } from 'kibana/server';
import { resolve } from 'path';
import { PluginStart as DataPluginStart } from '../../../../src/plugins/data/server';
import { PluginSetupContract as SecurityPluginSetup } from '../../../plugins/security/server';
import { PLUGIN_ID, UI_SETTINGS_CUSTOM_PDF_LOGO } from './common/constants';
import { config as reportingConfig } from './config';
import {
LegacySetup,
ReportingPlugin,
reportingPluginFactory,
ReportingSetupDeps,
} from './server/plugin';
import { legacyInit } from './server/legacy';
import { ReportingConfigOptions, ReportingPluginSpecOptions } from './types.d';

const kbToBase64Length = (kb: number) => {
return Math.floor((kb * 1024 * 8) / 6);
};

interface ReportingDeps {
data: DataPluginStart;
}

export const reporting = (kibana: any) => {
return new kibana.Plugin({
id: PLUGIN_ID,
Expand Down Expand Up @@ -73,35 +61,7 @@ export const reporting = (kibana: any) => {
},

async init(server: Legacy.Server) {
const coreSetup = server.newPlatform.setup.core;
const pluginsSetup: ReportingSetupDeps = {
security: server.newPlatform.setup.plugins.security as SecurityPluginSetup,
usageCollection: server.newPlatform.setup.plugins.usageCollection,
};

const fieldFormatServiceFactory = async (uiSettings: IUiSettingsClient) => {
const [, plugins] = await coreSetup.getStartServices();
const { fieldFormats } = (plugins as ReportingDeps).data;

return fieldFormats.fieldFormatServiceFactory(uiSettings);
};

const __LEGACY: LegacySetup = {
config: server.config,
info: server.info,
route: server.route.bind(server),
plugins: {
elasticsearch: server.plugins.elasticsearch,
xpack_main: server.plugins.xpack_main,
},
savedObjects: server.savedObjects,
fieldFormatServiceFactory,
uiSettingsServiceFactory: server.uiSettingsServiceFactory,
};

const initializerContext = server.newPlatform.coreContext;
const plugin: ReportingPlugin = reportingPluginFactory(initializerContext, __LEGACY, this);
await plugin.setup(coreSetup, pluginsSetup);
return legacyInit(server);
},

deprecations({ unused }: any) {
Expand Down
12 changes: 12 additions & 0 deletions x-pack/legacy/plugins/reporting/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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 { ReportingPlugin as Plugin } from './plugin';

export const plugin = (context: PluginInitializerContext) => {
return new Plugin(context);
};
41 changes: 41 additions & 0 deletions x-pack/legacy/plugins/reporting/server/legacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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 { Legacy } from 'kibana';
import { PluginInitializerContext } from 'src/core/server';
import { plugin } from './index';
import { LegacySetup, ReportingSetupDeps, ReportingStartDeps } from './plugin';
import { PluginSetupContract as SecurityPluginSetup } from '../../../../plugins/security/server';
import { PluginStart as DataPluginStart } from '../../../../../src/plugins/data/server';

const buildLegacyDependencies = (server: Legacy.Server): LegacySetup => ({
config: server.config,
info: server.info,
route: server.route.bind(server),
plugins: {
elasticsearch: server.plugins.elasticsearch,
xpack_main: server.plugins.xpack_main,
},
savedObjects: server.savedObjects,
uiSettingsServiceFactory: server.uiSettingsServiceFactory,
});

export const legacyInit = async (server: Legacy.Server) => {
const coreSetup = server.newPlatform.setup.core;
const pluginInstance = plugin(server.newPlatform.coreContext as PluginInitializerContext);

await pluginInstance.setup(coreSetup, {
security: server.newPlatform.setup.plugins.security as SecurityPluginSetup,
usageCollection: server.newPlatform.setup.plugins.usageCollection,
__LEGACY: buildLegacyDependencies(server),
} as ReportingSetupDeps);

// Schedule to call the "start" hook only after start dependencies are ready
coreSetup.getStartServices().then(([core, plugins]) =>
pluginInstance.start(core, {
data: (plugins as any).data as DataPluginStart,
} as ReportingStartDeps)
);
};
Loading

0 comments on commit 74bb4d0

Please sign in to comment.