Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | 6x 6x 6x 6x 6x 6x 5x 4x 6x 4x 4x 1x 3x 3x 15x 3x 6x 15x 15x 15x 15x 15x 15x 6x 12x 6x 9x 6x 6x | import { Component, OnInit } from '@angular/core';
import { NodeEvent, TreeModel } from 'ng2-tree';
import { HealthService } from '../../../shared/api/health.service';
@Component({
selector: 'cd-crushmap',
template: require('./crushmap.component.html'),
styles: []
})
export class CrushmapComponent implements OnInit {
tree: TreeModel;
metadata: any;
metadataTitle: string;
metadataKeyMap: { [key: number]: number } = {};
constructor(private healthService: HealthService) {}
ngOnInit() {
this.healthService.getFullHealth().subscribe((data: any) => {
this.tree = this._abstractTreeData(data);
});
}
_abstractTreeData(data: any): TreeModel {
const nodes = data.osd_map.tree.nodes || [];
const treeNodeMap: { [key: number]: any } = {};
if (0 === nodes.length) {
return {
value: 'No nodes!',
settings: { static: true }
};
}
const rootNodeId = nodes[0].id || null;
nodes.reverse().forEach((node) => {
treeNodeMap[node.id] = this.generateTreeLeaf(node, treeNodeMap);
});
return treeNodeMap[rootNodeId];
}
private generateTreeLeaf(node: any, treeNodeMap) {
const id = node.id;
this.metadataKeyMap[id] = node;
const settings = { static: true };
const value: string = node.name + ' (' + node.type + ')';
const status: string = node.status;
const children: any[] = [];
if (node.children) {
node.children.sort().forEach((childId) => {
children.push(treeNodeMap[childId]);
});
return { value, status, settings, id, children };
}
return { value, status, settings, id };
}
onNodeSelected(e: NodeEvent) {
const { name, type, status, ...remain } = this.metadataKeyMap[e.node.id];
this.metadata = remain;
this.metadataTitle = name + ' (' + type + ')';
}
}
|