mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +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',
|
'DrydockFilesystemInterface' => 'applications/drydock/interface/filesystem/DrydockFilesystemInterface.php',
|
||||||
'DrydockInterface' => 'applications/drydock/interface/DrydockInterface.php',
|
'DrydockInterface' => 'applications/drydock/interface/DrydockInterface.php',
|
||||||
'DrydockLease' => 'applications/drydock/storage/DrydockLease.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',
|
'DrydockLeaseController' => 'applications/drydock/controller/DrydockLeaseController.php',
|
||||||
'DrydockLeaseDatasource' => 'applications/drydock/typeahead/DrydockLeaseDatasource.php',
|
'DrydockLeaseDatasource' => 'applications/drydock/typeahead/DrydockLeaseDatasource.php',
|
||||||
'DrydockLeaseDestroyWorker' => 'applications/drydock/worker/DrydockLeaseDestroyWorker.php',
|
'DrydockLeaseDestroyWorker' => 'applications/drydock/worker/DrydockLeaseDestroyWorker.php',
|
||||||
|
'DrydockLeaseDestroyedLogType' => 'applications/drydock/logtype/DrydockLeaseDestroyedLogType.php',
|
||||||
'DrydockLeaseListController' => 'applications/drydock/controller/DrydockLeaseListController.php',
|
'DrydockLeaseListController' => 'applications/drydock/controller/DrydockLeaseListController.php',
|
||||||
'DrydockLeaseListView' => 'applications/drydock/view/DrydockLeaseListView.php',
|
'DrydockLeaseListView' => 'applications/drydock/view/DrydockLeaseListView.php',
|
||||||
'DrydockLeasePHIDType' => 'applications/drydock/phid/DrydockLeasePHIDType.php',
|
'DrydockLeasePHIDType' => 'applications/drydock/phid/DrydockLeasePHIDType.php',
|
||||||
'DrydockLeaseQuery' => 'applications/drydock/query/DrydockLeaseQuery.php',
|
'DrydockLeaseQuery' => 'applications/drydock/query/DrydockLeaseQuery.php',
|
||||||
|
'DrydockLeaseQueuedLogType' => 'applications/drydock/logtype/DrydockLeaseQueuedLogType.php',
|
||||||
'DrydockLeaseReleaseController' => 'applications/drydock/controller/DrydockLeaseReleaseController.php',
|
'DrydockLeaseReleaseController' => 'applications/drydock/controller/DrydockLeaseReleaseController.php',
|
||||||
|
'DrydockLeaseReleasedLogType' => 'applications/drydock/logtype/DrydockLeaseReleasedLogType.php',
|
||||||
'DrydockLeaseSearchEngine' => 'applications/drydock/query/DrydockLeaseSearchEngine.php',
|
'DrydockLeaseSearchEngine' => 'applications/drydock/query/DrydockLeaseSearchEngine.php',
|
||||||
'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php',
|
'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php',
|
||||||
'DrydockLeaseUpdateWorker' => 'applications/drydock/worker/DrydockLeaseUpdateWorker.php',
|
'DrydockLeaseUpdateWorker' => 'applications/drydock/worker/DrydockLeaseUpdateWorker.php',
|
||||||
|
@ -850,6 +855,7 @@ phutil_register_library_map(array(
|
||||||
'DrydockLogListView' => 'applications/drydock/view/DrydockLogListView.php',
|
'DrydockLogListView' => 'applications/drydock/view/DrydockLogListView.php',
|
||||||
'DrydockLogQuery' => 'applications/drydock/query/DrydockLogQuery.php',
|
'DrydockLogQuery' => 'applications/drydock/query/DrydockLogQuery.php',
|
||||||
'DrydockLogSearchEngine' => 'applications/drydock/query/DrydockLogSearchEngine.php',
|
'DrydockLogSearchEngine' => 'applications/drydock/query/DrydockLogSearchEngine.php',
|
||||||
|
'DrydockLogType' => 'applications/drydock/logtype/DrydockLogType.php',
|
||||||
'DrydockManagementCommandWorkflow' => 'applications/drydock/management/DrydockManagementCommandWorkflow.php',
|
'DrydockManagementCommandWorkflow' => 'applications/drydock/management/DrydockManagementCommandWorkflow.php',
|
||||||
'DrydockManagementLeaseWorkflow' => 'applications/drydock/management/DrydockManagementLeaseWorkflow.php',
|
'DrydockManagementLeaseWorkflow' => 'applications/drydock/management/DrydockManagementLeaseWorkflow.php',
|
||||||
'DrydockManagementReleaseLeaseWorkflow' => 'applications/drydock/management/DrydockManagementReleaseLeaseWorkflow.php',
|
'DrydockManagementReleaseLeaseWorkflow' => 'applications/drydock/management/DrydockManagementReleaseLeaseWorkflow.php',
|
||||||
|
@ -4569,14 +4575,19 @@ phutil_register_library_map(array(
|
||||||
'DrydockDAO',
|
'DrydockDAO',
|
||||||
'PhabricatorPolicyInterface',
|
'PhabricatorPolicyInterface',
|
||||||
),
|
),
|
||||||
|
'DrydockLeaseAcquiredLogType' => 'DrydockLogType',
|
||||||
|
'DrydockLeaseActivatedLogType' => 'DrydockLogType',
|
||||||
'DrydockLeaseController' => 'DrydockController',
|
'DrydockLeaseController' => 'DrydockController',
|
||||||
'DrydockLeaseDatasource' => 'PhabricatorTypeaheadDatasource',
|
'DrydockLeaseDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||||
'DrydockLeaseDestroyWorker' => 'DrydockWorker',
|
'DrydockLeaseDestroyWorker' => 'DrydockWorker',
|
||||||
|
'DrydockLeaseDestroyedLogType' => 'DrydockLogType',
|
||||||
'DrydockLeaseListController' => 'DrydockLeaseController',
|
'DrydockLeaseListController' => 'DrydockLeaseController',
|
||||||
'DrydockLeaseListView' => 'AphrontView',
|
'DrydockLeaseListView' => 'AphrontView',
|
||||||
'DrydockLeasePHIDType' => 'PhabricatorPHIDType',
|
'DrydockLeasePHIDType' => 'PhabricatorPHIDType',
|
||||||
'DrydockLeaseQuery' => 'DrydockQuery',
|
'DrydockLeaseQuery' => 'DrydockQuery',
|
||||||
|
'DrydockLeaseQueuedLogType' => 'DrydockLogType',
|
||||||
'DrydockLeaseReleaseController' => 'DrydockLeaseController',
|
'DrydockLeaseReleaseController' => 'DrydockLeaseController',
|
||||||
|
'DrydockLeaseReleasedLogType' => 'DrydockLogType',
|
||||||
'DrydockLeaseSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'DrydockLeaseSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'DrydockLeaseStatus' => 'DrydockConstants',
|
'DrydockLeaseStatus' => 'DrydockConstants',
|
||||||
'DrydockLeaseUpdateWorker' => 'DrydockWorker',
|
'DrydockLeaseUpdateWorker' => 'DrydockWorker',
|
||||||
|
@ -4592,6 +4603,7 @@ phutil_register_library_map(array(
|
||||||
'DrydockLogListView' => 'AphrontView',
|
'DrydockLogListView' => 'AphrontView',
|
||||||
'DrydockLogQuery' => 'DrydockQuery',
|
'DrydockLogQuery' => 'DrydockQuery',
|
||||||
'DrydockLogSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'DrydockLogSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
|
'DrydockLogType' => 'Phobject',
|
||||||
'DrydockManagementCommandWorkflow' => 'DrydockManagementWorkflow',
|
'DrydockManagementCommandWorkflow' => 'DrydockManagementWorkflow',
|
||||||
'DrydockManagementLeaseWorkflow' => 'DrydockManagementWorkflow',
|
'DrydockManagementLeaseWorkflow' => 'DrydockManagementWorkflow',
|
||||||
'DrydockManagementReleaseLeaseWorkflow' => '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(),
|
'objectPHID' => $this->getPHID(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$this->logEvent(DrydockLeaseQueuedLogType::LOGCONST);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,6 +242,7 @@ final class DrydockLease extends DrydockDAO
|
||||||
|
|
||||||
$this
|
$this
|
||||||
->setResourcePHID($resource->getPHID())
|
->setResourcePHID($resource->getPHID())
|
||||||
|
->attachResource($resource)
|
||||||
->setStatus($new_status)
|
->setStatus($new_status)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
|
@ -250,6 +253,8 @@ final class DrydockLease extends DrydockDAO
|
||||||
|
|
||||||
$this->isAcquired = true;
|
$this->isAcquired = true;
|
||||||
|
|
||||||
|
$this->logEvent(DrydockLeaseAcquiredLogType::LOGCONST);
|
||||||
|
|
||||||
if ($new_status == DrydockLeaseStatus::STATUS_ACTIVE) {
|
if ($new_status == DrydockLeaseStatus::STATUS_ACTIVE) {
|
||||||
$this->didActivate();
|
$this->didActivate();
|
||||||
}
|
}
|
||||||
|
@ -347,8 +352,7 @@ final class DrydockLease extends DrydockDAO
|
||||||
$viewer = PhabricatorUser::getOmnipotentUser();
|
$viewer = PhabricatorUser::getOmnipotentUser();
|
||||||
$need_update = false;
|
$need_update = false;
|
||||||
|
|
||||||
// TODO: This is just a placeholder to get some data in the table.
|
$this->logEvent(DrydockLeaseActivatedLogType::LOGCONST);
|
||||||
$this->logEvent('activated');
|
|
||||||
|
|
||||||
$commands = id(new DrydockCommandQuery())
|
$commands = id(new DrydockCommandQuery())
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
|
@ -382,8 +386,10 @@ final class DrydockLease extends DrydockDAO
|
||||||
|
|
||||||
$log->setLeasePHID($this->getPHID());
|
$log->setLeasePHID($this->getPHID());
|
||||||
|
|
||||||
$resource = $this->getResource();
|
$resource_phid = $this->getResourcePHID();
|
||||||
if ($resource) {
|
if ($resource_phid) {
|
||||||
|
$resource = $this->getResource();
|
||||||
|
|
||||||
$log->setResourcePHID($resource->getPHID());
|
$log->setResourcePHID($resource->getPHID());
|
||||||
$log->setBlueprintPHID($resource->getBlueprintPHID());
|
$log->setBlueprintPHID($resource->getBlueprintPHID());
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ final class DrydockLogListView extends AphrontView {
|
||||||
|
|
||||||
$view = new PHUIObjectItemListView();
|
$view = new PHUIObjectItemListView();
|
||||||
|
|
||||||
|
$types = DrydockLogType::getAllLogTypes();
|
||||||
|
|
||||||
$rows = array();
|
$rows = array();
|
||||||
foreach ($logs as $log) {
|
foreach ($logs as $log) {
|
||||||
$blueprint_phid = $log->getBlueprintPHID();
|
$blueprint_phid = $log->getBlueprintPHID();
|
||||||
|
@ -40,47 +42,64 @@ final class DrydockLogListView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($log->isComplete()) {
|
if ($log->isComplete()) {
|
||||||
// TODO: This is a placeholder.
|
$type_key = $log->getType();
|
||||||
$type = $log->getType();
|
if (isset($types[$type_key])) {
|
||||||
$data = print_r($log->getData(), true);
|
$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 {
|
} else {
|
||||||
$type = phutil_tag('em', array(), pht('Restricted'));
|
$type = phutil_tag('em', array(), pht('Restricted'));
|
||||||
$data = phutil_tag(
|
$data = phutil_tag(
|
||||||
'em',
|
'em',
|
||||||
array(),
|
array(),
|
||||||
pht('You do not have permission to view this log event.'));
|
pht('You do not have permission to view this log event.'));
|
||||||
|
$icon = 'fa-lock grey';
|
||||||
}
|
}
|
||||||
|
|
||||||
$rows[] = array(
|
$rows[] = array(
|
||||||
$blueprint,
|
$blueprint,
|
||||||
$resource,
|
$resource,
|
||||||
$lease,
|
$lease,
|
||||||
|
id(new PHUIIconView())->setIconFont($icon),
|
||||||
$type,
|
$type,
|
||||||
$data,
|
$data,
|
||||||
phabricator_datetime($log->getEpoch(), $viewer),
|
phabricator_datetime($log->getEpoch(), $viewer),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$table = new AphrontTableView($rows);
|
$table = id(new AphrontTableView($rows))
|
||||||
$table->setDeviceReadyTable(true);
|
->setDeviceReadyTable(true)
|
||||||
$table->setHeaders(
|
->setHeaders(
|
||||||
array(
|
array(
|
||||||
pht('Blueprint'),
|
pht('Blueprint'),
|
||||||
pht('Resource'),
|
pht('Resource'),
|
||||||
pht('Lease'),
|
pht('Lease'),
|
||||||
pht('Type'),
|
null,
|
||||||
pht('Data'),
|
pht('Type'),
|
||||||
pht('Date'),
|
pht('Data'),
|
||||||
));
|
pht('Date'),
|
||||||
$table->setColumnClasses(
|
))
|
||||||
array(
|
->setColumnClasses(
|
||||||
'',
|
array(
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'wide',
|
'icon',
|
||||||
'',
|
'',
|
||||||
));
|
'wide',
|
||||||
|
'',
|
||||||
|
));
|
||||||
|
|
||||||
return $table;
|
return $table;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@ final class DrydockLeaseDestroyWorker extends DrydockWorker {
|
||||||
$lease
|
$lease
|
||||||
->setStatus(DrydockLeaseStatus::STATUS_DESTROYED)
|
->setStatus(DrydockLeaseStatus::STATUS_DESTROYED)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
|
$lease->logEvent(DrydockLeaseDestroyedLogType::LOGCONST);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,8 @@ final class DrydockLeaseUpdateWorker extends DrydockWorker {
|
||||||
'objectPHID' => $lease->getPHID(),
|
'objectPHID' => $lease->getPHID(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$lease->logEvent(DrydockLeaseReleasedLogType::LOGCONST);
|
||||||
|
|
||||||
$resource = $lease->getResource();
|
$resource = $lease->getResource();
|
||||||
$blueprint = $resource->getBlueprint();
|
$blueprint = $resource->getBlueprint();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue