-
Notifications
You must be signed in to change notification settings - Fork 970
Created the Configuration class for Ec2Metadata #3265
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
Created the Configuration class for Ec2Metadata #3265
Conversation
core/imds/pom.xml
Outdated
| <dependency> | ||
| <groupId>software.amazon.awssdk</groupId> | ||
| <artifactId>url-connection-client</artifactId> | ||
| <version>2.17.209-SNAPSHOT</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with ${awsjavasdk.version}
| /** | ||
| * @return The number of retry attempts for any failed request. | ||
| */ | ||
| Integer retries(); | ||
|
|
||
| /** | ||
| * @return The endpoint of IMDS. | ||
| */ | ||
| String endpoint(); | ||
|
|
||
| /** | ||
| * @return The port for the endpoint. | ||
| */ | ||
| Integer port(); | ||
|
|
||
| /** | ||
| * @return The Time to live (TTL) of the token. | ||
| */ | ||
| Integer tokenTtl(); | ||
|
|
||
| /** | ||
| * @return The endpoint mode of IMDS.Supported values include IPv4 and IPv6. | ||
| */ | ||
| String endpointMode(); | ||
|
|
||
| /** | ||
| * @return The number of seconds to wait for the connection to open. | ||
| */ | ||
| Integer httpOpenTimeout(); | ||
|
|
||
| /** | ||
| * @return The number of seconds for one chunk of data to be read. | ||
| */ | ||
| Integer httpReadTimeout(); | ||
|
|
||
| /** | ||
| * @return The output stream for debugging. | ||
| */ | ||
| String httpDebugOutput(); | ||
|
|
||
| /** | ||
| * @return The number of seconds to sleep in-between retries. | ||
| */ | ||
| Integer backoff(); | ||
|
|
||
| /** | ||
| * @return The SdkHttpClient instance to make the http requests. | ||
| */ | ||
| SdkHttpClient httpClient(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need getters for all of this? I would recommend leaving most if not all of them out for now. In general, this is probably information that the user will already know (because they configured it), or not really care about if they're getting the client from something else that created it for them.
| * @param retries The number of retry attempts for any failed request. | ||
| * @return Returns a reference to this builder | ||
| */ | ||
| Builder retries(Integer retries); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be using something like (but maybe a simplified version) of RetryPolicy:
aws-sdk-java-v2/core/sdk-core/src/main/java/software/amazon/awssdk/core/retry/RetryPolicy.java
Line 47 in b3ff6d5
| public final class RetryPolicy implements ToCopyableBuilder<RetryPolicy.Builder, RetryPolicy> { |
| * @param endpoint The endpoint of IMDS. | ||
| * @return Returns a reference to this builder | ||
| */ | ||
| Builder endpoint(String endpoint); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
endpoint should probably be a URI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted.
| * @param tokenTtl The Time to live (TTL) of the token. | ||
| * @return Returns a reference to this builder | ||
| */ | ||
| Builder tokenTtl(Integer tokenTtl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be Duration
| * @param port The port for the endpoint. | ||
| * @return Returns a reference to this builder | ||
| */ | ||
| Builder port(Integer port); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why boxed time here? Can it just be int?
| Builder httpOpenTimeout(Integer httpOpenTimeout); | ||
|
|
||
| /** | ||
| * Define the number of seconds for one chunk of data to be read. | ||
| * | ||
| * @param httpReadTimeout The number of seconds for one chunk of data to be read. | ||
| * @return Returns a reference to this builder | ||
| */ | ||
| Builder httpReadTimeout(Integer httpReadTimeout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are configs that are already handled at the SdkHttpClient level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted.
| * @param httpDebugOutput TThe output stream for debugging. | ||
| * @return Returns a reference to this builder | ||
| */ | ||
| Builder httpDebugOutput(String httpDebugOutput); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what this
| @Test | ||
| public void verify_not_equal_objects(){ | ||
|
|
||
| Ec2Metadata client = Ec2Metadata.builder().retries(2).build(); | ||
| Ec2Metadata anotherClient = Ec2Metadata.builder().build(); | ||
| assertThat(client.retries()).isNotEqualTo(anotherClient.retries()); | ||
| } | ||
|
|
||
| @Test | ||
| public void verify_hashcode_equal(){ | ||
|
|
||
| Ec2Metadata client = Ec2Metadata.builder().build(); | ||
| Ec2Metadata anotherClient = Ec2Metadata.builder().build(); | ||
| assertThat(client.hashCode()).isEqualTo(anotherClient.hashCode()); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use equalsVerifier
Line 25 in 1032916
| EqualsVerifier.forClass(DefaultCopy.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not know about it. Will implement
5c7a498 to
7720343
Compare
| /** | ||
| * Define the Time to live (TTL) of the token. | ||
| * | ||
| * @param tokenTtl The Time to live (TTL) of the token. | ||
| * @return Returns a reference to this builder | ||
| */ | ||
| Builder tokenTtl(Duration tokenTtl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe token ttl is not something configurable and is provided by IMDS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SEP mentions to have the tokenTtl functionality support
| * @param backoff The number of seconds to sleep in-between retries. | ||
| * @return Returns a reference to this builder | ||
| */ | ||
| Builder backoff(Integer backoff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this included in the retryPolicy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 we should remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SEP mentions that the if the user mentions the backoff , it should be an override. Would it be better to have a field for it as it would be convenient for user ?
|
|
||
| /** | ||
| * @return The retry policy which includes the number of retry attempts for any failed request. | ||
| */ | ||
| RetryPolicy retryPolicy(); | ||
|
|
||
| /** | ||
| * @return The endpoint of IMDS. | ||
| */ | ||
| URI endpoint(); | ||
|
|
||
| /** | ||
| * @return The port for the endpoint. | ||
| */ | ||
| Integer port(); | ||
|
|
||
| /** | ||
| * @return The Time to live (TTL) of the token. | ||
| */ | ||
| Duration tokenTtl(); | ||
|
|
||
| /** | ||
| * @return The endpoint mode of IMDS.Supported values include IPv4 and IPv6. | ||
| */ | ||
| String endpointMode(); | ||
|
|
||
| /** | ||
| * @return The output stream for debugging. | ||
| */ | ||
| String httpDebugOutput(); | ||
|
|
||
| /** | ||
| * @return The number of seconds to sleep in-between retries. | ||
| */ | ||
| Integer backoff(); | ||
|
|
||
| /** | ||
| * @return The SdkHttpClient instance to make the http requests. | ||
| */ | ||
| SdkHttpClient httpClient(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to expose getters for the settings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the client configuration.md file , it had getters there.
| * @param endpointMode The endpoint mode of IMDS.Supported values include IPv4 and IPv6. | ||
| * @return Returns a reference to this builder | ||
| */ | ||
| Builder endpointMode(String endpointMode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use enum for the endpoint mode so users can easily choose from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Will change it
| * @param port The port for the endpoint. | ||
| * @return Returns a reference to this builder | ||
| */ | ||
| Builder port(Integer port); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably not needed because it should be supplied as part of URI in endpoint
7720343 to
e873bc2
Compare
| IPv4, | ||
| IPv6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enum should use all caps. IPV4, IPV6
|
SonarCloud Quality Gate failed. |








Created a Client Class . Implemented the Builder Interface and the entire build functionality to create client Objects.
Motivation and Context
Implemented the Builder Interface and the entire build functionality to create client Objects.
Modifications
Implemented the Builder Interface and the entire build functionality to create client Objects.
Testing
Wrote Unit cases to test the multiple methods
Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License