mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
Fail in a more comprehensible way when a WorkingCopy lease omits or mangles "repositories.map"
Summary: Ref T13676. When the required "repositories.map" attribute is omitted, `bin/drydock lease` currently fatals in an unhelpful way when trying to lease a working copy. Test Plan: Ran `bin/drydock lease --type working-copy` with no attributes, after following steps in T13676. ``` <Allocation Failed> One or more blueprints promised a new resource, but failed when allocating: [PhutilAggregateException] All blueprints failed to allocate a suitable new resource when trying to allocate lease ("PHID-DRYL-orbtwtlinksm3xqpyhmw"). - Exception: Working copy lease is missing required attribute "repositories.map". Attribute "repositories.map" should be a map of repository specifications. ``` Subscribers: yelirekim, PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13676 Differential Revision: https://secure.phabricator.com/D21796
This commit is contained in:
parent
00a20d3cdc
commit
d1fd2975b0
1 changed files with 39 additions and 8 deletions
|
@ -135,14 +135,7 @@ final class DrydockWorkingCopyBlueprintImplementation
|
||||||
->setAllowedBlueprintPHIDs($blueprint_phids);
|
->setAllowedBlueprintPHIDs($blueprint_phids);
|
||||||
$resource->setAttribute('host.leasePHID', $host_lease->getPHID());
|
$resource->setAttribute('host.leasePHID', $host_lease->getPHID());
|
||||||
|
|
||||||
$map = $lease->getAttribute('repositories.map');
|
$map = $this->getWorkingCopyRepositoryMap($lease);
|
||||||
foreach ($map as $key => $value) {
|
|
||||||
$map[$key] = array_select_keys(
|
|
||||||
$value,
|
|
||||||
array(
|
|
||||||
'phid',
|
|
||||||
));
|
|
||||||
}
|
|
||||||
$resource->setAttribute('repositories.map', $map);
|
$resource->setAttribute('repositories.map', $map);
|
||||||
|
|
||||||
$slot_lock = $this->getConcurrentResourceLimitSlotLock($blueprint);
|
$slot_lock = $this->getConcurrentResourceLimitSlotLock($blueprint);
|
||||||
|
@ -157,6 +150,44 @@ final class DrydockWorkingCopyBlueprintImplementation
|
||||||
return $resource;
|
return $resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getWorkingCopyRepositoryMap(DrydockLease $lease) {
|
||||||
|
$attribute = 'repositories.map';
|
||||||
|
$map = $lease->getAttribute($attribute);
|
||||||
|
|
||||||
|
// TODO: Leases should validate their attributes more formally.
|
||||||
|
|
||||||
|
if (!is_array($map) || !$map) {
|
||||||
|
$message = array();
|
||||||
|
if ($map === null) {
|
||||||
|
$message[] = pht(
|
||||||
|
'Working copy lease is missing required attribute "%s".',
|
||||||
|
$attribute);
|
||||||
|
} else {
|
||||||
|
$message[] = pht(
|
||||||
|
'Working copy lease has invalid attribute "%s".',
|
||||||
|
$attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
$message[] = pht(
|
||||||
|
'Attribute "repositories.map" should be a map of repository '.
|
||||||
|
'specifications.');
|
||||||
|
|
||||||
|
$message = implode("\n\n", $message);
|
||||||
|
|
||||||
|
throw new Exception($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($map as $key => $value) {
|
||||||
|
$map[$key] = array_select_keys(
|
||||||
|
$value,
|
||||||
|
array(
|
||||||
|
'phid',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $map;
|
||||||
|
}
|
||||||
|
|
||||||
public function activateResource(
|
public function activateResource(
|
||||||
DrydockBlueprint $blueprint,
|
DrydockBlueprint $blueprint,
|
||||||
DrydockResource $resource) {
|
DrydockResource $resource) {
|
||||||
|
|
Loading…
Reference in a new issue