summaryrefslogtreecommitdiffstats
path: root/controller-api
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2017-12-06 14:48:51 +0100
committerMartin Polden <mpolden@mpolden.no>2017-12-06 14:56:27 +0100
commit6f4ec5592bf0db7235d0c4f74fd9f65ccce8742a (patch)
tree58a9729aa873284a386c84e3feadd13a05a1d83a /controller-api
parente4975438ac6ff14d01c944e64dc1178e96cb19f4 (diff)
Update name service interface
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/NameService.java12
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/Record.java18
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordData.java49
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordName.java47
5 files changed, 129 insertions, 14 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 c82a3fd571d..9f4af82c5b0 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,20 +22,33 @@ public class MemoryNameService implements NameService {
}
@Override
- public RecordId createCname(String alias, String canonicalName) {
+ public RecordId createCname(RecordName alias, RecordData canonicalName) {
RecordId id = new RecordId(UUID.randomUUID().toString());
records.put(id, new Record(id, Record.Type.CNAME, alias, canonicalName));
return id;
}
@Override
- public Optional<Record> findRecord(Record.Type type, String name) {
+ public Optional<Record> findRecord(Record.Type type, RecordName name) {
return records.values().stream()
.filter(record -> record.type() == type && record.name().equals(name))
.findFirst();
}
@Override
+ public Optional<Record> findRecord(Record.Type type, RecordData data) {
+ return records.values()
+ .stream()
+ .filter(record -> record.type() == type && record.value().equals(data))
+ .findFirst();
+ }
+
+ @Override
+ public void updateRecord(RecordId id, RecordData newData) {
+ records.computeIfPresent(id, (k, record) -> new Record(id, record.type(), record.name(), newData));
+ }
+
+ @Override
public void removeRecord(RecordId id) {
records.remove(id);
}
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 9b7c527db63..078a7e7cefb 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
@@ -14,12 +14,18 @@ public interface NameService {
* Create a new CNAME record
*
* @param alias The alias to create
- * @param canonicalName The canonical name which the alias should point to. This must be a domain.
+ * @param canonicalName The canonical name which the alias should point to. This must be a FQDN.
*/
- RecordId createCname(String alias, String canonicalName);
+ RecordId createCname(RecordName alias, RecordData canonicalName);
/** Find record by type and name */
- Optional<Record> findRecord(Record.Type type, String name);
+ Optional<Record> findRecord(Record.Type type, RecordName name);
+
+ /** Find record by type and data */
+ Optional<Record> findRecord(Record.Type type, RecordData data);
+
+ /** Update existing record */
+ void updateRecord(RecordId id, RecordData newData);
/** Remove record by ID */
void removeRecord(RecordId id);
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 f190d11cf8f..fd9bddac2c6 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
@@ -12,14 +12,14 @@ public class Record {
private final RecordId id;
private final Type type;
- private final String name;
- private final String value;
+ private final RecordName name;
+ private final RecordData value;
- public Record(RecordId id, Type type, String name, String value) {
- this.id = id;
- this.type = type;
- this.name = name;
- this.value = value;
+ public Record(RecordId id, Type type, RecordName name, RecordData value) {
+ this.id = Objects.requireNonNull(id, "id cannot be null");
+ this.type = Objects.requireNonNull(type, "type cannot be null");
+ this.name = Objects.requireNonNull(name, "name cannot be null");
+ this.value = Objects.requireNonNull(value, "value cannot be null");
}
/** Unique identifier for this */
@@ -33,12 +33,12 @@ public class Record {
}
/** Value for this, e.g. IP address for "A" record */
- public String value() {
+ public RecordData value() {
return value;
}
/** Name of this, e.g. a FQDN for "A" record */
- public String name() {
+ public RecordName name() {
return name;
}
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordData.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordData.java
new file mode 100644
index 00000000000..444ee28f672
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordData.java
@@ -0,0 +1,49 @@
+// 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.Objects;
+
+/**
+ * Represents the data field of a DNS record (RDATA).
+ *
+ * E.g. this may be an IP address for A records, or a FQDN for CNAME records.
+ *
+ * @author mpolden
+ */
+public class RecordData {
+
+ private final String data;
+
+ private RecordData(String data) {
+ this.data = Objects.requireNonNull(data, "data cannot be null");
+ }
+
+ public String asString() {
+ return data;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ RecordData that = (RecordData) o;
+ return Objects.equals(data, that.data);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(data);
+ }
+
+ @Override
+ public String toString() {
+ return "RecordValue{" +
+ "value='" + data + '\'' +
+ '}';
+ }
+
+ public static RecordData from(String data) {
+ return new RecordData(data);
+ }
+
+}
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordName.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordName.java
new file mode 100644
index 00000000000..aa239ece588
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordName.java
@@ -0,0 +1,47 @@
+// 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.Objects;
+
+/**
+ * Represents the name field of a DNS record (NAME). This is typically a FQDN.
+ *
+ * @author mpolden
+ */
+public class RecordName {
+
+ private final String name;
+
+ private RecordName(String name) {
+ this.name = Objects.requireNonNull(name, "name cannot be null");
+ }
+
+ public String asString() {
+ return name;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ RecordName that = (RecordName) o;
+ return Objects.equals(name, that.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name);
+ }
+
+ @Override
+ public String toString() {
+ return "RecordName{" +
+ "name='" + name + '\'' +
+ '}';
+ }
+
+ public static RecordName from(String name) {
+ return new RecordName(name);
+ }
+
+}