Search in sources :

Example 6 with MD5MD5CRC32FileChecksum

use of org.apache.hadoop.fs.MD5MD5CRC32FileChecksum in project kylo by Teradata.

the class ComputeHDFSChecksumsTest method testMultipleFilesWithDirectoryDefined.

@Test
public void testMultipleFilesWithDirectoryDefined() throws Exception {
    String fileName = "000000_0";
    String fileName2 = "000000_1";
    String fileName3 = "000000_2";
    String directory = "/dropzone";
    Mockito.when(fileSystem.getFileChecksum(any(Path.class))).thenReturn(new MD5MD5CRC32FileChecksum(0, 512, new MD5Hash("112233445566778899aabbccddeeff00"))).thenReturn(new MD5MD5CRC32FileChecksum(0, 512, new MD5Hash("112233445566778899aabbccddeeff01"))).thenReturn(new MD5MD5CRC32FileChecksum(0, 512, new MD5Hash("112233445566778899aabbccddeeff02")));
    runner.setProperty(ComputeHDFSChecksums.DIRECTORY, directory);
    runner.setProperty(ComputeHDFSChecksums.FAIL_IF_INCORRECT_CHECKSUM, "True");
    runner.setProperty(ComputeHDFSChecksums.FILES, String.format("[" + fileEntry + "," + fileEntry + "," + fileEntry + "]", fileName, "AAAAAAAAAAAAAAIAESIzRFVmd4iZqrvM3e7/AAAAAAA=", fileName2, "AAAAAAAAAAAAAAIAESIzRFVmd4iZqrvM3e7/AQAAAAA=", fileName3, "AAAAAAAAAAAAAAIAESIzRFVmd4iZqrvM3e7/AgAAAAA="));
    runner.enqueue(new byte[0]);
    runner.run();
    // Check relationships
    Assert.assertEquals(0, runner.getFlowFilesForRelationship(ComputeHDFSChecksums.REL_FAILURE).size());
    Assert.assertEquals(1, runner.getFlowFilesForRelationship(ComputeHDFSChecksums.REL_SUCCESS).size());
    // Check file system calls
    InOrder inOrder = Mockito.inOrder(fileSystem);
    inOrder.verify(fileSystem).getFileChecksum(new Path(directory, fileName));
    inOrder.verify(fileSystem).getFileChecksum(new Path(directory, fileName2));
    inOrder.verify(fileSystem).getFileChecksum(new Path(directory, fileName3));
    inOrder.verifyNoMoreInteractions();
}
Also used : Path(org.apache.hadoop.fs.Path) MD5MD5CRC32FileChecksum(org.apache.hadoop.fs.MD5MD5CRC32FileChecksum) InOrder(org.mockito.InOrder) MD5Hash(org.apache.hadoop.io.MD5Hash) Test(org.junit.Test)

Example 7 with MD5MD5CRC32FileChecksum

use of org.apache.hadoop.fs.MD5MD5CRC32FileChecksum in project hadoop by apache.

the class WebHdfsFileSystem method getFileChecksum.

@Override
public MD5MD5CRC32FileChecksum getFileChecksum(final Path p) throws IOException {
    statistics.incrementReadOps(1);
    storageStatistics.incrementOpCounter(OpType.GET_FILE_CHECKSUM);
    final HttpOpParam.Op op = GetOpParam.Op.GETFILECHECKSUM;
    return new FsPathResponseRunner<MD5MD5CRC32FileChecksum>(op, p) {

        @Override
        MD5MD5CRC32FileChecksum decodeResponse(Map<?, ?> json) throws IOException {
            return JsonUtilClient.toMD5MD5CRC32FileChecksum(json);
        }
    }.run();
}
Also used : MD5MD5CRC32FileChecksum(org.apache.hadoop.fs.MD5MD5CRC32FileChecksum) Op(org.apache.hadoop.hdfs.web.resources.HttpOpParam.Op) IOException(java.io.IOException)

Example 8 with MD5MD5CRC32FileChecksum

use of org.apache.hadoop.fs.MD5MD5CRC32FileChecksum in project kylo by Teradata.

the class ComputeHDFSChecksumsTest method testSingleFileInListFailOnWrongChecksum.

@Test
public void testSingleFileInListFailOnWrongChecksum() throws Exception {
    String fileName = "000000_0";
    Mockito.doReturn(new MD5MD5CRC32FileChecksum(0, 512, new MD5Hash("112233445566778899aabbccddeeff00"))).when(fileSystem).getFileChecksum(any(Path.class));
    runner.setProperty(ComputeHDFSChecksums.FAIL_IF_INCORRECT_CHECKSUM, "True");
    runner.setProperty(ComputeHDFSChecksums.FILES, String.format("[" + fileEntry + "]", fileName, "AAACAAAAAAAAAAAArRnBpxcZ9ze14XqfLMB4yA=="));
    runner.enqueue(new byte[0]);
    runner.run();
    // Check relationships
    Assert.assertEquals(1, runner.getFlowFilesForRelationship(ComputeHDFSChecksums.REL_FAILURE).size());
    Assert.assertEquals(0, runner.getFlowFilesForRelationship(ComputeHDFSChecksums.REL_SUCCESS).size());
    // Check file system calls
    verifyGetFileChecksumCall(fileName);
}
Also used : Path(org.apache.hadoop.fs.Path) MD5MD5CRC32FileChecksum(org.apache.hadoop.fs.MD5MD5CRC32FileChecksum) MD5Hash(org.apache.hadoop.io.MD5Hash) Test(org.junit.Test)

