Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/cluster/search/PhabricatorSearchHost.php
13450 views
1
<?php
2
3
abstract class PhabricatorSearchHost
4
extends Phobject {
5
6
const KEY_REFS = 'cluster.search.refs';
7
const KEY_HEALTH = 'cluster.search.health';
8
9
protected $engine;
10
protected $healthRecord;
11
protected $roles = array();
12
13
protected $disabled;
14
protected $host;
15
protected $port;
16
17
const STATUS_OKAY = 'okay';
18
const STATUS_FAIL = 'fail';
19
20
public function __construct(PhabricatorFulltextStorageEngine $engine) {
21
$this->engine = $engine;
22
}
23
24
public function setDisabled($disabled) {
25
$this->disabled = $disabled;
26
return $this;
27
}
28
29
public function getDisabled() {
30
return $this->disabled;
31
}
32
33
/**
34
* @return PhabricatorFulltextStorageEngine
35
*/
36
public function getEngine() {
37
return $this->engine;
38
}
39
40
public function isWritable() {
41
return $this->hasRole('write');
42
}
43
44
public function isReadable() {
45
return $this->hasRole('read');
46
}
47
48
public function hasRole($role) {
49
return isset($this->roles[$role]) && $this->roles[$role] === true;
50
}
51
52
public function setRoles(array $roles) {
53
foreach ($roles as $role => $val) {
54
$this->roles[$role] = $val;
55
}
56
return $this;
57
}
58
59
public function getRoles() {
60
$roles = array();
61
foreach ($this->roles as $key => $val) {
62
if ($val) {
63
$roles[$key] = $val;
64
}
65
}
66
return $roles;
67
}
68
69
public function setPort($value) {
70
$this->port = $value;
71
return $this;
72
}
73
74
public function getPort() {
75
return $this->port;
76
}
77
78
public function setHost($value) {
79
$this->host = $value;
80
return $this;
81
}
82
83
public function getHost() {
84
return $this->host;
85
}
86
87
88
public function getHealthRecordCacheKey() {
89
$host = $this->getHost();
90
$port = $this->getPort();
91
$key = self::KEY_HEALTH;
92
93
return "{$key}({$host}, {$port})";
94
}
95
96
/**
97
* @return PhabricatorClusterServiceHealthRecord
98
*/
99
public function getHealthRecord() {
100
if (!$this->healthRecord) {
101
$this->healthRecord = new PhabricatorClusterServiceHealthRecord(
102
$this->getHealthRecordCacheKey());
103
}
104
return $this->healthRecord;
105
}
106
107
public function didHealthCheck($reachable) {
108
$record = $this->getHealthRecord();
109
$should_check = $record->getShouldCheck();
110
111
if ($should_check) {
112
$record->didHealthCheck($reachable);
113
}
114
}
115
116
/**
117
* @return string[] Get a list of fields to show in the status overview UI
118
*/
119
abstract public function getStatusViewColumns();
120
121
abstract public function getConnectionStatus();
122
123
}
124
125