Path: blob/master/src/applications/config/controller/services/PhabricatorConfigClusterDatabasesController.php
12262 views
<?php12final class PhabricatorConfigClusterDatabasesController3extends PhabricatorConfigServicesController {45public function handleRequest(AphrontRequest $request) {6$nav = $this->newNavigation('database-servers');78$title = pht('Database Servers');9$doc_href = PhabricatorEnv::getDoclink('Cluster: Databases');10$button = id(new PHUIButtonView())11->setIcon('fa-book')12->setHref($doc_href)13->setTag('a')14->setText(pht('Documentation'));1516$header = $this->buildHeaderView($title, $button);1718$database_status = $this->buildClusterDatabaseStatus();19$status = $this->buildConfigBoxView(pht('Status'), $database_status);2021$crumbs = $this->newCrumbs()22->addTextCrumb($title);2324$content = id(new PHUITwoColumnView())25->setHeader($header)26->setFooter($status);2728return $this->newPage()29->setTitle($title)30->setCrumbs($crumbs)31->setNavigation($nav)32->appendChild($content);33}3435private function buildClusterDatabaseStatus() {36$viewer = $this->getViewer();3738$databases = PhabricatorDatabaseRef::queryAll();39$connection_map = PhabricatorDatabaseRef::getConnectionStatusMap();40$replica_map = PhabricatorDatabaseRef::getReplicaStatusMap();41Javelin::initBehavior('phabricator-tooltips');4243$rows = array();44foreach ($databases as $database) {45$messages = array();4647if ($database->getIsMaster()) {48$role_icon = id(new PHUIIconView())49->setIcon('fa-database sky')50->addSigil('has-tooltip')51->setMetadata(52array(53'tip' => pht('Master'),54));55} else {56$role_icon = id(new PHUIIconView())57->setIcon('fa-download')58->addSigil('has-tooltip')59->setMetadata(60array(61'tip' => pht('Replica'),62));63}6465if ($database->getDisabled()) {66$conn_icon = 'fa-times';67$conn_color = 'grey';68$conn_label = pht('Disabled');69} else {70$status = $database->getConnectionStatus();7172$info = idx($connection_map, $status, array());73$conn_icon = idx($info, 'icon');74$conn_color = idx($info, 'color');75$conn_label = idx($info, 'label');7677if ($status === PhabricatorDatabaseRef::STATUS_OKAY) {78$latency = $database->getConnectionLatency();79$latency = (int)(1000000 * $latency);80$conn_label = pht('%s us', new PhutilNumber($latency));81}82}8384$connection = array(85id(new PHUIIconView())->setIcon("{$conn_icon} {$conn_color}"),86' ',87$conn_label,88);8990if ($database->getDisabled()) {91$replica_icon = 'fa-times';92$replica_color = 'grey';93$replica_label = pht('Disabled');94} else {95$status = $database->getReplicaStatus();9697$info = idx($replica_map, $status, array());98$replica_icon = idx($info, 'icon');99$replica_color = idx($info, 'color');100$replica_label = idx($info, 'label');101102if ($database->getIsMaster()) {103if ($status === PhabricatorDatabaseRef::REPLICATION_OKAY) {104$replica_icon = 'fa-database';105}106} else {107switch ($status) {108case PhabricatorDatabaseRef::REPLICATION_OKAY:109case PhabricatorDatabaseRef::REPLICATION_SLOW:110$delay = $database->getReplicaDelay();111if ($delay) {112$replica_label = pht('%ss Behind', new PhutilNumber($delay));113} else {114$replica_label = pht('Up to Date');115}116break;117}118}119}120121$replication = array(122id(new PHUIIconView())->setIcon("{$replica_icon} {$replica_color}"),123' ',124$replica_label,125);126127$health = $database->getHealthRecord();128$health_up = $health->getUpEventCount();129$health_down = $health->getDownEventCount();130131if ($health->getIsHealthy()) {132$health_icon = id(new PHUIIconView())133->setIcon('fa-plus green');134} else {135$health_icon = id(new PHUIIconView())136->setIcon('fa-times red');137$messages[] = pht(138'UNHEALTHY: This database has failed recent health checks. Traffic '.139'will not be sent to it until it recovers.');140}141142$health_count = pht(143'%s / %s',144new PhutilNumber($health_up),145new PhutilNumber($health_up + $health_down));146147$health_status = array(148$health_icon,149' ',150$health_count,151);152153$conn_message = $database->getConnectionMessage();154if ($conn_message) {155$messages[] = $conn_message;156}157158$replica_message = $database->getReplicaMessage();159if ($replica_message) {160$messages[] = $replica_message;161}162163$messages = phutil_implode_html(phutil_tag('br'), $messages);164165$partition = null;166if ($database->getIsMaster()) {167if ($database->getIsDefaultPartition()) {168$partition = id(new PHUIIconView())169->setIcon('fa-circle sky')170->addSigil('has-tooltip')171->setMetadata(172array(173'tip' => pht('Default Partition'),174));175} else {176$map = $database->getApplicationMap();177if ($map) {178$list = implode(', ', $map);179} else {180$list = pht('Empty');181}182183$partition = id(new PHUIIconView())184->setIcon('fa-adjust sky')185->addSigil('has-tooltip')186->setMetadata(187array(188'tip' => pht('Partition: %s', $list),189));190}191}192193$rows[] = array(194$role_icon,195$partition,196$database->getHost(),197$database->getPort(),198$database->getUser(),199$connection,200$replication,201$health_status,202$messages,203);204}205206207$table = id(new AphrontTableView($rows))208->setNoDataString(209pht('This server is not configured in cluster mode.'))210->setHeaders(211array(212null,213null,214pht('Host'),215pht('Port'),216pht('User'),217pht('Connection'),218pht('Replication'),219pht('Health'),220pht('Messages'),221))222->setColumnClasses(223array(224null,225null,226null,227null,228null,229null,230null,231null,232'wide',233));234235return $table;236}237238}239240241