mirror of
https://github.com/google/nomulus.git
synced 2025-05-28 11:10:57 +02:00
Append event year to poll message external IDs
This solves the problem of external poll message IDs not being globally unique by simply appending the event year. This means that autorenew poll messages will increment by one every year, so they will always be unique. This also requires no data schema changes, and thus most importantly, no data migration. Incoming requests lacking this new year field will continue to work for now for backwards compatibility reasons. This is possible because we don't actually use the year for anything. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178012685
This commit is contained in:
parent
8e33bc898f
commit
931156fdd7
26 changed files with 270 additions and 127 deletions
|
@ -16,7 +16,6 @@ package google.registry.model.poll;
|
|||
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
||||
import com.google.common.base.Converter;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.googlecode.objectify.Key;
|
||||
|
@ -31,7 +30,7 @@ import java.util.List;
|
|||
* A converter between external key strings for {@link PollMessage}s (i.e. what registrars use to
|
||||
* identify and ACK them) and Datastore keys to the resource.
|
||||
*
|
||||
* <p>The format of the key string is A-B-C-D-E as follows:
|
||||
* <p>The format of the key string is A-B-C-D-E-F as follows:
|
||||
*
|
||||
* <pre>
|
||||
* A = EppResource.typeId (decimal)
|
||||
|
@ -39,9 +38,12 @@ import java.util.List;
|
|||
* C = EppResource.repoId suffix (STRING)
|
||||
* D = HistoryEntry.id (decimal)
|
||||
* E = PollMessage.id (decimal)
|
||||
* F = PollMessage.eventTime (decimal, year only)
|
||||
* </pre>
|
||||
*
|
||||
* <p>A typical poll message ID might thus look like: 1-FE0F22-TLD-10071463070-10072612074-2018
|
||||
*/
|
||||
public class PollMessageExternalKeyConverter extends Converter<Key<PollMessage>, String> {
|
||||
public class PollMessageExternalKeyConverter {
|
||||
|
||||
/** An exception thrown when an external key cannot be parsed. */
|
||||
public static class PollMessageExternalKeyParseException extends RuntimeException {}
|
||||
|
@ -56,29 +58,38 @@ public class PollMessageExternalKeyConverter extends Converter<Key<PollMessage>,
|
|||
ContactResource.class, 2L,
|
||||
HostResource.class, 3L);
|
||||
|
||||
@Override
|
||||
protected String doForward(Key<PollMessage> key) {
|
||||
/** Returns an external poll message ID for the given poll message. */
|
||||
public static String makePollMessageExternalId(PollMessage pollMessage) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Key<EppResource> ancestorResource =
|
||||
(Key<EppResource>) (Key<?>) key.getParent().getParent();
|
||||
long externalKeyClassId = EXTERNAL_KEY_CLASS_ID_MAP.get(
|
||||
ofy().factory().getMetadata(ancestorResource.getKind()).getEntityClass());
|
||||
return String.format("%d-%s-%d-%d",
|
||||
(Key<EppResource>) (Key<?>) pollMessage.getParentKey().getParent();
|
||||
long externalKeyClassId =
|
||||
EXTERNAL_KEY_CLASS_ID_MAP.get(
|
||||
ofy().factory().getMetadata(ancestorResource.getKind()).getEntityClass());
|
||||
return String.format(
|
||||
"%d-%s-%d-%d-%d",
|
||||
externalKeyClassId,
|
||||
ancestorResource.getName(),
|
||||
key.getParent().getId(),
|
||||
key.getId());
|
||||
pollMessage.getParentKey().getId(),
|
||||
pollMessage.getId(),
|
||||
pollMessage.getEventTime().getYear());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Objectify Key to a PollMessage corresponding with the external key string.
|
||||
* Returns an Objectify Key to a PollMessage corresponding with the external ID.
|
||||
*
|
||||
* <p>Note that the year field that is included at the end of the poll message isn't actually
|
||||
* used for anything; it exists solely to create unique externally visible IDs for autorenews. We
|
||||
* thus ignore it (for now) for backwards compatibility reasons, so that registrars can still ACK
|
||||
* existing poll message IDs they may have lying around.
|
||||
*
|
||||
* @throws PollMessageExternalKeyParseException if the external key has an invalid format.
|
||||
*/
|
||||
@Override
|
||||
protected Key<PollMessage> doBackward(String externalKey) {
|
||||
// TODO(b/68953444): Make the year field mandatory once sufficient time has elapsed and backwards
|
||||
// compatibility is no longer necessary.
|
||||
public static Key<PollMessage> parsePollMessageExternalId(String externalKey) {
|
||||
List<String> idComponents = Splitter.on('-').splitToList(externalKey);
|
||||
if (idComponents.size() != 5) {
|
||||
if (idComponents.size() != 5 && idComponents.size() != 6) {
|
||||
throw new PollMessageExternalKeyParseException();
|
||||
}
|
||||
try {
|
||||
|
@ -97,9 +108,12 @@ public class PollMessageExternalKeyConverter extends Converter<Key<PollMessage>,
|
|||
Long.parseLong(idComponents.get(3))),
|
||||
PollMessage.class,
|
||||
Long.parseLong(idComponents.get(4)));
|
||||
// Note that idComponents.get(5) is entirely ignored; we never use the year field internally.
|
||||
} catch (NumberFormatException e) {
|
||||
throw new PollMessageExternalKeyParseException();
|
||||
}
|
||||
}
|
||||
|
||||
private PollMessageExternalKeyConverter() {}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue