Copilot commented on code in PR #11713:
URL: https://github.com/apache/gravitino/pull/11713#discussion_r3452861500


##########
api/src/main/java/org/apache/gravitino/credential/COSSecretKeyCredential.java:
##########
@@ -0,0 +1,120 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.gravitino.credential;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+
+/** Tencent Cloud COS secret key credential. */
+public class COSSecretKeyCredential implements Credential {
+
+  /** COS secret key credential type. */
+  public static final String COS_SECRET_KEY_CREDENTIAL_TYPE = "cos-secret-key";
+  /** The static access key ID (a.k.a. SecretId in Tencent Cloud) used to 
access COS data. */
+  public static final String GRAVITINO_COS_STATIC_ACCESS_KEY_ID = 
"cos-access-key-id";
+  /** The static secret access key (a.k.a. SecretKey in Tencent Cloud) used to 
access COS data. */
+  public static final String GRAVITINO_COS_STATIC_SECRET_ACCESS_KEY = 
"cos-secret-access-key";
+
+  private String accessKeyId;
+  private String secretAccessKey;
+
+  /**
+   * Constructs an instance of {@link COSSecretKeyCredential} with the static 
COS access key ID and
+   * secret access key.
+   *
+   * @param accessKeyId The COS static access key ID.
+   * @param secretAccessKey The COS static secret access key.
+   */
+  public COSSecretKeyCredential(String accessKeyId, String secretAccessKey) {
+    validate(accessKeyId, secretAccessKey, 0);
+    this.accessKeyId = accessKeyId;
+    this.secretAccessKey = secretAccessKey;
+  }
+
+  /**
+   * This is the constructor that is used by credential factory to create an 
instance of credential
+   * according to the credential information.
+   */
+  public COSSecretKeyCredential() {}
+
+  @Override
+  public String credentialType() {
+    return COS_SECRET_KEY_CREDENTIAL_TYPE;
+  }
+
+  @Override
+  public long expireTimeInMs() {
+    return 0;
+  }
+
+  @Override
+  public Map<String, String> credentialInfo() {
+    return (new ImmutableMap.Builder<String, String>())
+        .put(GRAVITINO_COS_STATIC_ACCESS_KEY_ID, accessKeyId)
+        .put(GRAVITINO_COS_STATIC_SECRET_ACCESS_KEY, secretAccessKey)
+        .build();
+  }
+
+  /**
+   * Initialize the credential with the credential information.
+   *
+   * <p>This method is invoked to deserialize the credential in client side.
+   *
+   * @param credentialInfo The credential information from {@link 
#credentialInfo}.
+   * @param expireTimeInMs The expire-time from {@link #expireTimeInMs()}.
+   */
+  @Override
+  public void initialize(Map<String, String> credentialInfo, long 
expireTimeInMs) {
+    String accessKeyId = 
credentialInfo.get(GRAVITINO_COS_STATIC_ACCESS_KEY_ID);
+    String secretAccessKey = 
credentialInfo.get(GRAVITINO_COS_STATIC_SECRET_ACCESS_KEY);
+    validate(accessKeyId, secretAccessKey, expireTimeInMs);
+    this.accessKeyId = accessKeyId;
+    this.secretAccessKey = secretAccessKey;
+  }
+
+  /**
+   * Get COS static access key ID.
+   *
+   * @return The COS access key ID.
+   */
+  public String accessKeyId() {
+    return accessKeyId;
+  }
+
+  /**
+   * Get COS static secret access key.
+   *
+   * @return The COS secret access key.
+   */
+  public String secretAccessKey() {
+    return secretAccessKey;
+  }
+
+  private void validate(String accessKeyId, String secretAccessKey, long 
expireTimeInMs) {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(accessKeyId), "COS access key Id should not 
empty");
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(secretAccessKey), "COS secret access key should 
not empty");

Review Comment:
   The validation error messages are grammatically incorrect ("should not 
empty") and use inconsistent capitalization ("Id"). These messages are 
user-facing via Preconditions and should be corrected for clarity.



##########
gradle/libs.versions.toml:
##########
@@ -45,6 +45,7 @@ hadoop3 = "3.3.6"
 hadoop3-gcs = "1.9.4-hadoop3"
 hadoop3-abs = "3.3.6"
 hadoop3-aliyun = "3.3.6"
+hadoop-cos = "3.3.0-8.3.23"

Review Comment:
   The project’s Hadoop dependency version is 3.3.6, but the selected 
hadoop-cos artifact version encodes Hadoop 3.3.0 ("3.3.0-8.3.23"). Please 
confirm binary compatibility with Hadoop 3.3.6 (and the other bundled Hadoop 
3.3.6 artifacts), or pick a hadoop-cos build that matches the repo’s Hadoop 
minor/patch level if available.



##########
docs/fileset-catalog.md:
##########
@@ -12,9 +12,10 @@ Fileset catalog is a fileset catalog that using Hadoop 
Compatible File System (H
 the storage location of the fileset. It supports the local filesystem and 
HDFS. Since
 0.7.0-incubating, Gravitino supports [S3](fileset-catalog-with-s3.md), 
[GCS](fileset-catalog-with-gcs.md),
 [OSS](fileset-catalog-with-oss.md) and [Azure Blob 
Storage](fileset-catalog-with-adls.md) through Fileset catalog.
+Since 1.3.0, Gravitino also supports [Tencent Cloud 
COS](fileset-catalog-with-cos.md).

Review Comment:
   The Fileset catalog doc says COS support is available since 1.3.0, but the 
COS-specific documentation and new config entries indicate this feature is 
introduced in 1.4.0. This inconsistency will confuse users and should be 
aligned to the actual release version.



##########
catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/integration/test/FilesetCOSCatalogIT.java:
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.catalog.fileset.integration.test;
+
+import static 
org.apache.gravitino.catalog.fileset.FilesetCatalogPropertiesMetadata.FILESYSTEM_PROVIDERS;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Map;
+import org.apache.gravitino.Catalog;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Schema;
+import org.apache.gravitino.file.Fileset;
+import org.apache.gravitino.integration.test.util.GravitinoITUtils;
+import org.apache.gravitino.storage.COSProperties;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIf;
+import org.junit.platform.commons.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Integration test for the fileset catalog backed by Tencent Cloud COS. It is 
disabled unless the
+ * required environment variables (COS_*) are present, mirroring the OSS / AWS 
counterparts.
+ */
+@EnabledIf(value = "cosIsConfigured", disabledReason = "Tencent Cloud COS is 
not configured.")
+public class FilesetCOSCatalogIT extends FilesetCatalogIT {
+  private static final Logger LOG = 
LoggerFactory.getLogger(FilesetCOSCatalogIT.class);
+
+  public static final String BUCKET_NAME = System.getenv("COS_BUCKET_NAME");
+  public static final String COS_ACCESS_KEY = 
System.getenv("COS_ACCESS_KEY_ID");
+  public static final String COS_SECRET_KEY = 
System.getenv("COS_SECRET_ACCESS_KEY");
+  public static final String COS_REGION = System.getenv("COS_REGION");
+  // Optional: caller may override the endpoint suffix (e.g. for cos-internal 
endpoints).
+  public static final String COS_ENDPOINT = System.getenv("COS_ENDPOINT");
+
+  @VisibleForTesting
+  public void startIntegrationTest() throws Exception {}
+
+  @BeforeAll
+  public void setup() throws IOException {
+    copyBundleJarsToHadoop("tencent-bundle");
+
+    try {
+      super.startIntegrationTest();
+    } catch (Exception e) {
+      throw new RuntimeException("Failed to start integration test", e);
+    }
+
+    metalakeName = GravitinoITUtils.genRandomName("CatalogFilesetIT_metalake");
+    catalogName = GravitinoITUtils.genRandomName("CatalogFilesetIT_catalog");
+    schemaName = GravitinoITUtils.genRandomName(SCHEMA_PREFIX);
+    Configuration conf = new Configuration();
+
+    conf.set("fs.cosn.userinfo.secretId", COS_ACCESS_KEY);
+    conf.set("fs.cosn.userinfo.secretKey", COS_SECRET_KEY);
+    conf.set("fs.cosn.bucket.region", COS_REGION);
+    if (StringUtils.isNotBlank(COS_ENDPOINT)) {
+      conf.set("fs.cosn.bucket.endpoint_suffix", COS_ENDPOINT);
+    }
+    conf.set("fs.cosn.impl", "org.apache.hadoop.fs.CosFileSystem");
+    fileSystem = FileSystem.get(URI.create(String.format("cosn://%s", 
BUCKET_NAME)), conf);
+
+    createMetalake();
+    createCatalog();
+    createSchema();
+  }
+
+  @AfterAll
+  public void stop() throws IOException {
+    Catalog catalog = metalake.loadCatalog(catalogName);
+    catalog.asSchemas().dropSchema(schemaName, true);
+    metalake.dropCatalog(catalogName, true);
+    client.dropMetalake(metalakeName, true);
+
+    try {
+      closer.close();
+    } catch (Exception e) {
+      LOG.error("Failed to close CloseableGroup", e);
+    }
+  }

Review Comment:
   This `@AfterAll` cleanup duplicates the parent implementation but omits 
resource cleanup (e.g., closing the COS FileSystem and the HTTP client) that 
FilesetCatalogIT#stop() performs. This can leak FS/client resources across 
integration tests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to