From 3f70428eea0bd535bab39772dbe34482a14bfe79 Mon Sep 17 00:00:00 2001 From: vintmd <61688729+vintmd@users.noreply.github.com> Date: Thu, 27 Oct 2022 16:38:58 +0800 Subject: [PATCH] add reuse config and compatible implements (#83) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: alantong(佟明达) --- .../org/apache/hadoop/fs/CosFileSystem.java | 52 +++++++++++++++++++ .../hadoop/fs/CosNFSDataOutputStream.java | 2 +- .../org/apache/hadoop/fs/cosn/Constants.java | 3 ++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/hadoop/fs/CosFileSystem.java b/src/main/java/org/apache/hadoop/fs/CosFileSystem.java index 86909f0d..4107054e 100644 --- a/src/main/java/org/apache/hadoop/fs/CosFileSystem.java +++ b/src/main/java/org/apache/hadoop/fs/CosFileSystem.java @@ -388,6 +388,39 @@ public Token getDelegationToken(String renewer) throws IOException { return super.getDelegationToken(renewer); } + // some other implements of ofs, for now only support + // for posix bucket. contain the getContentSummary, setOwner,setPermission,setTimes + @Override + public ContentSummary getContentSummary(Path f) throws IOException { + LOG.debug("get content summary: {}.", f); + checkInitialized(); + return this.actualImplFS.getContentSummary(f); + } + + @Override + public void setOwner(Path p, String userName, String groupName) throws IOException { + LOG.debug("set owner, path: {}, userName: {}, groupName: {}",p, userName, groupName); + checkInitialized(); + checkPermission(p, RangerAccessType.WRITE); + this.actualImplFS.setOwner(p, userName, groupName); + } + + @Override + public void setPermission(Path p, FsPermission permission) throws IOException { + LOG.debug("set permission, path :{}", p); + checkInitialized(); + checkPermission(p, RangerAccessType.WRITE); + this.actualImplFS.setPermission(p, permission); + } + + @Override + public void setTimes(Path p, long mtime, long atime) throws IOException { + LOG.debug("set times, path :{}, mtime: {}, atime: {}", p, mtime, atime); + checkInitialized(); + checkPermission(p, RangerAccessType.WRITE); + this.actualImplFS.setTimes(p, mtime, atime); + } + public NativeFileSystemStore getStore() { return this.nativeStore; } @@ -425,12 +458,31 @@ private void passThroughRangerConfig() { // exclude the ofs original config, filter the ofs config with COSN_CONFIG_TRANSFER_PREFIX private void transferOfsConfig() { + // 0. re-use the same configuration + String appidStr = this.getConf().get(CosNConfigKeys.COSN_APPID_KEY); + if (null != appidStr && !appidStr.isEmpty()) { + String trsfKey = Constants.COSN_CONFIG_TRANSFER_PREFIX. + concat(Constants.COSN_POSIX_BUCKET_APPID_CONFIG); + this.getConf().set(trsfKey, appidStr); + } + + String regionStr = this.getConf().get(CosNConfigKeys.COSN_REGION_KEY); + if (null == regionStr) { + regionStr = this.getConf().get(CosNConfigKeys.COSN_REGION_PREV_KEY); + } + if (null != regionStr && !regionStr.isEmpty()) { + String trsfKey = Constants.COSN_CONFIG_TRANSFER_PREFIX. + concat(Constants.COSN_POSIX_BUCKET_REGION_CONFIG); + this.getConf().set(trsfKey, regionStr); + } + // 1. list to get transfer prefix ofs config Map tmpConf = new HashMap<>(); for (Map.Entry entry : this.getConf()) { if (entry.getKey().startsWith(Constants.COSN_OFS_CONFIG_PREFIX)) { this.getConf().unset(entry.getKey()); } + if (entry.getKey().startsWith(Constants.COSN_CONFIG_TRANSFER_PREFIX)) { int pos = Constants.COSN_CONFIG_TRANSFER_PREFIX.length(); String subConfigKey = entry.getKey().substring(pos); diff --git a/src/main/java/org/apache/hadoop/fs/CosNFSDataOutputStream.java b/src/main/java/org/apache/hadoop/fs/CosNFSDataOutputStream.java index 6ac575f7..e07a9518 100644 --- a/src/main/java/org/apache/hadoop/fs/CosNFSDataOutputStream.java +++ b/src/main/java/org/apache/hadoop/fs/CosNFSDataOutputStream.java @@ -510,7 +510,7 @@ public PartETag call() throws Exception { currentThread.setContextClassLoader(this.getClass().getClassLoader()); try { - LOG.info("Start to upload the part: {}", uploadPart); + LOG.debug("Start to upload the part: {}", uploadPart); PartETag partETag = (nativeStore).uploadPart( new BufferInputStream(uploadPart.getCosNByteBuffer()), this.localKey, diff --git a/src/main/java/org/apache/hadoop/fs/cosn/Constants.java b/src/main/java/org/apache/hadoop/fs/cosn/Constants.java index 36252c69..a514ac4d 100644 --- a/src/main/java/org/apache/hadoop/fs/cosn/Constants.java +++ b/src/main/java/org/apache/hadoop/fs/cosn/Constants.java @@ -42,4 +42,7 @@ private Constants() { public static final String COSN_POSIX_BUCKET_RANGER_POLICY_URL = "fs.ofs.cosn.ranger.policy.url"; public static final String COSN_POSIX_BUCKET_RANGER_AUTH_JAR_MD5 = "fs.ofs.cosn.ranger.auth.jar.md5"; public static final String COSN_POSIX_BUCKCET_OFS_RANGER_FLAG = "fs.ofs.ranger.enable.flag"; + + public static final String COSN_POSIX_BUCKET_APPID_CONFIG = "fs.ofs.user.appid"; + public static final String COSN_POSIX_BUCKET_REGION_CONFIG = "fs.ofs.bucket.region"; }