Java将数据从HDFS转移到S3

4
我想在Java中将文件从HDFS传输到S3。一些文件可能很大,因此我不想在上传到S3之前先将文件下载到本地。有没有办法在Java中实现这一点?
以下是我当前拥有的代码片段(上传本地文件到S3)。我不能真正使用它,因为使用File对象意味着我必须将其保存在我的硬盘驱动器上。
File f = new File("/home/myuser/test");

TransferManager transferManager  = new TransferManager(credentials);
MultipleFileUpload upload = transferManager.uploadDirectory("mybucket","test_folder",f,true);

谢谢


哪个版本的Hadoop? 2.x(至少)支持将S3作为文件系统,因此您可以从HDFS打开流并将其写入S3。开始的地方应该是查看'hadoop fs copy'的代码。 - kdgregory
我不能使用这个实用程序(或者至少我不知道如何使用)。我需要一个桶和钥匙。 - Serban Stoenescu
1个回答

3

我解决了上传部分的问题。

AWSCredentials credentials = new BasicAWSCredentials(
            "whatever",
            "whatever");

    File f = new File("/home/myuser/test");

    TransferManager transferManager  = new TransferManager(credentials);

    //+upload from HDFS to S3
    Configuration conf = new Configuration();
    // set the hadoop config files
    conf.addResource(new Path("/etc/hadoop/conf/core-site.xml"));
    conf.addResource(new Path("/etc/hadoop/conf/hdfs-site.xml"));

    Path path = new Path("hdfs://my_ip_address/user/ubuntu/test/test.txt");
    FileSystem fs = path.getFileSystem(conf);
    FSDataInputStream inputStream = fs.open(path);
    ObjectMetadata objectMetadata =  new ObjectMetadata();
    Upload upload = transferManager.upload("xpatterns-deployment-ubuntu", "test_cu_jmen3", inputStream, objectMetadata);
    //-upload from HDFS to S3

    try {
        upload.waitForCompletion();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

有没有关于如何进行类似下载的想法?我在TransferManager中没有找到可以使用上述代码中类似流的download()方法。

有没有类似的方法可以上传整个文件夹? - CodeHunter

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接