Path: blob/master/src/applications/config/check/PhabricatorElasticsearchSetupCheck.php
12256 views
<?php12final class PhabricatorElasticsearchSetupCheck extends PhabricatorSetupCheck {34public function getDefaultGroup() {5return self::GROUP_OTHER;6}78protected function executeChecks() {9// TODO: Avoid fataling if we don't have a master database configured10// but have the MySQL search index configured. See T12965.11if (PhabricatorEnv::isReadOnly()) {12return;13}1415$services = PhabricatorSearchService::getAllServices();1617foreach ($services as $service) {18try {19$host = $service->getAnyHostForRole('read');20} catch (PhabricatorClusterNoHostForRoleException $e) {21// ignore the error22continue;23}24if ($host instanceof PhabricatorElasticsearchHost) {25$index_exists = null;26$index_sane = null;27try {28$engine = $host->getEngine();29$index_exists = $engine->indexExists();30if ($index_exists) {31$index_sane = $engine->indexIsSane();32}33} catch (Exception $ex) {34$summary = pht('Elasticsearch is not reachable as configured.');35$message = pht(36'Elasticsearch is configured (with the %s setting) but an '.37'exception was encountered when trying to test the index.'.38"\n\n".39'%s',40phutil_tag('tt', array(), 'cluster.search'),41phutil_tag('pre', array(), $ex->getMessage()));4243$this->newIssue('elastic.misconfigured')44->setName(pht('Elasticsearch Misconfigured'))45->setSummary($summary)46->setMessage($message)47->addRelatedPhabricatorConfig('cluster.search');48return;49}5051if (!$index_exists) {52$summary = pht(53'You enabled Elasticsearch but the index does not exist.');5455$message = pht(56'You likely enabled cluster.search without creating the '.57'index. Use the following command to create a new index.');5859$this60->newIssue('elastic.missing-index')61->setName(pht('Elasticsearch Index Not Found'))62->addCommand('./bin/search init')63->setSummary($summary)64->setMessage($message);6566} else if (!$index_sane) {67$summary = pht(68'Elasticsearch index exists but needs correction.');6970$message = pht(71'Either the schema for Elasticsearch has changed '.72'or Elasticsearch created the index automatically. '.73'Use the following command to rebuild the index.');7475$this76->newIssue('elastic.broken-index')77->setName(pht('Elasticsearch Index Schema Mismatch'))78->addCommand('./bin/search init')79->setSummary($summary)80->setMessage($message);81}82}83}84}858687}888990