diff options
author | Torbjørn Smørgrav <smorgrav@users.noreply.github.com> | 2018-10-04 14:00:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-04 14:00:00 +0200 |
commit | 963d16440f7534e39cbe36be695c272a95b7e3fb (patch) | |
tree | 36af8a565ba0d6bde83f5c7b67e95e51bf288f11 | |
parent | 46f4c5c7c91550c0e9561ca61dc044f01d56c12f (diff) | |
parent | 502a44bb90ced322931e606c920e0e2ae992ef4f (diff) |
Merge pull request #7197 from vespa-engine/smorgrav/expand_nameservice
Add method to look up multiple records by name and apply this
2 files changed, 19 insertions, 8 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/NameService.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/NameService.java index 1d341f06f90..8c5579cf97c 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/NameService.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/NameService.java @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.dns; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -19,9 +20,16 @@ public interface NameService { */ RecordId createCname(RecordName alias, RecordData canonicalName); - /** Find record by type and name */ + /** Find record by type and name - will throw exception if more than one record matches */ Optional<Record> findRecord(Record.Type type, RecordName name); + /** Find record by type and name - may return multiple records */ + default List<Record> findRecords(Record.Type type, RecordName name) { + List<Record> result = new ArrayList<>(); + findRecord(type, name).ifPresent(result::add); + return result; + } + /** Find record by type and data */ List<Record> findRecord(Record.Type type, RecordData data); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java index c2dbc8bdc59..79bc72f950d 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java @@ -482,16 +482,19 @@ public class ApplicationController { /** 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()) { + List<Record> records = nameService.findRecords(Record.Type.CNAME, RecordName.from(dnsName)); + records.forEach(record -> { // 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() + "'"); + if ( ! record.data().equals(rotationName)) { + nameService.updateRecord(record.id(), rotationName); + log.info("Updated mapping for record ID " + record.id().asString() + ": '" + dnsName + + "' -> '" + rotation.name() + "'"); } - } else { + }); + + if (records.isEmpty()) { RecordId id = nameService.createCname(RecordName.from(dnsName), rotationName); log.info("Registered mapping with record ID " + id.asString() + ": '" + dnsName + "' -> '" + rotation.name() + "'"); |