@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+51
+33
src/applications/harbormaster/engine/HarbormasterBuildEngine.php
··· 66 66 $build->save(); 67 67 68 68 $lock->unlock(); 69 + 70 + $this->releaseAllArtifacts($build); 71 + 69 72 throw $ex; 70 73 } 71 74 ··· 87 90 if ($new_status != $old_status || $this->shouldForceBuildableUpdate()) { 88 91 $this->updateBuildable($build->getBuildable()); 89 92 } 93 + 94 + // If we are no longer building for any reason, release all artifacts. 95 + if (!$build->isBuilding()) { 96 + $this->releaseAllArtifacts($build); 97 + } 90 98 } 91 99 92 100 private function updateBuild(HarbormasterBuild $build) { ··· 115 123 } 116 124 117 125 private function destroyBuildTargets(HarbormasterBuild $build) { 126 + $this->releaseAllArtifacts($build); 127 + 118 128 $targets = id(new HarbormasterBuildTargetQuery()) 119 129 ->setViewer($this->getViewer()) 120 130 ->withBuildPHIDs(array($build->getPHID())) ··· 438 448 } 439 449 } 440 450 } 451 + } 452 + 453 + private function releaseAllArtifacts(HarbormasterBuild $build) { 454 + $targets = id(new HarbormasterBuildTargetQuery()) 455 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 456 + ->withBuildPHIDs(array($build->getPHID())) 457 + ->execute(); 458 + 459 + if (count($targets) === 0) { 460 + return; 461 + } 462 + 463 + $target_phids = mpull($targets, 'getPHID'); 464 + 465 + $artifacts = id(new HarbormasterBuildArtifactQuery()) 466 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 467 + ->withBuildTargetPHIDs($target_phids) 468 + ->execute(); 469 + 470 + foreach ($artifacts as $artifact) { 471 + $artifact->release(); 472 + } 473 + 441 474 } 442 475 443 476 }
+18
src/applications/harbormaster/storage/build/HarbormasterBuildArtifact.php
··· 125 125 return $file; 126 126 } 127 127 128 + public function release() { 129 + switch ($this->getArtifactType()) { 130 + case self::TYPE_HOST: 131 + $this->releaseDrydockLease(); 132 + break; 133 + } 134 + } 135 + 136 + public function releaseDrydockLease() { 137 + $lease = $this->loadDrydockLease(); 138 + $resource = $lease->getResource(); 139 + $blueprint = $resource->getBlueprint(); 140 + 141 + if ($lease->isActive()) { 142 + $blueprint->releaseLease($resource, $lease); 143 + } 144 + } 145 + 128 146 129 147 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 130 148