mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-28 16:30:59 +01:00
Allow leases to be explicitly released via web or CLI
Summary: Permit the forcible release of Drydock leases. The implementation isn't very exciting for now. Test Plan: Released leases via web and CLI. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D4181
This commit is contained in:
parent
081163ab6d
commit
e4bb9255be
8 changed files with 153 additions and 3 deletions
|
@ -18,6 +18,7 @@ $workflows = array(
|
|||
new DrydockManagementWaitForLeaseWorkflow(),
|
||||
new DrydockManagementLeaseWorkflow(),
|
||||
new DrydockManagementCloseWorkflow(),
|
||||
new DrydockManagementReleaseWorkflow(),
|
||||
new PhutilHelpArgumentWorkflow(),
|
||||
);
|
||||
|
||||
|
|
|
@ -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',
|
||||
'DrydockLeaseReleaseController' => 'applications/drydock/controller/DrydockLeaseReleaseController.php',
|
||||
'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php',
|
||||
'DrydockLeaseViewController' => 'applications/drydock/controller/DrydockLeaseViewController.php',
|
||||
'DrydockLocalCommandInterface' => 'applications/drydock/interface/command/DrydockLocalCommandInterface.php',
|
||||
|
@ -441,6 +442,7 @@ phutil_register_library_map(array(
|
|||
'DrydockLogQuery' => 'applications/drydock/query/DrydockLogQuery.php',
|
||||
'DrydockManagementCloseWorkflow' => 'applications/drydock/management/DrydockManagementCloseWorkflow.php',
|
||||
'DrydockManagementLeaseWorkflow' => 'applications/drydock/management/DrydockManagementLeaseWorkflow.php',
|
||||
'DrydockManagementReleaseWorkflow' => 'applications/drydock/management/DrydockManagementReleaseWorkflow.php',
|
||||
'DrydockManagementWaitForLeaseWorkflow' => 'applications/drydock/management/DrydockManagementWaitForLeaseWorkflow.php',
|
||||
'DrydockManagementWorkflow' => 'applications/drydock/management/DrydockManagementWorkflow.php',
|
||||
'DrydockResource' => 'applications/drydock/storage/DrydockResource.php',
|
||||
|
@ -1719,6 +1721,7 @@ phutil_register_library_map(array(
|
|||
'DrydockDAO' => 'PhabricatorLiskDAO',
|
||||
'DrydockLease' => 'DrydockDAO',
|
||||
'DrydockLeaseListController' => 'DrydockController',
|
||||
'DrydockLeaseReleaseController' => 'DrydockController',
|
||||
'DrydockLeaseStatus' => 'DrydockConstants',
|
||||
'DrydockLeaseViewController' => 'DrydockController',
|
||||
'DrydockLocalCommandInterface' => 'DrydockCommandInterface',
|
||||
|
@ -1728,6 +1731,7 @@ phutil_register_library_map(array(
|
|||
'DrydockLogQuery' => 'PhabricatorOffsetPagedQuery',
|
||||
'DrydockManagementCloseWorkflow' => 'DrydockManagementWorkflow',
|
||||
'DrydockManagementLeaseWorkflow' => 'DrydockManagementWorkflow',
|
||||
'DrydockManagementReleaseWorkflow' => 'DrydockManagementWorkflow',
|
||||
'DrydockManagementWaitForLeaseWorkflow' => 'DrydockManagementWorkflow',
|
||||
'DrydockManagementWorkflow' => 'PhutilArgumentWorkflow',
|
||||
'DrydockResource' => 'DrydockDAO',
|
||||
|
|
|
@ -38,6 +38,7 @@ final class PhabricatorApplicationDrydock extends PhabricatorApplication {
|
|||
'lease/' => array(
|
||||
'' => 'DrydockLeaseListController',
|
||||
'(?P<id>[1-9]\d*)/' => 'DrydockLeaseViewController',
|
||||
'(?P<id>[1-9]\d*)/release/' => 'DrydockLeaseReleaseController',
|
||||
),
|
||||
'log/' => 'DrydockLogController',
|
||||
),
|
||||
|
|
|
@ -219,6 +219,35 @@ abstract class DrydockBlueprint {
|
|||
DrydockLease $lease);
|
||||
|
||||
|
||||
|
||||
final public function releaseLease(
|
||||
DrydockResource $resource,
|
||||
DrydockLease $lease) {
|
||||
$scope = $this->pushActiveScope(null, $lease);
|
||||
|
||||
$released = false;
|
||||
|
||||
$lease->openTransaction();
|
||||
$lease->beginReadLocking();
|
||||
$lease->reload();
|
||||
|
||||
if ($lease->getStatus() == DrydockLeaseStatus::STATUS_ACTIVE) {
|
||||
$lease->setStatus(DrydockLeaseStatus::STATUS_RELEASED);
|
||||
$lease->save();
|
||||
$released = true;
|
||||
}
|
||||
|
||||
$lease->endReadLocking();
|
||||
$lease->saveTransaction();
|
||||
|
||||
if (!$released) {
|
||||
throw new Exception("Unable to release lease: lease not active!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* -( Resource Allocation )------------------------------------------------ */
|
||||
|
||||
|
||||
|
|
|
@ -55,10 +55,12 @@ final class DrydockLocalHostBlueprint extends DrydockBlueprint {
|
|||
|
||||
$lease_id = $lease->getID();
|
||||
|
||||
$cmd = $lease->getInterface('command');
|
||||
$cmd->execx('mkdir %s', $lease_id);
|
||||
$full_path = $resource->getAttribute('path').$lease_id.'/';
|
||||
|
||||
$lease->setAttribute('path', $resource->getAttribute('path').$lease_id.'/');
|
||||
$cmd = $lease->getInterface('command');
|
||||
$cmd->execx('mkdir %s', $full_path);
|
||||
|
||||
$lease->setAttribute('path', $full_path);
|
||||
}
|
||||
|
||||
public function getType() {
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
final class DrydockLeaseReleaseController extends DrydockController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = $data['id'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$lease = id(new DrydockLease())->load($this->id);
|
||||
if (!$lease) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$lease_uri = '/lease/'.$lease->getID().'/';
|
||||
$lease_uri = $this->getApplicationURI($lease_uri);
|
||||
|
||||
if ($lease->getStatus() != DrydockLeaseStatus::STATUS_ACTIVE) {
|
||||
$dialog = id(new AphrontDialogView())
|
||||
->setUser($user)
|
||||
->setTitle(pht('Lease Not Active'))
|
||||
->appendChild(
|
||||
'<p>'.pht('You can only release "active" leases.').'</p>')
|
||||
->addCancelButton($lease_uri);
|
||||
|
||||
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||
}
|
||||
|
||||
if (!$request->isDialogFormPost()) {
|
||||
$dialog = id(new AphrontDialogView())
|
||||
->setUser($user)
|
||||
->setTitle(pht('Really release lease?'))
|
||||
->appendChild(
|
||||
'<p>'.pht(
|
||||
'Releasing a lease may cause trouble for the lease holder and '.
|
||||
'trigger cleanup of the underlying resource. It can not be '.
|
||||
'undone. Continue?').'</p>')
|
||||
->addSubmitButton(pht('Release Lease'))
|
||||
->addCancelButton($lease_uri);
|
||||
|
||||
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||
}
|
||||
|
||||
$resource = $lease->loadResource();
|
||||
$blueprint = $resource->getBlueprint();
|
||||
$blueprint->releaseLease($resource, $lease);
|
||||
|
||||
return id(new AphrontReloadResponse())->setURI($lease_uri);
|
||||
}
|
||||
|
||||
}
|
|
@ -62,6 +62,18 @@ final class DrydockLeaseViewController extends DrydockController {
|
|||
->setUser($this->getRequest()->getUser())
|
||||
->setObject($lease);
|
||||
|
||||
$id = $lease->getID();
|
||||
|
||||
$can_release = ($lease->getStatus() == DrydockLeaseStatus::STATUS_ACTIVE);
|
||||
|
||||
$view->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName(pht('Release Lease'))
|
||||
->setIcon('delete')
|
||||
->setHref($this->getApplicationURI("/lease/{$id}/release/"))
|
||||
->setWorkflow(true)
|
||||
->setDisabled(!$can_release));
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
final class DrydockManagementReleaseWorkflow
|
||||
extends DrydockManagementWorkflow {
|
||||
|
||||
public function didConstruct() {
|
||||
$this
|
||||
->setName('release')
|
||||
->setSynopsis('Release a lease.')
|
||||
->setArguments(
|
||||
array(
|
||||
array(
|
||||
'name' => 'ids',
|
||||
'wildcard' => true,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
public function execute(PhutilArgumentParser $args) {
|
||||
$console = PhutilConsole::getConsole();
|
||||
|
||||
$ids = $args->getArg('ids');
|
||||
if (!$ids) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
"Specify one or more lease IDs to release.");
|
||||
}
|
||||
|
||||
foreach ($ids as $id) {
|
||||
$lease = id(new DrydockLease())->load($id);
|
||||
if (!$lease) {
|
||||
$console->writeErr("Lease %d does not exist!\n", $id);
|
||||
} else if ($lease->getStatus() != DrydockLeaseStatus::STATUS_ACTIVE) {
|
||||
$console->writeErr("Lease %d is not 'active'!\n", $id);
|
||||
} else {
|
||||
$resource = $lease->loadResource();
|
||||
$blueprint = $resource->getBlueprint();
|
||||
$blueprint->releaseLease($resource, $lease);
|
||||
|
||||
$console->writeErr("Released lease %d.\n", $id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue