Make TRID field in async host/contact deletion non-optional

This cleans up a TODO introduced in the original bug, which allowed tasks to
have optional Trids in the case it was an older enqueued task.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=154477042
This commit is contained in:
larryruili 2017-04-27 15:19:29 -07:00 committed by Ben McIlwain
parent d4d02f8977
commit 62c05c112d

View file

@ -361,28 +361,20 @@ public class DeleteContactsAndHostsAction implements Runnable {
EppResource resource, EppResource resource,
boolean deleteAllowed, boolean deleteAllowed,
DateTime now) { DateTime now) {
Optional<String> clientTransactionId = deletionRequest.clientTransactionId(); String clientTransactionId = deletionRequest.clientTransactionId();
Optional<String> serverTransactionId = deletionRequest.serverTransactionId(); String serverTransactionId = deletionRequest.serverTransactionId();
// TODO(b/36402020): Make this unconditional, once older tasks enqueued without Trid data Trid trid = Trid.create(clientTransactionId, serverTransactionId);
// have been processed out of the queue. if (resource instanceof HostResource) {
checkState( return ImmutableList.of(
clientTransactionId.isPresent() == serverTransactionId.isPresent(), HostPendingActionNotificationResponse.create(
"Found one part of TRID without the other!"); ((HostResource) resource).getFullyQualifiedHostName(), deleteAllowed, trid, now));
if (clientTransactionId.isPresent() && serverTransactionId.isPresent()) { } else if (resource instanceof ContactResource) {
Trid trid = Trid.create(clientTransactionId.get(), serverTransactionId.get()); return ImmutableList.of(
if (resource instanceof HostResource) { ContactPendingActionNotificationResponse.create(
return ImmutableList.of( ((ContactResource) resource).getContactId(), deleteAllowed, trid, now));
HostPendingActionNotificationResponse.create( } else {
((HostResource) resource).getFullyQualifiedHostName(), deleteAllowed, trid, now)); throw new IllegalStateException("EPP resource of unknown type " + Key.create(resource));
} else if (resource instanceof ContactResource) {
return ImmutableList.of(
ContactPendingActionNotificationResponse.create(
((ContactResource) resource).getContactId(), deleteAllowed, trid, now));
} else {
throw new IllegalStateException("EPP resource of unknown type " + Key.create(resource));
}
} }
return ImmutableList.of();
} }
/** /**
@ -442,10 +434,10 @@ public class DeleteContactsAndHostsAction implements Runnable {
abstract String requestingClientId(); abstract String requestingClientId();
/** First half of TRID for the original request, split for serializability. */ /** First half of TRID for the original request, split for serializability. */
abstract Optional<String> clientTransactionId(); abstract String clientTransactionId();
/** Second half of TRID for the original request, split for serializability. */ /** Second half of TRID for the original request, split for serializability. */
abstract Optional<String> serverTransactionId(); abstract String serverTransactionId();
abstract boolean isSuperuser(); abstract boolean isSuperuser();
abstract TaskHandle task(); abstract TaskHandle task();
@ -455,8 +447,8 @@ public class DeleteContactsAndHostsAction implements Runnable {
abstract Builder setKey(Key<? extends EppResource> key); abstract Builder setKey(Key<? extends EppResource> key);
abstract Builder setLastUpdateTime(DateTime lastUpdateTime); abstract Builder setLastUpdateTime(DateTime lastUpdateTime);
abstract Builder setRequestingClientId(String requestingClientId); abstract Builder setRequestingClientId(String requestingClientId);
abstract Builder setClientTransactionId(Optional<String> clientTransactionId); abstract Builder setClientTransactionId(String clientTransactionId);
abstract Builder setServerTransactionId(Optional<String> serverTransactionId); abstract Builder setServerTransactionId(String serverTransactionId);
abstract Builder setIsSuperuser(boolean isSuperuser); abstract Builder setIsSuperuser(boolean isSuperuser);
abstract Builder setTask(TaskHandle task); abstract Builder setTask(TaskHandle task);
abstract DeletionRequest build(); abstract DeletionRequest build();
@ -485,11 +477,13 @@ public class DeleteContactsAndHostsAction implements Runnable {
checkNotNull( checkNotNull(
params.get(PARAM_REQUESTING_CLIENT_ID), "Requesting client id not specified")) params.get(PARAM_REQUESTING_CLIENT_ID), "Requesting client id not specified"))
.setClientTransactionId( .setClientTransactionId(
Optional.fromNullable( checkNotNull(
params.get(PARAM_CLIENT_TRANSACTION_ID))) params.get(PARAM_CLIENT_TRANSACTION_ID),
"Client transaction id not specified"))
.setServerTransactionId( .setServerTransactionId(
Optional.fromNullable( checkNotNull(
params.get(PARAM_SERVER_TRANSACTION_ID))) params.get(PARAM_SERVER_TRANSACTION_ID),
"Server transaction id not specified"))
.setIsSuperuser( .setIsSuperuser(
Boolean.valueOf( Boolean.valueOf(
checkNotNull(params.get(PARAM_IS_SUPERUSER), "Is superuser not specified"))) checkNotNull(params.get(PARAM_IS_SUPERUSER), "Is superuser not specified")))