From cced12b136b9d9af33203324e5dbf9ac1013a92b Mon Sep 17 00:00:00 2001 From: Klim Todrik Date: Fri, 17 Nov 2023 15:07:13 +0100 Subject: [PATCH] Show settings support --- src/Manticore/ManticoreConnector.php | 20 ++++++++ tests/ManticoreConnectorTest.php | 73 +++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/src/Manticore/ManticoreConnector.php b/src/Manticore/ManticoreConnector.php index bd46ba8..3487e3c 100644 --- a/src/Manticore/ManticoreConnector.php +++ b/src/Manticore/ManticoreConnector.php @@ -234,6 +234,26 @@ public function addTableToCluster($tableName, $log = true): bool return true; } + public function showSettings($log = false): array + { + $settings = $this->fetcher->fetch("show settings", $log); + + if ($this->getConnectionError()) { + return []; + } + + $searchdSettings = []; + foreach ($settings as $row) { + if ($row['Setting_name'] === 'searchd.listen'){ + $searchdSettings[$row['Setting_name']][] = $row['Value']; + continue; + } + $searchdSettings[$row['Setting_name']] = $row['Value']; + } + + + return $searchdSettings; + } public function reloadIndexes() { diff --git a/tests/ManticoreConnectorTest.php b/tests/ManticoreConnectorTest.php index f5f3407..aa2abee 100644 --- a/tests/ManticoreConnectorTest.php +++ b/tests/ManticoreConnectorTest.php @@ -573,7 +573,6 @@ public function joinClusterReturnFalseOnConnectionError() } - /** * @test * @return void @@ -708,6 +707,78 @@ public function optimize() } + /** + * @test + * + * @return void + */ + public function showSettings() + { + $this->mock->shouldReceive('fetch') + ->withArgs(['show settings', false]) + ->andReturn( + [ + ['Setting_name' => 'configuration_file', 'Value' => '/etc/manticoresearch/envreader.sh'], + ['Setting_name' => 'worker_pid', 'Value' => '1'], + ['Setting_name' => 'searchd.query_log_format', 'Value' => 'sphinxql'], + ['Setting_name' => 'searchd.listen', 'Value' => '9306:mysql41'], + ['Setting_name' => 'searchd.listen', 'Value' => '/var/run/mysqld/mysqld.sock:mysql41'], + ['Setting_name' => 'searchd.listen', 'Value' => '9308:http'], + ['Setting_name' => 'searchd.listen', 'Value' => '172.17.0.2:9312'], + ['Setting_name' => 'searchd.listen', 'Value' => '172.17.0.2:9315-9325:replication'], + ['Setting_name' => 'searchd.max_packet_size', 'Value' => '128M'], + ['Setting_name' => 'searchd.log', 'Value' => '/var/log/manticore/searchd.log'], + ['Setting_name' => 'searchd.pid_file', 'Value' => '/var/run/manticore/searchd.pid'], + ['Setting_name' => 'searchd.data_dir', 'Value' => '/var/lib/manticore'], + ['Setting_name' => 'searchd.binlog_path', 'Value' => '/var/lib/manticore/binlog'], + ['Setting_name' => 'common.plugin_dir', 'Value' => '/usr/local/lib/manticore'] + ] + ); + + $this->mock->shouldReceive('getConnectionError')->andReturn(false); + + $result = $this->manticoreConnection->showSettings(); + $this->assertSame( + $result, + [ + 'configuration_file' => '/etc/manticoresearch/envreader.sh', + 'worker_pid' => '1', + 'searchd.query_log_format' => 'sphinxql', + 'searchd.listen' => [ + '9306:mysql41', + '/var/run/mysqld/mysqld.sock:mysql41', + '9308:http', + '172.17.0.2:9312', + '172.17.0.2:9315-9325:replication' + ], + 'searchd.max_packet_size' => '128M', + 'searchd.log' => '/var/log/manticore/searchd.log', + 'searchd.pid_file' => '/var/run/manticore/searchd.pid', + 'searchd.data_dir' => '/var/lib/manticore', + 'searchd.binlog_path' => '/var/lib/manticore/binlog', + 'common.plugin_dir' => '/usr/local/lib/manticore' + ] + ); + } + + + /** + * @test + * + * @return void + */ + public function showSettingsConnectionError() + { + $this->mock->shouldReceive('fetch') + ->withArgs(['show settings', false]) + ->andReturnNull(); + + $this->mock->shouldReceive('getConnectionError')->andReturn(true); + + $result = $this->manticoreConnection->showSettings(); + $this->assertEmpty($result); + } + /** * @test * @return void