mirror of
https://github.com/google/nomulus
synced 2026-07-19 14:32:44 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d0ff74377 | |||
| 7a301edab7 | |||
| 08bcf579a5 | |||
| 7d2330c943 | |||
| 670941bec8 | |||
| 1f516e34b6 | |||
| 70942c87d1 | |||
| 406059db72 |
@@ -117,3 +117,6 @@ core/**/registrar_dbg*.css
|
||||
# Appengine generated files
|
||||
core/WEB-INF/appengine-generated/*.bin
|
||||
core/WEB-INF/appengine-generated/*.xml
|
||||
|
||||
# jEnv
|
||||
.java-version
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
17
|
||||
+3
-2
@@ -383,8 +383,9 @@ subprojects {
|
||||
apply from: "${rootDir.path}/java_common.gradle"
|
||||
|
||||
// When changing Java version here, be sure to update BEAM Java runtime:
|
||||
// in core/build.gradle, search for `flex-template-base-image` and update
|
||||
// the parameter value.
|
||||
// search for `flex-template-base-image` and update the parameter value.
|
||||
// There are at least two instances, one in core/build.gradle, one in
|
||||
// release/stage_beam_pipeline.sh
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ public class CloudTasksUtils implements Serializable {
|
||||
Service service,
|
||||
Multimap<String, String> params,
|
||||
Optional<Integer> jitterSeconds) {
|
||||
if (!jitterSeconds.isPresent() || jitterSeconds.get() <= 0) {
|
||||
if (jitterSeconds.isEmpty() || jitterSeconds.get() <= 0) {
|
||||
return createTask(path, method, service, params);
|
||||
}
|
||||
return createTaskWithDelay(
|
||||
|
||||
@@ -171,7 +171,7 @@ public class DeleteExpiredDomainsAction implements Runnable {
|
||||
tm().transact(
|
||||
() -> {
|
||||
Domain transDomain = tm().loadByKey(domain.createVKey());
|
||||
if (!domain.getAutorenewEndTime().isPresent()
|
||||
if (domain.getAutorenewEndTime().isEmpty()
|
||||
|| domain.getAutorenewEndTime().get().isAfter(tm().getTransactionTime())) {
|
||||
logger.atSevere().log(
|
||||
"Failed to delete domain %s because of its autorenew end time: %s.",
|
||||
|
||||
+1
-1
@@ -151,7 +151,7 @@ public class SendExpiringCertificateNotificationEmailAction implements Runnable
|
||||
DateTime lastExpiringCertNotificationSentDate,
|
||||
CertificateType certificateType,
|
||||
Optional<String> certificate) {
|
||||
if (!certificate.isPresent()
|
||||
if (certificate.isEmpty()
|
||||
|| !certificateChecker.shouldReceiveExpiringNotification(
|
||||
lastExpiringCertNotificationSentDate, certificate.get())) {
|
||||
return false;
|
||||
|
||||
@@ -21,26 +21,21 @@ import google.registry.reporting.billing.BillingModule;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.beam.sdk.coders.AtomicCoder;
|
||||
import org.apache.beam.sdk.coders.Coder;
|
||||
import org.apache.beam.sdk.coders.DoubleCoder;
|
||||
import org.apache.beam.sdk.coders.NullableCoder;
|
||||
import org.apache.beam.sdk.coders.StringUtf8Coder;
|
||||
import org.apache.beam.sdk.coders.VarIntCoder;
|
||||
import org.apache.beam.sdk.coders.VarLongCoder;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* A POJO representing a single billable event, parsed from a {@code SchemaAndRecord}.
|
||||
*
|
||||
* <p>This is a trivially serializable class that allows Beam to transform the results of a Cloud
|
||||
* SQL query into a standard Java representation, giving us the type guarantees and ease of
|
||||
* manipulation Cloud SQL lacks.
|
||||
*/
|
||||
/** A POJO representing a single billable event, parsed from a {@code SchemaAndRecord}. */
|
||||
@AutoValue
|
||||
public abstract class BillingEvent implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3593088371541450077L;
|
||||
public abstract class BillingEvent {
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER =
|
||||
DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss zzz");
|
||||
@@ -85,7 +80,7 @@ public abstract class BillingEvent implements Serializable {
|
||||
/** Returns the tld this event was generated for. */
|
||||
abstract String tld();
|
||||
|
||||
/** Returns the billable action this event was generated for (i.e. RENEW, CREATE, TRANSFER...) */
|
||||
/** Returns the billable action this event was generated for (i.e., RENEW, CREATE, TRANSFER...) */
|
||||
abstract String action();
|
||||
|
||||
/** Returns the fully qualified domain name this event was generated for. */
|
||||
@@ -97,7 +92,7 @@ public abstract class BillingEvent implements Serializable {
|
||||
/** Returns the number of years this billing event is made out for. */
|
||||
abstract int years();
|
||||
|
||||
/** Returns the 3-letter currency code for the billing event (i.e. USD or JPY.) */
|
||||
/** Returns the 3-letter currency code for the billing event (i.e., USD or JPY.) */
|
||||
abstract String currency();
|
||||
|
||||
/** Returns the cost associated with this billing event. */
|
||||
@@ -203,9 +198,7 @@ public abstract class BillingEvent implements Serializable {
|
||||
|
||||
/** Key for each {@code BillingEvent}, when aggregating for the overall invoice. */
|
||||
@AutoValue
|
||||
abstract static class InvoiceGroupingKey implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -151561764235256205L;
|
||||
abstract static class InvoiceGroupingKey {
|
||||
|
||||
private static final ImmutableList<String> INVOICE_HEADERS =
|
||||
ImmutableList.of(
|
||||
@@ -277,8 +270,14 @@ public abstract class BillingEvent implements Serializable {
|
||||
|
||||
/** Coder that provides deterministic (de)serialization for {@code InvoiceGroupingKey}. */
|
||||
static class InvoiceGroupingKeyCoder extends AtomicCoder<InvoiceGroupingKey> {
|
||||
private static final Coder<String> stringCoder = StringUtf8Coder.of();
|
||||
private static final InvoiceGroupingKeyCoder INSTANCE = new InvoiceGroupingKeyCoder();
|
||||
|
||||
private static final long serialVersionUID = 6680701524304107547L;
|
||||
public static InvoiceGroupingKeyCoder of() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private InvoiceGroupingKeyCoder() {}
|
||||
|
||||
@Override
|
||||
public void encode(InvoiceGroupingKey value, OutputStream outStream) throws IOException {
|
||||
@@ -295,7 +294,6 @@ public abstract class BillingEvent implements Serializable {
|
||||
|
||||
@Override
|
||||
public InvoiceGroupingKey decode(InputStream inStream) throws IOException {
|
||||
Coder<String> stringCoder = StringUtf8Coder.of();
|
||||
return new AutoValue_BillingEvent_InvoiceGroupingKey(
|
||||
stringCoder.decode(inStream),
|
||||
stringCoder.decode(inStream),
|
||||
@@ -308,4 +306,55 @@ public abstract class BillingEvent implements Serializable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class BillingEventCoder extends AtomicCoder<BillingEvent> {
|
||||
private static final Coder<String> stringCoder = StringUtf8Coder.of();
|
||||
private static final Coder<Integer> integerCoder = VarIntCoder.of();
|
||||
private static final Coder<Long> longCoder = VarLongCoder.of();
|
||||
private static final Coder<Double> doubleCoder = DoubleCoder.of();
|
||||
private static final BillingEventCoder INSTANCE = new BillingEventCoder();
|
||||
|
||||
static NullableCoder<BillingEvent> ofNullable() {
|
||||
return NullableCoder.of(INSTANCE);
|
||||
}
|
||||
|
||||
private BillingEventCoder() {}
|
||||
|
||||
@Override
|
||||
public void encode(BillingEvent value, OutputStream outStream) throws IOException {
|
||||
longCoder.encode(value.id(), outStream);
|
||||
stringCoder.encode(DATE_TIME_FORMATTER.print(value.billingTime()), outStream);
|
||||
stringCoder.encode(DATE_TIME_FORMATTER.print(value.eventTime()), outStream);
|
||||
stringCoder.encode(value.registrarId(), outStream);
|
||||
stringCoder.encode(value.billingId(), outStream);
|
||||
stringCoder.encode(value.poNumber(), outStream);
|
||||
stringCoder.encode(value.tld(), outStream);
|
||||
stringCoder.encode(value.action(), outStream);
|
||||
stringCoder.encode(value.domain(), outStream);
|
||||
stringCoder.encode(value.repositoryId(), outStream);
|
||||
integerCoder.encode(value.years(), outStream);
|
||||
stringCoder.encode(value.currency(), outStream);
|
||||
doubleCoder.encode(value.amount(), outStream);
|
||||
stringCoder.encode(value.flags(), outStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BillingEvent decode(InputStream inStream) throws IOException {
|
||||
return new AutoValue_BillingEvent(
|
||||
longCoder.decode(inStream),
|
||||
DATE_TIME_FORMATTER.parseDateTime(stringCoder.decode(inStream)),
|
||||
DATE_TIME_FORMATTER.parseDateTime(stringCoder.decode(inStream)),
|
||||
stringCoder.decode(inStream),
|
||||
stringCoder.decode(inStream),
|
||||
stringCoder.decode(inStream),
|
||||
stringCoder.decode(inStream),
|
||||
stringCoder.decode(inStream),
|
||||
stringCoder.decode(inStream),
|
||||
stringCoder.decode(inStream),
|
||||
integerCoder.decode(inStream),
|
||||
stringCoder.decode(inStream),
|
||||
doubleCoder.decode(inStream),
|
||||
stringCoder.decode(inStream));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static org.apache.beam.sdk.values.TypeDescriptors.strings;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import google.registry.beam.billing.BillingEvent.BillingEventCoder;
|
||||
import google.registry.beam.billing.BillingEvent.InvoiceGroupingKey;
|
||||
import google.registry.beam.billing.BillingEvent.InvoiceGroupingKey.InvoiceGroupingKeyCoder;
|
||||
import google.registry.beam.common.RegistryJpaIO;
|
||||
@@ -30,6 +31,7 @@ import google.registry.reporting.billing.BillingModule;
|
||||
import google.registry.util.DomainNameUtils;
|
||||
import google.registry.util.ResourceUtils;
|
||||
import google.registry.util.SqlTemplate;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.YearMonth;
|
||||
import java.util.Objects;
|
||||
@@ -37,13 +39,13 @@ import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.beam.sdk.Pipeline;
|
||||
import org.apache.beam.sdk.PipelineResult;
|
||||
import org.apache.beam.sdk.coders.SerializableCoder;
|
||||
import org.apache.beam.sdk.coders.StringUtf8Coder;
|
||||
import org.apache.beam.sdk.io.FileIO;
|
||||
import org.apache.beam.sdk.io.TextIO;
|
||||
import org.apache.beam.sdk.options.PipelineOptionsFactory;
|
||||
import org.apache.beam.sdk.transforms.Contextful;
|
||||
import org.apache.beam.sdk.transforms.Count;
|
||||
import org.apache.beam.sdk.transforms.Distinct;
|
||||
import org.apache.beam.sdk.transforms.Filter;
|
||||
import org.apache.beam.sdk.transforms.MapElements;
|
||||
import org.apache.beam.sdk.transforms.PTransform;
|
||||
@@ -65,7 +67,7 @@ import org.joda.money.CurrencyUnit;
|
||||
*/
|
||||
public class InvoicingPipeline implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 5386330443625580081L;
|
||||
@Serial private static final long serialVersionUID = 5386330443625580081L;
|
||||
|
||||
private static final Pattern SQL_COMMENT_REGEX =
|
||||
Pattern.compile("^\\s*--.*\\n", Pattern.MULTILINE);
|
||||
@@ -97,13 +99,11 @@ public class InvoicingPipeline implements Serializable {
|
||||
Read<Object[], google.registry.beam.billing.BillingEvent> read =
|
||||
RegistryJpaIO.<Object[], google.registry.beam.billing.BillingEvent>read(
|
||||
makeCloudSqlQuery(options.getYearMonth()), false, row -> parseRow(row).orElse(null))
|
||||
.withCoder(SerializableCoder.of(google.registry.beam.billing.BillingEvent.class));
|
||||
|
||||
PCollection<google.registry.beam.billing.BillingEvent> billingEventsWithNulls =
|
||||
pipeline.apply("Read BillingEvents from Cloud SQL", read);
|
||||
|
||||
// Remove null billing events
|
||||
return billingEventsWithNulls.apply(Filter.by(Objects::nonNull));
|
||||
.withCoder(BillingEventCoder.ofNullable());
|
||||
return pipeline
|
||||
.apply("Read BillingEvents from Cloud SQL", read)
|
||||
.apply("Remove null elements", Filter.by(Objects::nonNull))
|
||||
.apply("Remove duplicates", Distinct.create());
|
||||
}
|
||||
|
||||
private static Optional<google.registry.beam.billing.BillingEvent> parseRow(Object[] row) {
|
||||
@@ -142,7 +142,7 @@ public class InvoicingPipeline implements Serializable {
|
||||
extends PTransform<
|
||||
PCollection<google.registry.beam.billing.BillingEvent>, PCollection<String>> {
|
||||
|
||||
private static final long serialVersionUID = -8090619008258393728L;
|
||||
@Serial private static final long serialVersionUID = -8090619008258393728L;
|
||||
|
||||
@Override
|
||||
public PCollection<String> expand(
|
||||
@@ -152,9 +152,9 @@ public class InvoicingPipeline implements Serializable {
|
||||
"Map to invoicing key",
|
||||
MapElements.into(TypeDescriptor.of(InvoiceGroupingKey.class))
|
||||
.via(google.registry.beam.billing.BillingEvent::getInvoiceGroupingKey))
|
||||
.setCoder(InvoiceGroupingKeyCoder.of())
|
||||
.apply(
|
||||
"Filter out free events", Filter.by((InvoiceGroupingKey key) -> key.unitPrice() != 0))
|
||||
.setCoder(new InvoiceGroupingKeyCoder())
|
||||
.apply("Count occurrences", Count.perElement())
|
||||
.apply(
|
||||
"Format as CSVs",
|
||||
|
||||
@@ -219,8 +219,7 @@ public final class RegistryJpaIO {
|
||||
() -> {
|
||||
query.stream().map(resultMapper::apply).forEach(outputReceiver::output);
|
||||
return null;
|
||||
},
|
||||
null);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class BsaDownloadAction implements Runnable {
|
||||
return null;
|
||||
}
|
||||
Optional<DownloadSchedule> scheduleOptional = downloadScheduler.schedule();
|
||||
if (!scheduleOptional.isPresent()) {
|
||||
if (scheduleOptional.isEmpty()) {
|
||||
logger.atInfo().log("Nothing to do.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class BsaRefreshAction implements Runnable {
|
||||
return null;
|
||||
}
|
||||
Optional<RefreshSchedule> maybeSchedule = scheduler.schedule();
|
||||
if (!maybeSchedule.isPresent()) {
|
||||
if (maybeSchedule.isEmpty()) {
|
||||
logger.atInfo().log("No completed downloads yet. Exiting.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ public final class BsaTransactions {
|
||||
@CanIgnoreReturnValue
|
||||
public static <T> T bsaTransact(Callable<T> work) {
|
||||
verify(!isInTransaction(), "May only be used for top-level transactions.");
|
||||
return tm().transact(work, TRANSACTION_REPEATABLE_READ);
|
||||
return tm().transact(TRANSACTION_REPEATABLE_READ, work);
|
||||
}
|
||||
|
||||
public static void bsaTransact(ThrowingRunnable work) {
|
||||
verify(!isInTransaction(), "May only be used for top-level transactions.");
|
||||
tm().transact(work, TRANSACTION_REPEATABLE_READ);
|
||||
tm().transact(TRANSACTION_REPEATABLE_READ, work);
|
||||
}
|
||||
|
||||
@CanIgnoreReturnValue
|
||||
|
||||
@@ -67,6 +67,7 @@ public final class LabelDiffUpdates {
|
||||
labels.stream().collect(groupingBy(BlockLabel::labelType, toImmutableList())));
|
||||
|
||||
tm().transact(
|
||||
TRANSACTION_REPEATABLE_READ,
|
||||
() -> {
|
||||
for (Map.Entry<LabelType, ImmutableList<BlockLabel>> entry :
|
||||
labelsByType.entrySet()) {
|
||||
@@ -128,8 +129,7 @@ public final class LabelDiffUpdates {
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
TRANSACTION_REPEATABLE_READ);
|
||||
});
|
||||
logger.atInfo().log("Processed %s of labels.", labels.size());
|
||||
return nonBlockedDomains.build();
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class RefreshScheduler {
|
||||
}
|
||||
// No previously completed refreshes. Need start time of a completed download as
|
||||
// lower bound of refresh checks.
|
||||
if (!mostRecentDownload.isPresent()) {
|
||||
if (mostRecentDownload.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ public class CloudDnsWriter extends BaseDnsWriter {
|
||||
// Return early if no DNS records should be published.
|
||||
// desiredRecordsBuilder is populated with an empty set to indicate that all existing records
|
||||
// should be deleted.
|
||||
if (!domain.isPresent() || !domain.get().shouldPublishToDns()) {
|
||||
if (domain.isEmpty() || !domain.get().shouldPublishToDns()) {
|
||||
desiredRecords.put(absoluteDomainName, ImmutableSet.of());
|
||||
return;
|
||||
}
|
||||
@@ -192,7 +192,7 @@ public class CloudDnsWriter extends BaseDnsWriter {
|
||||
Optional<Host> host = loadByForeignKey(Host.class, hostName, clock.nowUtc());
|
||||
|
||||
// Return early if the host is deleted.
|
||||
if (!host.isPresent()) {
|
||||
if (host.isEmpty()) {
|
||||
desiredRecords.put(absoluteHostName, ImmutableSet.of());
|
||||
return;
|
||||
}
|
||||
@@ -247,7 +247,7 @@ public class CloudDnsWriter extends BaseDnsWriter {
|
||||
Optional<InternetDomainName> tld = Tlds.findTldForName(host);
|
||||
|
||||
// Host not managed by our registry, no need to update DNS.
|
||||
if (!tld.isPresent()) {
|
||||
if (tld.isEmpty()) {
|
||||
logger.atSevere().log("publishHost called for invalid host '%s'.", hostName);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ public class DnsUpdateWriter extends BaseDnsWriter {
|
||||
Optional<InternetDomainName> tld = Tlds.findTldForName(host);
|
||||
|
||||
// host not managed by our registry, no need to update DNS.
|
||||
if (!tld.isPresent()) {
|
||||
if (tld.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ public class ExportPremiumTermsAction implements Runnable {
|
||||
"Skipping premium terms export for TLD %s because Drive folder isn't specified.", tldStr);
|
||||
return Optional.of("Skipping export because no Drive folder is associated with this TLD");
|
||||
}
|
||||
if (!tld.getPremiumListName().isPresent()) {
|
||||
if (tld.getPremiumListName().isEmpty()) {
|
||||
logger.atInfo().log("No premium terms to export for TLD '%s'.", tldStr);
|
||||
return Optional.of("No premium lists configured");
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class SyncRegistrarsSheet {
|
||||
boolean wereRegistrarsModified() {
|
||||
Optional<Cursor> cursor =
|
||||
tm().transact(() -> tm().loadByKeyIfPresent(Cursor.createGlobalVKey(SYNC_REGISTRAR_SHEET)));
|
||||
DateTime lastUpdateTime = !cursor.isPresent() ? START_OF_TIME : cursor.get().getCursorTime();
|
||||
DateTime lastUpdateTime = cursor.isEmpty() ? START_OF_TIME : cursor.get().getCursorTime();
|
||||
for (Registrar registrar : Registrar.loadAllCached()) {
|
||||
if (DateTimeUtils.isAtOrAfter(registrar.getLastUpdateTime(), lastUpdateTime)) {
|
||||
return true;
|
||||
|
||||
@@ -112,11 +112,11 @@ public class SyncRegistrarsSheetAction implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
final Optional<String> sheetId = Optional.ofNullable(idParam.orElse(idConfig.orElse(null)));
|
||||
if (!sheetId.isPresent()) {
|
||||
if (sheetId.isEmpty()) {
|
||||
Result.MISSINGNO.send(response, null);
|
||||
return;
|
||||
}
|
||||
if (!idParam.isPresent()) {
|
||||
if (idParam.isEmpty()) {
|
||||
if (!syncRegistrarsSheet.wereRegistrarsModified()) {
|
||||
Result.NOTMODIFIED.send(response, null);
|
||||
return;
|
||||
|
||||
@@ -22,7 +22,6 @@ import static google.registry.flows.FlowUtils.unmarshalEpp;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import google.registry.flows.FlowModule.EppExceptionInProviderException;
|
||||
@@ -45,7 +44,7 @@ import org.json.simple.JSONValue;
|
||||
public final class EppController {
|
||||
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
private static final String LOG_SEPARATOR = Strings.repeat("=", 40);
|
||||
private static final String LOG_SEPARATOR = "=".repeat(40);
|
||||
|
||||
@Inject FlowComponent.Builder flowComponentBuilder;
|
||||
@Inject EppMetric.Builder eppMetricBuilder;
|
||||
|
||||
@@ -17,7 +17,6 @@ package google.registry.flows;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.xml.XmlTransformer.prettyPrint;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import google.registry.flows.FlowModule.DryRun;
|
||||
import google.registry.flows.FlowModule.InputXml;
|
||||
@@ -36,7 +35,7 @@ import javax.inject.Provider;
|
||||
/** Run a flow, either transactionally or not, with logging and retrying as needed. */
|
||||
public class FlowRunner {
|
||||
|
||||
private static final String COMMAND_LOG_FORMAT = "EPP Command" + Strings.repeat("\n\t%s", 8);
|
||||
private static final String COMMAND_LOG_FORMAT = "EPP Command" + "\n\t%s".repeat(8);
|
||||
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
@@ -81,6 +80,7 @@ public class FlowRunner {
|
||||
// TODO(mcilwain/weiminyu): Use transactReadOnly() here for TransactionalFlow and transact()
|
||||
// for MutatingFlow.
|
||||
return tm().transact(
|
||||
isolationLevelOverride.orElse(null),
|
||||
() -> {
|
||||
try {
|
||||
EppOutput output = EppOutput.create(flowProvider.get().run());
|
||||
@@ -96,8 +96,7 @@ public class FlowRunner {
|
||||
} catch (EppException e) {
|
||||
throw new EppRuntimeException(e);
|
||||
}
|
||||
},
|
||||
isolationLevelOverride.orElse(null));
|
||||
});
|
||||
} catch (DryRunException e) {
|
||||
return e.output;
|
||||
} catch (EppRuntimeException e) {
|
||||
|
||||
@@ -122,7 +122,7 @@ public final class ResourceFlowUtils {
|
||||
/** Check that the given AuthInfo is present for a resource being transferred. */
|
||||
public static void verifyAuthInfoPresentForResourceTransfer(Optional<AuthInfo> authInfo)
|
||||
throws EppException {
|
||||
if (!authInfo.isPresent()) {
|
||||
if (authInfo.isEmpty()) {
|
||||
throw new MissingTransferRequestAuthInfoException();
|
||||
}
|
||||
}
|
||||
@@ -160,7 +160,7 @@ public final class ResourceFlowUtils {
|
||||
domain.getReferencedContacts().stream()
|
||||
.filter(key -> key.getKey().equals(authRepoId))
|
||||
.findFirst();
|
||||
if (!foundContact.isPresent()) {
|
||||
if (foundContact.isEmpty()) {
|
||||
throw new BadAuthInfoForResourceException();
|
||||
}
|
||||
// Check the authInfo against the contact.
|
||||
|
||||
@@ -105,7 +105,7 @@ public class TlsCredentials implements TransportCredentials {
|
||||
}
|
||||
// In the rare unexpected case that the client inet address wasn't passed along at all, then
|
||||
// by default deny access.
|
||||
if (!clientInetAddr.isPresent()) {
|
||||
if (clientInetAddr.isEmpty()) {
|
||||
logger.atWarning().log(
|
||||
"Authentication error: Missing IP address for registrar %s.", registrar.getRegistrarId());
|
||||
throw new BadRegistrarIpAddressException(clientInetAddr);
|
||||
@@ -129,8 +129,8 @@ public class TlsCredentials implements TransportCredentials {
|
||||
|
||||
@VisibleForTesting
|
||||
void validateCertificateHash(Registrar registrar) throws AuthenticationErrorException {
|
||||
if (!registrar.getClientCertificateHash().isPresent()
|
||||
&& !registrar.getFailoverClientCertificateHash().isPresent()) {
|
||||
if (registrar.getClientCertificateHash().isEmpty()
|
||||
&& registrar.getFailoverClientCertificateHash().isEmpty()) {
|
||||
if (requireSslCertificates) {
|
||||
throw new RegistrarCertificateNotConfiguredException();
|
||||
} else {
|
||||
@@ -140,7 +140,7 @@ public class TlsCredentials implements TransportCredentials {
|
||||
}
|
||||
}
|
||||
// Check that the request included the certificate hash
|
||||
if (!clientCertificateHash.isPresent()) {
|
||||
if (clientCertificateHash.isEmpty()) {
|
||||
logger.atInfo().log(
|
||||
"Request from registrar %s did not include X-SSL-Certificate.",
|
||||
registrar.getRegistrarId());
|
||||
|
||||
@@ -75,7 +75,7 @@ public final class ContactTransferQueryFlow implements TransactionalFlow {
|
||||
}
|
||||
// Note that the authorization info on the command (if present) has already been verified. If
|
||||
// it's present, then the other checks are unnecessary.
|
||||
if (!authInfo.isPresent()
|
||||
if (authInfo.isEmpty()
|
||||
&& !registrarId.equals(contact.getTransferData().getGainingRegistrarId())
|
||||
&& !registrarId.equals(contact.getTransferData().getLosingRegistrarId())) {
|
||||
throw new NotAuthorizedToViewTransferException();
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package google.registry.flows.custom;
|
||||
|
||||
import com.google.auto.value.AutoBuilder;
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.flows.EppException;
|
||||
@@ -81,30 +82,23 @@ public class DomainRenewFlowCustomLogic extends BaseFlowCustomLogic {
|
||||
}
|
||||
|
||||
/** A class to encapsulate parameters for a call to {@link #afterValidation}. */
|
||||
@AutoValue
|
||||
public abstract static class AfterValidationParameters extends ImmutableObject {
|
||||
|
||||
public abstract Domain existingDomain();
|
||||
|
||||
public abstract int years();
|
||||
|
||||
public abstract DateTime now();
|
||||
public record AfterValidationParameters(Domain existingDomain, int years, DateTime now) {
|
||||
|
||||
public static Builder newBuilder() {
|
||||
return new AutoValue_DomainRenewFlowCustomLogic_AfterValidationParameters.Builder();
|
||||
return new AutoBuilder_DomainRenewFlowCustomLogic_AfterValidationParameters_Builder();
|
||||
}
|
||||
|
||||
/** Builder for {@link AfterValidationParameters}. */
|
||||
@AutoValue.Builder
|
||||
public abstract static class Builder {
|
||||
@AutoBuilder
|
||||
public interface Builder {
|
||||
|
||||
public abstract Builder setExistingDomain(Domain existingDomain);
|
||||
Builder setExistingDomain(Domain existingDomain);
|
||||
|
||||
public abstract Builder setYears(int years);
|
||||
Builder setYears(int years);
|
||||
|
||||
public abstract Builder setNow(DateTime now);
|
||||
Builder setNow(DateTime now);
|
||||
|
||||
public abstract AfterValidationParameters build();
|
||||
AfterValidationParameters build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ public final class DomainCheckFlow implements TransactionalFlow {
|
||||
domainCheckResults,
|
||||
tldStates,
|
||||
allocationToken);
|
||||
boolean isAvailable = !message.isPresent();
|
||||
boolean isAvailable = message.isEmpty();
|
||||
checksBuilder.add(DomainCheck.create(isAvailable, domainName, message.orElse(null)));
|
||||
if (isAvailable) {
|
||||
availableDomains.add(domainName);
|
||||
@@ -289,7 +289,7 @@ public final class DomainCheckFlow implements TransactionalFlow {
|
||||
throws EppException {
|
||||
Optional<FeeCheckCommandExtension> feeCheckOpt =
|
||||
eppInput.getSingleExtension(FeeCheckCommandExtension.class);
|
||||
if (!feeCheckOpt.isPresent()) {
|
||||
if (feeCheckOpt.isEmpty()) {
|
||||
return ImmutableList.of(); // No fee checks were requested.
|
||||
}
|
||||
FeeCheckCommandExtension<?, ?> feeCheck = feeCheckOpt.get();
|
||||
|
||||
@@ -276,7 +276,7 @@ public final class DomainCreateFlow implements MutatingFlow {
|
||||
now,
|
||||
eppInput.getSingleExtension(AllocationTokenExtension.class));
|
||||
boolean defaultTokenUsed = false;
|
||||
if (!allocationToken.isPresent()) {
|
||||
if (allocationToken.isEmpty()) {
|
||||
allocationToken =
|
||||
DomainFlowUtils.checkForDefaultToken(
|
||||
tld, command.getDomainName(), CommandName.CREATE, registrarId, now);
|
||||
@@ -519,7 +519,7 @@ public final class DomainCreateFlow implements MutatingFlow {
|
||||
if (behavior.equals(RegistrationBehavior.BYPASS_TLD_STATE)
|
||||
|| behavior.equals(RegistrationBehavior.ANCHOR_TENANT)) {
|
||||
// Non-trademarked names with the state check bypassed are always available
|
||||
if (!claimsList.getClaimKey(domainLabel).isPresent()) {
|
||||
if (claimsList.getClaimKey(domainLabel).isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!currentState.equals(START_DATE_SUNRISE)) {
|
||||
|
||||
@@ -215,7 +215,7 @@ public class DomainFlowUtils {
|
||||
throw new DomainNameExistsAsTldException();
|
||||
}
|
||||
Optional<InternetDomainName> tldParsed = findTldForName(domainName);
|
||||
if (!tldParsed.isPresent()) {
|
||||
if (tldParsed.isEmpty()) {
|
||||
throw new TldDoesNotExistException(domainName.parent().toString());
|
||||
}
|
||||
if (domainName.parts().size() != tldParsed.get().parts().size() + 1) {
|
||||
@@ -256,7 +256,7 @@ public class DomainFlowUtils {
|
||||
Optional<String> idnTableName =
|
||||
IDN_LABEL_VALIDATOR.findValidIdnTableForTld(
|
||||
domainName.parts().get(0), domainName.parent().toString());
|
||||
if (!idnTableName.isPresent()) {
|
||||
if (idnTableName.isEmpty()) {
|
||||
throw new InvalidIdnDomainLabelException();
|
||||
}
|
||||
return idnTableName.get();
|
||||
@@ -368,7 +368,7 @@ public class DomainFlowUtils {
|
||||
}
|
||||
ImmutableList<DomainDsData> invalidDigestTypes =
|
||||
dsData.stream()
|
||||
.filter(ds -> !DigestType.fromWireValue(ds.getDigestType()).isPresent())
|
||||
.filter(ds -> DigestType.fromWireValue(ds.getDigestType()).isEmpty())
|
||||
.collect(toImmutableList());
|
||||
if (!invalidDigestTypes.isEmpty()) {
|
||||
throw new InvalidDsRecordException(
|
||||
@@ -816,7 +816,7 @@ public class DomainFlowUtils {
|
||||
FeesAndCredits feesAndCredits,
|
||||
boolean defaultTokenUsed)
|
||||
throws EppException {
|
||||
if (feesAndCredits.hasAnyPremiumFees() && !feeCommand.isPresent()) {
|
||||
if (feesAndCredits.hasAnyPremiumFees() && feeCommand.isEmpty()) {
|
||||
throw new FeesRequiredForPremiumNameException();
|
||||
}
|
||||
validateFeesAckedIfPresent(feeCommand, feesAndCredits, defaultTokenUsed);
|
||||
@@ -837,7 +837,7 @@ public class DomainFlowUtils {
|
||||
// Check for the case where a fee command extension was required but not provided.
|
||||
// This only happens when the total fees are non-zero and include custom fees requiring the
|
||||
// extension.
|
||||
if (!feeCommand.isPresent()) {
|
||||
if (feeCommand.isEmpty()) {
|
||||
if (!feesAndCredits.getEapCost().isZero()) {
|
||||
throw new FeesRequiredDuringEarlyAccessProgramException(feesAndCredits.getEapCost());
|
||||
}
|
||||
@@ -1049,7 +1049,7 @@ public class DomainFlowUtils {
|
||||
/** Validate the secDNS extension, if present. */
|
||||
static Optional<SecDnsCreateExtension> validateSecDnsExtension(
|
||||
Optional<SecDnsCreateExtension> secDnsCreate) throws EppException {
|
||||
if (!secDnsCreate.isPresent()) {
|
||||
if (secDnsCreate.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (secDnsCreate.get().getDsData() == null) {
|
||||
|
||||
@@ -182,7 +182,7 @@ public final class DomainRenewFlow implements MutatingFlow {
|
||||
CommandName.RENEW,
|
||||
eppInput.getSingleExtension(AllocationTokenExtension.class));
|
||||
boolean defaultTokenUsed = false;
|
||||
if (!allocationToken.isPresent()) {
|
||||
if (allocationToken.isEmpty()) {
|
||||
allocationToken =
|
||||
DomainFlowUtils.checkForDefaultToken(
|
||||
tld, existingDomain.getDomainName(), CommandName.RENEW, registrarId, now);
|
||||
|
||||
@@ -81,7 +81,7 @@ public final class DomainTransferQueryFlow implements TransactionalFlow {
|
||||
}
|
||||
// Note that the authorization info on the command (if present) has already been verified. If
|
||||
// it's present, then the other checks are unnecessary.
|
||||
if (!authInfo.isPresent()
|
||||
if (authInfo.isEmpty()
|
||||
&& !registrarId.equals(transferData.getGainingRegistrarId())
|
||||
&& !registrarId.equals(transferData.getLosingRegistrarId())) {
|
||||
throw new NotAuthorizedToViewTransferException();
|
||||
|
||||
@@ -201,7 +201,7 @@ public final class DomainTransferRequestFlow implements MutatingFlow {
|
||||
Optional<FeesAndCredits> feesAndCredits;
|
||||
if (period.getValue() == 0) {
|
||||
feesAndCredits = Optional.empty();
|
||||
} else if (!existingDomain.getCurrentBulkToken().isPresent()) {
|
||||
} else if (existingDomain.getCurrentBulkToken().isEmpty()) {
|
||||
feesAndCredits =
|
||||
Optional.of(pricingLogic.getTransferPrice(tld, targetId, now, existingBillingRecurrence));
|
||||
} else {
|
||||
|
||||
@@ -182,7 +182,7 @@ public class AllocationTokenFlowUtils {
|
||||
maybeTokenEntity =
|
||||
tm().transact(() -> tm().loadByKeyIfPresent(VKey.create(AllocationToken.class, token)));
|
||||
|
||||
if (!maybeTokenEntity.isPresent()) {
|
||||
if (maybeTokenEntity.isEmpty()) {
|
||||
throw new InvalidAllocationTokenException();
|
||||
}
|
||||
if (maybeTokenEntity.get().isRedeemed()) {
|
||||
@@ -199,7 +199,7 @@ public class AllocationTokenFlowUtils {
|
||||
DateTime now,
|
||||
Optional<AllocationTokenExtension> extension)
|
||||
throws EppException {
|
||||
if (!extension.isPresent()) {
|
||||
if (extension.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
AllocationToken tokenEntity = loadToken(extension.get().getAllocationToken());
|
||||
@@ -222,7 +222,7 @@ public class AllocationTokenFlowUtils {
|
||||
CommandName commandName,
|
||||
Optional<AllocationTokenExtension> extension)
|
||||
throws EppException {
|
||||
if (!extension.isPresent()) {
|
||||
if (extension.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
AllocationToken tokenEntity = loadToken(extension.get().getAllocationToken());
|
||||
@@ -254,7 +254,7 @@ public class AllocationTokenFlowUtils {
|
||||
|
||||
public static Domain maybeApplyBulkPricingRemovalToken(
|
||||
Domain domain, Optional<AllocationToken> allocationToken) {
|
||||
if (!allocationToken.isPresent()
|
||||
if (allocationToken.isEmpty()
|
||||
|| !TokenBehavior.REMOVE_BULK_PRICING.equals(allocationToken.get().getTokenBehavior())) {
|
||||
return domain;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class HostFlowUtils {
|
||||
public static Optional<Domain> lookupSuperordinateDomain(
|
||||
InternetDomainName hostName, DateTime now) throws EppException {
|
||||
Optional<InternetDomainName> tld = findTldForName(hostName);
|
||||
if (!tld.isPresent()) {
|
||||
if (tld.isEmpty()) {
|
||||
// This is an host on a TLD we don't run, therefore obviously external, so we are done.
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class HostFlowUtils {
|
||||
.skip(hostName.parts().size() - (tld.get().parts().size() + 1))
|
||||
.collect(joining("."));
|
||||
Optional<Domain> superordinateDomain = loadByForeignKey(Domain.class, domainName, now);
|
||||
if (!superordinateDomain.isPresent() || !isActive(superordinateDomain.get(), now)) {
|
||||
if (superordinateDomain.isEmpty() || !isActive(superordinateDomain.get(), now)) {
|
||||
throw new SuperordinateDomainDoesNotExistException(domainName);
|
||||
}
|
||||
return superordinateDomain;
|
||||
|
||||
@@ -148,23 +148,25 @@ public class FlowPicker {
|
||||
* <p>This provider must be tried before {@link #RESOURCE_CRUD_FLOW_PROVIDER}. Otherwise, the
|
||||
* regular domain update flow will match first.
|
||||
*/
|
||||
private static final FlowProvider DOMAIN_RESTORE_FLOW_PROVIDER = new FlowProvider() {
|
||||
@Override
|
||||
Class<? extends Flow> get(
|
||||
EppInput eppInput, InnerCommand innerCommand, ResourceCommand resourceCommand) {
|
||||
if (!(resourceCommand instanceof DomainCommand.Update)) {
|
||||
return null;
|
||||
}
|
||||
Optional<RgpUpdateExtension> rgpUpdateExtension =
|
||||
eppInput.getSingleExtension(RgpUpdateExtension.class);
|
||||
if (!rgpUpdateExtension.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
// Restore command with an op of "report" is not currently supported.
|
||||
return (rgpUpdateExtension.get().getRestoreCommand().getRestoreOp() == RestoreOp.REQUEST)
|
||||
? DomainRestoreRequestFlow.class
|
||||
: UnimplementedRestoreFlow.class;
|
||||
}};
|
||||
private static final FlowProvider DOMAIN_RESTORE_FLOW_PROVIDER =
|
||||
new FlowProvider() {
|
||||
@Override
|
||||
Class<? extends Flow> get(
|
||||
EppInput eppInput, InnerCommand innerCommand, ResourceCommand resourceCommand) {
|
||||
if (!(resourceCommand instanceof DomainCommand.Update)) {
|
||||
return null;
|
||||
}
|
||||
Optional<RgpUpdateExtension> rgpUpdateExtension =
|
||||
eppInput.getSingleExtension(RgpUpdateExtension.class);
|
||||
if (rgpUpdateExtension.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// Restore command with an op of "report" is not currently supported.
|
||||
return (rgpUpdateExtension.get().getRestoreCommand().getRestoreOp() == RestoreOp.REQUEST)
|
||||
? DomainRestoreRequestFlow.class
|
||||
: UnimplementedRestoreFlow.class;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The claims check flow is keyed on the type of the {@link ResourceCommand} and on having the
|
||||
@@ -180,7 +182,7 @@ public class FlowPicker {
|
||||
}
|
||||
Optional<LaunchCheckExtension> launchCheck =
|
||||
eppInput.getSingleExtension(LaunchCheckExtension.class);
|
||||
if (!launchCheck.isPresent()
|
||||
if (launchCheck.isEmpty()
|
||||
|| CheckType.AVAILABILITY.equals(launchCheck.get().getCheckType())) {
|
||||
// We don't distinguish between registry phases for "avail", so don't bother checking
|
||||
// phase.
|
||||
|
||||
@@ -86,7 +86,7 @@ public final class PollAckFlow implements MutatingFlow {
|
||||
// it as if it doesn't exist yet. Same for if the message ID year isn't the same as the actual
|
||||
// poll message's event time (that means they're passing in an old already-acked ID).
|
||||
Optional<PollMessage> maybePollMessage = tm().loadByKeyIfPresent(pollMessageKey);
|
||||
if (!maybePollMessage.isPresent()
|
||||
if (maybePollMessage.isEmpty()
|
||||
|| !isBeforeOrAt(maybePollMessage.get().getEventTime(), now)
|
||||
|| !makePollMessageExternalId(maybePollMessage.get()).equals(messageId)) {
|
||||
throw new MessageDoesNotExistException(messageId);
|
||||
|
||||
@@ -66,7 +66,7 @@ public final class PollRequestFlow implements TransactionalFlow {
|
||||
// Return the oldest message from the queue.
|
||||
DateTime now = tm().getTransactionTime();
|
||||
Optional<PollMessage> maybePollMessage = getFirstPollMessage(registrarId, now);
|
||||
if (!maybePollMessage.isPresent()) {
|
||||
if (maybePollMessage.isEmpty()) {
|
||||
return responseBuilder.setResultFromCode(SUCCESS_WITH_NO_MESSAGES).build();
|
||||
}
|
||||
PollMessage pollMessage = maybePollMessage.get();
|
||||
|
||||
@@ -123,7 +123,7 @@ public class LoginFlow implements MutatingFlow {
|
||||
serviceExtensionUrisBuilder.add(uri);
|
||||
}
|
||||
Optional<Registrar> registrar = Registrar.loadByRegistrarIdCached(login.getClientId());
|
||||
if (!registrar.isPresent()) {
|
||||
if (registrar.isEmpty()) {
|
||||
throw new BadRegistrarIdException(login.getClientId());
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ public class LoginFlow implements MutatingFlow {
|
||||
});
|
||||
// Load fresh from database (bypassing the cache) to ensure we don't save stale data.
|
||||
Optional<Registrar> freshRegistrar = Registrar.loadByRegistrarId(login.getClientId());
|
||||
if (!freshRegistrar.isPresent()) {
|
||||
if (freshRegistrar.isEmpty()) {
|
||||
throw new BadRegistrarIdException(login.getClientId());
|
||||
}
|
||||
tm().put(freshRegistrar.get().asBuilder().setPassword(newPassword).build());
|
||||
|
||||
@@ -539,7 +539,7 @@ public class DomainBase extends EppResource
|
||||
for (GracePeriod gracePeriod : almostBuilt.getGracePeriods()) {
|
||||
if (isBeforeOrAt(gracePeriod.getExpirationTime(), now)) {
|
||||
builder.removeGracePeriod(gracePeriod);
|
||||
if (!newLastEppUpdateTime.isPresent()
|
||||
if (newLastEppUpdateTime.isEmpty()
|
||||
|| isBeforeOrAt(newLastEppUpdateTime.get(), gracePeriod.getExpirationTime())) {
|
||||
newLastEppUpdateTime = Optional.of(gracePeriod.getExpirationTime());
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ public final class RegistryLock extends UpdateAutoTimestampEntity implements Bui
|
||||
|
||||
/** Returns true iff the lock was requested >= 1 hour ago and has not been verified. */
|
||||
public boolean isLockRequestExpired(DateTime now) {
|
||||
return !getLockCompletionTime().isPresent()
|
||||
return getLockCompletionTime().isEmpty()
|
||||
&& isBeforeOrAt(getLockRequestTime(), now.minusHours(1));
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ public final class RegistryLock extends UpdateAutoTimestampEntity implements Bui
|
||||
public boolean isUnlockRequestExpired(DateTime now) {
|
||||
Optional<DateTime> unlockRequestTimestamp = getUnlockRequestTime();
|
||||
return unlockRequestTimestamp.isPresent()
|
||||
&& !getUnlockCompletionTime().isPresent()
|
||||
&& getUnlockCompletionTime().isEmpty()
|
||||
&& isBeforeOrAt(unlockRequestTimestamp.get(), now.minusHours(1));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
|
||||
import static google.registry.util.DateTimeUtils.isAtOrAfter;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
@@ -129,26 +128,11 @@ public class Lock extends ImmutableObject implements Serializable {
|
||||
return String.format("%s-%s", scope, resourceName);
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
abstract static class AcquireResult {
|
||||
public abstract DateTime transactionTime();
|
||||
|
||||
@Nullable
|
||||
public abstract Lock existingLock();
|
||||
|
||||
@Nullable
|
||||
public abstract Lock newLock();
|
||||
|
||||
public abstract LockState lockState();
|
||||
|
||||
public static AcquireResult create(
|
||||
DateTime transactionTime,
|
||||
@Nullable Lock existingLock,
|
||||
@Nullable Lock newLock,
|
||||
LockState lockState) {
|
||||
return new AutoValue_Lock_AcquireResult(transactionTime, existingLock, newLock, lockState);
|
||||
}
|
||||
}
|
||||
record AcquireResult(
|
||||
DateTime transactionTime,
|
||||
@Nullable Lock existingLock,
|
||||
@Nullable Lock newLock,
|
||||
LockState lockState) {}
|
||||
|
||||
private static void logAcquireResult(AcquireResult acquireResult) {
|
||||
try {
|
||||
@@ -204,13 +188,13 @@ public class Lock extends ImmutableObject implements Serializable {
|
||||
lockState = LockState.TIMED_OUT;
|
||||
} else {
|
||||
lockState = LockState.IN_USE;
|
||||
return AcquireResult.create(now, lock, null, lockState);
|
||||
return new AcquireResult(now, lock, null, lockState);
|
||||
}
|
||||
|
||||
Lock newLock = create(resourceName, scope, now, leaseLength);
|
||||
tm().put(newLock);
|
||||
|
||||
return AcquireResult.create(now, lock, newLock, lockState);
|
||||
return new AcquireResult(now, lock, newLock, lockState);
|
||||
};
|
||||
AcquireResult acquireResult = tm().transact(lockAcquirer);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ServerSecret extends CrossTldSingleton {
|
||||
// Make sure we're in a transaction and attempt to load any existing secret, then
|
||||
// create it if it's absent.
|
||||
Optional<ServerSecret> secret = tm().loadSingleton(ServerSecret.class);
|
||||
if (!secret.isPresent()) {
|
||||
if (secret.isEmpty()) {
|
||||
secret = Optional.of(create(UUID.randomUUID()));
|
||||
tm().insert(secret.get());
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public final class PremiumListDao {
|
||||
*/
|
||||
public static Optional<Money> getPremiumPrice(String premiumListName, String label) {
|
||||
Optional<PremiumList> maybeLoadedList = getLatestRevision(premiumListName);
|
||||
if (!maybeLoadedList.isPresent()) {
|
||||
if (maybeLoadedList.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
PremiumList loadedList = maybeLoadedList.get();
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package google.registry.module;
|
||||
|
||||
import com.google.appengine.api.LifecycleManager;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.monitoring.metrics.MetricReporter;
|
||||
import dagger.Lazy;
|
||||
@@ -46,25 +45,26 @@ public class ServletBase extends HttpServlet {
|
||||
public void init() {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
|
||||
// If metric reporter failed to instantiate for any reason (bad keyring, bad json credential,
|
||||
// etc), we log the error but keep the main thread running. Also the shutdown hook will only be
|
||||
// registered if metric reporter starts up correctly.
|
||||
// If the metric reporter failed to instantiate for any reason (bad keyring, bad json
|
||||
// credential, etc.), we log the error but keep the main thread running. Also, the shutdown hook
|
||||
// will only be registered if the metric reporter starts up correctly.
|
||||
try {
|
||||
metricReporter.get().startAsync().awaitRunning(java.time.Duration.ofSeconds(10));
|
||||
logger.atInfo().log("Started up MetricReporter.");
|
||||
LifecycleManager.getInstance()
|
||||
.setShutdownHook(
|
||||
() -> {
|
||||
try {
|
||||
metricReporter
|
||||
.get()
|
||||
.stopAsync()
|
||||
.awaitTerminated(java.time.Duration.ofSeconds(10));
|
||||
logger.atInfo().log("Shut down MetricReporter.");
|
||||
} catch (TimeoutException e) {
|
||||
logger.atSevere().withCause(e).log("Failed to stop MetricReporter.");
|
||||
}
|
||||
});
|
||||
Runtime.getRuntime()
|
||||
.addShutdownHook(
|
||||
new Thread(
|
||||
() -> {
|
||||
try {
|
||||
metricReporter
|
||||
.get()
|
||||
.stopAsync()
|
||||
.awaitTerminated(java.time.Duration.ofSeconds(10));
|
||||
logger.atInfo().log("Shut down MetricReporter.");
|
||||
} catch (TimeoutException e) {
|
||||
logger.atSevere().withCause(e).log("Failed to stop MetricReporter.");
|
||||
}
|
||||
}));
|
||||
} catch (Exception e) {
|
||||
logger.atSevere().withCause(e).log("Failed to initialize MetricReporter.");
|
||||
}
|
||||
|
||||
+16
-11
@@ -175,14 +175,14 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||
public <T> T reTransact(Callable<T> work) {
|
||||
// This prevents inner transaction from retrying, thus avoiding a cascade retry effect.
|
||||
if (inTransaction()) {
|
||||
return transactNoRetry(work, null);
|
||||
return transactNoRetry(null, work);
|
||||
}
|
||||
return retrier.callWithRetry(
|
||||
() -> transactNoRetry(work, null), JpaRetries::isFailedTxnRetriable);
|
||||
() -> transactNoRetry(null, work), JpaRetries::isFailedTxnRetriable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T transact(Callable<T> work, TransactionIsolationLevel isolationLevel) {
|
||||
public <T> T transact(TransactionIsolationLevel isolationLevel, Callable<T> work) {
|
||||
if (inTransaction()) {
|
||||
if (!getHibernateAllowNestedTransactions()) {
|
||||
throw new IllegalStateException(NESTED_TRANSACTION_MESSAGE);
|
||||
@@ -192,20 +192,25 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||
logger.atWarning().withStackTrace(StackSize.MEDIUM).log(NESTED_TRANSACTION_MESSAGE);
|
||||
}
|
||||
// This prevents inner transaction from retrying, thus avoiding a cascade retry effect.
|
||||
return transactNoRetry(work, isolationLevel);
|
||||
return transactNoRetry(isolationLevel, work);
|
||||
}
|
||||
return retrier.callWithRetry(
|
||||
() -> transactNoRetry(work, isolationLevel), JpaRetries::isFailedTxnRetriable);
|
||||
() -> transactNoRetry(isolationLevel, work), JpaRetries::isFailedTxnRetriable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T transact(Callable<T> work) {
|
||||
return transact(work, null);
|
||||
return transact(null, work);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T transactNoRetry(Callable<T> work) {
|
||||
return transactNoRetry(null, work);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T transactNoRetry(
|
||||
Callable<T> work, @Nullable TransactionIsolationLevel isolationLevel) {
|
||||
@Nullable TransactionIsolationLevel isolationLevel, Callable<T> work) {
|
||||
if (inTransaction()) {
|
||||
// This check will no longer be necessary when the transact() method always throws
|
||||
// inside a nested transaction, as the only way to pass a non-null isolation level
|
||||
@@ -266,18 +271,18 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transact(ThrowingRunnable work, TransactionIsolationLevel isolationLevel) {
|
||||
public void transact(TransactionIsolationLevel isolationLevel, ThrowingRunnable work) {
|
||||
transact(
|
||||
isolationLevel,
|
||||
() -> {
|
||||
work.run();
|
||||
return null;
|
||||
},
|
||||
isolationLevel);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transact(ThrowingRunnable work) {
|
||||
transact(work, null);
|
||||
transact(null, work);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -61,7 +61,19 @@ public interface TransactionManager {
|
||||
* Executes the work in a transaction at the given {@link TransactionIsolationLevel} and returns
|
||||
* the result.
|
||||
*/
|
||||
<T> T transact(Callable<T> work, TransactionIsolationLevel isolationLevel);
|
||||
<T> T transact(TransactionIsolationLevel isolationLevel, Callable<T> work);
|
||||
|
||||
/**
|
||||
* Executes the work in a transaction and returns the result, without retrying upon retryable
|
||||
* exceptions.
|
||||
*
|
||||
* <p>This method should only be used when the transaction contains side effects that are not
|
||||
* rolled back by the transaction manager, for example in {@link
|
||||
* google.registry.beam.common.RegistryJpaIO} where the results from a query are streamed to the
|
||||
* next transformation inside a transaction, as the result stream has to materialize to a list
|
||||
* outside a transaction and doing so would greatly affect the parallelism of the pipeline.
|
||||
*/
|
||||
<T> T transactNoRetry(Callable<T> work);
|
||||
|
||||
/**
|
||||
* Executes the work in a transaction at the given {@link TransactionIsolationLevel} and returns
|
||||
@@ -73,7 +85,7 @@ public interface TransactionManager {
|
||||
* next transformation inside a transaction, as the result stream has to materialize to a list
|
||||
* outside a transaction and doing so would greatly affect the parallelism of the pipeline.
|
||||
*/
|
||||
<T> T transactNoRetry(Callable<T> work, TransactionIsolationLevel isolationLevel);
|
||||
<T> T transactNoRetry(TransactionIsolationLevel isolationLevel, Callable<T> work);
|
||||
|
||||
/**
|
||||
* Executes the work in a (potentially wrapped) transaction and returns the result.
|
||||
@@ -95,7 +107,7 @@ public interface TransactionManager {
|
||||
void transact(ThrowingRunnable work);
|
||||
|
||||
/** Executes the work in a transaction at the given {@link TransactionIsolationLevel}. */
|
||||
void transact(ThrowingRunnable work, TransactionIsolationLevel isolationLevel);
|
||||
void transact(TransactionIsolationLevel isolationLevel, ThrowingRunnable work);
|
||||
|
||||
/**
|
||||
* Executes the work in a (potentially wrapped) transaction and returns the result.
|
||||
|
||||
@@ -387,7 +387,7 @@ abstract class AbstractJsonableObject implements Jsonable {
|
||||
*/
|
||||
static void verifyAllowedJsonKeyName(String name, @Nullable Member member, Class<?> clazz) {
|
||||
Optional<ImmutableSet<String>> allowedFieldNames = getNameRestriction(clazz);
|
||||
if (!allowedFieldNames.isPresent()) {
|
||||
if (allowedFieldNames.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
checkState(
|
||||
@@ -416,7 +416,7 @@ abstract class AbstractJsonableObject implements Jsonable {
|
||||
// We ignore any Optional that are empty, as if they didn't exist at all
|
||||
if (object instanceof Optional) {
|
||||
Optional<?> optional = (Optional<?>) object;
|
||||
if (!optional.isPresent()) {
|
||||
if (optional.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
object = optional.get();
|
||||
|
||||
@@ -64,7 +64,7 @@ public class RdapDomainAction extends RdapActionBase {
|
||||
Domain.class,
|
||||
pathSearchString,
|
||||
shouldIncludeDeleted() ? START_OF_TIME : rdapJsonFormatter.getRequestTime());
|
||||
if (!domain.isPresent() || !isAuthorized(domain.get())) {
|
||||
if (domain.isEmpty() || !isAuthorized(domain.get())) {
|
||||
// RFC7480 5.3 - if the server wishes to respond that it doesn't have data satisfying the
|
||||
// query, it MUST reply with 404 response code.
|
||||
//
|
||||
|
||||
@@ -342,7 +342,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
|
||||
Host.class,
|
||||
partialStringQuery.getInitialString(),
|
||||
shouldIncludeDeleted() ? START_OF_TIME : getRequestTime());
|
||||
return (!host.isPresent()
|
||||
return (host.isEmpty()
|
||||
|| !desiredRegistrar.get().equals(host.get().getPersistedCurrentSponsorRegistrarId()))
|
||||
? ImmutableList.of()
|
||||
: ImmutableList.of(host.get().createVKey());
|
||||
|
||||
@@ -121,7 +121,7 @@ public class RdapEntitySearchAction extends RdapSearchActionBase {
|
||||
|
||||
// Check the subtype.
|
||||
Subtype subtype;
|
||||
if (!subtypeParam.isPresent() || subtypeParam.get().equalsIgnoreCase("all")) {
|
||||
if (subtypeParam.isEmpty() || subtypeParam.get().equalsIgnoreCase("all")) {
|
||||
subtype = Subtype.ALL;
|
||||
} else if (subtypeParam.get().equalsIgnoreCase("contacts")) {
|
||||
subtype = Subtype.CONTACTS;
|
||||
@@ -133,7 +133,7 @@ public class RdapEntitySearchAction extends RdapSearchActionBase {
|
||||
|
||||
CursorType cursorType;
|
||||
Optional<String> cursorQueryString;
|
||||
if (!cursorString.isPresent()) {
|
||||
if (cursorString.isEmpty()) {
|
||||
cursorType = CursorType.NONE;
|
||||
cursorQueryString = Optional.empty();
|
||||
} else {
|
||||
|
||||
@@ -101,7 +101,7 @@ public final class RdapModule {
|
||||
@Provides
|
||||
static RdapAuthorization provideRdapAuthorization(
|
||||
AuthResult authResult, AuthenticatedRegistrarAccessor registrarAccessor) {
|
||||
if (!authResult.userAuthInfo().isPresent()) {
|
||||
if (authResult.userAuthInfo().isEmpty()) {
|
||||
return RdapAuthorization.PUBLIC_AUTHORIZATION;
|
||||
}
|
||||
UserAuthInfo userAuthInfo = authResult.userAuthInfo().get();
|
||||
|
||||
@@ -66,7 +66,7 @@ public class RdapNameserverAction extends RdapActionBase {
|
||||
Host.class,
|
||||
pathSearchString,
|
||||
shouldIncludeDeleted() ? START_OF_TIME : getRequestTime());
|
||||
if (!host.isPresent() || !isAuthorized(host.get())) {
|
||||
if (host.isEmpty() || !isAuthorized(host.get())) {
|
||||
// RFC7480 5.3 - if the server wishes to respond that it doesn't have data satisfying the
|
||||
// query, it MUST reply with 404 response code.
|
||||
//
|
||||
|
||||
@@ -175,7 +175,7 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
|
||||
RdapSearchPattern partialStringQuery) {
|
||||
Optional<Domain> domain =
|
||||
loadByForeignKeyCached(Domain.class, partialStringQuery.getSuffix(), getRequestTime());
|
||||
if (!domain.isPresent()) {
|
||||
if (domain.isEmpty()) {
|
||||
// Don't allow wildcards with suffixes which are not domains we manage. That would risk a
|
||||
// table scan in many easily foreseeable cases. The user might ask for ns*.zombo.com,
|
||||
// forcing us to query for all hosts beginning with ns, then filter for those ending in
|
||||
|
||||
@@ -121,7 +121,7 @@ public abstract class RdapSearchActionBase extends RdapActionBase {
|
||||
*/
|
||||
protected boolean shouldBeVisible(EppResource eppResource) {
|
||||
return isAuthorized(eppResource)
|
||||
&& (!registrarParam.isPresent()
|
||||
&& (registrarParam.isEmpty()
|
||||
|| registrarParam.get().equals(eppResource.getPersistedCurrentSponsorRegistrarId()));
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public abstract class RdapSearchActionBase extends RdapActionBase {
|
||||
*/
|
||||
protected boolean shouldBeVisible(Registrar registrar) {
|
||||
return isAuthorized(registrar)
|
||||
&& (!registrarParam.isPresent() || registrarParam.get().equals(registrar.getRegistrarId()));
|
||||
&& (registrarParam.isEmpty() || registrarParam.get().equals(registrar.getRegistrarId()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,8 +38,8 @@ import google.registry.xml.ValidationMode;
|
||||
import google.registry.xml.XmlException;
|
||||
import google.registry.xml.XmlFragmentMarshaller;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collection;
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
@@ -51,7 +51,7 @@ import org.joda.time.DateTime;
|
||||
public final class RdeMarshaller implements Serializable {
|
||||
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
private static final long serialVersionUID = 202890386611768455L;
|
||||
@Serial private static final long serialVersionUID = 202890386611768455L;
|
||||
|
||||
private final ValidationMode validationMode;
|
||||
private transient XmlFragmentMarshaller memoizedMarshaller;
|
||||
@@ -85,13 +85,12 @@ public final class RdeMarshaller implements Serializable {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
try {
|
||||
XjcXmlTransformer.marshal(deposit, os, UTF_8, validationMode);
|
||||
// TODO: Call StandardCharset.UTF_8 instead once we are one Java 17 runtime.
|
||||
String rdeDocument = os.toString("UTF-8");
|
||||
String rdeDocument = os.toString(UTF_8);
|
||||
String marker = "<rde:contents>\n";
|
||||
int startOfContents = rdeDocument.indexOf(marker);
|
||||
verify(startOfContents > 0, "Bad RDE document:\n%s", rdeDocument);
|
||||
return rdeDocument.substring(0, startOfContents + marker.length());
|
||||
} catch (XmlException | UnsupportedEncodingException e) {
|
||||
} catch (XmlException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ public final class RdeReportAction implements Runnable, EscrowTask {
|
||||
RdeRevision.getCurrentRevision(tld, watermark, FULL)
|
||||
.orElseThrow(
|
||||
() -> new IllegalStateException("RdeRevision was not set on generated deposit"));
|
||||
if (!prefix.isPresent()) {
|
||||
if (prefix.isEmpty()) {
|
||||
prefix = Optional.of(findMostRecentPrefixForWatermark(watermark, bucket, tld, gcsUtils));
|
||||
}
|
||||
String name = prefix.get() + RdeNamingUtils.makeRydeFilename(tld, watermark, FULL, 1, revision);
|
||||
|
||||
@@ -23,7 +23,6 @@ import static google.registry.util.DomainNameUtils.canonicalizeHostname;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.api.client.http.HttpMethods;
|
||||
import com.google.appengine.api.urlfetch.HTTPResponse;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.common.net.MediaType;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
@@ -107,7 +106,7 @@ public class RdeReporter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmarshals IIRDEA XML result object from {@link HTTPResponse} payload.
|
||||
* Unmarshall IIRDEA XML result object from HTTP response payload.
|
||||
*
|
||||
* @see <a
|
||||
* href="http://tools.ietf.org/html/draft-lozano-icann-registry-interfaces-05#section-4.1">
|
||||
|
||||
@@ -352,7 +352,7 @@ public final class RdeStagingAction implements Runnable {
|
||||
}
|
||||
|
||||
private ImmutableSetMultimap<String, PendingDeposit> getManualPendingDeposits() {
|
||||
if (!directory.isPresent()) {
|
||||
if (directory.isEmpty()) {
|
||||
throw new BadRequestException("Directory parameter required in manual operation");
|
||||
}
|
||||
if (directory.get().startsWith("/")) {
|
||||
|
||||
@@ -138,7 +138,7 @@ public final class RdeUploadAction implements Runnable, EscrowTask {
|
||||
public void runWithLock(final DateTime watermark) throws Exception {
|
||||
// If a prefix is not provided,try to determine the prefix. This should only happen when the RDE
|
||||
// upload cron job runs to catch up any un-retried (i. e. expected) RDE failures.
|
||||
if (!prefix.isPresent()) {
|
||||
if (prefix.isEmpty()) {
|
||||
prefix = Optional.of(findMostRecentPrefixForWatermark(watermark, bucket, tld, gcsUtils));
|
||||
}
|
||||
logger.atInfo().log("Verifying readiness to upload the RDE deposit.");
|
||||
|
||||
@@ -161,7 +161,7 @@ final class RydeEncryption {
|
||||
.filter(ciphertext -> ciphertext.getKeyID() == privateKey.getKeyID())
|
||||
.findAny();
|
||||
// If we can't find one with our key ID, then we can't decrypt the file!
|
||||
if (!cyphertext.isPresent()) {
|
||||
if (cyphertext.isEmpty()) {
|
||||
String keyIds =
|
||||
PgpUtils.stream(ciphertextList, PGPPublicKeyEncryptedData.class)
|
||||
.map(ciphertext -> Long.toHexString(ciphertext.getKeyID()))
|
||||
|
||||
@@ -104,7 +104,7 @@ public final class CopyDetailReportsAction implements Runnable {
|
||||
// TODO(larryruili): Determine a safer way of enforcing this.
|
||||
String registrarId = Iterables.get(Splitter.on('_').split(detailReportName), 3);
|
||||
Optional<Registrar> registrar = Registrar.loadByRegistrarId(registrarId);
|
||||
if (!registrar.isPresent()) {
|
||||
if (registrar.isEmpty()) {
|
||||
logger.atWarning().log(
|
||||
"Registrar %s not found in database for file '%s'.", registrar, detailReportName);
|
||||
continue;
|
||||
|
||||
@@ -132,7 +132,7 @@ public class RequestHandler<C> {
|
||||
}
|
||||
String path = req.getRequestURI();
|
||||
Optional<Route> route = router.route(path);
|
||||
if (!route.isPresent()) {
|
||||
if (route.isEmpty()) {
|
||||
logger.atInfo().log("No action found for: %s", path);
|
||||
rsp.sendError(SC_NOT_FOUND);
|
||||
return;
|
||||
@@ -144,7 +144,7 @@ public class RequestHandler<C> {
|
||||
}
|
||||
Optional<AuthResult> authResult =
|
||||
requestAuthenticator.authorize(route.get().action().auth().authSettings(), req);
|
||||
if (!authResult.isPresent()) {
|
||||
if (authResult.isEmpty()) {
|
||||
rsp.sendError(SC_FORBIDDEN, "Not authorized");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import static com.google.common.net.HttpHeaders.CONTENT_LENGTH;
|
||||
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.net.MediaType;
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -133,6 +132,6 @@ public final class UrlConnectionUtils {
|
||||
random.nextBytes(rand);
|
||||
// Boundary strings can be up to 70 characters long, so use 30 hyphens plus 32 random digits.
|
||||
// See https://tools.ietf.org/html/rfc2046#section-5.1.1
|
||||
return Strings.repeat("-", 30) + base64().encode(rand);
|
||||
return "-".repeat(30) + base64().encode(rand);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ public class AuthenticatedRegistrarAccessor {
|
||||
Lazy<GroupsConnection> lazyGroupsConnection,
|
||||
String userEmail,
|
||||
Optional<String> gSuiteSupportGroupEmailAddress) {
|
||||
if (!gSuiteSupportGroupEmailAddress.isPresent()) {
|
||||
if (gSuiteSupportGroupEmailAddress.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
@@ -282,7 +282,7 @@ public class AuthenticatedRegistrarAccessor {
|
||||
AuthResult authResult,
|
||||
Optional<String> gSuiteSupportGroupEmailAddress,
|
||||
Lazy<GroupsConnection> lazyGroupsConnection) {
|
||||
if (!authResult.userAuthInfo().isPresent()) {
|
||||
if (authResult.userAuthInfo().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ public class AuthenticatedRegistrarAccessor {
|
||||
/** Returns a map of registrar IDs to roles for all registrars that the user has access to. */
|
||||
private static ImmutableSetMultimap<String, Role> createRoleMap(
|
||||
AuthResult authResult, boolean isAdmin, String registryAdminRegistrarId) {
|
||||
if (!authResult.userAuthInfo().isPresent()) {
|
||||
if (authResult.userAuthInfo().isEmpty()) {
|
||||
return ImmutableSetMultimap.of();
|
||||
}
|
||||
ImmutableSetMultimap.Builder<String, Role> builder = new ImmutableSetMultimap.Builder<>();
|
||||
|
||||
@@ -24,8 +24,8 @@ import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
import google.registry.model.server.Lock;
|
||||
import google.registry.util.AppEngineTimeLimiter;
|
||||
import google.registry.util.Clock;
|
||||
import google.registry.util.TimeLimiter;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -82,7 +82,7 @@ public class LockHandlerImpl implements LockHandler {
|
||||
DateTime startTime = clock.nowUtc();
|
||||
String sanitizedTld = Strings.emptyToNull(tld);
|
||||
try {
|
||||
return AppEngineTimeLimiter.create()
|
||||
return TimeLimiter.create()
|
||||
.callWithTimeout(
|
||||
new LockingCallable(callable, lockAcquirer, sanitizedTld, leaseLength, lockNames),
|
||||
leaseLength.minus(LOCK_TIMEOUT_FUDGE).getMillis(),
|
||||
@@ -147,7 +147,7 @@ public class LockHandlerImpl implements LockHandler {
|
||||
try {
|
||||
for (String lockName : lockNames) {
|
||||
Optional<Lock> lock = lockAcquirer.acquireLock(lockName, tld, leaseLength);
|
||||
if (!lock.isPresent()) {
|
||||
if (lock.isEmpty()) {
|
||||
logger.atInfo().log("Couldn't acquire lock named: %s for TLD %s.", lockName, tld);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright 2018 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.tools;
|
||||
|
||||
import com.google.api.services.appengine.v1.Appengine;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import google.registry.config.CredentialModule.LocalCredential;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.util.GoogleCredentialsBundle;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/** Module providing the instance of {@link Appengine} to access App Engine Admin Api. */
|
||||
@Module
|
||||
public abstract class AppEngineAdminApiModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public static Appengine provideAppengine(
|
||||
@LocalCredential GoogleCredentialsBundle credentialsBundle,
|
||||
@Config("projectId") String projectId) {
|
||||
return new Appengine.Builder(
|
||||
credentialsBundle.getHttpTransport(),
|
||||
credentialsBundle.getJsonFactory(),
|
||||
credentialsBundle.getHttpRequestInitializer())
|
||||
.setApplicationName(projectId)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@ package google.registry.tools;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.common.base.Ascii;
|
||||
import com.google.common.base.Strings;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.ForeignKeyUtils;
|
||||
import google.registry.model.contact.Contact;
|
||||
@@ -46,10 +45,8 @@ class CommandUtilities {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: change Strings.repeat("-", n) to "-".repeat(n) once we are on Java 17 runtime.
|
||||
@SuppressWarnings("InlineMeInliner")
|
||||
static String addHeader(String header, String body) {
|
||||
return String.format("%s:\n%s\n%s", header, Strings.repeat("-", header.length() + 1), body);
|
||||
return String.format("%s:\n%s\n%s", header, "-".repeat(header.length() + 1), body);
|
||||
}
|
||||
|
||||
/** Prompts for yes/no input using promptText, defaulting to no. */
|
||||
|
||||
@@ -237,7 +237,7 @@ public class ConfigureTldCommand extends MutatingCommand {
|
||||
|
||||
private void checkPremiumList(Tld newTld) {
|
||||
Optional<String> premiumListName = newTld.getPremiumListName();
|
||||
if (!premiumListName.isPresent()) {
|
||||
if (premiumListName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Optional<PremiumList> premiumList = PremiumListDao.getLatestRevision(premiumListName.get());
|
||||
|
||||
@@ -31,7 +31,7 @@ public final class CreateBulkPricingPackageCommand extends CreateOrUpdateBulkPri
|
||||
@Override
|
||||
BulkPricingPackage getOldBulkPricingPackage(String tokenString) {
|
||||
checkArgument(
|
||||
!BulkPricingPackage.loadByTokenString(tokenString).isPresent(),
|
||||
BulkPricingPackage.loadByTokenString(tokenString).isEmpty(),
|
||||
"BulkPricingPackage with token %s already exists",
|
||||
tokenString);
|
||||
return null;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class CreatePremiumListCommand extends CreateOrUpdatePremiumListCommand {
|
||||
currency = CurrencyUnit.of(currencyUnit);
|
||||
name = Strings.isNullOrEmpty(name) ? convertFilePathToName(inputFile) : name;
|
||||
checkArgument(
|
||||
!PremiumListDao.getLatestRevision(name).isPresent(),
|
||||
PremiumListDao.getLatestRevision(name).isEmpty(),
|
||||
"A premium list already exists by this name");
|
||||
if (!override) {
|
||||
assertTldExists(
|
||||
|
||||
@@ -81,9 +81,7 @@ final class CreateRegistrarCommand extends CreateOrUpdateRegistrarCommand
|
||||
clientId);
|
||||
}
|
||||
checkState(
|
||||
!Registrar.loadByRegistrarId(clientId).isPresent(),
|
||||
"Registrar %s already exists",
|
||||
clientId);
|
||||
Registrar.loadByRegistrarId(clientId).isEmpty(), "Registrar %s already exists", clientId);
|
||||
List<Registrar> collisions =
|
||||
Streams.stream(Registrar.loadAll())
|
||||
.filter(registrar -> normalizeRegistrarId(registrar.getRegistrarId()).equals(clientId))
|
||||
|
||||
@@ -47,8 +47,7 @@ final class CreateReservedListCommand extends CreateOrUpdateReservedListCommand
|
||||
@Override
|
||||
protected String prompt() throws Exception {
|
||||
name = Strings.isNullOrEmpty(name) ? convertFilePathToName(input) : name;
|
||||
checkArgument(
|
||||
!ReservedList.get(name).isPresent(), "A reserved list already exists by this name");
|
||||
checkArgument(ReservedList.get(name).isEmpty(), "A reserved list already exists by this name");
|
||||
if (!override) {
|
||||
validateListName(name);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ public class CreateUserCommand extends CreateOrUpdateUserCommand {
|
||||
@Nullable
|
||||
@Override
|
||||
User getExistingUser(String email) {
|
||||
checkArgument(
|
||||
!UserDao.loadUser(email).isPresent(), "A user with email %s already exists", email);
|
||||
checkArgument(UserDao.loadUser(email).isEmpty(), "A user with email %s already exists", email);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ final class DeleteAllocationTokensCommand extends UpdateOrDeleteAllocationTokens
|
||||
// since the query ran. This also filters out per-domain tokens if they're not to be deleted.
|
||||
ImmutableSet<VKey<AllocationToken>> tokensToDelete =
|
||||
tm().loadByKeys(batch).values().stream()
|
||||
.filter(t -> withDomains || !t.getDomainName().isPresent())
|
||||
.filter(t -> withDomains || t.getDomainName().isEmpty())
|
||||
.filter(t -> t.getTokenType().isOneTimeUse())
|
||||
.filter(t -> !t.isRedeemed())
|
||||
.map(AllocationToken::createVKey)
|
||||
|
||||
@@ -102,7 +102,7 @@ public final class DomainLockUtils {
|
||||
RegistryLock lock = getByVerificationCode(verificationCode);
|
||||
|
||||
checkArgument(
|
||||
!lock.getLockCompletionTime().isPresent(),
|
||||
lock.getLockCompletionTime().isEmpty(),
|
||||
"Domain %s is already locked",
|
||||
lock.getDomainName());
|
||||
|
||||
@@ -129,7 +129,7 @@ public final class DomainLockUtils {
|
||||
DateTime now = tm().getTransactionTime();
|
||||
RegistryLock previousLock = getByVerificationCode(verificationCode);
|
||||
checkArgument(
|
||||
!previousLock.getUnlockCompletionTime().isPresent(),
|
||||
previousLock.getUnlockCompletionTime().isEmpty(),
|
||||
"Domain %s is already unlocked",
|
||||
previousLock.getDomainName());
|
||||
|
||||
@@ -298,7 +298,7 @@ public final class DomainLockUtils {
|
||||
checkArgument(
|
||||
lock.isLocked(), "Lock object for domain %s is not currently locked", domainName);
|
||||
checkArgument(
|
||||
!lock.getUnlockRequestTime().isPresent() || lock.isUnlockRequestExpired(now),
|
||||
lock.getUnlockRequestTime().isEmpty() || lock.isUnlockRequestExpired(now),
|
||||
"A pending unlock action already exists for %s",
|
||||
domainName);
|
||||
checkArgument(
|
||||
|
||||
@@ -62,7 +62,7 @@ final class GetAllocationTokenCommand implements Command {
|
||||
if (loadedTokens.containsKey(token)) {
|
||||
AllocationToken loadedToken = loadedTokens.get(token);
|
||||
System.out.println(loadedToken.toString());
|
||||
if (!loadedToken.getRedemptionHistoryId().isPresent()) {
|
||||
if (loadedToken.getRedemptionHistoryId().isEmpty()) {
|
||||
System.out.printf("Token %s was not redeemed.\n", token);
|
||||
} else {
|
||||
VKey<Domain> domainKey =
|
||||
|
||||
@@ -19,7 +19,6 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.model.common.Cursor;
|
||||
import google.registry.model.common.Cursor.CursorType;
|
||||
@@ -64,7 +63,7 @@ final class ListCursorsCommand implements Command {
|
||||
tm().transact(() -> tm().loadByKeysIfPresent(cursorKeys.values()));
|
||||
if (!cursorKeys.isEmpty()) {
|
||||
String header = String.format(OUTPUT_FMT, "TLD", "Cursor Time", "Last Update Time");
|
||||
System.out.printf("%s\n%s\n", header, Strings.repeat("-", header.length()));
|
||||
System.out.printf("%s\n%s\n", header, "-".repeat(header.length()));
|
||||
cursorKeys.entrySet().stream()
|
||||
.map(e -> renderLine(e.getKey(), Optional.ofNullable(cursors.get(e.getValue()))))
|
||||
.sorted()
|
||||
|
||||
@@ -96,7 +96,7 @@ class LoadTestCommand extends ConfirmingCommand implements CommandWithConnection
|
||||
errorPrintStream.printf("No such TLD: %s\n", tld);
|
||||
return false;
|
||||
}
|
||||
if (!Registrar.loadByRegistrarId(clientId).isPresent()) {
|
||||
if (Registrar.loadByRegistrarId(clientId).isEmpty()) {
|
||||
errorPrintStream.printf("No such client: %s\n", clientId);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,6 @@ import javax.inject.Singleton;
|
||||
@Singleton
|
||||
@Component(
|
||||
modules = {
|
||||
AppEngineAdminApiModule.class,
|
||||
AuthModule.class,
|
||||
BatchModule.class,
|
||||
BigqueryModule.class,
|
||||
|
||||
@@ -93,8 +93,7 @@ class UnrenewDomainCommand extends ConfirmingCommand {
|
||||
continue;
|
||||
}
|
||||
Optional<Domain> domain = loadByForeignKey(Domain.class, domainName, now);
|
||||
if (!domain.isPresent()
|
||||
|| domain.get().getStatusValues().contains(StatusValue.PENDING_DELETE)) {
|
||||
if (domain.isEmpty() || domain.get().getStatusValues().contains(StatusValue.PENDING_DELETE)) {
|
||||
domainsDeletingBuilder.add(domainName);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ import org.joda.time.DateTime;
|
||||
final class UpdateAllocationTokensCommand extends UpdateOrDeleteAllocationTokensCommand {
|
||||
|
||||
@Parameter(
|
||||
names = {"--allowed_client_ids"},
|
||||
names = {"-c", "--allowed_client_ids"},
|
||||
description =
|
||||
"Comma-separated list of allowed client IDs. Use the empty string to clear the "
|
||||
+ "existing list.",
|
||||
@@ -60,7 +60,7 @@ final class UpdateAllocationTokensCommand extends UpdateOrDeleteAllocationTokens
|
||||
private List<String> allowedClientIds;
|
||||
|
||||
@Parameter(
|
||||
names = {"--allowed_tlds"},
|
||||
names = {"-t", "--allowed_tlds"},
|
||||
description =
|
||||
"Comma-separated list of allowed TLDs. Use the empty string to clear the "
|
||||
+ "existing list.",
|
||||
@@ -91,7 +91,7 @@ final class UpdateAllocationTokensCommand extends UpdateOrDeleteAllocationTokens
|
||||
private Boolean discountPremiums;
|
||||
|
||||
@Parameter(
|
||||
names = {"--discount_years"},
|
||||
names = {"-y", "--discount_years"},
|
||||
description = "The number of years the discount applies for. Default is 1, max value is 10.")
|
||||
private Integer discountYears;
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Streams;
|
||||
@@ -94,14 +93,14 @@ final class VerifyOteCommand implements CommandWithConnection {
|
||||
ImmutableMap.of(
|
||||
"summarize", Boolean.toString(summarize),
|
||||
"registrars", new ArrayList<>(registrars)));
|
||||
System.out.println(Strings.repeat("-", 80));
|
||||
System.out.println("-".repeat(80));
|
||||
for (Entry<String, Object> registrar : response.entrySet()) {
|
||||
System.out.printf(
|
||||
summarize ? "%-20s - %s\n" : "\n=========== %s OT&E status ============\n%s\n",
|
||||
registrar.getKey(),
|
||||
registrar.getValue());
|
||||
}
|
||||
System.out.println(Strings.repeat("-", 80));
|
||||
System.out.println("-".repeat(80));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -113,11 +113,11 @@ public class CreateGroupsAction implements Runnable {
|
||||
}
|
||||
|
||||
private Registrar initAndLoadRegistrar() {
|
||||
if (!clientId.isPresent()) {
|
||||
if (clientId.isEmpty()) {
|
||||
respondToBadRequest("Error creating Google Groups, missing parameter: clientId");
|
||||
}
|
||||
Optional<Registrar> registrar = Registrar.loadByRegistrarId(clientId.get());
|
||||
if (!registrar.isPresent()) {
|
||||
if (registrar.isEmpty()) {
|
||||
respondToBadRequest(String.format(
|
||||
"Error creating Google Groups; could not find registrar with id %s", clientId.get()));
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ public abstract class ListObjectsAction<T extends ImmutableObject> implements Ru
|
||||
private ImmutableSet<String> getFieldsToUse(ImmutableSet<T> objects) {
|
||||
// Get the list of fields from the received parameter.
|
||||
List<String> fieldsToUse;
|
||||
if ((fields == null) || !fields.isPresent()) {
|
||||
if ((fields == null) || fields.isEmpty()) {
|
||||
fieldsToUse = new ArrayList<>();
|
||||
} else {
|
||||
fieldsToUse = Splitter.on(',').splitToList(fields.get());
|
||||
@@ -239,8 +239,7 @@ public abstract class ListObjectsAction<T extends ImmutableObject> implements Ru
|
||||
lines.add(rowFormatter.apply(headerRow));
|
||||
|
||||
// Add a row of separator lines (column names mapping to '-' * column width).
|
||||
Map<String, String> separatorRow =
|
||||
Maps.transformValues(columnWidths, width -> Strings.repeat("-", width));
|
||||
Map<String, String> separatorRow = Maps.transformValues(columnWidths, "-"::repeat);
|
||||
lines.add(rowFormatter.apply(separatorRow));
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ public class RefreshDnsForAllDomainsAction implements Runnable {
|
||||
public void run() {
|
||||
assertTldsExist(tlds);
|
||||
checkArgument(batchSize > 0, "Must specify a positive number for batch size");
|
||||
Duration smear = tm().transact(this::calculateSmear, TRANSACTION_REPEATABLE_READ);
|
||||
Duration smear = tm().transact(TRANSACTION_REPEATABLE_READ, this::calculateSmear);
|
||||
|
||||
ImmutableList<String> domainsBatch;
|
||||
@Nullable String lastInPreviousBatch = null;
|
||||
@@ -105,7 +105,7 @@ public class RefreshDnsForAllDomainsAction implements Runnable {
|
||||
Optional<String> lastInPreviousBatchOpt = Optional.ofNullable(lastInPreviousBatch);
|
||||
domainsBatch =
|
||||
tm().transact(
|
||||
() -> refreshBatch(lastInPreviousBatchOpt, smear), TRANSACTION_REPEATABLE_READ);
|
||||
TRANSACTION_REPEATABLE_READ, () -> refreshBatch(lastInPreviousBatchOpt, smear));
|
||||
lastInPreviousBatch = domainsBatch.isEmpty() ? null : getLast(domainsBatch);
|
||||
} while (domainsBatch.size() == batchSize);
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ public final class RegistrarFormFields {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
Optional<List<Map<String, ?>>> contactsAsMaps = CONTACTS_AS_MAPS.extractUntyped(args);
|
||||
if (!contactsAsMaps.isPresent()) {
|
||||
if (contactsAsMaps.isEmpty()) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
ImmutableList.Builder<RegistrarPoc.Builder> result = new ImmutableList.Builder<>();
|
||||
|
||||
@@ -35,7 +35,7 @@ public abstract class ConsoleApiAction implements Runnable {
|
||||
@Override
|
||||
public final void run() {
|
||||
// Shouldn't be even possible because of Auth annotations on the various implementing classes
|
||||
if (!consoleApiParams.authResult().userAuthInfo().get().consoleUser().isPresent()) {
|
||||
if (consoleApiParams.authResult().userAuthInfo().get().consoleUser().isEmpty()) {
|
||||
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
||||
return;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public abstract class ConsoleApiAction implements Runnable {
|
||||
Arrays.stream(consoleApiParams.request().getCookies())
|
||||
.filter(c -> XsrfTokenManager.X_CSRF_TOKEN.equals(c.getName()))
|
||||
.findFirst();
|
||||
if (!maybeCookie.isPresent()
|
||||
if (maybeCookie.isEmpty()
|
||||
|| !consoleApiParams.xsrfTokenManager().validateToken(maybeCookie.get().getValue())) {
|
||||
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
||||
return false;
|
||||
|
||||
@@ -60,12 +60,12 @@ public class ConsoleDomainGetAction implements JsonGetAction {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!authResult.isAuthenticated() || !authResult.userAuthInfo().isPresent()) {
|
||||
if (!authResult.isAuthenticated() || authResult.userAuthInfo().isEmpty()) {
|
||||
response.setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
||||
return;
|
||||
}
|
||||
UserAuthInfo authInfo = authResult.userAuthInfo().get();
|
||||
if (!authInfo.consoleUser().isPresent()) {
|
||||
if (authInfo.consoleUser().isEmpty()) {
|
||||
response.setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
||||
return;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public class ConsoleDomainGetAction implements JsonGetAction {
|
||||
() ->
|
||||
EppResourceUtils.loadByForeignKeyCached(
|
||||
Domain.class, paramDomain, tm().getTransactionTime()));
|
||||
if (!possibleDomain.isPresent()) {
|
||||
if (possibleDomain.isEmpty()) {
|
||||
response.setStatus(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class RegistrarsAction implements JsonGetAction {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!registrar.isPresent()) {
|
||||
if (registrar.isEmpty()) {
|
||||
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||
response.setPayload(gson.toJson("'registrar' parameter is not present"));
|
||||
return;
|
||||
@@ -164,7 +164,7 @@ public class RegistrarsAction implements JsonGetAction {
|
||||
tm().transact(
|
||||
() -> {
|
||||
checkArgument(
|
||||
!Registrar.loadByRegistrarId(registrar.getRegistrarId()).isPresent(),
|
||||
Registrar.loadByRegistrarId(registrar.getRegistrarId()).isEmpty(),
|
||||
"Registrar with registrarId %s already exists",
|
||||
registrar.getRegistrarId());
|
||||
tm().putAll(registrar, contact);
|
||||
|
||||
@@ -109,7 +109,7 @@ public class ContactAction implements JsonGetAction {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!contacts.isPresent()) {
|
||||
if (contacts.isEmpty()) {
|
||||
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||
response.setPayload(gson.toJson("Contacts parameter is not present"));
|
||||
return;
|
||||
|
||||
@@ -77,7 +77,7 @@ public class SecurityAction implements JsonGetAction {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!registrar.isPresent()) {
|
||||
if (registrar.isEmpty()) {
|
||||
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||
response.setPayload(gson.toJson("'registrar' parameter is not present"));
|
||||
return;
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ public class WhoisRegistrarFieldsAction implements JsonGetAction {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!registrar.isPresent()) {
|
||||
if (registrar.isEmpty()) {
|
||||
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||
response.setPayload(gson.toJson("'registrar' parameter is not present"));
|
||||
return;
|
||||
|
||||
+1
-1
@@ -233,7 +233,7 @@ public final class ConsoleRegistrarCreatorAction extends HtmlAction {
|
||||
tm().transact(
|
||||
() -> {
|
||||
checkState(
|
||||
!Registrar.loadByRegistrarId(registrar.getRegistrarId()).isPresent(),
|
||||
Registrar.loadByRegistrarId(registrar.getRegistrarId()).isEmpty(),
|
||||
"Registrar with client ID %s already exists",
|
||||
registrar.getRegistrarId());
|
||||
tm().putAll(registrar, contact);
|
||||
|
||||
@@ -67,7 +67,7 @@ public abstract class HtmlAction implements Runnable {
|
||||
response.setHeader(X_FRAME_OPTIONS, "SAMEORIGIN"); // Disallow iframing.
|
||||
response.setHeader("X-Ui-Compatible", "IE=edge"); // Ask IE not to be silly.
|
||||
|
||||
if (!authResult.userAuthInfo().isPresent()) {
|
||||
if (authResult.userAuthInfo().isEmpty()) {
|
||||
response.setStatus(SC_MOVED_TEMPORARILY);
|
||||
String location;
|
||||
try {
|
||||
|
||||
@@ -383,7 +383,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
||||
*/
|
||||
private boolean validateCertificate(
|
||||
Optional<String> existingCertificate, String certificateString) {
|
||||
if (!existingCertificate.isPresent() || !existingCertificate.get().equals(certificateString)) {
|
||||
if (existingCertificate.isEmpty() || !existingCertificate.get().equals(certificateString)) {
|
||||
try {
|
||||
certificateChecker.validateCertificate(certificateString);
|
||||
} catch (InsecureCertificateException e) {
|
||||
@@ -514,7 +514,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
||||
}
|
||||
// If there was a domain WHOIS abuse contact in the old set, the new set must have one.
|
||||
if (getDomainWhoisVisibleAbuseContact(existingContacts).isPresent()
|
||||
&& !domainWhoisAbuseContact.isPresent()) {
|
||||
&& domainWhoisAbuseContact.isEmpty()) {
|
||||
throw new ContactRequirementException(
|
||||
"An abuse contact visible in domain WHOIS query must be designated");
|
||||
}
|
||||
@@ -569,7 +569,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
||||
updatedContact ->
|
||||
updatedContact.getEmailAddress().equals(contact.getEmailAddress()))
|
||||
.findFirst();
|
||||
if (!updatedContactOptional.isPresent()) {
|
||||
if (updatedContactOptional.isEmpty()) {
|
||||
throw new FormException(
|
||||
String.format(
|
||||
"Cannot delete the contact %s that has registry lock enabled",
|
||||
|
||||
@@ -210,11 +210,11 @@ public final class RegistryLockGetAction implements JsonGetAction {
|
||||
.put(DOMAIN_NAME_PARAM, lock.getDomainName())
|
||||
.put(LOCKED_TIME_PARAM, lock.getLockCompletionTime().map(DateTime::toString).orElse(""))
|
||||
.put(LOCKED_BY_PARAM, lock.isSuperuser() ? "admin" : lock.getRegistrarPocId())
|
||||
.put(IS_LOCK_PENDING_PARAM, !lock.getLockCompletionTime().isPresent())
|
||||
.put(IS_LOCK_PENDING_PARAM, lock.getLockCompletionTime().isEmpty())
|
||||
.put(
|
||||
IS_UNLOCK_PENDING_PARAM,
|
||||
lock.getUnlockRequestTime().isPresent()
|
||||
&& !lock.getUnlockCompletionTime().isPresent()
|
||||
&& lock.getUnlockCompletionTime().isEmpty()
|
||||
&& !lock.isUnlockRequestExpired(now))
|
||||
.put(USER_CAN_UNLOCK_PARAM, isAdmin || !lock.isSuperuser())
|
||||
.build();
|
||||
|
||||
@@ -62,7 +62,7 @@ public class DomainLookupCommand implements WhoisCommand {
|
||||
Optional<InternetDomainName> tld = findTldForName(domainName);
|
||||
// Google Registry Policy: Do not return records under TLDs for which we're not
|
||||
// authoritative.
|
||||
if (!tld.isPresent() || !getTlds().contains(tld.get().toString())) {
|
||||
if (tld.isEmpty() || !getTlds().contains(tld.get().toString())) {
|
||||
throw new WhoisException(now, SC_NOT_FOUND, ERROR_PREFIX + " not found.");
|
||||
}
|
||||
// Include `getResponse` and `isBlockedByBsa` in one transaction to reduce latency.
|
||||
|
||||
@@ -146,7 +146,7 @@ final class DomainWhoisResponse extends WhoisResponseImpl {
|
||||
/** Emit the contact entry of the given type. */
|
||||
DomainEmitter emitContact(
|
||||
String contactType, Optional<VKey<Contact>> contact, boolean preferUnicode) {
|
||||
if (!contact.isPresent()) {
|
||||
if (contact.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
// If we refer to a contact that doesn't exist, that's a bug. It means referential integrity
|
||||
|
||||
@@ -196,7 +196,7 @@ class WhoisReader {
|
||||
// We don't know at this point whether we have a domain name or a host name. We have to
|
||||
// search through our configured TLDs to see if there's one that prefixes the name.
|
||||
Optional<InternetDomainName> tld = findTldForName(targetName);
|
||||
if (!tld.isPresent()) {
|
||||
if (tld.isEmpty()) {
|
||||
// This target is not under any configured TLD, so just try it as a registrar name.
|
||||
logger.atInfo().log("Attempting registrar lookup using %s as a registrar.", arg1);
|
||||
return commandFactory.registrarLookup(arg1);
|
||||
|
||||
@@ -285,7 +285,7 @@ public class TestPipelineExtension extends Pipeline
|
||||
options.as(ApplicationNameOptions.class).setAppName(getAppName(context));
|
||||
|
||||
// if the enforcement level has not been set by the user do auto-inference
|
||||
if (!enforcement.isPresent()) {
|
||||
if (enforcement.isEmpty()) {
|
||||
final boolean isCrashingRunner = CrashingRunner.class.isAssignableFrom(options.getRunner());
|
||||
|
||||
checkState(
|
||||
|
||||
@@ -16,12 +16,14 @@ package google.registry.beam.billing;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import google.registry.beam.billing.BillingEvent.BillingEventCoder;
|
||||
import google.registry.beam.billing.BillingEvent.InvoiceGroupingKey;
|
||||
import google.registry.beam.billing.BillingEvent.InvoiceGroupingKey.InvoiceGroupingKeyCoder;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import org.apache.beam.sdk.coders.NullableCoder;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -120,13 +122,22 @@ class BillingEventTest {
|
||||
@Test
|
||||
void testInvoiceGroupingKeyCoder_deterministicSerialization() throws IOException {
|
||||
InvoiceGroupingKey invoiceKey = event.getInvoiceGroupingKey();
|
||||
InvoiceGroupingKeyCoder coder = new InvoiceGroupingKeyCoder();
|
||||
InvoiceGroupingKeyCoder coder = InvoiceGroupingKeyCoder.of();
|
||||
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||
coder.encode(invoiceKey, outStream);
|
||||
InputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
|
||||
assertThat(coder.decode(inStream)).isEqualTo(invoiceKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBillingEventCoder_deterministicSerialization() throws IOException {
|
||||
NullableCoder<BillingEvent> coder = BillingEventCoder.ofNullable();
|
||||
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||
coder.encode(event, outStream);
|
||||
InputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
|
||||
assertThat(coder.decode(inStream)).isEqualTo(event);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetDetailReportHeader() {
|
||||
assertThat(BillingEvent.getHeader())
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user