Add package for flow pickers

This also renames the existing FlowRegistry to FlowPicker to avoid
overloaded uses of the word "registry".  Absent this renaming, the new
package would've been google.registry.flows.registry, which gives
entirely the wrong impression as it makes it sound like the home for
flows that affect TLDs.

This is a preparatory CL for adding flow picker engines that will
allow customized flows to run on a per-TLD basis.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=122671260
This commit is contained in:
mcilwain 2016-05-18 14:54:40 -07:00 committed by Ben McIlwain
parent 59e9d77ecc
commit ca0e546230
8 changed files with 14 additions and 11 deletions

View file

@ -16,7 +16,7 @@ package google.registry.flows;
import static google.registry.flows.EppXmlTransformer.marshalWithLenientRetry; import static google.registry.flows.EppXmlTransformer.marshalWithLenientRetry;
import static google.registry.flows.EppXmlTransformer.unmarshal; import static google.registry.flows.EppXmlTransformer.unmarshal;
import static google.registry.flows.FlowRegistry.getFlowClass; import static google.registry.flows.picker.FlowPicker.getFlowClass;
import com.google.apphosting.api.ApiProxy; import com.google.apphosting.api.ApiProxy;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package google.registry.flows; package google.registry.flows.picker;
import static google.registry.model.domain.launch.LaunchCreateExtension.CreateType.APPLICATION; import static google.registry.model.domain.launch.LaunchCreateExtension.CreateType.APPLICATION;
@ -22,8 +22,10 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableTable; import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Table; import com.google.common.collect.Table;
import google.registry.flows.EppException;
import google.registry.flows.EppException.SyntaxErrorException; import google.registry.flows.EppException.SyntaxErrorException;
import google.registry.flows.EppException.UnimplementedCommandException; import google.registry.flows.EppException.UnimplementedCommandException;
import google.registry.flows.Flow;
import google.registry.flows.contact.ContactCheckFlow; import google.registry.flows.contact.ContactCheckFlow;
import google.registry.flows.contact.ContactCreateFlow; import google.registry.flows.contact.ContactCreateFlow;
import google.registry.flows.contact.ContactDeleteFlow; import google.registry.flows.contact.ContactDeleteFlow;
@ -87,8 +89,8 @@ import google.registry.model.host.HostCommand;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
/** Registry that can select a flow to handle a given Epp command. */ /** Class that picks a flow to handle a given EPP command. */
public class FlowRegistry { public class FlowPicker {
/** Marker class for unimplemented flows. */ /** Marker class for unimplemented flows. */
private abstract static class UnimplementedFlow extends Flow {} private abstract static class UnimplementedFlow extends Flow {}

View file

@ -32,12 +32,12 @@ import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import google.registry.flows.Flow; import google.registry.flows.Flow;
import google.registry.flows.FlowRegistry;
import google.registry.flows.FlowRunner; import google.registry.flows.FlowRunner;
import google.registry.flows.FlowRunner.CommitMode; import google.registry.flows.FlowRunner.CommitMode;
import google.registry.flows.FlowRunner.UserPrivileges; import google.registry.flows.FlowRunner.UserPrivileges;
import google.registry.flows.SessionMetadata; import google.registry.flows.SessionMetadata;
import google.registry.flows.TlsCredentials; import google.registry.flows.TlsCredentials;
import google.registry.flows.picker.FlowPicker;
import google.registry.model.eppcommon.Trid; import google.registry.model.eppcommon.Trid;
import google.registry.model.eppinput.EppInput; import google.registry.model.eppinput.EppInput;
import google.registry.tools.Command.GtechCommand; import google.registry.tools.Command.GtechCommand;
@ -103,7 +103,7 @@ final class ValidateLoginCredentialsCommand implements RemoteApiCommand, GtechCo
.render() .render()
.getBytes(UTF_8); .getBytes(UTF_8);
EppInput eppInput = unmarshal(inputXmlBytes); EppInput eppInput = unmarshal(inputXmlBytes);
Class<? extends Flow> flowClass = FlowRegistry.getFlowClass(eppInput); Class<? extends Flow> flowClass = FlowPicker.getFlowClass(eppInput);
System.out.println(runFlow( System.out.println(runFlow(
new FlowRunner( new FlowRunner(
flowClass, flowClass,

View file

@ -17,7 +17,7 @@ package google.registry.tools.server;
import static com.google.common.base.Predicates.not; import static com.google.common.base.Predicates.not;
import static com.google.common.collect.Maps.toMap; import static com.google.common.collect.Maps.toMap;
import static google.registry.flows.EppXmlTransformer.unmarshal; import static google.registry.flows.EppXmlTransformer.unmarshal;
import static google.registry.flows.FlowRegistry.getFlowClass; import static google.registry.flows.picker.FlowPicker.getFlowClass;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.CollectionUtils.isNullOrEmpty; import static google.registry.util.CollectionUtils.isNullOrEmpty;
import static google.registry.util.DomainNameUtils.ACE_PREFIX; import static google.registry.util.DomainNameUtils.ACE_PREFIX;

View file

@ -37,6 +37,7 @@ import com.google.common.collect.Maps;
import google.registry.flows.FlowRunner.CommitMode; import google.registry.flows.FlowRunner.CommitMode;
import google.registry.flows.FlowRunner.UserPrivileges; import google.registry.flows.FlowRunner.UserPrivileges;
import google.registry.flows.SessionMetadata.SessionSource; import google.registry.flows.SessionMetadata.SessionSource;
import google.registry.flows.picker.FlowPicker;
import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent;
import google.registry.model.domain.GracePeriod; import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.rgp.GracePeriodStatus;
@ -129,7 +130,7 @@ public abstract class FlowTestCase<F extends Flow> {
/** Load a flow from an epp object. */ /** Load a flow from an epp object. */
private FlowRunner createFlowRunner() throws Exception { private FlowRunner createFlowRunner() throws Exception {
EppInput eppInput = eppLoader.getEpp(); EppInput eppInput = eppLoader.getEpp();
flowClass = firstNonNull(flowClass, FlowRegistry.getFlowClass(eppInput)); flowClass = firstNonNull(flowClass, FlowPicker.getFlowClass(eppInput));
Class<?> expectedFlowClass = new TypeInstantiator<F>(getClass()){}.getExactType(); Class<?> expectedFlowClass = new TypeInstantiator<F>(getClass()){}.getExactType();
assertThat(flowClass).isEqualTo(expectedFlowClass); assertThat(flowClass).isEqualTo(expectedFlowClass);
return new FlowRunner( return new FlowRunner(

View file

@ -103,7 +103,7 @@ public class DomainAllocateFlowTest
public void initAllocateTest() throws Exception { public void initAllocateTest() throws Exception {
setEppInput("domain_allocate.xml", ImmutableMap.of("APPLICATIONID", "2-TLD")); setEppInput("domain_allocate.xml", ImmutableMap.of("APPLICATIONID", "2-TLD"));
clock.setTo(APPLICATION_TIME); clock.setTo(APPLICATION_TIME);
// We must manually set the flow class since this flow is not registered in the flow registry. // We must manually set the flow class since this flow is not registered in the flow picker.
flowClass = DomainAllocateFlow.class; flowClass = DomainAllocateFlow.class;
} }

View file

@ -15,7 +15,7 @@
package google.registry.model; package google.registry.model;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.flows.FlowRegistry.getFlowClass; import static google.registry.flows.picker.FlowPicker.getFlowClass;
import static google.registry.model.EppResourceUtils.loadAtPointInTime; import static google.registry.model.EppResourceUtils.loadAtPointInTime;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;

View file

@ -19,7 +19,7 @@ import static com.google.common.io.Resources.getResource;
import static com.google.common.io.Resources.toByteArray; import static com.google.common.io.Resources.toByteArray;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.flows.EppServletUtils.APPLICATION_EPP_XML_UTF8; import static google.registry.flows.EppServletUtils.APPLICATION_EPP_XML_UTF8;
import static google.registry.flows.FlowRegistry.getFlowClass; import static google.registry.flows.picker.FlowPicker.getFlowClass;
import static google.registry.model.domain.DesignatedContact.Type.ADMIN; import static google.registry.model.domain.DesignatedContact.Type.ADMIN;
import static google.registry.model.domain.DesignatedContact.Type.BILLING; import static google.registry.model.domain.DesignatedContact.Type.BILLING;
import static google.registry.model.domain.DesignatedContact.Type.TECH; import static google.registry.model.domain.DesignatedContact.Type.TECH;