1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 20:10:55 +01:00

Give visual feedback when a Drydock resource or lease is releasing

Summary: Ref T9252. Show the user when a resource or lease has a pending release command in queue.

Test Plan: Released a resource and lease from the web UI. In both cases, saw a "releasing" tag and the action disable.

Reviewers: hach-que, chad

Reviewed By: chad

Maniphest Tasks: T9252

Differential Revision: https://secure.phabricator.com/D14177
This commit is contained in:
epriestley 2015-09-28 09:35:26 -07:00
parent ec6d69e74d
commit cd2dd2a08f
6 changed files with 110 additions and 2 deletions

View file

@ -9,6 +9,7 @@ final class DrydockLeaseViewController extends DrydockLeaseController {
$lease = id(new DrydockLeaseQuery())
->setViewer($viewer)
->withIDs(array($id))
->needUnconsumedCommands(true)
->executeOne();
if (!$lease) {
return new Aphront404Response();
@ -21,6 +22,10 @@ final class DrydockLeaseViewController extends DrydockLeaseController {
$header = id(new PHUIHeaderView())
->setHeader($title);
if ($lease->isReleasing()) {
$header->setStatus('fa-exclamation-triangle', 'red', pht('Releasing'));
}
$actions = $this->buildActionListView($lease);
$properties = $this->buildPropertyListView($lease, $actions);
@ -78,6 +83,10 @@ final class DrydockLeaseViewController extends DrydockLeaseController {
$id = $lease->getID();
$can_release = $lease->canRelease();
if ($lease->isReleasing()) {
$can_release = false;
}
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$lease,

View file

@ -9,6 +9,7 @@ final class DrydockResourceViewController extends DrydockResourceController {
$resource = id(new DrydockResourceQuery())
->setViewer($viewer)
->withIDs(array($id))
->needUnconsumedCommands(true)
->executeOne();
if (!$resource) {
return new Aphront404Response();
@ -21,6 +22,10 @@ final class DrydockResourceViewController extends DrydockResourceController {
->setPolicyObject($resource)
->setHeader($title);
if ($resource->isReleasing()) {
$header->setStatus('fa-exclamation-triangle', 'red', pht('Releasing'));
}
$actions = $this->buildActionListView($resource);
$properties = $this->buildPropertyListView($resource, $actions);
@ -82,6 +87,10 @@ final class DrydockResourceViewController extends DrydockResourceController {
->setObject($resource);
$can_release = $resource->canRelease();
if ($resource->isReleasing()) {
$can_release = false;
}
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$resource,

View file

@ -7,7 +7,7 @@ final class DrydockLeaseQuery extends DrydockQuery {
private $resourcePHIDs;
private $statuses;
private $datasourceQuery;
private $needCommands;
private $needUnconsumedCommands;
public function withIDs(array $ids) {
$this->ids = $ids;
@ -34,6 +34,11 @@ final class DrydockLeaseQuery extends DrydockQuery {
return $this;
}
public function needUnconsumedCommands($need) {
$this->needUnconsumedCommands = $need;
return $this;
}
public function newResultObject() {
return new DrydockLease();
}
@ -71,6 +76,25 @@ final class DrydockLeaseQuery extends DrydockQuery {
return $leases;
}
protected function didFilterPage(array $leases) {
if ($this->needUnconsumedCommands) {
$commands = id(new DrydockCommandQuery())
->setViewer($this->getViewer())
->setParentQuery($this)
->withTargetPHIDs(mpull($leases, 'getPHID'))
->withConsumed(false)
->execute();
$commands = mgroup($commands, 'getTargetPHID');
foreach ($leases as $lease) {
$list = idx($commands, $lease->getPHID(), array());
$lease->attachUnconsumedCommands($list);
}
}
return $leases;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);

View file

@ -8,6 +8,7 @@ final class DrydockResourceQuery extends DrydockQuery {
private $types;
private $blueprintPHIDs;
private $datasourceQuery;
private $needUnconsumedCommands;
public function withIDs(array $ids) {
$this->ids = $ids;
@ -39,6 +40,11 @@ final class DrydockResourceQuery extends DrydockQuery {
return $this;
}
public function needUnconsumedCommands($need) {
$this->needUnconsumedCommands = $need;
return $this;
}
public function newResultObject() {
return new DrydockResource();
}
@ -69,6 +75,25 @@ final class DrydockResourceQuery extends DrydockQuery {
return $resources;
}
protected function didFilterPage(array $resources) {
if ($this->needUnconsumedCommands) {
$commands = id(new DrydockCommandQuery())
->setViewer($this->getViewer())
->setParentQuery($this)
->withTargetPHIDs(mpull($resources, 'getPHID'))
->withConsumed(false)
->execute();
$commands = mgroup($commands, 'getTargetPHID');
foreach ($resources as $resource) {
$list = idx($commands, $resource->getPHID(), array());
$resource->attachUnconsumedCommands($list);
}
}
return $resources;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);

View file

@ -11,6 +11,8 @@ final class DrydockLease extends DrydockDAO
protected $status = DrydockLeaseStatus::STATUS_PENDING;
private $resource = self::ATTACHABLE;
private $unconsumedCommands = self::ATTACHABLE;
private $releaseOnDestruction;
private $isAcquired = false;
private $isActivated = false;
@ -104,6 +106,25 @@ final class DrydockLease extends DrydockDAO
return ($this->resource !== null);
}
public function getUnconsumedCommands() {
return $this->assertAttached($this->unconsumedCommands);
}
public function attachUnconsumedCommands(array $commands) {
$this->unconsumedCommands = $commands;
return $this;
}
public function isReleasing() {
foreach ($this->getUnconsumedCommands() as $command) {
if ($command->getCommand() == DrydockCommand::COMMAND_RELEASE) {
return true;
}
}
return false;
}
public function queueForActivation() {
if ($this->getID()) {
throw new Exception(

View file

@ -8,7 +8,6 @@ final class DrydockResource extends DrydockDAO
protected $blueprintPHID;
protected $status;
protected $until;
protected $type;
protected $name;
protected $attributes = array();
@ -16,6 +15,8 @@ final class DrydockResource extends DrydockDAO
protected $ownerPHID;
private $blueprint = self::ATTACHABLE;
private $unconsumedCommands = self::ATTACHABLE;
private $isAllocated = false;
private $isActivated = false;
private $activateWhenAllocated = false;
@ -80,6 +81,25 @@ final class DrydockResource extends DrydockDAO
return $this;
}
public function getUnconsumedCommands() {
return $this->assertAttached($this->unconsumedCommands);
}
public function attachUnconsumedCommands(array $commands) {
$this->unconsumedCommands = $commands;
return $this;
}
public function isReleasing() {
foreach ($this->getUnconsumedCommands() as $command) {
if ($command->getCommand() == DrydockCommand::COMMAND_RELEASE) {
return true;
}
}
return false;
}
public function setActivateWhenAllocated($activate) {
$this->activateWhenAllocated = $activate;
return $this;