Add host linker mapreduce for RDE imports

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=147025088
This commit is contained in:
Wolfgang Meyers 2017-02-09 05:49:24 -08:00 committed by Ben McIlwain
parent 6cdb3d81d3
commit da1f83a7b4
15 changed files with 353 additions and 29 deletions

View file

@ -16,6 +16,7 @@ package google.registry.rde.imports;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.getHistoryEntries;
import static google.registry.testing.DatastoreHelper.newHostResource;
import static google.registry.testing.DatastoreHelper.persistResource;
@ -66,6 +67,7 @@ public class RdeHostImportActionTest extends MapreduceTestCase<RdeHostImportActi
@Before
public void before() throws Exception {
createTld("test");
response = new FakeResponse();
mrRunner = new MapreduceRunner(Optional.<Integer>absent(), Optional.<Integer>absent());
action = new RdeHostImportAction(

View file

@ -0,0 +1,108 @@
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.rde.imports;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newHostResource;
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.appengine.tools.cloudstorage.GcsFilename;
import com.google.appengine.tools.cloudstorage.GcsService;
import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
import com.google.appengine.tools.cloudstorage.RetryParams;
import com.google.common.base.Optional;
import com.google.common.io.ByteSource;
import com.google.common.io.ByteStreams;
import com.googlecode.objectify.Key;
import google.registry.config.RegistryConfig.ConfigModule;
import google.registry.gcs.GcsUtils;
import google.registry.mapreduce.MapreduceRunner;
import google.registry.model.domain.DomainResource;
import google.registry.model.host.HostResource;
import google.registry.model.index.ForeignKeyIndex.ForeignKeyDomainIndex;
import google.registry.request.Response;
import google.registry.testing.FakeResponse;
import google.registry.testing.mapreduce.MapreduceTestCase;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link RdeHostLinkAction}. */
@RunWith(JUnit4.class)
public class RdeHostLinkActionTest extends MapreduceTestCase<RdeHostLinkAction> {
private static final ByteSource DEPOSIT_1_HOST = RdeImportsTestData.get("deposit_1_host.xml");
private static final String IMPORT_BUCKET_NAME = "import-bucket";
private static final String IMPORT_FILE_NAME = "escrow-file.xml";
private static final GcsService GCS_SERVICE =
GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
private MapreduceRunner mrRunner;
private Response response;
private final Optional<Integer> mapShards = Optional.absent();
@Before
public void before() throws Exception {
createTld("test");
response = new FakeResponse();
mrRunner = new MapreduceRunner(Optional.<Integer>absent(), Optional.<Integer>absent());
action =
new RdeHostLinkAction(mrRunner, response, IMPORT_BUCKET_NAME, IMPORT_FILE_NAME, mapShards);
}
@Test
public void test_mapreduceSuccessfullyLinksHost() throws Exception {
// Create host and domain first
persistResource(
newHostResource("ns1.example1.test")
.asBuilder()
.setRepoId("Hns1_example1_test-TEST")
.build());
DomainResource superordinateDomain = persistActiveDomain("example1.test");
ForeignKeyDomainIndex.create(superordinateDomain, END_OF_TIME);
Key<DomainResource> superOrdinateDomainKey = Key.create(superordinateDomain);
pushToGcs(DEPOSIT_1_HOST);
runMapreduce();
List<HostResource> hosts = ofy().load().type(HostResource.class).list();
assertThat(hosts).hasSize(1);
assertThat(hosts.get(0).getSuperordinateDomain()).isEqualTo(superOrdinateDomainKey);
}
private void runMapreduce() throws Exception {
action.run();
executeTasksUntilEmpty("mapreduce");
}
private static void pushToGcs(ByteSource source) throws IOException {
try (OutputStream outStream =
new GcsUtils(GCS_SERVICE, ConfigModule.provideGcsBufferSize())
.openOutputStream(new GcsFilename(IMPORT_BUCKET_NAME, IMPORT_FILE_NAME));
InputStream inStream = source.openStream()) {
ByteStreams.copy(inStream, outStream);
}
}
}

View file

@ -132,6 +132,16 @@ public class XjcToDomainResourceConverterTest {
assertThat(domain.getAuthInfo().getPw().getValue()).isEqualTo("0123456789abcdef");
}
/** Verifies that uppercase domain names are converted to lowercase */
@Test
public void testConvertDomainResourceUpperCase() throws Exception {
persistActiveContact("jd1234");
persistActiveContact("sh8013");
final XjcRdeDomain xjcDomain = loadDomainFromRdeXml("domain_fragment_ucase.xml");
DomainResource domain = convertDomainInTransaction(xjcDomain);
assertThat(domain.getFullyQualifiedDomainName()).isEqualTo("example1.example");
}
@Test
public void testConvertDomainResourceAddPeriod() throws Exception {
persistActiveContact("jd1234");

View file

@ -51,6 +51,8 @@ import org.junit.runners.JUnit4;
public class XjcToHostResourceConverterTest extends ShardableTestCase {
private static final ByteSource HOST_XML = RdeImportsTestData.get("host_fragment.xml");
private static final ByteSource HOST_XML_UCASE =
RdeImportsTestData.get("host_fragment_ucase.xml");
// List of packages to initialize JAXBContext
private static final String JAXB_CONTEXT_PACKAGES = Joiner.on(":")
@ -103,6 +105,14 @@ public class XjcToHostResourceConverterTest extends ShardableTestCase {
assertThat(host.getLastTransferTime()).isEqualTo(DateTime.parse("2008-10-03T09:34:00.0Z"));
}
/** Verifies that uppercase host names are converted to lowercase */
@Test
public void testConvertHostResourceUpperCase() throws Exception {
XjcRdeHost xjcHost = loadHostFromRdeXml(HOST_XML_UCASE);
HostResource host = convertHostInTransaction(xjcHost);
assertThat(host.getFullyQualifiedHostName()).isEqualTo("ns1.example1.test");
}
@Test
public void testConvertHostResourceHistoryEntry() throws Exception {
XjcRdeHost xjcHost = loadHostFromRdeXml();
@ -134,7 +144,11 @@ public class XjcToHostResourceConverterTest extends ShardableTestCase {
}
private XjcRdeHost loadHostFromRdeXml() throws Exception {
try (InputStream ins = HOST_XML.openStream()) {
return loadHostFromRdeXml(HOST_XML);
}
private XjcRdeHost loadHostFromRdeXml(ByteSource source) throws Exception {
try (InputStream ins = source.openStream()) {
return ((XjcRdeHostElement) unmarshaller.unmarshal(ins)).getValue();
}
}

View file

@ -9,7 +9,7 @@
<rdeDom:contact type="tech">sh8013</rdeDom:contact>
<rdeDom:ns>
<domain:hostObj>ns1.example.net</domain:hostObj>
<domain:hostObj>ns2.example.net</domain:hostObj>
<domain:hostObj>NS2.EXAMPLE.NET</domain:hostObj>
</rdeDom:ns>
<rdeDom:clID>RegistrarX</rdeDom:clID>
<rdeDom:crRr client="jdoe">RegistrarX</rdeDom:crRr>

View file

@ -0,0 +1,14 @@
<rdeDom:domain
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"
xmlns:rdeDom="urn:ietf:params:xml:ns:rdeDomain-1.0">
<rdeDom:name>EXAMPLE1.EXAMPLE</rdeDom:name>
<rdeDom:roid>Dexample1-TEST</rdeDom:roid>
<rdeDom:status s="ok"/>
<rdeDom:registrant>jd1234</rdeDom:registrant>
<rdeDom:contact type="admin">sh8013</rdeDom:contact>
<rdeDom:contact type="tech">sh8013</rdeDom:contact>
<rdeDom:clID>RegistrarX</rdeDom:clID>
<rdeDom:crRr client="jdoe">RegistrarX</rdeDom:crRr>
<rdeDom:crDate>1999-04-03T22:00:00.0Z</rdeDom:crDate>
<rdeDom:exDate>2015-04-03T22:00:00.0Z</rdeDom:exDate>
</rdeDom:domain>

View file

@ -0,0 +1,15 @@
<rdeHost:host xmlns:rdeHost="urn:ietf:params:xml:ns:rdeHost-1.0">
<rdeHost:name>NS1.EXAMPLE1.TEST</rdeHost:name>
<rdeHost:roid>Hns1_example1_test-TEST</rdeHost:roid>
<rdeHost:status s="ok"/>
<rdeHost:status s="linked"/>
<rdeHost:addr ip="v4">192.0.2.2</rdeHost:addr>
<rdeHost:addr ip="v4">192.0.2.29</rdeHost:addr>
<rdeHost:addr ip="v6">1080:0:0:0:8:800:200C:417A</rdeHost:addr>
<rdeHost:clID>RegistrarX</rdeHost:clID>
<rdeHost:crRr>RegistrarX</rdeHost:crRr>
<rdeHost:crDate>1999-05-08T12:10:00.0Z</rdeHost:crDate>
<rdeHost:upRr>RegistrarX</rdeHost:upRr>
<rdeHost:upDate>2009-10-03T09:34:00.0Z</rdeHost:upDate>
<rdeHost:trDate>2008-10-03T09:34:00.0Z</rdeHost:trDate>
</rdeHost:host>