mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 12:52:42 +01:00
Remove names from Drydock resources
Summary: Ref T9252. Long ago you sometimes manually created resources, so they had human-enterable names. However, users never make resources manually any more, so this field isn't really useful any more. In particular, it means we write a lot of untranslatable strings like "Working Copy" to the database in the default locale. Instead, do the call at runtime so resource names are translatable. Also clean up a few minor things I hit while kicking the tires here. It's possible we might eventually want to introduce a human-choosable label so you can rename your favorite resources and this would just be a default name. I don't really have much of a use case for that yet, though, and I'm not sure there will ever be one. Test Plan: - Restarted a Harbormaster build, got a clean build. - Released all leases/resources, restarted build, got a clean build with proper resource names. Reviewers: hach-que, chad Reviewed By: hach-que, chad Maniphest Tasks: T9252 Differential Revision: https://secure.phabricator.com/D14213
This commit is contained in:
parent
b219bcfb3d
commit
d4a0b1c870
13 changed files with 80 additions and 37 deletions
2
resources/sql/autopatches/20151001.drydock.rname.1.sql
Normal file
2
resources/sql/autopatches/20151001.drydock.rname.1.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_drydock.drydock_resource
|
||||||
|
DROP name;
|
|
@ -69,8 +69,9 @@ final class DrydockAlmanacServiceHostBlueprintImplementation
|
||||||
|
|
||||||
$binding_phid = $binding->getPHID();
|
$binding_phid = $binding->getPHID();
|
||||||
|
|
||||||
$resource = $this->newResourceTemplate($blueprint, $device_name)
|
$resource = $this->newResourceTemplate($blueprint)
|
||||||
->setActivateWhenAllocated(true)
|
->setActivateWhenAllocated(true)
|
||||||
|
->setAttribute('almanacDeviceName', $device_name)
|
||||||
->setAttribute('almanacServicePHID', $binding->getServicePHID())
|
->setAttribute('almanacServicePHID', $binding->getServicePHID())
|
||||||
->setAttribute('almanacBindingPHID', $binding_phid)
|
->setAttribute('almanacBindingPHID', $binding_phid)
|
||||||
->needSlotLock("almanac.host.binding({$binding_phid})");
|
->needSlotLock("almanac.host.binding({$binding_phid})");
|
||||||
|
@ -95,6 +96,15 @@ final class DrydockAlmanacServiceHostBlueprintImplementation
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getResourceName(
|
||||||
|
DrydockBlueprint $blueprint,
|
||||||
|
DrydockResource $resource) {
|
||||||
|
$device_name = $resource->getAttribute(
|
||||||
|
'almanacDeviceName',
|
||||||
|
pht('<Unknown>'));
|
||||||
|
return pht('Host (%s)', $device_name);
|
||||||
|
}
|
||||||
|
|
||||||
public function canAcquireLeaseOnResource(
|
public function canAcquireLeaseOnResource(
|
||||||
DrydockBlueprint $blueprint,
|
DrydockBlueprint $blueprint,
|
||||||
DrydockResource $resource,
|
DrydockResource $resource,
|
||||||
|
|
|
@ -237,6 +237,19 @@ abstract class DrydockBlueprintImplementation extends Phobject {
|
||||||
DrydockResource $resource);
|
DrydockResource $resource);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a human readable name for a resource.
|
||||||
|
*
|
||||||
|
* @param DrydockBlueprint Blueprint which built the resource.
|
||||||
|
* @param DrydockResource Resource to get the name of.
|
||||||
|
* @return string Human-readable resource name.
|
||||||
|
* @task resource
|
||||||
|
*/
|
||||||
|
abstract public function getResourceName(
|
||||||
|
DrydockBlueprint $blueprint,
|
||||||
|
DrydockResource $resource);
|
||||||
|
|
||||||
|
|
||||||
/* -( Resource Interfaces )------------------------------------------------ */
|
/* -( Resource Interfaces )------------------------------------------------ */
|
||||||
|
|
||||||
|
|
||||||
|
@ -260,16 +273,13 @@ abstract class DrydockBlueprintImplementation extends Phobject {
|
||||||
return idx(self::getAllBlueprintImplementations(), $class);
|
return idx(self::getAllBlueprintImplementations(), $class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function newResourceTemplate(
|
protected function newResourceTemplate(DrydockBlueprint $blueprint) {
|
||||||
DrydockBlueprint $blueprint,
|
|
||||||
$name) {
|
|
||||||
|
|
||||||
$resource = id(new DrydockResource())
|
$resource = id(new DrydockResource())
|
||||||
->setBlueprintPHID($blueprint->getPHID())
|
->setBlueprintPHID($blueprint->getPHID())
|
||||||
->attachBlueprint($blueprint)
|
->attachBlueprint($blueprint)
|
||||||
->setType($this->getType())
|
->setType($this->getType())
|
||||||
->setStatus(DrydockResourceStatus::STATUS_PENDING)
|
->setStatus(DrydockResourceStatus::STATUS_PENDING);
|
||||||
->setName($name);
|
|
||||||
|
|
||||||
// Pre-allocate the resource PHID.
|
// Pre-allocate the resource PHID.
|
||||||
$resource->setPHID($resource->generatePHID());
|
$resource->setPHID($resource->generatePHID());
|
||||||
|
|
|
@ -97,9 +97,7 @@ final class DrydockWorkingCopyBlueprintImplementation
|
||||||
DrydockBlueprint $blueprint,
|
DrydockBlueprint $blueprint,
|
||||||
DrydockLease $lease) {
|
DrydockLease $lease) {
|
||||||
|
|
||||||
$resource = $this->newResourceTemplate(
|
$resource = $this->newResourceTemplate($blueprint);
|
||||||
$blueprint,
|
|
||||||
pht('Working Copy'));
|
|
||||||
|
|
||||||
$resource_phid = $resource->getPHID();
|
$resource_phid = $resource->getPHID();
|
||||||
|
|
||||||
|
@ -185,6 +183,13 @@ final class DrydockWorkingCopyBlueprintImplementation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getResourceName(
|
||||||
|
DrydockBlueprint $blueprint,
|
||||||
|
DrydockResource $resource) {
|
||||||
|
return pht('Working Copy');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function activateLease(
|
public function activateLease(
|
||||||
DrydockBlueprint $blueprint,
|
DrydockBlueprint $blueprint,
|
||||||
DrydockResource $resource,
|
DrydockResource $resource,
|
||||||
|
|
|
@ -44,7 +44,7 @@ abstract class DrydockLeaseController
|
||||||
$this->getApplicationURI('resource/'));
|
$this->getApplicationURI('resource/'));
|
||||||
|
|
||||||
$crumbs->addTextCrumb(
|
$crumbs->addTextCrumb(
|
||||||
$resource->getName(),
|
$resource->getResourceName(),
|
||||||
$this->getApplicationURI("resource/{$id}/"));
|
$this->getApplicationURI("resource/{$id}/"));
|
||||||
|
|
||||||
$crumbs->addTextCrumb(
|
$crumbs->addTextCrumb(
|
||||||
|
|
|
@ -91,7 +91,7 @@ abstract class DrydockLogController
|
||||||
$this->getApplicationURI('resource/'));
|
$this->getApplicationURI('resource/'));
|
||||||
|
|
||||||
$crumbs->addTextCrumb(
|
$crumbs->addTextCrumb(
|
||||||
$resource->getName(),
|
$resource->getResourceName(),
|
||||||
$this->getApplicationURI("resource/{$id}/"));
|
$this->getApplicationURI("resource/{$id}/"));
|
||||||
|
|
||||||
$crumbs->addTextCrumb(
|
$crumbs->addTextCrumb(
|
||||||
|
|
|
@ -15,7 +15,10 @@ final class DrydockResourceViewController extends DrydockResourceController {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
$title = pht('Resource %s %s', $resource->getID(), $resource->getName());
|
$title = pht(
|
||||||
|
'Resource %s %s',
|
||||||
|
$resource->getID(),
|
||||||
|
$resource->getResourceName());
|
||||||
|
|
||||||
$header = id(new PHUIHeaderView())
|
$header = id(new PHUIHeaderView())
|
||||||
->setUser($viewer)
|
->setUser($viewer)
|
||||||
|
|
|
@ -33,7 +33,7 @@ final class DrydockResourcePHIDType extends PhabricatorPHIDType {
|
||||||
pht(
|
pht(
|
||||||
'Resource %d: %s',
|
'Resource %d: %s',
|
||||||
$id,
|
$id,
|
||||||
$resource->getName()));
|
$resource->getResourceName()));
|
||||||
|
|
||||||
$handle->setURI("/drydock/resource/{$id}/");
|
$handle->setURI("/drydock/resource/{$id}/");
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,6 +162,16 @@ final class DrydockBlueprint extends DrydockDAO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @task resource
|
||||||
|
*/
|
||||||
|
public function getResourceName(DrydockResource $resource) {
|
||||||
|
return $this->getImplementation()->getResourceName(
|
||||||
|
$this,
|
||||||
|
$resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( Acquiring Leases )--------------------------------------------------- */
|
/* -( Acquiring Leases )--------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ final class DrydockResource extends DrydockDAO
|
||||||
protected $status;
|
protected $status;
|
||||||
protected $until;
|
protected $until;
|
||||||
protected $type;
|
protected $type;
|
||||||
protected $name;
|
|
||||||
protected $attributes = array();
|
protected $attributes = array();
|
||||||
protected $capabilities = array();
|
protected $capabilities = array();
|
||||||
protected $ownerPHID;
|
protected $ownerPHID;
|
||||||
|
@ -30,7 +29,6 @@ final class DrydockResource extends DrydockDAO
|
||||||
'capabilities' => self::SERIALIZATION_JSON,
|
'capabilities' => self::SERIALIZATION_JSON,
|
||||||
),
|
),
|
||||||
self::CONFIG_COLUMN_SCHEMA => array(
|
self::CONFIG_COLUMN_SCHEMA => array(
|
||||||
'name' => 'text255',
|
|
||||||
'ownerPHID' => 'phid?',
|
'ownerPHID' => 'phid?',
|
||||||
'status' => 'text32',
|
'status' => 'text32',
|
||||||
'type' => 'text64',
|
'type' => 'text64',
|
||||||
|
@ -51,6 +49,10 @@ final class DrydockResource extends DrydockDAO
|
||||||
return PhabricatorPHID::generateNewPHID(DrydockResourcePHIDType::TYPECONST);
|
return PhabricatorPHID::generateNewPHID(DrydockResourcePHIDType::TYPECONST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getResourceName() {
|
||||||
|
return $this->getBlueprint()->getResourceName($this);
|
||||||
|
}
|
||||||
|
|
||||||
public function getAttribute($key, $default = null) {
|
public function getAttribute($key, $default = null) {
|
||||||
return idx($this->attributes, $key, $default);
|
return idx($this->attributes, $key, $default);
|
||||||
}
|
}
|
||||||
|
@ -118,6 +120,16 @@ final class DrydockResource extends DrydockDAO
|
||||||
'Only new resources may be allocated.'));
|
'Only new resources may be allocated.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We expect resources to have a pregenerated PHID, as they should have
|
||||||
|
// been created by a call to DrydockBlueprint->newResourceTemplate().
|
||||||
|
if (!$this->getPHID()) {
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
'Trying to allocate a resource with no generated PHID. Use "%s" to '.
|
||||||
|
'create new resource templates.',
|
||||||
|
'newResourceTemplate()'));
|
||||||
|
}
|
||||||
|
|
||||||
$expect_status = DrydockResourceStatus::STATUS_PENDING;
|
$expect_status = DrydockResourceStatus::STATUS_PENDING;
|
||||||
$actual_status = $this->getStatus();
|
$actual_status = $this->getStatus();
|
||||||
if ($actual_status != $expect_status) {
|
if ($actual_status != $expect_status) {
|
||||||
|
@ -135,12 +147,10 @@ final class DrydockResource extends DrydockDAO
|
||||||
$new_status = DrydockResourceStatus::STATUS_PENDING;
|
$new_status = DrydockResourceStatus::STATUS_PENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
$phid = $this->generatePHID();
|
|
||||||
|
|
||||||
$this->openTransaction();
|
$this->openTransaction();
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
DrydockSlotLock::acquireLocks($phid, $this->slotLocks);
|
DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks);
|
||||||
$this->slotLocks = array();
|
$this->slotLocks = array();
|
||||||
} catch (DrydockSlotLockException $ex) {
|
} catch (DrydockSlotLockException $ex) {
|
||||||
$this->logEvent(
|
$this->logEvent(
|
||||||
|
@ -152,7 +162,6 @@ final class DrydockResource extends DrydockDAO
|
||||||
}
|
}
|
||||||
|
|
||||||
$this
|
$this
|
||||||
->setPHID($phid)
|
|
||||||
->setStatus($new_status)
|
->setStatus($new_status)
|
||||||
->save();
|
->save();
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
|
|
|
@ -22,19 +22,10 @@ final class DrydockLeaseListView extends AphrontView {
|
||||||
->setHeader($lease->getLeaseName())
|
->setHeader($lease->getLeaseName())
|
||||||
->setHref('/drydock/lease/'.$lease->getID().'/');
|
->setHref('/drydock/lease/'.$lease->getID().'/');
|
||||||
|
|
||||||
if ($lease->hasAttachedResource()) {
|
$resource_phid = $lease->getResourcePHID();
|
||||||
$resource = $lease->getResource();
|
if ($resource_phid) {
|
||||||
|
|
||||||
$resource_href = '/drydock/resource/'.$resource->getID().'/';
|
|
||||||
$resource_name = $resource->getName();
|
|
||||||
|
|
||||||
$item->addAttribute(
|
$item->addAttribute(
|
||||||
phutil_tag(
|
$viewer->renderHandle($resource_phid));
|
||||||
'a',
|
|
||||||
array(
|
|
||||||
'href' => $resource_href,
|
|
||||||
),
|
|
||||||
$resource_name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$status = DrydockLeaseStatus::getNameForStatus($lease->getStatus());
|
$status = DrydockLeaseStatus::getNameForStatus($lease->getStatus());
|
||||||
|
|
|
@ -16,11 +16,12 @@ final class DrydockResourceListView extends AphrontView {
|
||||||
|
|
||||||
$view = new PHUIObjectItemListView();
|
$view = new PHUIObjectItemListView();
|
||||||
foreach ($resources as $resource) {
|
foreach ($resources as $resource) {
|
||||||
$name = pht('Resource %d', $resource->getID()).': '.$resource->getName();
|
$id = $resource->getID();
|
||||||
|
|
||||||
$item = id(new PHUIObjectItemView())
|
$item = id(new PHUIObjectItemView())
|
||||||
->setHref('/drydock/resource/'.$resource->getID().'/')
|
->setHref("/drydock/resource/{$id}/")
|
||||||
->setHeader($name);
|
->setObjectName(pht('Resource %d', $id))
|
||||||
|
->setHeader($resource->getResourceName());
|
||||||
|
|
||||||
$status = DrydockResourceStatus::getNameForStatus($resource->getStatus());
|
$status = DrydockResourceStatus::getNameForStatus($resource->getStatus());
|
||||||
$item->addAttribute($status);
|
$item->addAttribute($status);
|
||||||
|
|
|
@ -690,7 +690,7 @@ final class DrydockLeaseUpdateWorker extends DrydockWorker {
|
||||||
->setStatus(DrydockLeaseStatus::STATUS_BROKEN)
|
->setStatus(DrydockLeaseStatus::STATUS_BROKEN)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
$lease->scheduleDestruction();
|
$lease->scheduleUpdate();
|
||||||
|
|
||||||
$lease->logEvent(
|
$lease->logEvent(
|
||||||
DrydockLeaseActivationFailureLogType::LOGCONST,
|
DrydockLeaseActivationFailureLogType::LOGCONST,
|
||||||
|
@ -715,9 +715,11 @@ final class DrydockLeaseUpdateWorker extends DrydockWorker {
|
||||||
*/
|
*/
|
||||||
private function destroyLease(DrydockLease $lease) {
|
private function destroyLease(DrydockLease $lease) {
|
||||||
$resource = $lease->getResource();
|
$resource = $lease->getResource();
|
||||||
$blueprint = $resource->getBlueprint();
|
|
||||||
|
|
||||||
$blueprint->destroyLease($resource, $lease);
|
if ($resource) {
|
||||||
|
$blueprint = $resource->getBlueprint();
|
||||||
|
$blueprint->destroyLease($resource, $lease);
|
||||||
|
}
|
||||||
|
|
||||||
DrydockSlotLock::releaseLocks($lease->getPHID());
|
DrydockSlotLock::releaseLocks($lease->getPHID());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue