-
Notifications
You must be signed in to change notification settings - Fork 8.1k
/
plugin.ts
118 lines (99 loc) · 3.99 KB
/
plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { i18n } from '@kbn/i18n';
import { get } from 'lodash';
import { firstValueFrom } from 'rxjs';
import { CoreSetup, Plugin, PluginInitializerContext } from '@kbn/core/public';
import { PLUGIN, MANAGEMENT_ID } from '../common/constants';
import { init as initUiMetric } from './app/services/track_ui_metric';
import { init as initNotification } from './app/services/notifications';
import { PluginDependencies, ClientConfigType } from './types';
// @ts-ignore;
import { setHttpClient } from './app/services/api';
export class CrossClusterReplicationPlugin implements Plugin {
constructor(private readonly initializerContext: PluginInitializerContext) {}
public setup(coreSetup: CoreSetup, plugins: PluginDependencies) {
const { licensing, remoteClusters, usageCollection, management, indexManagement } = plugins;
const esSection = management.sections.section.data;
const {
http,
notifications: { toasts },
fatalErrors,
getStartServices,
} = coreSetup;
// Initialize services even if the app isn't mounted, because they're used by index management extensions.
setHttpClient(http);
initUiMetric(usageCollection);
initNotification(toasts, fatalErrors);
const ccrApp = esSection.registerApp({
id: MANAGEMENT_ID,
title: PLUGIN.TITLE,
order: 6,
mount: async ({ element, setBreadcrumbs, history }) => {
const { mountApp } = await import('./app');
const [coreStart] = await getStartServices();
const {
chrome: { docTitle },
docLinks,
application: { getUrlForApp },
executionContext,
} = coreStart;
docTitle.change(PLUGIN.TITLE);
const unmountAppCallback = await mountApp({
startServices: coreStart,
element,
setBreadcrumbs,
docLinks,
history,
getUrlForApp,
executionContext,
});
return () => {
docTitle.reset();
unmountAppCallback();
};
},
});
// NOTE: We enable the plugin by default instead of disabling it by default because this
// creates a race condition that causes functional tests to fail on CI (see #66781).
Promise.all([firstValueFrom(licensing.license$), getStartServices()]).then(
([license, startServices]) => {
const licenseStatus = license.check(PLUGIN.ID, PLUGIN.minimumLicenseType);
const isLicenseOk = licenseStatus.state === 'valid';
const config = this.initializerContext.config.get<ClientConfigType>();
const capabilities = startServices[0].application.capabilities;
// remoteClusters.isUiEnabled is driven by the xpack.remote_clusters.ui.enabled setting.
// The CCR UI depends upon the Remote Clusters UI (e.g. by cross-linking to it), so if
// the Remote Clusters UI is disabled we can't show the CCR UI.
const isCcrUiEnabled =
capabilities.management.data?.[MANAGEMENT_ID] &&
config.ui.enabled &&
remoteClusters.isUiEnabled;
if (isLicenseOk && isCcrUiEnabled) {
if (indexManagement) {
const propertyPath = 'isFollowerIndex';
const followerBadgeExtension = {
matchIndex: (index: any) => {
return get(index, propertyPath);
},
label: i18n.translate('xpack.crossClusterReplication.indexMgmtBadge.followerLabel', {
defaultMessage: 'Follower',
}),
color: 'default',
filterExpression: 'isFollowerIndex:true',
};
indexManagement.extensionsService.addBadge(followerBadgeExtension);
}
} else {
ccrApp.disable();
}
}
);
}
public start() {}
public stop() {}
}