Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14035252
D14213.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
11 KB
Referenced Files
None
Subscribers
None
D14213.id.diff
View Options
diff --git a/resources/sql/autopatches/20151001.drydock.rname.1.sql b/resources/sql/autopatches/20151001.drydock.rname.1.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20151001.drydock.rname.1.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_drydock.drydock_resource
+ DROP name;
diff --git a/src/applications/drydock/blueprint/DrydockAlmanacServiceHostBlueprintImplementation.php b/src/applications/drydock/blueprint/DrydockAlmanacServiceHostBlueprintImplementation.php
--- a/src/applications/drydock/blueprint/DrydockAlmanacServiceHostBlueprintImplementation.php
+++ b/src/applications/drydock/blueprint/DrydockAlmanacServiceHostBlueprintImplementation.php
@@ -69,8 +69,9 @@
$binding_phid = $binding->getPHID();
- $resource = $this->newResourceTemplate($blueprint, $device_name)
+ $resource = $this->newResourceTemplate($blueprint)
->setActivateWhenAllocated(true)
+ ->setAttribute('almanacDeviceName', $device_name)
->setAttribute('almanacServicePHID', $binding->getServicePHID())
->setAttribute('almanacBindingPHID', $binding_phid)
->needSlotLock("almanac.host.binding({$binding_phid})");
@@ -95,6 +96,15 @@
return;
}
+ public function getResourceName(
+ DrydockBlueprint $blueprint,
+ DrydockResource $resource) {
+ $device_name = $resource->getAttribute(
+ 'almanacDeviceName',
+ pht('<Unknown>'));
+ return pht('Host (%s)', $device_name);
+ }
+
public function canAcquireLeaseOnResource(
DrydockBlueprint $blueprint,
DrydockResource $resource,
diff --git a/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php b/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php
--- a/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php
+++ b/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php
@@ -237,6 +237,19 @@
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 )------------------------------------------------ */
@@ -260,16 +273,13 @@
return idx(self::getAllBlueprintImplementations(), $class);
}
- protected function newResourceTemplate(
- DrydockBlueprint $blueprint,
- $name) {
+ protected function newResourceTemplate(DrydockBlueprint $blueprint) {
$resource = id(new DrydockResource())
->setBlueprintPHID($blueprint->getPHID())
->attachBlueprint($blueprint)
->setType($this->getType())
- ->setStatus(DrydockResourceStatus::STATUS_PENDING)
- ->setName($name);
+ ->setStatus(DrydockResourceStatus::STATUS_PENDING);
// Pre-allocate the resource PHID.
$resource->setPHID($resource->generatePHID());
diff --git a/src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php b/src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php
--- a/src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php
+++ b/src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php
@@ -97,9 +97,7 @@
DrydockBlueprint $blueprint,
DrydockLease $lease) {
- $resource = $this->newResourceTemplate(
- $blueprint,
- pht('Working Copy'));
+ $resource = $this->newResourceTemplate($blueprint);
$resource_phid = $resource->getPHID();
@@ -185,6 +183,13 @@
}
}
+ public function getResourceName(
+ DrydockBlueprint $blueprint,
+ DrydockResource $resource) {
+ return pht('Working Copy');
+ }
+
+
public function activateLease(
DrydockBlueprint $blueprint,
DrydockResource $resource,
diff --git a/src/applications/drydock/controller/DrydockLeaseController.php b/src/applications/drydock/controller/DrydockLeaseController.php
--- a/src/applications/drydock/controller/DrydockLeaseController.php
+++ b/src/applications/drydock/controller/DrydockLeaseController.php
@@ -44,7 +44,7 @@
$this->getApplicationURI('resource/'));
$crumbs->addTextCrumb(
- $resource->getName(),
+ $resource->getResourceName(),
$this->getApplicationURI("resource/{$id}/"));
$crumbs->addTextCrumb(
diff --git a/src/applications/drydock/controller/DrydockLogController.php b/src/applications/drydock/controller/DrydockLogController.php
--- a/src/applications/drydock/controller/DrydockLogController.php
+++ b/src/applications/drydock/controller/DrydockLogController.php
@@ -91,7 +91,7 @@
$this->getApplicationURI('resource/'));
$crumbs->addTextCrumb(
- $resource->getName(),
+ $resource->getResourceName(),
$this->getApplicationURI("resource/{$id}/"));
$crumbs->addTextCrumb(
diff --git a/src/applications/drydock/controller/DrydockResourceViewController.php b/src/applications/drydock/controller/DrydockResourceViewController.php
--- a/src/applications/drydock/controller/DrydockResourceViewController.php
+++ b/src/applications/drydock/controller/DrydockResourceViewController.php
@@ -15,7 +15,10 @@
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())
->setUser($viewer)
diff --git a/src/applications/drydock/phid/DrydockResourcePHIDType.php b/src/applications/drydock/phid/DrydockResourcePHIDType.php
--- a/src/applications/drydock/phid/DrydockResourcePHIDType.php
+++ b/src/applications/drydock/phid/DrydockResourcePHIDType.php
@@ -33,7 +33,7 @@
pht(
'Resource %d: %s',
$id,
- $resource->getName()));
+ $resource->getResourceName()));
$handle->setURI("/drydock/resource/{$id}/");
}
diff --git a/src/applications/drydock/storage/DrydockBlueprint.php b/src/applications/drydock/storage/DrydockBlueprint.php
--- a/src/applications/drydock/storage/DrydockBlueprint.php
+++ b/src/applications/drydock/storage/DrydockBlueprint.php
@@ -162,6 +162,16 @@
}
+ /**
+ * @task resource
+ */
+ public function getResourceName(DrydockResource $resource) {
+ return $this->getImplementation()->getResourceName(
+ $this,
+ $resource);
+ }
+
+
/* -( Acquiring Leases )--------------------------------------------------- */
diff --git a/src/applications/drydock/storage/DrydockResource.php b/src/applications/drydock/storage/DrydockResource.php
--- a/src/applications/drydock/storage/DrydockResource.php
+++ b/src/applications/drydock/storage/DrydockResource.php
@@ -9,7 +9,6 @@
protected $status;
protected $until;
protected $type;
- protected $name;
protected $attributes = array();
protected $capabilities = array();
protected $ownerPHID;
@@ -30,7 +29,6 @@
'capabilities' => self::SERIALIZATION_JSON,
),
self::CONFIG_COLUMN_SCHEMA => array(
- 'name' => 'text255',
'ownerPHID' => 'phid?',
'status' => 'text32',
'type' => 'text64',
@@ -51,6 +49,10 @@
return PhabricatorPHID::generateNewPHID(DrydockResourcePHIDType::TYPECONST);
}
+ public function getResourceName() {
+ return $this->getBlueprint()->getResourceName($this);
+ }
+
public function getAttribute($key, $default = null) {
return idx($this->attributes, $key, $default);
}
@@ -118,6 +120,16 @@
'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;
$actual_status = $this->getStatus();
if ($actual_status != $expect_status) {
@@ -135,12 +147,10 @@
$new_status = DrydockResourceStatus::STATUS_PENDING;
}
- $phid = $this->generatePHID();
-
$this->openTransaction();
try {
try {
- DrydockSlotLock::acquireLocks($phid, $this->slotLocks);
+ DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks);
$this->slotLocks = array();
} catch (DrydockSlotLockException $ex) {
$this->logEvent(
@@ -152,7 +162,6 @@
}
$this
- ->setPHID($phid)
->setStatus($new_status)
->save();
} catch (Exception $ex) {
diff --git a/src/applications/drydock/view/DrydockLeaseListView.php b/src/applications/drydock/view/DrydockLeaseListView.php
--- a/src/applications/drydock/view/DrydockLeaseListView.php
+++ b/src/applications/drydock/view/DrydockLeaseListView.php
@@ -22,19 +22,10 @@
->setHeader($lease->getLeaseName())
->setHref('/drydock/lease/'.$lease->getID().'/');
- if ($lease->hasAttachedResource()) {
- $resource = $lease->getResource();
-
- $resource_href = '/drydock/resource/'.$resource->getID().'/';
- $resource_name = $resource->getName();
-
+ $resource_phid = $lease->getResourcePHID();
+ if ($resource_phid) {
$item->addAttribute(
- phutil_tag(
- 'a',
- array(
- 'href' => $resource_href,
- ),
- $resource_name));
+ $viewer->renderHandle($resource_phid));
}
$status = DrydockLeaseStatus::getNameForStatus($lease->getStatus());
diff --git a/src/applications/drydock/view/DrydockResourceListView.php b/src/applications/drydock/view/DrydockResourceListView.php
--- a/src/applications/drydock/view/DrydockResourceListView.php
+++ b/src/applications/drydock/view/DrydockResourceListView.php
@@ -16,11 +16,12 @@
$view = new PHUIObjectItemListView();
foreach ($resources as $resource) {
- $name = pht('Resource %d', $resource->getID()).': '.$resource->getName();
+ $id = $resource->getID();
$item = id(new PHUIObjectItemView())
- ->setHref('/drydock/resource/'.$resource->getID().'/')
- ->setHeader($name);
+ ->setHref("/drydock/resource/{$id}/")
+ ->setObjectName(pht('Resource %d', $id))
+ ->setHeader($resource->getResourceName());
$status = DrydockResourceStatus::getNameForStatus($resource->getStatus());
$item->addAttribute($status);
diff --git a/src/applications/drydock/worker/DrydockLeaseUpdateWorker.php b/src/applications/drydock/worker/DrydockLeaseUpdateWorker.php
--- a/src/applications/drydock/worker/DrydockLeaseUpdateWorker.php
+++ b/src/applications/drydock/worker/DrydockLeaseUpdateWorker.php
@@ -690,7 +690,7 @@
->setStatus(DrydockLeaseStatus::STATUS_BROKEN)
->save();
- $lease->scheduleDestruction();
+ $lease->scheduleUpdate();
$lease->logEvent(
DrydockLeaseActivationFailureLogType::LOGCONST,
@@ -715,9 +715,11 @@
*/
private function destroyLease(DrydockLease $lease) {
$resource = $lease->getResource();
- $blueprint = $resource->getBlueprint();
- $blueprint->destroyLease($resource, $lease);
+ if ($resource) {
+ $blueprint = $resource->getBlueprint();
+ $blueprint->destroyLease($resource, $lease);
+ }
DrydockSlotLock::releaseLocks($lease->getPHID());
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 11, 5:11 AM (1 w, 9 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6711860
Default Alt Text
D14213.id.diff (11 KB)
Attached To
Mode
D14213: Remove names from Drydock resources
Attached
Detach File
Event Timeline
Log In to Comment