Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS: create HttpClientProperties, move s3 related methods into S3FileIOProperties #7562

Merged
merged 8 commits into from
May 10, 2023

Conversation

akshayakp97
Copy link
Contributor

@akshayakp97 akshayakp97 commented May 8, 2023

Subtask of #7516

This PR creates separate class HttpClientProperties. Also, move all s3 related methods into S3FileIOProperties since we plan to deprecate AwsProperties.

As part of #7156, when S3FileIOAwsClientFactory is added for creating S3 client, we will use methods from S3FileIOProperties and HttpClientProperties.

Ran integ tests - TestS3FileIOIntegration, TestS3MultipartUpload and TestDefaultAwsClientFactory

@github-actions github-actions bot added the AWS label May 8, 2023
* use this provider to get AWS credentials provided instead of reading the default credential
* chain to get AWS access credentials.
*/
public static final String CLIENT_CREDENTIALS_PROVIDER = "client.credentials-provider";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be in S3FileIOProperties, this is generic configuration for all AWS clients, thus the prefix client.. So we could create a class AwsClientProperties for them

Copy link
Contributor

@amogh-jahagirdar amogh-jahagirdar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @akshayakp97, I reviewed the code change and had some comments but didn't get a chance to review the tests. I'll take a look at the tests when I get a chance

public static final String HTTP_CLIENT_TYPE_DEFAULT = HTTP_CLIENT_TYPE_APACHE;
/**
* @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties}
* instead
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation for instead on the newline (and in all the other places) looks off to me, is this how spotless is formatting it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup

Comment on lines 111 to 130
try {
try {
provider =
DynMethods.builder("create")
.hiddenImpl(providerClass, Map.class)
.buildStaticChecked()
.invoke(clientCredentialsProviderProperties);
} catch (NoSuchMethodException e) {
provider =
DynMethods.builder("create").hiddenImpl(providerClass).buildStaticChecked().invoke();
}

return provider;
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException(
String.format(
"Cannot create an instance of %s, it does not contain a static 'create' or 'create(Map<String, String>)' method",
credentialsProviderClass),
e);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is a bit hard to read imo, I got what's going on but while we're at this refactoring we can take the opportunity to do some cleanup. For this could we have a separate helper for obtaining the provider with some inline comment on our "fallback" behavior.

@SuppressWarnings("checkstyle:HiddenField")
public AwsCredentialsProvider credentialsProvider(
String accessKeyId, String secretAccessKey, String sessionToken) {
if (accessKeyId != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and secretAccessKey not null

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use Strings.isNullOrEmpty for all these

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that's probably a miss we can fix here

"Cannot initialize %s, it does not implement %s.",
credentialsProviderClass, AwsCredentialsProvider.class.getName()));

// try to invoke 'create(Map<String, String>)' static method, otherwise fallback to 'create()'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once javadoc is added, this can be removed

}

@SuppressWarnings("checkstyle:HiddenField")
private <T extends SdkClientBuilder> void configureEndpoint(T builder, String endpoint) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just merge this method to applyEndpointConfigurations?

}

/**
* Tries to first dynamically load the credentials provider class. If successful, try to invoke
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't typically add javadoc for private methods, this can be moved as a part of the public method doc to explain how the credential provider dynamic loading works.

Copy link
Contributor

@jackye1995 jackye1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me!

@amogh-jahagirdar amogh-jahagirdar merged commit 46fa4e2 into apache:master May 10, 2023
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants