From a055f96325cbbb6f5b0fec7b0909275836c6cbab Mon Sep 17 00:00:00 2001 From: Tiago Melo Date: Thu, 9 May 2019 14:39:48 +0000 Subject: [PATCH] mgr/dashboard: Add multi root support in CRUSH map Fixes: http://tracker.ceph.com/issues/39647 Signed-off-by: Tiago Melo --- .../cluster/crushmap/crushmap.component.html | 1 + .../crushmap/crushmap.component.spec.ts | 97 +++++++++++++++---- .../cluster/crushmap/crushmap.component.ts | 14 ++- 3 files changed, 93 insertions(+), 19 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.html index a9394aeed978d..5642543073906 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.html @@ -9,6 +9,7 @@
{ { 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 } + { status: 'up', type: 'osd', name: 'osd.2', id: 2 }, + { children: [-4], type: 'root', name: 'default-2', id: -3 }, + { children: [4], type: 'host', name: 'my-host-2', id: -4 }, + { status: 'up', type: 'osd', name: 'osd.0-2', id: 4 } ]); }); - it('should have tree structure derived from a root', () => { - expect(component.tree.value).toBe('default (root)'); - }); - - it('should have one host child with 3 osd 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('should have 3 osds in orderd', () => { - expect(component.tree.children[0].children[0].value).toBe('osd.0 (osd)'); - expect(component.tree.children[0].children[1].value).toBe('osd.1 (osd)'); - expect(component.tree.children[0].children[2].value).toBe('osd.2 (osd)'); + it('should have two root nodes', () => { + expect(component.tree.children).toEqual([ + { + children: [ + { + children: [ + { + id: 4, + settings: { + static: true + }, + status: 'up', + value: 'osd.0-2 (osd)' + } + ], + id: -4, + settings: { + static: true + }, + status: undefined, + value: 'my-host-2 (host)' + } + ], + id: -3, + settings: { + static: true + }, + status: undefined, + value: 'default-2 (root)' + }, + { + children: [ + { + children: [ + { + id: 0, + settings: { + static: true + }, + status: 'up', + value: 'osd.0 (osd)' + }, + { + id: 1, + settings: { + static: true + }, + status: 'down', + value: 'osd.1 (osd)' + }, + { + id: 2, + settings: { + static: true + }, + status: 'up', + value: 'osd.2 (osd)' + } + ], + id: -2, + settings: { + static: true + }, + status: undefined, + value: 'my-host (host)' + } + ], + id: -1, + settings: { + static: true + }, + status: undefined, + value: 'default (root)' + } + ]); }); }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.ts index d7a6f5e4fbd5f..37b56b52de5ba 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.ts @@ -34,12 +34,22 @@ export class CrushmapComponent implements OnInit { }; } - const rootNodeId = nodes[0].id || null; + const roots = []; nodes.reverse().forEach((node) => { + if (node.type === 'root') { + roots.push(node.id); + } treeNodeMap[node.id] = this.generateTreeLeaf(node, treeNodeMap); }); - return treeNodeMap[rootNodeId]; + const children = roots.map((id) => { + return treeNodeMap[id]; + }); + + return { + value: 'CRUSH map', + children: children + }; } private generateTreeLeaf(node: any, treeNodeMap) { -- 2.39.5