From 40226bbfd0f2bd4fb185dcfa682f39e82e216175 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 23 Jul 2013 12:10:41 -0700 Subject: [PATCH] Mostly modernize daemon detail views Summary: Ref T3557. The major goals here are: - Modernize use of UI elements. - Present daemon status with more clarity. Particularly, the "Waiting" status is called out and explained in detail. Test Plan: {F51247} {F51248} Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3557 Differential Revision: https://secure.phabricator.com/D6541 --- src/__phutil_library_map__.php | 1 + .../PhabricatorDaemonLogViewController.php | 178 +++++++++++++----- .../query/PhabricatorDaemonLogQuery.php | 13 ++ .../view/PhabricatorDaemonLogListView.php | 4 +- 4 files changed, 146 insertions(+), 50 deletions(-) create mode 100644 src/applications/daemon/query/PhabricatorDaemonLogQuery.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 45b3c763a9..359adc1d55 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1026,6 +1026,7 @@ phutil_register_library_map(array( 'PhabricatorDaemonLogEventsView' => 'applications/daemon/view/PhabricatorDaemonLogEventsView.php', 'PhabricatorDaemonLogListController' => 'applications/daemon/controller/PhabricatorDaemonLogListController.php', 'PhabricatorDaemonLogListView' => 'applications/daemon/view/PhabricatorDaemonLogListView.php', + 'PhabricatorDaemonLogQuery' => 'applications/daemon/query/PhabricatorDaemonLogQuery.php', 'PhabricatorDaemonLogViewController' => 'applications/daemon/controller/PhabricatorDaemonLogViewController.php', 'PhabricatorDaemonManagementDebugWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementDebugWorkflow.php', 'PhabricatorDaemonManagementLaunchWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementLaunchWorkflow.php', diff --git a/src/applications/daemon/controller/PhabricatorDaemonLogViewController.php b/src/applications/daemon/controller/PhabricatorDaemonLogViewController.php index d67128a3a2..1138172cfa 100644 --- a/src/applications/daemon/controller/PhabricatorDaemonLogViewController.php +++ b/src/applications/daemon/controller/PhabricatorDaemonLogViewController.php @@ -22,64 +22,146 @@ final class PhabricatorDaemonLogViewController 'logID = %d ORDER BY id DESC LIMIT 1000', $log->getID()); - $content = array(); + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addCrumb( + id(new PhabricatorCrumbView()) + ->setName(pht('Daemon %s', $log->getID()))); - $argv = $log->getArgv(); - if (is_array($argv)) { - $argv = implode("\n", $argv); + $header = id(new PhabricatorHeaderView()) + ->setHeader($log->getDaemon()); + + $tag = id(new PhabricatorTagView()) + ->setType(PhabricatorTagView::TYPE_STATE); + + $status = $log->getStatus(); + switch ($status) { + case PhabricatorDaemonLog::STATUS_UNKNOWN: + $tag->setBackgroundColor(PhabricatorTagView::COLOR_ORANGE); + $tag->setName(pht('Unknown')); + break; + case PhabricatorDaemonLog::STATUS_RUNNING: + $tag->setBackgroundColor(PhabricatorTagView::COLOR_GREEN); + $tag->setName(pht('Running')); + break; + case PhabricatorDaemonLog::STATUS_DEAD: + $tag->setBackgroundColor(PhabricatorTagView::COLOR_RED); + $tag->setName(pht('Dead')); + break; + case PhabricatorDaemonLog::STATUS_WAIT: + $tag->setBackgroundColor(PhabricatorTagView::COLOR_BLUE); + $tag->setName(pht('Waiting')); + break; + case PhabricatorDaemonLog::STATUS_EXITED: + $tag->setBackgroundColor(PhabricatorTagView::COLOR_GREY); + $tag->setName(pht('Exited')); + break; } - $form = id(new AphrontFormView()) + $header->addTag($tag); + + $properties = $this->buildPropertyListView($log); + + $event_view = id(new PhabricatorDaemonLogEventsView()) ->setUser($user) - ->appendChild( - id(new AphrontFormStaticControl()) - ->setLabel(pht('Daemon')) - ->setValue($log->getDaemon())) - ->appendChild( - id(new AphrontFormStaticControl()) - ->setLabel(pht('Host')) - ->setValue($log->getHost())) - ->appendChild( - id(new AphrontFormStaticControl()) - ->setLabel(pht('PID')) - ->setValue($log->getPID())) - ->appendChild( - id(new AphrontFormStaticControl()) - ->setLabel(pht('Started')) - ->setValue( - phabricator_datetime($log->getDateCreated(), $user))) - ->appendChild( - id(new AphrontFormTextAreaControl()) - ->setLabel(pht('Argv')) - ->setValue($argv)); + ->setEvents($events); - $panel = new AphrontPanelView(); - $panel->setHeader(pht('Daemon Details')); - $panel->setNoBackground(); - $panel->appendChild($form); - - $content[] = $panel; - - $event_view = new PhabricatorDaemonLogEventsView(); - $event_view->setUser($user); - $event_view->setEvents($events); - - $log_panel = new AphrontPanelView(); - $log_panel->setHeader(pht('Daemon Logs')); - $log_panel->setNoBackground(); - $log_panel->appendChild($event_view); - - $content[] = $log_panel; - - $nav = $this->buildSideNavView(); - $nav->selectFilter('log'); - $nav->appendChild($content); + $event_panel = new AphrontPanelView(); + $event_panel->setNoBackground(); + $event_panel->appendChild($event_view); return $this->buildApplicationPage( - $nav, + array( + $crumbs, + $header, + $properties, + $event_panel, + ), array( 'title' => pht('Daemon Log'), )); } + private function buildPropertyListView(PhabricatorDaemonLog $daemon) { + $request = $this->getRequest(); + $viewer = $request->getUser(); + + $view = id(new PhabricatorPropertyListView()) + ->setUser($viewer); + + $c_epoch = $daemon->getDateCreated(); + $u_epoch = $daemon->getDateModified(); + + $unknown_time = PhabricatorDaemonLogQuery::getTimeUntilUnknown(); + $dead_time = PhabricatorDaemonLogQuery::getTimeUntilDead(); + + $details = null; + $status = $daemon->getStatus(); + switch ($status) { + case PhabricatorDaemonLog::STATUS_RUNNING: + $details = pht( + 'This daemon is running normally and reported a status update '. + 'recently (within %s).', + phabricator_format_relative_time($unknown_time)); + break; + case PhabricatorDaemonLog::STATUS_UNKNOWN: + $details = pht( + 'This daemon has not reported a status update recently (within %s). '. + 'It may have exited abruptly. After %s, it will be presumed dead.', + phabricator_format_relative_time($unknown_time), + phabricator_format_relative_time($dead_time)); + break; + case PhabricatorDaemonLog::STATUS_DEAD: + $details = pht( + 'This daemon did not report a status update for %s. It is '. + 'presumed dead. Usually, this indicates that the daemon was '. + 'killed or otherwise exited abruptly with an error. You may '. + 'need to restart it.', + phabricator_format_relative_time($dead_time)); + break; + case PhabricatorDaemonLog::STATUS_WAIT: + $details = pht( + 'This daemon is running normally and reported a status update '. + 'recently (within %s). However, it encountered an error while '. + 'doing work and is waiting a little while to resume processing. '. + 'After encountering an error, daemons wait before resuming work '. + 'to avoid overloading services.', + phabricator_format_relative_time($unknown_time)); + break; + case PhabricatorDaemonLog::STATUS_EXITED: + $details = pht( + 'This daemon exited normally and is no longer running.'); + break; + } + + $view->addProperty(pht('Status Details'), $details); + + $view->addProperty(pht('Daemon Class'), $daemon->getDaemon()); + $view->addProperty(pht('Host'), $daemon->getHost()); + $view->addProperty(pht('PID'), $daemon->getPID()); + $view->addProperty(pht('Started'), phabricator_datetime($c_epoch, $viewer)); + $view->addProperty( + pht('Seen'), + pht( + '%s ago (%s)', + phabricator_format_relative_time(time() - $u_epoch), + phabricator_datetime($u_epoch, $viewer))); + + $argv = $daemon->getArgv(); + if (is_array($argv)) { + $argv = implode("\n", $argv); + } + + $view->addProperty( + pht('Argv'), + phutil_tag( + 'textarea', + array( + 'style' => 'width: 100%; height: 12em;', + ), + $argv)); + + + return $view; + } + } diff --git a/src/applications/daemon/query/PhabricatorDaemonLogQuery.php b/src/applications/daemon/query/PhabricatorDaemonLogQuery.php new file mode 100644 index 0000000000..45e56275a2 --- /dev/null +++ b/src/applications/daemon/query/PhabricatorDaemonLogQuery.php @@ -0,0 +1,13 @@ +