DistCpOptions { public void appendToConf(Configuration conf) { DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.ATOMIC_COMMIT, String.valueOf(atomicCommit)); DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.IGNORE_FAILURES, String.valueOf(ignoreFailures)); DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.SYNC_FOLDERS, String.valueOf(syncFolder)); DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.DELETE_MISSING, String.valueOf(deleteMissing)); DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.OVERWRITE, String.valueOf(overwrite)); DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.APPEND, String.valueOf(append)); DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.DIFF, String.valueOf(useDiff)); DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.RDIFF, String.valueOf(useRdiff)); DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.SKIP_CRC, String.valueOf(skipCRC)); if (mapBandwidth > 0) { DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.BANDWIDTH, String.valueOf(mapBandwidth)); } DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.PRESERVE_STATUS, DistCpUtils.packAttributes(preserveStatus)); if (filtersFile != null) { DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.FILTERS, filtersFile); } DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.BLOCKS_PER_CHUNK, String.valueOf(blocksPerChunk)); DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.COPY_BUFFER_SIZE, String.valueOf(copyBufferSize)); DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.VERBOSE_LOG, String.valueOf(verboseLog)); if (trackPath != null) { DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.TRACK_MISSING, String.valueOf(trackPath)); } if (numListstatusThreads > 0) { DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.NUM_LISTSTATUS_THREADS, Integer.toString(numListstatusThreads)); } DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.DIRECT_WRITE, String.valueOf(directWrite)); } private  DistCpOptions(Builder builder); Path getSourceFileListing(); List<Path> getSourcePaths(); Path getTargetPath(); boolean shouldAtomicCommit(); Path getAtomicWorkPath(); boolean shouldSyncFolder(); boolean shouldDeleteMissing(); boolean shouldIgnoreFailures(); boolean shouldOverwrite(); boolean shouldAppend(); boolean shouldSkipCRC(); boolean shouldBlock(); boolean shouldUseDiff(); boolean shouldUseRdiff(); boolean shouldUseSnapshotDiff(); String getFromSnapshot(); String getToSnapshot(); String getFiltersFile(); Path getLogPath(); String getCopyStrategy(); int getNumListstatusThreads(); int getMaxMaps(); float getMapBandwidth(); Set<FileAttribute> getPreserveAttributes(); boolean shouldPreserve(FileAttribute attribute); int getBlocksPerChunk(); int getCopyBufferSize(); boolean shouldVerboseLog(); Path getTrackPath(); boolean shouldDirectWrite(); void appendToConf(Configuration conf); @Override String toString(); static final int MAX_NUM_LISTSTATUS_THREADS; }
@Test public void testAppendToConf() { final int expectedBlocksPerChunk = 999; final String expectedValForEmptyConfigKey = "VALUE_OF_EMPTY_CONFIG_KEY"; DistCpOptions options = new DistCpOptions.Builder( Collections.singletonList( new Path("hdfs: new Path("hdfs: .withBlocksPerChunk(expectedBlocksPerChunk) .build(); Configuration config = new Configuration(); config.set("", expectedValForEmptyConfigKey); options.appendToConf(config); Assert.assertEquals(expectedBlocksPerChunk, config.getInt( DistCpOptionSwitch .BLOCKS_PER_CHUNK .getConfigLabel(), 0)); Assert.assertEquals( "Some DistCpOptionSwitch's config label is empty! " + "Pls ensure the config label is provided when apply to config, " + "otherwise it may not be fetched properly", expectedValForEmptyConfigKey, config.get("")); }