All files / src/app/ceph/cluster/crushmap crushmap.component.ts

84.78% Statements 39/46
83.33% Branches 10/12
90% Functions 9/10
92.11% Lines 35/38

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 72 73 74 75 76 77 78 79 80 816x       6x             6x       4x   4x   6x 3x 2x       6x 2x 2x   2x 1x           1x 1x 8x 2x   8x     1x 2x     1x           6x 8x 8x 8x   8x 8x   8x 8x 4x 6x     4x     4x     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 roots = [];
    nodes.reverse().forEach((node) => {
      if (node.type === 'root') {
        roots.push(node.id);
      }
      treeNodeMap[node.id] = this.generateTreeLeaf(node, treeNodeMap);
    });
 
    const children = roots.map((id) => {
      return treeNodeMap[id];
    });
 
    return {
      value: 'CRUSH map',
      children: children
    };
  }
 
  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 + ')';
  }
}