Search in sources :

Example 6 with ApplicationVersion

use of com.yahoo.vespa.hosted.controller.application.ApplicationVersion in project vespa by vespa-engine.

the class ApplicationController method artifactFor.

/**
 * Decide application package and version pair to use in given zone
 */
private Pair<ApplicationPackage, ApplicationVersion> artifactFor(ZoneId zone, Application application, Optional<ApplicationPackage> applicationPackage, boolean canDeployDirectly, boolean deployCurrentVersion) {
    ApplicationVersion version;
    ApplicationPackage pkg;
    Optional<DeploymentJobs.JobType> job = DeploymentJobs.JobType.from(controller.system(), zone);
    if (canDeployDirectly) {
        pkg = applicationPackage.orElseThrow(() -> new IllegalArgumentException("Application package must be " + "given when deploying to " + zone));
        version = ApplicationVersion.unknown;
    } else {
        if (!job.isPresent()) {
            throw new IllegalArgumentException("No job found for zone " + zone);
        }
        version = application.deployApplicationVersionFor(job.get(), controller, deployCurrentVersion).orElseThrow(() -> new IllegalArgumentException("Cannot determine application version to use for " + job.get()));
        pkg = new ApplicationPackage(artifactRepository.getApplicationPackage(application.id(), version.id()));
    }
    return new Pair<>(pkg, version);
}
Also used : ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) Pair(com.yahoo.collections.Pair)

Example 7 with ApplicationVersion

use of com.yahoo.vespa.hosted.controller.application.ApplicationVersion in project vespa by vespa-engine.

the class DeploymentTriggerTest method applicationVersionIsNotDowngraded.

@Test
public void applicationVersionIsNotDowngraded() {
    DeploymentTester tester = new DeploymentTester();
    Application application = tester.createApplication("app1", "tenant1", 1, 1L);
    Supplier<Application> app = () -> tester.application(application.id());
    ApplicationPackage applicationPackage = new ApplicationPackageBuilder().environment(Environment.prod).region("us-central-1").region("eu-west-1").build();
    tester.deployCompletely(application, applicationPackage);
    // productionUsCentral1 fails after deployment, causing a mismatch between deployed and successful state.
    tester.completeDeploymentWithError(application, applicationPackage, BuildJob.defaultBuildNumber + 1, productionUsCentral1);
    // deployAndNotify doesn't actually deploy if the job fails, so we need to do that manually.
    tester.deployAndNotify(application, Optional.empty(), false, true, productionUsCentral1);
    tester.deploy(productionUsCentral1, application, Optional.empty(), false);
    ApplicationVersion appVersion1 = ApplicationVersion.from(BuildJob.defaultSourceRevision, BuildJob.defaultBuildNumber + 1);
    assertEquals(appVersion1, app.get().deployments().get(ZoneId.from("prod.us-central-1")).applicationVersion());
    // Verify the application change is not removed when change is cancelled.
    tester.deploymentTrigger().cancelChange(application.id(), true);
    assertEquals(Change.of(appVersion1), app.get().change());
    // Now cancel the change as is done through the web API.
    tester.deploymentTrigger().cancelChange(application.id(), false);
    assertEquals(Change.empty(), app.get().change());
    // A new version is released, which should now deploy the currently deployed application version to avoid downgrades.
    Version version1 = new Version("6.2");
    tester.upgradeSystem(version1);
    tester.jobCompletion(productionUsCentral1).application(application).unsuccessful().submit();
    tester.completeUpgrade(application, version1, applicationPackage);
    assertEquals(appVersion1, app.get().deployments().get(ZoneId.from("prod.us-central-1")).applicationVersion());
}
Also used : ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) Version(com.yahoo.component.Version) ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) Application(com.yahoo.vespa.hosted.controller.Application) LockedApplication(com.yahoo.vespa.hosted.controller.LockedApplication) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) JobType.systemTest(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest) Test(org.junit.Test) JobType.stagingTest(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest)

Example 8 with ApplicationVersion

use of com.yahoo.vespa.hosted.controller.application.ApplicationVersion in project vespa by vespa-engine.

the class ControllerTest method testDeployment.

