Search in sources :

Example 6 with DistCpOptions

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

the class TestCopyCommitter method testDeleteMissingFlatInterleavedFiles.

@Test
public void testDeleteMissingFlatInterleavedFiles() {
    TaskAttemptContext taskAttemptContext = getTaskAttemptContext(config);
    JobContext jobContext = new JobContextImpl(taskAttemptContext.getConfiguration(), taskAttemptContext.getTaskAttemptID().getJobID());
    Configuration conf = jobContext.getConfiguration();
    String sourceBase;
    String targetBase;
    FileSystem fs = null;
    try {
        OutputCommitter committer = new CopyCommitter(null, taskAttemptContext);
        fs = FileSystem.get(conf);
        sourceBase = "/tmp1/" + String.valueOf(rand.nextLong());
        targetBase = "/tmp1/" + String.valueOf(rand.nextLong());
        TestDistCpUtils.createFile(fs, sourceBase + "/1");
        TestDistCpUtils.createFile(fs, sourceBase + "/3");
        TestDistCpUtils.createFile(fs, sourceBase + "/4");
        TestDistCpUtils.createFile(fs, sourceBase + "/5");
        TestDistCpUtils.createFile(fs, sourceBase + "/7");
        TestDistCpUtils.createFile(fs, sourceBase + "/8");
        TestDistCpUtils.createFile(fs, sourceBase + "/9");
        TestDistCpUtils.createFile(fs, targetBase + "/2");
        TestDistCpUtils.createFile(fs, targetBase + "/4");
        TestDistCpUtils.createFile(fs, targetBase + "/5");
        TestDistCpUtils.createFile(fs, targetBase + "/7");
        TestDistCpUtils.createFile(fs, targetBase + "/9");
        TestDistCpUtils.createFile(fs, targetBase + "/A");
        DistCpOptions options = new DistCpOptions(Arrays.asList(new Path(sourceBase)), new Path("/out"));
        options.setSyncFolder(true);
        options.setDeleteMissing(true);
        options.appendToConf(conf);
        CopyListing listing = new GlobbedCopyListing(conf, CREDENTIALS);
        Path listingFile = new Path("/tmp1/" + String.valueOf(rand.nextLong()));
        listing.buildListing(listingFile, options);
        conf.set(DistCpConstants.CONF_LABEL_TARGET_WORK_PATH, targetBase);
        conf.set(DistCpConstants.CONF_LABEL_TARGET_FINAL_PATH, targetBase);
        committer.commitJob(jobContext);
        if (!TestDistCpUtils.checkIfFoldersAreInSync(fs, targetBase, sourceBase)) {
            Assert.fail("Source and target folders are not in sync");
        }
        Assert.assertEquals(fs.listStatus(new Path(targetBase)).length, 4);
        //Test for idempotent commit
        committer.commitJob(jobContext);
        if (!TestDistCpUtils.checkIfFoldersAreInSync(fs, targetBase, sourceBase)) {
            Assert.fail("Source and target folders are not in sync");
        }
        Assert.assertEquals(fs.listStatus(new Path(targetBase)).length, 4);
    } catch (IOException e) {
        LOG.error("Exception encountered while testing for delete missing", e);
        Assert.fail("Delete missing failure");
    } finally {
        TestDistCpUtils.delete(fs, "/tmp1");
        conf.set(DistCpConstants.CONF_LABEL_DELETE_MISSING, "false");
    }
}
Also used : Path(org.apache.hadoop.fs.Path) JobContextImpl(org.apache.hadoop.mapreduce.task.JobContextImpl) Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException) CopyListing(org.apache.hadoop.tools.CopyListing) GlobbedCopyListing(org.apache.hadoop.tools.GlobbedCopyListing) DistCpOptions(org.apache.hadoop.tools.DistCpOptions) FileSystem(org.apache.hadoop.fs.FileSystem) GlobbedCopyListing(org.apache.hadoop.tools.GlobbedCopyListing)

Example 7 with DistCpOptions

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

the class TestOptionsParser method testParseSkipCRC.

