Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/config/controller/services/PhabricatorConfigClusterSearchController.php
12262 views
1
<?php
2
3
final class PhabricatorConfigClusterSearchController
4
extends PhabricatorConfigServicesController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$title = pht('Search Servers');
8
$doc_href = PhabricatorEnv::getDoclink('Cluster: Search');
9
10
$button = id(new PHUIButtonView())
11
->setIcon('fa-book')
12
->setHref($doc_href)
13
->setTag('a')
14
->setText(pht('Documentation'));
15
16
$header = $this->buildHeaderView($title, $button);
17
18
$search_status = $this->buildClusterSearchStatus();
19
20
$crumbs = $this->newCrumbs()
21
->addTextCrumb($title);
22
23
$content = id(new PHUITwoColumnView())
24
->setHeader($header)
25
->setFooter($search_status);
26
27
$nav = $this->newNavigation('search-servers');
28
29
return $this->newPage()
30
->setTitle($title)
31
->setCrumbs($crumbs)
32
->setNavigation($nav)
33
->appendChild($content);
34
}
35
36
private function buildClusterSearchStatus() {
37
$viewer = $this->getViewer();
38
39
$services = PhabricatorSearchService::getAllServices();
40
Javelin::initBehavior('phabricator-tooltips');
41
42
$view = array();
43
foreach ($services as $service) {
44
$view[] = $this->renderStatusView($service);
45
}
46
return $view;
47
}
48
49
private function renderStatusView($service) {
50
$head = array_merge(
51
array(pht('Type')),
52
array_keys($service->getStatusViewColumns()),
53
array(pht('Status')));
54
55
$rows = array();
56
57
$status_map = PhabricatorSearchService::getConnectionStatusMap();
58
$stats = false;
59
$stats_view = false;
60
61
foreach ($service->getHosts() as $host) {
62
try {
63
$status = $host->getConnectionStatus();
64
$status = idx($status_map, $status, array());
65
} catch (Exception $ex) {
66
$status['icon'] = 'fa-times';
67
$status['label'] = pht('Connection Error');
68
$status['color'] = 'red';
69
$host->didHealthCheck(false);
70
}
71
72
if (!$stats_view) {
73
try {
74
$stats = $host->getEngine()->getIndexStats($host);
75
$stats_view = $this->renderIndexStats($stats);
76
} catch (Exception $e) {
77
$stats_view = false;
78
}
79
}
80
81
$type_icon = 'fa-search sky';
82
$type_tip = $host->getDisplayName();
83
84
$type_icon = id(new PHUIIconView())
85
->setIcon($type_icon);
86
$status_view = array(
87
id(new PHUIIconView())->setIcon($status['icon'].' '.$status['color']),
88
' ',
89
$status['label'],
90
);
91
$row = array(array($type_icon, ' ', $type_tip));
92
$row = array_merge($row, array_values(
93
$host->getStatusViewColumns()));
94
$row[] = $status_view;
95
$rows[] = $row;
96
}
97
98
$table = id(new AphrontTableView($rows))
99
->setNoDataString(pht('No search servers are configured.'))
100
->setHeaders($head);
101
102
$view = $this->buildConfigBoxView(pht('Search Servers'), $table);
103
104
$stats = null;
105
if ($stats_view->hasAnyProperties()) {
106
$stats = $this->buildConfigBoxView(
107
pht('%s Stats', $service->getDisplayName()),
108
$stats_view);
109
}
110
111
return array($stats, $view);
112
}
113
114
private function renderIndexStats($stats) {
115
$view = id(new PHUIPropertyListView());
116
if ($stats !== false) {
117
foreach ($stats as $label => $val) {
118
$view->addProperty($label, $val);
119
}
120
}
121
return $view;
122
}
123
124
}
125
126