]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.ts
import ceph nautilus 14.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / crushmap / crushmap.component.ts
1 import { Component, OnInit } from '@angular/core';
2
3 import { NodeEvent, TreeModel } from 'ng2-tree';
4
5 import { HealthService } from '../../../shared/api/health.service';
6
7 @Component({
8 selector: 'cd-crushmap',
9 templateUrl: './crushmap.component.html',
10 styleUrls: ['./crushmap.component.scss']
11 })
12 export class CrushmapComponent implements OnInit {
13 tree: TreeModel;
14 metadata: any;
15 metadataTitle: string;
16 metadataKeyMap: { [key: number]: number } = {};
17
18 constructor(private healthService: HealthService) {}
19
20 ngOnInit() {
21 this.healthService.getFullHealth().subscribe((data: any) => {
22 this.tree = this._abstractTreeData(data);
23 });
24 }
25
26 _abstractTreeData(data: any): TreeModel {
27 const nodes = data.osd_map.tree.nodes || [];
28 const treeNodeMap: { [key: number]: any } = {};
29
30 if (0 === nodes.length) {
31 return {
32 value: 'No nodes!',
33 settings: { static: true }
34 };
35 }
36
37 const roots = [];
38 nodes.reverse().forEach((node) => {
39 if (node.type === 'root') {
40 roots.push(node.id);
41 }
42 treeNodeMap[node.id] = this.generateTreeLeaf(node, treeNodeMap);
43 });
44
45 const children = roots.map((id) => {
46 return treeNodeMap[id];
47 });
48
49 return {
50 value: 'CRUSH map',
51 children: children
52 };
53 }
54
55 private generateTreeLeaf(node: any, treeNodeMap) {
56 const id = node.id;
57 this.metadataKeyMap[id] = node;
58 const settings = { static: true };
59
60 const value: string = node.name + ' (' + node.type + ')';
61 const status: string = node.status;
62
63 const children: any[] = [];
64 if (node.children) {
65 node.children.sort().forEach((childId) => {
66 children.push(treeNodeMap[childId]);
67 });
68
69 return { value, status, settings, id, children };
70 }
71
72 return { value, status, settings, id };
73 }
74
75 onNodeSelected(e: NodeEvent) {
76 const { name, type, status, ...remain } = this.metadataKeyMap[e.node.id];
77 this.metadata = remain;
78 this.metadataTitle = name + ' (' + type + ')';
79 }
80 }