Search in sources :

Example 1 with Record

use of com.yahoo.vespa.hosted.controller.api.integration.dns.Record in project vespa by vespa-engine.

the class ControllerTest method testDnsAliasRegistration.

@Test
public void testDnsAliasRegistration() {
    DeploymentTester tester = new DeploymentTester();
    Application application = tester.createApplication("app1", "tenant1", 1, 1L);
    ApplicationPackage applicationPackage = new ApplicationPackageBuilder().environment(Environment.prod).globalServiceId("foo").region("us-west-1").region(// Two deployments should result in each DNS alias being registered once
    "us-central-1").build();
    tester.deployCompletely(application, applicationPackage);
    assertEquals(2, tester.controllerTester().nameService().records().size());
    Optional<Record> record = tester.controllerTester().nameService().findRecord(Record.Type.CNAME, RecordName.from("app1--tenant1.global.vespa.yahooapis.com"));
    assertTrue(record.isPresent());
    assertEquals("app1--tenant1.global.vespa.yahooapis.com", record.get().name().asString());
    assertEquals("rotation-fqdn-01.", record.get().data().asString());
    record = tester.controllerTester().nameService().findRecord(Record.Type.CNAME, RecordName.from("app1.tenant1.global.vespa.yahooapis.com"));
    assertTrue(record.isPresent());
    assertEquals("app1.tenant1.global.vespa.yahooapis.com", record.get().name().asString());
    assertEquals("rotation-fqdn-01.", record.get().data().asString());
}
Also used : DeploymentTester(com.yahoo.vespa.hosted.controller.deployment.DeploymentTester) ApplicationPackageBuilder(com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder) Record(com.yahoo.vespa.hosted.controller.api.integration.dns.Record) 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 2 with Record

use of com.yahoo.vespa.hosted.controller.api.integration.dns.Record in project vespa by vespa-engine.

the class DnsMaintainerTest method removes_record_for_unassigned_rotation.

@Test
public void removes_record_for_unassigned_rotation() {
    DeploymentTester tester = new DeploymentTester();
    Application application = tester.createApplication("app1", "tenant1", 1, 1L);
    DnsMaintainer dnsMaintainer = new DnsMaintainer(tester.controller(), Duration.ofHours(12), new JobControl(new MockCuratorDb()), tester.controllerTester().nameService());
    ApplicationPackage applicationPackage = new ApplicationPackageBuilder().environment(Environment.prod).globalServiceId("foo").region("us-west-1").region("us-central-1").build();
    // Deploy application
    tester.deployCompletely(application, applicationPackage);
    assertEquals(2, tester.controllerTester().nameService().records().size());
    Optional<Record> record = tester.controllerTester().nameService().findRecord(Record.Type.CNAME, RecordName.from("app1--tenant1.global.vespa.yahooapis.com"));
    assertTrue(record.isPresent());
    assertEquals("app1--tenant1.global.vespa.yahooapis.com", record.get().name().asString());
    assertEquals("rotation-fqdn-01.", record.get().data().asString());
    record = tester.controllerTester().nameService().findRecord(Record.Type.CNAME, RecordName.from("app1.tenant1.global.vespa.yahooapis.com"));
    assertTrue(record.isPresent());
    assertEquals("app1.tenant1.global.vespa.yahooapis.com", record.get().name().asString());
    assertEquals("rotation-fqdn-01.", record.get().data().asString());
    // DnsMaintainer does nothing
    dnsMaintainer.maintain();
    assertTrue("DNS record is not removed", tester.controllerTester().nameService().findRecord(Record.Type.CNAME, RecordName.from("app1--tenant1.global.vespa.yahooapis.com")).isPresent());
    assertTrue("DNS record is not removed", tester.controllerTester().nameService().findRecord(Record.Type.CNAME, RecordName.from("app1.tenant1.global.vespa.yahooapis.com")).isPresent());
    // Remove application
    applicationPackage = new ApplicationPackageBuilder().environment(Environment.prod).allow(ValidationId.deploymentRemoval).build();
    tester.jobCompletion(component).application(application).nextBuildNumber().uploadArtifact(applicationPackage).submit();
    tester.deployAndNotify(application, applicationPackage, true, systemTest);
    tester.applications().deactivate(application, ZoneId.from(Environment.test, RegionName.from("us-east-1")));
    tester.applications().deactivate(application, ZoneId.from(Environment.staging, RegionName.from("us-east-3")));
    tester.applications().deleteApplication(application.id(), Optional.of(new NToken("ntoken")));
    // DnsMaintainer removes records
    dnsMaintainer.maintain();
    assertFalse("DNS record removed", tester.controllerTester().nameService().findRecord(Record.Type.CNAME, RecordName.from("app1--tenant1.global.vespa.yahooapis.com")).isPresent());
    dnsMaintainer.maintain();
    assertFalse("DNS record removed", tester.controllerTester().nameService().findRecord(Record.Type.CNAME, RecordName.from("app1.tenant1.global.vespa.yahooapis.com")).isPresent());
}
Also used : MockCuratorDb(com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb) NToken(com.yahoo.vespa.athenz.api.NToken) DeploymentTester(com.yahoo.vespa.hosted.controller.deployment.DeploymentTester) ApplicationPackageBuilder(com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder) Record(com.yahoo.vespa.hosted.controller.api.integration.dns.Record) Application(com.yahoo.vespa.hosted.controller.Application) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) Test(org.junit.Test) JobType.systemTest(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest)

Example 3 with Record

use of com.yahoo.vespa.hosted.controller.api.integration.dns.Record in project vespa by vespa-engine.

the class ApplicationController method registerRotationInDns.

/**
 * Register a DNS name for rotation
 */
private void registerRotationInDns(Rotation rotation, String dnsName) {
    try {
        Optional<Record> record = nameService.findRecord(Record.Type.CNAME, RecordName.from(dnsName));
        RecordData rotationName = RecordData.fqdn(rotation.name());
        if (record.isPresent()) {
            // Ensure that the existing record points to the correct rotation
            if (!record.get().data().equals(rotationName)) {
                nameService.updateRecord(record.get().id(), rotationName);
                log.info("Updated mapping for record ID " + record.get().id().asString() + ": '" + dnsName + "' -> '" + rotation.name() + "'");
            }
        } else {
            RecordId id = nameService.createCname(RecordName.from(dnsName), rotationName);
            log.info("Registered mapping with record ID " + id.asString() + ": '" + dnsName + "' -> '" + rotation.name() + "'");
        }
    } catch (RuntimeException e) {
        log.log(Level.WARNING, "Failed to register CNAME", e);
    }
}
Also used : RecordData(com.yahoo.vespa.hosted.controller.api.integration.dns.RecordData) Record(com.yahoo.vespa.hosted.controller.api.integration.dns.Record) RecordId(com.yahoo.vespa.hosted.controller.api.integration.dns.RecordId)

Aggregations

Record (com.yahoo.vespa.hosted.controller.api.integration.dns.Record)3 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)2 JobType.systemTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest)2 ApplicationPackageBuilder (com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder)2 DeploymentTester (com.yahoo.vespa.hosted.controller.deployment.DeploymentTester)2 Test (org.junit.Test)2 NToken (com.yahoo.vespa.athenz.api.NToken)1 Application (com.yahoo.vespa.hosted.controller.Application)1 RecordData (com.yahoo.vespa.hosted.controller.api.integration.dns.RecordData)1 RecordId (com.yahoo.vespa.hosted.controller.api.integration.dns.RecordId)1 JobType.stagingTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest)1 MockCuratorDb (com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb)1