diff --git a/x-pack/plugins/ml/public/application/management/index.ts b/x-pack/plugins/ml/public/application/management/index.ts index 897731304ee7a..61b497391249e 100644 --- a/x-pack/plugins/ml/public/application/management/index.ts +++ b/x-pack/plugins/ml/public/application/management/index.ts @@ -11,37 +11,28 @@ */ import { i18n } from '@kbn/i18n'; -import { take } from 'rxjs/operators'; import { CoreSetup } from 'kibana/public'; -import { MlStartDependencies, MlSetupDependencies } from '../../plugin'; +import { ManagementSetup } from 'src/plugins/management/public'; +import { MlStartDependencies } from '../../plugin'; import { ManagementAppMountParams } from '../../../../../../src/plugins/management/public'; -import { PLUGIN_ID } from '../../../common/constants/app'; -import { MINIMUM_FULL_LICENSE } from '../../../common/license'; export function initManagementSection( - pluginsSetup: MlSetupDependencies, + management: ManagementSetup | undefined, core: CoreSetup ) { - const licensing = pluginsSetup.licensing.license$.pipe(take(1)); - licensing.subscribe((license) => { - const management = pluginsSetup.management; - if ( - management !== undefined && - license.check(PLUGIN_ID, MINIMUM_FULL_LICENSE).state === 'valid' - ) { - management.sections.section.insightsAndAlerting.registerApp({ - id: 'jobsListLink', - title: i18n.translate('xpack.ml.management.jobsListTitle', { - defaultMessage: 'Machine Learning Jobs', - }), - order: 2, - async mount(params: ManagementAppMountParams) { - const { mountApp } = await import('./jobs_list'); - return mountApp(core, params); - }, - }); - } - }); + if (management !== undefined) { + management.sections.section.insightsAndAlerting.registerApp({ + id: 'jobsListLink', + title: i18n.translate('xpack.ml.management.jobsListTitle', { + defaultMessage: 'Machine Learning Jobs', + }), + order: 2, + async mount(params: ManagementAppMountParams) { + const { mountApp } = await import('./jobs_list'); + return mountApp(core, params); + }, + }); + } } diff --git a/x-pack/plugins/ml/public/plugin.ts b/x-pack/plugins/ml/public/plugin.ts index 931af6a7eb6d2..1d41023448956 100644 --- a/x-pack/plugins/ml/public/plugin.ts +++ b/x-pack/plugins/ml/public/plugin.ts @@ -33,7 +33,8 @@ import { UiActionsSetup, UiActionsStart } from '../../../../src/plugins/ui_actio import { registerMlUiActions } from './ui_actions'; import { KibanaLegacyStart } from '../../../../src/plugins/kibana_legacy/public'; import { MlUrlGenerator, MlUrlGeneratorState, ML_APP_URL_GENERATOR } from './url_generator'; -import { isMlEnabled } from '../common/license'; +import { isMlEnabled, isFullLicense } from '../common/license'; +import { MINIMUM_FULL_LICENSE } from '../../../common/license'; export interface MlStartDependencies { data: DataPublicPluginStart; @@ -66,69 +67,68 @@ export class MlPlugin implements Plugin { constructor(private initializerContext: PluginInitializerContext) {} async setup(core: MlCoreSetup, pluginsSetup: MlSetupDependencies) { - // const license = pluginsSetup.licensing.license$.pipe(take(1)); - const license = await pluginsSetup.licensing.license$.pipe(take(1)).toPromise(); - // licensing.subscribe((license) => { - // console.dir(license.getFeature('ml')); - // console.dir(license.getFeature('graph')); - if (isMlEnabled(license) === false) { - return {}; - } - const baseUrl = core.http.basePath.prepend('/app/ml'); + const licensing = pluginsSetup.licensing.license$.pipe(take(1)); + licensing.subscribe((license) => { + if (isMlEnabled(license) === false) { + return; + } - pluginsSetup.share.urlGenerators.registerUrlGenerator( - new MlUrlGenerator({ - appBasePath: baseUrl, - useHash: core.uiSettings.get('state:storeInSessionStorage'), - }) - ); + const baseUrl = core.http.basePath.prepend('/app/ml'); - core.application.register({ - id: PLUGIN_ID, - title: i18n.translate('xpack.ml.plugin.title', { - defaultMessage: 'Machine Learning', - }), - order: 5000, - euiIconType: PLUGIN_ICON, - appRoute: '/app/ml', - category: DEFAULT_APP_CATEGORIES.kibana, - mount: async (params: AppMountParameters) => { - const [coreStart, pluginsStart] = await core.getStartServices(); - const kibanaVersion = this.initializerContext.env.packageInfo.version; - const { renderApp } = await import('./application/app'); - return renderApp( - coreStart, - { - data: pluginsStart.data, - share: pluginsStart.share, - kibanaLegacy: pluginsStart.kibanaLegacy, - security: pluginsSetup.security, - licensing: pluginsSetup.licensing, - management: pluginsSetup.management, - usageCollection: pluginsSetup.usageCollection, - licenseManagement: pluginsSetup.licenseManagement, - home: pluginsSetup.home, - embeddable: pluginsSetup.embeddable, - uiActions: pluginsStart.uiActions, - kibanaVersion, - }, - { - element: params.element, - appBasePath: params.appBasePath, - onAppLeave: params.onAppLeave, - history: params.history, - } - ); - }, - }); + pluginsSetup.share.urlGenerators.registerUrlGenerator( + new MlUrlGenerator({ + appBasePath: baseUrl, + useHash: core.uiSettings.get('state:storeInSessionStorage'), + }) + ); - registerFeature(pluginsSetup.home); + core.application.register({ + id: PLUGIN_ID, + title: i18n.translate('xpack.ml.plugin.title', { + defaultMessage: 'Machine Learning', + }), + order: 5000, + euiIconType: PLUGIN_ICON, + appRoute: '/app/ml', + category: DEFAULT_APP_CATEGORIES.kibana, + mount: async (params: AppMountParameters) => { + const [coreStart, pluginsStart] = await core.getStartServices(); + const kibanaVersion = this.initializerContext.env.packageInfo.version; + const { renderApp } = await import('./application/app'); + return renderApp( + coreStart, + { + data: pluginsStart.data, + share: pluginsStart.share, + kibanaLegacy: pluginsStart.kibanaLegacy, + security: pluginsSetup.security, + licensing: pluginsSetup.licensing, + management: pluginsSetup.management, + usageCollection: pluginsSetup.usageCollection, + licenseManagement: pluginsSetup.licenseManagement, + home: pluginsSetup.home, + embeddable: pluginsSetup.embeddable, + uiActions: pluginsStart.uiActions, + kibanaVersion, + }, + { + element: params.element, + appBasePath: params.appBasePath, + onAppLeave: params.onAppLeave, + history: params.history, + } + ); + }, + }); - initManagementSection(pluginsSetup, core); - registerEmbeddables(pluginsSetup.embeddable, core); - registerMlUiActions(pluginsSetup.uiActions, core); - // }); + registerFeature(pluginsSetup.home); + if (isFullLicense(license)) { + initManagementSection(pluginsSetup.management, core); + } + registerEmbeddables(pluginsSetup.embeddable, core); + registerMlUiActions(pluginsSetup.uiActions, core); + }); return {}; } diff --git a/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts b/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts index cf1c5b110f398..0eeb7a8851345 100644 --- a/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts +++ b/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts @@ -31,8 +31,6 @@ function getSwitcher(license$: Observable, logger: Logger): Capabiliti try { const license = await license$.pipe(take(1)).toPromise(); const mlCaps = capabilities.ml as MlCapabilities; - // console.dir(license.getFeature('ml')); - // console.dir(license.getFeature('graph')); if (isMlEnabled(license) === false) { disableAllCapabilities(mlCaps); return capabilities;