diff options
author | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2018-08-30 10:48:38 +0200 |
---|---|---|
committer | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2018-08-30 10:48:38 +0200 |
commit | cf4898674735a733d8af4b1b2f96202c81062d21 (patch) | |
tree | d47bd1080e098c523687de0f5c2cf64d8a1499c2 /controller-server | |
parent | 389c149b8f1a1f27ae6b060f6ffa8958daccec5b (diff) |
Simplify and make available some deployment trigger logic
Diffstat (limited to 'controller-server')
2 files changed, 25 insertions, 10 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTrigger.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTrigger.java index c2920bc08eb..becef782519 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTrigger.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTrigger.java @@ -345,7 +345,7 @@ public class DeploymentTrigger { } /** Returns whether job can trigger at given instant */ - private boolean triggerAt(Instant instant, JobType job, Versions versions, Application application) { + public boolean triggerAt(Instant instant, JobType job, Versions versions, Application application) { Optional<JobStatus> jobStatus = application.deploymentJobs().statusOf(job); if (!jobStatus.isPresent()) return true; if (jobStatus.get().isSuccess()) return true; // Success @@ -410,7 +410,7 @@ public class DeploymentTrigger { * change for the application downgrades the deployment, which is an acknowledgement that the deployed * version is broken somehow, such that the job may be locked in failure until a new version is released. */ - private boolean isComplete(Change change, Application application, JobType jobType) { + public boolean isComplete(Change change, Application application, JobType jobType) { Optional<Deployment> existingDeployment = deploymentFor(application, jobType); return successOn(application, jobType, Versions.from(change, application, existingDeployment, controller.systemVersion())).isPresent() || jobType.isProduction() @@ -427,18 +427,20 @@ public class DeploymentTrigger { } private boolean isTested(Application application, Versions versions) { - return testedAt(application, versions).isPresent() || alreadyTriggered(application, versions); + return testedIn(application, systemTest, versions) + && testedIn(application, stagingTest, versions) + || alreadyTriggered(application, versions); } - private Optional<Instant> testedAt(Application application, Versions versions) { - Optional<JobRun> testRun = successOn(application, systemTest, versions); - Optional<JobRun> stagingRun = successOn(application, stagingTest, versions) - .filter(versions::sourcesMatchIfPresent); - return max(testRun.map(JobRun::at), stagingRun.map(JobRun::at)) - .filter(__ -> testRun.isPresent() && stagingRun.isPresent()); + public boolean testedIn(Application application, JobType testType, Versions versions) { + if (testType == systemTest) + return successOn(application, systemTest, versions).isPresent(); + if (testType == stagingTest) + return successOn(application, stagingTest, versions).filter(versions::sourcesMatchIfPresent).isPresent(); + throw new IllegalArgumentException(testType + " is not a test job!"); } - private boolean alreadyTriggered(Application application, Versions versions) { + public boolean alreadyTriggered(Application application, Versions versions) { return application.deploymentJobs().jobStatus().values().stream() .filter(job -> job.type().isProduction()) .anyMatch(job -> job.lastTriggered() diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/Versions.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/Versions.java index 1ec64e1b3d6..f146dd57885 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/Versions.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/Versions.java @@ -66,6 +66,19 @@ public class Versions { sourceApplication.equals(jobRun.sourceApplication())); } + /** Returns whether source versions are present and match those of the given job other versions. */ + public boolean sourcesMatchIfPresent(Versions versions) { + return ( ! sourcePlatform.filter(version -> ! version.equals(targetPlatform)).isPresent() || + sourcePlatform.equals(versions.sourcePlatform())) && + ( ! sourceApplication.filter(version -> ! version.equals(targetApplication)).isPresent() || + sourceApplication.equals(versions.sourceApplication())); + } + + public boolean targetsMatch(Versions versions) { + return targetPlatform.equals(versions.targetPlatform()) && + targetApplication.equals(versions.targetApplication()); + } + public boolean targetsMatch(JobStatus.JobRun jobRun) { return targetPlatform.equals(jobRun.platform()) && targetApplication.equals(jobRun.application()); |