@Test
public void testDeployment() {
    // Setup system
    DeploymentTester tester = new DeploymentTester();
    ApplicationController applications = tester.controller().applications();
    ApplicationPackage applicationPackage = new ApplicationPackageBuilder().environment(Environment.prod).region("corp-us-east-1").region("us-east-3").build();
    // staging job - succeeding
    Version version1 = tester.defaultVespaVersion();
    Application app1 = tester.createApplication("app1", "tenant1", 1, 11L);
    tester.jobCompletion(component).application(app1).uploadArtifact(applicationPackage).submit();
    assertEquals("Application version is known from completion of initial job", ApplicationVersion.from(BuildJob.defaultSourceRevision, BuildJob.defaultBuildNumber), tester.controller().applications().require(app1.id()).change().application().get());
    tester.deployAndNotify(app1, applicationPackage, true, systemTest);
    tester.deployAndNotify(app1, applicationPackage, true, stagingTest);
    assertEquals(4, applications.require(app1.id()).deploymentJobs().jobStatus().size());
    ApplicationVersion applicationVersion = tester.controller().applications().require(app1.id()).change().application().get();
    assertTrue("Application version has been set during deployment", applicationVersion != ApplicationVersion.unknown);
    assertStatus(JobStatus.initial(stagingTest).withTriggering(version1, applicationVersion, "", tester.clock().instant().minus(Duration.ofMillis(1))).withCompletion(42, Optional.empty(), tester.clock().instant(), tester.controller()), app1.id(), tester.controller());
    // Causes first deployment job to be triggered
    assertStatus(JobStatus.initial(productionCorpUsEast1).withTriggering(version1, applicationVersion, "", tester.clock().instant()), app1.id(), tester.controller());
    tester.clock().advance(Duration.ofSeconds(1));
    // production job (failing)
    tester.deployAndNotify(app1, applicationPackage, false, productionCorpUsEast1);
    assertEquals(4, applications.require(app1.id()).deploymentJobs().jobStatus().size());
    JobStatus expectedJobStatus = JobStatus.initial(productionCorpUsEast1).withTriggering(version1, applicationVersion, "", // Triggered first without application version info
    tester.clock().instant()).withCompletion(42, Optional.of(JobError.unknown), tester.clock().instant(), tester.controller()).withTriggering(version1, applicationVersion, "", // Re-triggering (due to failure) has application version info
    tester.clock().instant());
    assertStatus(expectedJobStatus, app1.id(), tester.controller());
    // Simulate restart
    tester.restartController();
    applications = tester.controller().applications();
    assertNotNull(tester.controller().tenants().tenant(new TenantId("tenant1")));
    assertNotNull(applications.get(ApplicationId.from(TenantName.from("tenant1"), ApplicationName.from("application1"), InstanceName.from("default"))));
    assertEquals(4, applications.require(app1.id()).deploymentJobs().jobStatus().size());
    tester.clock().advance(Duration.ofHours(1));
    // system and staging test job - succeeding
    tester.jobCompletion(component).application(app1).nextBuildNumber().uploadArtifact(applicationPackage).submit();
    applicationVersion = tester.application("app1").change().application().get();
    tester.deployAndNotify(app1, applicationPackage, true, false, systemTest);
    assertStatus(JobStatus.initial(systemTest).withTriggering(version1, applicationVersion, "", tester.clock().instant().minus(Duration.ofMillis(1))).withCompletion(42, Optional.empty(), tester.clock().instant(), tester.controller()), app1.id(), tester.controller());
    tester.deployAndNotify(app1, applicationPackage, true, stagingTest);
    // production job succeeding now
    tester.jobCompletion(productionCorpUsEast1).application(app1).unsuccessful().submit();
    tester.deployAndNotify(app1, applicationPackage, true, productionCorpUsEast1);
    expectedJobStatus = expectedJobStatus.withTriggering(version1, applicationVersion, "", tester.clock().instant().minus(Duration.ofMillis(1))).withCompletion(42, Optional.empty(), tester.clock().instant(), tester.controller());
    assertStatus(expectedJobStatus, app1.id(), tester.controller());
    // causes triggering of next production job
    assertStatus(JobStatus.initial(productionUsEast3).withTriggering(version1, applicationVersion, "", tester.clock().instant()), app1.id(), tester.controller());
    tester.deployAndNotify(app1, applicationPackage, true, productionUsEast3);
    assertEquals(5, applications.get(app1.id()).get().deploymentJobs().jobStatus().size());
    // prod zone removal is not allowed
    applicationPackage = new ApplicationPackageBuilder().environment(Environment.prod).region("us-east-3").build();
    tester.jobCompletion(component).application(app1).nextBuildNumber().uploadArtifact(applicationPackage).submit();
    try {
        tester.deploy(systemTest, app1, applicationPackage);
        fail("Expected exception due to unallowed production deployment removal");
    } catch (IllegalArgumentException e) {
        assertEquals("deployment-removal: application 'tenant1.app1' is deployed in corp-us-east-1, but does not include this zone in deployment.xml", e.getMessage());
    }
    assertNotNull("Zone was not removed", applications.require(app1.id()).deployments().get(productionCorpUsEast1.zone(SystemName.main).get()));
    JobStatus jobStatus = applications.require(app1.id()).deploymentJobs().jobStatus().get(productionCorpUsEast1);
    assertNotNull("Deployment job was not removed", jobStatus);
    assertEquals(42, jobStatus.lastCompleted().get().id());
    assertEquals("Available change in staging-test", jobStatus.lastCompleted().get().reason());
    // prod zone removal is allowed with override
    applicationPackage = new ApplicationPackageBuilder().allow(ValidationId.deploymentRemoval).upgradePolicy("default").environment(Environment.prod).region("us-east-3").build();
    tester.jobCompletion(component).application(app1).nextBuildNumber(2).uploadArtifact(applicationPackage).submit();
    tester.deployAndNotify(app1, applicationPackage, true, systemTest);
    assertNull("Zone was removed", applications.require(app1.id()).deployments().get(productionCorpUsEast1.zone(SystemName.main).get()));
    assertNull("Deployment job was removed", applications.require(app1.id()).deploymentJobs().jobStatus().get(productionCorpUsEast1));
}
Also used : JobStatus(com.yahoo.vespa.hosted.controller.application.JobStatus) TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) VespaVersion(com.yahoo.vespa.hosted.controller.versions.VespaVersion) Version(com.yahoo.component.Version) DeploymentTester(com.yahoo.vespa.hosted.controller.deployment.DeploymentTester) ApplicationPackageBuilder(com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) JobType.stagingTest(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest) JobType.systemTest(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest) Test(org.junit.Test)

