本文整理汇总了Java中org.apache.hadoop.tools.DistCpOptions类的典型用法代码示例。如果您正苦于以下问题:Java DistCpOptions类的具体用法?Java DistCpOptions怎么用?Java DistCpOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DistCpOptions类属于org.apache.hadoop.tools包,在下文中一共展示了DistCpOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doBuildListing
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
@Override
public void doBuildListing(Path pathToListFile, DistCpOptions options) throws IOException {
try (Writer writer = newWriter(pathToListFile)) {
Path sourceRootPath = getRootPath(getConf());
for (Path sourcePath : options.getSourcePaths()) {
FileSystem fileSystem = sourcePath.getFileSystem(getConf());
FileStatus directory = fileSystem.getFileStatus(sourcePath);
Map<String, CopyListingFileStatus> children = new FileStatusTreeTraverser(fileSystem)
.preOrderTraversal(directory)
.transform(new CopyListingFileStatusFunction(fileSystem, options))
.uniqueIndex(new RelativePathFunction(sourceRootPath));
for (Entry<String, CopyListingFileStatus> entry : children.entrySet()) {
LOG.debug("Adding '{}' with relative path '{}'", entry.getValue().getPath(), entry.getKey());
writer.append(new Text(entry.getKey()), entry.getValue());
writer.sync();
}
}
}
}
示例2: distCopy
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
public void distCopy(Path sourceFile, Path destFile) {
try {
Configuration conf = new Configuration();
DistCp distCp = new DistCp(conf, new DistCpOptions(sourceFile, destFile));
distCp.run(new String[] { sourceFile.toString(), destFile.toString() });
} catch (Exception e) {
log.error("Couldn't execute distCp from {} to {}", sourceFile.toString(), destFile.toString());
e.printStackTrace();
}
}
示例3: assertDefaultValues
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
private void assertDefaultValues(DistCpOptions distCpOptions) {
assertThat(distCpOptions, is(not(nullValue())));
assertThat(distCpOptions.preserveAttributes().hasNext(), is(false));
assertThat(distCpOptions.shouldPreserveRawXattrs(), is(false));
assertThat(distCpOptions.shouldAppend(), is(false));
assertThat(distCpOptions.shouldAtomicCommit(), is(false));
assertThat(distCpOptions.getAtomicWorkPath(), is(nullValue()));
assertThat(distCpOptions.shouldBlock(), is(true));
assertThat(distCpOptions.getCopyStrategy(), is(DistCpConstants.UNIFORMSIZE));
assertThat(distCpOptions.shouldDeleteMissing(), is(false));
assertThat(distCpOptions.shouldIgnoreFailures(), is(false));
assertThat(distCpOptions.getLogPath(), is(nullValue()));
assertThat(distCpOptions.getMapBandwidth(), is(DistCpConstants.DEFAULT_BANDWIDTH_MB));
assertThat(distCpOptions.getMaxMaps(), is(DistCpConstants.DEFAULT_MAPS));
assertThat(distCpOptions.shouldOverwrite(), is(false));
assertThat(distCpOptions.shouldSkipCRC(), is(false));
assertThat(distCpOptions.getSslConfigurationFile(), is(nullValue()));
assertThat(distCpOptions.shouldSyncFolder(), is(false));
assertThat(distCpOptions.getTargetPathExists(), is(true));
}
示例4: copyFileWithRetry
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
private void copyFileWithRetry(String description,
FileStatus sourceFileStatus, Path target, Context context,
FileAction action, EnumSet<DistCpOptions.FileAttribute> fileAttributes)
throws IOException {
long bytesCopied;
try {
bytesCopied = (Long) new RetriableFileCopyCommand(skipCrc, description,
action).execute(sourceFileStatus, target, context, fileAttributes);
} catch (Exception e) {
context.setStatus("Copy Failure: " + sourceFileStatus.getPath());
throw new IOException("File copy failed: " + sourceFileStatus.getPath() +
" --> " + target, e);
}
incrementCounter(context, Counter.BYTESEXPECTED, sourceFileStatus.getLen());
incrementCounter(context, Counter.BYTESCOPIED, bytesCopied);
incrementCounter(context, Counter.COPY, 1);
}
示例5: copyFileWithRetry
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
private void copyFileWithRetry(String description,
FileStatus sourceFileStatus, Path target, Context context,
FileAction action, EnumSet<DistCpOptions.FileAttribute> fileAttributes)
throws IOException {
long bytesCopied;
try {
bytesCopied = (Long) new RetriableFileCopyCommand(skipCrc, description,
action).execute(sourceFileStatus, target, context, fileAttributes);
} catch (Exception e) {
context.setStatus("Copy Failure: " + sourceFileStatus.getPath());
throw new IOException("File copy failed: " + sourceFileStatus.getPath() +
" --> " + target, e);
}
incrementCounter(context, Counter.BYTESEXPECTED, sourceFileStatus.getLen());
incrementCounter(context, Counter.BYTESCOPIED, bytesCopied);
incrementCounter(context, Counter.COPY, 1);
totalBytesCopied += bytesCopied;
}
示例6: copyFileWithRetry
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
private void copyFileWithRetry(String description, FileStatus sourceFileStatus,
Path target, Context context,
EnumSet<DistCpOptions.FileAttribute> fileAttributes) throws IOException {
long bytesCopied;
try {
bytesCopied = (Long)new RetriableFileCopyCommand(skipCrc, description)
.execute(sourceFileStatus, target, context, fileAttributes);
} catch (Exception e) {
context.setStatus("Copy Failure: " + sourceFileStatus.getPath());
throw new IOException("File copy failed: " + sourceFileStatus.getPath() +
" --> " + target, e);
}
incrementCounter(context, Counter.BYTESEXPECTED, sourceFileStatus.getLen());
incrementCounter(context, Counter.BYTESCOPIED, bytesCopied);
incrementCounter(context, Counter.COPY, 1);
}
示例7: getDistCp
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
@Override
protected DistCp getDistCp(Configuration conf, DistCpOptions options) {
assertEquals(Constants.MAPRED_MAP_MAX_ATTEMPTS,
Integer.parseInt(conf.get("mapred.map.max.attempts")));
assertEquals(Constants.CHECKSUM_BYTES,
Integer.parseInt(conf.get("io.bytes.per.checksum")));
long blockSizeExpected = blockSize;
if (blockSizeExpected % Constants.CHECKSUM_BYTES != 0) {
blockSizeExpected = (blockSize / Constants.CHECKSUM_BYTES + 1) * Constants.CHECKSUM_BYTES;
}
assertEquals(blockSizeExpected, Long.parseLong(conf.get("dfs.block.size")));
assertEquals(REPLICA_FACTOR, Integer.parseInt(conf.get("dfs.replication")));
assertEquals(sourceFiles, options.getSourcePaths());
assertTrue(options.shouldSkipCRC());
assertTrue(options.shouldSyncFolder());
assertTrue(options.getTargetPath().toString().startsWith("hdfs://" + NAME_NODE + HDFS_DIR));
if (numPartition == 1) {
assertTrue(options.getTargetPath().toString()
.endsWith(TerrapinUtil.formatPartitionName(0)));
}
return distCp;
}
示例8: getSourcePaths
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private List<Path> getSourcePaths(Field fieldInputOptions) throws IOException{
Object options;
try {
options = fieldInputOptions.get(this);
if (options instanceof DistCpOptions) {
return ((DistCpOptions) options).getSourcePaths();
} else {
// Hadoop 3
Class<?> classContext = Class.forName("org.apache.hadoop.tools.DistCpContext");
Method methodGetSourcePaths = classContext.getDeclaredMethod("getSourcePaths");
methodGetSourcePaths.setAccessible(true);
return (List<Path>) methodGetSourcePaths.invoke(options);
}
} catch (IllegalArgumentException | IllegalAccessException |
ClassNotFoundException | NoSuchMethodException |
SecurityException | InvocationTargetException e) {
throw new IOException(e);
}
}
示例9: testRunStarPattern
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
@Test
public void testRunStarPattern() throws Exception {
final URI uri = FileSystem.getLocal(new Configuration()).getUri();
final String pathString = uri.toString();
Path fileSystemPath = new Path(pathString);
Path source = new Path(fileSystemPath.toString() + "///tmp/source");
Path target = new Path(fileSystemPath.toString() + "///tmp/target");
Path listingPath = new Path(fileSystemPath.toString() + "///tmp/META/fileList.seq");
DistCpOptions options = new DistCpOptions(Arrays.asList(source), target);
Configuration configuration = new Configuration();
configuration.set("ivory.include.path", "*/3/*");
new FilteredCopyListing(configuration, CREDENTIALS).buildListing(listingPath, options);
verifyContents(listingPath, 3);
}
示例10: testRunQuestionPattern
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
@Test
public void testRunQuestionPattern() throws Exception {
final URI uri = FileSystem.getLocal(new Configuration()).getUri();
final String pathString = uri.toString();
Path fileSystemPath = new Path(pathString);
Path source = new Path(fileSystemPath.toString() + "///tmp/source");
Path target = new Path(fileSystemPath.toString() + "///tmp/target");
Path listingPath = new Path(fileSystemPath.toString() + "///tmp/META/fileList.seq");
DistCpOptions options = new DistCpOptions(Arrays.asList(source), target);
Configuration configuration = new Configuration();
configuration.set("ivory.include.path", "*/3/?");
new FilteredCopyListing(configuration, CREDENTIALS).buildListing(listingPath, options);
verifyContents(listingPath, 2);
}
示例11: testRunRangePattern
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
@Test
public void testRunRangePattern() throws Exception {
final URI uri = FileSystem.getLocal(new Configuration()).getUri();
final String pathString = uri.toString();
Path fileSystemPath = new Path(pathString);
Path source = new Path(fileSystemPath.toString() + "///tmp/source");
Path target = new Path(fileSystemPath.toString() + "///tmp/target");
Path listingPath = new Path(fileSystemPath.toString() + "///tmp/META/fileList.seq");
DistCpOptions options = new DistCpOptions(Arrays.asList(source), target);
Configuration configuration = new Configuration();
configuration.set("ivory.include.path", "*/3/[47]");
new FilteredCopyListing(configuration, CREDENTIALS).buildListing(listingPath, options);
verifyContents(listingPath, 2);
}
示例12: testRunSpecificPattern
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
@Test
public void testRunSpecificPattern() throws Exception {
final URI uri = FileSystem.getLocal(new Configuration()).getUri();
final String pathString = uri.toString();
Path fileSystemPath = new Path(pathString);
Path source = new Path(fileSystemPath.toString() + "///tmp/source");
Path target = new Path(fileSystemPath.toString() + "///tmp/target");
Path listingPath = new Path(fileSystemPath.toString() + "///tmp/META/fileList.seq");
DistCpOptions options = new DistCpOptions(Arrays.asList(source), target);
Configuration configuration = new Configuration();
configuration.set("ivory.include.path", "*/3/40");
new FilteredCopyListing(configuration, CREDENTIALS).buildListing(listingPath, options);
verifyContents(listingPath, 1);
}
示例13: testRunListPattern
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
@Test
public void testRunListPattern() throws Exception {
final URI uri = FileSystem.getLocal(new Configuration()).getUri();
final String pathString = uri.toString();
Path fileSystemPath = new Path(pathString);
Path source = new Path(fileSystemPath.toString() + "///tmp/source");
Path target = new Path(fileSystemPath.toString() + "///tmp/target");
Path listingPath = new Path(fileSystemPath.toString() + "///tmp/META/fileList.seq");
DistCpOptions options = new DistCpOptions(Arrays.asList(source), target);
Configuration configuration = new Configuration();
configuration.set("ivory.include.path", "*/3/{4,7}");
new FilteredCopyListing(configuration, CREDENTIALS).buildListing(listingPath, options);
verifyContents(listingPath, 2);
}
示例14: testArguments
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
@Test
public void testArguments() throws Exception {
/*
* <arg>-update</arg>
* <arg>-blocking</arg><arg>true</arg> <arg>-maxMaps</arg><arg>20</arg>
* <arg>-sourcePaths</arg><arg>${distcpSourcePaths}</arg>
* <arg>-targetPath</arg><arg>${distcpTargetPaths}</arg>
*/
FeedReplicator replicator = new FeedReplicator();
DistCpOptions options = replicator.getDistCpOptions(new String[] { "-update",
"-blocking", "true", "-maxMaps", "5", "-sourcePaths",
"hdfs://localhost:8020/tmp/", "-targetPath",
"hdfs://localhost1:8020/tmp/" });
List<Path> srcPaths = new ArrayList<Path>();
srcPaths.add(new Path("hdfs://localhost:8020/tmp/"));
Assert.assertEquals(options.getSourcePaths(), srcPaths);
Assert.assertEquals(options.getTargetPath(), new Path("hdfs://localhost1:8020/tmp/"));
}
示例15: testRunStarPattern
import org.apache.hadoop.tools.DistCpOptions; //导入依赖的package包/类
@Test
public void testRunStarPattern() throws Exception {
final URI uri = FileSystem.getLocal(new Configuration()).getUri();
final String pathString = uri.toString();
Path fileSystemPath = new Path(pathString);
Path source = new Path(fileSystemPath.toString() + "///tmp/source");
Path target = new Path(fileSystemPath.toString() + "///tmp/target");
Path listingPath = new Path(fileSystemPath.toString() + "///tmp/META/fileList.seq");
DistCpOptions options = new DistCpOptions(Arrays.asList(source), target);
Configuration configuration = new Configuration();
configuration.set("falcon.include.path", "*/3/*");
new FilteredCopyListing(configuration, CREDENTIALS).buildListing(listingPath, options);
verifyContents(listingPath, 3);
}