Search in sources :

Example 16 with DistCpOptions

use of org.apache.hadoop.tools.DistCpOptions in project hadoop by apache.

the class TestOptionsParser method testAppendOption.

@Test
public void testAppendOption() {
    Configuration conf = new Configuration();
    Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.APPEND.getConfigLabel(), false));
    Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.SYNC_FOLDERS.getConfigLabel(), false));
    DistCpOptions options = OptionsParser.parse(new String[] { "-update", "-append", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
    options.appendToConf(conf);
    Assert.assertTrue(conf.getBoolean(DistCpOptionSwitch.APPEND.getConfigLabel(), false));
    Assert.assertTrue(conf.getBoolean(DistCpOptionSwitch.SYNC_FOLDERS.getConfigLabel(), false));
    // make sure -append is only valid when -update is specified
    try {
        OptionsParser.parse(new String[] { "-append", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
        fail("Append should fail if update option is not specified");
    } catch (IllegalArgumentException e) {
        GenericTestUtils.assertExceptionContains("Append is valid only with update options", e);
    }
    // make sure -append is invalid when skipCrc is specified
    try {
        OptionsParser.parse(new String[] { "-append", "-update", "-skipcrccheck", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
        fail("Append should fail if skipCrc option is specified");
    } catch (IllegalArgumentException e) {
        GenericTestUtils.assertExceptionContains("Append is disallowed when skipping CRC", e);
    }
}
Also used : DistCpOptions(org.apache.hadoop.tools.DistCpOptions) Configuration(org.apache.hadoop.conf.Configuration) Test(org.junit.Test)

Example 17 with DistCpOptions

use of org.apache.hadoop.tools.DistCpOptions in project hadoop by apache.

the class TestOptionsParser method testToString.

@Test
public void testToString() {
    DistCpOptions option = new DistCpOptions(new Path("abc"), new Path("xyz"));
    String val = "DistCpOptions{atomicCommit=false, syncFolder=false, " + "deleteMissing=false, ignoreFailures=false, overwrite=false, " + "append=false, useDiff=false, useRdiff=false, " + "fromSnapshot=null, toSnapshot=null, " + "skipCRC=false, blocking=true, numListstatusThreads=0, maxMaps=20, " + "mapBandwidth=0.0, " + "copyStrategy='uniformsize', preserveStatus=[], " + "preserveRawXattrs=false, atomicWorkPath=null, logPath=null, " + "sourceFileListing=abc, sourcePaths=null, targetPath=xyz, " + "targetPathExists=true, filtersFile='null'}";
    String optionString = option.toString();
    Assert.assertEquals(val, optionString);
    Assert.assertNotSame(DistCpOptionSwitch.ATOMIC_COMMIT.toString(), DistCpOptionSwitch.ATOMIC_COMMIT.name());
}
Also used : Path(org.apache.hadoop.fs.Path) DistCpOptions(org.apache.hadoop.tools.DistCpOptions) Test(org.junit.Test)

Example 18 with DistCpOptions

use of org.apache.hadoop.tools.DistCpOptions in project hadoop by apache.

the class TestOptionsParser method testParseWorkPath.

@Test
public void testParseWorkPath() {
    DistCpOptions options = OptionsParser.parse(new String[] { "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
    Assert.assertNull(options.getAtomicWorkPath());
    options = OptionsParser.parse(new String[] { "-atomic", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
    Assert.assertNull(options.getAtomicWorkPath());
    options = OptionsParser.parse(new String[] { "-atomic", "-tmp", "hdfs://localhost:9820/work", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
    Assert.assertEquals(options.getAtomicWorkPath(), new Path("hdfs://localhost:9820/work"));
    try {
        OptionsParser.parse(new String[] { "-tmp", "hdfs://localhost:9820/work", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
        Assert.fail("work path was allowed without -atomic switch");
    } catch (IllegalArgumentException ignore) {
    }
}
Also used : Path(org.apache.hadoop.fs.Path) DistCpOptions(org.apache.hadoop.tools.DistCpOptions) Test(org.junit.Test)

Example 19 with DistCpOptions

use of org.apache.hadoop.tools.DistCpOptions in project hadoop by apache.

the class TestOptionsParser method testParsebandwidth.

@Test
public void testParsebandwidth() {
    DistCpOptions options = OptionsParser.parse(new String[] { "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
    Assert.assertEquals(options.getMapBandwidth(), 0, DELTA);
    options = OptionsParser.parse(new String[] { "-bandwidth", "11.2", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
    Assert.assertEquals(options.getMapBandwidth(), 11.2, DELTA);
}
Also used : DistCpOptions(org.apache.hadoop.tools.DistCpOptions) Test(org.junit.Test)

Example 20 with DistCpOptions

use of org.apache.hadoop.tools.DistCpOptions in project hive by apache.

the class Hadoop23Shims method runDistCp.

@Override
public boolean runDistCp(List<Path> srcPaths, Path dst, Configuration conf) throws IOException {
    DistCpOptions options = new DistCpOptions.Builder(srcPaths, dst).withSyncFolder(true).withCRC(true).preserve(FileAttribute.BLOCKSIZE).build();
    // Creates the command-line parameters for distcp
    List<String> params = constructDistCpParams(srcPaths, dst, conf);
    try {
        conf.setBoolean("mapred.mapper.new-api", true);
        DistCp distcp = new DistCp(conf, options);
        // added by HADOOP-10459
        if (distcp.run(params.toArray(new String[0])) == 0) {
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        throw new IOException("Cannot execute DistCp process: " + e, e);
    } finally {
        conf.setBoolean("mapred.mapper.new-api", false);
    }
}
Also used : DistCpOptions(org.apache.hadoop.tools.DistCpOptions) DistCp(org.apache.hadoop.tools.DistCp) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AccessControlException(java.security.AccessControlException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

DistCpOptions (org.apache.hadoop.tools.DistCpOptions)34 Test (org.junit.Test)22 Path (org.apache.hadoop.fs.Path)13 Configuration (org.apache.hadoop.conf.Configuration)10 IOException (java.io.IOException)6 FileSystem (org.apache.hadoop.fs.FileSystem)5 JobContextImpl (org.apache.hadoop.mapreduce.task.JobContextImpl)5 CopyListing (org.apache.hadoop.tools.CopyListing)4 DistCp (org.apache.hadoop.tools.DistCp)4 GlobbedCopyListing (org.apache.hadoop.tools.GlobbedCopyListing)4 FileNotFoundException (java.io.FileNotFoundException)3 ArrayList (java.util.ArrayList)3 Text (org.apache.hadoop.io.Text)3 CopyListingFileStatus (org.apache.hadoop.tools.CopyListingFileStatus)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 AccessControlException (java.security.AccessControlException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 StubContext (org.apache.hadoop.tools.StubContext)2 NoSuchElementException (java.util.NoSuchElementException)1