Example 9 with ApplicationVersion

use of com.yahoo.vespa.hosted.controller.application.ApplicationVersion in project vespa by vespa-engine.

the class ApplicationController method deployApplication.

/**
 * Deploys an application. If the application does not exist it is created.
 */
// TODO: Get rid of the options arg
public ActivateResult deployApplication(ApplicationId applicationId, ZoneId zone, Optional<ApplicationPackage> applicationPackageFromDeployer, DeployOptions options) {
    try (Lock lock = lock(applicationId)) {
        LockedApplication application = get(applicationId).map(app -> new LockedApplication(app, lock)).orElseGet(() -> new LockedApplication(createApplication(applicationId, Optional.empty()), lock));
        final boolean canDeployDirectly = canDeployDirectlyTo(zone, options);
        // Determine Vespa version to use
        Version version;
        if (options.deployCurrentVersion) {
            version = application.versionIn(zone, controller);
        } else if (canDeployDirectlyTo(zone, options)) {
            version = options.vespaVersion.map(Version::new).orElse(controller.systemVersion());
        } else if (!application.change().isPresent() && !zone.environment().isManuallyDeployed()) {
            return unexpectedDeployment(applicationId, zone, applicationPackageFromDeployer);
        } else {
            version = application.deployVersionIn(zone, controller);
        }
        // Determine application package to use
        Pair<ApplicationPackage, ApplicationVersion> artifact = artifactFor(zone, application, applicationPackageFromDeployer, canDeployDirectly, options.deployCurrentVersion);
        ApplicationPackage applicationPackage = artifact.getFirst();
        ApplicationVersion applicationVersion = artifact.getSecond();
        validate(applicationPackage.deploymentSpec());
        // Update application with information from application package
        if (!options.deployCurrentVersion) {
            // Store information about application package
            application = application.with(applicationPackage.deploymentSpec());
            application = application.with(applicationPackage.validationOverrides());
            // Delete zones not listed in DeploymentSpec, if allowed
            // We do this at deployment time to be able to return a validation failure message when necessary
            application = deleteRemovedDeployments(application);
            // Clean up deployment jobs that are no longer referenced by deployment spec
            application = deleteUnreferencedDeploymentJobs(application);
            // TODO jvenstad: Store triggering information here, including versions, when job status is read from the build service.
            // store missing information even if we fail deployment below
            store(application);
        }
        // Validate the change being deployed
        if (!canDeployDirectly) {
            validateChange(application, zone, version);
        }
        // Assign global rotation
        application = withRotation(application, zone);
        Set<String> rotationNames = new HashSet<>();
        Set<String> cnames = new HashSet<>();
        application.rotation().ifPresent(applicationRotation -> {
            rotationNames.add(applicationRotation.id().asString());
            cnames.add(applicationRotation.dnsName());
            cnames.add(applicationRotation.secureDnsName());
        });
        // Carry out deployment
        options = withVersion(version, options);
        ConfigServerClient.PreparedApplication preparedApplication = configServer.prepare(new DeploymentId(applicationId, zone), options, cnames, rotationNames, applicationPackage.zippedContent());
        preparedApplication.activate();
        application = application.withNewDeployment(zone, applicationVersion, version, clock.instant());
        store(application);
        return new ActivateResult(new RevisionId(applicationPackage.hash()), preparedApplication.prepareResponse(), applicationPackage.zippedContent().length);
    }
}
Also used : ArtifactRepository(com.yahoo.vespa.hosted.controller.api.integration.deployment.ArtifactRepository) ZmsClient(com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsClient) EndpointStatus(com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus) DeploymentTrigger(com.yahoo.vespa.hosted.controller.deployment.DeploymentTrigger) URISyntaxException(java.net.URISyntaxException) DeploymentJobs(com.yahoo.vespa.hosted.controller.application.DeploymentJobs) ValidationId(com.yahoo.config.application.api.ValidationId) JobReport(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobReport) TenantName(com.yahoo.config.provision.TenantName) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) DeploymentExpirer(com.yahoo.vespa.hosted.controller.maintenance.DeploymentExpirer) RevisionId(com.yahoo.vespa.hosted.controller.api.identifiers.RevisionId) Duration(java.time.Duration) Map(java.util.Map) DeployOptions(com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions) URI(java.net.URI) Rotation(com.yahoo.vespa.hosted.controller.rotation.Rotation) Exceptions(com.yahoo.yolean.Exceptions) RotationRepository(com.yahoo.vespa.hosted.controller.rotation.RotationRepository) ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) Set(java.util.Set) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) List(java.util.List) Optional(java.util.Optional) Deployment(com.yahoo.vespa.hosted.controller.application.Deployment) RotationsConfig(com.yahoo.vespa.hosted.rotation.config.RotationsConfig) Log(com.yahoo.vespa.hosted.controller.api.integration.configserver.Log) AthenzClientFactory(com.yahoo.vespa.hosted.controller.api.integration.athenz.AthenzClientFactory) Version(com.yahoo.component.Version) ApplicationId(com.yahoo.config.provision.ApplicationId) DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) RecordId(com.yahoo.vespa.hosted.controller.api.integration.dns.RecordId) ConfigServerClient(com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerClient) HashMap(java.util.HashMap) NToken(com.yahoo.vespa.athenz.api.NToken) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) ConfigChangeActions(com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.ConfigChangeActions) ImmutableList(com.google.common.collect.ImmutableList) TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) RecordData(com.yahoo.vespa.hosted.controller.api.integration.dns.RecordData) RoutingEndpoint(com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingEndpoint) RoutingGenerator(com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingGenerator) ActivateResult(com.yahoo.vespa.hosted.controller.api.ActivateResult) NoInstanceException(com.yahoo.vespa.hosted.controller.api.integration.configserver.NoInstanceException) Lock(com.yahoo.vespa.curator.Lock) Hostname(com.yahoo.vespa.hosted.controller.api.identifiers.Hostname) Environment(com.yahoo.config.provision.Environment) ControllerDb(com.yahoo.vespa.hosted.controller.persistence.ControllerDb) CuratorDb(com.yahoo.vespa.hosted.controller.persistence.CuratorDb) IOException(java.io.IOException) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) Consumer(java.util.function.Consumer) Pair(com.yahoo.collections.Pair) DeploymentSpec(com.yahoo.config.application.api.DeploymentSpec) RecordName(com.yahoo.vespa.hosted.controller.api.integration.dns.RecordName) Clock(java.time.Clock) NameService(com.yahoo.vespa.hosted.controller.api.integration.dns.NameService) PrepareResponse(com.yahoo.vespa.hosted.controller.api.integration.configserver.PrepareResponse) Collections(java.util.Collections) Record(com.yahoo.vespa.hosted.controller.api.integration.dns.Record) RotationLock(com.yahoo.vespa.hosted.controller.rotation.RotationLock) DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) RevisionId(com.yahoo.vespa.hosted.controller.api.identifiers.RevisionId) Lock(com.yahoo.vespa.curator.Lock) RotationLock(com.yahoo.vespa.hosted.controller.rotation.RotationLock) ActivateResult(com.yahoo.vespa.hosted.controller.api.ActivateResult) ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) Version(com.yahoo.component.Version) ConfigServerClient(com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerClient) HashSet(java.util.HashSet)

