denominator.dynect.DynECTResourceRecordSetApi Maven / Gradle / Ivy
package denominator.dynect;
import static denominator.common.Preconditions.checkArgument;
import static denominator.common.Preconditions.checkNotNull;
import static denominator.common.Util.nextOrNull;
import static java.lang.String.format;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import denominator.ResourceRecordSetApi;
import denominator.dynect.DynECT.Record;
import denominator.model.ResourceRecordSet;
import feign.FeignException;
public final class DynECTResourceRecordSetApi implements denominator.ResourceRecordSetApi {
private final DynECT api;
private final String zone;
DynECTResourceRecordSetApi(DynECT api, String zone) {
this.api = api;
this.zone = zone;
}
@Override
public Iterator> iterator() {
try {
return api.rrsets(zone).data;
} catch (FeignException e) {
if (e.getMessage().indexOf("NOT_FOUND") != -1) {
throw new IllegalArgumentException("zone " + zone + " not found", e);
}
throw e;
}
}
@Override
public Iterator> iterateByName(final String name) {
checkNotNull(name, "name");
return emptyIteratorOn404(new Iterable>() {
public Iterator> iterator() {
return api.rrsetsInZoneByName(zone, name).data;
}
});
}
@Override
public ResourceRecordSet> getByNameAndType(final String name, final String type) {
checkNotNull(name, "name");
checkNotNull(type, "type");
Iterator> rrset = emptyIteratorOn404(new Iterable>() {
public Iterator> iterator() {
return api.rrsetsInZoneByNameAndType(zone, name, type).data;
}
});
return nextOrNull(rrset);
}
@Override
public void put(final ResourceRecordSet> rrset) {
checkNotNull(rrset, "rrset was null");
checkArgument(!rrset.records().isEmpty(), "rrset was empty %s", rrset);
int ttlToApply = rrset.ttl() != null ? rrset.ttl() : 0;
List