1 import { Component, OnInit } from '@angular/core';
3 import { NodeEvent, TreeModel } from 'ng2-tree';
5 import { HealthService } from '../../../shared/api/health.service';
8 selector: 'cd-crushmap',
9 templateUrl: './crushmap.component.html',
10 styleUrls: ['./crushmap.component.scss']
12 export class CrushmapComponent implements OnInit {
15 metadataTitle: string;
16 metadataKeyMap: { [key: number]: number } = {};
18 constructor(private healthService: HealthService) {}
21 this.healthService.getFullHealth().subscribe((data: any) => {
22 this.tree = this._abstractTreeData(data);
26 _abstractTreeData(data: any): TreeModel {
27 const nodes = data.osd_map.tree.nodes || [];
28 const treeNodeMap: { [key: number]: any } = {};
30 if (0 === nodes.length) {
33 settings: { static: true }
38 nodes.reverse().forEach((node) => {
39 if (node.type === 'root') {
42 treeNodeMap[node.id] = this.generateTreeLeaf(node, treeNodeMap);
45 const children = roots.map((id) => {
46 return treeNodeMap[id];
55 private generateTreeLeaf(node: any, treeNodeMap) {
57 this.metadataKeyMap[id] = node;
58 const settings = { static: true };
60 const value: string = node.name + ' (' + node.type + ')';
61 const status: string = node.status;
63 const children: any[] = [];
65 node.children.sort().forEach((childId) => {
66 children.push(treeNodeMap[childId]);
69 return { value, status, settings, id, children };
72 return { value, status, settings, id };
75 onNodeSelected(e: NodeEvent) {
76 const { name, type, status, ...remain } = this.metadataKeyMap[e.node.id];
77 this.metadata = remain;
78 this.metadataTitle = name + ' (' + type + ')';