MAPREDUCE服务 MRS-HDFS访问OBS:代码样例

时间:2024-06-19 14:14:18

代码样例

如下是实例化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);
  }
support.huaweicloud.com/devg-mrs/mrs_06_0133.html