@Test
public void testParseSkipCRC() {
    DistCpOptions options = OptionsParser.parse(new String[] { "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
    Assert.assertFalse(options.shouldSkipCRC());
    options = OptionsParser.parse(new String[] { "-update", "-skipcrccheck", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
    Assert.assertTrue(options.shouldSyncFolder());
    Assert.assertTrue(options.shouldSkipCRC());
}
Also used : DistCpOptions(org.apache.hadoop.tools.DistCpOptions) Test(org.junit.Test)

Example 8 with DistCpOptions

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

the class TestOptionsParser method testSnapshotDiffOption.

// Test -diff or -rdiff
private void testSnapshotDiffOption(boolean isDiff) {
    final String optionStr = isDiff ? "-diff" : "-rdiff";
    final String optionLabel = isDiff ? DistCpOptionSwitch.DIFF.getConfigLabel() : DistCpOptionSwitch.RDIFF.getConfigLabel();
    Configuration conf = new Configuration();
    Assert.assertFalse(conf.getBoolean(optionLabel, false));
    DistCpOptions options = OptionsParser.parse(new String[] { "-update", optionStr, "s1", "s2", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
    options.appendToConf(conf);
    Assert.assertTrue(conf.getBoolean(optionLabel, false));
    Assert.assertTrue(isDiff ? options.shouldUseDiff() : options.shouldUseRdiff());
    Assert.assertEquals("s1", options.getFromSnapshot());
    Assert.assertEquals("s2", options.getToSnapshot());
    options = OptionsParser.parse(new String[] { optionStr, "s1", ".", "-update", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
    options.appendToConf(conf);
    Assert.assertTrue(conf.getBoolean(optionLabel, false));
    Assert.assertTrue(isDiff ? options.shouldUseDiff() : options.shouldUseRdiff());
    Assert.assertEquals("s1", options.getFromSnapshot());
    Assert.assertEquals(".", options.getToSnapshot());
    // -diff/-rdiff requires two option values
    try {
        OptionsParser.parse(new String[] { optionStr, "s1", "-update", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
        fail(optionStr + " should fail with only one snapshot name");
    } catch (IllegalArgumentException e) {
        GenericTestUtils.assertExceptionContains("Must provide both the starting and ending snapshot names", e);
    }
    // make sure -diff/-rdiff is only valid when -update is specified
    try {
        OptionsParser.parse(new String[] { optionStr, "s1", "s2", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
        fail(optionStr + " should fail if -update option is not specified");
    } catch (IllegalArgumentException e) {
        GenericTestUtils.assertExceptionContains("-diff/-rdiff is valid only with -update option", e);
    }
    try {
        options = OptionsParser.parse(new String[] { optionStr, "s1", "s2", "-update", "-delete", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
        assertFalse("-delete should be ignored when " + optionStr + " is specified", options.shouldDeleteMissing());
    } catch (IllegalArgumentException e) {
        fail("Got unexpected IllegalArgumentException: " + e.getMessage());
    }
    try {
        options = OptionsParser.parse(new String[] { optionStr, "s1", "s2", "-delete", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
        fail(optionStr + " should fail if -update option is not specified");
    } catch (IllegalArgumentException e) {
        assertFalse("-delete should be ignored when -diff is specified", options.shouldDeleteMissing());
        GenericTestUtils.assertExceptionContains("-diff/-rdiff is valid only with -update option", e);
    }
    try {
        OptionsParser.parse(new String[] { optionStr, "s1", "s2", "-delete", "-overwrite", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
        fail(optionStr + " should fail if -update option is not specified");
    } catch (IllegalArgumentException e) {
        GenericTestUtils.assertExceptionContains("-diff/-rdiff is valid only with -update option", e);
    }
    final String optionStrOther = isDiff ? "-rdiff" : "-diff";
    try {
        OptionsParser.parse(new String[] { optionStr, "s1", "s2", optionStrOther, "s2", "s1", "-update", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
        fail(optionStr + " should fail if " + optionStrOther + " is also specified");
    } catch (IllegalArgumentException e) {
        GenericTestUtils.assertExceptionContains("-diff and -rdiff are mutually exclusive", e);
    }
}
Also used : DistCpOptions(org.apache.hadoop.tools.DistCpOptions) Configuration(org.apache.hadoop.conf.Configuration)

Example 9 with DistCpOptions

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

the class TestOptionsParser method testParseDeleteMissing.

@Test
public void testParseDeleteMissing() {
    DistCpOptions options = OptionsParser.parse(new String[] { "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
    Assert.assertFalse(options.shouldDeleteMissing());
    options = OptionsParser.parse(new String[] { "-update", "-delete", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
    Assert.assertTrue(options.shouldSyncFolder());
    Assert.assertTrue(options.shouldDeleteMissing());
    options = OptionsParser.parse(new String[] { "-overwrite", "-delete", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
    Assert.assertTrue(options.shouldOverwrite());
    Assert.assertTrue(options.shouldDeleteMissing());
    try {
        OptionsParser.parse(new String[] { "-atomic", "-delete", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
        Assert.fail("Atomic and delete folders were allowed");
    } catch (IllegalArgumentException ignore) {
    }
}
Also used : DistCpOptions(org.apache.hadoop.tools.DistCpOptions) Test(org.junit.Test)

Example 10 with DistCpOptions

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

the class TestOptionsParser method testSourceListing.

@Test
public void testSourceListing() {
    DistCpOptions options = OptionsParser.parse(new String[] { "-f", "hdfs://localhost:9820/source/first", "hdfs://localhost:9820/target/" });
    Assert.assertEquals(options.getSourceFileListing(), new Path("hdfs://localhost:9820/source/first"));
}
Also used : Path(org.apache.hadoop.fs.Path) DistCpOptions(org.apache.hadoop.tools.DistCpOptions) Test(org.junit.Test)

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