Updated on 2022-09-14 GMT+08:00

Accessing OBS

Function Description

The OBS access process is as follows:

  1. Set fs.obs.access.key and fs.obs.secret.key.
  2. Use the FileSystem instance to read, add, and delete various resources.

The appending operation is not supported.

Sample Code

The following provides code snippets for instantiating the FileSystem. For complete codes, see the HdfsMain class in com.huawei.bigdata.hdfs.examples.

/**
   * 
   * 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);
  }