Page MenuHomePhabricator

D10321.diff
No OneTemporary

D10321.diff

diff --git a/resources/sql/autopatches/20140821.harbormasterbuildgen.1.sql b/resources/sql/autopatches/20140821.harbormasterbuildgen.1.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20140821.harbormasterbuildgen.1.sql
@@ -0,0 +1,5 @@
+ALTER TABLE {$NAMESPACE}_harbormaster.harbormaster_build
+ ADD COLUMN `buildGeneration` INT UNSIGNED NOT NULL DEFAULT 0;
+
+ALTER TABLE {$NAMESPACE}_harbormaster.harbormaster_buildtarget
+ ADD COLUMN `buildGeneration` INT UNSIGNED NOT NULL DEFAULT 0;
diff --git a/src/applications/harbormaster/controller/HarbormasterBuildViewController.php b/src/applications/harbormaster/controller/HarbormasterBuildViewController.php
--- a/src/applications/harbormaster/controller/HarbormasterBuildViewController.php
+++ b/src/applications/harbormaster/controller/HarbormasterBuildViewController.php
@@ -14,6 +14,7 @@
$viewer = $request->getUser();
$id = $this->id;
+ $generation = $request->getInt('g');
$build = id(new HarbormasterBuildQuery())
->setViewer($viewer)
@@ -52,13 +53,18 @@
'/'.$build->getBuildable()->getMonogram());
$crumbs->addTextCrumb($title);
+ if ($generation === null || $generation > $build->getBuildGeneration() ||
+ $generation < 0) {
+ $generation = $build->getBuildGeneration();
+ }
+
$build_targets = id(new HarbormasterBuildTargetQuery())
->setViewer($viewer)
->needBuildSteps(true)
->withBuildPHIDs(array($build->getPHID()))
+ ->withBuildGenerations(array($generation))
->execute();
-
if ($build_targets) {
$messages = id(new HarbormasterBuildMessageQuery())
->setViewer($viewer)
@@ -435,9 +441,12 @@
$handles[$build->getBuildPlanPHID()]->renderLink());
$properties->addProperty(
+ pht('Restarts'),
+ $build->getBuildGeneration());
+
+ $properties->addProperty(
pht('Status'),
$this->getStatus($build));
-
}
private function getStatus(HarbormasterBuild $build) {
diff --git a/src/applications/harbormaster/engine/HarbormasterBuildEngine.php b/src/applications/harbormaster/engine/HarbormasterBuildEngine.php
--- a/src/applications/harbormaster/engine/HarbormasterBuildEngine.php
+++ b/src/applications/harbormaster/engine/HarbormasterBuildEngine.php
@@ -100,7 +100,7 @@
private function updateBuild(HarbormasterBuild $build) {
if (($build->getBuildStatus() == HarbormasterBuild::STATUS_PENDING) ||
($build->isRestarting())) {
- $this->destroyBuildTargets($build);
+ $this->restartBuild($build);
$build->setBuildStatus(HarbormasterBuild::STATUS_BUILDING);
$build->save();
}
@@ -122,38 +122,28 @@
}
}
- private function destroyBuildTargets(HarbormasterBuild $build) {
- $this->releaseAllArtifacts($build);
-
- $targets = id(new HarbormasterBuildTargetQuery())
- ->setViewer($this->getViewer())
- ->withBuildPHIDs(array($build->getPHID()))
- ->execute();
+ private function restartBuild(HarbormasterBuild $build) {
- if (!$targets) {
- return;
- }
-
- $target_phids = mpull($targets, 'getPHID');
+ // We're restarting the build, so release all previous artifacts.
+ $this->releaseAllArtifacts($build);
- $artifacts = id(new HarbormasterBuildArtifactQuery())
- ->setViewer($this->getViewer())
- ->withBuildTargetPHIDs($target_phids)
- ->execute();
+ // Increment the build generation counter on the build.
+ $build->setBuildGeneration($build->getBuildGeneration() + 1);
- foreach ($artifacts as $artifact) {
- $artifact->delete();
- }
+ // TODO: Currently running targets should periodically check their build
+ // generation (which won't have changed) against the build's generation.
+ // If it is different, they should automatically stop what they're doing
+ // and abort.
- foreach ($targets as $target) {
- $target->delete();
- }
+ // Previously we used to delete targets, logs and artifacts here. Instead
+ // leave them around so users can view previous generations of this build.
}
private function updateBuildSteps(HarbormasterBuild $build) {
$targets = id(new HarbormasterBuildTargetQuery())
->setViewer($this->getViewer())
->withBuildPHIDs(array($build->getPHID()))
+ ->withBuildGenerations(array($build->getBuildGeneration()))
->execute();
$this->updateWaitingTargets($targets);
@@ -454,6 +444,7 @@
$targets = id(new HarbormasterBuildTargetQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withBuildPHIDs(array($build->getPHID()))
+ ->withBuildGenerations(array($build->getBuildGeneration()))
->execute();
if (count($targets) === 0) {
diff --git a/src/applications/harbormaster/query/HarbormasterBuildQuery.php b/src/applications/harbormaster/query/HarbormasterBuildQuery.php
--- a/src/applications/harbormaster/query/HarbormasterBuildQuery.php
+++ b/src/applications/harbormaster/query/HarbormasterBuildQuery.php
@@ -122,6 +122,13 @@
$targets = mgroup($targets, 'getBuildPHID');
foreach ($page as $build) {
$build_targets = idx($targets, $build->getPHID(), array());
+
+ foreach ($build_targets as $phid => $target) {
+ if ($target->getBuildGeneration() !== $build->getBuildGeneration()) {
+ unset($build_targets[$phid]);
+ }
+ }
+
$build->attachBuildTargets($build_targets);
}
}
diff --git a/src/applications/harbormaster/query/HarbormasterBuildTargetQuery.php b/src/applications/harbormaster/query/HarbormasterBuildTargetQuery.php
--- a/src/applications/harbormaster/query/HarbormasterBuildTargetQuery.php
+++ b/src/applications/harbormaster/query/HarbormasterBuildTargetQuery.php
@@ -6,6 +6,7 @@
private $ids;
private $phids;
private $buildPHIDs;
+ private $buildGenerations;
private $needBuildSteps;
public function withIDs(array $ids) {
@@ -23,6 +24,11 @@
return $this;
}
+ public function withBuildGenerations(array $build_generations) {
+ $this->buildGenerations = $build_generations;
+ return $this;
+ }
+
public function needBuildSteps($need_build_steps) {
$this->needBuildSteps = $need_build_steps;
return $this;
@@ -67,6 +73,13 @@
$this->buildPHIDs);
}
+ if ($this->buildGenerations) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'buildGeneration in (%Ld)',
+ $this->buildGenerations);
+ }
+
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuild.php b/src/applications/harbormaster/storage/build/HarbormasterBuild.php
--- a/src/applications/harbormaster/storage/build/HarbormasterBuild.php
+++ b/src/applications/harbormaster/storage/build/HarbormasterBuild.php
@@ -6,6 +6,7 @@
protected $buildablePHID;
protected $buildPlanPHID;
protected $buildStatus;
+ protected $buildGeneration;
private $buildable = self::ATTACHABLE;
private $buildPlan = self::ATTACHABLE;
diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php b/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php
--- a/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php
+++ b/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php
@@ -12,6 +12,7 @@
protected $targetStatus;
protected $dateStarted;
protected $dateCompleted;
+ protected $buildGeneration;
const STATUS_PENDING = 'target/pending';
const STATUS_BUILDING = 'target/building';
@@ -82,7 +83,8 @@
->setClassName($build_step->getClassName())
->setDetails($build_step->getDetails())
->setTargetStatus(self::STATUS_PENDING)
- ->setVariables($variables);
+ ->setVariables($variables)
+ ->setBuildGeneration($build->getBuildGeneration());
}
public function getConfiguration() {

File Metadata

Mime Type
text/plain
Expires
Sat, May 18, 1:23 AM (2 w, 15 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6287676
Default Alt Text
D10321.diff (7 KB)

Event Timeline