Remove transition code from []

The parameters were optional during the transition to allow old jobs stuck in the queue to work properly. It's been 2 months now so it's time to end the transition.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=190235532
This commit is contained in:
guyben 2018-03-23 10:10:00 -07:00 committed by jianglai
parent 785225fc28
commit 89d8ba93f2
5 changed files with 29 additions and 34 deletions

View file

@ -25,7 +25,6 @@ import static google.registry.dns.PublishDnsUpdatesAction.PARAM_PUBLISH_TASK_ENQ
import static google.registry.dns.PublishDnsUpdatesAction.PARAM_REFRESH_REQUEST_CREATED;
import static google.registry.request.RequestParameters.extractEnumParameter;
import static google.registry.request.RequestParameters.extractOptionalIntParameter;
import static google.registry.request.RequestParameters.extractOptionalParameter;
import static google.registry.request.RequestParameters.extractRequiredParameter;
import static google.registry.request.RequestParameters.extractSetOfParameters;
@ -40,7 +39,6 @@ import google.registry.dns.DnsConstants.TargetType;
import google.registry.dns.writer.DnsWriterZone;
import google.registry.request.Parameter;
import google.registry.request.RequestParameters;
import java.util.Optional;
import java.util.Set;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
@ -79,16 +77,14 @@ public abstract class DnsModule {
@Provides
@Parameter(PARAM_PUBLISH_TASK_ENQUEUED)
// TODO(b/73343464): make the param required once the transition has finished
static Optional<DateTime> provideCreateTime(HttpServletRequest req) {
return extractOptionalParameter(req, PARAM_PUBLISH_TASK_ENQUEUED).map(DateTime::parse);
static DateTime provideCreateTime(HttpServletRequest req) {
return DateTime.parse(extractRequiredParameter(req, PARAM_PUBLISH_TASK_ENQUEUED));
}
@Provides
@Parameter(PARAM_REFRESH_REQUEST_CREATED)
// TODO(b/73343464): make the param required once the transition has finished
static Optional<DateTime> provideItemsCreateTime(HttpServletRequest req) {
return extractOptionalParameter(req, PARAM_REFRESH_REQUEST_CREATED).map(DateTime::parse);
static DateTime provideItemsCreateTime(HttpServletRequest req) {
return DateTime.parse(extractRequiredParameter(req, PARAM_REFRESH_REQUEST_CREATED));
}
@Provides

View file

@ -33,7 +33,6 @@ import google.registry.request.lock.LockHandler;
import google.registry.util.Clock;
import google.registry.util.DomainNameUtils;
import google.registry.util.FormattingLogger;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
import javax.inject.Inject;
@ -75,10 +74,14 @@ public final class PublishDnsUpdatesAction implements Runnable, Callable<Void> {
* out (and not necessarily currently).
*/
@Inject @Parameter(PARAM_DNS_WRITER) String dnsWriter;
// TODO(b/73343464): make not-optional once transition has ended
@Inject @Parameter(PARAM_PUBLISH_TASK_ENQUEUED) Optional<DateTime> enqueuedTime;
// TODO(b/73343464): make not-optional once transition has ended
@Inject @Parameter(PARAM_REFRESH_REQUEST_CREATED) Optional<DateTime> itemsCreateTime;
@Inject
@Parameter(PARAM_PUBLISH_TASK_ENQUEUED)
DateTime enqueuedTime;
@Inject
@Parameter(PARAM_REFRESH_REQUEST_CREATED)
DateTime itemsCreateTime;
@Inject @Parameter(PARAM_LOCK_INDEX) int lockIndex;
@Inject @Parameter(PARAM_NUM_PUBLISH_LOCKS) int numPublishLocks;
@ -96,8 +99,8 @@ public final class PublishDnsUpdatesAction implements Runnable, Callable<Void> {
dnsWriter,
status,
nullToEmpty(domains).size() + nullToEmpty(hosts).size(),
new Duration(itemsCreateTime.orElse(now), now),
new Duration(enqueuedTime.orElse(now), now));
new Duration(itemsCreateTime, now),
new Duration(enqueuedTime, now));
logger.infofmt(
"publishDnsWriter latency statistics: TLD: %s, dnsWriter: %s, actionStatus: %s, "
+ "numItems: %s, timeSinceCreation: %s, timeInQueue: %s",
@ -105,8 +108,8 @@ public final class PublishDnsUpdatesAction implements Runnable, Callable<Void> {
dnsWriter,
status,
nullToEmpty(domains).size() + nullToEmpty(hosts).size(),
new Duration(itemsCreateTime.orElse(now), now),
new Duration(enqueuedTime.orElse(now), now));
new Duration(itemsCreateTime, now),
new Duration(enqueuedTime, now));
}
/** Runs the task. */

View file

@ -218,7 +218,7 @@ public final class ReadDnsQueueAction implements Runnable {
* tasks for paused TLDs or tasks for TLDs not part of {@link Registries#getTlds()}.
*/
private void dispatchTasks(ImmutableSet<TaskHandle> tasks, ImmutableSet<String> tlds) {
ClassifiedTasks classifiedTasks = classifyTasks(tasks, tlds, clock.nowUtc());
ClassifiedTasks classifiedTasks = classifyTasks(tasks, tlds);
if (!classifiedTasks.pausedTlds().isEmpty()) {
logger.infofmt("The dns-pull queue is paused for TLDs: %s.", classifiedTasks.pausedTlds());
}
@ -255,7 +255,7 @@ public final class ReadDnsQueueAction implements Runnable {
* taken on them) or in no category (if no action is to be taken on them)
*/
private static ClassifiedTasks classifyTasks(
ImmutableSet<TaskHandle> tasks, ImmutableSet<String> tlds, DateTime now) {
ImmutableSet<TaskHandle> tasks, ImmutableSet<String> tlds) {
ClassifiedTasks.Builder classifiedTasksBuilder = ClassifiedTasks.builder();
@ -263,14 +263,7 @@ public final class ReadDnsQueueAction implements Runnable {
for (TaskHandle task : tasks) {
try {
Map<String, String> params = ImmutableMap.copyOf(task.extractParams());
// We allow 'null' create-time for the transition period - and during that time we set the
// create-time to "now".
//
// TODO(b/73343464):remove support for null create-time once transition is over.
DateTime creationTime =
Optional.ofNullable(params.get(DNS_TARGET_CREATE_TIME_PARAM))
.map(DateTime::parse)
.orElse(now);
DateTime creationTime = DateTime.parse(params.get(DNS_TARGET_CREATE_TIME_PARAM));
String tld = params.get(RequestParameters.PARAM_TLD);
if (tld == null) {
logger.severefmt("Discarding invalid DNS refresh request %s; no TLD specified.", task);

View file

@ -42,7 +42,6 @@ import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeLockHandler;
import google.registry.testing.InjectRule;
import java.util.Optional;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.Before;
@ -93,8 +92,8 @@ public class PublishDnsUpdatesActionTest {
action.tld = tld;
action.hosts = ImmutableSet.of();
action.domains = ImmutableSet.of();
action.itemsCreateTime = Optional.of(clock.nowUtc().minusHours(2));
action.enqueuedTime = Optional.of(clock.nowUtc().minusHours(1));
action.itemsCreateTime = clock.nowUtc().minusHours(2);
action.enqueuedTime = clock.nowUtc().minusHours(1);
action.dnsWriter = "correctWriter";
action.dnsWriterProxy = new DnsWriterProxy(ImmutableMap.of("correctWriter", dnsWriter));
action.dnsMetrics = dnsMetrics;

View file

@ -67,6 +67,8 @@ public class ReadDnsQueueActionTest {
private static final int TEST_TLD_UPDATE_BATCH_SIZE = 100;
private DnsQueue dnsQueue;
// Because of a bug in the queue test environment - b/73372999 - we must set the fake date of the
// test in the future. Set to year 3000 so it'll remain in the future for a very long time.
private FakeClock clock = new FakeClock(DateTime.parse("3000-01-01TZ"));
@Rule
@ -129,10 +131,11 @@ public class ReadDnsQueueActionTest {
}
private static TaskOptions createRefreshTask(String name, TargetType type) {
TaskOptions options = TaskOptions.Builder
.withMethod(Method.PULL)
TaskOptions options =
TaskOptions.Builder.withMethod(Method.PULL)
.param(DNS_TARGET_TYPE_PARAM, type.toString())
.param(DNS_TARGET_NAME_PARAM, name);
.param(DNS_TARGET_NAME_PARAM, name)
.param(DNS_TARGET_CREATE_TIME_PARAM, "3000-01-01TZ");
String tld = InternetDomainName.from(name).parts().reverse().get(0);
return options.param("tld", tld);
}
@ -285,6 +288,7 @@ public class ReadDnsQueueActionTest {
.method(Method.PULL)
.param(DNS_TARGET_TYPE_PARAM, TargetType.DOMAIN.toString())
.param(DNS_TARGET_NAME_PARAM, "domain.unknown")
.param(DNS_TARGET_CREATE_TIME_PARAM, "3000-01-01TZ")
.param(PARAM_TLD, "unknown"));
run();