Example 9 with MD5MD5CRC32FileChecksum

use of org.apache.hadoop.fs.MD5MD5CRC32FileChecksum in project kylo by Teradata.

the class ComputeHDFSChecksumsTest method testMultipleFilesFailOnSingleWrongChecksum.

@Test
public void testMultipleFilesFailOnSingleWrongChecksum() throws Exception {
    String fileName = "000000_0";
    String fileName2 = "000000_1";
    String fileName3 = "000000_2";
    Mockito.when(fileSystem.getFileChecksum(any(Path.class))).thenReturn(new MD5MD5CRC32FileChecksum(0, 512, new MD5Hash("112233445566778899aabbccddeeff00"))).thenReturn(new MD5MD5CRC32FileChecksum(0, 512, new MD5Hash("112233445566778899aabbccddeeff01"))).thenReturn(new MD5MD5CRC32FileChecksum(0, 512, new MD5Hash("112233445566778899aabbccddeeff02")));
    runner.setProperty(ComputeHDFSChecksums.FAIL_IF_INCORRECT_CHECKSUM, "True");
    runner.setProperty(ComputeHDFSChecksums.FILES, String.format("[" + fileEntry + "," + fileEntry + "," + fileEntry + "]", fileName, "AAAAAAAAAAAAAAIAESIzRFVmd4iZqrvM3e7/AAAAAAA=", fileName2, "AAAAAAAAAAAAAAIAESIzRFVmd4iZqrvM3e7/AAAAAAA=", fileName3, "AAAAAAAAAAAAAAIAESIzRFVmd4iZqrvM3e7/AgAAAAA="));
    runner.enqueue(new byte[0]);
    runner.run();
    // Check relationships
    Assert.assertEquals(1, runner.getFlowFilesForRelationship(ComputeHDFSChecksums.REL_FAILURE).size());
    Assert.assertEquals(0, runner.getFlowFilesForRelationship(ComputeHDFSChecksums.REL_SUCCESS).size());
    // Check file system calls
    InOrder inOrder = Mockito.inOrder(fileSystem);
    inOrder.verify(fileSystem).getFileChecksum(new Path(fileName));
    inOrder.verify(fileSystem).getFileChecksum(new Path(fileName2));
    inOrder.verifyNoMoreInteractions();
}
Also used : Path(org.apache.hadoop.fs.Path) MD5MD5CRC32FileChecksum(org.apache.hadoop.fs.MD5MD5CRC32FileChecksum) InOrder(org.mockito.InOrder) MD5Hash(org.apache.hadoop.io.MD5Hash) Test(org.junit.Test)

Example 10 with MD5MD5CRC32FileChecksum

use of org.apache.hadoop.fs.MD5MD5CRC32FileChecksum in project SSM by Intel-bigdata.

the class SmartDFSClient method getFileChecksum.

@Override
public MD5MD5CRC32FileChecksum getFileChecksum(String src, long length) throws IOException {
    MD5MD5CRC32FileChecksum ret = super.getFileChecksum(src, length);
    if (ret.getChecksumOpt().getBytesPerChecksum() == 0) {
        FileState fileState = getFileState(src);
        if (fileState instanceof CompactFileState) {
            try {
                // Get original checksum for small file.
                byte[] bytes = getXAttr(src, SmartConstants.SMART_FILE_CHECKSUM_XATTR_NAME);
                ret = new MD5MD5CRC32FileChecksum();
                ret.readFields(new DataInputStream(new ByteArrayInputStream(bytes)));
            } catch (IOException e) {
                throw new IOException("Failed to get checksum for SSM Small File: " + e.getMessage());
            }
        }
    }
    return ret;
}
Also used : NormalFileState(org.smartdata.model.NormalFileState) CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) MD5MD5CRC32FileChecksum(org.apache.hadoop.fs.MD5MD5CRC32FileChecksum) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) CompactFileState(org.smartdata.model.CompactFileState)

Aggregations

MD5MD5CRC32FileChecksum (org.apache.hadoop.fs.MD5MD5CRC32FileChecksum)11 Path (org.apache.hadoop.fs.Path)7 Test (org.junit.Test)6 MD5Hash (org.apache.hadoop.io.MD5Hash)5 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 InOrder (org.mockito.InOrder)2 Gson (com.google.gson.Gson)1 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 Map (java.util.Map)1 Configuration (org.apache.hadoop.conf.Configuration)1 CreateFlag (org.apache.hadoop.fs.CreateFlag)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 MD5MD5CRC32CastagnoliFileChecksum (org.apache.hadoop.fs.MD5MD5CRC32CastagnoliFileChecksum)1 MD5MD5CRC32GzipFileChecksum (org.apache.hadoop.fs.MD5MD5CRC32GzipFileChecksum)1 ChecksumOpt (org.apache.hadoop.fs.Options.ChecksumOpt)1