1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Implement "drydock.resource.search"

Summary: Fixes T13383. Provide a basic "drydock.resource.search". Also allow "drydock.lease.search" to be queried by resource PHID.

Test Plan: Called "drydock.resource.search" and "drydock.lease.search" with various constraints.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13383

Differential Revision: https://secure.phabricator.com/D20723
This commit is contained in:
epriestley 2019-08-20 12:46:09 -07:00
parent 803eb29c71
commit 721a86401f
6 changed files with 87 additions and 7 deletions

View file

@ -1222,6 +1222,7 @@ phutil_register_library_map(array(
'DrydockResourceQuery' => 'applications/drydock/query/DrydockResourceQuery.php', 'DrydockResourceQuery' => 'applications/drydock/query/DrydockResourceQuery.php',
'DrydockResourceReclaimLogType' => 'applications/drydock/logtype/DrydockResourceReclaimLogType.php', 'DrydockResourceReclaimLogType' => 'applications/drydock/logtype/DrydockResourceReclaimLogType.php',
'DrydockResourceReleaseController' => 'applications/drydock/controller/DrydockResourceReleaseController.php', 'DrydockResourceReleaseController' => 'applications/drydock/controller/DrydockResourceReleaseController.php',
'DrydockResourceSearchConduitAPIMethod' => 'applications/drydock/conduit/DrydockResourceSearchConduitAPIMethod.php',
'DrydockResourceSearchEngine' => 'applications/drydock/query/DrydockResourceSearchEngine.php', 'DrydockResourceSearchEngine' => 'applications/drydock/query/DrydockResourceSearchEngine.php',
'DrydockResourceStatus' => 'applications/drydock/constants/DrydockResourceStatus.php', 'DrydockResourceStatus' => 'applications/drydock/constants/DrydockResourceStatus.php',
'DrydockResourceUpdateWorker' => 'applications/drydock/worker/DrydockResourceUpdateWorker.php', 'DrydockResourceUpdateWorker' => 'applications/drydock/worker/DrydockResourceUpdateWorker.php',
@ -7021,6 +7022,7 @@ phutil_register_library_map(array(
'DrydockResource' => array( 'DrydockResource' => array(
'DrydockDAO', 'DrydockDAO',
'PhabricatorPolicyInterface', 'PhabricatorPolicyInterface',
'PhabricatorConduitResultInterface',
), ),
'DrydockResourceActivationFailureLogType' => 'DrydockLogType', 'DrydockResourceActivationFailureLogType' => 'DrydockLogType',
'DrydockResourceActivationYieldLogType' => 'DrydockLogType', 'DrydockResourceActivationYieldLogType' => 'DrydockLogType',
@ -7034,6 +7036,7 @@ phutil_register_library_map(array(
'DrydockResourceQuery' => 'DrydockQuery', 'DrydockResourceQuery' => 'DrydockQuery',
'DrydockResourceReclaimLogType' => 'DrydockLogType', 'DrydockResourceReclaimLogType' => 'DrydockLogType',
'DrydockResourceReleaseController' => 'DrydockResourceController', 'DrydockResourceReleaseController' => 'DrydockResourceController',
'DrydockResourceSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
'DrydockResourceSearchEngine' => 'PhabricatorApplicationSearchEngine', 'DrydockResourceSearchEngine' => 'PhabricatorApplicationSearchEngine',
'DrydockResourceStatus' => 'PhabricatorObjectStatus', 'DrydockResourceStatus' => 'PhabricatorObjectStatus',
'DrydockResourceUpdateWorker' => 'DrydockWorker', 'DrydockResourceUpdateWorker' => 'DrydockWorker',

View file

@ -0,0 +1,18 @@
<?php
final class DrydockResourceSearchConduitAPIMethod
extends PhabricatorSearchEngineAPIMethod {
public function getAPIMethodName() {
return 'drydock.resource.search';
}
public function newSearchEngine() {
return new DrydockResourceSearchEngine();
}
public function getMethodSummary() {
return pht('Retrieve information about Drydock resources.');
}
}

View file

@ -44,6 +44,10 @@ final class DrydockLeaseSearchEngine
$query->withOwnerPHIDs($map['ownerPHIDs']); $query->withOwnerPHIDs($map['ownerPHIDs']);
} }
if ($map['resourcePHIDs']) {
$query->withResourcePHIDs($map['resourcePHIDs']);
}
return $query; return $query;
} }
@ -58,6 +62,11 @@ final class DrydockLeaseSearchEngine
->setKey('ownerPHIDs') ->setKey('ownerPHIDs')
->setAliases(array('owner', 'owners', 'ownerPHID')) ->setAliases(array('owner', 'owners', 'ownerPHID'))
->setDescription(pht('Search leases by owner.')), ->setDescription(pht('Search leases by owner.')),
id(new PhabricatorPHIDsSearchField())
->setLabel(pht('Resources'))
->setKey('resourcePHIDs')
->setAliases(array('resorucePHID', 'resource', 'resources'))
->setDescription(pht('Search leases by resource.')),
); );
} }

View file

@ -100,46 +100,50 @@ final class DrydockResourceQuery extends DrydockQuery {
if ($this->ids !== null) { if ($this->ids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'id IN (%Ld)', 'resource.id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids !== null) { if ($this->phids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'phid IN (%Ls)', 'resource.phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->types !== null) { if ($this->types !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'type IN (%Ls)', 'resource.type IN (%Ls)',
$this->types); $this->types);
} }
if ($this->statuses !== null) { if ($this->statuses !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'status IN (%Ls)', 'resource.status IN (%Ls)',
$this->statuses); $this->statuses);
} }
if ($this->blueprintPHIDs !== null) { if ($this->blueprintPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'blueprintPHID IN (%Ls)', 'resource.blueprintPHID IN (%Ls)',
$this->blueprintPHIDs); $this->blueprintPHIDs);
} }
if ($this->datasourceQuery !== null) { if ($this->datasourceQuery !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'name LIKE %>', 'resource.name LIKE %>',
$this->datasourceQuery); $this->datasourceQuery);
} }
return $where; return $where;
} }
protected function getPrimaryTableAlias() {
return 'resource';
}
} }

View file

@ -40,6 +40,10 @@ final class DrydockResourceSearchEngine
$query->withStatuses($map['statuses']); $query->withStatuses($map['statuses']);
} }
if ($map['blueprintPHIDs']) {
$query->withBlueprintPHIDs($map['blueprintPHIDs']);
}
return $query; return $query;
} }
@ -49,6 +53,12 @@ final class DrydockResourceSearchEngine
->setLabel(pht('Statuses')) ->setLabel(pht('Statuses'))
->setKey('statuses') ->setKey('statuses')
->setOptions(DrydockResourceStatus::getStatusMap()), ->setOptions(DrydockResourceStatus::getStatusMap()),
id(new PhabricatorPHIDsSearchField())
->setLabel(pht('Blueprints'))
->setKey('blueprintPHIDs')
->setAliases(array('blueprintPHID', 'blueprints', 'blueprint'))
->setDescription(
pht('Search for resources generated by particular blueprints.')),
); );
} }

View file

@ -1,7 +1,9 @@
<?php <?php
final class DrydockResource extends DrydockDAO final class DrydockResource extends DrydockDAO
implements PhabricatorPolicyInterface { implements
PhabricatorPolicyInterface,
PhabricatorConduitResultInterface {
protected $id; protected $id;
protected $phid; protected $phid;
@ -340,4 +342,38 @@ final class DrydockResource extends DrydockDAO
public function describeAutomaticCapability($capability) { public function describeAutomaticCapability($capability) {
return pht('Resources inherit the policies of their blueprints.'); return pht('Resources inherit the policies of their blueprints.');
} }
/* -( PhabricatorConduitResultInterface )---------------------------------- */
public function getFieldSpecificationsForConduit() {
return array(
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('blueprintPHID')
->setType('phid')
->setDescription(pht('The blueprint which generated this resource.')),
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('status')
->setType('map<string, wild>')
->setDescription(pht('Information about resource status.')),
);
}
public function getFieldValuesForConduit() {
$status = $this->getStatus();
return array(
'blueprintPHID' => $this->getBlueprintPHID(),
'status' => array(
'value' => $status,
'name' => DrydockResourceStatus::getNameForStatus($status),
),
);
}
public function getConduitSearchAttachments() {
return array();
}
} }