Differential D14144 Diff 34181 src/applications/drydock/blueprint/DrydockAlmanacServiceHostBlueprintImplementation.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/drydock/blueprint/DrydockAlmanacServiceHostBlueprintImplementation.php
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | foreach ($free_bindings as $binding) { | ||||
} | } | ||||
} | } | ||||
throw new PhutilAggregateException( | throw new PhutilAggregateException( | ||||
pht('Unable to allocate any binding as a resource.'), | pht('Unable to allocate any binding as a resource.'), | ||||
$exceptions); | $exceptions); | ||||
} | } | ||||
public function destroyResource( | |||||
DrydockBlueprint $blueprint, | |||||
DrydockResource $resource) { | |||||
// We don't create anything when allocating hosts, so we don't need to do | |||||
// any cleanup here. | |||||
return; | |||||
} | |||||
public function canAcquireLeaseOnResource( | public function canAcquireLeaseOnResource( | ||||
DrydockBlueprint $blueprint, | DrydockBlueprint $blueprint, | ||||
DrydockResource $resource, | DrydockResource $resource, | ||||
DrydockLease $lease) { | DrydockLease $lease) { | ||||
if (!DrydockSlotLock::isLockFree($this->getLeaseSlotLock($resource))) { | if (!DrydockSlotLock::isLockFree($this->getLeaseSlotLock($resource))) { | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
public function acquireLease( | public function acquireLease( | ||||
DrydockBlueprint $blueprint, | DrydockBlueprint $blueprint, | ||||
DrydockResource $resource, | DrydockResource $resource, | ||||
DrydockLease $lease) { | DrydockLease $lease) { | ||||
$lease | $lease | ||||
->setActivateWhenAcquired(true) | ->setActivateWhenAcquired(true) | ||||
->needSlotLock($this->getLeaseSlotLock($resource)) | ->needSlotLock($this->getLeaseSlotLock($resource)) | ||||
->acquireOnResource($resource); | ->acquireOnResource($resource); | ||||
} | } | ||||
public function didReleaseLease( | |||||
DrydockBlueprint $blueprint, | |||||
DrydockResource $resource, | |||||
DrydockLease $lease) { | |||||
// Almanac hosts stick around indefinitely so we don't need to recycle them | |||||
// if they don't have any leases. | |||||
return; | |||||
} | |||||
public function destroyLease( | |||||
DrydockBlueprint $blueprint, | |||||
DrydockResource $resource, | |||||
DrydockLease $lease) { | |||||
// We don't create anything when activating a lease, so we don't need to | |||||
// throw anything away. | |||||
return; | |||||
} | |||||
private function getLeaseSlotLock(DrydockResource $resource) { | private function getLeaseSlotLock(DrydockResource $resource) { | ||||
$resource_phid = $resource->getPHID(); | $resource_phid = $resource->getPHID(); | ||||
return "almanac.host.lease({$resource_phid})"; | return "almanac.host.lease({$resource_phid})"; | ||||
} | } | ||||
public function getType() { | public function getType() { | ||||
return 'host'; | return 'host'; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 143 Lines • Show Last 20 Lines |