Example 10 with ApplicationVersion

use of com.yahoo.vespa.hosted.controller.application.ApplicationVersion in project vespa by vespa-engine.

the class DeploymentTrigger method triggerFromCompletion.

// --- Start of methods which triggers deployment jobs -------------------------
/**
 * Called each time a job completes (successfully or not) to cause triggering of one or more follow-up jobs
 * (which may possibly the same job once over).
 *
 * @param report information about the job that just completed
 */
public void triggerFromCompletion(JobReport report) {
    applications().lockOrThrow(report.applicationId(), application -> {
        ApplicationVersion applicationVersion = applicationVersionFrom(report);
        application = application.withJobCompletion(report, applicationVersion, clock.instant(), controller);
        application = application.withProjectId(report.projectId());
        // Handle successful starting and ending
        if (report.jobType() == JobType.component) {
            if (report.success()) {
                if (!acceptNewApplicationVersionNow(application))
                    application = application.withOutstandingChange(Change.of(applicationVersion));
                else
                    // Note that in case of an ongoing upgrade this may result in both the upgrade and application
                    // change being deployed together
                    application = application.withChange(application.change().with(applicationVersion));
            }
        } else if (report.jobType().isProduction() && deploymentComplete(application)) {
            // change completed
            // TODO jvenstad: Check for and remove individual parts of Change.
            application = application.withChange(Change.empty());
        }
        applications().store(application);
    });
}
Also used : ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion)

