From 9b584cba86753aa3c6b137d22a3aac17c7192d21 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Thu, 24 Jan 2019 14:44:06 +0100 Subject: Clean up NameService interface --- .../api/integration/dns/MemoryNameService.java | 13 ++++++------- .../controller/api/integration/dns/NameService.java | 17 ++++------------- .../hosted/controller/api/integration/dns/Record.java | 7 +------ 3 files changed, 11 insertions(+), 26 deletions(-) (limited to 'controller-api/src/main') 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 06599aa0b82..105d2626dcd 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 @@ -6,7 +6,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; @@ -31,17 +30,17 @@ public class MemoryNameService implements NameService { } @Override - public Optional findRecord(Record.Type type, RecordName name) { + public List findRecords(Record.Type type, RecordName name) { return records.values().stream() - .filter(record -> record.type() == type && record.name().equals(name)) - .findFirst(); + .filter(record -> record.type() == type && record.name().equals(name)) + .collect(Collectors.toUnmodifiableList()); } @Override - public List findRecord(Record.Type type, RecordData data) { + public List findRecords(Record.Type type, RecordData data) { return records.values().stream() - .filter(record -> record.type() == type && record.data().equals(data)) - .collect(Collectors.toList()); + .filter(record -> record.type() == type && record.data().equals(data)) + .collect(Collectors.toUnmodifiableList()); } @Override 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 8c5579cf97c..170196fd483 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,9 +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; /** * A managed DNS service. @@ -20,18 +18,11 @@ public interface NameService { */ RecordId createCname(RecordName alias, RecordData canonicalName); - /** Find record by type and name - will throw exception if more than one record matches */ - Optional findRecord(Record.Type type, RecordName name); + /** Find records matching type and name */ + List findRecords(Record.Type type, RecordName name); - /** Find record by type and name - may return multiple records */ - default List findRecords(Record.Type type, RecordName name) { - List result = new ArrayList<>(); - findRecord(type, name).ifPresent(result::add); - return result; - } - - /** Find record by type and data */ - List findRecord(Record.Type type, RecordData data); + /** Find records matching type and data */ + List findRecords(Record.Type type, RecordData data); /** Update existing record */ void updateRecord(RecordId id, RecordData newData); 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 b51202e8261..dd9747ce5ca 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 @@ -56,12 +56,7 @@ public class Record { @Override public String toString() { - return "Record{" + - "id=" + id + - ", type=" + type + - ", name='" + name + '\'' + - ", data='" + data + '\'' + - '}'; + return String.format("%s: %s %s -> %s", id, type, name, data); } @Override -- cgit v1.2.3