1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

Allow Drydock logs to be associated with RepositoryOperation objects

Summary: Ref T13197. See PHI873. I want to give RepositoryOperation objects access to Drydock logging like leases, resources, and blueprints currently have. This just does the schema/query changes, no actual UI or new logging yet.

Test Plan: Ran storage upgrade, poked around the UI looking for anything broken.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13197

Differential Revision: https://secure.phabricator.com/D19671
This commit is contained in:
epriestley 2018-09-14 06:34:17 -07:00
parent 40d5d5c984
commit 10f219fb82
3 changed files with 58 additions and 2 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_drydock.drydock_log
ADD operationPHID VARBINARY(64);

View file

@ -5,6 +5,7 @@ final class DrydockLogQuery extends DrydockQuery {
private $blueprintPHIDs; private $blueprintPHIDs;
private $resourcePHIDs; private $resourcePHIDs;
private $leasePHIDs; private $leasePHIDs;
private $operationPHIDs;
public function withBlueprintPHIDs(array $phids) { public function withBlueprintPHIDs(array $phids) {
$this->blueprintPHIDs = $phids; $this->blueprintPHIDs = $phids;
@ -21,6 +22,11 @@ final class DrydockLogQuery extends DrydockQuery {
return $this; return $this;
} }
public function withOperationPHIDs(array $phids) {
$this->operationPHIDs = $phids;
return $this;
}
public function newResultObject() { public function newResultObject() {
return new DrydockLog(); return new DrydockLog();
} }
@ -93,6 +99,27 @@ final class DrydockLogQuery extends DrydockQuery {
$log->attachLease($lease); $log->attachLease($lease);
} }
$operation_phids = array_filter(mpull($logs, 'getOperationPHID'));
if ($operation_phids) {
$operations = id(new DrydockRepositoryOperationQuery())
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($operation_phids)
->execute();
$operations = mpull($operations, null, 'getPHID');
} else {
$operations = array();
}
foreach ($logs as $key => $log) {
$operation = null;
$operation_phid = $log->getOperationPHID();
if ($operation_phid) {
$operation = idx($operations, $operation_phid);
}
$log->attachOperation($operation);
}
return $logs; return $logs;
} }
@ -120,6 +147,13 @@ final class DrydockLogQuery extends DrydockQuery {
$this->leasePHIDs); $this->leasePHIDs);
} }
if ($this->operationPHIDs !== null) {
$where[] = qsprintf(
$conn,
'operationPHID IN (%Ls)',
$this->operationPHIDs);
}
return $where; return $where;
} }

View file

@ -6,6 +6,7 @@ final class DrydockLog extends DrydockDAO
protected $blueprintPHID; protected $blueprintPHID;
protected $resourcePHID; protected $resourcePHID;
protected $leasePHID; protected $leasePHID;
protected $operationPHID;
protected $epoch; protected $epoch;
protected $type; protected $type;
protected $data = array(); protected $data = array();
@ -13,6 +14,7 @@ final class DrydockLog extends DrydockDAO
private $blueprint = self::ATTACHABLE; private $blueprint = self::ATTACHABLE;
private $resource = self::ATTACHABLE; private $resource = self::ATTACHABLE;
private $lease = self::ATTACHABLE; private $lease = self::ATTACHABLE;
private $operation = self::ATTACHABLE;
protected function getConfiguration() { protected function getConfiguration() {
return array( return array(
@ -24,6 +26,7 @@ final class DrydockLog extends DrydockDAO
'blueprintPHID' => 'phid?', 'blueprintPHID' => 'phid?',
'resourcePHID' => 'phid?', 'resourcePHID' => 'phid?',
'leasePHID' => 'phid?', 'leasePHID' => 'phid?',
'operationPHID' => 'phid?',
'type' => 'text64', 'type' => 'text64',
), ),
self::CONFIG_KEY_SCHEMA => array( self::CONFIG_KEY_SCHEMA => array(
@ -36,6 +39,9 @@ final class DrydockLog extends DrydockDAO
'key_lease' => array( 'key_lease' => array(
'columns' => array('leasePHID', 'type'), 'columns' => array('leasePHID', 'type'),
), ),
'key_operation' => array(
'columns' => array('operationPHID', 'type'),
),
'epoch' => array( 'epoch' => array(
'columns' => array('epoch'), 'columns' => array('epoch'),
), ),
@ -70,6 +76,16 @@ final class DrydockLog extends DrydockDAO
return $this->assertAttached($this->lease); return $this->assertAttached($this->lease);
} }
public function attachOperation(
DrydockRepositoryOperation $operation = null) {
$this->operation = $operation;
return $this;
}
public function getOperation() {
return $this->assertAttached($this->operation);
}
public function isComplete() { public function isComplete() {
if ($this->getBlueprintPHID() && !$this->getBlueprint()) { if ($this->getBlueprintPHID() && !$this->getBlueprint()) {
return false; return false;
@ -83,6 +99,10 @@ final class DrydockLog extends DrydockDAO
return false; return false;
} }
if ($this->getOperationPHID() && !$this->getOperation()) {
return false;
}
return true; return true;
} }
@ -108,8 +128,8 @@ final class DrydockLog extends DrydockDAO
public function describeAutomaticCapability($capability) { public function describeAutomaticCapability($capability) {
return pht( return pht(
'To view log details, you must be able to view the associated '. 'To view log details, you must be able to view all associated '.
'blueprint, resource and lease.'); 'blueprints, resources, leases, and repository operations.');
} }
} }