From 765befa22f5de03934842f71a3e13cb33f3e22ab Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 20 Apr 2024 02:02:28 +0300 Subject: [PATCH] Remove empty nodes from tree because PG DSL expects that all leaf nodes are OSDs --- mon/mon.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mon/mon.js b/mon/mon.js index 94036ec9..56f2c948 100644 --- a/mon/mon.js +++ b/mon/mon.js @@ -958,6 +958,25 @@ class Mon const parent = parent_level && parent_level < node_level ? node_cfg.parent : ''; tree[parent].children.push(tree[node_id]); } + // Delete empty nodes + let deleted = 0; + do + { + deleted = 0; + for (const node_id in tree) + { + if (tree[node_id].level !== 'osd' && (!tree[node_id].children || !tree[node_id].children.length)) + { + const parent = tree[node_id].parent; + if (parent) + { + tree[parent].children = tree[parent].children.filter(c => c != tree[node_id]); + } + deleted++; + delete tree[node_id]; + } + } + } while (deleted > 0); return tree; }