Search in sources :

Example 16 with TenantId

use of com.yahoo.vespa.hosted.controller.api.identifiers.TenantId in project vespa by vespa-engine.

the class ControllerTest method testDeployUntestedChangeFails.

@Test
public void testDeployUntestedChangeFails() {
    DeploymentTester tester = new DeploymentTester();
    ApplicationController applications = tester.controller().applications();
    TenantId tenant = tester.controllerTester().createTenant("tenant1", "domain1", 11L);
    Application app = tester.controllerTester().createApplication(tenant, "app1", "default", 1);
    tester.deployCompletely(app, applicationPackage);
    tester.controller().applications().lockOrThrow(app.id(), application -> {
        application = application.withChange(Change.of(Version.fromString("6.3")));
        applications.store(application);
        try {
            tester.controllerTester().deploy(app, ZoneId.from("prod", "corp-us-east-1"), applicationPackage);
            fail("Expected exception");
        } catch (IllegalArgumentException e) {
            assertEquals("Rejecting deployment of application 'tenant1.app1' to zone prod.corp-us-east-1 as upgrade to 6.3 is not tested", e.getMessage());
        }
    });
}
Also used : TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) DeploymentTester(com.yahoo.vespa.hosted.controller.deployment.DeploymentTester) 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 17 with TenantId

use of com.yahoo.vespa.hosted.controller.api.identifiers.TenantId 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 18 with TenantId

use of com.yahoo.vespa.hosted.controller.api.identifiers.TenantId in project vespa by vespa-engine.

the class ContainerControllerTester method createApplication.

public Application createApplication(String athensDomain, String tenant, String application) {
    AthenzDomain domain1 = addTenantAthenzDomain(athensDomain, "mytenant");
    controller().tenants().createAthenzTenant(Tenant.createAthensTenant(new TenantId(tenant), domain1, new Property("property1"), Optional.of(new PropertyId("1234"))), TestIdentities.userNToken);
    ApplicationId app = ApplicationId.from(tenant, application, "default");
    return controller().applications().createApplication(app, Optional.of(TestIdentities.userNToken));
}
Also used : TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) AthenzDomain(com.yahoo.vespa.athenz.api.AthenzDomain) ApplicationId(com.yahoo.config.provision.ApplicationId) Property(com.yahoo.vespa.hosted.controller.api.identifiers.Property) PropertyId(com.yahoo.vespa.hosted.controller.api.identifiers.PropertyId)

Example 19 with TenantId

use of com.yahoo.vespa.hosted.controller.api.identifiers.TenantId in project vespa by vespa-engine.

the class TenantController method createUserTenant.

public Tenant createUserTenant(String userName) {
    TenantId userTenantId = new UserId(userName).toTenantId();
    try (Lock lock = lock(userTenantId)) {
        Tenant tenant = Tenant.createUserTenant(userTenantId);
        internalCreateTenant(tenant, Optional.empty());
        return tenant;
    }
}
Also used : TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) UserId(com.yahoo.vespa.hosted.controller.api.identifiers.UserId) Lock(com.yahoo.vespa.curator.Lock)

Aggregations

TenantId (com.yahoo.vespa.hosted.controller.api.identifiers.TenantId)19 Tenant (com.yahoo.vespa.hosted.controller.api.Tenant)9 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)7 Test (org.junit.Test)7 JobType.stagingTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest)6 JobType.systemTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest)6 Application (com.yahoo.vespa.hosted.controller.Application)5 Version (com.yahoo.component.Version)4 AthenzDomain (com.yahoo.vespa.athenz.api.AthenzDomain)4 Inspector (com.yahoo.slime.Inspector)3 Lock (com.yahoo.vespa.curator.Lock)3 LockedApplication (com.yahoo.vespa.hosted.controller.LockedApplication)3 Property (com.yahoo.vespa.hosted.controller.api.identifiers.Property)3 ApplicationId (com.yahoo.config.provision.ApplicationId)2 Environment (com.yahoo.config.provision.Environment)2 NToken (com.yahoo.vespa.athenz.api.NToken)2 EndpointStatus (com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus)2 ConfigChangeActions (com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.ConfigChangeActions)2 DeploymentId (com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId)2 PropertyId (com.yahoo.vespa.hosted.controller.api.identifiers.PropertyId)2