Path: blob/master/src/applications/config/controller/services/PhabricatorConfigClusterNotificationsController.php
12262 views
<?php12final class PhabricatorConfigClusterNotificationsController3extends PhabricatorConfigServicesController {45public function handleRequest(AphrontRequest $request) {6$title = pht('Notification Servers');7$doc_href = PhabricatorEnv::getDoclink('Cluster: Notifications');8$button = id(new PHUIButtonView())9->setIcon('fa-book')10->setHref($doc_href)11->setTag('a')12->setText(pht('Documentation'));1314$header = $this->buildHeaderView($title, $button);1516$notification_status = $this->buildClusterNotificationStatus();17$status = $this->buildConfigBoxView(18pht('Notifications Status'),19$notification_status);2021$crumbs = $this->newCrumbs()22->addTextCrumb($title);2324$content = id(new PHUITwoColumnView())25->setHeader($header)26->setFooter($status);2728$nav = $this->newNavigation('notification-servers');2930return $this->newPage()31->setTitle($title)32->setCrumbs($crumbs)33->setNavigation($nav)34->appendChild($content);35}3637private function buildClusterNotificationStatus() {38$viewer = $this->getViewer();3940$servers = PhabricatorNotificationServerRef::newRefs();41Javelin::initBehavior('phabricator-tooltips');4243$rows = array();44foreach ($servers as $server) {45if ($server->isAdminServer()) {46$type_icon = 'fa-database sky';47$type_tip = pht('Admin Server');48} else {49$type_icon = 'fa-bell sky';50$type_tip = pht('Client Server');51}5253$type_icon = id(new PHUIIconView())54->setIcon($type_icon)55->addSigil('has-tooltip')56->setMetadata(57array(58'tip' => $type_tip,59));6061$messages = array();6263$details = array();64if ($server->isAdminServer()) {65try {66$details = $server->loadServerStatus();67$status_icon = 'fa-exchange green';68$status_label = pht('Version %s', idx($details, 'version'));69} catch (Exception $ex) {70$status_icon = 'fa-times red';71$status_label = pht('Connection Error');72$messages[] = $ex->getMessage();73}74} else {75try {76$server->testClient();77$status_icon = 'fa-exchange green';78$status_label = pht('Connected');79} catch (Exception $ex) {80$status_icon = 'fa-times red';81$status_label = pht('Connection Error');82$messages[] = $ex->getMessage();83}84}8586if ($details) {87$uptime = idx($details, 'uptime');88$uptime = $uptime / 1000;89$uptime = phutil_format_relative_time_detailed($uptime);9091$clients = pht(92'%s Active / %s Total',93new PhutilNumber(idx($details, 'clients.active')),94new PhutilNumber(idx($details, 'clients.total')));9596$stats = pht(97'%s In / %s Out',98new PhutilNumber(idx($details, 'messages.in')),99new PhutilNumber(idx($details, 'messages.out')));100101if (idx($details, 'history.size')) {102$history = pht(103'%s Held / %sms',104new PhutilNumber(idx($details, 'history.size')),105new PhutilNumber(idx($details, 'history.age')));106} else {107$history = pht('No Messages');108}109110} else {111$uptime = null;112$clients = null;113$stats = null;114$history = null;115}116117$status_view = array(118id(new PHUIIconView())->setIcon($status_icon),119' ',120$status_label,121);122123$messages = phutil_implode_html(phutil_tag('br'), $messages);124125$rows[] = array(126$type_icon,127$server->getProtocol(),128$server->getHost(),129$server->getPort(),130$status_view,131$uptime,132$clients,133$stats,134$history,135$messages,136);137}138139$table = id(new AphrontTableView($rows))140->setNoDataString(141pht('No notification servers are configured.'))142->setHeaders(143array(144null,145pht('Proto'),146pht('Host'),147pht('Port'),148pht('Status'),149pht('Uptime'),150pht('Clients'),151pht('Messages'),152pht('History'),153null,154))155->setColumnClasses(156array(157null,158null,159null,160null,161null,162null,163null,164null,165null,166'wide',167));168169return $table;170}171172}173174175