-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathplugin.ts
408 lines (378 loc) · 16.5 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { i18n } from "@osd/i18n";
import { IndexManagementPluginStart, IndexManagementPluginSetup } from ".";
import {
AppCategory,
AppMountParameters,
AppUpdater,
CoreSetup,
CoreStart,
DEFAULT_APP_CATEGORIES,
DEFAULT_NAV_GROUPS,
Plugin,
PluginInitializerContext,
WorkspaceAvailability,
} from "../../../src/core/public";
import { actionRepoSingleton } from "./pages/VisualCreatePolicy/utils/helpers";
import { ROUTES } from "./utils/constants";
import { JobHandlerRegister } from "./JobHandler";
import { ManagementOverViewPluginSetup } from "../../../src/plugins/management_overview/public";
import { DataSourceManagementPluginSetup } from "../../../src/plugins/data_source_management/public";
import { dataSourceObservable } from "./pages/Main/Main";
import { BehaviorSubject } from "rxjs";
import { NavigationPublicPluginStart } from "../../../src/plugins/navigation/public";
import { setApplication, setNavigationUI, setUISettings } from "./services/Services";
interface IndexManagementSetupDeps {
managementOverview?: ManagementOverViewPluginSetup;
dataSourceManagement?: DataSourceManagementPluginSetup;
}
const ISM_CATEGORIES: Record<string, AppCategory> = Object.freeze({
automation_policies: {
id: "automation_policies",
label: "Automation policies",
order: 2000,
},
templates: {
id: "templates",
label: "Templates",
order: 3000,
},
index_backup_and_recovery: {
id: "index_backup_and_recovery",
label: "Index backup and recovery",
order: 4000,
},
});
const ISM_FEATURE_DESCRIPTION: Record<string, string> = Object.freeze({
index_management: i18n.translate("index-management-dashboards-plugin.indexManagement.description", {
defaultMessage: "Manage your indexes with state polices, templates and aliases. You can also roll up or transform your indexes.",
}),
snapshot_management: i18n.translate("index-management-dashboards-plugin.snapshotManagement.description", {
defaultMessage: "Back up and restore your cluster's indexes and state. Setup a policy to automate snapshot creation and deletion.",
}),
indexes: i18n.translate("index-management-dashboards-plugin.indexes.description", {
defaultMessage: "Configure and manage indexes.",
}),
policy_managed_indexes: i18n.translate("index-management-dashboards-plugin.policyManagedIndexes.description", {
defaultMessage: "View indexes managed by Index State Management (ISM) policies.",
}),
data_streams: i18n.translate("index-management-dashboards-plugin.dataStreams.description", {
defaultMessage: "Simplify time-series data management.",
}),
aliases: i18n.translate("index-management-dashboards-plugin.aliases.description", {
defaultMessage: "Organize multiple indexes under virtual index names.",
}),
index_state_management_policies: i18n.translate("index-management-dashboards-plugin.indexStateManagementPolicies.description", {
defaultMessage: "Automate periodic administrative tasks.",
}),
index_templates: i18n.translate("index-management-dashboards-plugin.indexTemplates.description", {
defaultMessage: "Create predefined mappings and settings for new indexes.",
}),
notification_settings: i18n.translate("index-management-dashboards-plugin.notificationSettings.description", {
defaultMessage: "Set default notifications on index operation statuses.",
}),
rollup_jobs: i18n.translate("index-management-dashboards-plugin.rollupJobs.description", {
defaultMessage: "Reduce data granularity by rolling up old data into summarized indexes.",
}),
transform_jobs: i18n.translate("index-management-dashboards-plugin.transformJobs.description", {
defaultMessage: "Create summarized views of your data organized by specific fields.",
}),
index_snapshots: i18n.translate("index-management-dashboards-plugin.indexSnapshots.description", {
defaultMessage: "Back up your indexes.",
}),
snapshot_policies: i18n.translate("index-management-dashboards-plugin.snapshotPolicies.description", {
defaultMessage: "Set up automatic data snapshots.",
}),
snapshot_repositories: i18n.translate("index-management-dashboards-plugin.snapshotRepositories.description", {
defaultMessage: "Configure remote storage for snapshots.",
}),
component_templates: i18n.translate("index-management-dashboards-plugin.componentTemplates.description", {
defaultMessage: "Define components for your index templates.",
}),
});
export interface ISMPluginStartDeps {
navigation: NavigationPublicPluginStart;
}
export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup, IndexManagementPluginStart, IndexManagementSetupDeps> {
constructor(private readonly initializerContext: PluginInitializerContext) {
// can retrieve config from initializerContext
}
private updateDefaultRouteOfManagementApplications: AppUpdater = () => {
const hash = `#/?dataSourceId=${dataSourceObservable.value?.id || ""}`;
return {
defaultPath: hash,
};
};
private appStateUpdater = new BehaviorSubject<AppUpdater>(this.updateDefaultRouteOfManagementApplications);
public setup(core: CoreSetup, { managementOverview, dataSourceManagement }: IndexManagementSetupDeps): IndexManagementPluginSetup {
JobHandlerRegister(core);
const mountWrapper = async (params: AppMountParameters, redirect: string) => {
const { renderApp } = await import("./index_management_app");
const [coreStart, depsStart] = await core.getStartServices();
return renderApp(coreStart, depsStart, params, redirect, dataSourceManagement);
};
if (managementOverview) {
managementOverview.register({
id: "opensearch_index_management_dashboards",
title: "Index Management",
order: 9010,
description: i18n.translate("indexManagement.description", {
defaultMessage: "Manage your indexes with state polices, templates and aliases. You can also roll up or transform your indexes.",
}),
});
managementOverview.register({
id: "opensearch_snapshot_management_dashboards",
title: "Snapshot Management",
order: 9020,
description: i18n.translate("snapshotManagement.description", {
defaultMessage:
"Back up and restore your cluster's indexes and state. Setup a policy to automate snapshot creation and deletion.",
}),
});
}
const imApplicationID = "opensearch_index_management_dashboards";
const smApplicationID = "opensearch_snapshot_management_dashboards";
core.application.register({
id: imApplicationID,
title: "Index Management",
order: 9010,
category: DEFAULT_APP_CATEGORIES.management,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.index_management,
mount: async (params: AppMountParameters) => {
const { renderApp } = await import("./index_management_app");
const [coreStart, depsStart] = await core.getStartServices();
return renderApp(coreStart, depsStart, params, ROUTES.INDEX_POLICIES, dataSourceManagement);
},
});
core.application.register({
id: smApplicationID,
title: "Snapshot Management",
order: 9020,
category: DEFAULT_APP_CATEGORIES.management,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.snapshot_management,
mount: async (params: AppMountParameters) => {
const { renderApp } = await import("./index_management_app");
const [coreStart, depsStart] = await core.getStartServices();
return renderApp(coreStart, depsStart, params, ROUTES.SNAPSHOT_POLICIES, dataSourceManagement);
},
});
// In-app navigation registration
if (core.chrome.navGroup.getNavGroupEnabled()) {
// indices route
core.application.register({
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.INDICES)}`,
title: "Indexes",
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.indexes,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.INDICES);
},
});
// policy managed index route
core.application.register({
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.MANAGED_INDICES)}`,
title: "Policy-managed indexes",
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.policy_managed_indexes,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.MANAGED_INDICES);
},
});
// data streams route
core.application.register({
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.DATA_STREAMS)}`,
title: "Data streams",
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.data_streams,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.DATA_STREAMS);
},
});
// index alias route
core.application.register({
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.ALIASES)}`,
title: "Index aliases",
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.aliases,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.ALIASES);
},
});
// index templates route
core.application.register({
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.TEMPLATES)}`,
title: "Index templates",
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.index_templates,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.TEMPLATES);
},
});
// component templates route
core.application.register({
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.COMPOSABLE_TEMPLATES)}`,
title: "Component templates",
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.component_templates,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.COMPOSABLE_TEMPLATES);
},
});
// notification settings route
core.application.register({
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.NOTIFICATIONS)}`,
title: "Index operation notifications",
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.notification_settings,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.NOTIFICATIONS);
},
});
// rollup jobs route
core.application.register({
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.ROLLUPS)}`,
title: "Rollup jobs",
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.rollup_jobs,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.ROLLUPS);
},
});
// transform jobs route
core.application.register({
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.TRANSFORMS)}`,
title: "Transform jobs",
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.transform_jobs,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.TRANSFORMS);
},
});
// index snapshots route
core.application.register({
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.SNAPSHOTS)}`,
title: "Index snapshots",
category: ISM_CATEGORIES.index_backup_and_recovery,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.index_snapshots,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.SNAPSHOTS);
},
});
// snapshot repositories route
core.application.register({
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.REPOSITORIES)}`,
title: "Snapshot repositories",
category: ISM_CATEGORIES.index_backup_and_recovery,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.snapshot_repositories,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.REPOSITORIES);
},
});
}
dataSourceObservable.subscribe((dataSourceOption) => {
if (dataSourceOption) {
this.appStateUpdater.next(this.updateDefaultRouteOfManagementApplications);
}
});
core.chrome.navGroup.addNavLinksToGroup(DEFAULT_NAV_GROUPS.dataAdministration, [
{
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.INDICES)}`,
category: DEFAULT_APP_CATEGORIES.manageData,
order: 200,
},
{
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.MANAGED_INDICES)}`,
category: ISM_CATEGORIES.automation_policies,
order: 100,
},
{
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.DATA_STREAMS)}`,
category: DEFAULT_APP_CATEGORIES.manageData,
order: 400,
},
{
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.ALIASES)}`,
category: DEFAULT_APP_CATEGORIES.manageData,
order: 300,
},
{
id: imApplicationID,
category: ISM_CATEGORIES.automation_policies,
title: "Index State Management policies",
order: 200,
},
{
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.TEMPLATES)}`,
category: ISM_CATEGORIES.templates,
order: 100,
},
{
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.NOTIFICATIONS)}`,
category: DEFAULT_APP_CATEGORIES.manageData,
order: 500,
},
{
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.ROLLUPS)}`,
category: ISM_CATEGORIES.automation_policies,
order: 300,
},
{
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.TRANSFORMS)}`,
category: ISM_CATEGORIES.automation_policies,
order: 400,
},
{
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.SNAPSHOTS)}`,
category: ISM_CATEGORIES.index_backup_and_recovery,
order: 100,
},
{
id: smApplicationID,
category: ISM_CATEGORIES.index_backup_and_recovery,
title: "Snapshot policies",
order: 200,
},
{
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.REPOSITORIES)}`,
category: ISM_CATEGORIES.index_backup_and_recovery,
order: 300,
},
{
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.COMPOSABLE_TEMPLATES)}`,
category: ISM_CATEGORIES.templates,
order: 200,
},
]);
return {
registerAction: (actionType, uiActionCtor, defaultAction) => {
actionRepoSingleton.registerAction(actionType, uiActionCtor, defaultAction);
},
};
}
public start(core: CoreStart, { navigation }: ISMPluginStartDeps): IndexManagementPluginStart {
Object.freeze(actionRepoSingleton.repository);
// After this point, calling registerAction will throw error because "Object is not extensible"
setNavigationUI(navigation.ui);
setApplication(core.application);
setUISettings(core.uiSettings);
return {};
}
}