summaryrefslogtreecommitdiffstats
path: root/controller-api
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2019-05-02 12:35:43 +0200
committerMartin Polden <mpolden@mpolden.no>2019-05-02 12:45:17 +0200
commit964979259baa261f190be29c1a85b35801e9ae3f (patch)
tree9ae76be25569611e972160b8df6f38dcddccfc18 /controller-api
parent3158e4d0322b95d1f4eaef86d970e19807c52573 (diff)
Add TTL field to Record
Diffstat (limited to 'controller-api')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/MemoryNameService.java17
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/Record.java19
2 files changed, 29 insertions, 7 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/MemoryNameService.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/MemoryNameService.java
index 80b3a0bf25c..75d49e542dc 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/MemoryNameService.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/MemoryNameService.java
@@ -22,10 +22,19 @@ public class MemoryNameService implements NameService {
return Collections.unmodifiableSet(records);
}
+ private void add(Record record) {
+ if (records.stream().anyMatch(r -> r.type().equals(record.type()) &&
+ r.name().equals(record.name()) &&
+ r.data().equals(record.data()))) {
+ throw new IllegalArgumentException("Record already exists: " + record);
+ }
+ records.add(record);
+ }
+
@Override
public Record createCname(RecordName name, RecordData canonicalName) {
var record = new Record(Record.Type.CNAME, name, canonicalName);
- records.add(record);
+ add(record);
return record;
}
@@ -37,7 +46,7 @@ public class MemoryNameService implements NameService {
.collect(Collectors.toList());
// Satisfy idempotency contract of interface
removeRecords(findRecords(Record.Type.ALIAS, name));
- this.records.addAll(records);
+ records.forEach(this::add);
return records;
}
@@ -46,7 +55,7 @@ public class MemoryNameService implements NameService {
var records = txtData.stream()
.map(data -> new Record(Record.Type.TXT, name, data))
.collect(Collectors.toList());
- this.records.addAll(records);
+ records.forEach(this::add);
return records;
}
@@ -76,7 +85,7 @@ public class MemoryNameService implements NameService {
}
var existing = records.get(0);
this.records.remove(existing);
- this.records.add(new Record(existing.type(), existing.name(), newData));
+ add(new Record(existing.type(), existing.name(), newData));
}
@Override
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/Record.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/Record.java
index a4219569ab1..7beb3076156 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/Record.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/Record.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.time.Duration;
import java.util.Comparator;
import java.util.Objects;
@@ -16,20 +17,31 @@ public class Record implements Comparable<Record> {
.thenComparing(Record::data);
private final Type type;
+ private final Duration ttl;
private final RecordName name;
private final RecordData data;
- public Record(Type type, RecordName name, RecordData data) {
+ public Record(Type type, Duration ttl, RecordName name, RecordData data) {
this.type = Objects.requireNonNull(type, "type cannot be null");
+ this.ttl = Objects.requireNonNull(ttl, "ttl cannot be null");
this.name = Objects.requireNonNull(name, "name cannot be null");
this.data = Objects.requireNonNull(data, "data cannot be null");
}
+ public Record(Type type, RecordName name, RecordData data) {
+ this(type, Duration.ofMinutes(5), name, data);
+ }
+
/** DNS type of this */
public Type type() {
return type;
}
+ /** The TTL value of this */
+ public Duration ttl() {
+ return ttl;
+ }
+
/** Data in this, e.g. IP address for records of type A */
public RecordData data() {
return data;
@@ -58,7 +70,7 @@ public class Record implements Comparable<Record> {
@Override
public String toString() {
- return String.format("%s %s -> %s", type, name, data);
+ return String.format("%s %s -> %s [TTL: %s]", type, name, data, ttl);
}
@Override
@@ -67,13 +79,14 @@ public class Record implements Comparable<Record> {
if (o == null || getClass() != o.getClass()) return false;
Record record = (Record) o;
return type == record.type &&
+ ttl.equals(record.ttl) &&
name.equals(record.name) &&
data.equals(record.data);
}
@Override
public int hashCode() {
- return Objects.hash(type, name, data);
+ return Objects.hash(type, ttl, name, data);
}
@Override