1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 13:22:42 +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()) $lease = id(new DrydockLeaseQuery())
->setViewer($viewer) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->needUnconsumedCommands(true)
->executeOne(); ->executeOne();
if (!$lease) { if (!$lease) {
return new Aphront404Response(); return new Aphront404Response();
@ -21,6 +22,10 @@ final class DrydockLeaseViewController extends DrydockLeaseController {
$header = id(new PHUIHeaderView()) $header = id(new PHUIHeaderView())
->setHeader($title); ->setHeader($title);
if ($lease->isReleasing()) {
$header->setStatus('fa-exclamation-triangle', 'red', pht('Releasing'));
}
$actions = $this->buildActionListView($lease); $actions = $this->buildActionListView($lease);
$properties = $this->buildPropertyListView($lease, $actions); $properties = $this->buildPropertyListView($lease, $actions);
@ -78,6 +83,10 @@ final class DrydockLeaseViewController extends DrydockLeaseController {
$id = $lease->getID(); $id = $lease->getID();
$can_release = $lease->canRelease(); $can_release = $lease->canRelease();
if ($lease->isReleasing()) {
$can_release = false;
}
$can_edit = PhabricatorPolicyFilter::hasCapability( $can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer, $viewer,
$lease, $lease,

View file

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

View file

@ -7,7 +7,7 @@ final class DrydockLeaseQuery extends DrydockQuery {
private $resourcePHIDs; private $resourcePHIDs;
private $statuses; private $statuses;
private $datasourceQuery; private $datasourceQuery;
private $needCommands; private $needUnconsumedCommands;
public function withIDs(array $ids) { public function withIDs(array $ids) {
$this->ids = $ids; $this->ids = $ids;
@ -34,6 +34,11 @@ final class DrydockLeaseQuery extends DrydockQuery {
return $this; return $this;
} }
public function needUnconsumedCommands($need) {
$this->needUnconsumedCommands = $need;
return $this;
}
public function newResultObject() { public function newResultObject() {
return new DrydockLease(); return new DrydockLease();
} }
@ -71,6 +76,25 @@ final class DrydockLeaseQuery extends DrydockQuery {
return $leases; 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) { protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn); $where = parent::buildWhereClauseParts($conn);

View file

@ -8,6 +8,7 @@ final class DrydockResourceQuery extends DrydockQuery {
private $types; private $types;
private $blueprintPHIDs; private $blueprintPHIDs;
private $datasourceQuery; private $datasourceQuery;
private $needUnconsumedCommands;
public function withIDs(array $ids) { public function withIDs(array $ids) {
$this->ids = $ids; $this->ids = $ids;
@ -39,6 +40,11 @@ final class DrydockResourceQuery extends DrydockQuery {
return $this; return $this;
} }
public function needUnconsumedCommands($need) {
$this->needUnconsumedCommands = $need;
return $this;
}
public function newResultObject() { public function newResultObject() {
return new DrydockResource(); return new DrydockResource();
} }
@ -69,6 +75,25 @@ final class DrydockResourceQuery extends DrydockQuery {
return $resources; 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) { protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn); $where = parent::buildWhereClauseParts($conn);

View file

@ -11,6 +11,8 @@ final class DrydockLease extends DrydockDAO
protected $status = DrydockLeaseStatus::STATUS_PENDING; protected $status = DrydockLeaseStatus::STATUS_PENDING;
private $resource = self::ATTACHABLE; private $resource = self::ATTACHABLE;
private $unconsumedCommands = self::ATTACHABLE;
private $releaseOnDestruction; private $releaseOnDestruction;
private $isAcquired = false; private $isAcquired = false;
private $isActivated = false; private $isActivated = false;
@ -104,6 +106,25 @@ final class DrydockLease extends DrydockDAO
return ($this->resource !== null); 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() { public function queueForActivation() {
if ($this->getID()) { if ($this->getID()) {
throw new Exception( throw new Exception(

View file

@ -8,7 +8,6 @@ final class DrydockResource extends DrydockDAO
protected $blueprintPHID; protected $blueprintPHID;
protected $status; protected $status;
protected $until; protected $until;
protected $type; protected $type;
protected $name; protected $name;
protected $attributes = array(); protected $attributes = array();
@ -16,6 +15,8 @@ final class DrydockResource extends DrydockDAO
protected $ownerPHID; protected $ownerPHID;
private $blueprint = self::ATTACHABLE; private $blueprint = self::ATTACHABLE;
private $unconsumedCommands = self::ATTACHABLE;
private $isAllocated = false; private $isAllocated = false;
private $isActivated = false; private $isActivated = false;
private $activateWhenAllocated = false; private $activateWhenAllocated = false;
@ -80,6 +81,25 @@ final class DrydockResource extends DrydockDAO
return $this; 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) { public function setActivateWhenAllocated($activate) {
$this->activateWhenAllocated = $activate; $this->activateWhenAllocated = $activate;
return $this; return $this;