Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion kibana.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
/**
* All exports from TS source files (where the implementation is actually done in TS).
*/
export * from './target/types/type_exports';
export { Public, Server } from 'src/core';

/**
* All exports from TS ambient definitions (where types are added for JS source in a .d.ts file).
*/
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
"uiFramework:createComponent": "cd packages/kbn-ui-framework && yarn createComponent",
"uiFramework:documentComponent": "cd packages/kbn-ui-framework && yarn documentComponent",
"kbn:watch": "node scripts/kibana --dev --logging.json=false",
"build:types": "tsc --p tsconfig.types.json",
"kbn:bootstrap": "yarn build:types && node scripts/register_git_hook"
"kbn:bootstrap": "node scripts/register_git_hook"
},
"repository": {
"type": "git",
Expand Down
23 changes: 23 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.
*/

import * as Public from './public';
import * as Server from './server';

export { Public, Server };
2 changes: 2 additions & 0 deletions src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ interface Params {
* of Kibana in the UI, including the LegacyPlatform which is managed
* by the LegacyPlatformService. As we migrate more things to the new
* platform the CoreSystem will get many more Services.
*
* @internal
*/
export class CoreSystem {
private readonly fatalErrors: FatalErrorsService;
Expand Down
20 changes: 20 additions & 0 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,24 @@
* under the License.
*/

import { BasePathStart } from './base_path';
import { ChromeStart } from './chrome';
import { FatalErrorsStart } from './fatal_errors';
import { HttpStart } from './http';
import { I18nStart } from './i18n';
import { InjectedMetadataStart } from './injected_metadata';
import { NotificationsStart } from './notifications';
import { UiSettingsClient } from './ui_settings';

export { CoreSystem } from './core_system';

export interface CoreStart {
i18n: I18nStart;
injectedMetadata: InjectedMetadataStart;
fatalErrors: FatalErrorsStart;
notifications: NotificationsStart;
http: HttpStart;
basePath: BasePathStart;
uiSettings: UiSettingsClient;
chrome: ChromeStart;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export interface InjectedMetadataParams {
* and is read from the DOM in most cases.
*/
export class InjectedMetadataService {
private state = deepFreeze(this.params.injectedMetadata);
private state = deepFreeze(
this.params.injectedMetadata
) as InjectedMetadataParams['injectedMetadata'];

constructor(private readonly params: InjectedMetadataParams) {}

Expand Down
26 changes: 4 additions & 22 deletions src/core/public/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,7 @@
*/

import angular from 'angular';
import { BasePathStart } from '../base_path';
import { ChromeStart } from '../chrome';
import { FatalErrorsStart } from '../fatal_errors';
import { HttpStart } from '../http';
import { I18nStart } from '../i18n';
import { InjectedMetadataStart } from '../injected_metadata';
import { NotificationsStart } from '../notifications';
import { UiSettingsClient } from '../ui_settings';

interface Deps {
i18n: I18nStart;
injectedMetadata: InjectedMetadataStart;
fatalErrors: FatalErrorsStart;
notifications: NotificationsStart;
http: HttpStart;
basePath: BasePathStart;
uiSettings: UiSettingsClient;
chrome: ChromeStart;
}
import { CoreStart } from '../';

export interface LegacyPlatformParams {
targetDomElement: HTMLElement;
Expand All @@ -54,7 +36,7 @@ export interface LegacyPlatformParams {
export class LegacyPlatformService {
constructor(private readonly params: LegacyPlatformParams) {}

public start(deps: Deps) {
public start(core: CoreStart) {
const {
i18n,
injectedMetadata,
Expand All @@ -64,10 +46,10 @@ export class LegacyPlatformService {
basePath,
uiSettings,
chrome,
} = deps;
} = core;
// Inject parts of the new platform into parts of the legacy platform
// so that legacy APIs/modules can mimic their new platform counterparts
require('ui/new_platform').__newPlatformInit__(deps);
require('ui/new_platform').__newPlatformInit__(core);
require('ui/metadata').__newPlatformInit__(injectedMetadata.getLegacyMetadata());
require('ui/i18n').__newPlatformInit__(i18n.Context);
require('ui/notify/fatal_error').__newPlatformInit__(fatalErrors);
Expand Down
5 changes: 5 additions & 0 deletions src/core/server/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ interface BootstrapArgs {
features: KibanaFeatures;
}

/**
* @interal
*
* @param options
*/
export async function bootstrap({
configs,
cliArgs,
Expand Down
66 changes: 3 additions & 63 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,7 @@
* under the License.
*/

import { PluginsModule } from './plugins';

export { bootstrap } from './bootstrap';

import { first } from 'rxjs/operators';
import { ConfigService, Env } from './config';
import { ElasticsearchModule } from './elasticsearch';
import { HttpConfig, HttpModule, HttpServerInfo } from './http';
import { LegacyCompatModule } from './legacy';
import { Logger, LoggerFactory } from './logging';

export class Server {
private readonly elasticsearch: ElasticsearchModule;
private readonly http: HttpModule;
private readonly plugins: PluginsModule;
private readonly legacy: LegacyCompatModule;
private readonly log: Logger;

constructor(configService: ConfigService, logger: LoggerFactory, private readonly env: Env) {
this.log = logger.get('server');

this.http = new HttpModule(configService.atPath('server', HttpConfig), logger);

const core = { env, configService, logger };
this.plugins = new PluginsModule(core);
this.legacy = new LegacyCompatModule(core);
this.elasticsearch = new ElasticsearchModule(core);
}

public async start() {
this.log.debug('starting server');

// We shouldn't start http service in two cases:
// 1. If `server.autoListen` is explicitly set to `false`.
// 2. When the process is run as dev cluster master in which case cluster manager
// will fork a dedicated process where http service will be started instead.
let httpStart: HttpServerInfo | undefined;
const httpConfig = await this.http.config$.pipe(first()).toPromise();
if (!this.env.isDevClusterMaster && httpConfig.autoListen) {
httpStart = await this.http.service.start();
}

const elasticsearchServiceStart = await this.elasticsearch.service.start();

const pluginsStart = await this.plugins.service.start({
elasticsearch: elasticsearchServiceStart,
});

await this.legacy.service.start({
elasticsearch: elasticsearchServiceStart,
http: httpStart,
plugins: pluginsStart,
});
}

public async stop() {
this.log.debug('stopping server');

await this.legacy.service.stop();
await this.plugins.service.stop();
await this.elasticsearch.service.stop();
await this.http.service.stop();
}
}
export { CallAPIOptions, ClusterClient } from './elasticsearch';
export { Logger, LoggerFactory } from './logging';
export { PluginInitializerContext, PluginName, PluginStartContext } from './plugins';
2 changes: 1 addition & 1 deletion src/core/server/root/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jest.mock('../config/config_service', () => ({
}));

const mockServer = { start: jest.fn(), stop: jest.fn() };
jest.mock('../', () => ({ Server: jest.fn(() => mockServer) }));
jest.mock('../server', () => ({ Server: jest.fn(() => mockServer) }));

import { BehaviorSubject } from 'rxjs';
import { filter, first } from 'rxjs/operators';
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/root/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import { ConnectableObservable, Observable, Subscription } from 'rxjs';
import { first, map, publishReplay, switchMap, tap } from 'rxjs/operators';

import { Server } from '..';
import { Config, ConfigService, Env } from '../config';
import { Logger, LoggerFactory, LoggingConfig, LoggingService } from '../logging';
import { Server } from '../server';

/**
* Top-level entry point to kick off the app and start the Kibana server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ jest.mock('./legacy/legacy_service', () => ({
}));

import { BehaviorSubject } from 'rxjs';
import { Server } from '.';
import { Env } from './config';
import { getEnvOptions } from './config/__mocks__/env';
import { loggingServiceMock } from './logging/logging_service.mock';
import { Server } from './server';

import { getEnvOptions } from './config/__mocks__/env';
import { configServiceMock } from './config/config_service.mock';
import { loggingServiceMock } from './logging/logging_service.mock';

const configService = configServiceMock.create();
const env = new Env('.', getEnvOptions());
Expand Down
80 changes: 80 additions & 0 deletions src/core/server/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.
*/

import { first } from 'rxjs/operators';
import { ConfigService, Env } from './config';
import { ElasticsearchModule } from './elasticsearch';
import { HttpConfig, HttpModule, HttpServerInfo } from './http';
import { LegacyCompatModule } from './legacy';
import { Logger, LoggerFactory } from './logging';
import { PluginsModule } from './plugins';

export class Server {
private readonly elasticsearch: ElasticsearchModule;
private readonly http: HttpModule;
private readonly plugins: PluginsModule;
private readonly legacy: LegacyCompatModule;
private readonly log: Logger;

constructor(configService: ConfigService, logger: LoggerFactory, private readonly env: Env) {
this.log = logger.get('server');

this.http = new HttpModule(configService.atPath('server', HttpConfig), logger);

const core = { env, configService, logger };
this.plugins = new PluginsModule(core);
this.legacy = new LegacyCompatModule(core);
this.elasticsearch = new ElasticsearchModule(core);
}

public async start() {
this.log.debug('starting server');

// We shouldn't start http service in two cases:
// 1. If `server.autoListen` is explicitly set to `false`.
// 2. When the process is run as dev cluster master in which case cluster manager
// will fork a dedicated process where http service will be started instead.
let httpStart: HttpServerInfo | undefined;
const httpConfig = await this.http.config$.pipe(first()).toPromise();
if (!this.env.isDevClusterMaster && httpConfig.autoListen) {
httpStart = await this.http.service.start();
}

const elasticsearchServiceStart = await this.elasticsearch.service.start();

const pluginsStart = await this.plugins.service.start({
elasticsearch: elasticsearchServiceStart,
});

await this.legacy.service.start({
elasticsearch: elasticsearchServiceStart,
http: httpStart,
plugins: pluginsStart,
});
}

public async stop() {
this.log.debug('stopping server');

await this.legacy.service.stop();
await this.plugins.service.stop();
await this.elasticsearch.service.stop();
await this.http.service.stop();
}
}
6 changes: 0 additions & 6 deletions src/dev/build/tasks/transpile_typescript_task.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export const TranspileTypescriptTask = {
description: 'Transpiling sources with typescript compiler',

async run(config, log, build) {
// the types project is built inside the repo so x-pack can use it for it's in-repo build.
const typesProjectRepo = new Project(config.resolveFromRepo('tsconfig.types.json'));
const typesProjectBuild = new Project(build.resolvePath('tsconfig.types.json'));

// these projects are built in the build folder
const defaultProject = new Project(build.resolvePath('tsconfig.json'));
const browserProject = new Project(build.resolvePath('tsconfig.browser.json'));
Expand All @@ -52,8 +48,6 @@ export const TranspileTypescriptTask = {
}));

const projects = [
typesProjectRepo.tsConfigPath,
typesProjectBuild.tsConfigPath,
// Browser needs to be compiled before server code so that any shared code
// is compiled to the lowest common denominator (server's CommonJS format)
// which can be supported by both environments.
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/elasticsearch/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { errors } from 'elasticsearch';
import { CallAPIOptions, ClusterClient } from 'kibana';
import { CallAPIOptions, ClusterClient } from 'kibana/server';

export class Cluster {
public readonly errors = errors;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/testbed/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { map, mergeMap } from 'rxjs/operators';

import { Logger, PluginInitializerContext, PluginName, PluginStartContext } from 'kibana';
import { Logger, PluginInitializerContext, PluginName, PluginStartContext } from 'kibana/server';
import { TestBedConfig } from './config';

class Plugin {
Expand Down
Loading