更新时间:2023-09-14 GMT+08:00
分享

访问OBS

功能简介

访问OBS过程为:

  1. 设置“fs.obs.access.key”和“fs.obs.secret.key”。
  2. 由此FileSystem实例可以读取、新增和删除各类资源。

不支持追加操作。

前提条件

对接OBS前需要提前在OBS服务中创建相关目录,并确保访问用户具有对应目录的访问操作权限。

代码样例

如下是实例化FileSystem的代码片段,详细代码请参考com.huawei.bigdata.hdfs.examples中的HdfsMain类。

/**
   * 
   * Add configuration file if the application run on the linux ,then need make
   * the path of the core-site.xml and hdfs-site.xml to in the linux client file
   * 
   */
  private void confLoad() throws IOException {
    conf = new Configuration();
    // conf file
    conf.addResource(new Path(PATH_TO_HDFS_SITE_XML));
    conf.addResource(new Path(PATH_TO_CORE_SITE_XML));
    conf.set("fs.obs.access.key","*** Provide your Access Key ***");
    conf.set("fs.obs.secret.key","*** Provide your Secret Key ***");
    }

  /**
   * build HDFS instance
   */
  private void instanceBuild() throws IOException {
    // get filesystem
 // fSystem = FileSystem.get(conf);
    fSystem =  FileSystem.get(URI.create("obs://[BuketName]"),conf);
  }
分享:

    相关文档

    相关产品