diff options
| author | Yuriy Andamasov <yuriy@vyos.io> | 2026-05-22 10:43:48 +0300 |
|---|---|---|
| committer | Yuriy Andamasov <yuriy@vyos.io> | 2026-05-22 10:43:48 +0300 |
| commit | 77fdd523554e18abc3a834bbd52527f015bc4aa8 (patch) | |
| tree | 379777dc790c25af69e7710b60d3bb8e891ac531 /src | |
| parent | ea323c862121e2b309f526d5027a511b8d61e906 (diff) | |
| download | phorge-elasticsearch-modern-77fdd523554e18abc3a834bbd52527f015bc4aa8.tar.gz phorge-elasticsearch-modern-77fdd523554e18abc3a834bbd52527f015bc4aa8.zip | |
Add VyOSElasticModernHost + placeholder engine stub
Host class mirrors PhabricatorElasticsearchHost's surface. Engine is
a stub providing only getEngineIdentifier() and getHostType() so the
host's tests can construct an engine instance; real engine
implementation lands in subsequent commits. All six abstract methods
of PhabricatorFulltextStorageEngine are implemented (four as throwing
stubs to be replaced in E7/E8).
.arcconfig gains "src/" in the load list so arc unit can discover the
extension library; test case extends PhutilTestCase (no DB needed for
pure-PHP host property assertions).
🤖 Generated by [robots](https://vyos.io)
Diffstat (limited to 'src')
| -rw-r--r-- | src/__phutil_library_map__.php | 12 | ||||
| -rw-r--r-- | src/__tests__/VyOSElasticModernHostTestCase.php | 52 | ||||
| -rw-r--r-- | src/engine/VyOSElasticModernFulltextStorageEngine.php | 40 | ||||
| -rw-r--r-- | src/host/VyOSElasticModernHost.php | 89 |
4 files changed, 191 insertions, 2 deletions
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 1ebc28b..298810e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -8,7 +8,15 @@ */ phutil_register_library_map(array( '__library_version__' => 2, - 'class' => array(), + 'class' => array( + 'VyOSElasticModernFulltextStorageEngine' => 'engine/VyOSElasticModernFulltextStorageEngine.php', + 'VyOSElasticModernHost' => 'host/VyOSElasticModernHost.php', + 'VyOSElasticModernHostTestCase' => '__tests__/VyOSElasticModernHostTestCase.php', + ), 'function' => array(), - 'xmap' => array(), + 'xmap' => array( + 'VyOSElasticModernFulltextStorageEngine' => 'PhabricatorFulltextStorageEngine', + 'VyOSElasticModernHost' => 'PhabricatorSearchHost', + 'VyOSElasticModernHostTestCase' => 'PhutilTestCase', + ), )); diff --git a/src/__tests__/VyOSElasticModernHostTestCase.php b/src/__tests__/VyOSElasticModernHostTestCase.php new file mode 100644 index 0000000..1c5ef95 --- /dev/null +++ b/src/__tests__/VyOSElasticModernHostTestCase.php @@ -0,0 +1,52 @@ +<?php + +final class VyOSElasticModernHostTestCase + extends PhutilTestCase { + + public function testDisplayName() { + $engine = new VyOSElasticModernFulltextStorageEngine(); + $host = new VyOSElasticModernHost($engine); + $this->assertEqual( + 'Elasticsearch (modern)', + (string)$host->getDisplayName()); + } + + public function testConfigDefaults() { + $engine = new VyOSElasticModernFulltextStorageEngine(); + $host = new VyOSElasticModernHost($engine); + $host->setConfig(array()); + $this->assertEqual('http', $host->getProtocol()); + $this->assertEqual('phabricator/', $host->getPath()); + $this->assertEqual(7, $host->getVersion()); + } + + public function testConfigOverrides() { + $engine = new VyOSElasticModernFulltextStorageEngine(); + $host = new VyOSElasticModernHost($engine); + $host->setConfig(array( + 'host' => 'es.example.com', + 'port' => 9200, + 'protocol' => 'https', + 'path' => '/myphorge', + 'version' => 8, + )); + $this->assertEqual('https', $host->getProtocol()); + $this->assertEqual('/myphorge', $host->getPath()); + $this->assertEqual(8, $host->getVersion()); + } + + public function testGetURI() { + $engine = new VyOSElasticModernFulltextStorageEngine(); + $host = new VyOSElasticModernHost($engine); + $host->setConfig(array( + 'host' => 'es.example.com', + 'port' => 9200, + 'protocol' => 'http', + 'path' => '/phabricator', + )); + $uri = (string)$host->getURI('/_doc/abc'); + $this->assertTrue(strpos($uri, 'es.example.com') !== false); + $this->assertTrue(strpos($uri, '/_doc/abc') !== false); + } + +} diff --git a/src/engine/VyOSElasticModernFulltextStorageEngine.php b/src/engine/VyOSElasticModernFulltextStorageEngine.php new file mode 100644 index 0000000..d10bac7 --- /dev/null +++ b/src/engine/VyOSElasticModernFulltextStorageEngine.php @@ -0,0 +1,40 @@ +<?php + +/** + * Placeholder for the engine class. Real implementation grows in Phase 3-4. + * Tasks E1-E8 replace the throwing stubs below with working code. + */ +class VyOSElasticModernFulltextStorageEngine + extends PhabricatorFulltextStorageEngine { + + public function getEngineIdentifier() { + return 'elasticsearch-modern'; + } + + public function getHostType() { + return new VyOSElasticModernHost($this); + } + + public function reindexAbstractDocument( + PhabricatorSearchAbstractDocument $doc) { + throw new Exception(pht( + 'reindexAbstractDocument() is not yet implemented on '. + 'VyOSElasticModernFulltextStorageEngine; lands in Task E7.')); + } + + public function executeSearch(PhabricatorSavedQuery $query) { + throw new Exception(pht( + 'executeSearch() is not yet implemented; lands in Task E8.')); + } + + public function indexExists() { + throw new Exception(pht( + 'indexExists() is not yet implemented; lands in Task E8.')); + } + + public function getIndexStats() { + throw new Exception(pht( + 'getIndexStats() is not yet implemented; lands in Task E8.')); + } + +} diff --git a/src/host/VyOSElasticModernHost.php b/src/host/VyOSElasticModernHost.php new file mode 100644 index 0000000..8bbd29e --- /dev/null +++ b/src/host/VyOSElasticModernHost.php @@ -0,0 +1,89 @@ +<?php + +/** + * Host subclass for the phorge-elasticsearch-modern extension. + * + * Mirrors PhabricatorElasticsearchHost's surface area; differs only in + * the display name and (in future versions) the auth config fields. + */ +final class VyOSElasticModernHost extends PhabricatorSearchHost { + + private $version = 7; + private $path = 'phabricator/'; + private $protocol = 'http'; + + const KEY_REFS = 'search.elasticmodern.refs'; + + public function setConfig($config) { + $this->setRoles(idx($config, 'roles', $this->getRoles())) + ->setHost(idx($config, 'host', $this->host)) + ->setPort(idx($config, 'port', $this->port)) + ->setProtocol(idx($config, 'protocol', $this->protocol)) + ->setPath(idx($config, 'path', $this->path)) + ->setVersion(idx($config, 'version', $this->version)); + return $this; + } + + public function getDisplayName() { + return pht('Elasticsearch (modern)'); + } + + public function getStatusViewColumns() { + return array( + pht('Protocol') => $this->getProtocol(), + pht('Host') => $this->getHost(), + pht('Port') => $this->getPort(), + pht('Index Path') => $this->getPath(), + pht('Version') => $this->getVersion(), + pht('Roles') => implode(', ', array_keys($this->getRoles())), + ); + } + + public function setProtocol($protocol) { + $this->protocol = $protocol; + return $this; + } + + public function getProtocol() { + return $this->protocol; + } + + public function setPath($path) { + $this->path = $path; + return $this; + } + + public function getPath() { + return $this->path; + } + + public function setVersion($version) { + $this->version = $version; + return $this; + } + + public function getVersion() { + return $this->version; + } + + /** + * @return PhutilURI + */ + public function getURI($to_path = null) { + $uri = id(new PhutilURI('http://'.$this->getHost())) + ->setProtocol($this->getProtocol()) + ->setPort($this->getPort()) + ->setPath($this->getPath()); + + if ($to_path) { + $uri->appendPath($to_path); + } + return $uri; + } + + public function getConnectionStatus() { + $status = $this->getEngine()->indexIsSane($this); + return $status ? parent::STATUS_OKAY : parent::STATUS_FAIL; + } + +} |
