开发者社区> 问答> 正文

java.lang.IllegalArgumentException: Wrong FS: oss://id:key@testemr.oss-cn-hangzhou-internal.aliyuncs.com/output5, expected: hdfs://ip:9000

已解决

在使用E-Mapreduce产品时,出现如下问题:

java.lang.IllegalArgumentException: Wrong FS: oss://id:key@testemr.oss-cn-hangzhou-internal.aliyuncs.com/output5, expected: hdfs://ip:9000
    at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:645)
    at org.apache.hadoop.hdfs.DistributedFileSystem.getPathName(DistributedFileSystem.java:193)
    at org.apache.hadoop.hdfs.DistributedFileSystem.access$000(DistributedFileSystem.java:105)
    at org.apache.hadoop.hdfs.DistributedFileSystem$18.doCall(DistributedFileSystem.java:1118)
    at org.apache.hadoop.hdfs.DistributedFileSystem$18.doCall(DistributedFileSystem.java:1114)
    at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)
    at org.apache.hadoop.hdfs.DistributedFileSystem.getFileStatus(DistributedFileSystem.java:1114)
    at org.apache.hadoop.fs.FileSystem.exists(FileSystem.java:1400)
    at com.aliyun.emr.example.WordCount.main(WordCount.java:129)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)

代码为,出错的行为: if (fs.exists(outputPath)) {

   List<String> otherArgs = new ArrayList<String>();
        for (int i = 0; i < remainingArgs.length; ++i) {
            if ("-skip".equals(remainingArgs[i])) {
                job.addCacheFile(new Path(EMapReduceOSSUtil.buildOSSCompleteUri(remainingArgs[++i], conf)).toUri());
                job.getConfiguration().setBoolean("wordcount.skip.patterns", true);
            } else {
                otherArgs.add(remainingArgs[i]);
            }
        }
        Path outputPath = new Path(EMapReduceOSSUtil.buildOSSCompleteUri(otherArgs.get(1), conf));

        org.apache.hadoop.fs.FileSystem fs = org.apache.hadoop.fs.FileSystem.get(conf);
        if (fs.exists(outputPath)) {
            fs.delete(outputPath, true);
        }
        FileInputFormat.addInputPath(job, new Path(EMapReduceOSSUtil.buildOSSCompleteUri(otherArgs.get(0), conf)));
        FileOutputFormat.setOutputPath(job, new Path(EMapReduceOSSUtil.buildOSSCompleteUri(otherArgs.get(1), conf)));

        System.exit(job.waitForCompletion(true) ? 0 : 1);

展开
收起
封神 2016-05-27 17:31:38 5571 0
2 条回答
写回答
取消 提交回答
  • 专注在大数据分布式计算、数据库及存储领域,拥有13+年大数据引擎、数据仓库、宽表引擎、平台研发经验,6年云智能大数据产品技术一号位经验,10年技术团队管理经验;云智能技术架构/云布道师; 研发阿里历代的大数据技术产品包括ODPS、DLA、ADB,最近五年主导宽表引擎研发、DLA、ADB湖仓研发;
    采纳回答

    这个一般就是:访问 oss://id:key@testemr.oss-cn-hangzhou-internal.aliyuncs.com/output5 但是拿到了DistributedFileSystem

    看具体的代码:

            Path outputPath = new Path(EMapReduceOSSUtil.buildOSSCompleteUri(otherArgs.get(1), conf));
    
            org.apache.hadoop.fs.FileSystem fs = org.apache.hadoop.fs.FileSystem.get(conf);
            if (fs.exists(outputPath)) {
                fs.delete(outputPath, true);
            }

    因为 outputPath 为: oss://id:key@testemr.oss-cn-hangzhou-internal.aliyuncs.com/output5 实际 fs为:DistributedFileSystem 就会出现如上的问题。

    解决的办法应该写成下面的,用具体的路径拿到FileSystem

    FileSystem.get(conf); 改为 FileSystem.get(outputPath.toUri(), conf);

    
            Path outputPath = new Path(EMapReduceOSSUtil.buildOSSCompleteUri(otherArgs.get(1), conf));
    
            org.apache.hadoop.fs.FileSystem fs = org.apache.hadoop.fs.FileSystem.get(outputPath.toUri(), conf);
            if (fs.exists(outputPath)) {
                fs.delete(outputPath, true);
            }
    

    以前一般只有一个HDFS;现在除了有HDFS,还有OSS,还请大家注意。

    2019-07-17 19:18:27
    赞同 1 展开评论 打赏
  • 我调用sqoop从mysql往EMR的hive导数据出现这个问题,要怎么解决?

    2019-07-17 19:18:27
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
OSS运维进阶实战手册 立即下载
《OSS运维基础实战手册》 立即下载
OSS运维基础实战手册 立即下载