Page MenuHomePhabricator

D10892.id26165.diff
No OneTemporary

D10892.id26165.diff

diff --git a/resources/sql/autopatches/20140917.drydocklogblueprint.1.sql b/resources/sql/autopatches/20140917.drydocklogblueprint.1.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20140917.drydocklogblueprint.1.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_drydock.drydock_log
+ ADD blueprintPHID VARCHAR(64) NULL COLLATE utf8_bin;
diff --git a/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php b/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php
--- a/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php
+++ b/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php
@@ -344,6 +344,7 @@
if ($context->getCurrentResourceLeaseCount() === 0) {
if ($this->shouldCloseUnleasedResource($context, $resource)) {
DrydockBlueprintImplementation::writeLog(
+ $this->instance,
$resource,
null,
pht('Closing resource because it has no more active leases'));
@@ -424,7 +425,11 @@
$lease->setStatus(DrydockLeaseStatus::STATUS_RELEASED);
break;
}
- DrydockBlueprintImplementation::writeLog($resource, $lease, $message);
+ DrydockBlueprintImplementation::writeLog(
+ $this->instance,
+ $resource,
+ $lease,
+ $message);
$lease->save();
}
@@ -475,6 +480,7 @@
*/
protected function log($message) {
self::writeLog(
+ $this->instance,
$this->activeResource,
$this->activeLease,
$message);
@@ -485,6 +491,7 @@
* @task log
*/
public static function writeLog(
+ DrydockBlueprint $blueprint = null,
DrydockResource $resource = null,
DrydockLease $lease = null,
$message) {
@@ -493,6 +500,10 @@
->setEpoch(time())
->setMessage($message);
+ if ($blueprint) {
+ $log->setBlueprintPHID($blueprint->getPHID());
+ }
+
if ($resource) {
$log->setResourceID($resource->getID());
}
diff --git a/src/applications/drydock/query/DrydockLogQuery.php b/src/applications/drydock/query/DrydockLogQuery.php
--- a/src/applications/drydock/query/DrydockLogQuery.php
+++ b/src/applications/drydock/query/DrydockLogQuery.php
@@ -31,6 +31,30 @@
}
public function willFilterPage(array $logs) {
+ $blueprint_phids = array_filter(mpull($logs, 'getBlueprintPHID'));
+ if ($blueprint_phids) {
+ $blueprints = id(new DrydockBlueprintQuery())
+ ->setParentQuery($this)
+ ->setViewer($this->getViewer())
+ ->withPHIDs($blueprint_phids)
+ ->execute();
+ $blueprints = mpull($blueprints, null, 'getPHID');
+ } else {
+ $blueprints = array();
+ }
+
+ foreach ($logs as $key => $log) {
+ $blueprint = null;
+ if ($log->getBlueprintPHID()) {
+ $blueprint = idx($blueprints, $log->getBlueprintPHID());
+ if (!$blueprint) {
+ unset($logs[$key]);
+ continue;
+ }
+ }
+ $log->attachBlueprint($blueprint);
+ }
+
$resource_ids = array_filter(mpull($logs, 'getResourceID'));
if ($resource_ids) {
$resources = id(new DrydockResourceQuery())
@@ -47,7 +71,7 @@
if ($log->getResourceID()) {
$resource = idx($resources, $log->getResourceID());
if (!$resource) {
- unset($logs[$key]);
+ $log->attachResource(null);
continue;
}
}
@@ -70,21 +94,13 @@
if ($log->getLeaseID()) {
$lease = idx($leases, $log->getLeaseID());
if (!$lease) {
- unset($logs[$key]);
+ $log->attachLease(null);
continue;
}
}
$log->attachLease($lease);
}
- // These logs are meaningless and their policies aren't computable. They
- // shouldn't exist, but throw them away if they do.
- foreach ($logs as $key => $log) {
- if (!$log->getResource() && !$log->getLease()) {
- unset($logs[$key]);
- }
- }
-
return $logs;
}
diff --git a/src/applications/drydock/storage/DrydockLog.php b/src/applications/drydock/storage/DrydockLog.php
--- a/src/applications/drydock/storage/DrydockLog.php
+++ b/src/applications/drydock/storage/DrydockLog.php
@@ -3,11 +3,13 @@
final class DrydockLog extends DrydockDAO
implements PhabricatorPolicyInterface {
+ protected $blueprintPHID;
protected $resourceID;
protected $leaseID;
protected $epoch;
protected $message;
+ private $blueprint = self::ATTACHABLE;
private $resource = self::ATTACHABLE;
private $lease = self::ATTACHABLE;
@@ -33,6 +35,15 @@
) + parent::getConfiguration();
}
+ public function attachBlueprint(DrydockBlueprint $blueprint = null) {
+ $this->blueprint = $blueprint;
+ return $this;
+ }
+
+ public function getBlueprint() {
+ return $this->assertAttached($this->blueprint);
+ }
+
public function attachResource(DrydockResource $resource = null) {
$this->resource = $resource;
return $this;
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
@@ -18,22 +18,46 @@
$rows = array();
foreach ($logs as $log) {
- $resource_uri = '/drydock/resource/'.$log->getResourceID().'/';
- $lease_uri = '/drydock/lease/'.$log->getLeaseID().'/';
+ $blueprint_id = null;
+ if ($log->getBlueprintPHID() !== null) {
+ $blueprint_id = $log->getBlueprint()->getID();
+ }
- $rows[] = array(
- phutil_tag(
+ $blueprint_uri = '/drydock/blueprint/'.$blueprint_id.'/';
+
+ if ($log->getResource()) {
+ $resource_uri = '/drydock/resource/'.$log->getResourceID().'/';
+ $resource_tag = phutil_tag(
'a',
array(
'href' => $resource_uri,
),
- $log->getResourceID()),
- phutil_tag(
+ $log->getResourceID());
+ } else {
+ $resource_tag = $log->getResourceID();
+ }
+
+ if ($log->getLease()) {
+ $lease_uri = '/drydock/lease/'.$log->getLeaseID().'/';
+ $lease_tag = phutil_tag(
'a',
array(
'href' => $lease_uri,
),
- $log->getLeaseID()),
+ $log->getLeaseID());
+ } else {
+ $lease_tag = $log->getLeaseID();
+ }
+
+ $rows[] = array(
+ phutil_tag(
+ 'a',
+ array(
+ 'href' => $blueprint_uri,
+ ),
+ $blueprint_id),
+ $resource_tag,
+ $lease_tag,
$log->getMessage(),
phabricator_datetime($log->getEpoch(), $viewer),
);
@@ -43,6 +67,7 @@
$table->setDeviceReadyTable(true);
$table->setHeaders(
array(
+ 'Blueprint',
'Resource',
'Lease',
'Message',
@@ -50,6 +75,7 @@
));
$table->setShortHeaders(
array(
+ 'B',
'R',
'L',
'Message',
@@ -59,6 +85,7 @@
array(
'',
'',
+ '',
'wide',
'',
));
diff --git a/src/applications/drydock/worker/DrydockAllocatorWorker.php b/src/applications/drydock/worker/DrydockAllocatorWorker.php
--- a/src/applications/drydock/worker/DrydockAllocatorWorker.php
+++ b/src/applications/drydock/worker/DrydockAllocatorWorker.php
@@ -33,6 +33,7 @@
private function logToDrydock($message) {
DrydockBlueprintImplementation::writeLog(
null,
+ null,
$this->loadLease(),
$message);
}

File Metadata

Mime Type
text/plain
Expires
Thu, Apr 10, 7:33 AM (2 w, 9 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7738727
Default Alt Text
D10892.id26165.diff (7 KB)

Event Timeline