mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 13:30:55 +01:00
Convert Drydock lease and resource constants to strings
Summary: Ref T9252. Drydock currently uses integer statuses, but there's no reason for this (they don't need to be ordered) and it makes debugging them, working with them, future APIs, etc., more cumbersome. Switch to string instead. Also rename `STATUS_OPEN` to `STATUS_ACTIVE` and `STATUS_CLOSED` to `STATUS_RELEASED` for consistency. This makes resources and leases have more similar states, and gives resource states more accurate names. Test Plan: Browsed web UI, grepped for changed constants, applied patch, inspected database. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9252 Differential Revision: https://secure.phabricator.com/D14153
This commit is contained in:
parent
c6aade4392
commit
e117ace8c7
13 changed files with 78 additions and 38 deletions
39
resources/sql/autopatches/20150924.drydock.status.1.sql
Normal file
39
resources/sql/autopatches/20150924.drydock.status.1.sql
Normal file
|
@ -0,0 +1,39 @@
|
|||
ALTER TABLE {$NAMESPACE}_drydock.drydock_lease
|
||||
CHANGE status status VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
|
||||
|
||||
UPDATE {$NAMESPACE}_drydock.drydock_lease
|
||||
SET status = 'pending' WHERE status = '0';
|
||||
|
||||
UPDATE {$NAMESPACE}_drydock.drydock_lease
|
||||
SET status = 'acquired' WHERE status = '5';
|
||||
|
||||
UPDATE {$NAMESPACE}_drydock.drydock_lease
|
||||
SET status = 'active' WHERE status = '1';
|
||||
|
||||
UPDATE {$NAMESPACE}_drydock.drydock_lease
|
||||
SET status = 'released' WHERE status = '2';
|
||||
|
||||
UPDATE {$NAMESPACE}_drydock.drydock_lease
|
||||
SET status = 'broken' WHERE status = '3';
|
||||
|
||||
UPDATE {$NAMESPACE}_drydock.drydock_lease
|
||||
SET status = 'destroyed' WHERE status = '4';
|
||||
|
||||
|
||||
ALTER TABLE {$NAMESPACE}_drydock.drydock_resource
|
||||
CHANGE status status VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
|
||||
|
||||
UPDATE {$NAMESPACE}_drydock.drydock_resource
|
||||
SET status = 'pending' WHERE status = '0';
|
||||
|
||||
UPDATE {$NAMESPACE}_drydock.drydock_resource
|
||||
SET status = 'active' WHERE status = '1';
|
||||
|
||||
UPDATE {$NAMESPACE}_drydock.drydock_resource
|
||||
SET status = 'released' WHERE status = '2';
|
||||
|
||||
UPDATE {$NAMESPACE}_drydock.drydock_resource
|
||||
SET status = 'broken' WHERE status = '3';
|
||||
|
||||
UPDATE {$NAMESPACE}_drydock.drydock_resource
|
||||
SET status = 'destroyed' WHERE status = '4';
|
|
@ -252,8 +252,8 @@ final class DrydockAlmanacServiceHostBlueprintImplementation
|
|||
->withStatuses(
|
||||
array(
|
||||
DrydockResourceStatus::STATUS_PENDING,
|
||||
DrydockResourceStatus::STATUS_OPEN,
|
||||
DrydockResourceStatus::STATUS_CLOSED,
|
||||
DrydockResourceStatus::STATUS_ACTIVE,
|
||||
DrydockResourceStatus::STATUS_RELEASED,
|
||||
))
|
||||
->execute();
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
final class DrydockLeaseStatus extends DrydockConstants {
|
||||
|
||||
const STATUS_PENDING = 0;
|
||||
const STATUS_ACQUIRED = 5;
|
||||
const STATUS_ACTIVE = 1;
|
||||
const STATUS_RELEASED = 2;
|
||||
const STATUS_BROKEN = 3;
|
||||
const STATUS_DESTROYED = 4;
|
||||
const STATUS_PENDING = 'pending';
|
||||
const STATUS_ACQUIRED = 'acquired';
|
||||
const STATUS_ACTIVE = 'active';
|
||||
const STATUS_RELEASED = 'released';
|
||||
const STATUS_BROKEN = 'broken';
|
||||
const STATUS_DESTROYED = 'destroyed';
|
||||
|
||||
public static function getNameForStatus($status) {
|
||||
$map = array(
|
||||
|
|
|
@ -2,17 +2,17 @@
|
|||
|
||||
final class DrydockResourceStatus extends DrydockConstants {
|
||||
|
||||
const STATUS_PENDING = 0;
|
||||
const STATUS_OPEN = 1;
|
||||
const STATUS_CLOSED = 2;
|
||||
const STATUS_BROKEN = 3;
|
||||
const STATUS_DESTROYED = 4;
|
||||
const STATUS_PENDING = 'pending';
|
||||
const STATUS_ACTIVE = 'active';
|
||||
const STATUS_RELEASED = 'released';
|
||||
const STATUS_BROKEN = 'broken';
|
||||
const STATUS_DESTROYED = 'destroyed';
|
||||
|
||||
public static function getNameForStatus($status) {
|
||||
$map = array(
|
||||
self::STATUS_PENDING => pht('Pending'),
|
||||
self::STATUS_OPEN => pht('Open'),
|
||||
self::STATUS_CLOSED => pht('Closed'),
|
||||
self::STATUS_ACTIVE => pht('Active'),
|
||||
self::STATUS_RELEASED => pht('Released'),
|
||||
self::STATUS_BROKEN => pht('Broken'),
|
||||
self::STATUS_DESTROYED => pht('Destroyed'),
|
||||
);
|
||||
|
@ -23,8 +23,8 @@ final class DrydockResourceStatus extends DrydockConstants {
|
|||
public static function getAllStatuses() {
|
||||
return array(
|
||||
self::STATUS_PENDING,
|
||||
self::STATUS_OPEN,
|
||||
self::STATUS_CLOSED,
|
||||
self::STATUS_ACTIVE,
|
||||
self::STATUS_RELEASED,
|
||||
self::STATUS_BROKEN,
|
||||
self::STATUS_DESTROYED,
|
||||
);
|
||||
|
|
|
@ -98,7 +98,7 @@ final class DrydockLeaseQuery extends DrydockQuery {
|
|||
if ($this->statuses !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'status IN (%Ld)',
|
||||
'status IN (%Ls)',
|
||||
$this->statuses);
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ final class DrydockResourceSearchEngine
|
|||
'statuses',
|
||||
array(
|
||||
DrydockResourceStatus::STATUS_PENDING,
|
||||
DrydockResourceStatus::STATUS_OPEN,
|
||||
DrydockResourceStatus::STATUS_ACTIVE,
|
||||
));
|
||||
case 'all':
|
||||
return $query;
|
||||
|
|
|
@ -60,7 +60,7 @@ final class DrydockLease extends DrydockDAO
|
|||
'attributes' => self::SERIALIZATION_JSON,
|
||||
),
|
||||
self::CONFIG_COLUMN_SCHEMA => array(
|
||||
'status' => 'uint32',
|
||||
'status' => 'text32',
|
||||
'until' => 'epoch?',
|
||||
'resourceType' => 'text128',
|
||||
'ownerPHID' => 'phid?',
|
||||
|
|
|
@ -30,14 +30,15 @@ final class DrydockResource extends DrydockDAO
|
|||
self::CONFIG_COLUMN_SCHEMA => array(
|
||||
'name' => 'text255',
|
||||
'ownerPHID' => 'phid?',
|
||||
'status' => 'uint32',
|
||||
'status' => 'text32',
|
||||
'type' => 'text64',
|
||||
),
|
||||
self::CONFIG_KEY_SCHEMA => array(
|
||||
'key_phid' => null,
|
||||
'phid' => array(
|
||||
'columns' => array('phid'),
|
||||
'unique' => true,
|
||||
'key_type' => array(
|
||||
'columns' => array('type', 'status'),
|
||||
),
|
||||
'key_blueprint' => array(
|
||||
'columns' => array('blueprintPHID', 'status'),
|
||||
),
|
||||
),
|
||||
) + parent::getConfiguration();
|
||||
|
@ -107,7 +108,7 @@ final class DrydockResource extends DrydockDAO
|
|||
}
|
||||
|
||||
if ($this->activateWhenAllocated) {
|
||||
$new_status = DrydockResourceStatus::STATUS_OPEN;
|
||||
$new_status = DrydockResourceStatus::STATUS_ACTIVE;
|
||||
} else {
|
||||
$new_status = DrydockResourceStatus::STATUS_PENDING;
|
||||
}
|
||||
|
@ -153,7 +154,7 @@ final class DrydockResource extends DrydockDAO
|
|||
$this->openTransaction();
|
||||
|
||||
$this
|
||||
->setStatus(DrydockResourceStatus::STATUS_OPEN)
|
||||
->setStatus(DrydockResourceStatus::STATUS_ACTIVE)
|
||||
->save();
|
||||
|
||||
DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks);
|
||||
|
@ -172,7 +173,7 @@ final class DrydockResource extends DrydockDAO
|
|||
|
||||
public function canRelease() {
|
||||
switch ($this->getStatus()) {
|
||||
case DrydockResourceStatus::STATUS_CLOSED:
|
||||
case DrydockResourceStatus::STATUS_RELEASED:
|
||||
case DrydockResourceStatus::STATUS_DESTROYED:
|
||||
return false;
|
||||
default:
|
||||
|
|
|
@ -29,7 +29,7 @@ final class DrydockResourceListView extends AphrontView {
|
|||
case DrydockResourceStatus::STATUS_PENDING:
|
||||
$item->setStatusIcon('fa-dot-circle-o yellow');
|
||||
break;
|
||||
case DrydockResourceStatus::STATUS_OPEN:
|
||||
case DrydockResourceStatus::STATUS_ACTIVE:
|
||||
$item->setStatusIcon('fa-dot-circle-o green');
|
||||
break;
|
||||
case DrydockResourceStatus::STATUS_DESTROYED:
|
||||
|
|
|
@ -229,7 +229,7 @@ final class DrydockAllocatorWorker extends DrydockWorker {
|
|||
->withStatuses(
|
||||
array(
|
||||
DrydockResourceStatus::STATUS_PENDING,
|
||||
DrydockResourceStatus::STATUS_OPEN,
|
||||
DrydockResourceStatus::STATUS_ACTIVE,
|
||||
))
|
||||
->execute();
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ final class DrydockLeaseWorker extends DrydockWorker {
|
|||
throw new Exception(pht('Resource still activating.'));
|
||||
}
|
||||
|
||||
if ($resource_status != DrydockResourceStatus::STATUS_OPEN) {
|
||||
if ($resource_status != DrydockResourceStatus::STATUS_ACTIVE) {
|
||||
throw new PhabricatorWorkerPermanentFailureException(
|
||||
pht(
|
||||
'Trying to activate lease on a dead resource (in status "%s").',
|
||||
|
|
|
@ -12,7 +12,7 @@ final class DrydockResourceDestroyWorker extends DrydockWorker {
|
|||
$status = $resource->getStatus();
|
||||
|
||||
switch ($status) {
|
||||
case DrydockResourceStatus::STATUS_CLOSED:
|
||||
case DrydockResourceStatus::STATUS_RELEASED:
|
||||
case DrydockResourceStatus::STATUS_BROKEN:
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -20,7 +20,7 @@ final class DrydockResourceUpdateWorker extends DrydockWorker {
|
|||
private function updateResource(DrydockResource $resource) {
|
||||
$commands = $this->loadCommands($resource->getPHID());
|
||||
foreach ($commands as $command) {
|
||||
if ($resource->getStatus() != DrydockResourceStatus::STATUS_OPEN) {
|
||||
if ($resource->getStatus() != DrydockResourceStatus::STATUS_ACTIVE) {
|
||||
// Resources can't receive commands before they activate or after they
|
||||
// release.
|
||||
break;
|
||||
|
@ -46,7 +46,7 @@ final class DrydockResourceUpdateWorker extends DrydockWorker {
|
|||
}
|
||||
|
||||
private function releaseResource(DrydockResource $resource) {
|
||||
if ($resource->getStatus() != DrydockResourceStatus::STATUS_OPEN) {
|
||||
if ($resource->getStatus() != DrydockResourceStatus::STATUS_ACTIVE) {
|
||||
// If we had multiple release commands
|
||||
// This command is only meaningful to resources in the "Open" state.
|
||||
return;
|
||||
|
@ -57,7 +57,7 @@ final class DrydockResourceUpdateWorker extends DrydockWorker {
|
|||
|
||||
$resource->openTransaction();
|
||||
$resource
|
||||
->setStatus(DrydockResourceStatus::STATUS_CLOSED)
|
||||
->setStatus(DrydockResourceStatus::STATUS_RELEASED)
|
||||
->save();
|
||||
|
||||
// TODO: Hold slot locks until destruction?
|
||||
|
|
Loading…
Reference in a new issue