java 连接hdfs高可用报错

AbstractMethodError: org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider.getProxy

解决 1 查看是否版本 不一致
解决 2 查看jar 包冲突 用 maven helper 插件搜索 hdfs common 等看看是否有冲突 一般处于都是这两个原因

package com.umetrap.domp.dao;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import lombok.extern.slf4j.Slf4j;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.ContentSummary;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider;

@Slf4j
public class HDFSDao {

  public static void main(String[] args)
      throws URISyntaxException, IOException, InterruptedException {
    FileSystem fs=null;

    try {
      Configuration conf = new Configuration();
 //这里 的配置参考hadoop官网然后 根hdfs 人员沟通填写 主要是两个主节点的 ip和端口 
      conf.set("fs.defaultFS", "hdfs://xxcluster");
      conf.set("dfs.nameservices", "xxcluster");
      conf.set("dfs.ha.namenodes.xxcluster", "namenode197,namenode200");
      conf.set("dfs.namenode.rpc-address.umecdhcluster.namenode197", "IP:port namenode节点");
      conf.set("dfs.namenode.rpc-address.umecdhcluster.namenode200", "IP:port namenode节点");
      conf.set("dfs.client.failover.proxy.provider.xxcluster", "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider");

      fs = FileSystem.get(new URI("hdfs://xxcluster"), conf, "hdfs");
    } catch (Exception e) {
      log.error("createFileSystem", e);
    }
    ContentSummary contentSummary = fs.getContentSummary(
        new Path("/user"));
    long spaceConsumed = contentSummary.getSpaceConsumed();
    long length = contentSummary.getLength();
    long fileCount = contentSummary.getFileCount();
    System.out.println(spaceConsumed+"*********"+length+"******"+fileCount);
  }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值