aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Marius Venstad <jvenstad@yahoo-inc.com>2018-01-05 12:32:09 +0100
committerJon Marius Venstad <jvenstad@yahoo-inc.com>2018-01-05 12:32:09 +0100
commit7a1e1667753c77a0214a1e0d475cf4bac0627f3b (patch)
treef626c54be50de44f5cf62b2363225c9284108586
parent1122a0a8945c41703af2d746d927f30273c3f678 (diff)
Moved mock to stubs and removed unused code (putting it in a different branch)
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockBuildService.java15
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/CuratorDb.java2
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggererTest.java2
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/MockBuildService.java26
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/MockTimeline.java108
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/MockTimelineBuildService.java170
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java2
7 files changed, 18 insertions, 307 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockBuildService.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockBuildService.java
new file mode 100644
index 00000000000..786a26a2330
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockBuildService.java
@@ -0,0 +1,15 @@
+package com.yahoo.vespa.hosted.controller.api.integration.stubs;
+
+import com.yahoo.vespa.hosted.controller.api.integration.BuildService;
+
+/**
+ * @author jvenstad
+ */
+public class MockBuildService implements BuildService {
+
+ @Override
+ public boolean trigger(BuildJob buildJob) {
+ return true;
+ }
+
+}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/CuratorDb.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/CuratorDb.java
index cd7d630b4f2..caf2af5114c 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/CuratorDb.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/CuratorDb.java
@@ -133,7 +133,7 @@ public class CuratorDb {
return jobQueueSerializer.fromJson(data.get());
}
catch (RuntimeException e) {
- log.log(Level.WARNING, "Error reading job queue, deleting inactive state");
+ log.log(Level.WARNING, "Error reading job queue of type '" + jobType.jobName() + "'; deleting it.");
writeJobQueue(jobType, Collections::emptyIterator);
return new ArrayDeque<>();
}
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggererTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggererTest.java
index f7e99f69ff7..c93e1375db0 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggererTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggererTest.java
@@ -58,7 +58,7 @@ public class DeploymentTriggererTest {
tester.deploymentQueue().addJob(app3, DeploymentJobs.JobType.productionUsWest1, false);
triggerer.maintain();
- assertEquals("One of each capacity constrained job and production jobs not for app2 are triggered after one maintenance run.",
+ assertEquals("One system test job and all production jobs not for app2 are triggered after one maintenance run.",
Arrays.asList(new BuildJob(project1, DeploymentJobs.JobType.systemTest.jobName()),
new BuildJob(project1, DeploymentJobs.JobType.productionUsWest1.jobName()),
new BuildJob(project3, DeploymentJobs.JobType.productionUsWest1.jobName())),
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/MockBuildService.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/MockBuildService.java
deleted file mode 100644
index 33e396cc17c..00000000000
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/MockBuildService.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.yahoo.vespa.hosted.controller.deployment;
-
-import com.yahoo.config.provision.ApplicationId;
-import com.yahoo.vespa.hosted.controller.ApplicationController;
-import com.yahoo.vespa.hosted.controller.api.integration.BuildService;
-import com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobError;
-import com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobReport;
-import com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType;
-
-import java.util.HashSet;
-import java.util.Optional;
-import java.util.Set;
-
-import static com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobError.unknown;
-
-/**
- * @author jvenstad
- */
-public class MockBuildService implements BuildService {
-
- @Override
- public boolean trigger(BuildJob buildJob) {
- return true;
- }
-
-}
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/MockTimeline.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/MockTimeline.java
deleted file mode 100644
index 8746c9b8c06..00000000000
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/MockTimeline.java
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.hosted.controller.deployment;
-
-import com.yahoo.test.ManualClock;
-
-import java.time.Duration;
-import java.time.Instant;
-import java.time.temporal.ChronoUnit;
-import java.util.Comparator;
-import java.util.PriorityQueue;
-
-/**
- * Simulates concurrent series of events where time is a significant factor.
- *
- * Each event is modelled as a runnable and a time at which to run.
- * A priority queue keeps all pending events, sorted on when they will run.
- * A manual clock is used to keep the time, and is advanced to the point in
- * time where an event will happen, right before running the event.
- * For events with exactly the same time of happening, the order is undefined.
- *
- * An event may be added with a fixed time at which to run, or with a delay
- * relative to the current time in the timeline. The latter can be used to
- * chain several events together, by letting each event add its successor.
- * The time may similarly be advanced to a given instant, or by a given duration.
- *
- * @author jvenstad
- */
-public class MockTimeline {
-
- private final ManualClock clock;
- private final PriorityQueue<Event> events;
-
- public MockTimeline(ManualClock clock) {
- this.events = new PriorityQueue<>(Comparator.comparing(Event::at));
- this.clock = clock;
- }
-
- /** Makes the given event happen at the given instant. */
- public void at(Instant instant, Runnable event) {
- if (instant.isBefore(now()))
- throw new IllegalArgumentException("The flow of time runs only one way, my friend.");
- events.add(new Event(instant, event));
- }
-
- /** Makes the given event happen after the given delay. */
- public void in(Duration delay, Runnable event) {
- at(now().plus(delay), event);
- }
-
- /** Makes the given event happen with the given period, starting with the given delay from now. */
- public void every(Duration period, Duration delay, Runnable event) {
- in(delay, () -> {
- every(period, event);
- event.run();
- });
- }
-
- /** Makes the given event happen with the given period, starting with one period delay from now. */
- public void every(Duration period, Runnable event) {
- every(period, period, event);
- }
-
- /** Returns the current time, as measured by the internal clock. */
- public Instant now() {
- return clock.instant();
- }
-
- /** Returns whether pending events remain in the timeline. */
- public boolean hasNext() {
- return ! events.isEmpty();
- }
-
- /** Advances time to the next event, let it happen, and return the time of this event. */
- public Instant next() {
- Event event = events.poll();
- clock.advance(Duration.ofMillis(now().until(event.at(), ChronoUnit.MILLIS)));
- event.happen();
- return event.at();
- }
-
- /** Advances the time until the given instant, letting all events from now to then happen. */
- public void advance(Instant until) {
- at(until, () -> {});
- while (next() != until);
- }
-
- /** Advances the time by the given duration, letting all events from now to then happen. */
- public void advance(Duration duration) {
- advance(now().plus(duration));
- }
-
-
- private static class Event {
-
- private final Instant at;
- private final Runnable event;
-
- private Event(Instant at, Runnable event) {
- this.at = at;
- this.event = event;
- }
-
- public Instant at() { return at; }
- public void happen() { event.run(); }
-
- }
-
-}
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/MockTimelineBuildService.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/MockTimelineBuildService.java
deleted file mode 100644
index 3bc015d9580..00000000000
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/MockTimelineBuildService.java
+++ /dev/null
@@ -1,170 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.hosted.controller.deployment;
-
-import com.yahoo.vespa.hosted.controller.ApplicationController;
-import com.yahoo.vespa.hosted.controller.ControllerTester;
-import com.yahoo.config.provision.ApplicationId;
-import com.yahoo.vespa.hosted.controller.api.integration.BuildService;
-import com.yahoo.vespa.hosted.controller.application.DeploymentJobs;
-import com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobError;
-import com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType;
-
-import java.time.Duration;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-import java.util.function.Supplier;
-
-import static com.yahoo.vespa.hosted.controller.deployment.MockTimelineBuildService.JobRunStatus.ENQUEUED;
-import static com.yahoo.vespa.hosted.controller.deployment.MockTimelineBuildService.JobRunStatus.RUNNING;
-
-/**
- * Simulates enqueueing of build jobs in an external build service.
- *
- * The external build service simulated here allows only one concurrent execution of each job,
- * and enqueueing a job which is currently running makes this job run one more time when finished,
- * regardless of the number of times it is enqueued.
- *
- * @author jvenstad
- */
-public class MockTimelineBuildService implements BuildService {
-
- private final ApplicationController applications;
- private final MockTimeline timeline;
- private final Map<String, Job> jobs;
- private final Map<String, JobRunStatus> jobStatuses;
-
- public MockTimelineBuildService(ControllerTester tester, MockTimeline timeline) {
- this.applications = tester.controller().applications();
- this.timeline = timeline;
- jobs = new HashMap<>();
- jobStatuses = new HashMap<>();
- }
-
- /** Simulates the triggering of a Screwdriver job, where jobs are enqueued if already running. */
- @Override
- public boolean trigger(BuildJob buildJob) {
- String key = buildJob.jobName() + "@" + buildJob.projectId();
- System.err.println(timeline.now() + ": Asked to trigger " + key);
-
- if ( ! jobStatuses.containsKey(key))
- start(key);
- else
- jobStatuses.put(key, ENQUEUED);
-
- return true;
- }
-
- /** Simulates the internal triggering of Screwdriver, where only one instance is run at a time. */
- private void start(String key) {
- jobStatuses.put(key, RUNNING);
- Job job = jobs.get(key);
- if (job == null)
- return;
-
- timeline.in(job.duration, () -> {
- job.outcome();
- if (jobStatuses.get(key) == ENQUEUED)
- start(key);
- else
- jobStatuses.remove(key);
- });
- System.err.println(timeline.now() + ": Triggered " + key + "; it will finish at " + timeline.now().plus(job.duration));
- }
-
- /** Add job to the set of Job objects we have information about. */
- private void add(Job job) {
- jobs.put(job.buildJob().jobName() + "@" + job.buildJob().projectId(), job);
- }
-
- /** Add project to the set of Project objects we have information about. */
- private void add(Project project) {
- project.jobs.values().forEach(this::add);
- }
-
- // TODO: Replace with something that relies on ApplicationPackage.
- /** Make a Project with the given settings, modify it if desired, and add() it its jobs to the pool of known ones. */
- public Project project(ApplicationId applicationId, Long projectId, Duration duration, Supplier<JobError> error) {
- return new Project(applicationId, projectId, duration, error);
- }
-
-
- /** Convenience creator for many jobs belonging to the same project. Jobs can be modified independently after creation. */
- class Project {
-
- private final ApplicationId applicationId;
- private final Long projectId;
- private final Map<JobType, Job> jobs;
-
- private Project(ApplicationId applicationId, Long projectId, Duration duration, Supplier<JobError> error) {
- this.applicationId = applicationId;
- this.projectId = projectId;
-
- jobs = new EnumMap<>(JobType.class);
-
- for (JobType jobType : JobType.values())
- jobs.put(jobType, new Job(applicationId, projectId, jobType, duration, error));
- }
-
- /** Set duration for jobType of this Project. */
- public Project set(Duration duration, JobType jobType) {
- jobs.compute(jobType, (__, job) -> new Job(applicationId, projectId, jobType, duration, job.error));
- return this;
- }
-
- /** Set success for jobType of this Project. */
- public Project set(Supplier<JobError> error, JobType jobType) {
- jobs.compute(jobType, (__, job) -> new Job(applicationId, projectId, jobType, job.duration, error));
- return this;
- }
-
- /** Add the Job objects of this Project to the pool of known jobs for this MockBuildService. */
- public void add() {
- MockTimelineBuildService.this.add(this);
- }
-
- }
-
-
- /** Representation of a simulated job -- most noteworthy is the outcome(), which is used to simulate a job completing. */
- private class Job {
-
- private final ApplicationId applicationId;
- private final Long projectId;
- private final JobType jobType;
- private final Duration duration;
- private final Supplier<JobError> error;
-
- private long buildNumber = 0;
-
- private Job(ApplicationId applicationId, Long projectId, JobType jobType, Duration duration, Supplier<JobError> error) {
- this.applicationId = applicationId;
- this.projectId = projectId;
- this.jobType = jobType;
- this.duration = duration;
- this.error = error;
- }
-
- private void outcome() {
- if (error == null) return; // null JobError supplier means the job doesn't report back, i.e., is aborted.
-
- JobError jobError = this.error.get();
- System.err.println(timeline.now() + ": Job " + projectId + ":" + jobType + " reports " + (jobError == null ? " success " : jobError));
- applications.notifyJobCompletion(new DeploymentJobs.JobReport(applicationId,
- jobType,
- projectId,
- ++buildNumber, // TODO: Increase this on triggering instead.
- Optional.ofNullable(jobError)));
- }
-
- private BuildJob buildJob() { return new BuildJob(projectId, jobType.jobName()); }
-
- }
-
- enum JobRunStatus {
- ENQUEUED,
- RUNNING
- }
-
-}
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java
index e8cb254b9fa..70564a1e85b 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java
@@ -59,7 +59,7 @@ public class ControllerContainerTest {
" <component id='com.yahoo.vespa.hosted.controller.ConfigServerClientMock'/>\n" +
" <component id='com.yahoo.vespa.hosted.controller.ZoneRegistryMock'/>\n" +
" <component id='com.yahoo.vespa.hosted.controller.Controller'/>\n" +
- " <component id='com.yahoo.vespa.hosted.controller.deployment.MockBuildService'/>\n" +
+ " <component id='com.yahoo.vespa.hosted.controller.api.integration.stubs.MockBuildService'/>\n" +
" <component id='com.yahoo.vespa.hosted.controller.ConfigServerProxyMock'/>\n" +
" <component id='com.yahoo.vespa.hosted.controller.integration.MockMetricsService'/>\n" +
" <component id='com.yahoo.vespa.hosted.controller.maintenance.ControllerMaintenance'/>\n" +