diff options
author | jonmv <venstad@gmail.com> | 2022-06-09 12:30:10 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-06-10 12:34:05 +0200 |
commit | 073c4eec84043026e83803e0138660c184f96d8c (patch) | |
tree | ecb5778c232f2beeddf182edadd2ac89dc51e97e | |
parent | e7cac19f671e32b168357e33710f25062b590f24 (diff) |
Eliminate wrong use of optional
7 files changed, 91 insertions, 90 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java index 3105adb2488..894b175961b 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java @@ -157,7 +157,7 @@ public class InternalStepRunner implements StepRunner { } private Optional<RunStatus> deployInitialReal(RunId id, DualLogger logger) { - Versions versions = controller.jobController().run(id).get().versions(); + Versions versions = controller.jobController().run(id).versions(); logger.log("Deploying platform version " + versions.sourcePlatform().orElse(versions.targetPlatform()) + " and application " + @@ -166,16 +166,16 @@ public class InternalStepRunner implements StepRunner { } private Optional<RunStatus> deployReal(RunId id, DualLogger logger) { - Versions versions = controller.jobController().run(id).get().versions(); + Versions versions = controller.jobController().run(id).versions(); logger.log("Deploying platform version " + versions.targetPlatform() + " and application " + versions.targetRevision() + " ..."); return deployReal(id, false, logger); } private Optional<RunStatus> deployReal(RunId id, boolean setTheStage, DualLogger logger) { - Optional<X509Certificate> testerCertificate = controller.jobController().run(id).get().testerCertificate(); + Optional<X509Certificate> testerCertificate = controller.jobController().run(id).testerCertificate(); return deploy(() -> controller.applications().deploy(id.job(), setTheStage), - controller.jobController().run(id).get() + controller.jobController().run(id) .stepInfo(setTheStage ? deployInitialReal : deployReal).get() .startTime().get(), logger) @@ -184,8 +184,8 @@ public class InternalStepRunner implements StepRunner { if ( ! useTesterCertificate(id) || result != running) return true; // If tester cert, ensure real is deployed with the tester cert whose key was successfully deployed. - return controller.jobController().run(id).get().stepStatus(deployTester).get() == succeeded - && testerCertificate.equals(controller.jobController().run(id).get().testerCertificate()); + return controller.jobController().run(id).stepStatus(deployTester).get() == succeeded + && testerCertificate.equals(controller.jobController().run(id).testerCertificate()); }); } @@ -196,7 +196,7 @@ public class InternalStepRunner implements StepRunner { testerPackage(id), id.type().zone(), platform), - controller.jobController().run(id).get() + controller.jobController().run(id) .stepInfo(deployTester).get() .startTime().get(), logger); @@ -287,10 +287,10 @@ public class InternalStepRunner implements StepRunner { return Optional.of(installationFailed); } - Versions versions = controller.jobController().run(id).get().versions(); + Versions versions = controller.jobController().run(id).versions(); Version platform = setTheStage ? versions.sourcePlatform().orElse(versions.targetPlatform()) : versions.targetPlatform(); - Run run = controller.jobController().run(id).get(); + Run run = controller.jobController().run(id); Optional<ServiceConvergence> services = controller.serviceRegistry().configServer().serviceConvergence(new DeploymentId(id.application(), id.type().zone()), Optional.of(platform)); if (services.isEmpty()) { @@ -409,14 +409,14 @@ public class InternalStepRunner implements StepRunner { } private Version testerPlatformVersion(RunId id) { - Version targetPlatform = controller.jobController().run(id).get().versions().targetPlatform(); + Version targetPlatform = controller.jobController().run(id).versions().targetPlatform(); Version systemVersion = controller.readSystemVersion(); boolean incompatible = controller.applications().versionCompatibility(id.application()).refuse(targetPlatform, systemVersion); return incompatible || application(id.application()).change().isPinned() ? targetPlatform : systemVersion; } private Optional<RunStatus> installTester(RunId id, DualLogger logger) { - Run run = controller.jobController().run(id).get(); + Run run = controller.jobController().run(id); Version platform = testerPlatformVersion(id); ZoneId zone = id.type().zone(); ApplicationId testerId = id.tester().id(); @@ -622,7 +622,7 @@ public class InternalStepRunner implements StepRunner { return Optional.of(error); } - Optional<X509Certificate> testerCertificate = controller.jobController().run(id).get().testerCertificate(); + Optional<X509Certificate> testerCertificate = controller.jobController().run(id).testerCertificate(); if (testerCertificate.isPresent()) { try { testerCertificate.get().checkValidity(Date.from(controller.clock().instant())); @@ -684,7 +684,7 @@ public class InternalStepRunner implements StepRunner { } // Hitting a config server which doesn't have this particular app loaded causes a 404. catch (ConfigServerException e) { - Instant doom = controller.jobController().run(id).get().stepInfo(copyVespaLogs).get().startTime().get() + Instant doom = controller.jobController().run(id).stepInfo(copyVespaLogs).get().startTime().get() .plus(Duration.ofMinutes(3)); if (e.code() == ConfigServerException.ErrorCode.NOT_FOUND && controller.clock().instant().isBefore(doom)) { logger.log(INFO, "Found no logs, but will retry"); @@ -710,7 +710,7 @@ public class InternalStepRunner implements StepRunner { } catch (RuntimeException e) { logger.log(WARNING, "Failed deleting application " + id.application(), e); - Instant startTime = controller.jobController().run(id).get().stepInfo(deactivateReal).get().startTime().get(); + Instant startTime = controller.jobController().run(id).stepInfo(deactivateReal).get().startTime().get(); return startTime.isBefore(controller.clock().instant().minus(Duration.ofHours(1))) ? Optional.of(error) : Optional.empty(); @@ -725,7 +725,7 @@ public class InternalStepRunner implements StepRunner { } catch (RuntimeException e) { logger.log(WARNING, "Failed deleting tester of " + id.application(), e); - Instant startTime = controller.jobController().run(id).get().stepInfo(deactivateTester).get().startTime().get(); + Instant startTime = controller.jobController().run(id).stepInfo(deactivateTester).get().startTime().get(); return startTime.isBefore(controller.clock().instant().minus(Duration.ofHours(1))) ? Optional.of(error) : Optional.empty(); @@ -749,7 +749,7 @@ public class InternalStepRunner implements StepRunner { return Optional.of(error); } catch (RuntimeException e) { - Instant start = controller.jobController().run(id).get().stepInfo(report).get().startTime().get(); + Instant start = controller.jobController().run(id).stepInfo(report).get().startTime().get(); return (controller.clock().instant().isAfter(start.plusSeconds(180))) ? Optional.empty() : Optional.of(error); @@ -871,7 +871,7 @@ public class InternalStepRunner implements StepRunner { private boolean timedOut(RunId id, Deployment deployment, Duration defaultTimeout) { // TODO jonmv: This is a workaround for new deployment writes not yet being visible in spite of Curator locking. // TODO Investigate what's going on here, and remove this workaround. - Run run = controller.jobController().run(id).get(); + Run run = controller.jobController().run(id); if ( ! controller.system().isCd() && run.start().isAfter(deployment.at())) return false; @@ -887,7 +887,7 @@ public class InternalStepRunner implements StepRunner { /** Returns the application package for the tester application, assembled from a generated config, fat-jar and services.xml. */ private ApplicationPackage testerPackage(RunId id) { - RevisionId revision = controller.jobController().run(id).get().versions().targetRevision(); + RevisionId revision = controller.jobController().run(id).versions().targetRevision(); DeploymentSpec spec = controller.applications().requireApplication(TenantAndApplicationId.from(id.application())).deploymentSpec(); byte[] testZip = controller.applications().applicationStore().getTester(id.application().tenant(), id.application().application(), revision); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java index 9331c9942b6..3d4a2f40303 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java @@ -47,6 +47,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.NavigableMap; +import java.util.NoSuchElementException; import java.util.Optional; import java.util.OptionalLong; import java.util.Set; @@ -298,11 +299,12 @@ public class JobController { return runs.build(); } - /** Returns the run with the given id, if it exists. */ - public Optional<Run> run(RunId id) { + /** Returns the run with the given id, or throws if no such run exists. */ + public Run run(RunId id) { return runs(id.application(), id.type()).values().stream() .filter(run -> run.id().equals(id)) - .findAny(); + .findAny() + .orElseThrow(() -> new NoSuchElementException("no run with id '" + id + "' exists")); } /** Returns the last run of the given type, for the given application, if one has been run. */ @@ -412,7 +414,7 @@ public class JobController { Deque<Mutex> locks = new ArrayDeque<>(); try { // Ensure no step is still running before we finish the run — report depends transitively on all the other steps. - Run unlockedRun = run(id).get(); + Run unlockedRun = run(id); locks.push(curator.lock(id.application(), id.type(), report)); for (Step step : report.allPrerequisites(unlockedRun.steps().keySet())) locks.push(curator.lock(id.application(), id.type(), step)); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/JobRunner.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/JobRunner.java index b4fac8074aa..94ec4129744 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/JobRunner.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/JobRunner.java @@ -81,7 +81,7 @@ public class JobRunner extends ControllerMaintainer { && controller().clock().instant().isAfter(run.sleepUntil().orElse(run.start()).plus(jobTimeout))) executors.execute(() -> { jobs.abort(run.id(), "job timeout of " + jobTimeout + " reached"); - advance(jobs.run(run.id()).get()); + advance(jobs.run(run.id())); }); else if (run.readySteps().isEmpty()) executors.execute(() -> finish(run.id())); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelper.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelper.java index 80425609aa6..8c49df43c30 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelper.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelper.java @@ -112,8 +112,7 @@ class JobControllerApiHandlerHelper { Slime slime = new Slime(); Cursor detailsObject = slime.setObject(); - Run run = jobController.run(runId) - .orElseThrow(() -> new IllegalStateException("Unknown run '" + runId + "'")); + Run run = jobController.run(runId); detailsObject.setBool("active", ! run.hasEnded()); detailsObject.setString("status", nameOf(run.status())); try { diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentContext.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentContext.java index 27951d95689..b3db4a8b845 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentContext.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentContext.java @@ -355,7 +355,7 @@ public class DeploymentContext { var job = jobId(type); RunId id = currentRun(job).id(); runner.advance(currentRun(job)); - Run run = jobs.run(id).get(); + Run run = jobs.run(id); assertTrue(run.hasFailed()); assertTrue(run.hasEnded()); if (messagePart.isPresent()) { @@ -441,10 +441,10 @@ public class DeploymentContext { RunId id = currentRun(job).id(); - assertEquals(unfinished, jobs.run(id).get().stepStatuses().get(Step.endTests)); + assertEquals(unfinished, jobs.run(id).stepStatuses().get(Step.endTests)); tester.cloud().set(noTests ? Status.NO_TESTS : Status.FAILURE); runner.advance(currentRun(job)); - assertTrue(jobs.run(id).get().hasEnded()); + assertTrue(jobs.run(id).hasEnded()); assertTrue(configServer().nodeRepository().list(job.type().zone(), NodeFilter.all().applications(TesterId.of(instanceId).id())).isEmpty()); return this; @@ -481,7 +481,7 @@ public class DeploymentContext { assertSame(RunStatus.aborted, run.status()); assertFalse(run.hasEnded()); runner.advance(run); - assertTrue(jobs.run(run.id()).get().hasEnded()); + assertTrue(jobs.run(run.id()).hasEnded()); return this; } @@ -493,8 +493,8 @@ public class DeploymentContext { doDeploy(job); tester.clock().advance(Timeouts.of(tester.controller().system()).noNodesDown().plusSeconds(1)); runner.advance(currentRun(job)); - assertTrue(jobs.run(id).get().hasFailed()); - assertTrue(jobs.run(id).get().hasEnded()); + assertTrue(jobs.run(id).hasFailed()); + assertTrue(jobs.run(id).hasEnded()); return this; } @@ -507,8 +507,8 @@ public class DeploymentContext { doUpgrade(job); tester.clock().advance(Timeouts.of(tester.controller().system()).noNodesDown().plusSeconds(1)); runner.advance(currentRun(job)); - assertTrue(jobs.run(id).get().hasFailed()); - assertTrue(jobs.run(id).get().hasEnded()); + assertTrue(jobs.run(id).hasFailed()); + assertTrue(jobs.run(id).hasEnded()); return this; } @@ -540,8 +540,8 @@ public class DeploymentContext { configServer().convergeServices(instanceId, testZone); configServer().convergeServices(testerId.id(), testZone); runner.run(); - assertEquals(unfinished, jobs.run(id).get().stepStatuses().get(Step.endTests)); - assertTrue(jobs.run(id).get().steps().get(Step.endTests).startTime().isPresent()); + assertEquals(unfinished, jobs.run(id).stepStatuses().get(Step.endTests)); + assertTrue(jobs.run(id).steps().get(Step.endTests).startTime().isPresent()); return id; } @@ -571,21 +571,21 @@ public class DeploymentContext { doInstallTester(job); if (job.type().equals(stagingTest)) { // Do the initial deployment and installation of the real application. - assertEquals(unfinished, jobs.run(id).get().stepStatuses().get(Step.installInitialReal)); + assertEquals(unfinished, jobs.run(id).stepStatuses().get(Step.installInitialReal)); tester.configServer().nodeRepository().doUpgrade(deployment, Optional.empty(), tester.configServer().application(job.application(), zone).get().version().get()); configServer().convergeServices(id.application(), zone); runner.advance(currentRun(job)); - assertEquals(succeeded, jobs.run(id).get().stepStatuses().get(Step.installInitialReal)); + assertEquals(succeeded, jobs.run(id).stepStatuses().get(Step.installInitialReal)); // All installation is complete and endpoints are ready, so setup may begin. - assertEquals(succeeded, jobs.run(id).get().stepStatuses().get(Step.installInitialReal)); - assertEquals(succeeded, jobs.run(id).get().stepStatuses().get(Step.installTester)); - assertEquals(succeeded, jobs.run(id).get().stepStatuses().get(Step.startStagingSetup)); + assertEquals(succeeded, jobs.run(id).stepStatuses().get(Step.installInitialReal)); + assertEquals(succeeded, jobs.run(id).stepStatuses().get(Step.installTester)); + assertEquals(succeeded, jobs.run(id).stepStatuses().get(Step.startStagingSetup)); - assertEquals(unfinished, jobs.run(id).get().stepStatuses().get(Step.endStagingSetup)); + assertEquals(unfinished, jobs.run(id).stepStatuses().get(Step.endStagingSetup)); tester.cloud().set(Status.SUCCESS); runner.advance(currentRun(job)); - assertEquals(succeeded, jobs.run(id).get().stepStatuses().get(Step.endStagingSetup)); + assertEquals(succeeded, jobs.run(id).stepStatuses().get(Step.endStagingSetup)); } } @@ -595,7 +595,7 @@ public class DeploymentContext { ZoneId zone = job.type().zone(); DeploymentId deployment = new DeploymentId(job.application(), zone); - assertEquals(unfinished, jobs.run(id).get().stepStatuses().get(Step.installReal)); + assertEquals(unfinished, jobs.run(id).stepStatuses().get(Step.installReal)); configServer().nodeRepository().doUpgrade(deployment, Optional.empty(), tester.configServer().application(job.application(), zone).get().version().get()); runner.advance(currentRun(job)); } @@ -615,15 +615,15 @@ public class DeploymentContext { RunId id = currentRun(job).id(); ZoneId zone = job.type().zone(); - assertEquals(unfinished, jobs.run(id).get().stepStatuses().get(Step.installReal)); + assertEquals(unfinished, jobs.run(id).stepStatuses().get(Step.installReal)); configServer().convergeServices(id.application(), zone); runner.advance(currentRun(job)); if (job.type().environment().isManuallyDeployed()) { - assertEquals(succeeded, jobs.run(id).get().stepStatuses().get(Step.installReal)); - assertTrue(jobs.run(id).get().hasEnded()); + assertEquals(succeeded, jobs.run(id).stepStatuses().get(Step.installReal)); + assertTrue(jobs.run(id).hasEnded()); return; } - assertEquals("Status of " + id, succeeded, jobs.run(id).get().stepStatuses().get(Step.installReal)); + assertEquals("Status of " + id, succeeded, jobs.run(id).stepStatuses().get(Step.installReal)); } /** Installs tester and starts tests. */ @@ -631,13 +631,13 @@ public class DeploymentContext { RunId id = currentRun(job).id(); ZoneId zone = job.type().zone(); - assertEquals(unfinished, jobs.run(id).get().stepStatuses().get(Step.installTester)); + assertEquals(unfinished, jobs.run(id).stepStatuses().get(Step.installTester)); configServer().nodeRepository().doUpgrade(new DeploymentId(TesterId.of(job.application()).id(), zone), Optional.empty(), tester.configServer().application(id.tester().id(), zone).get().version().get()); runner.advance(currentRun(job)); - assertEquals(unfinished, jobs.run(id).get().stepStatuses().get(Step.installTester)); + assertEquals(unfinished, jobs.run(id).stepStatuses().get(Step.installTester)); configServer().convergeServices(TesterId.of(id.application()).id(), zone); runner.advance(currentRun(job)); - assertEquals(succeeded, jobs.run(id).get().stepStatuses().get(Step.installTester)); + assertEquals(succeeded, jobs.run(id).stepStatuses().get(Step.installTester)); runner.advance(currentRun(job)); } @@ -648,15 +648,15 @@ public class DeploymentContext { // All installation is complete and endpoints are ready, so tests may begin. if (job.type().isDeployment()) - assertEquals(succeeded, jobs.run(id).get().stepStatuses().get(Step.installReal)); - assertEquals(succeeded, jobs.run(id).get().stepStatuses().get(Step.installTester)); - assertEquals(succeeded, jobs.run(id).get().stepStatuses().get(Step.startTests)); + assertEquals(succeeded, jobs.run(id).stepStatuses().get(Step.installReal)); + assertEquals(succeeded, jobs.run(id).stepStatuses().get(Step.installTester)); + assertEquals(succeeded, jobs.run(id).stepStatuses().get(Step.startTests)); - assertEquals(unfinished, jobs.run(id).get().stepStatuses().get(Step.endTests)); + assertEquals(unfinished, jobs.run(id).stepStatuses().get(Step.endTests)); tester.cloud().set(Status.SUCCESS); runner.advance(currentRun(job)); - assertTrue(jobs.run(id).get().hasEnded()); - assertFalse(jobs.run(id).get().hasFailed()); + assertTrue(jobs.run(id).hasEnded()); + assertFalse(jobs.run(id).hasFailed()); Instance instance = tester.application(TenantAndApplicationId.from(instanceId)).require(id.application().instance()); assertEquals(job.type().isProduction(), instance.deployments().containsKey(zone)); assertTrue(configServer().nodeRepository().list(zone, NodeFilter.all().applications(TesterId.of(instance.id()).id())).isEmpty()); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTester.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTester.java index 4219c52be20..78e7606d7c6 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTester.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTester.java @@ -136,8 +136,8 @@ public class DeploymentTester { triggerJobs(); for (Run run : jobs.active()) { jobs.abort(run.id(), "DeploymentTester.abortAll"); - runner.advance(jobs.run(run.id()).get()); - assertTrue(jobs.run(run.id()).get().hasEnded()); + runner.advance(jobs.run(run.id())); + assertTrue(jobs.run(run.id()).hasEnded()); } } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java index ae08d1b3a22..d781b1f1d3f 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java @@ -120,19 +120,19 @@ public class InternalStepRunnerTest { HostName host = tester.configServer().hostFor(instanceId, zone); tester.runner().run(); - assertEquals(succeeded, tester.jobs().run(id).get().stepStatuses().get(Step.deployReal)); + assertEquals(succeeded, tester.jobs().run(id).stepStatuses().get(Step.deployReal)); tester.configServer().convergeServices(app.instanceId(), zone); - assertEquals(unfinished, tester.jobs().run(id).get().stepStatuses().get(Step.installReal)); + assertEquals(unfinished, tester.jobs().run(id).stepStatuses().get(Step.installReal)); tester.configServer().nodeRepository().doRestart(app.deploymentIdIn(zone), Optional.of(host)); tester.configServer().nodeRepository().requestReboot(app.deploymentIdIn(zone), Optional.of(host)); tester.runner().run(); - assertEquals(unfinished, tester.jobs().run(id).get().stepStatuses().get(Step.installReal)); + assertEquals(unfinished, tester.jobs().run(id).stepStatuses().get(Step.installReal)); tester.clock().advance(InternalStepRunner.Timeouts.of(system()).noNodesDown().plus(Duration.ofSeconds(1))); tester.runner().run(); - assertEquals(installationFailed, tester.jobs().run(id).get().status()); + assertEquals(installationFailed, tester.jobs().run(id).status()); } @Test @@ -251,7 +251,7 @@ public class InternalStepRunnerTest { @Test public void noTestsThenErrorIsError() { RunId id = app.startSystemTestTests(); - Run run = tester.jobs().run(id).get(); + Run run = tester.jobs().run(id); run = run.with(noTests, new LockedStep(() -> { }, Step.endTests)); assertFalse(run.hasFailed()); run = run.with(RunStatus.error, new LockedStep(() -> { }, Step.deactivateReal)); @@ -264,8 +264,8 @@ public class InternalStepRunnerTest { RunId id = app.startSystemTestTests(); tester.cloud().set(Status.NO_TESTS); tester.runner().run(); - assertEquals(succeeded, tester.jobs().run(id).get().stepStatuses().get(Step.endTests)); - Run run = tester.jobs().run(id).get(); + assertEquals(succeeded, tester.jobs().run(id).stepStatuses().get(Step.endTests)); + Run run = tester.jobs().run(id); assertEquals(noTests, run.status()); } @@ -274,7 +274,7 @@ public class InternalStepRunnerTest { RunId id = app.startSystemTestTests(); tester.cloud().set(TesterCloud.Status.NOT_STARTED); tester.runner().run(); - assertEquals(failed, tester.jobs().run(id).get().stepStatuses().get(Step.endTests)); + assertEquals(failed, tester.jobs().run(id).stepStatuses().get(Step.endTests)); } @Test @@ -288,7 +288,7 @@ public class InternalStepRunnerTest { assertTestLogEntries(id, Step.endTests, new LogEntry(lastId + 1, Instant.ofEpochMilli(321), error, "Failure!"), new LogEntry(lastId + 2, tester.clock().instant(), info, "Tests failed.")); - assertEquals(failed, tester.jobs().run(id).get().stepStatuses().get(Step.endTests)); + assertEquals(failed, tester.jobs().run(id).stepStatuses().get(Step.endTests)); } @Test @@ -299,7 +299,7 @@ public class InternalStepRunnerTest { long lastId = tester.jobs().details(id).get().lastId().getAsLong(); tester.runner().run(); - assertEquals(failed, tester.jobs().run(id).get().stepStatuses().get(Step.endTests)); + assertEquals(failed, tester.jobs().run(id).stepStatuses().get(Step.endTests)); assertTestLogEntries(id, Step.endTests, new LogEntry(lastId + 1, Instant.ofEpochMilli(123), error, "Error!"), new LogEntry(lastId + 2, tester.clock().instant(), info, "Tester failed running its tests!")); @@ -309,7 +309,7 @@ public class InternalStepRunnerTest { public void testsSucceedWhenTheyDoRemotely() { RunId id = app.startSystemTestTests(); tester.runner().run(); - assertEquals(unfinished, tester.jobs().run(id).get().stepStatuses().get(Step.endTests)); + assertEquals(unfinished, tester.jobs().run(id).stepStatuses().get(Step.endTests)); var testZone = DeploymentContext.systemTest.zone(); Inspector configObject = SlimeUtils.jsonToSlime(tester.cloud().config()).get(); assertEquals(app.instanceId().serializedForm(), configObject.field("application").asString()); @@ -338,7 +338,7 @@ public class InternalStepRunnerTest { new LogEntry(lastId + 2, Instant.ofEpochMilli(1234), info, "Steady!"), new LogEntry(lastId + 3, Instant.ofEpochMilli(12345), info, "Success!"), new LogEntry(lastId + 4, tester.clock().instant(), info, "Tests completed successfully.")); - assertEquals(succeeded, tester.jobs().run(id).get().stepStatuses().get(Step.endTests)); + assertEquals(succeeded, tester.jobs().run(id).stepStatuses().get(Step.endTests)); } @Test @@ -351,16 +351,16 @@ public class InternalStepRunnerTest { long lastId1 = tester.jobs().details(id).get().lastId().getAsLong(); Instant instant1 = tester.clock().instant(); tester.runner().run(); - assertEquals(unfinished, tester.jobs().run(id).get().stepStatuses().get(Step.endTests)); - assertEquals(running, tester.jobs().run(id).get().status()); + assertEquals(unfinished, tester.jobs().run(id).stepStatuses().get(Step.endTests)); + assertEquals(running, tester.jobs().run(id).status()); tester.cloud().clearLog(); // Test sleeps for a while. tester.runner().run(); - assertEquals(unfinished, tester.jobs().run(id).get().stepStatuses().get(Step.deployTester)); + assertEquals(unfinished, tester.jobs().run(id).stepStatuses().get(Step.deployTester)); tester.clock().advance(Duration.ofSeconds(899)); tester.runner().run(); - assertEquals(unfinished, tester.jobs().run(id).get().stepStatuses().get(Step.deployTester)); + assertEquals(unfinished, tester.jobs().run(id).stepStatuses().get(Step.deployTester)); tester.clock().advance(JobRunner.jobTimeout); var testZone = DeploymentContext.systemTest.zone(); @@ -369,14 +369,14 @@ public class InternalStepRunnerTest { tester.configServer().convergeServices(app.instanceId(), testZone); tester.configServer().convergeServices(app.testerId().id(), testZone); tester.runner().run(); - assertEquals(unfinished, tester.jobs().run(id).get().stepStatuses().get(Step.endTests)); - assertTrue(tester.jobs().run(id).get().steps().get(Step.endTests).startTime().isPresent()); + assertEquals(unfinished, tester.jobs().run(id).stepStatuses().get(Step.endTests)); + assertTrue(tester.jobs().run(id).steps().get(Step.endTests).startTime().isPresent()); tester.cloud().set(TesterCloud.Status.SUCCESS); tester.cloud().testReport(TestReport.fromJson("{\"bar\":2}")); long lastId2 = tester.jobs().details(id).get().lastId().getAsLong(); tester.runner().run(); - assertEquals(success, tester.jobs().run(id).get().status()); + assertEquals(success, tester.jobs().run(id).status()); assertTestLogEntries(id, Step.endTests, new LogEntry(lastId1 + 1, Instant.ofEpochMilli(123), info, "Not enough data!"), @@ -394,7 +394,7 @@ public class InternalStepRunnerTest { tester.jobs().deploy(app.instanceId(), DeploymentContext.devUsEast1, Optional.empty(), applicationPackage()); tester.runner().run(); RunId id = tester.jobs().last(app.instanceId(), DeploymentContext.devUsEast1).get().id(); - assertEquals(unfinished, tester.jobs().run(id).get().stepStatuses().get(Step.installReal)); + assertEquals(unfinished, tester.jobs().run(id).stepStatuses().get(Step.installReal)); Version version = new Version("7.8.9"); Future<?> concurrentDeployment = Executors.newSingleThreadExecutor().submit(() -> { @@ -409,7 +409,7 @@ public class InternalStepRunnerTest { tester.runner().run(); // Job run order determined by JobType enum order per application. tester.configServer().convergeServices(app.instanceId(), zone); - assertEquals(unfinished, tester.jobs().run(id).get().stepStatuses().get(Step.installReal)); + assertEquals(unfinished, tester.jobs().run(id).stepStatuses().get(Step.installReal)); assertEquals(applicationPackage().hash(), tester.configServer().application(app.instanceId(), zone).get().applicationPackage().hash()); assertEquals(otherPackage.hash(), tester.configServer().application(app.instanceId(), DeploymentContext.perfUsEast3.zone()).get().applicationPackage().hash()); @@ -450,8 +450,8 @@ public class InternalStepRunnerTest { tester.configServer().setLogStream(() -> { throw new ConfigServerException(ConfigServerException.ErrorCode.NOT_FOUND, "404", "context"); }); long lastId = tester.jobs().details(id).get().lastId().getAsLong(); tester.runner().run(); - assertEquals(failed, tester.jobs().run(id).get().stepStatuses().get(Step.endTests)); - assertEquals(unfinished, tester.jobs().run(id).get().stepStatuses().get(Step.copyVespaLogs)); + assertEquals(failed, tester.jobs().run(id).stepStatuses().get(Step.endTests)); + assertEquals(unfinished, tester.jobs().run(id).stepStatuses().get(Step.copyVespaLogs)); assertTestLogEntries(id, Step.copyVespaLogs, new LogEntry(lastId + 2, tester.clock().instant(), info, "Found no logs, but will retry")); @@ -459,7 +459,7 @@ public class InternalStepRunnerTest { // Config servers now provide the log, and we get it. tester.configServer().setLogStream(() -> vespaLog(tester.clock().instant())); tester.runner().run(); - assertEquals(failed, tester.jobs().run(id).get().stepStatuses().get(Step.endTests)); + assertEquals(failed, tester.jobs().run(id).stepStatuses().get(Step.endTests)); assertTestLogEntries(id, Step.copyVespaLogs, new LogEntry(lastId + 2, tester.clock().instant(), info, "Found no logs, but will retry"), @@ -511,21 +511,21 @@ public class InternalStepRunnerTest { throw new ConfigServerException(ConfigServerException.ErrorCode.PARENT_HOST_NOT_READY, "provisioning", "deploy tester"); }); tester.runner().run(); - assertEquals(unfinished, tester.jobs().run(id).get().stepStatuses().get(Step.deployTester)); - assertEquals(unfinished, tester.jobs().run(id).get().stepStatuses().get(Step.deployReal)); + assertEquals(unfinished, tester.jobs().run(id).stepStatuses().get(Step.deployTester)); + assertEquals(unfinished, tester.jobs().run(id).stepStatuses().get(Step.deployReal)); List<X509Certificate> oldTrusted = new ArrayList<>(DeploymentContext.publicApplicationPackage().trustedCertificates()); - X509Certificate oldCert = tester.jobs().run(id).get().testerCertificate().get(); + X509Certificate oldCert = tester.jobs().run(id).testerCertificate().get(); oldTrusted.add(oldCert); assertEquals(oldTrusted, tester.configServer().application(app.instanceId(), id.type().zone()).get().applicationPackage().trustedCertificates()); tester.configServer().throwOnNextPrepare(null); tester.runner().run(); - assertEquals(succeeded, tester.jobs().run(id).get().stepStatuses().get(Step.deployTester)); - assertEquals(succeeded, tester.jobs().run(id).get().stepStatuses().get(Step.deployReal)); + assertEquals(succeeded, tester.jobs().run(id).stepStatuses().get(Step.deployTester)); + assertEquals(succeeded, tester.jobs().run(id).stepStatuses().get(Step.deployReal)); List<X509Certificate> newTrusted = new ArrayList<>(DeploymentContext.publicApplicationPackage().trustedCertificates()); - X509Certificate newCert = tester.jobs().run(id).get().testerCertificate().get(); + X509Certificate newCert = tester.jobs().run(id).testerCertificate().get(); newTrusted.add(newCert); assertEquals(newTrusted, tester.configServer().application(app.instanceId(), id.type().zone()).get().applicationPackage().trustedCertificates()); assertNotEquals(oldCert, newCert); @@ -538,12 +538,12 @@ public class InternalStepRunnerTest { RunId id = app.startSystemTestTests(); List<X509Certificate> trusted = new ArrayList<>(DeploymentContext.publicApplicationPackage().trustedCertificates()); - trusted.add(tester.jobs().run(id).get().testerCertificate().get()); + trusted.add(tester.jobs().run(id).testerCertificate().get()); assertEquals(trusted, tester.configServer().application(app.instanceId(), id.type().zone()).get().applicationPackage().trustedCertificates()); tester.clock().advance(InternalStepRunner.Timeouts.of(system()).testerCertificate().plus(Duration.ofSeconds(1))); tester.runner().run(); - assertEquals(RunStatus.error, tester.jobs().run(id).get().status()); + assertEquals(RunStatus.error, tester.jobs().run(id).status()); } private void assertTestLogEntries(RunId id, Step step, LogEntry... entries) { |