mirror of
https://github.com/google/nomulus
synced 2026-04-26 03:00:48 +00:00
Remove more usage of AutoValue (#2432)
This PR also removes `SerializedForm` used to serialize `PendingDeposit`, as it is now a simple record.
This commit is contained in:
@@ -14,9 +14,9 @@
|
||||
|
||||
package google.registry.persistence.transaction;
|
||||
|
||||
import autovalue.shaded.com.google.common.collect.ImmutableList;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Optional;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
package google.registry.privileges.secretmanager;
|
||||
|
||||
import static avro.shaded.com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
package google.registry.rdap;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.auto.value.AutoBuilder;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.monitoring.metrics.DistributionFitter;
|
||||
@@ -102,10 +102,7 @@ public class RdapMetrics {
|
||||
static final IncrementableMetric requests =
|
||||
MetricRegistryImpl.getDefault()
|
||||
.newIncrementableMetric(
|
||||
"/rdap/requests",
|
||||
"Count of RDAP Requests",
|
||||
"count",
|
||||
LABEL_DESCRIPTORS_FOR_REQUESTS);
|
||||
"/rdap/requests", "Count of RDAP Requests", "count", LABEL_DESCRIPTORS_FOR_REQUESTS);
|
||||
|
||||
@VisibleForTesting
|
||||
static final IncrementableMetric responses =
|
||||
@@ -163,8 +160,7 @@ public class RdapMetrics {
|
||||
* ways of looking at the data, since cardinality constraints prevent us from saving all the
|
||||
* information in a single metric.
|
||||
*/
|
||||
public void updateMetrics(
|
||||
RdapMetricInformation rdapMetricInformation) {
|
||||
public void updateMetrics(RdapMetricInformation rdapMetricInformation) {
|
||||
requests.increment(
|
||||
rdapMetricInformation.endpointType().toString(),
|
||||
rdapMetricInformation.includeDeleted() ? "YES" : "NO",
|
||||
@@ -206,95 +202,76 @@ public class RdapMetrics {
|
||||
}
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
abstract static class RdapMetricInformation {
|
||||
/**
|
||||
* Information on RDAP metrics.
|
||||
*
|
||||
* @param endpointType The type of RDAP endpoint (domain, domains, nameserver, etc.).
|
||||
* @param searchType The search type (by domain name, by nameserver name, etc.).
|
||||
* @param wildcardType The type of wildcarding requested (prefix, suffix, etc.).
|
||||
* @param prefixLength The length of the prefix string before the wildcard, if any; any length
|
||||
* longer than MAX_RECORDED_PREFIX_LENGTH is limited to MAX_RECORDED_PREFIX_LENGTH when
|
||||
* recording the metric, to avoid cardinality problems.
|
||||
* @param includeDeleted Whether the search included deleted records.
|
||||
* @param registrarSpecified Whether the search requested a specific registrar.
|
||||
* @param role Type of authentication/authorization: public, admin or registrar.
|
||||
* @param requestMethod Http request method (GET, POST, HEAD, etc.).
|
||||
* @param statusCode Http status code.
|
||||
* @param incompletenessWarningType Incompleteness warning type (e.g. truncated).
|
||||
* @param numDomainsRetrieved Number of domains retrieved from the database; this might be more
|
||||
* than were actually returned in the response; absent if a search was not performed.
|
||||
* @param numHostsRetrieved Number of hosts retrieved from the database; this might be more than
|
||||
* were actually returned in the response; absent if a search was not performed.
|
||||
* @param numContactsRetrieved Number of contacts retrieved from the database; this might be more
|
||||
* than were actually returned in the response; absent if a search was not performed.
|
||||
*/
|
||||
record RdapMetricInformation(
|
||||
EndpointType endpointType,
|
||||
SearchType searchType,
|
||||
WildcardType wildcardType,
|
||||
int prefixLength,
|
||||
boolean includeDeleted,
|
||||
boolean registrarSpecified,
|
||||
RdapAuthorization.Role role,
|
||||
Action.Method requestMethod,
|
||||
int statusCode,
|
||||
IncompletenessWarningType incompletenessWarningType,
|
||||
Optional<Long> numDomainsRetrieved,
|
||||
Optional<Long> numHostsRetrieved,
|
||||
Optional<Long> numContactsRetrieved) {
|
||||
|
||||
/** The type of RDAP endpoint (domain, domains, nameserver, etc.). */
|
||||
abstract EndpointType endpointType();
|
||||
@AutoBuilder
|
||||
interface Builder {
|
||||
Builder setEndpointType(EndpointType endpointType);
|
||||
|
||||
/** The search type (by domain name, by nameserver name, etc.). */
|
||||
abstract SearchType searchType();
|
||||
Builder setSearchType(SearchType searchType);
|
||||
|
||||
/** The type of wildcarding requested (prefix, suffix, etc.). */
|
||||
abstract WildcardType wildcardType();
|
||||
Builder setWildcardType(WildcardType wildcardType);
|
||||
|
||||
/**
|
||||
* The length of the prefix string before the wildcard, if any; any length longer than
|
||||
* MAX_RECORDED_PREFIX_LENGTH is limited to MAX_RECORDED_PREFIX_LENGTH when recording the
|
||||
* metric, to avoid cardinality problems.
|
||||
*/
|
||||
abstract int prefixLength();
|
||||
Builder setPrefixLength(int prefixLength);
|
||||
|
||||
/** Whether the search included deleted records. */
|
||||
abstract boolean includeDeleted();
|
||||
Builder setIncludeDeleted(boolean includeDeleted);
|
||||
|
||||
/** Whether the search requested a specific registrar. */
|
||||
abstract boolean registrarSpecified();
|
||||
Builder setRegistrarSpecified(boolean registrarSpecified);
|
||||
|
||||
/** Type of authentication/authorization: public, admin or registrar. */
|
||||
abstract RdapAuthorization.Role role();
|
||||
Builder setRole(RdapAuthorization.Role role);
|
||||
|
||||
/** Http request method (GET, POST, HEAD, etc.). */
|
||||
abstract Action.Method requestMethod();
|
||||
Builder setRequestMethod(Action.Method requestMethod);
|
||||
|
||||
/** Http status code. */
|
||||
abstract int statusCode();
|
||||
Builder setStatusCode(int statusCode);
|
||||
|
||||
/** Incompleteness warning type (e.g. truncated). */
|
||||
abstract IncompletenessWarningType incompletenessWarningType();
|
||||
Builder setIncompletenessWarningType(IncompletenessWarningType incompletenessWarningType);
|
||||
|
||||
/**
|
||||
* Number of domains retrieved from the database; this might be more than were actually returned
|
||||
* in the response; absent if a search was not performed.
|
||||
*/
|
||||
abstract Optional<Long> numDomainsRetrieved();
|
||||
Builder setNumDomainsRetrieved(long numDomainsRetrieved);
|
||||
|
||||
/**
|
||||
* Number of hosts retrieved from the database; this might be more than were actually returned
|
||||
* in the response; absent if a search was not performed.
|
||||
*/
|
||||
abstract Optional<Long> numHostsRetrieved();
|
||||
Builder setNumHostsRetrieved(long numHostsRetrieved);
|
||||
|
||||
/**
|
||||
* Number of contacts retrieved from the database; this might be more than were actually
|
||||
* returned in the response; absent if a search was not performed.
|
||||
*/
|
||||
abstract Optional<Long> numContactsRetrieved();
|
||||
Builder setNumContactsRetrieved(long numContactRetrieved);
|
||||
|
||||
@AutoValue.Builder
|
||||
abstract static class Builder {
|
||||
abstract Builder setEndpointType(EndpointType endpointType);
|
||||
|
||||
abstract Builder setSearchType(SearchType searchType);
|
||||
|
||||
abstract Builder setWildcardType(WildcardType wildcardType);
|
||||
|
||||
abstract Builder setPrefixLength(int prefixLength);
|
||||
|
||||
abstract Builder setIncludeDeleted(boolean includeDeleted);
|
||||
|
||||
abstract Builder setRegistrarSpecified(boolean registrarSpecified);
|
||||
|
||||
abstract Builder setRole(RdapAuthorization.Role role);
|
||||
|
||||
abstract Builder setRequestMethod(Action.Method requestMethod);
|
||||
|
||||
abstract Builder setStatusCode(int statusCode);
|
||||
|
||||
abstract Builder setIncompletenessWarningType(
|
||||
IncompletenessWarningType incompletenessWarningType);
|
||||
|
||||
abstract Builder setNumDomainsRetrieved(long numDomainsRetrieved);
|
||||
|
||||
abstract Builder setNumHostsRetrieved(long numHostsRetrieved);
|
||||
|
||||
abstract Builder setNumContactsRetrieved(long numContactRetrieved);
|
||||
|
||||
abstract RdapMetricInformation build();
|
||||
RdapMetricInformation build();
|
||||
}
|
||||
|
||||
static Builder builder() {
|
||||
return new AutoValue_RdapMetrics_RdapMetricInformation.Builder()
|
||||
return new AutoBuilder_RdapMetrics_RdapMetricInformation_Builder()
|
||||
.setSearchType(SearchType.NONE)
|
||||
.setWildcardType(WildcardType.INVALID)
|
||||
.setPrefixLength(0)
|
||||
|
||||
@@ -14,14 +14,23 @@
|
||||
|
||||
package google.registry.rdap;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.rdap.RdapSearchResults.IncompletenessWarningType;
|
||||
import java.util.List;
|
||||
|
||||
@AutoValue
|
||||
abstract class RdapResultSet<T extends EppResource> {
|
||||
/**
|
||||
* RDAP result set.
|
||||
*
|
||||
* @param resources List of EPP resources.
|
||||
* @param incompletenessWarningType Type of warning to display regarding possible incomplete data.
|
||||
* @param numResourcesRetrieved Number of resources retrieved from the database in the process of
|
||||
* assembling the data set.
|
||||
*/
|
||||
record RdapResultSet<T extends EppResource>(
|
||||
ImmutableList<T> resources,
|
||||
IncompletenessWarningType incompletenessWarningType,
|
||||
int numResourcesRetrieved) {
|
||||
|
||||
static <S extends EppResource> RdapResultSet<S> create(List<S> resources) {
|
||||
return create(resources, IncompletenessWarningType.COMPLETE, resources.size());
|
||||
@@ -31,16 +40,7 @@ abstract class RdapResultSet<T extends EppResource> {
|
||||
List<S> resources,
|
||||
IncompletenessWarningType incompletenessWarningType,
|
||||
int numResourcesRetrieved) {
|
||||
return new AutoValue_RdapResultSet<>(
|
||||
return new RdapResultSet<>(
|
||||
ImmutableList.copyOf(resources), incompletenessWarningType, numResourcesRetrieved);
|
||||
}
|
||||
|
||||
/** List of EPP resources. */
|
||||
abstract ImmutableList<T> resources();
|
||||
|
||||
/** Type of warning to display regarding possible incomplete data. */
|
||||
abstract IncompletenessWarningType incompletenessWarningType();
|
||||
|
||||
/** Number of resources retrieved from the database in the process of assembling the data set. */
|
||||
abstract int numResourcesRetrieved();
|
||||
}
|
||||
|
||||
@@ -14,16 +14,13 @@
|
||||
|
||||
package google.registry.rde;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import google.registry.model.common.Cursor.CursorType;
|
||||
import google.registry.model.rde.RdeMode;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -49,10 +46,12 @@ import org.joda.time.Duration;
|
||||
* @param manual True if deposits should be generated via manual operation, which does not update
|
||||
* the cursor, and saves the generated deposits in a special manual subdirectory tree.
|
||||
* @param tld TLD for which a deposit should be generated.
|
||||
* @param watermark Watermark date for which a deposit should be generated.
|
||||
* @param watermarkStr String representation of the watermark date for which a deposit should be
|
||||
* generated.
|
||||
* @param mode Which type of deposit to generate: full (RDE) or thin (BRDA).
|
||||
* @param cursor The cursor type to update (not used in manual operation).
|
||||
* @param interval Amount of time to increment the cursor (not used in manual operation).
|
||||
* @param intervalStr String representation of the amount of time to increment the cursor (not used
|
||||
* in manual operation).
|
||||
* @param directoryWithTrailingSlash Subdirectory of bucket/manual in which files should be placed,
|
||||
* including a trailing slash (used only in manual operation).
|
||||
* @param revision Revision number for generated files; if absent, use the next available in the
|
||||
@@ -61,19 +60,28 @@ import org.joda.time.Duration;
|
||||
public record PendingDeposit(
|
||||
boolean manual,
|
||||
String tld,
|
||||
DateTime watermark,
|
||||
String watermarkStr,
|
||||
RdeMode mode,
|
||||
CursorType cursor,
|
||||
Duration interval,
|
||||
String directoryWithTrailingSlash,
|
||||
@Nullable CursorType cursor,
|
||||
@Nullable String intervalStr,
|
||||
@Nullable String directoryWithTrailingSlash,
|
||||
@Nullable Integer revision)
|
||||
implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3141095605225904433L;
|
||||
public DateTime watermark() {
|
||||
return DateTime.parse(watermarkStr);
|
||||
}
|
||||
|
||||
public Duration interval() {
|
||||
return intervalStr == null ? null : Duration.parse(intervalStr);
|
||||
}
|
||||
|
||||
@Serial private static final long serialVersionUID = 3141095605225904433L;
|
||||
|
||||
public static PendingDeposit create(
|
||||
String tld, DateTime watermark, RdeMode mode, CursorType cursor, Duration interval) {
|
||||
return new PendingDeposit(false, tld, watermark, mode, cursor, interval, null, null);
|
||||
return new PendingDeposit(
|
||||
false, tld, watermark.toString(), mode, cursor, interval.toString(), null, null);
|
||||
}
|
||||
|
||||
public static PendingDeposit createInManualOperation(
|
||||
@@ -83,55 +91,7 @@ public record PendingDeposit(
|
||||
String directoryWithTrailingSlash,
|
||||
@Nullable Integer revision) {
|
||||
return new PendingDeposit(
|
||||
true, tld, watermark, mode, null, null, directoryWithTrailingSlash, revision);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies that {@link SerializedForm} be used for {@code SafeObjectInputStream}-compatible
|
||||
* custom-serialization of {@link PendingDeposit the AutoValue implementation class}.
|
||||
*
|
||||
* <p>This method is package-protected so that the AutoValue implementation class inherits this
|
||||
* behavior.
|
||||
*
|
||||
* <p>This method leverages {@link PendingDepositCoder} to serializes an instance. However, it is
|
||||
* not invoked in Beam pipelines.
|
||||
*/
|
||||
Object writeReplace() throws ObjectStreamException {
|
||||
return new SerializedForm(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy for custom-serialization of {@link PendingDeposit}. This is necessary because the actual
|
||||
* class to be (de)serialized is the generated AutoValue implementation. See also {@link
|
||||
* #writeReplace}.
|
||||
*
|
||||
* <p>This class leverages {@link PendingDepositCoder} to safely deserializes an instance.
|
||||
* However, it is not used in Beam pipelines.
|
||||
*/
|
||||
private static class SerializedForm implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3141095605225904433L;
|
||||
|
||||
private PendingDeposit value;
|
||||
|
||||
private SerializedForm(PendingDeposit value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream os) throws IOException {
|
||||
checkState(value != null, "Non-null value expected for serialization.");
|
||||
PendingDepositCoder.INSTANCE.encode(value, os);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException {
|
||||
checkState(value == null, "Non-null value unexpected for deserialization.");
|
||||
this.value = PendingDepositCoder.INSTANCE.decode(is);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
return this.value;
|
||||
}
|
||||
true, tld, watermark.toString(), mode, null, null, directoryWithTrailingSlash, revision);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,15 +118,12 @@ public record PendingDeposit(
|
||||
public void encode(PendingDeposit value, OutputStream outStream) throws IOException {
|
||||
BooleanCoder.of().encode(value.manual(), outStream);
|
||||
StringUtf8Coder.of().encode(value.tld(), outStream);
|
||||
StringUtf8Coder.of().encode(value.watermark().toString(), outStream);
|
||||
StringUtf8Coder.of().encode(value.watermarkStr(), outStream);
|
||||
StringUtf8Coder.of().encode(value.mode().name(), outStream);
|
||||
NullableCoder.of(StringUtf8Coder.of())
|
||||
.encode(
|
||||
Optional.ofNullable(value.cursor()).map(CursorType::name).orElse(null), outStream);
|
||||
NullableCoder.of(StringUtf8Coder.of())
|
||||
.encode(
|
||||
Optional.ofNullable(value.interval()).map(Duration::toString).orElse(null),
|
||||
outStream);
|
||||
NullableCoder.of(StringUtf8Coder.of()).encode(value.intervalStr(), outStream);
|
||||
NullableCoder.of(StringUtf8Coder.of()).encode(value.directoryWithTrailingSlash(), outStream);
|
||||
NullableCoder.of(VarIntCoder.of()).encode(value.revision(), outStream);
|
||||
}
|
||||
@@ -176,14 +133,12 @@ public record PendingDeposit(
|
||||
return new PendingDeposit(
|
||||
BooleanCoder.of().decode(inStream),
|
||||
StringUtf8Coder.of().decode(inStream),
|
||||
DateTime.parse(StringUtf8Coder.of().decode(inStream)),
|
||||
StringUtf8Coder.of().decode(inStream),
|
||||
RdeMode.valueOf(StringUtf8Coder.of().decode(inStream)),
|
||||
Optional.ofNullable(NullableCoder.of(StringUtf8Coder.of()).decode(inStream))
|
||||
.map(CursorType::valueOf)
|
||||
.orElse(null),
|
||||
Optional.ofNullable(NullableCoder.of(StringUtf8Coder.of()).decode(inStream))
|
||||
.map(Duration::parse)
|
||||
.orElse(null),
|
||||
NullableCoder.of(StringUtf8Coder.of()).decode(inStream),
|
||||
NullableCoder.of(StringUtf8Coder.of()).decode(inStream),
|
||||
NullableCoder.of(VarIntCoder.of()).decode(inStream));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user