mirror of
https://github.com/google/nomulus.git
synced 2025-05-16 17:37:13 +02:00
Add an auto update time field to the Cursor entity
Also adjusts the nomulus list_cursors command to output the value of this field. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=206646117
This commit is contained in:
parent
3941249dfe
commit
f614044681
6 changed files with 62 additions and 14 deletions
|
@ -18,6 +18,7 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||||
|
|
||||||
import google.registry.model.translators.UpdateAutoTimestampTranslatorFactory;
|
import google.registry.model.translators.UpdateAutoTimestampTranslatorFactory;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,12 +30,12 @@ public class UpdateAutoTimestamp extends ImmutableObject {
|
||||||
|
|
||||||
DateTime timestamp;
|
DateTime timestamp;
|
||||||
|
|
||||||
/** Returns the timestamp, or {@link #START_OF_TIME} if it's null. */
|
/** Returns the timestamp, or {@link START_OF_TIME} if it's null. */
|
||||||
public DateTime getTimestamp() {
|
public DateTime getTimestamp() {
|
||||||
return Optional.ofNullable(timestamp).orElse(START_OF_TIME);
|
return Optional.ofNullable(timestamp).orElse(START_OF_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UpdateAutoTimestamp create(DateTime timestamp) {
|
public static UpdateAutoTimestamp create(@Nullable DateTime timestamp) {
|
||||||
UpdateAutoTimestamp instance = new UpdateAutoTimestamp();
|
UpdateAutoTimestamp instance = new UpdateAutoTimestamp();
|
||||||
instance.timestamp = timestamp;
|
instance.timestamp = timestamp;
|
||||||
return instance;
|
return instance;
|
||||||
|
|
|
@ -25,6 +25,7 @@ import com.googlecode.objectify.annotation.Entity;
|
||||||
import com.googlecode.objectify.annotation.Id;
|
import com.googlecode.objectify.annotation.Id;
|
||||||
import com.googlecode.objectify.annotation.Parent;
|
import com.googlecode.objectify.annotation.Parent;
|
||||||
import google.registry.model.ImmutableObject;
|
import google.registry.model.ImmutableObject;
|
||||||
|
import google.registry.model.UpdateAutoTimestamp;
|
||||||
import google.registry.model.registry.Registry;
|
import google.registry.model.registry.Registry;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
@ -108,6 +109,13 @@ public class Cursor extends ImmutableObject {
|
||||||
|
|
||||||
DateTime cursorTime = START_OF_TIME;
|
DateTime cursorTime = START_OF_TIME;
|
||||||
|
|
||||||
|
/** An automatically managed timestamp of when this object was last written to Datastore. */
|
||||||
|
UpdateAutoTimestamp lastUpdateTime = UpdateAutoTimestamp.create(null);
|
||||||
|
|
||||||
|
public DateTime getLastUpdateTime() {
|
||||||
|
return lastUpdateTime.getTimestamp();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks that the type of the scoped object (or null) matches the required type for the specified
|
* Checks that the type of the scoped object (or null) matches the required type for the specified
|
||||||
* cursor (or null, if the cursor is a global cursor).
|
* cursor (or null, if the cursor is a global cursor).
|
||||||
|
|
|
@ -19,6 +19,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
|
|
||||||
import com.beust.jcommander.Parameter;
|
import com.beust.jcommander.Parameter;
|
||||||
import com.beust.jcommander.Parameters;
|
import com.beust.jcommander.Parameters;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.googlecode.objectify.Key;
|
import com.googlecode.objectify.Key;
|
||||||
import google.registry.model.common.Cursor;
|
import google.registry.model.common.Cursor;
|
||||||
import google.registry.model.common.Cursor.CursorType;
|
import google.registry.model.common.Cursor.CursorType;
|
||||||
|
@ -27,6 +28,7 @@ import google.registry.model.registry.Registry;
|
||||||
import google.registry.model.registry.Registry.TldType;
|
import google.registry.model.registry.Registry.TldType;
|
||||||
import google.registry.tools.Command.RemoteApiCommand;
|
import google.registry.tools.Command.RemoteApiCommand;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/** Lists {@link Cursor} timestamps used by locking rolling cursor tasks, like in RDE. */
|
/** Lists {@link Cursor} timestamps used by locking rolling cursor tasks, like in RDE. */
|
||||||
@Parameters(separators = " =", commandDescription = "Lists cursor timestamps used by LRC tasks")
|
@Parameters(separators = " =", commandDescription = "Lists cursor timestamps used by LRC tasks")
|
||||||
|
@ -45,6 +47,8 @@ final class ListCursorsCommand implements RemoteApiCommand {
|
||||||
description = "Filter TLDs to only include those with RDE escrow enabled; defaults to false.")
|
description = "Filter TLDs to only include those with RDE escrow enabled; defaults to false.")
|
||||||
private boolean filterEscrowEnabled = false;
|
private boolean filterEscrowEnabled = false;
|
||||||
|
|
||||||
|
private static final String OUTPUT_FMT = "%-20s %-24s %-24s";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Map<Registry, Key<Cursor>> registries =
|
Map<Registry, Key<Cursor>> registries =
|
||||||
|
@ -55,18 +59,26 @@ final class ListCursorsCommand implements RemoteApiCommand {
|
||||||
.filter(r -> !filterEscrowEnabled || r.getEscrowEnabled())
|
.filter(r -> !filterEscrowEnabled || r.getEscrowEnabled())
|
||||||
.collect(toImmutableMap(r -> r, r -> Cursor.createKey(cursorType, r)));
|
.collect(toImmutableMap(r -> r, r -> Cursor.createKey(cursorType, r)));
|
||||||
Map<Key<Cursor>, Cursor> cursors = ofy().load().keys(registries.values());
|
Map<Key<Cursor>, Cursor> cursors = ofy().load().keys(registries.values());
|
||||||
registries
|
if (!registries.isEmpty()) {
|
||||||
.entrySet()
|
String header = String.format(OUTPUT_FMT, "TLD", "Cursor Time", "Last Update Time");
|
||||||
.stream()
|
System.out.printf("%s\n%s\n", header, Strings.repeat("-", header.length()));
|
||||||
.map(e -> renderLine(e.getKey().getTldStr(), e.getValue(), cursors))
|
registries
|
||||||
.sorted()
|
.entrySet()
|
||||||
.forEach(System.out::println);
|
.stream()
|
||||||
|
.map(
|
||||||
|
e ->
|
||||||
|
renderLine(
|
||||||
|
e.getKey().getTldStr(), Optional.ofNullable(cursors.get(e.getValue()))))
|
||||||
|
.sorted()
|
||||||
|
.forEach(System.out::println);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String renderLine(
|
private static String renderLine(String tld, Optional<Cursor> cursor) {
|
||||||
String tld, Key<Cursor> cursorKey, Map<Key<Cursor>, Cursor> cursors) {
|
|
||||||
return String.format(
|
return String.format(
|
||||||
"%-25s%s",
|
OUTPUT_FMT,
|
||||||
cursors.containsKey(cursorKey) ? cursors.get(cursorKey).getCursorTime() : "(absent)", tld);
|
tld,
|
||||||
|
cursor.map(c -> c.getCursorTime().toString()).orElse("(absent)"),
|
||||||
|
cursor.map(c -> c.getLastUpdateTime().toString()).orElse("(absent)"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
/** Unit tests for {@link Cursor}. */
|
/** Unit tests for {@link Cursor}. */
|
||||||
public class CursorTest extends EntityTestCase {
|
public class CursorTest extends EntityTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_persistScopedCursor() {
|
public void testSuccess_persistScopedCursor() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
|
|
|
@ -73,6 +73,7 @@ class google.registry.model.billing.BillingEvent$Recurring {
|
||||||
class google.registry.model.common.Cursor {
|
class google.registry.model.common.Cursor {
|
||||||
@Id java.lang.String id;
|
@Id java.lang.String id;
|
||||||
@Parent com.googlecode.objectify.Key<google.registry.model.common.EntityGroupRoot> parent;
|
@Parent com.googlecode.objectify.Key<google.registry.model.common.EntityGroupRoot> parent;
|
||||||
|
google.registry.model.UpdateAutoTimestamp lastUpdateTime;
|
||||||
org.joda.time.DateTime cursorTime;
|
org.joda.time.DateTime cursorTime;
|
||||||
}
|
}
|
||||||
class google.registry.model.common.EntityGroupRoot {
|
class google.registry.model.common.EntityGroupRoot {
|
||||||
|
|
|
@ -22,13 +22,32 @@ import static google.registry.testing.JUnitBackports.assertThrows;
|
||||||
import com.beust.jcommander.ParameterException;
|
import com.beust.jcommander.ParameterException;
|
||||||
import google.registry.model.common.Cursor;
|
import google.registry.model.common.Cursor;
|
||||||
import google.registry.model.common.Cursor.CursorType;
|
import google.registry.model.common.Cursor.CursorType;
|
||||||
|
import google.registry.model.ofy.Ofy;
|
||||||
import google.registry.model.registry.Registry;
|
import google.registry.model.registry.Registry;
|
||||||
|
import google.registry.testing.FakeClock;
|
||||||
|
import google.registry.testing.InjectRule;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/** Unit tests for {@link ListCursorsCommand}. */
|
/** Unit tests for {@link ListCursorsCommand}. */
|
||||||
public class ListCursorsCommandTest extends CommandTestCase<ListCursorsCommand> {
|
public class ListCursorsCommandTest extends CommandTestCase<ListCursorsCommand> {
|
||||||
|
|
||||||
|
private static final String HEADER_ONE =
|
||||||
|
"TLD Cursor Time Last Update Time";
|
||||||
|
|
||||||
|
private static final String HEADER_TWO =
|
||||||
|
"--------------------------------------------------------------------------";
|
||||||
|
|
||||||
|
@Rule public final InjectRule inject = new InjectRule();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() {
|
||||||
|
inject.setStaticField(
|
||||||
|
Ofy.class, "clock", new FakeClock(DateTime.parse("1984-12-21T06:07:08.789Z")));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListCursors_noTlds_printsNothing() throws Exception {
|
public void testListCursors_noTlds_printsNothing() throws Exception {
|
||||||
runCommand("--type=BRDA");
|
runCommand("--type=BRDA");
|
||||||
|
@ -42,7 +61,11 @@ public class ListCursorsCommandTest extends CommandTestCase<ListCursorsCommand>
|
||||||
Cursor.create(CursorType.BRDA, DateTime.parse("1984-12-18TZ"), Registry.get("bar")));
|
Cursor.create(CursorType.BRDA, DateTime.parse("1984-12-18TZ"), Registry.get("bar")));
|
||||||
runCommand("--type=BRDA");
|
runCommand("--type=BRDA");
|
||||||
assertThat(getStdoutAsLines())
|
assertThat(getStdoutAsLines())
|
||||||
.containsExactly("(absent) foo", "1984-12-18T00:00:00.000Z bar")
|
.containsExactly(
|
||||||
|
HEADER_ONE,
|
||||||
|
HEADER_TWO,
|
||||||
|
"bar 1984-12-18T00:00:00.000Z 1984-12-21T06:07:08.789Z",
|
||||||
|
"foo (absent) (absent)")
|
||||||
.inOrder();
|
.inOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +86,8 @@ public class ListCursorsCommandTest extends CommandTestCase<ListCursorsCommand>
|
||||||
createTlds("foo", "bar");
|
createTlds("foo", "bar");
|
||||||
persistResource(Registry.get("bar").asBuilder().setEscrowEnabled(true).build());
|
persistResource(Registry.get("bar").asBuilder().setEscrowEnabled(true).build());
|
||||||
runCommand("--type=BRDA", "--escrow_enabled");
|
runCommand("--type=BRDA", "--escrow_enabled");
|
||||||
assertThat(getStdoutAsLines()).containsExactly("(absent) bar");
|
assertThat(getStdoutAsLines())
|
||||||
|
.containsExactly(
|
||||||
|
HEADER_ONE, HEADER_TWO, "bar (absent) (absent)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue