Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/config/check/PhabricatorElasticsearchSetupCheck.php
12256 views
1
<?php
2
3
final class PhabricatorElasticsearchSetupCheck extends PhabricatorSetupCheck {
4
5
public function getDefaultGroup() {
6
return self::GROUP_OTHER;
7
}
8
9
protected function executeChecks() {
10
// TODO: Avoid fataling if we don't have a master database configured
11
// but have the MySQL search index configured. See T12965.
12
if (PhabricatorEnv::isReadOnly()) {
13
return;
14
}
15
16
$services = PhabricatorSearchService::getAllServices();
17
18
foreach ($services as $service) {
19
try {
20
$host = $service->getAnyHostForRole('read');
21
} catch (PhabricatorClusterNoHostForRoleException $e) {
22
// ignore the error
23
continue;
24
}
25
if ($host instanceof PhabricatorElasticsearchHost) {
26
$index_exists = null;
27
$index_sane = null;
28
try {
29
$engine = $host->getEngine();
30
$index_exists = $engine->indexExists();
31
if ($index_exists) {
32
$index_sane = $engine->indexIsSane();
33
}
34
} catch (Exception $ex) {
35
$summary = pht('Elasticsearch is not reachable as configured.');
36
$message = pht(
37
'Elasticsearch is configured (with the %s setting) but an '.
38
'exception was encountered when trying to test the index.'.
39
"\n\n".
40
'%s',
41
phutil_tag('tt', array(), 'cluster.search'),
42
phutil_tag('pre', array(), $ex->getMessage()));
43
44
$this->newIssue('elastic.misconfigured')
45
->setName(pht('Elasticsearch Misconfigured'))
46
->setSummary($summary)
47
->setMessage($message)
48
->addRelatedPhabricatorConfig('cluster.search');
49
return;
50
}
51
52
if (!$index_exists) {
53
$summary = pht(
54
'You enabled Elasticsearch but the index does not exist.');
55
56
$message = pht(
57
'You likely enabled cluster.search without creating the '.
58
'index. Use the following command to create a new index.');
59
60
$this
61
->newIssue('elastic.missing-index')
62
->setName(pht('Elasticsearch Index Not Found'))
63
->addCommand('./bin/search init')
64
->setSummary($summary)
65
->setMessage($message);
66
67
} else if (!$index_sane) {
68
$summary = pht(
69
'Elasticsearch index exists but needs correction.');
70
71
$message = pht(
72
'Either the schema for Elasticsearch has changed '.
73
'or Elasticsearch created the index automatically. '.
74
'Use the following command to rebuild the index.');
75
76
$this
77
->newIssue('elastic.broken-index')
78
->setName(pht('Elasticsearch Index Schema Mismatch'))
79
->addCommand('./bin/search init')
80
->setSummary($summary)
81
->setMessage($message);
82
}
83
}
84
}
85
}
86
87
88
}
89
90