@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+80 -37
+2
resources/sql/autopatches/20151001.drydock.rname.1.sql
··· 1 + ALTER TABLE {$NAMESPACE}_drydock.drydock_resource 2 + DROP name;
+11 -1
src/applications/drydock/blueprint/DrydockAlmanacServiceHostBlueprintImplementation.php
··· 69 69 70 70 $binding_phid = $binding->getPHID(); 71 71 72 - $resource = $this->newResourceTemplate($blueprint, $device_name) 72 + $resource = $this->newResourceTemplate($blueprint) 73 73 ->setActivateWhenAllocated(true) 74 + ->setAttribute('almanacDeviceName', $device_name) 74 75 ->setAttribute('almanacServicePHID', $binding->getServicePHID()) 75 76 ->setAttribute('almanacBindingPHID', $binding_phid) 76 77 ->needSlotLock("almanac.host.binding({$binding_phid})"); ··· 93 94 // We don't create anything when allocating hosts, so we don't need to do 94 95 // any cleanup here. 95 96 return; 97 + } 98 + 99 + public function getResourceName( 100 + DrydockBlueprint $blueprint, 101 + DrydockResource $resource) { 102 + $device_name = $resource->getAttribute( 103 + 'almanacDeviceName', 104 + pht('<Unknown>')); 105 + return pht('Host (%s)', $device_name); 96 106 } 97 107 98 108 public function canAcquireLeaseOnResource(
+15 -5
src/applications/drydock/blueprint/DrydockBlueprintImplementation.php
··· 237 237 DrydockResource $resource); 238 238 239 239 240 + /** 241 + * Get a human readable name for a resource. 242 + * 243 + * @param DrydockBlueprint Blueprint which built the resource. 244 + * @param DrydockResource Resource to get the name of. 245 + * @return string Human-readable resource name. 246 + * @task resource 247 + */ 248 + abstract public function getResourceName( 249 + DrydockBlueprint $blueprint, 250 + DrydockResource $resource); 251 + 252 + 240 253 /* -( Resource Interfaces )------------------------------------------------ */ 241 254 242 255 ··· 260 273 return idx(self::getAllBlueprintImplementations(), $class); 261 274 } 262 275 263 - protected function newResourceTemplate( 264 - DrydockBlueprint $blueprint, 265 - $name) { 276 + protected function newResourceTemplate(DrydockBlueprint $blueprint) { 266 277 267 278 $resource = id(new DrydockResource()) 268 279 ->setBlueprintPHID($blueprint->getPHID()) 269 280 ->attachBlueprint($blueprint) 270 281 ->setType($this->getType()) 271 - ->setStatus(DrydockResourceStatus::STATUS_PENDING) 272 - ->setName($name); 282 + ->setStatus(DrydockResourceStatus::STATUS_PENDING); 273 283 274 284 // Pre-allocate the resource PHID. 275 285 $resource->setPHID($resource->generatePHID());
+8 -3
src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php
··· 97 97 DrydockBlueprint $blueprint, 98 98 DrydockLease $lease) { 99 99 100 - $resource = $this->newResourceTemplate( 101 - $blueprint, 102 - pht('Working Copy')); 100 + $resource = $this->newResourceTemplate($blueprint); 103 101 104 102 $resource_phid = $resource->getPHID(); 105 103 ··· 184 182 } 185 183 } 186 184 } 185 + 186 + public function getResourceName( 187 + DrydockBlueprint $blueprint, 188 + DrydockResource $resource) { 189 + return pht('Working Copy'); 190 + } 191 + 187 192 188 193 public function activateLease( 189 194 DrydockBlueprint $blueprint,
+1 -1
src/applications/drydock/controller/DrydockLeaseController.php
··· 44 44 $this->getApplicationURI('resource/')); 45 45 46 46 $crumbs->addTextCrumb( 47 - $resource->getName(), 47 + $resource->getResourceName(), 48 48 $this->getApplicationURI("resource/{$id}/")); 49 49 50 50 $crumbs->addTextCrumb(
+1 -1
src/applications/drydock/controller/DrydockLogController.php
··· 91 91 $this->getApplicationURI('resource/')); 92 92 93 93 $crumbs->addTextCrumb( 94 - $resource->getName(), 94 + $resource->getResourceName(), 95 95 $this->getApplicationURI("resource/{$id}/")); 96 96 97 97 $crumbs->addTextCrumb(
+4 -1
src/applications/drydock/controller/DrydockResourceViewController.php
··· 15 15 return new Aphront404Response(); 16 16 } 17 17 18 - $title = pht('Resource %s %s', $resource->getID(), $resource->getName()); 18 + $title = pht( 19 + 'Resource %s %s', 20 + $resource->getID(), 21 + $resource->getResourceName()); 19 22 20 23 $header = id(new PHUIHeaderView()) 21 24 ->setUser($viewer)
+1 -1
src/applications/drydock/phid/DrydockResourcePHIDType.php
··· 33 33 pht( 34 34 'Resource %d: %s', 35 35 $id, 36 - $resource->getName())); 36 + $resource->getResourceName())); 37 37 38 38 $handle->setURI("/drydock/resource/{$id}/"); 39 39 }
+10
src/applications/drydock/storage/DrydockBlueprint.php
··· 162 162 } 163 163 164 164 165 + /** 166 + * @task resource 167 + */ 168 + public function getResourceName(DrydockResource $resource) { 169 + return $this->getImplementation()->getResourceName( 170 + $this, 171 + $resource); 172 + } 173 + 174 + 165 175 /* -( Acquiring Leases )--------------------------------------------------- */ 166 176 167 177
+15 -6
src/applications/drydock/storage/DrydockResource.php
··· 9 9 protected $status; 10 10 protected $until; 11 11 protected $type; 12 - protected $name; 13 12 protected $attributes = array(); 14 13 protected $capabilities = array(); 15 14 protected $ownerPHID; ··· 30 29 'capabilities' => self::SERIALIZATION_JSON, 31 30 ), 32 31 self::CONFIG_COLUMN_SCHEMA => array( 33 - 'name' => 'text255', 34 32 'ownerPHID' => 'phid?', 35 33 'status' => 'text32', 36 34 'type' => 'text64', ··· 49 47 50 48 public function generatePHID() { 51 49 return PhabricatorPHID::generateNewPHID(DrydockResourcePHIDType::TYPECONST); 50 + } 51 + 52 + public function getResourceName() { 53 + return $this->getBlueprint()->getResourceName($this); 52 54 } 53 55 54 56 public function getAttribute($key, $default = null) { ··· 118 120 'Only new resources may be allocated.')); 119 121 } 120 122 123 + // We expect resources to have a pregenerated PHID, as they should have 124 + // been created by a call to DrydockBlueprint->newResourceTemplate(). 125 + if (!$this->getPHID()) { 126 + throw new Exception( 127 + pht( 128 + 'Trying to allocate a resource with no generated PHID. Use "%s" to '. 129 + 'create new resource templates.', 130 + 'newResourceTemplate()')); 131 + } 132 + 121 133 $expect_status = DrydockResourceStatus::STATUS_PENDING; 122 134 $actual_status = $this->getStatus(); 123 135 if ($actual_status != $expect_status) { ··· 135 147 $new_status = DrydockResourceStatus::STATUS_PENDING; 136 148 } 137 149 138 - $phid = $this->generatePHID(); 139 - 140 150 $this->openTransaction(); 141 151 try { 142 152 try { 143 - DrydockSlotLock::acquireLocks($phid, $this->slotLocks); 153 + DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks); 144 154 $this->slotLocks = array(); 145 155 } catch (DrydockSlotLockException $ex) { 146 156 $this->logEvent( ··· 152 162 } 153 163 154 164 $this 155 - ->setPHID($phid) 156 165 ->setStatus($new_status) 157 166 ->save(); 158 167 } catch (Exception $ex) {
+3 -12
src/applications/drydock/view/DrydockLeaseListView.php
··· 22 22 ->setHeader($lease->getLeaseName()) 23 23 ->setHref('/drydock/lease/'.$lease->getID().'/'); 24 24 25 - if ($lease->hasAttachedResource()) { 26 - $resource = $lease->getResource(); 27 - 28 - $resource_href = '/drydock/resource/'.$resource->getID().'/'; 29 - $resource_name = $resource->getName(); 30 - 25 + $resource_phid = $lease->getResourcePHID(); 26 + if ($resource_phid) { 31 27 $item->addAttribute( 32 - phutil_tag( 33 - 'a', 34 - array( 35 - 'href' => $resource_href, 36 - ), 37 - $resource_name)); 28 + $viewer->renderHandle($resource_phid)); 38 29 } 39 30 40 31 $status = DrydockLeaseStatus::getNameForStatus($lease->getStatus());
+4 -3
src/applications/drydock/view/DrydockResourceListView.php
··· 16 16 17 17 $view = new PHUIObjectItemListView(); 18 18 foreach ($resources as $resource) { 19 - $name = pht('Resource %d', $resource->getID()).': '.$resource->getName(); 19 + $id = $resource->getID(); 20 20 21 21 $item = id(new PHUIObjectItemView()) 22 - ->setHref('/drydock/resource/'.$resource->getID().'/') 23 - ->setHeader($name); 22 + ->setHref("/drydock/resource/{$id}/") 23 + ->setObjectName(pht('Resource %d', $id)) 24 + ->setHeader($resource->getResourceName()); 24 25 25 26 $status = DrydockResourceStatus::getNameForStatus($resource->getStatus()); 26 27 $item->addAttribute($status);
+5 -3
src/applications/drydock/worker/DrydockLeaseUpdateWorker.php
··· 690 690 ->setStatus(DrydockLeaseStatus::STATUS_BROKEN) 691 691 ->save(); 692 692 693 - $lease->scheduleDestruction(); 693 + $lease->scheduleUpdate(); 694 694 695 695 $lease->logEvent( 696 696 DrydockLeaseActivationFailureLogType::LOGCONST, ··· 715 715 */ 716 716 private function destroyLease(DrydockLease $lease) { 717 717 $resource = $lease->getResource(); 718 - $blueprint = $resource->getBlueprint(); 719 718 720 - $blueprint->destroyLease($resource, $lease); 719 + if ($resource) { 720 + $blueprint = $resource->getBlueprint(); 721 + $blueprint->destroyLease($resource, $lease); 722 + } 721 723 722 724 DrydockSlotLock::releaseLocks($lease->getPHID()); 723 725