mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Improve Drydock log search engine
Summary: Ref T2015. This allows searching based on blueprints, resources or leases when viewing the logs, which helps when searching for events that occured to a particular blueprint / resource / lease. Unlike the logs shown on the resource / lease pages, the search engine supports paging properly, which means it can be used to find entries in the past. Test Plan: Used the Drydock log search page. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: joshuaspence, Korvin, epriestley Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D10874
This commit is contained in:
parent
ea3d528c4c
commit
0d4f9363a0
12 changed files with 210 additions and 9 deletions
|
@ -798,6 +798,7 @@ phutil_register_library_map(array(
|
|||
'DrydockBlueprintCoreCustomField' => 'applications/drydock/customfield/DrydockBlueprintCoreCustomField.php',
|
||||
'DrydockBlueprintCreateController' => 'applications/drydock/controller/DrydockBlueprintCreateController.php',
|
||||
'DrydockBlueprintCustomField' => 'applications/drydock/customfield/DrydockBlueprintCustomField.php',
|
||||
'DrydockBlueprintDatasource' => 'applications/drydock/typeahead/DrydockBlueprintDatasource.php',
|
||||
'DrydockBlueprintEditController' => 'applications/drydock/controller/DrydockBlueprintEditController.php',
|
||||
'DrydockBlueprintEditor' => 'applications/drydock/editor/DrydockBlueprintEditor.php',
|
||||
'DrydockBlueprintImplementation' => 'applications/drydock/blueprint/DrydockBlueprintImplementation.php',
|
||||
|
@ -822,6 +823,7 @@ phutil_register_library_map(array(
|
|||
'DrydockInterface' => 'applications/drydock/interface/DrydockInterface.php',
|
||||
'DrydockLease' => 'applications/drydock/storage/DrydockLease.php',
|
||||
'DrydockLeaseController' => 'applications/drydock/controller/DrydockLeaseController.php',
|
||||
'DrydockLeaseDatasource' => 'applications/drydock/typeahead/DrydockLeaseDatasource.php',
|
||||
'DrydockLeaseListController' => 'applications/drydock/controller/DrydockLeaseListController.php',
|
||||
'DrydockLeaseListView' => 'applications/drydock/view/DrydockLeaseListView.php',
|
||||
'DrydockLeasePHIDType' => 'applications/drydock/phid/DrydockLeasePHIDType.php',
|
||||
|
@ -847,6 +849,7 @@ phutil_register_library_map(array(
|
|||
'DrydockResource' => 'applications/drydock/storage/DrydockResource.php',
|
||||
'DrydockResourceCloseController' => 'applications/drydock/controller/DrydockResourceCloseController.php',
|
||||
'DrydockResourceController' => 'applications/drydock/controller/DrydockResourceController.php',
|
||||
'DrydockResourceDatasource' => 'applications/drydock/typeahead/DrydockResourceDatasource.php',
|
||||
'DrydockResourceListController' => 'applications/drydock/controller/DrydockResourceListController.php',
|
||||
'DrydockResourceListView' => 'applications/drydock/view/DrydockResourceListView.php',
|
||||
'DrydockResourcePHIDType' => 'applications/drydock/phid/DrydockResourcePHIDType.php',
|
||||
|
@ -4479,6 +4482,7 @@ phutil_register_library_map(array(
|
|||
),
|
||||
'DrydockBlueprintCreateController' => 'DrydockBlueprintController',
|
||||
'DrydockBlueprintCustomField' => 'PhabricatorCustomField',
|
||||
'DrydockBlueprintDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'DrydockBlueprintEditController' => 'DrydockBlueprintController',
|
||||
'DrydockBlueprintEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'DrydockBlueprintImplementation' => 'Phobject',
|
||||
|
@ -4506,6 +4510,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPolicyInterface',
|
||||
),
|
||||
'DrydockLeaseController' => 'DrydockController',
|
||||
'DrydockLeaseDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'DrydockLeaseListController' => 'DrydockLeaseController',
|
||||
'DrydockLeaseListView' => 'AphrontView',
|
||||
'DrydockLeasePHIDType' => 'PhabricatorPHIDType',
|
||||
|
@ -4537,6 +4542,7 @@ phutil_register_library_map(array(
|
|||
),
|
||||
'DrydockResourceCloseController' => 'DrydockResourceController',
|
||||
'DrydockResourceController' => 'DrydockController',
|
||||
'DrydockResourceDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'DrydockResourceListController' => 'DrydockResourceController',
|
||||
'DrydockResourceListView' => 'AphrontView',
|
||||
'DrydockResourcePHIDType' => 'PhabricatorPHIDType',
|
||||
|
|
|
@ -29,6 +29,9 @@ final class DrydockLeasePHIDType extends PhabricatorPHIDType {
|
|||
$lease = $objects[$phid];
|
||||
$id = $lease->getID();
|
||||
|
||||
$handle->setName(pht(
|
||||
'Lease %d',
|
||||
$id));
|
||||
$handle->setURI("/drydock/lease/{$id}/");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ final class DrydockResourcePHIDType extends PhabricatorPHIDType {
|
|||
$resource = $objects[$phid];
|
||||
$id = $resource->getID();
|
||||
|
||||
$handle->setName($resource->getName());
|
||||
$handle->setURI("/drydock/resource/{$id}/");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ final class DrydockBlueprintQuery extends DrydockQuery {
|
|||
|
||||
private $ids;
|
||||
private $phids;
|
||||
private $datasourceQuery;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
|
@ -15,6 +16,11 @@ final class DrydockBlueprintQuery extends DrydockQuery {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withDatasourceQuery($query) {
|
||||
$this->datasourceQuery = $query;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
$table = new DrydockBlueprint();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
@ -59,6 +65,13 @@ final class DrydockBlueprintQuery extends DrydockQuery {
|
|||
$this->phids);
|
||||
}
|
||||
|
||||
if ($this->datasourceQuery) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'blueprintName LIKE %>',
|
||||
$this->datasourceQuery);
|
||||
}
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ final class DrydockLeaseQuery extends DrydockQuery {
|
|||
private $phids;
|
||||
private $resourceIDs;
|
||||
private $statuses;
|
||||
private $datasourceQuery;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
|
@ -31,6 +32,11 @@ final class DrydockLeaseQuery extends DrydockQuery {
|
|||
return new DrydockLease();
|
||||
}
|
||||
|
||||
public function withDatasourceQuery($query) {
|
||||
$this->datasourceQuery = $query;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
return $this->loadStandardPage($this->newResultObject());
|
||||
}
|
||||
|
@ -65,34 +71,41 @@ final class DrydockLeaseQuery extends DrydockQuery {
|
|||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||
$where = parent::buildWhereClauseParts($conn);
|
||||
|
||||
if ($this->resourceIDs !== null) {
|
||||
if ($this->resourceIDs) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'resourceID IN (%Ld)',
|
||||
$this->resourceIDs);
|
||||
}
|
||||
|
||||
if ($this->ids !== null) {
|
||||
if ($this->ids) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->phids !== null) {
|
||||
if ($this->phids) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'phid IN (%Ls)',
|
||||
$this->phids);
|
||||
}
|
||||
|
||||
if ($this->statuses !== null) {
|
||||
if ($this->statuses) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'status IN (%Ld)',
|
||||
$this->statuses);
|
||||
}
|
||||
|
||||
if ($this->datasourceQuery) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'id = %d',
|
||||
(int)$this->datasourceQuery);
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,16 +11,55 @@ final class DrydockLogSearchEngine extends PhabricatorApplicationSearchEngine {
|
|||
}
|
||||
|
||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
return new PhabricatorSavedQuery();
|
||||
$query = new PhabricatorSavedQuery();
|
||||
|
||||
$query->setParameter(
|
||||
'resourcePHIDs',
|
||||
$this->readListFromRequest($request, 'resources'));
|
||||
$query->setParameter(
|
||||
'leasePHIDs',
|
||||
$this->readListFromRequest($request, 'leases'));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
return new DrydockLogQuery();
|
||||
|
||||
// TODO: Change logs to use PHIDs instead of IDs.
|
||||
$resource_ids = id(new DrydockResourceQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withPHIDs($saved->getParameter('resourcePHIDs', array()))
|
||||
->execute();
|
||||
$resource_ids = mpull($resource_ids, 'getID');
|
||||
$lease_ids = id(new DrydockLeaseQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withPHIDs($saved->getParameter('leasePHIDs', array()))
|
||||
->execute();
|
||||
$lease_ids = mpull($lease_ids, 'getID');
|
||||
|
||||
return id(new DrydockLogQuery())
|
||||
->withResourceIDs($resource_ids)
|
||||
->withLeaseIDs($lease_ids);
|
||||
}
|
||||
|
||||
public function buildSearchForm(
|
||||
AphrontFormView $form,
|
||||
PhabricatorSavedQuery $saved) {}
|
||||
PhabricatorSavedQuery $saved) {
|
||||
|
||||
$form
|
||||
->appendControl(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setDatasource(new DrydockResourceDatasource())
|
||||
->setName('resources')
|
||||
->setLabel(pht('Resources'))
|
||||
->setValue($saved->getParameter('resourcePHIDs', array())))
|
||||
->appendControl(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setDatasource(new DrydockLeaseDatasource())
|
||||
->setName('leases')
|
||||
->setLabel(pht('Leases'))
|
||||
->setValue($saved->getParameter('leasePHIDs', array())));
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
return '/drydock/log/'.$path;
|
||||
|
|
|
@ -7,6 +7,7 @@ final class DrydockResourceQuery extends DrydockQuery {
|
|||
private $statuses;
|
||||
private $types;
|
||||
private $blueprintPHIDs;
|
||||
private $datasourceQuery;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
|
@ -33,6 +34,11 @@ final class DrydockResourceQuery extends DrydockQuery {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withDatasourceQuery($query) {
|
||||
$this->datasourceQuery = $query;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
$table = new DrydockResource();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
@ -88,6 +94,13 @@ final class DrydockResourceQuery extends DrydockQuery {
|
|||
$this->blueprintPHIDs);
|
||||
}
|
||||
|
||||
if ($this->datasourceQuery) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'name LIKE %>',
|
||||
$this->datasourceQuery);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
|
|
|
@ -40,7 +40,7 @@ final class DrydockBlueprint extends DrydockDAO
|
|||
),
|
||||
self::CONFIG_COLUMN_SCHEMA => array(
|
||||
'className' => 'text255',
|
||||
'blueprintName' => 'text255',
|
||||
'blueprintName' => 'sort255',
|
||||
),
|
||||
) + parent::getConfiguration();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
final class DrydockBlueprintDatasource
|
||||
extends PhabricatorTypeaheadDatasource {
|
||||
|
||||
public function getPlaceholderText() {
|
||||
return pht('Type a blueprint name...');
|
||||
}
|
||||
|
||||
public function getDatasourceApplicationClass() {
|
||||
return 'PhabricatorDrydockApplication';
|
||||
}
|
||||
|
||||
public function loadResults() {
|
||||
$viewer = $this->getViewer();
|
||||
$raw_query = $this->getRawQuery();
|
||||
|
||||
$blueprints = id(new DrydockBlueprintQuery())
|
||||
->setViewer($viewer)
|
||||
->withDatasourceQuery($raw_query)
|
||||
->execute();
|
||||
|
||||
$handles = id(new PhabricatorHandleQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(mpull($blueprints, 'getPHID'))
|
||||
->execute();
|
||||
|
||||
$results = array();
|
||||
foreach ($handles as $handle) {
|
||||
$results[] = id(new PhabricatorTypeaheadResult())
|
||||
->setName($handle->getName())
|
||||
->setPHID($handle->getPHID());
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
final class DrydockLeaseDatasource
|
||||
extends PhabricatorTypeaheadDatasource {
|
||||
|
||||
public function getPlaceholderText() {
|
||||
return pht('Type a lease ID (exact match)...');
|
||||
}
|
||||
|
||||
public function getDatasourceApplicationClass() {
|
||||
return 'PhabricatorDrydockApplication';
|
||||
}
|
||||
|
||||
public function loadResults() {
|
||||
$viewer = $this->getViewer();
|
||||
$raw_query = $this->getRawQuery();
|
||||
|
||||
$leases = id(new DrydockLeaseQuery())
|
||||
->setViewer($viewer)
|
||||
->withDatasourceQuery($raw_query)
|
||||
->execute();
|
||||
|
||||
$handles = id(new PhabricatorHandleQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(mpull($leases, 'getPHID'))
|
||||
->execute();
|
||||
|
||||
$results = array();
|
||||
foreach ($handles as $handle) {
|
||||
$results[] = id(new PhabricatorTypeaheadResult())
|
||||
->setName($handle->getName())
|
||||
->setPHID($handle->getPHID());
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
final class DrydockResourceDatasource
|
||||
extends PhabricatorTypeaheadDatasource {
|
||||
|
||||
public function getPlaceholderText() {
|
||||
return pht('Type a resource name...');
|
||||
}
|
||||
|
||||
public function getDatasourceApplicationClass() {
|
||||
return 'PhabricatorDrydockApplication';
|
||||
}
|
||||
|
||||
public function loadResults() {
|
||||
$viewer = $this->getViewer();
|
||||
$raw_query = $this->getRawQuery();
|
||||
|
||||
$resources = id(new DrydockResourceQuery())
|
||||
->setViewer($viewer)
|
||||
->withDatasourceQuery($raw_query)
|
||||
->execute();
|
||||
|
||||
$handles = id(new PhabricatorHandleQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(mpull($resources, 'getPHID'))
|
||||
->execute();
|
||||
|
||||
$results = array();
|
||||
foreach ($handles as $handle) {
|
||||
$results[] = id(new PhabricatorTypeaheadResult())
|
||||
->setName($handle->getName())
|
||||
->setPHID($handle->getPHID());
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
|
@ -21,13 +21,18 @@ final class DrydockLogListView extends AphrontView {
|
|||
$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();
|
||||
}
|
||||
|
||||
$rows[] = array(
|
||||
phutil_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => $resource_uri,
|
||||
),
|
||||
$log->getResourceID()),
|
||||
$resource_name),
|
||||
phutil_tag(
|
||||
'a',
|
||||
array(
|
||||
|
|
Loading…
Reference in a new issue