配置文件优先级问题

配置文件优先级问题

配置文件分为好多种,分别是服务端配置文件,服务端默认配置文件,代码配置文件,api 端配置文件

package hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class HDFSConfigurationTest {

    private FileSystem fileSystem;

    /**
     * 如歌我们不设置 {@code configuration} 也可以通过 hadoop 系统默认的读取配置文件的机制来实现配置
     * 它默认会读取 {@file hdfs-site.xml} 我们可以配置
     * <br>
     * 注意:
     *      JAVA 代码操作
     *        代码的优先级 > 配置文件的优先级 > 服务器端的配置文件(xxx-default.xml)优先级
     *        在这里服务器端配置文件(xxx-site.xml)是不起作用的只有在 hadoop shell 操作的时候服务器端配置文件(xxx-site.xml)才会起作用
     *      Hadoop Shell 操作
     *        服务器端配置文件(xxx-site.xml) > 服务器端默认配置文件(xxx-default.xml)
     */
    @Before
    public void init() throws IOException, URISyntaxException, InterruptedException {
        Configuration configuration = new Configuration();
        // configuration.set("dfs.replication", "6");
        fileSystem = FileSystem.get(new URI("hdfs://192.168.11.132:8020"), configuration, "xing");
    }

    /**
     * 类似于
     * <code>
     *     hdfs dfs -mkdir /replication
     *     hadoop fs -copyFromLocal url /replication
     *     或者
     *     hdfs dfs -copyFromLocal url /replication
     * </code>
     */
    @Test
    public void replication() throws Exception {
        String url = "D:\\code\\resources\\file\\replication.txt";
        boolean mkdirs = fileSystem.mkdirs(new Path("/replication"));
        if (mkdirs) {
            fileSystem.copyFromLocalFile(false, true, new Path(url), new Path("/replication"));
        }
    }

    @After
    public void after() throws IOException {
        if (fileSystem != null) fileSystem.close();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值