]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory.component.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / inventory / inventory.component.ts
1 import { Component, Input, NgZone, OnChanges, OnDestroy, OnInit } from '@angular/core';
2
3 import { Subscription, timer as observableTimer } from 'rxjs';
4
5 import { HostService } from '~/app/shared/api/host.service';
6 import { OrchestratorService } from '~/app/shared/api/orchestrator.service';
7 import { Icons } from '~/app/shared/enum/icons.enum';
8 import { OrchestratorStatus } from '~/app/shared/models/orchestrator.interface';
9 import { InventoryDevice } from './inventory-devices/inventory-device.model';
10
11 @Component({
12 selector: 'cd-inventory',
13 templateUrl: './inventory.component.html',
14 styleUrls: ['./inventory.component.scss']
15 })
16 export class InventoryComponent implements OnChanges, OnInit, OnDestroy {
17 // Display inventory page only for this hostname, ignore to display all.
18 @Input() hostname?: string;
19
20 private reloadSubscriber: Subscription;
21 private reloadInterval = 5000;
22 private firstRefresh = true;
23
24 icons = Icons;
25
26 orchStatus: OrchestratorStatus;
27 showDocPanel = false;
28
29 devices: Array<InventoryDevice> = [];
30
31 constructor(
32 private orchService: OrchestratorService,
33 private hostService: HostService,
34 private ngZone: NgZone
35 ) {}
36
37 ngOnInit() {
38 this.orchService.status().subscribe((status) => {
39 this.orchStatus = status;
40 this.showDocPanel = !status.available;
41 if (status.available) {
42 // Create a timer to get cached inventory from the orchestrator.
43 // Do not ask the orchestrator frequently to refresh its cache data because it's expensive.
44 this.ngZone.runOutsideAngular(() => {
45 // start after first pass because the embedded table calls refresh at init.
46 this.reloadSubscriber = observableTimer(
47 this.reloadInterval,
48 this.reloadInterval
49 ).subscribe(() => {
50 this.ngZone.run(() => {
51 this.getInventory(false);
52 });
53 });
54 });
55 }
56 });
57 }
58
59 ngOnDestroy() {
60 this.reloadSubscriber?.unsubscribe();
61 }
62
63 ngOnChanges() {
64 if (this.orchStatus?.available) {
65 this.devices = [];
66 this.getInventory(false);
67 }
68 }
69
70 getInventory(refresh: boolean) {
71 if (this.hostname === '') {
72 return;
73 }
74 this.hostService.inventoryDeviceList(this.hostname, refresh).subscribe(
75 (devices: InventoryDevice[]) => {
76 this.devices = devices;
77 },
78 () => {
79 this.devices = [];
80 }
81 );
82 }
83
84 refresh() {
85 // Make the first reload (triggered by table) use cached data, and
86 // the remaining reloads (triggered by users) ask orchestrator to refresh inventory.
87 this.getInventory(!this.firstRefresh);
88 this.firstRefresh = false;
89 }
90 }