1 import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
8 } from '@circlon/angular-tree-component';
9 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
10 import _ from 'lodash';
12 import { forkJoin, Subscription, timer as observableTimer } from 'rxjs';
13 import { RgwRealmService } from '~/app/shared/api/rgw-realm.service';
14 import { RgwZoneService } from '~/app/shared/api/rgw-zone.service';
15 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
16 import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
17 import { ActionLabelsI18n, TimerServiceInterval } from '~/app/shared/constants/app.constants';
18 import { Icons } from '~/app/shared/enum/icons.enum';
19 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
20 import { CdTableAction } from '~/app/shared/models/cd-table-action';
21 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
22 import { Permission } from '~/app/shared/models/permissions';
23 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
24 import { ModalService } from '~/app/shared/services/modal.service';
25 import { NotificationService } from '~/app/shared/services/notification.service';
26 import { TimerService } from '~/app/shared/services/timer.service';
27 import { RgwRealm, RgwZone, RgwZonegroup } from '../models/rgw-multisite';
28 import { RgwMultisiteMigrateComponent } from '../rgw-multisite-migrate/rgw-multisite-migrate.component';
29 import { RgwMultisiteZoneDeletionFormComponent } from '../models/rgw-multisite-zone-deletion-form/rgw-multisite-zone-deletion-form.component';
30 import { RgwMultisiteZonegroupDeletionFormComponent } from '../models/rgw-multisite-zonegroup-deletion-form/rgw-multisite-zonegroup-deletion-form.component';
31 import { RgwMultisiteExportComponent } from '../rgw-multisite-export/rgw-multisite-export.component';
32 import { RgwMultisiteImportComponent } from '../rgw-multisite-import/rgw-multisite-import.component';
33 import { RgwMultisiteRealmFormComponent } from '../rgw-multisite-realm-form/rgw-multisite-realm-form.component';
34 import { RgwMultisiteZoneFormComponent } from '../rgw-multisite-zone-form/rgw-multisite-zone-form.component';
35 import { RgwMultisiteZonegroupFormComponent } from '../rgw-multisite-zonegroup-form/rgw-multisite-zonegroup-form.component';
36 import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
37 import { MgrModuleService } from '~/app/shared/api/mgr-module.service';
38 import { BlockUI, NgBlockUI } from 'ng-block-ui';
39 import { Router } from '@angular/router';
40 import { RgwMultisiteWizardComponent } from '../rgw-multisite-wizard/rgw-multisite-wizard.component';
41 import { RgwMultisiteSyncPolicyComponent } from '../rgw-multisite-sync-policy/rgw-multisite-sync-policy.component';
43 const BASE_URL = 'rgw/multisite/configuration';
46 selector: 'cd-rgw-multisite-details',
47 templateUrl: './rgw-multisite-details.component.html',
48 styleUrls: ['./rgw-multisite-details.component.scss']
50 export class RgwMultisiteDetailsComponent implements OnDestroy, OnInit {
51 private sub = new Subscription();
53 @ViewChild('tree') tree: TreeComponent;
54 @ViewChild(RgwMultisiteSyncPolicyComponent) syncPolicyComp: RgwMultisiteSyncPolicyComponent;
57 noDefaultRealm: $localize`Please create a default realm first to enable this feature`,
58 noMasterZone: $localize`Please create a master zone for each zone group to enable this feature`,
59 noRealmExists: $localize`No realm exists`,
60 disableExport: $localize`Please create master zone group and master zone for each of the realms`
67 permission: Permission;
68 selection = new CdTableSelection();
69 createTableActions: CdTableAction[];
70 migrateTableAction: CdTableAction[];
71 importAction: CdTableAction[];
72 exportAction: CdTableAction[];
73 multisiteReplicationActions: CdTableAction[];
74 loadingIndicator = true;
76 treeOptions: ITreeOptions = {
77 useVirtualScroll: true,
82 click: this.onNodeSelected.bind(this)
86 modalRef: NgbModalRef;
88 realms: RgwRealm[] = [];
89 zonegroups: RgwZonegroup[] = [];
90 zones: RgwZone[] = [];
92 metadataTitle: string;
93 bsModalRef: NgbModalRef;
94 realmIds: string[] = [];
95 zoneIds: string[] = [];
97 defaultZonegroupId = '';
99 multisiteInfo: object[] = [];
100 defaultsInfo: string[] = [];
101 showMigrateAndReplicationActions = false;
102 editTitle: string = 'Edit';
103 deleteTitle: string = 'Delete';
104 disableExport = true;
105 rgwModuleStatus: boolean;
106 restartGatewayMessage = false;
107 rgwModuleData: string | any[] = [];
111 private modalService: ModalService,
112 private timerService: TimerService,
113 private authStorageService: AuthStorageService,
114 public actionLabels: ActionLabelsI18n,
115 public timerServiceVariable: TimerServiceInterval,
116 public router: Router,
117 public rgwRealmService: RgwRealmService,
118 public rgwZonegroupService: RgwZonegroupService,
119 public rgwZoneService: RgwZoneService,
120 public rgwDaemonService: RgwDaemonService,
121 public mgrModuleService: MgrModuleService,
122 private notificationService: NotificationService
124 this.permission = this.authStorageService.getPermissions().rgw;
127 openModal(entity: any, edit = false) {
128 const entityName = edit ? entity.data.type : entity;
129 const action = edit ? 'edit' : 'create';
130 const initialState = {
131 resource: entityName,
134 defaultsInfo: this.defaultsInfo,
135 multisiteInfo: this.multisiteInfo
137 if (entityName === 'realm') {
138 this.bsModalRef = this.modalService.show(RgwMultisiteRealmFormComponent, initialState, {
141 } else if (entityName === 'zonegroup') {
142 this.bsModalRef = this.modalService.show(RgwMultisiteZonegroupFormComponent, initialState, {
146 this.bsModalRef = this.modalService.show(RgwMultisiteZoneFormComponent, initialState, {
152 openMultisiteSetupWizard() {
153 this.bsModalRef = this.modalService.show(RgwMultisiteWizardComponent, {
159 const initialState = {
160 multisiteInfo: this.multisiteInfo
162 this.bsModalRef = this.modalService.show(RgwMultisiteMigrateComponent, initialState, {
168 const initialState = {
169 multisiteInfo: this.multisiteInfo
171 this.bsModalRef = this.modalService.show(RgwMultisiteImportComponent, initialState, {
177 const initialState = {
178 defaultsInfo: this.defaultsInfo,
179 multisiteInfo: this.multisiteInfo
181 this.bsModalRef = this.modalService.show(RgwMultisiteExportComponent, initialState, {
187 this.realms.forEach((realm: any) => {
188 this.zonegroups.forEach((zonegroup) => {
189 if (realm.id === zonegroup.realm_id) {
190 if (zonegroup.is_master && zonegroup.master_zone !== '') {
191 this.disableExport = false;
196 if (!this.rgwModuleStatus) {
199 if (this.realms.length < 1) {
200 return this.messages.noRealmExists;
201 } else if (this.disableExport) {
202 return this.messages.disableExport;
209 if (!this.rgwModuleStatus) {
217 this.createTableActions = [
219 permission: 'create',
221 name: this.actionLabels.CREATE + ' Realm',
222 click: () => this.openModal('realm')
225 permission: 'create',
227 name: this.actionLabels.CREATE + ' Zone Group',
228 click: () => this.openModal('zonegroup'),
229 disable: () => this.getDisable()
232 permission: 'create',
234 name: this.actionLabels.CREATE + ' Zone',
235 click: () => this.openModal('zone')
238 this.migrateTableAction = [
240 permission: 'create',
242 name: this.actionLabels.MIGRATE,
243 click: () => this.openMigrateModal()
246 this.importAction = [
248 permission: 'create',
249 icon: Icons.download,
250 name: this.actionLabels.IMPORT,
251 click: () => this.openImportModal(),
252 disable: () => this.getDisableImport()
255 this.exportAction = [
257 permission: 'create',
259 name: this.actionLabels.EXPORT,
260 click: () => this.openExportModal(),
261 disable: () => this.getDisableExport()
264 this.multisiteReplicationActions = [
266 permission: 'create',
268 name: this.actionLabels.SETUP_MULTISITE_REPLICATION,
270 this.router.navigate([BASE_URL, { outlets: { modal: 'setup-multisite-replication' } }])
274 const observables = [
275 this.rgwRealmService.getAllRealmsInfo(),
276 this.rgwZonegroupService.getAllZonegroupsInfo(),
277 this.rgwZoneService.getAllZonesInfo()
279 this.sub = this.timerService
280 .get(() => forkJoin(observables), this.timerServiceVariable.TIMER_SERVICE_PERIOD * 2)
282 (multisiteInfo: [object, object, object]) => {
283 this.multisiteInfo = multisiteInfo;
284 this.loadingIndicator = false;
285 this.nodes = this.abstractTreeData(multisiteInfo);
289 this.mgrModuleService.list().subscribe((moduleData: any) => {
290 this.rgwModuleData = moduleData.filter((module: object) => module['name'] === 'rgw');
291 if (this.rgwModuleData.length > 0) {
292 this.rgwModuleStatus = this.rgwModuleData[0].enabled;
296 /* setConfigValues() {
297 this.rgwDaemonService
299 this.defaultsInfo['defaultRealmName'],
300 this.defaultsInfo['defaultZonegroupName'],
301 this.defaultsInfo['defaultZoneName']
303 .subscribe(() => {});
307 this.sub.unsubscribe();
310 private abstractTreeData(multisiteInfo: [object, object, object]): any[] {
311 let allNodes: object[] = [];
313 let firstChildNodes = {};
314 let allFirstChildNodes = [];
315 let secondChildNodes = {};
316 let allSecondChildNodes: {}[] = [];
317 this.realms = multisiteInfo[0]['realms'];
318 this.zonegroups = multisiteInfo[1]['zonegroups'];
319 this.zones = multisiteInfo[2]['zones'];
320 this.defaultRealmId = multisiteInfo[0]['default_realm'];
321 this.defaultZonegroupId = multisiteInfo[1]['default_zonegroup'];
322 this.defaultZoneId = multisiteInfo[2]['default_zone'];
323 this.defaultsInfo = this.getDefaultsEntities(
325 this.defaultZonegroupId,
328 if (this.realms.length > 0) {
329 // get tree for realm -> zonegroup -> zone
330 for (const realm of this.realms) {
331 const result = this.rgwRealmService.getRealmTree(realm, this.defaultRealmId);
332 rootNodes = result['nodes'];
333 this.realmIds = this.realmIds.concat(result['realmIds']);
334 for (const zonegroup of this.zonegroups) {
335 if (zonegroup.realm_id === realm.id) {
336 firstChildNodes = this.rgwZonegroupService.getZonegroupTree(
338 this.defaultZonegroupId,
341 for (const zone of zonegroup.zones) {
342 const zoneResult = this.rgwZoneService.getZoneTree(
349 secondChildNodes = zoneResult['nodes'];
350 this.zoneIds = this.zoneIds.concat(zoneResult['zoneIds']);
351 allSecondChildNodes.push(secondChildNodes);
352 secondChildNodes = {};
354 firstChildNodes['children'] = allSecondChildNodes;
355 allSecondChildNodes = [];
356 allFirstChildNodes.push(firstChildNodes);
357 firstChildNodes = {};
360 rootNodes['children'] = allFirstChildNodes;
361 allNodes.push(rootNodes);
362 firstChildNodes = {};
363 secondChildNodes = {};
365 allFirstChildNodes = [];
366 allSecondChildNodes = [];
369 if (this.zonegroups.length > 0) {
370 // get tree for zonegroup -> zone (standalone zonegroups that don't match a realm eg(initial default))
371 for (const zonegroup of this.zonegroups) {
372 if (!this.realmIds.includes(zonegroup.realm_id)) {
373 rootNodes = this.rgwZonegroupService.getZonegroupTree(zonegroup, this.defaultZonegroupId);
374 for (const zone of zonegroup.zones) {
375 const zoneResult = this.rgwZoneService.getZoneTree(
381 firstChildNodes = zoneResult['nodes'];
382 this.zoneIds = this.zoneIds.concat(zoneResult['zoneIds']);
383 allFirstChildNodes.push(firstChildNodes);
384 firstChildNodes = {};
386 rootNodes['children'] = allFirstChildNodes;
387 allNodes.push(rootNodes);
388 firstChildNodes = {};
390 allFirstChildNodes = [];
394 if (this.zones.length > 0) {
395 // get tree for standalone zones(zones that do not belong to a zonegroup)
396 for (const zone of this.zones) {
397 if (this.zoneIds.length > 0 && !this.zoneIds.includes(zone.id)) {
398 const zoneResult = this.rgwZoneService.getZoneTree(zone, this.defaultZoneId, this.zones);
399 rootNodes = zoneResult['nodes'];
400 allNodes.push(rootNodes);
405 if (this.realms.length < 1 && this.zonegroups.length < 1 && this.zones.length < 1) {
414 this.evaluateMigrateAndReplicationActions();
415 this.rgwDaemonService.list().subscribe((data: any) => {
416 const realmName = data.map((item: { [x: string]: any }) => item['realm_name']);
418 this.defaultRealmId != '' &&
419 this.defaultZonegroupId != '' &&
420 this.defaultZoneId != '' &&
421 realmName.includes('')
423 this.restartGatewayMessage = true;
430 defaultRealmId: string,
431 defaultZonegroupId: string,
432 defaultZoneId: string
434 const defaultRealm = this.realms.find((x: { id: string }) => x.id === defaultRealmId);
435 const defaultZonegroup = this.zonegroups.find(
436 (x: { id: string }) => x.id === defaultZonegroupId
438 const defaultZone = this.zones.find((x: { id: string }) => x.id === defaultZoneId);
439 const defaultRealmName = defaultRealm !== undefined ? defaultRealm.name : null;
440 const defaultZonegroupName = defaultZonegroup !== undefined ? defaultZonegroup.name : null;
441 const defaultZoneName = defaultZone !== undefined ? defaultZone.name : null;
443 defaultRealmName: defaultRealmName,
444 defaultZonegroupName: defaultZonegroupName,
445 defaultZoneName: defaultZoneName
449 onNodeSelected(tree: TreeModel, node: TreeNode) {
450 TREE_ACTIONS.ACTIVATE(tree, node, true);
451 this.metadataTitle = node.data.name;
452 this.metadata = node.data.info;
453 node.data.show = true;
457 this.tree.treeModel.expandAll();
461 let isMasterZone = true;
462 if (this.defaultRealmId === '') {
463 return this.messages.noDefaultRealm;
465 this.zonegroups.forEach((zgp: any) => {
466 if (_.isEmpty(zgp.master_zone)) {
467 isMasterZone = false;
472 'Please create a master zone for each existing zonegroup to enable this feature';
473 return this.messages.noMasterZone;
475 this.editTitle = 'Edit';
481 evaluateMigrateAndReplicationActions() {
483 this.realms.length === 0 &&
484 this.zonegroups.length === 1 &&
485 this.zonegroups[0].name === 'default' &&
486 this.zones.length === 1 &&
487 this.zones[0].name === 'default'
489 this.showMigrateAndReplicationActions = true;
491 this.showMigrateAndReplicationActions = false;
493 return this.showMigrateAndReplicationActions;
496 isDeleteDisabled(node: TreeNode): boolean {
497 let disable: boolean = false;
498 let masterZonegroupCount: number = 0;
499 if (node.data.type === 'realm' && node.data.is_default && this.realms.length < 2) {
503 if (node.data.type === 'zonegroup') {
504 if (this.zonegroups.length < 2) {
505 this.deleteTitle = 'You can not delete the only zonegroup available';
507 } else if (node.data.is_default) {
508 this.deleteTitle = 'You can not delete the default zonegroup';
510 } else if (node.data.is_master) {
511 for (let zonegroup of this.zonegroups) {
512 if (zonegroup.is_master === true) {
513 masterZonegroupCount++;
514 if (masterZonegroupCount > 1) break;
517 if (masterZonegroupCount < 2) {
518 this.deleteTitle = 'You can not delete the only master zonegroup available';
524 if (node.data.type === 'zone') {
525 if (this.zones.length < 2) {
526 this.deleteTitle = 'You can not delete the only zone available';
528 } else if (node.data.is_default) {
529 this.deleteTitle = 'You can not delete the default zone';
531 } else if (node.data.is_master && node.data.zone_zonegroup.zones.length < 2) {
533 'You can not delete the master zone as there are no more zones in this zonegroup';
539 this.deleteTitle = 'Delete';
545 delete(node: TreeNode) {
546 if (node.data.type === 'realm') {
547 this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
548 itemDescription: $localize`${node.data.type} ${node.data.name}`,
549 itemNames: [`${node.data.name}`],
550 submitAction: () => {
551 this.rgwRealmService.delete(node.data.name).subscribe(
553 this.modalRef.close();
554 this.notificationService.show(
555 NotificationType.success,
556 $localize`Realm: '${node.data.name}' deleted successfully`
560 this.modalRef.componentInstance.stopLoadingSpinner();
565 } else if (node.data.type === 'zonegroup') {
566 this.modalRef = this.modalService.show(RgwMultisiteZonegroupDeletionFormComponent, {
569 } else if (node.data.type === 'zone') {
570 this.modalRef = this.modalService.show(RgwMultisiteZoneDeletionFormComponent, {
578 const fnWaitUntilReconnected = () => {
579 observableTimer(2000).subscribe(() => {
580 // Trigger an API request to check if the connection is
582 this.mgrModuleService.list().subscribe(
584 // Resume showing the notification toasties.
585 this.notificationService.suspendToasties(false);
586 // Unblock the whole UI.
588 // Reload the data table content.
589 this.notificationService.show(NotificationType.success, $localize`Enabled RGW Module`);
590 this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => {
591 this.router.navigate(['/rgw/multisite']);
593 // Reload the data table content.
596 fnWaitUntilReconnected();
602 if (!this.rgwModuleStatus) {
603 $obs = this.mgrModuleService.enable('rgw');
608 // Suspend showing the notification toasties.
609 this.notificationService.suspendToasties(true);
610 // Block the whole UI to prevent user interactions until
611 // the connection to the backend is reestablished
612 this.blockUI.start($localize`Reconnecting, please wait ...`);
613 fnWaitUntilReconnected();