From 4ec13a9096c6d3e189363749e9c1d5dfbd8d9569 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 21 Apr 2023 13:52:46 +0200 Subject: [PATCH] ImportSource: ships object path array fixes #255 --- doc/84-Changelog.md | 5 ++ .../v1.8.0/84-18-03_path_export.png | Bin 0 -> 10341 bytes library/Vspheredb/Db/BulkPathLookup.php | 59 ++++++++++++++++++ library/Vspheredb/Db/QueryHelper.php | 25 ++++++++ .../ProvidedHook/Director/ImportSource.php | 31 +++------ 5 files changed, 99 insertions(+), 21 deletions(-) create mode 100644 doc/screenshot/84_changelog/v1.8.0/84-18-03_path_export.png create mode 100644 library/Vspheredb/Db/BulkPathLookup.php create mode 100644 library/Vspheredb/Db/QueryHelper.php diff --git a/doc/84-Changelog.md b/doc/84-Changelog.md index 470f7ad7..cf46d2ad 100644 --- a/doc/84-Changelog.md +++ b/doc/84-Changelog.md @@ -15,6 +15,11 @@ v1.8.0 (unreleased) * FIX: vCenter filter is now preserved across main table tabs (#516) +### Integrations +* FEATURE: Director Import Source now ships an object path array (#255) + +![Path Export](screenshot/84_changelog/v1.8.0/84-18-03_path_export.png) + ### REST API * Hosts, VirtualMachines and DataStores can now be exported via REST API (#511) diff --git a/doc/screenshot/84_changelog/v1.8.0/84-18-03_path_export.png b/doc/screenshot/84_changelog/v1.8.0/84-18-03_path_export.png new file mode 100644 index 0000000000000000000000000000000000000000..42772fa61be1e384c3f1dc35428d16bc0bde7ec7 GIT binary patch literal 10341 zcmb7qXEdB`+jaEbJEIew5TX+;GkOrc6P;l6B)aHkbWwBbz4z$76J7K&f@q@)M&8MN zKkr)4^S#fX@6W7R*R{@m9Q)jRA6L|C4Ilw7E$)*iPY9GjirP<}pa7Bohp{n{zaN%Z zXP!LaOx;m*s+|F6Rzb=>j_pDFKuglJMm3tz2onerR?n)-_2E+w?4E4DAZ#%ND=+NfO1^O08Nu*D{mzM(M8;unuj z?RBOVi2GQUn|@^JEQD&|)9N9@*Z$!7>;1(IU7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`>0?!e1uJ2GU=W8(gx%&%rv3schQaKwj3@;>%x?Eq)F; z<&Gh!k4mU{U^t+J(;%DT%PgpFu=yAMl0gt#OjMdG#v<6|VP7G3~xVKJ5{+06x9xcgAAXh8oZZ9NrUU@oINDnq`AMlaG}~ zJ$fa4o2|MzFczlP|M1nNbxg;<%2_7h*Wa7IA@Q(* zeZB+9zvyuUKhPT}HSY_5^CIPa6Pu*F>e1FH;?t)jOt%sPFqZF@S6sO=E^^_Wg6onM z-_Xfmyq%I^!vwGa(*`xf>*`sub+P3JGwfm9GWUw3v}`k@7SFE{_%jJ9;Z9j##$Bp_ zD_uxsT2JC&Bbye%b}m(3jDscxLV>?GN#htKhifiEo7+Ra6O{e#KjZiZ;ByC(WDc zgVi>hEb@{(Gn+MCA-g%G{#M=9e$k$*8sg{jwLdtRl_t=6x=>Bm2uQ@==|cgPRjqU+ zx@JkPp9Z>w z5^s)lQNup#SpKwDg$NOa^^>lXA0{(ik(?6!P0wmr>fIYES~IWNkT)>_6!Q~;WJY&q zM@Hy8Uy4SDSt+tLcpRe4M1S z+7my?i&5>=aCA8MTEuG+X(;?(P;4&3`TEefDLSjWjNRM8EH1%{&^0tV7MBsZbCO2i zQv7pQ8K)G|_@2lzV`w4*3Tqoir+>W1w%YsyTF$zuC$8elMnrP>Qh#V#<>(CUu6=o# zcQb%>gVbdzN=EZ#G%cE0$%B1X*gVfwTScX=YPE-0MBXb8tX!$9hXMkaeCE}Hwzmrtfa84DFd+UxHQz?^gQ&LvS^T(JgWQ?-Cwmy{M%*cM;iU$j=9# NC@X0wR>@n0{0}!ysMP=f literal 0 HcmV?d00001 diff --git a/library/Vspheredb/Db/BulkPathLookup.php b/library/Vspheredb/Db/BulkPathLookup.php new file mode 100644 index 00000000..d898d290 --- /dev/null +++ b/library/Vspheredb/Db/BulkPathLookup.php @@ -0,0 +1,59 @@ +db = $db; + $this->vCenterFilterUuids = $vCenterUuids; + } + + public function getParents(?string $objectParent): array + { + if ($this->nodes === null) { + $this->nodes = $this->fetchAllParents(); + } + $path = []; + $parentUuid = $objectParent; + while ($parentUuid !== null) { + if (! isset($this->nodes[$parentUuid])) { + throw new RuntimeException('Parent lookup failed: ' . Uuid::fromBytes($parentUuid)->toString()); + } + $node = $this->nodes[$parentUuid]; + $path[$parentUuid] = $node->object_name; + $parentUuid = $node->parent_uuid; + } + + return array_reverse($path, true); + } + + protected function fetchAllParents(): array + { + $db = $this->db->getDbAdapter(); + $query = $db->select()->from(['p' => 'object'], [ + 'uuid' => 'p.uuid', + 'parent_uuid' => 'p.parent_uuid', + 'object_name' => 'p.object_name' + ])->join(['o' => 'object'], 'o.parent_uuid = p.uuid', []); + QueryHelper::applyOptionalVCenterFilter($db, $query, 'o.vcenter_uuid', $this->vCenterFilterUuids); + $result = []; + foreach ($db->fetchAll($query) as $row) { + $result[$row->uuid] = $row; + } + return $result; + } +} diff --git a/library/Vspheredb/Db/QueryHelper.php b/library/Vspheredb/Db/QueryHelper.php new file mode 100644 index 00000000..29d55771 --- /dev/null +++ b/library/Vspheredb/Db/QueryHelper.php @@ -0,0 +1,25 @@ +where('1 = 0'); + return; + } + + if (count($vCenterFilterUuids) === 1) { + $query->where("$column = ?", DbUtil::quoteBinaryCompat(array_shift($vCenterFilterUuids), $db)); + } else { + $query->where("$column IN (?)", DbUtil::quoteBinaryCompat($vCenterFilterUuids, $db)); + } + } +} diff --git a/library/Vspheredb/ProvidedHook/Director/ImportSource.php b/library/Vspheredb/ProvidedHook/Director/ImportSource.php index 114461d2..e577829d 100644 --- a/library/Vspheredb/ProvidedHook/Director/ImportSource.php +++ b/library/Vspheredb/ProvidedHook/Director/ImportSource.php @@ -7,14 +7,15 @@ use Icinga\Module\Director\Hook\ImportSourceHook; use Icinga\Module\Director\Web\Form\QuickForm; use Icinga\Module\Vspheredb\Db; +use Icinga\Module\Vspheredb\Db\BulkPathLookup; use Icinga\Module\Vspheredb\Db\DbUtil; +use Icinga\Module\Vspheredb\Db\QueryHelper; use Icinga\Module\Vspheredb\DbObject\VCenter; use Icinga\Module\Vspheredb\Web\Table\TableWithParentFilter; use Icinga\Module\Vspheredb\Web\Table\TableWithVCenterFilter; use Ramsey\Uuid\Uuid; use Zend_Db_Adapter_Abstract as ZfDb; use function array_keys; -use function in_array; /** * Class ImportSource @@ -26,6 +27,7 @@ class ImportSource extends ImportSourceHook implements TableWithVCenterFilter, T protected $hostColumns = [ 'object_name' => 'o.object_name', 'uuid' => 'o.uuid', + 'parent_uuid' => 'o.parent_uuid', 'vcenter_name' => 'vc.name', 'sysinfo_vendor' => 'h.sysinfo_vendor', 'sysinfo_model' => 'h.sysinfo_model', @@ -43,6 +45,7 @@ class ImportSource extends ImportSourceHook implements TableWithVCenterFilter, T 'object_name' => 'o.object_name', 'moref' => 'o.moref', 'uuid' => 'o.uuid', + 'parent_uuid' => 'o.parent_uuid', 'vcenter_name' => 'vc.name', 'guest_ip_address' => 'vm.guest_ip_address', 'hardware_numcpu' => 'vm.hardware_numcpu', @@ -62,6 +65,7 @@ class ImportSource extends ImportSourceHook implements TableWithVCenterFilter, T 'object_name' => 'o.object_name', 'object_type' => 'o.object_type', 'uuid' => 'o.uuid', + 'parent_uuid' => 'o.parent_uuid', 'vcenter_name' => 'vc.name', 'effective_cpu_mhz' => 'cr.effective_cpu_mhz', 'effective_memory_size_mb' => 'cr.effective_memory_size_mb', @@ -77,6 +81,7 @@ class ImportSource extends ImportSourceHook implements TableWithVCenterFilter, T protected $datastoreColumns = [ 'object_name' => 'o.object_name', 'uuid' => 'o.uuid', + 'parent_uuid' => 'o.parent_uuid', 'vcenter_name' => 'vc.name', 'maintenance_mode' => 'ds.maintenance_mode', 'capacity' => 'ds.capacity', @@ -159,6 +164,7 @@ public function fetchData(): array { $connection = Db::newConfiguredInstance(); $db = $connection->getDbAdapter(); + $pathLookup = new BulkPathLookup($connection); $objectType = $this->getSetting('object_type'); switch ($objectType) { case 'host_system': @@ -176,7 +182,7 @@ public function fetchData(): array default: return []; } - $this->applyOptionalVCenterFilter($db, $query); + QueryHelper::applyOptionalVCenterFilter($db, $query, 'vc.instance_uuid', $this->vCenterFilterUuids); $this->applyOptionalParentFilter($query); $result = $db->fetchAll( $this->eventuallyFilterVCenter($this->joinVCenter($query)) @@ -187,6 +193,8 @@ public function fetchData(): array } foreach ($result as $row) { + $row->path = array_values($pathLookup->getParents($row->parent_uuid)); + unset($row->parent_uuid); static::convertDbRowToJsonData($row); } @@ -338,23 +346,4 @@ protected function applyOptionalParentFilter($query) $query->where('o.parent_uuid IN (?)', $this->parentFilterUuids); } - - protected function applyOptionalVCenterFilter(ZfDb $db, $query) - { - $uuids = $this->vCenterFilterUuids; - if ($uuids === null) { - return; - } - if (empty($uuids)) { - $query->where('1 = 0'); - return; - } - - $column = 'vc.instance_uuid'; - if (count($uuids) === 1) { - $query->where("$column = ?", DbUtil::quoteBinaryCompat(array_shift($uuids), $db)); - } else { - $query->where("$column IN (?)", DbUtil::quoteBinaryCompat($uuids, $db)); - } - } }