Page MenuHomePhabricator

D14198.id34295.diff
No OneTemporary

D14198.id34295.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -830,14 +830,19 @@
'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 @@
'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 @@
'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 @@
'DrydockLogListView' => 'AphrontView',
'DrydockLogQuery' => 'DrydockQuery',
'DrydockLogSearchEngine' => 'PhabricatorApplicationSearchEngine',
+ 'DrydockLogType' => 'Phobject',
'DrydockManagementCommandWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementLeaseWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementReleaseLeaseWorkflow' => 'DrydockManagementWorkflow',
diff --git a/src/applications/drydock/logtype/DrydockLeaseAcquiredLogType.php b/src/applications/drydock/logtype/DrydockLeaseAcquiredLogType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/logtype/DrydockLeaseAcquiredLogType.php
@@ -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.');
+ }
+
+}
diff --git a/src/applications/drydock/logtype/DrydockLeaseActivatedLogType.php b/src/applications/drydock/logtype/DrydockLeaseActivatedLogType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/logtype/DrydockLeaseActivatedLogType.php
@@ -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.');
+ }
+
+}
diff --git a/src/applications/drydock/logtype/DrydockLeaseDestroyedLogType.php b/src/applications/drydock/logtype/DrydockLeaseDestroyedLogType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/logtype/DrydockLeaseDestroyedLogType.php
@@ -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.');
+ }
+
+}
diff --git a/src/applications/drydock/logtype/DrydockLeaseQueuedLogType.php b/src/applications/drydock/logtype/DrydockLeaseQueuedLogType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/logtype/DrydockLeaseQueuedLogType.php
@@ -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.');
+ }
+
+}
diff --git a/src/applications/drydock/logtype/DrydockLeaseReleasedLogType.php b/src/applications/drydock/logtype/DrydockLeaseReleasedLogType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/logtype/DrydockLeaseReleasedLogType.php
@@ -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.');
+ }
+
+}
diff --git a/src/applications/drydock/logtype/DrydockLogType.php b/src/applications/drydock/logtype/DrydockLogType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/logtype/DrydockLogType.php
@@ -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();
+ }
+
+}
diff --git a/src/applications/drydock/storage/DrydockLease.php b/src/applications/drydock/storage/DrydockLease.php
--- a/src/applications/drydock/storage/DrydockLease.php
+++ b/src/applications/drydock/storage/DrydockLease.php
@@ -144,6 +144,8 @@
'objectPHID' => $this->getPHID(),
));
+ $this->logEvent(DrydockLeaseQueuedLogType::LOGCONST);
+
return $this;
}
@@ -240,6 +242,7 @@
$this
->setResourcePHID($resource->getPHID())
+ ->attachResource($resource)
->setStatus($new_status)
->save();
@@ -250,6 +253,8 @@
$this->isAcquired = true;
+ $this->logEvent(DrydockLeaseAcquiredLogType::LOGCONST);
+
if ($new_status == DrydockLeaseStatus::STATUS_ACTIVE) {
$this->didActivate();
}
@@ -347,8 +352,7 @@
$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 @@
$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());
}
diff --git a/src/applications/drydock/view/DrydockLogListView.php b/src/applications/drydock/view/DrydockLogListView.php
--- a/src/applications/drydock/view/DrydockLogListView.php
+++ b/src/applications/drydock/view/DrydockLogListView.php
@@ -16,6 +16,8 @@
$view = new PHUIObjectItemListView();
+ $types = DrydockLogType::getAllLogTypes();
+
$rows = array();
foreach ($logs as $log) {
$blueprint_phid = $log->getBlueprintPHID();
@@ -40,47 +42,64 @@
}
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;
}
diff --git a/src/applications/drydock/worker/DrydockLeaseDestroyWorker.php b/src/applications/drydock/worker/DrydockLeaseDestroyWorker.php
--- a/src/applications/drydock/worker/DrydockLeaseDestroyWorker.php
+++ b/src/applications/drydock/worker/DrydockLeaseDestroyWorker.php
@@ -32,6 +32,8 @@
$lease
->setStatus(DrydockLeaseStatus::STATUS_DESTROYED)
->save();
+
+ $lease->logEvent(DrydockLeaseDestroyedLogType::LOGCONST);
}
}
diff --git a/src/applications/drydock/worker/DrydockLeaseUpdateWorker.php b/src/applications/drydock/worker/DrydockLeaseUpdateWorker.php
--- a/src/applications/drydock/worker/DrydockLeaseUpdateWorker.php
+++ b/src/applications/drydock/worker/DrydockLeaseUpdateWorker.php
@@ -74,6 +74,8 @@
'objectPHID' => $lease->getPHID(),
));
+ $lease->logEvent(DrydockLeaseReleasedLogType::LOGCONST);
+
$resource = $lease->getResource();
$blueprint = $resource->getBlueprint();

File Metadata

Mime Type
text/plain
Expires
Fri, Sep 20, 2:35 PM (17 h, 43 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6621631
Default Alt Text
D14198.id34295.diff (13 KB)

Event Timeline