mirror of
https://github.com/google/nomulus.git
synced 2025-07-20 17:56:08 +02:00
Extract multiple commit prevention in DNS writers into a base class
This still retains the DnsWriter interface itself for better integration with Dagger and to preserve the option of having a DNS writer that does not have this requirement (e.g. because it is idempotent). This also makes the commit check thread-safe, which is a nice-to-have. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=168451114
This commit is contained in:
parent
f6e0d5fa0c
commit
51298aeabb
4 changed files with 49 additions and 32 deletions
|
@ -15,7 +15,6 @@
|
|||
package google.registry.dns.writer.clouddns;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
|
||||
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo;
|
||||
|
@ -33,6 +32,7 @@ import com.google.common.collect.ImmutableSet.Builder;
|
|||
import com.google.common.net.InternetDomainName;
|
||||
import com.google.common.util.concurrent.RateLimiter;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.dns.writer.BaseDnsWriter;
|
||||
import google.registry.dns.writer.DnsWriter;
|
||||
import google.registry.dns.writer.DnsWriterZone;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
|
@ -59,7 +59,7 @@ import org.joda.time.Duration;
|
|||
*
|
||||
* @see <a href="https://cloud.google.com/dns/docs/">Google Cloud DNS Documentation</a>
|
||||
*/
|
||||
public class CloudDnsWriter implements DnsWriter {
|
||||
public class CloudDnsWriter extends BaseDnsWriter {
|
||||
|
||||
/**
|
||||
* The name of the pricing engine, as used in {@code Registry.dnsWriter}. Remember to change
|
||||
|
@ -85,8 +85,6 @@ public class CloudDnsWriter implements DnsWriter {
|
|||
private final ImmutableMap.Builder<String, ImmutableSet<ResourceRecordSet>>
|
||||
desiredRecordsBuilder = new ImmutableMap.Builder<>();
|
||||
|
||||
private boolean committed = false;
|
||||
|
||||
@Inject
|
||||
CloudDnsWriter(
|
||||
Dns dnsConnection,
|
||||
|
@ -273,15 +271,9 @@ public class CloudDnsWriter implements DnsWriter {
|
|||
* representation built via this writer.
|
||||
*/
|
||||
@Override
|
||||
public void commit() {
|
||||
checkState(!committed, "commit() has already been called");
|
||||
committed = true;
|
||||
commit(desiredRecordsBuilder.build());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void commit(ImmutableMap<String, ImmutableSet<ResourceRecordSet>> desiredRecords) {
|
||||
retrier.callWithRetry(getMutateZoneCallback(desiredRecords), ZoneStateException.class);
|
||||
protected void commitUnchecked() {
|
||||
retrier.callWithRetry(
|
||||
getMutateZoneCallback(desiredRecordsBuilder.build()), ZoneStateException.class);
|
||||
logger.info("Wrote to Cloud DNS");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue