1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Implement artifact release for Harbormaster

Summary: Resolves T5836.  This automatically releases artifacts when Harbormaster builds finish (either passing or failing).  This allows Harbormaster to release the Drydock leases it has for hosts.

Test Plan: Tested it with a build plan that passes and fails; tested it with lots of builds running in parallel.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T5836

Differential Revision: https://secure.phabricator.com/D10208
This commit is contained in:
James Rhodes 2014-08-12 09:15:16 +10:00
parent d2111214f2
commit aab0ed1c50
2 changed files with 51 additions and 0 deletions

View file

@ -66,6 +66,9 @@ final class HarbormasterBuildEngine extends Phobject {
$build->save();
$lock->unlock();
$this->releaseAllArtifacts($build);
throw $ex;
}
@ -87,6 +90,11 @@ final class HarbormasterBuildEngine extends Phobject {
if ($new_status != $old_status || $this->shouldForceBuildableUpdate()) {
$this->updateBuildable($build->getBuildable());
}
// If we are no longer building for any reason, release all artifacts.
if (!$build->isBuilding()) {
$this->releaseAllArtifacts($build);
}
}
private function updateBuild(HarbormasterBuild $build) {
@ -115,6 +123,8 @@ final class HarbormasterBuildEngine extends Phobject {
}
private function destroyBuildTargets(HarbormasterBuild $build) {
$this->releaseAllArtifacts($build);
$targets = id(new HarbormasterBuildTargetQuery())
->setViewer($this->getViewer())
->withBuildPHIDs(array($build->getPHID()))
@ -440,4 +450,27 @@ final class HarbormasterBuildEngine extends Phobject {
}
}
private function releaseAllArtifacts(HarbormasterBuild $build) {
$targets = id(new HarbormasterBuildTargetQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withBuildPHIDs(array($build->getPHID()))
->execute();
if (count($targets) === 0) {
return;
}
$target_phids = mpull($targets, 'getPHID');
$artifacts = id(new HarbormasterBuildArtifactQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withBuildTargetPHIDs($target_phids)
->execute();
foreach ($artifacts as $artifact) {
$artifact->release();
}
}
}

View file

@ -125,6 +125,24 @@ final class HarbormasterBuildArtifact extends HarbormasterDAO
return $file;
}
public function release() {
switch ($this->getArtifactType()) {
case self::TYPE_HOST:
$this->releaseDrydockLease();
break;
}
}
public function releaseDrydockLease() {
$lease = $this->loadDrydockLease();
$resource = $lease->getResource();
$blueprint = $resource->getBlueprint();
if ($lease->isActive()) {
$blueprint->releaseLease($resource, $lease);
}
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */