Skip to content

Conversation

@srsaikumarreddy
Copy link
Contributor

@srsaikumarreddy srsaikumarreddy commented Jun 22, 2022

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

  • Bug fix (non-breaking change which fixes an issue)
  • [X ] New feature (non-breaking change which adds functionality)

Checklist

  • [ X] I have read the CONTRIBUTING document
  • [ X] Local run of mvn install succeeds
  • [ X] My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • [ X] I have added tests to cover my changes
  • [ X] All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • [ X] I confirm that this pull request can be released under the Apache 2 license

@srsaikumarreddy srsaikumarreddy requested a review from a team as a code owner June 22, 2022 22:28
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>url-connection-client</artifactId>
<version>2.17.209-SNAPSHOT</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace with ${awsjavasdk.version}

Comment on lines 35 to 76
/**
* @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();
Copy link
Contributor

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);
Copy link
Contributor

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:

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);
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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);
Copy link
Contributor

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?

Comment on lines 155 to 163
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);
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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

Comment on lines 57 to 72
@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());
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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

@srsaikumarreddy srsaikumarreddy force-pushed the saikred/client_configuration branch from 5c7a498 to 7720343 Compare June 24, 2022 03:10
Comment on lines +126 to +86
/**
* 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);
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

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 ?

Comment on lines 37 to 76

/**
* @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();
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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

@srsaikumarreddy srsaikumarreddy force-pushed the saikred/client_configuration branch from 7720343 to e873bc2 Compare June 25, 2022 01:23
Comment on lines 24 to 25
IPv4,
IPv6
Copy link
Contributor

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

@zoewangg zoewangg enabled auto-merge (squash) June 28, 2022 17:48
@zoewangg zoewangg merged commit 88902b9 into aws:feature/master/imds Jun 28, 2022
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

26.9% 26.9% Coverage
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants