noslowerdna commented on a change in pull request #20: CRUNCH-679: Improvements for usage of DistCp URL: https://github.com/apache/crunch/pull/20#discussion_r263044336
########## File path: crunch-core/src/main/java/org/apache/crunch/util/CrunchRenameCopyListing.java ########## @@ -0,0 +1,269 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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 org.apache.crunch.util; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.io.SequenceFile; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.security.Credentials; +import org.apache.hadoop.tools.CopyListing; +import org.apache.hadoop.tools.CopyListingFileStatus; +import org.apache.hadoop.tools.DistCpOptions; +import org.apache.hadoop.tools.DistCpOptions.FileAttribute; +import org.apache.hadoop.tools.SimpleCopyListing; +import org.apache.hadoop.tools.util.DistCpUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Stack; + +/** + * A custom {@link CopyListing} implementation capable of dynamically renaming + * the target paths according to a configured set of values. + * <p> + * Once https://issues.apache.org/jira/browse/HADOOP-16147 is available, this + * class can be significantly simplified. + * </p> + */ +public class CrunchRenameCopyListing extends SimpleCopyListing { + /** + * Comma-separated list of original-file:renamed-file path rename pairs. + */ + public static final String DISTCP_PATH_RENAMES = "crunch.distcp.path.renames"; + + private static final Logger LOG = LoggerFactory.getLogger(CrunchRenameCopyListing.class); + private final Map<String, String> pathRenames; + + private long totalPaths = 0; + private long totalBytesToCopy = 0; + + /** + * Protected constructor, to initialize configuration. + * + * @param configuration The input configuration, with which the source/target FileSystems may be accessed. + * @param credentials - Credentials object on which the FS delegation tokens are cached. If null + * delegation token caching is skipped + */ + protected CrunchRenameCopyListing(Configuration configuration, Credentials credentials) { Review comment: This constructor needs to be public, otherwise it can fail with the following exception (if HADOOP_CLASSPATH isn't set) ``` Caused by: java.io.IOException: Unable to instantiate org.apache.hadoop.tools.CrunchRenameCopyListing at org.apache.hadoop.tools.CopyListing.getCopyListing(CopyListing.java:284) at org.apache.hadoop.tools.CrunchDistCp.createInputFileListing(CrunchDistCp.java:430) at org.apache.hadoop.tools.CrunchDistCp.prepareFileListing(CrunchDistCp.java:94) at org.apache.hadoop.tools.CrunchDistCp.execute(CrunchDistCp.java:184) at org.apache.crunch.io.impl.FileTargetImpl.handleOutputsDistributedCopy(FileTargetImpl.java:278) ... 11 more Caused by: java.lang.IllegalAccessException: Class org.apache.hadoop.tools.CopyListing can not access a member of class org.apache.hadoop.tools.CrunchRenameCopyListing with modifiers "protected" at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102) at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296) at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288) at java.lang.reflect.Constructor.newInstance(Constructor.java:413) at org.apache.hadoop.tools.CopyListing.getCopyListing(CopyListing.java:282) ... 15 more ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services