1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52: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 $resourcePHIDs;
private $leasePHIDs;
private $operationPHIDs;
public function withBlueprintPHIDs(array $phids) {
$this->blueprintPHIDs = $phids;
@ -21,6 +22,11 @@ final class DrydockLogQuery extends DrydockQuery {
return $this;
}
public function withOperationPHIDs(array $phids) {
$this->operationPHIDs = $phids;
return $this;
}
public function newResultObject() {
return new DrydockLog();
}
@ -93,6 +99,27 @@ final class DrydockLogQuery extends DrydockQuery {
$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;
}
@ -120,6 +147,13 @@ final class DrydockLogQuery extends DrydockQuery {
$this->leasePHIDs);
}
if ($this->operationPHIDs !== null) {
$where[] = qsprintf(
$conn,
'operationPHID IN (%Ls)',
$this->operationPHIDs);
}
return $where;
}

View file

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