Skip to content
This repository was archived by the owner on Apr 7, 2022. It is now read-only.

Commit 8bf5905

Browse files
author
epriestley
committed
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
1 parent 06f9272 commit 8bf5905

11 files changed

+232
-27
lines changed

src/__phutil_library_map__.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,14 +830,19 @@
830830
'DrydockFilesystemInterface' => 'applications/drydock/interface/filesystem/DrydockFilesystemInterface.php',
831831
'DrydockInterface' => 'applications/drydock/interface/DrydockInterface.php',
832832
'DrydockLease' => 'applications/drydock/storage/DrydockLease.php',
833+
'DrydockLeaseAcquiredLogType' => 'applications/drydock/logtype/DrydockLeaseAcquiredLogType.php',
834+
'DrydockLeaseActivatedLogType' => 'applications/drydock/logtype/DrydockLeaseActivatedLogType.php',
833835
'DrydockLeaseController' => 'applications/drydock/controller/DrydockLeaseController.php',
834836
'DrydockLeaseDatasource' => 'applications/drydock/typeahead/DrydockLeaseDatasource.php',
835837
'DrydockLeaseDestroyWorker' => 'applications/drydock/worker/DrydockLeaseDestroyWorker.php',
838+
'DrydockLeaseDestroyedLogType' => 'applications/drydock/logtype/DrydockLeaseDestroyedLogType.php',
836839
'DrydockLeaseListController' => 'applications/drydock/controller/DrydockLeaseListController.php',
837840
'DrydockLeaseListView' => 'applications/drydock/view/DrydockLeaseListView.php',
838841
'DrydockLeasePHIDType' => 'applications/drydock/phid/DrydockLeasePHIDType.php',
839842
'DrydockLeaseQuery' => 'applications/drydock/query/DrydockLeaseQuery.php',
843+
'DrydockLeaseQueuedLogType' => 'applications/drydock/logtype/DrydockLeaseQueuedLogType.php',
840844
'DrydockLeaseReleaseController' => 'applications/drydock/controller/DrydockLeaseReleaseController.php',
845+
'DrydockLeaseReleasedLogType' => 'applications/drydock/logtype/DrydockLeaseReleasedLogType.php',
841846
'DrydockLeaseSearchEngine' => 'applications/drydock/query/DrydockLeaseSearchEngine.php',
842847
'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php',
843848
'DrydockLeaseUpdateWorker' => 'applications/drydock/worker/DrydockLeaseUpdateWorker.php',
@@ -850,6 +855,7 @@
850855
'DrydockLogListView' => 'applications/drydock/view/DrydockLogListView.php',
851856
'DrydockLogQuery' => 'applications/drydock/query/DrydockLogQuery.php',
852857
'DrydockLogSearchEngine' => 'applications/drydock/query/DrydockLogSearchEngine.php',
858+
'DrydockLogType' => 'applications/drydock/logtype/DrydockLogType.php',
853859
'DrydockManagementCommandWorkflow' => 'applications/drydock/management/DrydockManagementCommandWorkflow.php',
854860
'DrydockManagementLeaseWorkflow' => 'applications/drydock/management/DrydockManagementLeaseWorkflow.php',
855861
'DrydockManagementReleaseLeaseWorkflow' => 'applications/drydock/management/DrydockManagementReleaseLeaseWorkflow.php',
@@ -4569,14 +4575,19 @@
45694575
'DrydockDAO',
45704576
'PhabricatorPolicyInterface',
45714577
),
4578+
'DrydockLeaseAcquiredLogType' => 'DrydockLogType',
4579+
'DrydockLeaseActivatedLogType' => 'DrydockLogType',
45724580
'DrydockLeaseController' => 'DrydockController',
45734581
'DrydockLeaseDatasource' => 'PhabricatorTypeaheadDatasource',
45744582
'DrydockLeaseDestroyWorker' => 'DrydockWorker',
4583+
'DrydockLeaseDestroyedLogType' => 'DrydockLogType',
45754584
'DrydockLeaseListController' => 'DrydockLeaseController',
45764585
'DrydockLeaseListView' => 'AphrontView',
45774586
'DrydockLeasePHIDType' => 'PhabricatorPHIDType',
45784587
'DrydockLeaseQuery' => 'DrydockQuery',
4588+
'DrydockLeaseQueuedLogType' => 'DrydockLogType',
45794589
'DrydockLeaseReleaseController' => 'DrydockLeaseController',
4590+
'DrydockLeaseReleasedLogType' => 'DrydockLogType',
45804591
'DrydockLeaseSearchEngine' => 'PhabricatorApplicationSearchEngine',
45814592
'DrydockLeaseStatus' => 'DrydockConstants',
45824593
'DrydockLeaseUpdateWorker' => 'DrydockWorker',
@@ -4592,6 +4603,7 @@
45924603
'DrydockLogListView' => 'AphrontView',
45934604
'DrydockLogQuery' => 'DrydockQuery',
45944605
'DrydockLogSearchEngine' => 'PhabricatorApplicationSearchEngine',
4606+
'DrydockLogType' => 'Phobject',
45954607
'DrydockManagementCommandWorkflow' => 'DrydockManagementWorkflow',
45964608
'DrydockManagementLeaseWorkflow' => 'DrydockManagementWorkflow',
45974609
'DrydockManagementReleaseLeaseWorkflow' => 'DrydockManagementWorkflow',
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
final class DrydockLeaseAcquiredLogType extends DrydockLogType {
4+
5+
const LOGCONST = 'core.lease.acquired';
6+
7+
public function getLogTypeName() {
8+
return pht('Lease Acquired');
9+
}
10+
11+
public function getLogTypeIcon(array $data) {
12+
return 'fa-link yellow';
13+
}
14+
15+
public function renderLog(array $data) {
16+
return pht('Lease acquired.');
17+
}
18+
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
final class DrydockLeaseActivatedLogType extends DrydockLogType {
4+
5+
const LOGCONST = 'core.lease.activated';
6+
7+
public function getLogTypeName() {
8+
return pht('Lease Activated');
9+
}
10+
11+
public function getLogTypeIcon(array $data) {
12+
return 'fa-link green';
13+
}
14+
15+
public function renderLog(array $data) {
16+
return pht('Lease activated.');
17+
}
18+
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
final class DrydockLeaseDestroyedLogType extends DrydockLogType {
4+
5+
const LOGCONST = 'core.lease.destroyed';
6+
7+
public function getLogTypeName() {
8+
return pht('Lease Destroyed');
9+
}
10+
11+
public function getLogTypeIcon(array $data) {
12+
return 'fa-link grey';
13+
}
14+
15+
public function renderLog(array $data) {
16+
return pht('Lease destroyed.');
17+
}
18+
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
final class DrydockLeaseQueuedLogType extends DrydockLogType {
4+
5+
const LOGCONST = 'core.lease.queued';
6+
7+
public function getLogTypeName() {
8+
return pht('Lease Queued');
9+
}
10+
11+
public function getLogTypeIcon(array $data) {
12+
return 'fa-link blue';
13+
}
14+
15+
public function renderLog(array $data) {
16+
return pht('Lease queued for acquisition.');
17+
}
18+
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
final class DrydockLeaseReleasedLogType extends DrydockLogType {
4+
5+
const LOGCONST = 'core.lease.released';
6+
7+
public function getLogTypeName() {
8+
return pht('Lease Released');
9+
}
10+
11+
public function getLogTypeIcon(array $data) {
12+
return 'fa-link black';
13+
}
14+
15+
public function renderLog(array $data) {
16+
return pht('Lease released.');
17+
}
18+
19+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
abstract class DrydockLogType extends Phobject {
4+
5+
private $viewer;
6+
private $log;
7+
8+
abstract public function getLogTypeName();
9+
abstract public function getLogTypeIcon(array $data);
10+
abstract public function renderLog(array $data);
11+
12+
public function setViewer(PhabricatorUser $viewer) {
13+
$this->viewer = $viewer;
14+
return $this;
15+
}
16+
17+
public function getViewer() {
18+
return $this->viewer;
19+
}
20+
21+
final public function setLog(DrydockLog $log) {
22+
$this->log = $log;
23+
return $this;
24+
}
25+
26+
final public function getLog() {
27+
return $this->log;
28+
}
29+
30+
final public function getLogTypeConstant() {
31+
$class = new ReflectionClass($this);
32+
33+
$const = $class->getConstant('LOGCONST');
34+
if ($const === false) {
35+
throw new Exception(
36+
pht(
37+
'"%s" class "%s" must define a "%s" property.',
38+
__CLASS__,
39+
get_class($this),
40+
'LOGCONST'));
41+
}
42+
43+
$limit = self::getLogTypeConstantByteLimit();
44+
if (!is_string($const) || (strlen($const) > $limit)) {
45+
throw new Exception(
46+
pht(
47+
'"%s" class "%s" has an invalid "%s" property. Field constants '.
48+
'must be strings and no more than %s bytes in length.',
49+
__CLASS__,
50+
get_class($this),
51+
'LOGCONST',
52+
new PhutilNumber($limit)));
53+
}
54+
55+
return $const;
56+
}
57+
58+
final private static function getLogTypeConstantByteLimit() {
59+
return 64;
60+
}
61+
62+
final public static function getAllLogTypes() {
63+
return id(new PhutilClassMapQuery())
64+
->setAncestorClass(__CLASS__)
65+
->setUniqueMethod('getLogTypeConstant')
66+
->execute();
67+
}
68+
69+
}

src/applications/drydock/storage/DrydockLease.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public function queueForActivation() {
144144
'objectPHID' => $this->getPHID(),
145145
));
146146

147+
$this->logEvent(DrydockLeaseQueuedLogType::LOGCONST);
148+
147149
return $this;
148150
}
149151

@@ -240,6 +242,7 @@ public function acquireOnResource(DrydockResource $resource) {
240242

241243
$this
242244
->setResourcePHID($resource->getPHID())
245+
->attachResource($resource)
243246
->setStatus($new_status)
244247
->save();
245248

@@ -250,6 +253,8 @@ public function acquireOnResource(DrydockResource $resource) {
250253

251254
$this->isAcquired = true;
252255

256+
$this->logEvent(DrydockLeaseAcquiredLogType::LOGCONST);
257+
253258
if ($new_status == DrydockLeaseStatus::STATUS_ACTIVE) {
254259
$this->didActivate();
255260
}
@@ -347,8 +352,7 @@ private function didActivate() {
347352
$viewer = PhabricatorUser::getOmnipotentUser();
348353
$need_update = false;
349354

350-
// TODO: This is just a placeholder to get some data in the table.
351-
$this->logEvent('activated');
355+
$this->logEvent(DrydockLeaseActivatedLogType::LOGCONST);
352356

353357
$commands = id(new DrydockCommandQuery())
354358
->setViewer($viewer)
@@ -382,8 +386,10 @@ public function logEvent($type, array $data = array()) {
382386

383387
$log->setLeasePHID($this->getPHID());
384388

385-
$resource = $this->getResource();
386-
if ($resource) {
389+
$resource_phid = $this->getResourcePHID();
390+
if ($resource_phid) {
391+
$resource = $this->getResource();
392+
387393
$log->setResourcePHID($resource->getPHID());
388394
$log->setBlueprintPHID($resource->getBlueprintPHID());
389395
}

src/applications/drydock/view/DrydockLogListView.php

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public function render() {
1616

1717
$view = new PHUIObjectItemListView();
1818

19+
$types = DrydockLogType::getAllLogTypes();
20+
1921
$rows = array();
2022
foreach ($logs as $log) {
2123
$blueprint_phid = $log->getBlueprintPHID();
@@ -40,47 +42,64 @@ public function render() {
4042
}
4143

4244
if ($log->isComplete()) {
43-
// TODO: This is a placeholder.
44-
$type = $log->getType();
45-
$data = print_r($log->getData(), true);
45+
$type_key = $log->getType();
46+
if (isset($types[$type_key])) {
47+
$type_object = id(clone $types[$type_key])
48+
->setLog($log)
49+
->setViewer($viewer);
50+
51+
$log_data = $log->getData();
52+
53+
$type = $type_object->getLogTypeName();
54+
$icon = $type_object->getLogTypeIcon($log_data);
55+
$data = $type_object->renderLog($log_data);
56+
} else {
57+
$type = pht('<Unknown: %s>', $type_key);
58+
$data = null;
59+
$icon = 'fa-question-circle red';
60+
}
4661
} else {
4762
$type = phutil_tag('em', array(), pht('Restricted'));
4863
$data = phutil_tag(
4964
'em',
5065
array(),
5166
pht('You do not have permission to view this log event.'));
67+
$icon = 'fa-lock grey';
5268
}
5369

5470
$rows[] = array(
5571
$blueprint,
5672
$resource,
5773
$lease,
74+
id(new PHUIIconView())->setIconFont($icon),
5875
$type,
5976
$data,
6077
phabricator_datetime($log->getEpoch(), $viewer),
6178
);
6279
}
6380

64-
$table = new AphrontTableView($rows);
65-
$table->setDeviceReadyTable(true);
66-
$table->setHeaders(
67-
array(
68-
pht('Blueprint'),
69-
pht('Resource'),
70-
pht('Lease'),
71-
pht('Type'),
72-
pht('Data'),
73-
pht('Date'),
74-
));
75-
$table->setColumnClasses(
76-
array(
77-
'',
78-
'',
79-
'',
80-
'',
81-
'wide',
82-
'',
83-
));
81+
$table = id(new AphrontTableView($rows))
82+
->setDeviceReadyTable(true)
83+
->setHeaders(
84+
array(
85+
pht('Blueprint'),
86+
pht('Resource'),
87+
pht('Lease'),
88+
null,
89+
pht('Type'),
90+
pht('Data'),
91+
pht('Date'),
92+
))
93+
->setColumnClasses(
94+
array(
95+
'',
96+
'',
97+
'',
98+
'icon',
99+
'',
100+
'wide',
101+
'',
102+
));
84103

85104
return $table;
86105
}

src/applications/drydock/worker/DrydockLeaseDestroyWorker.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ private function destroyLease(DrydockLease $lease) {
3232
$lease
3333
->setStatus(DrydockLeaseStatus::STATUS_DESTROYED)
3434
->save();
35+
36+
$lease->logEvent(DrydockLeaseDestroyedLogType::LOGCONST);
3537
}
3638

3739
}

0 commit comments

Comments
 (0)