Changeset View
Changeset View
Standalone View
Standalone View
src/applications/drydock/worker/DrydockLeaseUpdateWorker.php
Show First 20 Lines • Show All 303 Lines • ▼ Show 20 Lines | private function loadBlueprintsForAllocatingLease( | ||||
DrydockLease $lease) { | DrydockLease $lease) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$impls = $this->loadBlueprintImplementationsForAllocatingLease($lease); | $impls = $this->loadBlueprintImplementationsForAllocatingLease($lease); | ||||
if (!$impls) { | if (!$impls) { | ||||
return array(); | return array(); | ||||
} | } | ||||
$query = id(new DrydockBlueprintQuery()) | |||||
->setViewer($viewer) | |||||
->withBlueprintClasses(array_keys($impls)) | |||||
->withDisabled(false); | |||||
$blueprint_phids = $lease->getAllowedBlueprintPHIDs(); | $blueprint_phids = $lease->getAllowedBlueprintPHIDs(); | ||||
if (!$blueprint_phids) { | if (!$blueprint_phids) { | ||||
$lease->logEvent(DrydockLeaseNoBlueprintsLogType::LOGCONST); | $lease->logEvent(DrydockLeaseNoBlueprintsLogType::LOGCONST); | ||||
return array(); | return array(); | ||||
} | } | ||||
$query = id(new DrydockBlueprintQuery()) | |||||
->setViewer($viewer) | |||||
->withPHIDs($blueprint_phids) | |||||
epriestley: This line is the important one we were missing -- we didn't actually do anything with… | |||||
->withBlueprintClasses(array_keys($impls)) | |||||
->withDisabled(false); | |||||
// The Drydock application itself is allowed to authorize anything. This | // The Drydock application itself is allowed to authorize anything. This | ||||
// is primarily used for leases generated by CLI administrative tools. | // is primarily used for leases generated by CLI administrative tools. | ||||
$drydock_phid = id(new PhabricatorDrydockApplication())->getPHID(); | $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID(); | ||||
$authorizing_phid = $lease->getAuthorizingPHID(); | $authorizing_phid = $lease->getAuthorizingPHID(); | ||||
if ($authorizing_phid != $drydock_phid) { | if ($authorizing_phid != $drydock_phid) { | ||||
$blueprints = id(clone $query) | $blueprints = id(clone $query) | ||||
->withAuthorizedPHIDs(array($authorizing_phid)) | ->withAuthorizedPHIDs(array($authorizing_phid)) | ||||
Not Done Inline Actions...although it didn't really matter much, because we almost always enforced an effectively identical check here anyway. epriestley: ...although it didn't really matter much, because we almost always enforced an effectively… | |||||
->execute(); | ->execute(); | ||||
if (!$blueprints) { | if (!$blueprints) { | ||||
// If we didn't hit any blueprints, check if this is an authorization | // If we didn't hit any blueprints, check if this is an authorization | ||||
// problem: re-execute the query without the authorization constraint. | // problem: re-execute the query without the authorization constraint. | ||||
// If the second query hits blueprints, the overall configuration is | // If the second query hits blueprints, the overall configuration is | ||||
// fine but this is an authorization problem. If the second query also | // fine but this is an authorization problem. If the second query also | ||||
// comes up blank, this is some other kind of configuration issue so | // comes up blank, this is some other kind of configuration issue so | ||||
// we fall through to the default pathway. | // we fall through to the default pathway. | ||||
$all_blueprints = $query->execute(); | $all_blueprints = $query->execute(); | ||||
if ($all_blueprints) { | if ($all_blueprints) { | ||||
$lease->logEvent( | $lease->logEvent( | ||||
DrydockLeaseNoAuthorizationsLogType::LOGCONST, | DrydockLeaseNoAuthorizationsLogType::LOGCONST, | ||||
array( | array( | ||||
'authorizingPHID' => $authorizing_phid, | 'authorizingPHID' => $authorizing_phid, | ||||
)); | )); | ||||
return array(); | return array(); | ||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
$blueprints = $query->execute(); | $blueprints = $query->execute(); | ||||
Not Done Inline Actions...but could have gone through this branch without enforcing the check, causing a CLI allocation to end up on a surprising blueprint. epriestley: ...but could have gone through this branch without enforcing the check, causing a CLI… | |||||
} | } | ||||
$keep = array(); | $keep = array(); | ||||
foreach ($blueprints as $key => $blueprint) { | foreach ($blueprints as $key => $blueprint) { | ||||
if (!$blueprint->canEverAllocateResourceForLease($lease)) { | if (!$blueprint->canEverAllocateResourceForLease($lease)) { | ||||
continue; | continue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 447 Lines • Show Last 20 Lines |
This line is the important one we were missing -- we didn't actually do anything with $blueprint_phids before.