// Copyright 2016 The Domain Registry 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; import static com.google.common.math.IntMath.divide; import static java.math.RoundingMode.CEILING; import static java.math.RoundingMode.FLOOR; 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.appengine.tools.mapreduce.Input; import com.google.appengine.tools.mapreduce.InputReader; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import google.registry.config.ConfigModule; import google.registry.gcs.GcsUtils; import google.registry.model.contact.ContactResource; import google.registry.rde.RdeParser.RdeHeader; import java.io.IOException; import java.io.InputStream; import java.util.List; /** * A MapReduce {@link Input} that imports {@link ContactResource} objects from an escrow file. * *
If a mapShards parameter has been specified, up to that many readers will be created
* so that each map shard has one reader. If a mapShards parameter has not been specified, a
* default number of readers will be created.
*/
public class RdeContactInput extends Input This method can be overridden by a subclass for the purposes of unit testing.
*/
protected RdeContactReader newReader(int offset, int maxResults) {
return new RdeContactReader(importBucketName, importFileName, offset, maxResults);
}
/**
* Creates a new instance of {@link RdeParser}
*/
private RdeParser newParser() {
GcsUtils utils = new GcsUtils(GCS_SERVICE, ConfigModule.provideGcsBufferSize());
GcsFilename filename = new GcsFilename(importBucketName, importFileName);
try (InputStream xmlInput = utils.openInputStream(filename)) {
return new RdeParser(xmlInput);
} catch (Exception e) {
throw new InitializationException(
String.format("Error opening rde file %s/%s", importBucketName, importFileName), e);
}
}
/**
* Thrown when the input cannot initialize properly.
*/
private static class InitializationException extends RuntimeException {
public InitializationException(String message, Throwable cause) {
super(message, cause);
}
}
}