summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Marius Venstad <jvenstad@yahoo-inc.com>2018-11-01 14:58:59 +0100
committerJon Marius Venstad <venstad@gmail.com>2018-11-01 21:28:51 +0100
commit68ef83a3be91da41dcf0a2bb389f9eeedcc45b50 (patch)
treeb37788deea2d2a4f6607c2ae96f9d038636150f4
parentb6f8062adb3edd1153872772a48f25bb3d6edbe9 (diff)
Add pausedUntil field in JobStatus
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/DeploymentJobs.java9
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/JobStatus.java50
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializer.java14
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java3
4 files changed, 49 insertions, 27 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/DeploymentJobs.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/DeploymentJobs.java
index 3703616cb68..6e9318042b5 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/DeploymentJobs.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/DeploymentJobs.java
@@ -71,6 +71,15 @@ public class DeploymentJobs {
return new DeploymentJobs(projectId, status, issueId, builtInternally);
}
+ public DeploymentJobs withPause(JobType jobType, OptionalLong pausedUntil) {
+ Map<JobType, JobStatus> status = new LinkedHashMap<>(this.status);
+ status.compute(jobType, (__, job) -> {
+ if (job == null) job = JobStatus.initial(jobType);
+ return job.withPause(pausedUntil);
+ });
+ return new DeploymentJobs(projectId, status, issueId, builtInternally);
+ }
+
public DeploymentJobs withProjectId(OptionalLong projectId) {
return new DeploymentJobs(projectId, status, issueId, builtInternally);
}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/JobStatus.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/JobStatus.java
index a06a3e00340..c1d6095bcbb 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/JobStatus.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/JobStatus.java
@@ -7,6 +7,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType;
import java.time.Instant;
import java.util.Objects;
import java.util.Optional;
+import java.util.OptionalLong;
import static java.util.Objects.requireNonNull;
@@ -25,6 +26,7 @@ public class JobStatus {
private final Optional<JobRun> lastCompleted;
private final Optional<JobRun> firstFailing;
private final Optional<JobRun> lastSuccess;
+ private final OptionalLong pausedUntil;
private final Optional<DeploymentJobs.JobError> jobError;
@@ -34,27 +36,23 @@ public class JobStatus {
*/
public JobStatus(JobType type, Optional<DeploymentJobs.JobError> jobError,
Optional<JobRun> lastTriggered, Optional<JobRun> lastCompleted,
- Optional<JobRun> firstFailing, Optional<JobRun> lastSuccess) {
- requireNonNull(type, "jobType cannot be null");
- requireNonNull(jobError, "jobError cannot be null");
- requireNonNull(lastTriggered, "lastTriggered cannot be null");
- requireNonNull(lastCompleted, "lastCompleted cannot be null");
- requireNonNull(firstFailing, "firstFailing cannot be null");
- requireNonNull(lastSuccess, "lastSuccess cannot be null");
-
- this.type = type;
- this.jobError = jobError;
+ Optional<JobRun> firstFailing, Optional<JobRun> lastSuccess,
+ OptionalLong pausedUntil) {
+ this.type = requireNonNull(type, "jobType cannot be null");
+ this.jobError = requireNonNull(jobError, "jobError cannot be null");
// Never say we triggered component because we don't:
- this.lastTriggered = type == JobType.component ? Optional.empty() : lastTriggered;
- this.lastCompleted = lastCompleted;
- this.firstFailing = firstFailing;
- this.lastSuccess = lastSuccess;
+ this.lastTriggered = type == JobType.component ? Optional.empty() : requireNonNull(lastTriggered, "lastTriggered cannot be null");
+ this.lastCompleted = requireNonNull(lastCompleted, "lastCompleted cannot be null");
+ this.firstFailing = requireNonNull(firstFailing, "firstFailing cannot be null");
+ this.lastSuccess = requireNonNull(lastSuccess, "lastSuccess cannot be null");
+ this.pausedUntil = requireNonNull(pausedUntil, "pausedUntil cannot be null");
+
}
/** Returns an empty job status */
public static JobStatus initial(JobType type) {
- return new JobStatus(type, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
+ return new JobStatus(type, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), OptionalLong.empty());
}
public JobStatus withTriggering(Version platform, ApplicationVersion application, Optional<Deployment> deployment, String reason, Instant triggeredAt) {
@@ -62,7 +60,7 @@ public class JobStatus {
}
public JobStatus withTriggering(JobRun jobRun) {
- return new JobStatus(type, jobError, Optional.of(jobRun), lastCompleted, firstFailing, lastSuccess);
+ return new JobStatus(type, jobError, Optional.of(jobRun), lastCompleted, firstFailing, lastSuccess, pausedUntil);
}
public JobStatus withCompletion(long runId, Optional<DeploymentJobs.JobError> jobError, Instant completion) {
@@ -80,7 +78,11 @@ public class JobStatus {
firstFailing = Optional.empty();
}
- return new JobStatus(type, jobError, lastTriggered, Optional.of(completion), firstFailing, lastSuccess);
+ return new JobStatus(type, jobError, lastTriggered, Optional.of(completion), firstFailing, lastSuccess, pausedUntil);
+ }
+
+ public JobStatus withPause(OptionalLong pausedUntil) {
+ return new JobStatus(type, jobError, lastTriggered, lastCompleted, firstFailing, lastSuccess, pausedUntil);
}
public JobType type() { return type; }
@@ -113,17 +115,21 @@ public class JobStatus {
/** Returns the run when this last succeeded, or empty if it has never succeeded */
public Optional<JobRun> lastSuccess() { return lastSuccess; }
+ /** Returns the time until which this job is paused, if currently paused */
+ public OptionalLong pausedUntil() { return pausedUntil; }
+
@Override
public String toString() {
return "job status of " + type + "[ " +
"last triggered: " + lastTriggered.map(JobRun::toString).orElse("(never)") +
", last completed: " + lastCompleted.map(JobRun::toString).orElse("(never)") +
", first failing: " + firstFailing.map(JobRun::toString).orElse("(not failing)") +
- ", lastSuccess: " + lastSuccess.map(JobRun::toString).orElse("(never)") + "]";
+ ", lastSuccess: " + lastSuccess.map(JobRun::toString).orElse("(never)") +
+ ", pausedUntil: " + (pausedUntil.isPresent() ? pausedUntil.getAsLong() : "(not paused)") + "]";
}
@Override
- public int hashCode() { return Objects.hash(type, jobError, lastTriggered, lastCompleted, firstFailing, lastSuccess); }
+ public int hashCode() { return Objects.hash(type, jobError, lastTriggered, lastCompleted, firstFailing, lastSuccess, pausedUntil); }
@Override
public boolean equals(Object o) {
@@ -135,7 +141,8 @@ public class JobStatus {
Objects.equals(lastTriggered, other.lastTriggered) &&
Objects.equals(lastCompleted, other.lastCompleted) &&
Objects.equals(firstFailing, other.firstFailing) &&
- Objects.equals(lastSuccess, other.lastSuccess);
+ Objects.equals(lastSuccess, other.lastSuccess) &&
+ Objects.equals(pausedUntil, other.pausedUntil);
}
/** Information about a particular triggering or completion of a run of a job. This is immutable. */
@@ -202,7 +209,7 @@ public class JobStatus {
@Override
public boolean equals(Object o) {
if (this == o) return true;
- if (!(o instanceof JobRun)) return false;
+ if ( ! (o instanceof JobRun)) return false;
JobRun run = (JobRun) o;
@@ -224,6 +231,7 @@ public class JobStatus {
result = 31 * result + at.hashCode();
return result;
}
+
}
}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializer.java
index 7b615249a65..365d74babb5 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializer.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializer.java
@@ -95,6 +95,7 @@ public class ApplicationSerializer {
private final String lastCompletedField = "lastCompleted";
private final String firstFailingField = "firstFailing";
private final String lastSuccessField = "lastSuccess";
+ private final String pausedUntilField = "pausedUntil";
// JobRun fields
private final String jobRunIdField = "id";
@@ -252,6 +253,7 @@ public class ApplicationSerializer {
jobStatus.lastCompleted().ifPresent(run -> jobRunToSlime(run, object, lastCompletedField));
jobStatus.lastSuccess().ifPresent(run -> jobRunToSlime(run, object, lastSuccessField));
jobStatus.firstFailing().ifPresent(run -> jobRunToSlime(run, object, firstFailingField));
+ jobStatus.pausedUntil().ifPresent(until -> object.setLong(pausedUntilField, until));
}
private void jobRunToSlime(JobStatus.JobRun jobRun, Cursor parent, String jobRunObjectName) {
@@ -440,11 +442,13 @@ public class ApplicationSerializer {
if (object.field(errorField).valid())
jobError = Optional.of(JobError.valueOf(object.field(errorField).asString()));
- return Optional.of(new JobStatus(jobType.get(), jobError,
- jobRunFromSlime(object.field(lastTriggeredField)),
- jobRunFromSlime(object.field(lastCompletedField)),
- jobRunFromSlime(object.field(firstFailingField)),
- jobRunFromSlime(object.field(lastSuccessField))));
+ return Optional.of(new JobStatus(jobType.get(),
+ jobError,
+ jobRunFromSlime(object.field(lastTriggeredField)),
+ jobRunFromSlime(object.field(lastCompletedField)),
+ jobRunFromSlime(object.field(firstFailingField)),
+ jobRunFromSlime(object.field(lastSuccessField)),
+ optionalLong(object.field(pausedUntilField))));
}
private Optional<JobStatus.JobRun> jobRunFromSlime(Inspector object) {
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java
index 094f8989530..e06578a545f 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java
@@ -83,7 +83,8 @@ public class ApplicationSerializerTest {
statusList.add(JobStatus.initial(JobType.systemTest)
.withTriggering(Version.fromString("5.6.7"), ApplicationVersion.unknown, empty(), "Test", Instant.ofEpochMilli(7))
- .withCompletion(30, empty(), Instant.ofEpochMilli(8)));
+ .withCompletion(30, empty(), Instant.ofEpochMilli(8))
+ .withPause(OptionalLong.of(1L << 32)));
statusList.add(JobStatus.initial(JobType.stagingTest)
.withTriggering(Version.fromString("5.6.6"), ApplicationVersion.unknown, empty(), "Test 2", Instant.ofEpochMilli(5))
.withCompletion(11, Optional.of(JobError.unknown), Instant.ofEpochMilli(6)));