Page MenuHomePhabricator

D10892.diff
No OneTemporary

D10892.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
@@ -494,6 +494,7 @@
*/
protected function log($message) {
self::writeLog(
+ $this->instance,
$this->activeResource,
$this->activeLease,
$message);
@@ -504,6 +505,7 @@
* @task log
*/
public static function writeLog(
+ DrydockBlueprint $blueprint = null,
DrydockResource $resource = null,
DrydockLease $lease = null,
$message = null) {
@@ -512,6 +514,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
@@ -2,9 +2,15 @@
final class DrydockLogQuery extends DrydockQuery {
+ private $blueprintPHIDs;
private $resourceIDs;
private $leaseIDs;
+ public function withBlueprintPHIDs(array $phids) {
+ $this->blueprintPHIDs = $phids;
+ return $this;
+ }
+
public function withResourceIDs(array $ids) {
$this->resourceIDs = $ids;
return $this;
@@ -31,6 +37,30 @@
}
protected 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 +77,7 @@
if ($log->getResourceID()) {
$resource = idx($resources, $log->getResourceID());
if (!$resource) {
- unset($logs[$key]);
+ $log->attachResource(null);
continue;
}
}
@@ -70,27 +100,26 @@
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;
}
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
+ if ($this->blueprintPHIDs !== null) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'blueprintPHID IN (%Ls)',
+ $this->blueprintPHIDs);
+ }
+
if ($this->resourceIDs !== null) {
$where[] = qsprintf(
$conn_r,
diff --git a/src/applications/drydock/query/DrydockLogSearchEngine.php b/src/applications/drydock/query/DrydockLogSearchEngine.php
--- a/src/applications/drydock/query/DrydockLogSearchEngine.php
+++ b/src/applications/drydock/query/DrydockLogSearchEngine.php
@@ -14,6 +14,9 @@
$query = new PhabricatorSavedQuery();
$query->setParameter(
+ 'blueprintPHIDs',
+ $this->readListFromRequest($request, 'blueprints'));
+ $query->setParameter(
'resourcePHIDs',
$this->readListFromRequest($request, 'resources'));
$query->setParameter(
@@ -24,6 +27,7 @@
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
+ $blueprint_phids = $saved->getParameter('blueprintPHIDs', array());
$resource_phids = $saved->getParameter('resourcePHIDs', array());
$lease_phids = $saved->getParameter('leasePHIDs', array());
@@ -48,6 +52,9 @@
}
$query = new DrydockLogQuery();
+ if ($blueprint_phids) {
+ $query->withBlueprintPHIDs($blueprint_phids);
+ }
if ($resource_ids) {
$query->withResourceIDs($resource_ids);
}
@@ -65,6 +72,12 @@
$form
->appendControl(
id(new AphrontFormTokenizerControl())
+ ->setDatasource(new DrydockBlueprintDatasource())
+ ->setName('blueprints')
+ ->setLabel(pht('Blueprints'))
+ ->setValue($saved->getParameter('blueprintPHIDs', array())))
+ ->appendControl(
+ id(new AphrontFormTokenizerControl())
->setDatasource(new DrydockResourceDatasource())
->setName('resources')
->setLabel(pht('Resources'))
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;
@@ -18,6 +20,7 @@
'resourceID' => 'id?',
'leaseID' => 'id?',
'message' => 'text',
+ 'blueprintPHID' => 'phid?',
),
self::CONFIG_KEY_SCHEMA => array(
'resourceID' => array(
@@ -33,6 +36,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,27 +18,47 @@
$rows = array();
foreach ($logs as $log) {
- $resource_uri = '/drydock/resource/'.$log->getResourceID().'/';
- $lease_uri = '/drydock/lease/'.$log->getLeaseID().'/';
-
- $resource_name = $log->getResourceID();
- if ($log->getResourceID() !== null) {
- $resource_name = $log->getResource()->getName();
+ if ($log->getBlueprintPHID() !== null) {
+ $blueprint_id = $log->getBlueprint()->getID();
+ $blueprint_uri = '/drydock/blueprint/'.$blueprint_id.'/';
+ $blueprint_tag = phutil_tag(
+ 'a',
+ array(
+ 'href' => $blueprint_uri,
+ ),
+ $log->getBlueprint()->getBlueprintName());
+ } else {
+ $blueprint_tag = '';
}
- $rows[] = array(
- phutil_tag(
+ if ($log->getResource()) {
+ $resource_uri = '/drydock/resource/'.$log->getResourceID().'/';
+ $resource_tag = phutil_tag(
'a',
array(
'href' => $resource_uri,
),
- $resource_name),
- phutil_tag(
+ $log->getResource()->getName());
+ } 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(
+ $blueprint_tag,
+ $resource_tag,
+ $lease_tag,
$log->getMessage(),
phabricator_datetime($log->getEpoch(), $viewer),
);
@@ -48,6 +68,7 @@
$table->setDeviceReadyTable(true);
$table->setHeaders(
array(
+ pht('Blueprint'),
pht('Resource'),
pht('Lease'),
pht('Message'),
@@ -55,6 +76,7 @@
));
$table->setShortHeaders(
array(
+ pht('B'),
pht('R'),
pht('L'),
pht('Message'),
@@ -64,6 +86,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, Mar 27, 12:36 AM (4 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7445770
Default Alt Text
D10892.diff (9 KB)

Event Timeline