mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Show Drydock resource leases, add DrydockLeaseQuery, allow reuse of working copies
Summary: Minor updates to Drydock things to make them work better. In particular, after this patch working copies are correctly allocated or reused. Test Plan: Ran "reparse.php --harbormaster <derp derp>", saw reuse of working copies when unleased resources were avilable. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D4216
This commit is contained in:
parent
adfe84ffce
commit
97045077c7
6 changed files with 133 additions and 5 deletions
|
@ -432,6 +432,7 @@ phutil_register_library_map(array(
|
|||
'DrydockInterface' => 'applications/drydock/interface/DrydockInterface.php',
|
||||
'DrydockLease' => 'applications/drydock/storage/DrydockLease.php',
|
||||
'DrydockLeaseListController' => 'applications/drydock/controller/DrydockLeaseListController.php',
|
||||
'DrydockLeaseQuery' => 'applications/drydock/query/DrydockLeaseQuery.php',
|
||||
'DrydockLeaseReleaseController' => 'applications/drydock/controller/DrydockLeaseReleaseController.php',
|
||||
'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php',
|
||||
'DrydockLeaseViewController' => 'applications/drydock/controller/DrydockLeaseViewController.php',
|
||||
|
@ -1721,6 +1722,7 @@ phutil_register_library_map(array(
|
|||
'DrydockDAO' => 'PhabricatorLiskDAO',
|
||||
'DrydockLease' => 'DrydockDAO',
|
||||
'DrydockLeaseListController' => 'DrydockController',
|
||||
'DrydockLeaseQuery' => 'PhabricatorOffsetPagedQuery',
|
||||
'DrydockLeaseReleaseController' => 'DrydockController',
|
||||
'DrydockLeaseStatus' => 'DrydockConstants',
|
||||
'DrydockLeaseViewController' => 'DrydockController',
|
||||
|
|
|
@ -23,13 +23,17 @@ abstract class DrydockBlueprint {
|
|||
}
|
||||
|
||||
protected function loadLease($lease_id) {
|
||||
$lease = id(new DrydockLease())->load($lease_id);
|
||||
$query = id(new DrydockLeaseQuery())
|
||||
->withIDs(array($lease_id))
|
||||
->needResources(true)
|
||||
->execute();
|
||||
|
||||
$lease = idx($query, $lease_id);
|
||||
|
||||
if (!$lease) {
|
||||
throw new Exception("No such lease '{$lease_id}'!");
|
||||
}
|
||||
|
||||
$resource = $lease->loadResource();
|
||||
$lease->attachResource($resource);
|
||||
return $lease;
|
||||
}
|
||||
|
||||
|
@ -43,6 +47,9 @@ abstract class DrydockBlueprint {
|
|||
final public function filterResource(
|
||||
DrydockResource $resource,
|
||||
DrydockLease $lease) {
|
||||
|
||||
$scope = $this->pushActiveScope($resource, $lease);
|
||||
|
||||
return $this->canAllocateLease($resource, $lease);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ final class DrydockWorkingCopyBlueprint extends DrydockBlueprint {
|
|||
$resource_repo = $resource->getAttribute('repositoryID');
|
||||
$lease_repo = $lease->getAttribute('repositoryID');
|
||||
|
||||
return ($resource_repo && $lease_repo && $resource_repo == $lease_repo);
|
||||
return ($resource_repo && $lease_repo && ($resource_repo == $lease_repo));
|
||||
}
|
||||
|
||||
protected function shouldAllocateLease(
|
||||
|
@ -66,6 +66,7 @@ final class DrydockWorkingCopyBlueprint extends DrydockBlueprint {
|
|||
$resource->setStatus(DrydockResourceStatus::STATUS_OPEN);
|
||||
$resource->setAttribute('lease.host', $host_lease->getID());
|
||||
$resource->setAttribute('path', $path);
|
||||
$resource->setAttribute('repositoryID', $repository->getID());
|
||||
$resource->save();
|
||||
|
||||
return $resource;
|
||||
|
|
|
@ -30,6 +30,13 @@ final class DrydockResourceViewController extends DrydockController {
|
|||
$resource_uri = 'resource/'.$resource->getID().'/';
|
||||
$resource_uri = $this->getApplicationURI($resource_uri);
|
||||
|
||||
$leases = id(new DrydockLeaseQuery())
|
||||
->withResourceIDs(array($resource->getID()))
|
||||
->execute();
|
||||
|
||||
$lease_list = $this->buildLeaseListView($leases);
|
||||
$lease_list->setNoDataString(pht('This resource has no leases.'));
|
||||
|
||||
$pager = new AphrontPagerView();
|
||||
$pager->setURI(new PhutilURI($resource_uri), 'offset');
|
||||
$pager->setOffset($request->getInt('offset'));
|
||||
|
@ -46,6 +53,7 @@ final class DrydockResourceViewController extends DrydockController {
|
|||
$header,
|
||||
$actions,
|
||||
$properties,
|
||||
$lease_list,
|
||||
$log_table,
|
||||
));
|
||||
|
||||
|
@ -106,4 +114,34 @@ final class DrydockResourceViewController extends DrydockController {
|
|||
return $view;
|
||||
}
|
||||
|
||||
private function buildLeaseListView(array $leases) {
|
||||
assert_instances_of($leases, 'DrydockLease');
|
||||
|
||||
$user = $this->getRequest()->getUser();
|
||||
|
||||
$view = new PhabricatorObjectItemListView();
|
||||
|
||||
foreach ($leases as $lease) {
|
||||
$item = id(new PhabricatorObjectItemView())
|
||||
->setHeader($lease->getLeaseName())
|
||||
->setHref($this->getApplicationURI('/lease/'.$lease->getID().'/'));
|
||||
|
||||
$status = DrydockLeaseStatus::getNameForStatus($lease->getStatus());
|
||||
$item->addAttribute(phutil_escape_html($status));
|
||||
|
||||
$date_created = phabricator_date($lease->getDateCreated(), $user);
|
||||
$item->addAttribute(pht('Created on %s', $date_created));
|
||||
|
||||
if ($lease->isActive()) {
|
||||
$item->setBarColor('green');
|
||||
} else {
|
||||
$item->setBarColor('red');
|
||||
}
|
||||
|
||||
$view->addItem($item);
|
||||
}
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
80
src/applications/drydock/query/DrydockLeaseQuery.php
Normal file
80
src/applications/drydock/query/DrydockLeaseQuery.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
final class DrydockLeaseQuery extends PhabricatorOffsetPagedQuery {
|
||||
|
||||
private $ids;
|
||||
private $resourceIDs;
|
||||
private $needResources;
|
||||
|
||||
public function withResourceIDs(array $ids) {
|
||||
$this->resourceIDs = $ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function needResources($need_resources) {
|
||||
$this->needResources = $need_resources;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
$table = new DrydockLease();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
||||
$data = queryfx_all(
|
||||
$conn_r,
|
||||
'SELECT lease.* FROM %T lease %Q %Q %Q',
|
||||
$table->getTableName(),
|
||||
$this->buildWhereClause($conn_r),
|
||||
$this->buildOrderClause($conn_r),
|
||||
$this->buildLimitClause($conn_r));
|
||||
|
||||
$leases = $table->loadAllFromArray($data);
|
||||
|
||||
if ($leases && $this->needResources) {
|
||||
$resources = id(new DrydockResource())->loadAllWhere(
|
||||
'id IN (%Ld)',
|
||||
mpull($leases, 'getResourceID'));
|
||||
|
||||
foreach ($leases as $lease) {
|
||||
if ($lease->getResourceID()) {
|
||||
$resource = idx($resources, $lease->getResourceID());
|
||||
if ($resource) {
|
||||
$lease->attachResource($resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $leases;
|
||||
}
|
||||
|
||||
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
|
||||
if ($this->resourceIDs) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'resourceID IN (%Ld)',
|
||||
$this->resourceIDs);
|
||||
}
|
||||
|
||||
if ($this->ids) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
private function buildOrderClause(AphrontDatabaseConnection $conn_r) {
|
||||
return qsprintf($conn_r, 'ORDER BY id DESC');
|
||||
}
|
||||
|
||||
}
|
|
@ -123,7 +123,7 @@ final class DrydockLease extends DrydockDAO {
|
|||
return $this;
|
||||
}
|
||||
|
||||
private function isActive() {
|
||||
public function isActive() {
|
||||
switch ($this->status) {
|
||||
case DrydockLeaseStatus::STATUS_ACTIVE:
|
||||
case DrydockLeaseStatus::STATUS_ACQUIRING:
|
||||
|
|
Loading…
Reference in a new issue