mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 13:22:42 +01:00
Add Drydock log types and more logging
Summary: Ref T9252. Make log types modular so they can be translated and have complicated rendering logic if necessary (currently, none have this). Test Plan: {F855330} Reviewers: chad Reviewed By: chad Maniphest Tasks: T9252 Differential Revision: https://secure.phabricator.com/D14198
This commit is contained in:
parent
06f9272502
commit
8bf5905024
11 changed files with 232 additions and 27 deletions
|
@ -830,14 +830,19 @@ phutil_register_library_map(array(
|
|||
'DrydockFilesystemInterface' => 'applications/drydock/interface/filesystem/DrydockFilesystemInterface.php',
|
||||
'DrydockInterface' => 'applications/drydock/interface/DrydockInterface.php',
|
||||
'DrydockLease' => 'applications/drydock/storage/DrydockLease.php',
|
||||
'DrydockLeaseAcquiredLogType' => 'applications/drydock/logtype/DrydockLeaseAcquiredLogType.php',
|
||||
'DrydockLeaseActivatedLogType' => 'applications/drydock/logtype/DrydockLeaseActivatedLogType.php',
|
||||
'DrydockLeaseController' => 'applications/drydock/controller/DrydockLeaseController.php',
|
||||
'DrydockLeaseDatasource' => 'applications/drydock/typeahead/DrydockLeaseDatasource.php',
|
||||
'DrydockLeaseDestroyWorker' => 'applications/drydock/worker/DrydockLeaseDestroyWorker.php',
|
||||
'DrydockLeaseDestroyedLogType' => 'applications/drydock/logtype/DrydockLeaseDestroyedLogType.php',
|
||||
'DrydockLeaseListController' => 'applications/drydock/controller/DrydockLeaseListController.php',
|
||||
'DrydockLeaseListView' => 'applications/drydock/view/DrydockLeaseListView.php',
|
||||
'DrydockLeasePHIDType' => 'applications/drydock/phid/DrydockLeasePHIDType.php',
|
||||
'DrydockLeaseQuery' => 'applications/drydock/query/DrydockLeaseQuery.php',
|
||||
'DrydockLeaseQueuedLogType' => 'applications/drydock/logtype/DrydockLeaseQueuedLogType.php',
|
||||
'DrydockLeaseReleaseController' => 'applications/drydock/controller/DrydockLeaseReleaseController.php',
|
||||
'DrydockLeaseReleasedLogType' => 'applications/drydock/logtype/DrydockLeaseReleasedLogType.php',
|
||||
'DrydockLeaseSearchEngine' => 'applications/drydock/query/DrydockLeaseSearchEngine.php',
|
||||
'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php',
|
||||
'DrydockLeaseUpdateWorker' => 'applications/drydock/worker/DrydockLeaseUpdateWorker.php',
|
||||
|
@ -850,6 +855,7 @@ phutil_register_library_map(array(
|
|||
'DrydockLogListView' => 'applications/drydock/view/DrydockLogListView.php',
|
||||
'DrydockLogQuery' => 'applications/drydock/query/DrydockLogQuery.php',
|
||||
'DrydockLogSearchEngine' => 'applications/drydock/query/DrydockLogSearchEngine.php',
|
||||
'DrydockLogType' => 'applications/drydock/logtype/DrydockLogType.php',
|
||||
'DrydockManagementCommandWorkflow' => 'applications/drydock/management/DrydockManagementCommandWorkflow.php',
|
||||
'DrydockManagementLeaseWorkflow' => 'applications/drydock/management/DrydockManagementLeaseWorkflow.php',
|
||||
'DrydockManagementReleaseLeaseWorkflow' => 'applications/drydock/management/DrydockManagementReleaseLeaseWorkflow.php',
|
||||
|
@ -4569,14 +4575,19 @@ phutil_register_library_map(array(
|
|||
'DrydockDAO',
|
||||
'PhabricatorPolicyInterface',
|
||||
),
|
||||
'DrydockLeaseAcquiredLogType' => 'DrydockLogType',
|
||||
'DrydockLeaseActivatedLogType' => 'DrydockLogType',
|
||||
'DrydockLeaseController' => 'DrydockController',
|
||||
'DrydockLeaseDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'DrydockLeaseDestroyWorker' => 'DrydockWorker',
|
||||
'DrydockLeaseDestroyedLogType' => 'DrydockLogType',
|
||||
'DrydockLeaseListController' => 'DrydockLeaseController',
|
||||
'DrydockLeaseListView' => 'AphrontView',
|
||||
'DrydockLeasePHIDType' => 'PhabricatorPHIDType',
|
||||
'DrydockLeaseQuery' => 'DrydockQuery',
|
||||
'DrydockLeaseQueuedLogType' => 'DrydockLogType',
|
||||
'DrydockLeaseReleaseController' => 'DrydockLeaseController',
|
||||
'DrydockLeaseReleasedLogType' => 'DrydockLogType',
|
||||
'DrydockLeaseSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'DrydockLeaseStatus' => 'DrydockConstants',
|
||||
'DrydockLeaseUpdateWorker' => 'DrydockWorker',
|
||||
|
@ -4592,6 +4603,7 @@ phutil_register_library_map(array(
|
|||
'DrydockLogListView' => 'AphrontView',
|
||||
'DrydockLogQuery' => 'DrydockQuery',
|
||||
'DrydockLogSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'DrydockLogType' => 'Phobject',
|
||||
'DrydockManagementCommandWorkflow' => 'DrydockManagementWorkflow',
|
||||
'DrydockManagementLeaseWorkflow' => 'DrydockManagementWorkflow',
|
||||
'DrydockManagementReleaseLeaseWorkflow' => 'DrydockManagementWorkflow',
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
final class DrydockLeaseAcquiredLogType extends DrydockLogType {
|
||||
|
||||
const LOGCONST = 'core.lease.acquired';
|
||||
|
||||
public function getLogTypeName() {
|
||||
return pht('Lease Acquired');
|
||||
}
|
||||
|
||||
public function getLogTypeIcon(array $data) {
|
||||
return 'fa-link yellow';
|
||||
}
|
||||
|
||||
public function renderLog(array $data) {
|
||||
return pht('Lease acquired.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
final class DrydockLeaseActivatedLogType extends DrydockLogType {
|
||||
|
||||
const LOGCONST = 'core.lease.activated';
|
||||
|
||||
public function getLogTypeName() {
|
||||
return pht('Lease Activated');
|
||||
}
|
||||
|
||||
public function getLogTypeIcon(array $data) {
|
||||
return 'fa-link green';
|
||||
}
|
||||
|
||||
public function renderLog(array $data) {
|
||||
return pht('Lease activated.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
final class DrydockLeaseDestroyedLogType extends DrydockLogType {
|
||||
|
||||
const LOGCONST = 'core.lease.destroyed';
|
||||
|
||||
public function getLogTypeName() {
|
||||
return pht('Lease Destroyed');
|
||||
}
|
||||
|
||||
public function getLogTypeIcon(array $data) {
|
||||
return 'fa-link grey';
|
||||
}
|
||||
|
||||
public function renderLog(array $data) {
|
||||
return pht('Lease destroyed.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
final class DrydockLeaseQueuedLogType extends DrydockLogType {
|
||||
|
||||
const LOGCONST = 'core.lease.queued';
|
||||
|
||||
public function getLogTypeName() {
|
||||
return pht('Lease Queued');
|
||||
}
|
||||
|
||||
public function getLogTypeIcon(array $data) {
|
||||
return 'fa-link blue';
|
||||
}
|
||||
|
||||
public function renderLog(array $data) {
|
||||
return pht('Lease queued for acquisition.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
final class DrydockLeaseReleasedLogType extends DrydockLogType {
|
||||
|
||||
const LOGCONST = 'core.lease.released';
|
||||
|
||||
public function getLogTypeName() {
|
||||
return pht('Lease Released');
|
||||
}
|
||||
|
||||
public function getLogTypeIcon(array $data) {
|
||||
return 'fa-link black';
|
||||
}
|
||||
|
||||
public function renderLog(array $data) {
|
||||
return pht('Lease released.');
|
||||
}
|
||||
|
||||
}
|
69
src/applications/drydock/logtype/DrydockLogType.php
Normal file
69
src/applications/drydock/logtype/DrydockLogType.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
abstract class DrydockLogType extends Phobject {
|
||||
|
||||
private $viewer;
|
||||
private $log;
|
||||
|
||||
abstract public function getLogTypeName();
|
||||
abstract public function getLogTypeIcon(array $data);
|
||||
abstract public function renderLog(array $data);
|
||||
|
||||
public function setViewer(PhabricatorUser $viewer) {
|
||||
$this->viewer = $viewer;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getViewer() {
|
||||
return $this->viewer;
|
||||
}
|
||||
|
||||
final public function setLog(DrydockLog $log) {
|
||||
$this->log = $log;
|
||||
return $this;
|
||||
}
|
||||
|
||||
final public function getLog() {
|
||||
return $this->log;
|
||||
}
|
||||
|
||||
final public function getLogTypeConstant() {
|
||||
$class = new ReflectionClass($this);
|
||||
|
||||
$const = $class->getConstant('LOGCONST');
|
||||
if ($const === false) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'"%s" class "%s" must define a "%s" property.',
|
||||
__CLASS__,
|
||||
get_class($this),
|
||||
'LOGCONST'));
|
||||
}
|
||||
|
||||
$limit = self::getLogTypeConstantByteLimit();
|
||||
if (!is_string($const) || (strlen($const) > $limit)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'"%s" class "%s" has an invalid "%s" property. Field constants '.
|
||||
'must be strings and no more than %s bytes in length.',
|
||||
__CLASS__,
|
||||
get_class($this),
|
||||
'LOGCONST',
|
||||
new PhutilNumber($limit)));
|
||||
}
|
||||
|
||||
return $const;
|
||||
}
|
||||
|
||||
final private static function getLogTypeConstantByteLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
final public static function getAllLogTypes() {
|
||||
return id(new PhutilClassMapQuery())
|
||||
->setAncestorClass(__CLASS__)
|
||||
->setUniqueMethod('getLogTypeConstant')
|
||||
->execute();
|
||||
}
|
||||
|
||||
}
|
|
@ -144,6 +144,8 @@ final class DrydockLease extends DrydockDAO
|
|||
'objectPHID' => $this->getPHID(),
|
||||
));
|
||||
|
||||
$this->logEvent(DrydockLeaseQueuedLogType::LOGCONST);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -240,6 +242,7 @@ final class DrydockLease extends DrydockDAO
|
|||
|
||||
$this
|
||||
->setResourcePHID($resource->getPHID())
|
||||
->attachResource($resource)
|
||||
->setStatus($new_status)
|
||||
->save();
|
||||
|
||||
|
@ -250,6 +253,8 @@ final class DrydockLease extends DrydockDAO
|
|||
|
||||
$this->isAcquired = true;
|
||||
|
||||
$this->logEvent(DrydockLeaseAcquiredLogType::LOGCONST);
|
||||
|
||||
if ($new_status == DrydockLeaseStatus::STATUS_ACTIVE) {
|
||||
$this->didActivate();
|
||||
}
|
||||
|
@ -347,8 +352,7 @@ final class DrydockLease extends DrydockDAO
|
|||
$viewer = PhabricatorUser::getOmnipotentUser();
|
||||
$need_update = false;
|
||||
|
||||
// TODO: This is just a placeholder to get some data in the table.
|
||||
$this->logEvent('activated');
|
||||
$this->logEvent(DrydockLeaseActivatedLogType::LOGCONST);
|
||||
|
||||
$commands = id(new DrydockCommandQuery())
|
||||
->setViewer($viewer)
|
||||
|
@ -382,8 +386,10 @@ final class DrydockLease extends DrydockDAO
|
|||
|
||||
$log->setLeasePHID($this->getPHID());
|
||||
|
||||
$resource = $this->getResource();
|
||||
if ($resource) {
|
||||
$resource_phid = $this->getResourcePHID();
|
||||
if ($resource_phid) {
|
||||
$resource = $this->getResource();
|
||||
|
||||
$log->setResourcePHID($resource->getPHID());
|
||||
$log->setBlueprintPHID($resource->getBlueprintPHID());
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ final class DrydockLogListView extends AphrontView {
|
|||
|
||||
$view = new PHUIObjectItemListView();
|
||||
|
||||
$types = DrydockLogType::getAllLogTypes();
|
||||
|
||||
$rows = array();
|
||||
foreach ($logs as $log) {
|
||||
$blueprint_phid = $log->getBlueprintPHID();
|
||||
|
@ -40,47 +42,64 @@ final class DrydockLogListView extends AphrontView {
|
|||
}
|
||||
|
||||
if ($log->isComplete()) {
|
||||
// TODO: This is a placeholder.
|
||||
$type = $log->getType();
|
||||
$data = print_r($log->getData(), true);
|
||||
$type_key = $log->getType();
|
||||
if (isset($types[$type_key])) {
|
||||
$type_object = id(clone $types[$type_key])
|
||||
->setLog($log)
|
||||
->setViewer($viewer);
|
||||
|
||||
$log_data = $log->getData();
|
||||
|
||||
$type = $type_object->getLogTypeName();
|
||||
$icon = $type_object->getLogTypeIcon($log_data);
|
||||
$data = $type_object->renderLog($log_data);
|
||||
} else {
|
||||
$type = pht('<Unknown: %s>', $type_key);
|
||||
$data = null;
|
||||
$icon = 'fa-question-circle red';
|
||||
}
|
||||
} else {
|
||||
$type = phutil_tag('em', array(), pht('Restricted'));
|
||||
$data = phutil_tag(
|
||||
'em',
|
||||
array(),
|
||||
pht('You do not have permission to view this log event.'));
|
||||
$icon = 'fa-lock grey';
|
||||
}
|
||||
|
||||
$rows[] = array(
|
||||
$blueprint,
|
||||
$resource,
|
||||
$lease,
|
||||
id(new PHUIIconView())->setIconFont($icon),
|
||||
$type,
|
||||
$data,
|
||||
phabricator_datetime($log->getEpoch(), $viewer),
|
||||
);
|
||||
}
|
||||
|
||||
$table = new AphrontTableView($rows);
|
||||
$table->setDeviceReadyTable(true);
|
||||
$table->setHeaders(
|
||||
array(
|
||||
pht('Blueprint'),
|
||||
pht('Resource'),
|
||||
pht('Lease'),
|
||||
pht('Type'),
|
||||
pht('Data'),
|
||||
pht('Date'),
|
||||
));
|
||||
$table->setColumnClasses(
|
||||
array(
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'wide',
|
||||
'',
|
||||
));
|
||||
$table = id(new AphrontTableView($rows))
|
||||
->setDeviceReadyTable(true)
|
||||
->setHeaders(
|
||||
array(
|
||||
pht('Blueprint'),
|
||||
pht('Resource'),
|
||||
pht('Lease'),
|
||||
null,
|
||||
pht('Type'),
|
||||
pht('Data'),
|
||||
pht('Date'),
|
||||
))
|
||||
->setColumnClasses(
|
||||
array(
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'icon',
|
||||
'',
|
||||
'wide',
|
||||
'',
|
||||
));
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ final class DrydockLeaseDestroyWorker extends DrydockWorker {
|
|||
$lease
|
||||
->setStatus(DrydockLeaseStatus::STATUS_DESTROYED)
|
||||
->save();
|
||||
|
||||
$lease->logEvent(DrydockLeaseDestroyedLogType::LOGCONST);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -74,6 +74,8 @@ final class DrydockLeaseUpdateWorker extends DrydockWorker {
|
|||
'objectPHID' => $lease->getPHID(),
|
||||
));
|
||||
|
||||
$lease->logEvent(DrydockLeaseReleasedLogType::LOGCONST);
|
||||
|
||||
$resource = $lease->getResource();
|
||||
$blueprint = $resource->getBlueprint();
|
||||
|
||||
|
|
Loading…
Reference in a new issue