[
https://issues.apache.org/jira/browse/HADOOP-19050?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17814442#comment-17814442
]
ASF GitHub Bot commented on HADOOP-19050:
-----------------------------------------
ahmarsuhail commented on code in PR #6507:
URL: https://github.com/apache/hadoop/pull/6507#discussion_r1478502544
##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/DefaultS3ClientFactory.java:
##########
@@ -401,4 +409,32 @@ private static Region getS3RegionFromEndpoint(final String
endpoint,
return Region.of(AWS_S3_DEFAULT_REGION);
}
+ public static <BuilderT extends S3BaseClientBuilder<BuilderT, ClientT>,
ClientT> void
Review Comment:
method can be private?
##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/tools/S3AccessGrantsUtil.java:
##########
@@ -0,0 +1,60 @@
+package org.apache.hadoop.fs.s3a.tools;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.s3a.DefaultS3ClientFactory;
+import org.apache.hadoop.fs.store.LogExactlyOnce;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.s3accessgrants.plugin.S3AccessGrantsPlugin;
+import software.amazon.awssdk.services.s3.S3BaseClientBuilder;
+
+import static
org.apache.hadoop.fs.s3a.Constants.AWS_S3_ACCESS_GRANTS_FALLBACK_TO_IAM_ENABLED;
+
+public class S3AccessGrantsUtil {
+
+ protected static final Logger LOG =
+ LoggerFactory.getLogger(S3AccessGrantsUtil.class);
+
+ private static final LogExactlyOnce LOG_EXACTLY_ONCE = new
LogExactlyOnce(LOG);
Review Comment:
rename from `LOG_EXACTLY_ONCE` to what this log is actually for, eg:
`IAM_FALLBACK_WARN`. look at `WARN_OF_DEFAULT_REGION_CHAIN` in
DefaultS3ClientFactory as an example.
##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/tools/S3AccessGrantsUtil.java:
##########
@@ -0,0 +1,60 @@
+package org.apache.hadoop.fs.s3a.tools;
+
+import org.apache.hadoop.conf.Configuration;
Review Comment:
add apache license to the top of this class (copy it over from any other
class)
##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/tools/S3AccessGrantsUtil.java:
##########
@@ -0,0 +1,60 @@
+package org.apache.hadoop.fs.s3a.tools;
+
Review Comment:
wrong package for this class, move to the impl package.
##########
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AccessGrantConfiguration.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.hadoop.fs.s3a;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.test.AbstractHadoopTestBase;
+import org.junit.Test;
+
+import software.amazon.awssdk.services.s3.S3AsyncClient;
+import software.amazon.awssdk.services.s3.S3BaseClientBuilder;
+import software.amazon.awssdk.services.s3.S3Client;
+
+import static org.apache.hadoop.fs.s3a.Constants.AWS_S3_ACCESS_GRANTS_ENABLED;
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * Test S3 Access Grants configurations.
+ */
+public class TestS3AccessGrantConfiguration extends AbstractHadoopTestBase {
+
+ @Test
+ public void testS3AccessGrantsEnabled() {
+ applyVerifyS3AGPlugin(S3Client.builder(), false, true);
+ }
+
+ @Test
+ public void testS3AccessGrantsEnabledAsync() {
+ applyVerifyS3AGPlugin(S3AsyncClient.builder(), false, true);
+ }
+
+ @Test
+ public void testS3AccessGrantsDisabled() {
+ applyVerifyS3AGPlugin(S3Client.builder(), false, false);
+ }
+
+ @Test
+ public void testS3AccessGrantsDisabledByDefault() {
+ applyVerifyS3AGPlugin(S3Client.builder(), true, false);
+ }
+
+ @Test
+ public void testS3AccessGrantsDisabledAsync() {
+ applyVerifyS3AGPlugin(S3AsyncClient.builder(), false, false);
+ }
+
+ @Test
+ public void testS3AccessGrantsDisabledByDefaultAsync() {
+ applyVerifyS3AGPlugin(S3AsyncClient.builder(), true, false);
+ }
+
+ private Configuration createConfig(boolean isDefault, boolean s3agEnabled) {
+ Configuration conf = new Configuration();
+ if (!isDefault){
+ conf.setBoolean(AWS_S3_ACCESS_GRANTS_ENABLED, s3agEnabled);
+ }
+ return conf;
+ }
+
+ private <BuilderT extends S3BaseClientBuilder<BuilderT, ClientT>, ClientT>
void
+ applyVerifyS3AGPlugin(BuilderT builder, boolean isDefault, boolean enabled) {
+ DefaultS3ClientFactory.applyS3AccessGrantsConfigurations(builder,
createConfig(isDefault, enabled));
+ if (enabled){
+ assertEquals(1, builder.plugins().size());
+
assertEquals("software.amazon.awssdk.s3accessgrants.plugin.S3AccessGrantsPlugin",
+ builder.plugins().get(0).getClass().getName()
+ );
+ }
+ else {
+ assertEquals(builder.plugins().size(), 0);
+ }
+ }
+}
Review Comment:
add new line after class
##########
hadoop-tools/hadoop-aws/pom.xml:
##########
@@ -508,6 +508,29 @@
<artifactId>bundle</artifactId>
<scope>compile</scope>
</dependency>
+ <dependency>
Review Comment:
these should all be moved into the pom.xml in hadoop-project as that where
we define dependencies. look at how we import the sdk dependency in this
pom.xml for example.
##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/DefaultS3ClientFactory.java:
##########
@@ -401,4 +409,32 @@ private static Region getS3RegionFromEndpoint(final String
endpoint,
return Region.of(AWS_S3_DEFAULT_REGION);
}
+ public static <BuilderT extends S3BaseClientBuilder<BuilderT, ClientT>,
ClientT> void
+ applyS3AccessGrantsConfigurations(BuilderT builder, Configuration conf) {
+ boolean s3agEnabled = conf.getBoolean(AWS_S3_ACCESS_GRANTS_ENABLED, false);
+ if (!s3agEnabled){
+ LOG_EXACTLY_ONCE.debug("s3ag plugin is not enabled.");
Review Comment:
this won't work, so basically it will log `s3ag plugin is not enabled.`
once, but then your `LOG_EXACTLY_ONCE.debug(
"Class {} is not found exception: {}."` and wherever else you use
it will never log. If you want to log those they will need their own instances
of log exactly once.
But also these are debug logs, you don't need to use log exactly once. We do
that more when we need to make user logs clearer when logging at `warn` or
`info`. You can just use a regular logger here in my opinion.
I also don't think you need this `s3ag plugin is not enabled.` log
specifically. it's getting logged for any who is not using S3AG, so not adding
any value. instead maybe add a log in the try block `Configuring S3 access
grants plugin`
##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/tools/S3AccessGrantsUtil.java:
##########
@@ -0,0 +1,60 @@
+package org.apache.hadoop.fs.s3a.tools;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.s3a.DefaultS3ClientFactory;
+import org.apache.hadoop.fs.store.LogExactlyOnce;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.s3accessgrants.plugin.S3AccessGrantsPlugin;
+import software.amazon.awssdk.services.s3.S3BaseClientBuilder;
+
+import static
org.apache.hadoop.fs.s3a.Constants.AWS_S3_ACCESS_GRANTS_FALLBACK_TO_IAM_ENABLED;
+
+public class S3AccessGrantsUtil {
+
+ protected static final Logger LOG =
+ LoggerFactory.getLogger(S3AccessGrantsUtil.class);
+
+ private static final LogExactlyOnce LOG_EXACTLY_ONCE = new
LogExactlyOnce(LOG);
+ private static final String S3AG_PLUGIN_CLASSNAME =
+ "software.amazon.awssdk.s3accessgrants.plugin.S3AccessGrantsPlugin";
+
+ /**
+ * S3 Access Grants plugin availability.
+ */
+ private static final boolean S3AG_PLUGIN_FOUND = checkForS3AGPlugin();
+
+ private static boolean checkForS3AGPlugin() {
+ try {
+ ClassLoader cl = DefaultS3ClientFactory.class.getClassLoader();
+ cl.loadClass(S3AG_PLUGIN_CLASSNAME);
+ LOG.debug("S3AG plugin class {} found", S3AG_PLUGIN_CLASSNAME);
+ return true;
+ } catch (Exception e) {
+ LOG.debug("S3AG plugin class {} not found", S3AG_PLUGIN_CLASSNAME, e);
+ return false;
+ }
+ }
+
+ /**
+ * Is the S3AG plugin available?
+ * @return true if it was found in the classloader
+ */
+ private static synchronized boolean isS3AGPluginAvailable() {
+ return S3AG_PLUGIN_FOUND;
+ }
+
+ public static <BuilderT extends S3BaseClientBuilder<BuilderT, ClientT>,
ClientT> void
+ applyS3AccessGrantsConfigurations(BuilderT builder, Configuration conf) {
+ if (isS3AGPluginAvailable()) {
+ boolean s3agFallbackEnabled = conf.getBoolean(
+ AWS_S3_ACCESS_GRANTS_FALLBACK_TO_IAM_ENABLED, false);
+ S3AccessGrantsPlugin accessGrantsPlugin =
+
S3AccessGrantsPlugin.builder().enableFallback(s3agFallbackEnabled).build();
+ builder.addPlugin(accessGrantsPlugin);
+ LOG_EXACTLY_ONCE.info("s3ag plugin is added to s3 client with fallback:
{}", s3agFallbackEnabled);
Review Comment:
and +1 on @adnanhemani 's comment, let's make these logs uniform so they
begin with "S3 access grant ... "
##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/tools/S3AccessGrantsUtil.java:
##########
@@ -0,0 +1,60 @@
+package org.apache.hadoop.fs.s3a.tools;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.s3a.DefaultS3ClientFactory;
+import org.apache.hadoop.fs.store.LogExactlyOnce;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.s3accessgrants.plugin.S3AccessGrantsPlugin;
+import software.amazon.awssdk.services.s3.S3BaseClientBuilder;
+
+import static
org.apache.hadoop.fs.s3a.Constants.AWS_S3_ACCESS_GRANTS_FALLBACK_TO_IAM_ENABLED;
+
+public class S3AccessGrantsUtil {
+
+ protected static final Logger LOG =
+ LoggerFactory.getLogger(S3AccessGrantsUtil.class);
+
+ private static final LogExactlyOnce LOG_EXACTLY_ONCE = new
LogExactlyOnce(LOG);
+ private static final String S3AG_PLUGIN_CLASSNAME =
+ "software.amazon.awssdk.s3accessgrants.plugin.S3AccessGrantsPlugin";
+
+ /**
+ * S3 Access Grants plugin availability.
+ */
+ private static final boolean S3AG_PLUGIN_FOUND = checkForS3AGPlugin();
+
+ private static boolean checkForS3AGPlugin() {
+ try {
+ ClassLoader cl = DefaultS3ClientFactory.class.getClassLoader();
+ cl.loadClass(S3AG_PLUGIN_CLASSNAME);
+ LOG.debug("S3AG plugin class {} found", S3AG_PLUGIN_CLASSNAME);
+ return true;
+ } catch (Exception e) {
+ LOG.debug("S3AG plugin class {} not found", S3AG_PLUGIN_CLASSNAME, e);
+ return false;
+ }
+ }
+
+ /**
+ * Is the S3AG plugin available?
+ * @return true if it was found in the classloader
+ */
+ private static synchronized boolean isS3AGPluginAvailable() {
+ return S3AG_PLUGIN_FOUND;
+ }
+
+ public static <BuilderT extends S3BaseClientBuilder<BuilderT, ClientT>,
ClientT> void
+ applyS3AccessGrantsConfigurations(BuilderT builder, Configuration conf) {
+ if (isS3AGPluginAvailable()) {
+ boolean s3agFallbackEnabled = conf.getBoolean(
+ AWS_S3_ACCESS_GRANTS_FALLBACK_TO_IAM_ENABLED, false);
+ S3AccessGrantsPlugin accessGrantsPlugin =
+
S3AccessGrantsPlugin.builder().enableFallback(s3agFallbackEnabled).build();
+ builder.addPlugin(accessGrantsPlugin);
+ LOG_EXACTLY_ONCE.info("s3ag plugin is added to s3 client with fallback:
{}", s3agFallbackEnabled);
Review Comment:
Have two different Loggers that log exactly once for these two different
statements.
> Add S3 Access Grants Support in S3A
> -----------------------------------
>
> Key: HADOOP-19050
> URL: https://issues.apache.org/jira/browse/HADOOP-19050
> Project: Hadoop Common
> Issue Type: New Feature
> Components: fs/s3
> Affects Versions: 3.4.0
> Reporter: Jason Han
> Assignee: Jason Han
> Priority: Minor
> Labels: pull-request-available
>
> Add support for S3 Access Grants
> (https://aws.amazon.com/s3/features/access-grants/) in S3A.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]