-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mgr/dashboard: CRUSH map viewer/architectural viewer
Signed-off-by: guodan1 <guodan1@lenovo.com>
- Loading branch information
guodan1
committed
Nov 3, 2018
1 parent
a71a984
commit f3157db
Showing
10 changed files
with
214 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div class="row"> | ||
<div class="col-sm-12 col-lg-12"> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<h3 class="panel-title"> | ||
<span i18n>{{ panelTitle }}</span> | ||
</h3> | ||
</div> | ||
<div class="panel-body"> | ||
<div class="col-sm-6 col-lg-6"> | ||
<tree [tree]="tree" | ||
(nodeSelected)="onNodeSelected($event)"></tree> | ||
</div> | ||
<div class="col-sm-6 col-lg-6 metadata"> | ||
<cd-table-key-value *ngIf="metadata" | ||
[data]="metadata"> | ||
</cd-table-key-value> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
3 changes: 3 additions & 0 deletions
3
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
::ng-deep tree-internal .tree li { | ||
cursor: pointer; | ||
} |
88 changes: 88 additions & 0 deletions
88
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { DebugElement } from '@angular/core'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { of } from 'rxjs'; | ||
|
||
import { TreeModule } from 'ng2-tree'; | ||
import { TabsModule } from 'ngx-bootstrap/tabs'; | ||
|
||
import { configureTestBed } from '../../../../testing/unit-test-helper'; | ||
import { DashboardService } from '../../../shared/api/dashboard.service'; | ||
import { SharedModule } from '../../../shared/shared.module'; | ||
import { CrushmapComponent } from './crushmap.component'; | ||
|
||
describe('CrushmapComponent', () => { | ||
let component: CrushmapComponent; | ||
let fixture: ComponentFixture<CrushmapComponent>; | ||
let debugElement: DebugElement; | ||
configureTestBed({ | ||
imports: [HttpClientTestingModule, TreeModule, TabsModule.forRoot(), SharedModule], | ||
declarations: [CrushmapComponent], | ||
providers: [DashboardService] | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(CrushmapComponent); | ||
component = fixture.componentInstance; | ||
debugElement = fixture.debugElement; | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should display right title', () => { | ||
fixture.detectChanges(); | ||
const span = debugElement.nativeElement.querySelector('span'); | ||
expect(span.textContent).toContain(component.panelTitle); | ||
}); | ||
|
||
describe('test tree', () => { | ||
let dashboardService: DashboardService; | ||
const prepareGetHealth = (nodes: object[]) => { | ||
spyOn(dashboardService, 'getHealth').and.returnValue( | ||
of({ osd_map: { tree: { nodes: nodes } } }) | ||
); | ||
fixture.detectChanges(); | ||
}; | ||
|
||
beforeEach(() => { | ||
dashboardService = debugElement.injector.get(DashboardService); | ||
}); | ||
|
||
it('should display "No nodes!" if ceph tree nodes is empty array', () => { | ||
prepareGetHealth([]); | ||
expect(dashboardService.getHealth).toHaveBeenCalled(); | ||
expect(component.tree.value).toEqual('No nodes!'); | ||
}); | ||
|
||
describe('ceph tree nodes has data', () => { | ||
beforeEach(() => { | ||
prepareGetHealth([ | ||
{ children: [-2], type: 'root', name: 'default', id: -1 }, | ||
{ children: [1, 0, 2], type: 'host', name: 'my-host', id: -2 }, | ||
{ status: 'up', type: 'osd', name: 'osd.0', id: 0 }, | ||
{ status: 'down', type: 'osd', name: 'osd.1', id: 1 }, | ||
{ status: 'up', type: 'osd', name: 'osd.2', id: 2 } | ||
]); | ||
}); | ||
|
||
it('has a tree structure deriving from root', () => { | ||
expect(component.tree.value).toBe('default (root)'); | ||
}); | ||
|
||
it('has a tree structure with one host child with 3 children', () => { | ||
expect(component.tree.children.length).toBe(1); | ||
expect(component.tree.children[0].value).toBe('my-host (host)'); | ||
expect(component.tree.children[0].children.length).toBe(3); | ||
}); | ||
|
||
it('has sorted all host children by id', () => { | ||
expect(component.tree.children[0].children[0].value).toBe('osd.0 (osd)--up'); | ||
expect(component.tree.children[0].children[1].value).toBe('osd.1 (osd)--down'); | ||
expect(component.tree.children[0].children[2].value).toBe('osd.2 (osd)--up'); | ||
}); | ||
}); | ||
}); | ||
}); |
72 changes: 72 additions & 0 deletions
72
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
import { NodeEvent, TreeModel } from 'ng2-tree'; | ||
|
||
import { DashboardService } from '../../../shared/api/dashboard.service'; | ||
|
||
@Component({ | ||
selector: 'cd-crushmap', | ||
templateUrl: './crushmap.component.html', | ||
styleUrls: ['./crushmap.component.scss'] | ||
}) | ||
export class CrushmapComponent implements OnInit { | ||
panelTitle: string; | ||
tree: TreeModel; | ||
metadata: any; | ||
metadataKeyMap: { [key: number]: number } = {}; | ||
|
||
constructor(private dashboardService: DashboardService) { | ||
this.panelTitle = 'CRUSH map viewer'; | ||
} | ||
|
||
ngOnInit() { | ||
this.dashboardService.getHealth().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 }; | ||
|
||
let value: string = node.name + ' (' + node.type + ')'; | ||
if (node.status) { | ||
value += '--' + node.status; | ||
} | ||
|
||
const children: any[] = []; | ||
if (node.children) { | ||
node.children.sort().forEach((childId) => { | ||
children.push(treeNodeMap[childId]); | ||
}); | ||
|
||
return { value, settings, id, children }; | ||
} | ||
|
||
return { value, settings, id }; | ||
} | ||
|
||
onNodeSelected(e: NodeEvent) { | ||
this.metadata = this.metadataKeyMap[e.node.id]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters