mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 07:20:57 +01:00
Expose Drydock leases via Conduit
Summary: See T13212 for some context and discussion on this being revived. See T11694 for original context. Add a query constraint for lease owners and implement the conduit search method for Drydock leases. Ref T11694. Fixes T13212. Test Plan: - Called the API method from conduit and browsed lease queries from the UI. - Used the new "ownerPHIDs" constraint via API console. {F5963044} Reviewers: yelirekim, amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam, epriestley Maniphest Tasks: T11694, T13212 Differential Revision: https://secure.phabricator.com/D16594
This commit is contained in:
parent
f6122547d7
commit
5f3a7cb41b
5 changed files with 111 additions and 1 deletions
|
@ -1146,6 +1146,7 @@ phutil_register_library_map(array(
|
|||
'DrydockLeaseReclaimLogType' => 'applications/drydock/logtype/DrydockLeaseReclaimLogType.php',
|
||||
'DrydockLeaseReleaseController' => 'applications/drydock/controller/DrydockLeaseReleaseController.php',
|
||||
'DrydockLeaseReleasedLogType' => 'applications/drydock/logtype/DrydockLeaseReleasedLogType.php',
|
||||
'DrydockLeaseSearchConduitAPIMethod' => 'applications/drydock/conduit/DrydockLeaseSearchConduitAPIMethod.php',
|
||||
'DrydockLeaseSearchEngine' => 'applications/drydock/query/DrydockLeaseSearchEngine.php',
|
||||
'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php',
|
||||
'DrydockLeaseUpdateWorker' => 'applications/drydock/worker/DrydockLeaseUpdateWorker.php',
|
||||
|
@ -6532,6 +6533,7 @@ phutil_register_library_map(array(
|
|||
'DrydockLease' => array(
|
||||
'DrydockDAO',
|
||||
'PhabricatorPolicyInterface',
|
||||
'PhabricatorConduitResultInterface',
|
||||
),
|
||||
'DrydockLeaseAcquiredLogType' => 'DrydockLogType',
|
||||
'DrydockLeaseActivatedLogType' => 'DrydockLogType',
|
||||
|
@ -6552,6 +6554,7 @@ phutil_register_library_map(array(
|
|||
'DrydockLeaseReclaimLogType' => 'DrydockLogType',
|
||||
'DrydockLeaseReleaseController' => 'DrydockLeaseController',
|
||||
'DrydockLeaseReleasedLogType' => 'DrydockLogType',
|
||||
'DrydockLeaseSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
|
||||
'DrydockLeaseSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'DrydockLeaseStatus' => 'PhabricatorObjectStatus',
|
||||
'DrydockLeaseUpdateWorker' => 'DrydockWorker',
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
final class DrydockLeaseSearchConduitAPIMethod
|
||||
extends PhabricatorSearchEngineAPIMethod {
|
||||
|
||||
public function getAPIMethodName() {
|
||||
return 'drydock.lease.search';
|
||||
}
|
||||
|
||||
public function newSearchEngine() {
|
||||
return new DrydockLeaseSearchEngine();
|
||||
}
|
||||
|
||||
public function getMethodSummary() {
|
||||
return pht('Retrieve information about Drydock leases.');
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ final class DrydockLeaseQuery extends DrydockQuery {
|
|||
private $ids;
|
||||
private $phids;
|
||||
private $resourcePHIDs;
|
||||
private $ownerPHIDs;
|
||||
private $statuses;
|
||||
private $datasourceQuery;
|
||||
private $needUnconsumedCommands;
|
||||
|
@ -24,6 +25,11 @@ final class DrydockLeaseQuery extends DrydockQuery {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withOwnerPHIDs(array $phids) {
|
||||
$this->ownerPHIDs = $phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withStatuses(array $statuses) {
|
||||
$this->statuses = $statuses;
|
||||
return $this;
|
||||
|
@ -105,6 +111,13 @@ final class DrydockLeaseQuery extends DrydockQuery {
|
|||
$this->resourcePHIDs);
|
||||
}
|
||||
|
||||
if ($this->ownerPHIDs !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'ownerPHID IN (%Ls)',
|
||||
$this->ownerPHIDs);
|
||||
}
|
||||
|
||||
if ($this->ids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
|
|
|
@ -40,6 +40,10 @@ final class DrydockLeaseSearchEngine
|
|||
$query->withStatuses($map['statuses']);
|
||||
}
|
||||
|
||||
if ($map['ownerPHIDs']) {
|
||||
$query->withOwnerPHIDs($map['ownerPHIDs']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
@ -49,6 +53,11 @@ final class DrydockLeaseSearchEngine
|
|||
->setLabel(pht('Statuses'))
|
||||
->setKey('statuses')
|
||||
->setOptions(DrydockLeaseStatus::getStatusMap()),
|
||||
id(new PhabricatorPHIDsSearchField())
|
||||
->setLabel(pht('Owners'))
|
||||
->setKey('ownerPHIDs')
|
||||
->setAliases(array('owner', 'owners', 'ownerPHID'))
|
||||
->setDescription(pht('Search leases by owner.')),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
|
||||
final class DrydockLease extends DrydockDAO
|
||||
implements PhabricatorPolicyInterface {
|
||||
implements
|
||||
PhabricatorPolicyInterface,
|
||||
PhabricatorConduitResultInterface {
|
||||
|
||||
protected $resourcePHID;
|
||||
protected $resourceType;
|
||||
|
@ -106,6 +108,9 @@ final class DrydockLease extends DrydockDAO
|
|||
'key_status' => array(
|
||||
'columns' => array('status'),
|
||||
),
|
||||
'key_owner' => array(
|
||||
'columns' => array('ownerPHID'),
|
||||
),
|
||||
),
|
||||
) + parent::getConfiguration();
|
||||
}
|
||||
|
@ -535,4 +540,66 @@ final class DrydockLease extends DrydockDAO
|
|||
return pht('Leases inherit policies from the resources they lease.');
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorConduitResultInterface )---------------------------------- */
|
||||
|
||||
|
||||
public function getFieldSpecificationsForConduit() {
|
||||
return array(
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('resourcePHID')
|
||||
->setType('phid?')
|
||||
->setDescription(pht('PHID of the leased resource, if any.')),
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('resourceType')
|
||||
->setType('string')
|
||||
->setDescription(pht('Type of resource being leased.')),
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('until')
|
||||
->setType('int?')
|
||||
->setDescription(pht('Epoch at which this lease expires, if any.')),
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('ownerPHID')
|
||||
->setType('phid?')
|
||||
->setDescription(pht('The PHID of the object that owns this lease.')),
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('authorizingPHID')
|
||||
->setType('phid')
|
||||
->setDescription(pht(
|
||||
'The PHID of the object that authorized this lease.')),
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('status')
|
||||
->setType('map<string, wild>')
|
||||
->setDescription(pht(
|
||||
"The string constant and name of this lease's status.")),
|
||||
);
|
||||
}
|
||||
|
||||
public function getFieldValuesForConduit() {
|
||||
$status = $this->getStatus();
|
||||
|
||||
$until = $this->getUntil();
|
||||
if ($until) {
|
||||
$until = (int)$until;
|
||||
} else {
|
||||
$until = null;
|
||||
}
|
||||
|
||||
return array(
|
||||
'resourcePHID' => $this->getResourcePHID(),
|
||||
'resourceType' => $this->getResourceType(),
|
||||
'until' => $until,
|
||||
'ownerPHID' => $this->getOwnerPHID(),
|
||||
'authorizingPHID' => $this->getAuthorizingPHID(),
|
||||
'status' => array(
|
||||
'value' => $status,
|
||||
'name' => DrydockLeaseStatus::getNameForStatus($status),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function getConduitSearchAttachments() {
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue