mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 14:30:56 +01:00
When creating a repository with EditEngine, allocate it onto a random cluster service
Summary: Ref T10748. This copies existing code in the `CreateController` which will eventually be removed. Test Plan: - Created a new repository with the EditPro workflow. - Saw it come up into the cluster properly. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10748 Differential Revision: https://secure.phabricator.com/D15835
This commit is contained in:
parent
cac26c8824
commit
319a9cefde
1 changed files with 38 additions and 0 deletions
|
@ -45,6 +45,44 @@ final class DiffusionRepositoryEditEngine
|
||||||
$repository->setVersionControlSystem($vcs);
|
$repository->setVersionControlSystem($vcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pick a random open service to allocate this repository on, if any exist.
|
||||||
|
// If there are no services, we aren't in cluster mode and will allocate
|
||||||
|
// locally. If there are services but none permit allocations, we fail.
|
||||||
|
|
||||||
|
// Eventually we can make this more flexible, but this rule is a reasonable
|
||||||
|
// starting point as we begin to deploy cluster services.
|
||||||
|
|
||||||
|
$services = id(new AlmanacServiceQuery())
|
||||||
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||||
|
->withServiceTypes(
|
||||||
|
array(
|
||||||
|
AlmanacClusterRepositoryServiceType::SERVICETYPE,
|
||||||
|
))
|
||||||
|
->needProperties(true)
|
||||||
|
->execute();
|
||||||
|
if ($services) {
|
||||||
|
// Filter out services which do not permit new allocations.
|
||||||
|
foreach ($services as $key => $possible_service) {
|
||||||
|
if ($possible_service->getAlmanacPropertyValue('closed')) {
|
||||||
|
unset($services[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$services) {
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
'This install is configured in cluster mode, but all available '.
|
||||||
|
'repository cluster services are closed to new allocations. '.
|
||||||
|
'At least one service must be open to allow new allocations to '.
|
||||||
|
'take place.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
shuffle($services);
|
||||||
|
$service = head($services);
|
||||||
|
|
||||||
|
$repository->setAlmanacServicePHID($service->getPHID());
|
||||||
|
}
|
||||||
|
|
||||||
return $repository;
|
return $repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue