use of com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType in project vespa by vespa-engine.
the class ControllerTest method testCleanupOfStaleDeploymentData.
@Test
public void testCleanupOfStaleDeploymentData() throws IOException {
DeploymentTester tester = new DeploymentTester();
tester.controllerTester().zoneRegistry().setSystem(SystemName.cd);
tester.controllerTester().zoneRegistry().setZones(ZoneId.from("prod", "cd-us-central-1"));
Supplier<Map<JobType, JobStatus>> statuses = () -> tester.application(ApplicationId.from("vespa", "canary", "default")).deploymentJobs().jobStatus();
// Current system version, matches version in test data
Version version = Version.fromString("6.141.117");
tester.configServer().setDefaultVersion(version);
tester.updateVersionStatus(version);
assertEquals(version, tester.controller().versionStatus().systemVersion().get().versionNumber());
// Load test data data
byte[] json = Files.readAllBytes(Paths.get("src/test/java/com/yahoo/vespa/hosted/controller/maintenance/testdata/canary-with-stale-data.json"));
Application application = tester.controllerTester().createApplication(SlimeUtils.jsonToSlime(json));
ApplicationPackage applicationPackage = new ApplicationPackageBuilder().upgradePolicy("canary").region("cd-us-central-1").build();
tester.jobCompletion(component).application(application).uploadArtifact(applicationPackage).submit();
long cdJobsCount = statuses.get().keySet().stream().filter(type -> type.zone(SystemName.cd).isPresent()).count();
long mainJobsCount = statuses.get().keySet().stream().filter(type -> type.zone(SystemName.main).isPresent() && !type.zone(SystemName.cd).isPresent()).count();
assertEquals("Irrelevant (main) data is present.", 8, mainJobsCount);
// New version is released
version = Version.fromString("6.142.1");
tester.configServer().setDefaultVersion(version);
tester.updateVersionStatus(version);
assertEquals(version, tester.controller().versionStatus().systemVersion().get().versionNumber());
tester.upgrader().maintain();
tester.readyJobTrigger().maintain();
// Test environments pass
tester.deploy(DeploymentJobs.JobType.systemTest, application, applicationPackage);
tester.deploymentQueue().takeJobsToRun();
tester.clock().advance(Duration.ofMinutes(10));
tester.jobCompletion(systemTest).application(application).submit();
long newCdJobsCount = statuses.get().keySet().stream().filter(type -> type.zone(SystemName.cd).isPresent()).count();
long newMainJobsCount = statuses.get().keySet().stream().filter(type -> type.zone(SystemName.main).isPresent() && !type.zone(SystemName.cd).isPresent()).count();
assertEquals("Irrelevant (main) job data is removed.", 0, newMainJobsCount);
assertEquals("Relevant (cd) data is not removed.", cdJobsCount, newCdJobsCount);
}
use of com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType in project vespa by vespa-engine.
the class ScrewdriverApiHandler method trigger.
private HttpResponse trigger(HttpRequest request, String tenantName, String applicationName) {
JobType jobType = Optional.of(asString(request.getData())).filter(s -> !s.isEmpty()).map(JobType::fromJobName).orElse(JobType.component);
ApplicationId applicationId = ApplicationId.from(tenantName, applicationName, "default");
controller.applications().lockOrThrow(applicationId, application -> {
// Since this is a manual operation we likely want it to trigger as soon as possible so we add it at to the
// front of the queue
application = controller.applications().deploymentTrigger().trigger(new DeploymentTrigger.Triggering(application, jobType, true, "Triggered from screwdriver/v1"), Collections.emptySet(), true);
controller.applications().store(application);
});
Slime slime = new Slime();
Cursor cursor = slime.setObject();
cursor.setString("message", "Triggered " + jobType.jobName() + " for " + applicationId);
return new SlimeJsonResponse(slime);
}
use of com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType in project vespa by vespa-engine.
the class DeploymentTester method consumeJobs.
/**
* Assert that the sceduled jobs of this application are exactly those given, and take them
*/
private void consumeJobs(Application application, boolean expectOnlyTheseJobs, JobType... jobs) {
for (JobType job : jobs) {
BuildService.BuildJob buildJob = findJob(application, job);
assertEquals((long) application.deploymentJobs().projectId().get(), buildJob.projectId());
assertEquals(job.jobName(), buildJob.jobName());
}
if (expectOnlyTheseJobs)
assertEquals("Unexpected job queue: " + jobsOf(application), jobs.length, jobsOf(application).size());
deploymentQueue().removeJobs(application.id());
}
use of com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType in project vespa by vespa-engine.
the class DeploymentTester method completeDeployment.
private void completeDeployment(Application application, ApplicationPackage applicationPackage, Optional<JobType> failOnJob, boolean includingProductionZones) {
DeploymentOrder order = new DeploymentOrder(controller());
List<JobType> jobs = order.jobsFrom(applicationPackage.deploymentSpec());
if (!includingProductionZones)
jobs = jobs.stream().filter(job -> !job.isProduction()).collect(Collectors.toList());
for (JobType job : jobs) {
boolean failJob = failOnJob.map(j -> j.equals(job)).orElse(false);
deployAndNotify(application, applicationPackage, !failJob, false, job);
if (failJob) {
break;
}
}
if (failOnJob.isPresent()) {
assertTrue(applications().require(application.id()).change().isPresent());
assertTrue(applications().require(application.id()).deploymentJobs().hasFailures());
} else if (includingProductionZones) {
assertFalse(applications().require(application.id()).change().isPresent());
} else {
assertTrue(applications().require(application.id()).change().isPresent());
}
}
use of com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType in project vespa by vespa-engine.
the class DeploymentTrigger method changeDeployed.
/**
* Returns whether the given application should skip deployment of its current change to the given production job zone.
*
* If the currently deployed application has a newer platform or application version than the application's
* current change, the method returns {@code true}, to avoid a downgrade.
* Otherwise, it returns whether the current change is redundant, i.e., all its components are already deployed.
*/
private boolean changeDeployed(Application application, JobType job) {
if (!job.isProduction())
throw new IllegalArgumentException(job + " is not a production job!");
Deployment deployment = application.deployments().get(job.zone(controller.system()).get());
if (deployment == null)
return false;
int applicationComparison = application.change().application().map(version -> version.compareTo(deployment.applicationVersion())).orElse(0);
int platformComparion = application.change().platform().map(version -> version.compareTo(deployment.version())).orElse(0);
if (applicationComparison == -1 || platformComparion == -1)
// Avoid downgrades!
return true;
return applicationComparison == 0 && platformComparion == 0;
}
Aggregations