Aggregations

ApplicationVersion (com.yahoo.vespa.hosted.controller.application.ApplicationVersion)11 Version (com.yahoo.component.Version)6 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)6 Test (org.junit.Test)5 JobType.stagingTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest)4 JobType.systemTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest)4 Application (com.yahoo.vespa.hosted.controller.Application)3 Deployment (com.yahoo.vespa.hosted.controller.application.Deployment)3 Pair (com.yahoo.collections.Pair)2 DeploymentSpec (com.yahoo.config.application.api.DeploymentSpec)2 LockedApplication (com.yahoo.vespa.hosted.controller.LockedApplication)2 TenantId (com.yahoo.vespa.hosted.controller.api.identifiers.TenantId)2 DeploymentJobs (com.yahoo.vespa.hosted.controller.application.DeploymentJobs)2 JobStatus (com.yahoo.vespa.hosted.controller.application.JobStatus)2 VespaVersion (com.yahoo.vespa.hosted.controller.versions.VespaVersion)2 ArrayList (java.util.ArrayList)2 ImmutableList (com.google.common.collect.ImmutableList)1 ValidationId (com.yahoo.config.application.api.ValidationId)1 ValidationOverrides (com.yahoo.config.application.api.ValidationOverrides)1 ApplicationId (com.yahoo.config.provision.ApplicationId)1