diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 804147e248..f07f29299e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/drydock/logtype/DrydockLeaseAcquiredLogType.php b/src/applications/drydock/logtype/DrydockLeaseAcquiredLogType.php new file mode 100644 index 0000000000..c9eef61922 --- /dev/null +++ b/src/applications/drydock/logtype/DrydockLeaseAcquiredLogType.php @@ -0,0 +1,19 @@ +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 index b16efbabbb..1dc9f0e180 100644 --- a/src/applications/drydock/storage/DrydockLease.php +++ b/src/applications/drydock/storage/DrydockLease.php @@ -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()); } diff --git a/src/applications/drydock/view/DrydockLogListView.php b/src/applications/drydock/view/DrydockLogListView.php index f6560270a0..4e1fe664cd 100644 --- a/src/applications/drydock/view/DrydockLogListView.php +++ b/src/applications/drydock/view/DrydockLogListView.php @@ -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('', $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 index e0b15095c7..12b9aa5a35 100644 --- a/src/applications/drydock/worker/DrydockLeaseDestroyWorker.php +++ b/src/applications/drydock/worker/DrydockLeaseDestroyWorker.php @@ -32,6 +32,8 @@ final class DrydockLeaseDestroyWorker extends DrydockWorker { $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 index 8f15201a2c..2003372b76 100644 --- a/src/applications/drydock/worker/DrydockLeaseUpdateWorker.php +++ b/src/applications/drydock/worker/DrydockLeaseUpdateWorker.php @@ -74,6 +74,8 @@ final class DrydockLeaseUpdateWorker extends DrydockWorker { 'objectPHID' => $lease->getPHID(), )); + $lease->logEvent(DrydockLeaseReleasedLogType::LOGCONST); + $resource = $lease->getResource(); $blueprint = $resource->getBlueprint();