|
19 | 19 | package org.apache.hadoop.fs.s3a;
|
20 | 20 |
|
21 | 21 | import java.io.IOException;
|
| 22 | +import java.lang.reflect.Method; |
22 | 23 | import java.net.URI;
|
23 | 24 | import java.net.URISyntaxException;
|
24 | 25 |
|
25 | 26 | import org.apache.hadoop.classification.VisibleForTesting;
|
26 | 27 | import org.apache.hadoop.fs.s3a.impl.AWSClientConfig;
|
27 |
| -import org.apache.hadoop.fs.s3a.impl.InstantiationIOException; |
28 | 28 | import org.slf4j.Logger;
|
29 | 29 | import org.slf4j.LoggerFactory;
|
30 | 30 |
|
|
38 | 38 | import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
|
39 | 39 | import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity;
|
40 | 40 | import software.amazon.awssdk.regions.Region;
|
41 |
| -import software.amazon.awssdk.s3accessgrants.plugin.S3AccessGrantsPlugin; |
42 | 41 | import software.amazon.awssdk.services.s3.S3AsyncClient;
|
43 | 42 | import software.amazon.awssdk.services.s3.S3BaseClientBuilder;
|
44 | 43 | import software.amazon.awssdk.services.s3.S3Client;
|
|
56 | 55 |
|
57 | 56 | import static org.apache.hadoop.fs.s3a.Constants.AWS_REGION;
|
58 | 57 | import static org.apache.hadoop.fs.s3a.Constants.AWS_S3_ACCESS_GRANTS_ENABLED;
|
59 |
| -import static org.apache.hadoop.fs.s3a.Constants.AWS_S3_ACCESS_GRANTS_FALLBACK_TO_IAM_ENABLED; |
60 | 58 | import static org.apache.hadoop.fs.s3a.Constants.AWS_S3_DEFAULT_REGION;
|
61 | 59 | import static org.apache.hadoop.fs.s3a.Constants.CENTRAL_ENDPOINT;
|
62 | 60 | import static org.apache.hadoop.fs.s3a.Constants.FIPS_ENDPOINT;
|
|
68 | 66 | import static org.apache.hadoop.fs.s3a.Constants.AWS_SERVICE_IDENTIFIER_S3;
|
69 | 67 | import static org.apache.hadoop.fs.s3a.auth.SignerFactory.createHttpSigner;
|
70 | 68 | import static org.apache.hadoop.fs.s3a.impl.AWSHeaders.REQUESTER_PAYS_HEADER;
|
71 |
| -import static org.apache.hadoop.fs.s3a.impl.InstantiationIOException.unavailable; |
72 | 69 | import static org.apache.hadoop.fs.s3a.impl.InternalConstants.AUTH_SCHEME_AWS_SIGV_4;
|
73 | 70 | import static org.apache.hadoop.util.Preconditions.checkArgument;
|
74 | 71 |
|
@@ -119,34 +116,8 @@ public class DefaultS3ClientFactory extends Configured
|
119 | 116 | public static final String ERROR_ENDPOINT_WITH_FIPS =
|
120 | 117 | "An endpoint cannot set when " + FIPS_ENDPOINT + " is true";
|
121 | 118 |
|
122 |
| - private static final String S3AG_PLUGIN_CLASSNAME = |
123 |
| - "software.amazon.awssdk.s3accessgrants.plugin.S3AccessGrantsPlugin"; |
124 |
| - |
125 |
| - /** |
126 |
| - * S3 Access Grants plugin availability. |
127 |
| - */ |
128 |
| - private static final boolean S3AG_PLUGIN_FOUND = checkForS3AGPlugin(); |
129 |
| - |
130 |
| - private static boolean checkForS3AGPlugin() { |
131 |
| - try { |
132 |
| - ClassLoader cl = DefaultS3ClientFactory.class.getClassLoader(); |
133 |
| - cl.loadClass(S3AG_PLUGIN_CLASSNAME); |
134 |
| - LOG.debug("S3AG plugin class {} found", S3AG_PLUGIN_CLASSNAME); |
135 |
| - return true; |
136 |
| - } catch (Exception e) { |
137 |
| - LOG.debug("S3AG plugin class {} not found", S3AG_PLUGIN_CLASSNAME, e); |
138 |
| - return false; |
139 |
| - } |
140 |
| - } |
141 |
| - |
142 |
| - /** |
143 |
| - * Is the Encryption client available? |
144 |
| - * @return true if it was found in the classloader |
145 |
| - */ |
146 |
| - private static synchronized boolean isS3AGPluginAvailable() { |
147 |
| - return S3AG_PLUGIN_FOUND; |
148 |
| - } |
149 |
| - |
| 119 | + private static final String S3AG_UTIL_CLASSNAME = |
| 120 | + "org.apache.hadoop.fs.s3a.tools.S3AccessGrantsUtil"; |
150 | 121 | @Override
|
151 | 122 | public S3Client createS3Client(
|
152 | 123 | final URI uri,
|
@@ -441,19 +412,32 @@ private static Region getS3RegionFromEndpoint(final String endpoint,
|
441 | 412 | public static <BuilderT extends S3BaseClientBuilder<BuilderT, ClientT>, ClientT> void
|
442 | 413 | applyS3AccessGrantsConfigurations(BuilderT builder, Configuration conf) {
|
443 | 414 | boolean s3agEnabled = conf.getBoolean(AWS_S3_ACCESS_GRANTS_ENABLED, false);
|
444 |
| - if (s3agEnabled) { |
445 |
| - if (isS3AGPluginAvailable()) { |
446 |
| - boolean s3agFallbackEnabled = conf.getBoolean( |
447 |
| - AWS_S3_ACCESS_GRANTS_FALLBACK_TO_IAM_ENABLED, false); |
448 |
| - S3AccessGrantsPlugin accessGrantsPlugin = |
449 |
| - S3AccessGrantsPlugin.builder().enableFallback(s3agFallbackEnabled).build(); |
450 |
| - builder.addPlugin(accessGrantsPlugin); |
451 |
| - LOG_EXACTLY_ONCE.info("s3ag plugin is added to s3 client with fallback: {}", s3agFallbackEnabled); |
452 |
| - } else { |
453 |
| - LOG_EXACTLY_ONCE.warn("s3ag plugin is not available."); |
454 |
| - } |
455 |
| - } else { |
456 |
| - LOG_EXACTLY_ONCE.debug("s3ag plugin is not added to s3 client."); |
| 415 | + if (!s3agEnabled){ |
| 416 | + LOG_EXACTLY_ONCE.debug("s3ag plugin is not enabled."); |
| 417 | + return; |
| 418 | + } |
| 419 | + try { |
| 420 | + Class s3agUtil = Class.forName(S3AG_UTIL_CLASSNAME); |
| 421 | + Class[] argTypes = new Class[2]; |
| 422 | + argTypes[0] = S3BaseClientBuilder.class; |
| 423 | + argTypes[1] = Configuration.class; |
| 424 | + Method applyS3agConfig = |
| 425 | + s3agUtil.getMethod("applyS3AccessGrantsConfigurations", S3BaseClientBuilder.class, Configuration.class); |
| 426 | + applyS3agConfig.invoke(null, builder, conf); |
| 427 | + } catch (ClassNotFoundException e) { |
| 428 | + LOG_EXACTLY_ONCE.debug( |
| 429 | + "Class {} is not found exception: {}.", |
| 430 | + S3AG_UTIL_CLASSNAME, |
| 431 | + e.getStackTrace() |
| 432 | + ); |
| 433 | + } catch (Exception e) { |
| 434 | + LOG_EXACTLY_ONCE.debug("{} exception: {})", e.getClass(), e.getStackTrace()); |
| 435 | + } catch (NoClassDefFoundError e) { |
| 436 | + LOG_EXACTLY_ONCE.debug( |
| 437 | + "Class {} is not found error: ", |
| 438 | + S3AG_UTIL_CLASSNAME, |
| 439 | + e.getStackTrace() |
| 440 | + ); |
457 | 441 | }
|
458 | 442 | }
|
459 | 443 | }
|
0 commit comments