12 } from '@angular/core';
14 import _ from 'lodash';
15 import { Observable, Subscription } from 'rxjs';
16 import { take } from 'rxjs/operators';
18 import { CephServiceService } from '~/app/shared/api/ceph-service.service';
19 import { DaemonService } from '~/app/shared/api/daemon.service';
20 import { HostService } from '~/app/shared/api/host.service';
21 import { OrchestratorService } from '~/app/shared/api/orchestrator.service';
22 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
23 import { TableComponent } from '~/app/shared/datatable/table/table.component';
24 import { Icons } from '~/app/shared/enum/icons.enum';
25 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
26 import { CdTableAction } from '~/app/shared/models/cd-table-action';
27 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
28 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
29 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
30 import { Daemon } from '~/app/shared/models/daemon.interface';
31 import { Permissions } from '~/app/shared/models/permissions';
32 import { CephServiceSpec } from '~/app/shared/models/service.interface';
33 import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
34 import { RelativeDatePipe } from '~/app/shared/pipes/relative-date.pipe';
35 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
36 import { NotificationService } from '~/app/shared/services/notification.service';
39 selector: 'cd-service-daemon-list',
40 templateUrl: './service-daemon-list.component.html',
41 styleUrls: ['./service-daemon-list.component.scss']
43 export class ServiceDaemonListComponent implements OnInit, OnChanges, AfterViewInit, OnDestroy {
44 @ViewChild('statusTpl', { static: true })
45 statusTpl: TemplateRef<any>;
47 @ViewChild('listTpl', { static: true })
48 listTpl: TemplateRef<any>;
50 @ViewChild('cpuTpl', { static: true })
51 cpuTpl: TemplateRef<any>;
53 @ViewChildren('daemonsTable')
54 daemonsTableTpls: QueryList<TemplateRef<TableComponent>>;
63 hiddenColumns: string[] = [];
70 warningThreshold = 0.8;
76 daemons: Daemon[] = [];
77 services: Array<CephServiceSpec> = [];
78 columns: CdTableColumn[] = [];
79 serviceColumns: CdTableColumn[] = [];
80 tableActions: CdTableAction[];
81 selection = new CdTableSelection();
82 permissions: Permissions;
84 hasOrchestrator = false;
87 private daemonsTable: TableComponent;
88 private daemonsTableTplsSub: Subscription;
89 private serviceSub: Subscription;
92 private hostService: HostService,
93 private cephServiceService: CephServiceService,
94 private orchService: OrchestratorService,
95 private relativeDatePipe: RelativeDatePipe,
96 private dimlessBinary: DimlessBinaryPipe,
97 public actionLabels: ActionLabelsI18n,
98 private authStorageService: AuthStorageService,
99 private daemonService: DaemonService,
100 private notificationService: NotificationService
104 this.permissions = this.authStorageService.getPermissions();
105 this.tableActions = [
107 permission: 'update',
109 click: () => this.daemonAction('start'),
110 name: this.actionLabels.START,
111 disable: () => this.actionDisabled('start')
114 permission: 'update',
116 click: () => this.daemonAction('stop'),
117 name: this.actionLabels.STOP,
118 disable: () => this.actionDisabled('stop')
121 permission: 'update',
123 click: () => this.daemonAction('restart'),
124 name: this.actionLabels.RESTART,
125 disable: () => this.actionDisabled('restart')
128 permission: 'update',
130 click: () => this.daemonAction('redeploy'),
131 name: this.actionLabels.REDEPLOY,
132 disable: () => this.actionDisabled('redeploy')
137 name: $localize`Hostname`,
143 name: $localize`Daemon name`,
149 name: $localize`Version`,
155 name: $localize`Status`,
159 cellTemplate: this.statusTpl
162 name: $localize`Last Refreshed`,
163 prop: 'last_refresh',
164 pipe: this.relativeDatePipe,
168 name: $localize`CPU Usage`,
169 prop: 'cpu_percentage',
171 cellTemplate: this.cpuTpl
174 name: $localize`Memory Usage`,
175 prop: 'memory_usage',
177 pipe: this.dimlessBinary,
178 cellClass: 'text-right'
181 name: $localize`Daemon Events`,
184 cellTemplate: this.listTpl
188 this.serviceColumns = [
190 name: $localize`Service Name`,
191 prop: 'service_name',
196 name: $localize`Service Type`,
197 prop: 'service_type',
202 name: $localize`Service Events`,
205 cellTemplate: this.listTpl
209 this.orchService.status().subscribe((data: { available: boolean }) => {
210 this.hasOrchestrator = data.available;
211 this.showDocPanel = !data.available;
214 this.columns = this.columns.filter((col: any) => {
215 return !this.hiddenColumns.includes(col.prop);
220 if (!_.isUndefined(this.daemonsTable)) {
221 this.daemonsTable.reloadData();
226 this.daemonsTableTplsSub = this.daemonsTableTpls.changes.subscribe(
227 (tableRefs: QueryList<TableComponent>) => {
228 this.daemonsTable = tableRefs.first;
234 if (this.daemonsTableTplsSub) {
235 this.daemonsTableTplsSub.unsubscribe();
237 if (this.serviceSub) {
238 this.serviceSub.unsubscribe();
242 getStatusClass(row: Daemon): string {
245 '-1': 'badge-danger',
246 '0': 'badge-warning',
254 getDaemons(context: CdTableFetchDataContext) {
255 let observable: Observable<Daemon[]>;
257 observable = this.hostService.getDaemons(this.hostname);
258 } else if (this.serviceName) {
259 observable = this.cephServiceService.getDaemons(this.serviceName);
264 observable.subscribe(
265 (daemons: Daemon[]) => {
266 this.daemons = daemons;
267 this.sortDaemonEvents();
277 this.daemons.forEach((daemon: any) => {
278 daemon.events?.sort((event1: any, event2: any) => {
279 return new Date(event2.created).getTime() - new Date(event1.created).getTime();
283 getServices(context: CdTableFetchDataContext) {
284 this.serviceSub = this.cephServiceService.list(this.serviceName).subscribe(
285 (services: CephServiceSpec[]) => {
286 this.services = services;
295 trackByFn(_index: any, item: any) {
299 updateSelection(selection: CdTableSelection) {
300 this.selection = selection;
303 daemonAction(actionType: string) {
305 .action(this.selection.first()?.daemon_name, actionType)
309 this.notificationService.show(
310 NotificationType.success,
311 `Daemon ${actionType} scheduled`,
316 this.notificationService.show(
317 NotificationType.error,
318 'Daemon action failed',
325 actionDisabled(actionType: string) {
326 if (this.selection?.hasSelection) {
327 const daemon = this.selection.selected[0];
328 if (daemon.daemon_type === 'mon' || daemon.daemon_type === 'mgr') {
329 return true; // don't allow actions on mon and mgr, dashboard requires them.
331 switch (actionType) {
333 if (daemon.status_desc === 'running') {
338 if (daemon.status_desc === 'stopped') {
345 return true; // if no selection then disable everything